Skip to content

Commit 0cb685e

Browse files
fix power point convergence value with customs
1 parent dc987c4 commit 0cb685e

File tree

1 file changed

+66
-9
lines changed

1 file changed

+66
-9
lines changed

popnhax/dllmain.cc

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include "SearchFile.h"
3333

34-
#define PROGRAM_VERSION "1.10.dev"
34+
#define PROGRAM_VERSION "1.10"
3535

3636
const char *g_game_dll_fn = NULL;
3737
const char *g_config_fn = NULL;
@@ -2677,13 +2677,6 @@ static bool patch_pfree() {
26772677
MH_CreateHook((LPVOID)patch_addr, (LPVOID)hook_pfree_pplist_inject,
26782678
(void **)&real_pfree_pplist_inject);
26792679
}
2680-
/* prevent crash when playing only customs in a credit */
2681-
{
2682-
if (!find_and_patch_hex(g_game_dll_fn, "\x0F\x8E\x5C\xFF\xFF\xFF\xEB\x04", 8, 6, "\x90\x90", 2))
2683-
{
2684-
LOG("popnhax: pfree: cannot patch end list pointer\n");
2685-
}
2686-
}
26872680

26882681
/* restore pp_list pointer so that it is freed at end of credit */
26892682
{
@@ -5116,6 +5109,33 @@ static bool patch_db_fix_cursor(){
51165109
return true;
51175110
}
51185111

5112+
void (*real_pp_mean_compute)();
5113+
void hook_pp_mean_compute()
5114+
{
5115+
__asm("test ecx, ecx\n");
5116+
__asm("jnz divide_list\n");
5117+
__asm("mov eax, 0\n");
5118+
__asm("jmp skip_divide\n");
5119+
__asm("divide_list:\n");
5120+
__asm("div ecx\n");
5121+
__asm("skip_divide:\n");
5122+
real_pp_mean_compute();
5123+
}
5124+
5125+
void (*real_pp_convergence_loop)();
5126+
void hook_pp_convergence_loop()
5127+
{
5128+
__asm("movzx eax, word ptr[ebx]\n");
5129+
__asm("cmp eax, 0xBB8\n");
5130+
__asm("jl conv_loop_rearm\n");
5131+
__asm("mov al, 0\n");
5132+
__asm("jmp conv_loop_leave\n");
5133+
__asm("conv_loop_rearm:\n");
5134+
__asm("mov al, 1\n");
5135+
__asm("conv_loop_leave:\n");
5136+
real_pp_convergence_loop();
5137+
}
5138+
51195139
bool patch_db_power_points()
51205140
{
51215141
DWORD dllSize = 0;
@@ -5145,7 +5165,20 @@ bool patch_db_power_points()
51455165
g_pfree_song_offset = *(uint8_t *) ((int64_t)data + pattern_offset + 0x03);
51465166
}
51475167

5148-
/* Adapt convergence value computation (skip cs_omni and customs) */
5168+
/* skip cs_omni and customs in power point convergence value */
5169+
{
5170+
int64_t pattern_offset = search(data, dllSize, "\x8B\x6C\x24\x30\x8B\x4C\x24\x2C", 8, 0);
5171+
if (pattern_offset == -1) {
5172+
LOG("popnhax: patch_db: cannot find power point convergence value computation loop\n");
5173+
return false;
5174+
}
5175+
5176+
uint64_t patch_addr = (int64_t)data + pattern_offset - 0x08;
5177+
MH_CreateHook((LPVOID)(patch_addr), (LPVOID)hook_pp_convergence_loop,
5178+
(void **)&real_pp_convergence_loop);
5179+
}
5180+
5181+
/* make sure they cannot count (sanity check) */
51495182
{
51505183
int64_t pattern_offset = search(data, dllSize, "\x84\xC0\x75\x11\x8D\x44\x24\x38", 8, 0);
51515184
if (pattern_offset == -1) {
@@ -5179,9 +5212,33 @@ bool patch_db_power_points()
51795212
return false;
51805213
}
51815214
skip_pp_list_elem = (void(*)()) ((int64_t)data + jump_addr_offset);
5215+
}
5216+
5217+
/* prevent crash when playing only customs in a credit */
5218+
{
5219+
if (!find_and_patch_hex(g_game_dll_fn, "\x0F\x8E\x5C\xFF\xFF\xFF\xEB\x04", 8, 6, "\x90\x90", 2))
5220+
{
5221+
LOG("popnhax: patch_db: cannot patch end list pointer\n");
5222+
}
5223+
}
5224+
5225+
/* prevent another crash when playing only customs in a credit (sanity check) */
5226+
{
5227+
int64_t pattern_offset = search(data, dllSize, "\xC1\xF9\x02\x33\xD2\xF7\xF1\x8B\xC8", 9, 0);
5228+
if (pattern_offset == -1) {
5229+
LOG("popnhax: patch_db: cannot find power point mean computation\n");
5230+
return false;
5231+
}
5232+
5233+
uint64_t patch_addr = (int64_t)data + pattern_offset + 0x05;
5234+
patch_memory(patch_addr, (char*)"\x90\x90", 2); // erase original div ecx (is taken care of in hook_pp_mean_compute)
51825235

5236+
/* fix possible divide by zero error */
5237+
MH_CreateHook((LPVOID)patch_addr, (LPVOID)hook_pp_mean_compute,
5238+
(void **)&real_pp_mean_compute);
51835239
}
51845240

5241+
LOG("popnhax: patch_db: power point computation fixed\n");
51855242
return true;
51865243
}
51875244

0 commit comments

Comments
 (0)