From b48f5da91da0e633654d9c6ca7f948acafec5f47 Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 6 Feb 2024 19:25:14 +0100 Subject: [PATCH] Correct an improperly decrypted CPlayerPedData::operator= that broke gang recruiting after activating replays Contributed by Wesser --- SilentPatchSA/SilentPatchSA.cpp | 90 +++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 0e39260..5b86d3b 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -2016,6 +2016,75 @@ namespace RacingCheckpointsRender } } +// ============= Correct an improperly decrypted CPlayerPedData::operator= that broke gang recruiting after activating replays ============= +namespace PlayerPedDataAssignment +{ + __declspec(naked) void AssignmentOp_Hoodlum() + { + _asm + { + xor edx, [ecx+34h] + and edx, 1 + xor [eax+34h], edx + mov esi, [eax+34h] + mov edx, [ecx+34h] + xor edx, esi + and edx, 2 + xor edx, esi + mov [eax+34h], edx + mov esi, [ecx+34h] + xor esi, edx + and esi, 4 + xor esi, edx + mov [eax+34h], esi + mov edx, [ecx+34h] + xor edx, esi + and edx, 8 + xor edx, esi + mov [eax+34h], edx + mov esi, [ecx+34h] + xor esi, edx + and esi, 10h + xor esi, edx + mov [eax+34h], esi + mov edx, [ecx+34h] + xor edx, esi + and edx, 20h + xor edx, esi + mov [eax+34h], edx + mov esi, [ecx+34h] + xor esi, edx + and esi, 40h + xor esi, edx + mov [eax+34h], esi + mov edx, [ecx+34h] + xor edx, esi + and edx, 80h + xor edx, esi + mov [eax+34h], edx + mov esi, [ecx+34h] + xor esi, edx + and esi, 100h + xor esi, edx + mov [eax+34h], esi + mov edx, [ecx+34h] + retn + } + } + + __declspec(naked) void AssignmentOp_Compact() + { + _asm + { + call AssignmentOp_Hoodlum + xor edx, esi + and edx, 200h + retn + } + } +} + + // ============= LS-RP Mode stuff ============= namespace LSRPMode @@ -4651,6 +4720,27 @@ void Patch_SA_10() } + // Correct an improperly decrypted CPlayerPedData::operator= that broke gang recruiting after activating replays + // Only broken in the HOODLUM EXE and the compact EXE that carried over the bug + // By Wesser + { + using namespace PlayerPedDataAssignment; + + uintptr_t placeToPatch = ModCompat::Utils::GetFunctionAddrIfRerouted(0x45C4B0) + 0x5D; + + // If we're overwriting actual meaningful instructions and not NOPs, use a different wrapper + if (MemEquals(placeToPatch, { 0x90, 0x90, 0x90, 0x90, 0x90 })) + { + InjectHook(placeToPatch, AssignmentOp_Hoodlum, HookType::Call); + } + else + { + InjectHook(placeToPatch, AssignmentOp_Compact, HookType::Call); + Nop(placeToPatch + 5, 3); + } + } + + #if FULL_PRECISION_D3D // Test - full precision D3D device Patch( 0x7F672B+1, *(uint8_t*)(0x7F672B+1) | D3DCREATE_FPU_PRESERVE );