Skip to content

Commit 6b3dfb1

Browse files
fix custom track format
1 parent 2130378 commit 6b3dfb1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

popnhax/custom_categs.cc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#define F_OK 0
2020

21-
2221
//game code takes array start address from offset 0xC and the address after the list end from offset 0x10
2322
typedef struct songlist_s {
2423
uint32_t dummy[3];
@@ -566,8 +565,8 @@ void (*real_categ_printf_call)();
566565
void (*real_categ_title_printf)();
567566
void hook_categ_title_printf()
568567
{
569-
__asm("cmp edi, 0x10\n");
570-
__asm("jle categ_title_printf_ok\n");
568+
__asm("cmp edi, [_g_max_categ_idx]\n");
569+
__asm("jl categ_title_printf_ok\n");
571570
__asm("mov eax, _g_categformat\n");
572571
__asm("push eax\n");
573572
__asm("jmp [_real_categ_printf_call]\n");
@@ -590,12 +589,16 @@ void hook_categ_listing()
590589
real_categ_listing();
591590
}
592591

592+
uint32_t g_songid_offset_title = 0; // offset from ESP to find songid in song printf
593+
uint32_t g_songid_offset_artist = 0; // offset from ESP to find songid in artist printf
593594
void (*real_song_printf)();
594595
void hook_song_printf()
595596
{
596597
__asm("push eax\n");
597598
__asm("push ebx\n");
598-
__asm("mov eax, [esp+0x50]\n");
599+
__asm("mov eax, [_g_songid_offset_title]\n");
600+
__asm("add eax, esp\n");
601+
__asm("mov eax, [eax]\n");
599602

600603
__asm("push ecx\n");
601604
__asm("push edx\n");
@@ -624,7 +627,9 @@ void hook_artist_printf()
624627
{
625628
__asm("push eax\n");
626629
__asm("push ebx\n");
627-
__asm("mov eax, [esp+0x50]\n");
630+
__asm("mov eax, [_g_songid_offset_artist]\n");
631+
__asm("add eax, esp\n");
632+
__asm("mov eax, [eax]\n");
628633

629634
__asm("push ecx\n");
630635
__asm("push edx\n");
@@ -648,15 +653,18 @@ void hook_artist_printf()
648653
real_artist_printf();
649654
}
650655

651-
static bool patch_custom_track_format(const char *game_dll_fn) {
656+
static bool patch_custom_track_format(const char *game_dll_fn, uint8_t game_version) {
652657
DWORD dllSize = 0;
653658
char *data = getDllData(game_dll_fn, &dllSize);
654659

660+
g_songid_offset_title = (game_version>27) ? 0x34 : 0x50;
661+
g_songid_offset_artist = (game_version>27) ? 0x4C : 0x50;
662+
655663
//hook format string for song/genre name
656664
{
657665
int64_t pattern_offset = _search(data, dllSize, "\x83\xC4\x08\x8B\x44\x24\x50\x50\x68", 9, 0);
658666
if (pattern_offset == -1) {
659-
pattern_offset = _search(data, dllSize, "\x83\xC4\x08\x8B\x44\x24\x4C\x50\x68", 9, 0); //usaneko
667+
pattern_offset = _search(data, dllSize, "\x83\xC4\x08\x8B\x44\x24\x4C\x50\x68", 9, 0); //usaneko or jamfizz+
660668
if (pattern_offset == -1) {
661669
LOG("popnhax: custom_track_title_format: cannot find song/genre print function\n");
662670
return false;
@@ -1217,7 +1225,7 @@ bool patch_custom_categs(const char *dllFilename, struct popnhax_config *config)
12171225
g_customformat = config->custom_track_title_format;
12181226

12191227
if ( g_customformat != NULL )
1220-
patch_custom_track_format(dllFilename);
1228+
patch_custom_track_format(dllFilename, config->game_version);
12211229

12221230
if (config->custom_exclude_from_version)
12231231
LOG("popnhax: Customs excluded from version folders\n"); //musichax_core_init took care of it

0 commit comments

Comments
 (0)