Correct an improperly decrypted CPlayerPedData::operator= that broke gang recruiting after activating replays

Contributed by Wesser
This commit is contained in:
Silent 2024-02-06 19:25:14 +01:00
parent 141ee0f1a5
commit b48f5da91d
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1

View File

@ -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<uint8_t>( 0x7F672B+1, *(uint8_t*)(0x7F672B+1) | D3DCREATE_FPU_PRESERVE );