From 3134755736c3bb1bf2d6c4d441737d5e0f3eda39 Mon Sep 17 00:00:00 2001 From: Trsdy <914137150@qq.com> Date: Sat, 24 Feb 2024 19:31:00 +0800 Subject: [PATCH] properly consider frame index for multi-section vxl shadow --- src/Ext/TechnoType/Hooks.cpp | 52 ++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/Ext/TechnoType/Hooks.cpp b/src/Ext/TechnoType/Hooks.cpp index 7ff4262782..f4649f4639 100644 --- a/src/Ext/TechnoType/Hooks.cpp +++ b/src/Ext/TechnoType/Hooks.cpp @@ -355,14 +355,15 @@ DEFINE_HOOK(0x4DB157, FootClass_DrawVoxelShadow_TurretShadow, 0x8) if (pTypeExt->TurretShadow.Get(RulesExt::Global()->DrawTurretShadow) && tur->VXL && tur->HVA) { - auto mtx = pThis->Locomotor->Shadow_Matrix(0); + auto mtx = Matrix3D::GetIdentity(); pTypeExt->ApplyTurretOffset(&mtx, *reinterpret_cast(0xB1D008)); - mtx.TranslateZ(-tur->HVA->Matrixes[0].GetZVal()); mtx.RotateZ(static_cast(pThis->SecondaryFacing.Current().GetRadian<32>() - pThis->PrimaryFacing.Current().GetRadian<32>())); - Matrix3D::MatrixMultiply(&mtx, &Matrix3D::VoxelDefaultMatrix, &mtx); + mtx = *pMatrix * mtx; pThis->DrawVoxelShadow(tur, 0, angle, 0, a4, &a3, &mtx, a9, pSurface, pos); - auto bar = &pType->BarrelVoxel; + + auto bar = (pType->TurretCount == 0 || pType->IsGattling) ? + &pType->BarrelVoxel : &pType->ChargerBarrels[pThis->CurrentTurretNumber]; if (bar->VXL && bar->HVA) pThis->DrawVoxelShadow(bar, 0, angle, 0, a4, &a3, &mtx, a9, pSurface, pos); @@ -376,13 +377,48 @@ DEFINE_HOOK(0x4DB157, FootClass_DrawVoxelShadow_TurretShadow, 0x8) { for (auto index : pTypeExt->ShadowIndices) { - auto hva = pVXL->HVA; - Matrix3D idxmtx = *pMatrix; - idxmtx.TranslateZ(-hva->Matrixes[index].GetZVal()); - Matrix3D::MatrixMultiply(&idxmtx, &Matrix3D::VoxelDefaultMatrix, &idxmtx); pThis->DrawVoxelShadow(pVXL, index, angle, a5, a4, &a3, pMatrix, a9, pSurface, pos); } } return 0x4DB195; } + +DEFINE_HOOK(0x7072A1, sub707280_TryFixingTheMatrix, 0x7) +{ + GET(FootClass*, pThis, EBX); + GET(VoxelStruct*, pVXL, EBP); + GET_STACK(Matrix3D*, pMat, STACK_OFFSET(0xE8, 0xC)); + GET_STACK(int, shadow_index, STACK_OFFSET(0xE8, 0x18)); + + REF_STACK(Matrix3D, matRet, STACK_OFFSET(0xE8, -0x60)); + + auto hva = pVXL->HVA; + // cursed + int index = shadow_index + hva->LayerCount * (pThis->WalkedFramesSoFar % hva->FrameCount); + Matrix3D hvamat = hva->Matrixes[index]; + // TODO : what is this Z offset supposed to be exactly? In order to properly shift the sections to the same level + hvamat.TranslateZ( + -hvamat.GetZVal() + - pVXL->VXL->TailerData->MinBounds.Z + ); + + matRet = *pMat * hvamat; + + // Recover vanilla instructions + auto pType = pThis->GetTechnoType(); + if (pType->UseBuffer) + *reinterpret_cast(0xB43180) = 1; + + REF_STACK(Matrix3D, b, STACK_OFFSET(0xE8, -0x90)); + b.MakeIdentity(); + + // TODO: properly scale this + if (pType->ConsideredAircraft) + b.Scale( + // 1.f - 0.5f * std::clamp(pThis->GetHeight(), 0, 728) / 728.f + 0.5f + ); + + return 0x707331; +}