fix another pplist crash when playing only customs

This commit is contained in:
CrazyRedMachine 2024-01-04 15:25:59 +01:00
parent dc987c46ac
commit 7c8248e00d

View File

@ -5116,6 +5116,19 @@ static bool patch_db_fix_cursor(){
return true;
}
void (*real_pp_mean_compute)();
void hook_pp_mean_compute()
{
__asm("test ecx, ecx\n");
__asm("jnz divide_list\n");
__asm("mov eax, 0\n");
__asm("jmp skip_divide\n");
__asm("divide_list:\n");
__asm("div ecx\n");
__asm("skip_divide:\n");
real_pp_mean_compute();
}
bool patch_db_power_points()
{
DWORD dllSize = 0;
@ -5181,7 +5194,23 @@ bool patch_db_power_points()
skip_pp_list_elem = (void(*)()) ((int64_t)data + jump_addr_offset);
}
/* prevent crash when playing only customs in a credit */
{
int64_t pattern_offset = search(data, dllSize, "\xC1\xF9\x02\x33\xD2\xF7\xF1\x8B\xC8", 9, 0);
if (pattern_offset == -1) {
LOG("popnhax: patch_db: cannot find power point mean computation\n");
return false;
}
uint64_t patch_addr = (int64_t)data + pattern_offset + 0x05;
patch_memory(patch_addr, (char*)"\x90\x90", 2); // erase original div ecx (is taken care of in hook_pp_mean_compute)
/* fix possible divide by zero error */
MH_CreateHook((LPVOID)patch_addr, (LPVOID)hook_pp_mean_compute,
(void **)&real_pp_mean_compute);
}
LOG("popnhax: patch_db: power point computation fixed\n");
return true;
}