diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 6134e34..b354eea 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -3210,6 +3210,30 @@ namespace NitrousReverseRechargeFix } +// ============= Fix Hydra's jet thrusters not displaying due to an uninitialized variable in RwMatrix ============= +// By B1ack_Wh1te +namespace JetThrustersFix +{ + // These are technically CMatrix, but for simplicity we use RwMatrix here + template + static RwMatrix* (*orgMatrixMultiply)(RwMatrix* out, const RwMatrix* lhs, const RwMatrix* rhs); + + template + static RwMatrix* MatrixMultiply_ZeroFlags(RwMatrix* out, const RwMatrix* lhs, const RwMatrix* rhs) + { + RwMatrix* result = orgMatrixMultiply(out, lhs, rhs); + + // Technically, this should be the same as RwMatrixUpdate, but this variable is on the stack + // and completely uninitialized, so zero it completely for consistent results. + rwMatrixSetFlags(result, 0); + + return result; + } + + HOOK_EACH_INIT(MatrixMultiply, orgMatrixMultiply, MatrixMultiply_ZeroFlags); +} + + // ============= LS-RP Mode stuff ============= namespace LSRPMode { @@ -6411,6 +6435,16 @@ void Patch_SA_10(HINSTANCE hInstance) } + // Fix Hydra's jet thrusters not displaying due to an uninitialized variable in RwMatrix + // By B1ack_Wh1te + { + using namespace JetThrustersFix; + + std::array matrixMult = { 0x6CA09F, 0x6CA122, 0x6CA1B2, 0x6CA242 }; + HookEach_MatrixMultiply(matrixMult, InterceptCall); + } + + #if FULL_PRECISION_D3D // Test - full precision D3D device Patch( 0x7F672B+1, *(uint8_t*)(0x7F672B+1) | D3DCREATE_FPU_PRESERVE ); @@ -8591,6 +8625,25 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance) InjectHook(getGasPedal.get(1), &NitrousControl_DontRechargeWhenReversing_NewBinaries, HookType::Call); } TXN_CATCH(); + + + // Fix Hydra's jet thrusters not displaying due to an uninitialized variable in RwMatrix + // By B1ack_Wh1te + try + { + using namespace JetThrustersFix; + + auto thrust = pattern("D9 5D DC E8 ? ? ? ? 83 C4 0C").count(4); + + std::array matrixMult = { + thrust.get(0).get(3), + thrust.get(1).get(3), + thrust.get(2).get(3), + thrust.get(3).get(3), + }; + HookEach_MatrixMultiply(matrixMult, InterceptCall); + } + TXN_CATCH(); }