From 11ee17f48b76b25503604b10634a59b0a00e3797 Mon Sep 17 00:00:00 2001 From: CrazyRedMachine Date: Wed, 1 May 2024 05:36:04 +0200 Subject: [PATCH] force_datecode auto --- popnhax/dllmain.cc | 114 +++++++++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 35 deletions(-) diff --git a/popnhax/dllmain.cc b/popnhax/dllmain.cc index f0af649..ef34705 100644 --- a/popnhax/dllmain.cc +++ b/popnhax/dllmain.cc @@ -1411,10 +1411,78 @@ static bool patch_purelong() return true; } +static bool get_music_limit(uint32_t* limit) { + DWORD dllSize = 0; + char *data = getDllData(g_game_dll_fn, &dllSize); + + { + int64_t string_loc = search(data, dllSize, "Illegal music no %d", 19, 0); + if (string_loc == -1) { + LOG("popnhax: patch_db: could not retrieve music limit error string\n"); + return false; + } + + string_loc += 0x10000000; //entrypoint + char *as_hex = (char *) &string_loc; + int64_t pattern_offset = search(data, dllSize, as_hex, 4, 0); + if (pattern_offset == -1) { + LOG("popnhax: patch_db: could not retrieve music limit test function\n"); + return false; + } + + uint64_t patch_addr = (int64_t)data + pattern_offset - 0x1F; + *limit = *(uint32_t*)patch_addr; + } + return true; +} + +char *get_datecode_from_patches() { + SearchFile s; + char datecode[11] = {0}; + uint32_t music_limit = 0; + if ( !get_music_limit(&music_limit) ) + { + LOG("WARNING: could not retrieve music limit for datecode_auto\n"); + return NULL; + } + + s.search("data_mods", "xml", false); + auto result = s.getResult(); + + for (uint16_t i=0; i