From 1f630edb101543adbe512009b22e3f313f660ad7 Mon Sep 17 00:00:00 2001 From: CrazyRedMachine Date: Wed, 1 May 2024 04:09:11 +0200 Subject: [PATCH] music limit check --- dist/popnhax/popnhax.xml | 6 ++-- popnhax/config.h | 1 + popnhax/dllmain.cc | 78 ++++++++++++++++++++++++++++++++++++---- popnhax/loader.cc | 7 ++-- 4 files changed, 79 insertions(+), 13 deletions(-) diff --git a/dist/popnhax/popnhax.xml b/dist/popnhax/popnhax.xml index fda72de..edb239e 100644 --- a/dist/popnhax/popnhax.xml +++ b/dist/popnhax/popnhax.xml @@ -6,9 +6,9 @@ 0 - 0 + 2 - 0 + 1 0 @@ -140,6 +140,8 @@ 0 0 + + 0 diff --git a/popnhax/config.h b/popnhax/config.h index 83fc3b1..f99e446 100644 --- a/popnhax/config.h +++ b/popnhax/config.h @@ -39,6 +39,7 @@ struct popnhax_config { bool disable_redirection; bool disable_multiboot; bool patch_xml_auto; + bool ignore_music_limit; char patch_xml_filename[MAX_PATH]; char force_datecode[11]; bool network_datecode; diff --git a/popnhax/dllmain.cc b/popnhax/dllmain.cc index c2d8781..64a3587 100644 --- a/popnhax/dllmain.cc +++ b/popnhax/dllmain.cc @@ -203,6 +203,8 @@ PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_STR, struct popnhax_config, custom_track_ti "/popnhax/custom_track_title_format") PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, local_favorites, "/popnhax/local_favorites") +PSMAP_MEMBER_REQ(PSMAP_PROPERTY_TYPE_BOOL, struct popnhax_config, ignore_music_limit, + "/popnhax/ignore_music_limit") PSMAP_END enum BufferIndexes { @@ -1453,12 +1455,36 @@ static bool patch_datecode(char *datecode) { 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; +} + static bool patch_database() { DWORD dllSize = 0; char *data = getDllData(g_game_dll_fn, &dllSize); patch_purelong(); - { int64_t pattern_offset = search(data, dllSize, "\x8D\x44\x24\x10\x88\x4C\x24\x10\x88\x5C\x24\x11\x8D\x50\x01", 15, 0); if (pattern_offset != -1) { @@ -1479,6 +1505,13 @@ static bool patch_database() { SearchFile s; uint8_t *datecode = NULL; bool found = false; + uint32_t music_limit = 0; + if ( !config.ignore_music_limit && !get_music_limit(&music_limit) ) + { + LOG("WARNING: could not retrieve music limit\n"); + } else { + LOG("popnhax: patch_db: music limit : %d\n", music_limit); + } if (config.force_datecode[0] != '\0') { @@ -1487,7 +1520,7 @@ static bool patch_database() { } else { - LOG("popnhax: auto detect patch file from ea3-config\n"); + LOG("popnhax: auto detect patch file with datecode from ea3-config\n"); property *config_xml = load_prop_file("prop/ea3-config.xml"); READ_STR_OPT(config_xml, property_search(config_xml, NULL, "/ea3/soft"), "ext", datecode) free(config_xml); @@ -1505,26 +1538,57 @@ static bool patch_database() { LOG("popnhax: patch_db: found %d xml files in data_mods\n",result.size()); for (uint16_t i=0; iforce_unlocks; - bool is_expansion_allowed = !config->disable_expansions; - bool is_redirection_allowed = !config->disable_redirection; + bool force_unlocks = config->force_unlocks; + bool is_expansion_allowed = !config->disable_expansions; + bool is_redirection_allowed = !config->disable_redirection; if (style_size > fontstyle_table_size) { fontstyle_table_size = style_size;