From 07be47bbba0d6e04e51c33f22df761916415dbdb Mon Sep 17 00:00:00 2001 From: aixxe Date: Wed, 1 May 2024 15:37:32 +0100 Subject: [PATCH 1/2] Refactor SECOND_DLL_FOR to allow more than one additional DLL --- overlay/windows/patch_manager.cpp | 144 +++++++++--------------------- 1 file changed, 41 insertions(+), 103 deletions(-) diff --git a/overlay/windows/patch_manager.cpp b/overlay/windows/patch_manager.cpp index d77421c..b37264a 100644 --- a/overlay/windows/patch_manager.cpp +++ b/overlay/windows/patch_manager.cpp @@ -55,26 +55,26 @@ namespace overlay::windows { std::string ACTIVE_JSON_FILE(""); - std::map SECOND_DLL_FOR = { - {"jubeat.dll", "music_db.dll"}, - {"arkmdxp3.dll", "gamemdx.dll"}, - {"arkmdxp4.dll", "gamemdx.dll"}, - {"arkmdxbio2.dl", "gamemdx.dll"}, - {"arkndd.dll", "gamendd.dll"}, - {"arkkep.dll", "game.dll"}, - {"arkjc9.dll", "gamejc9.dll"}, - {"arkkdm.dll", "gamekdm.dll"}, - {"arkmmd.dll", "gamemmd.dll"}, - {"arkklp.dll", "lpac.dll"}, - {"arknck.dll", "weac.dll"}, - {"gdxg.dll", "game.dll"} + std::map> EXTRA_DLLS = { + {"jubeat.dll", {"music_db.dll", "coin.dll"}}, + {"arkmdxp3.dll", {"gamemdx.dll"}}, + {"arkmdxp4.dll", {"gamemdx.dll"}}, + {"arkmdxbio2.dl", {"gamemdx.dll"}}, + {"arkndd.dll", {"gamendd.dll"}}, + {"arkkep.dll", {"game.dll"}}, + {"arkjc9.dll", {"gamejc9.dll"}}, + {"arkkdm.dll", {"gamekdm.dll"}}, + {"arkmmd.dll", {"gamemmd.dll"}}, + {"arkklp.dll", {"lpac.dll"}}, + {"arknck.dll", {"weac.dll"}}, + {"gdxg.dll", {"game.dll"}} }; - std::string getSecondDll(const std::string& firstDll) { - if (SECOND_DLL_FOR.find(firstDll) == SECOND_DLL_FOR.end()) { - return ""; + std::vector getExtraDlls(const std::string& firstDll) { + if (!EXTRA_DLLS.contains(firstDll)) { + return {}; } - return SECOND_DLL_FOR[firstDll]; + return EXTRA_DLLS[firstDll]; } // utility @@ -203,55 +203,10 @@ namespace overlay::windows { identifiers += avs::game::get_identifier() + "\n\n"; identifiers += avs::game::DLL_NAME + " / " + get_game_identifier((MODULE_PATH / avs::game::DLL_NAME).string()) + "\n"; - if (avs::game::DLL_NAME == "jubeat.dll") { - std::string music_db_path = (MODULE_PATH / "music_db.dll").string(); - if (fileutils::file_exists(music_db_path)) { - identifiers += "music_db.dll / " + get_game_identifier(music_db_path) + "\n"; - } - } else if (avs::game::DLL_NAME == "arkmdxp3.dll" || avs::game::DLL_NAME == "arkmdxp4.dll" || avs::game::DLL_NAME == "arkmdxbio2.dll") { - std::string gamemdx_path = (MODULE_PATH / "gamemdx.dll").string(); - if (fileutils::file_exists(gamemdx_path)) { - identifiers += "gamemdx.dll / " + get_game_identifier(gamemdx_path) + "\n"; - } - } else if (avs::game::DLL_NAME == "arkndd.dll") { - std::string gamendd_path = (MODULE_PATH / "gamendd.dll").string(); - if (fileutils::file_exists(gamendd_path)) { - identifiers += "gamendd.dll / " + get_game_identifier(gamendd_path) + "\n"; - } - } else if (avs::game::DLL_NAME == "arkkep.dll") { - std::string game_path = (MODULE_PATH / "game.dll").string(); - if (fileutils::file_exists(game_path)) { - identifiers += "game.dll / " + get_game_identifier(game_path) + "\n"; - } - } else if (avs::game::DLL_NAME == "arkjc9.dll") { - std::string gamejc9_path = (MODULE_PATH / "gamejc9.dll").string(); - if (fileutils::file_exists(gamejc9_path)) { - identifiers += "gamejc9.dll / " + get_game_identifier(gamejc9_path) + "\n"; - } - } else if (avs::game::DLL_NAME == "arkkdm.dll") { - std::string gamekdm_path = (MODULE_PATH / "gamekdm.dll").string(); - if (fileutils::file_exists(gamekdm_path)) { - identifiers += "gamekdm.dll / " + get_game_identifier(gamekdm_path) + "\n"; - } - } else if (avs::game::DLL_NAME == "arkmmd.dll") { - std::string gamemmd_path = (MODULE_PATH / "gamemmd.dll").string(); - if (fileutils::file_exists(gamemmd_path)) { - identifiers += "gamemmd.dll / " + get_game_identifier(gamemmd_path) + "\n"; - } - } else if (avs::game::DLL_NAME == "arkklp.dll") { - std::string lpac_path = (MODULE_PATH / "lpac.dll").string(); - if (fileutils::file_exists(lpac_path)) { - identifiers += "lpac.dll / " + get_game_identifier(lpac_path) + "\n"; - } - } else if (avs::game::DLL_NAME == "arknck.dll") { - std::string weac_path = (MODULE_PATH / "weac.dll").string(); - if (fileutils::file_exists(weac_path)) { - identifiers += "weac.dll / " + get_game_identifier(weac_path) + "\n"; - } - } else if (avs::game::DLL_NAME == "gdxg.dll") { - std::string game_path = (MODULE_PATH / "game.dll").string(); - if (fileutils::file_exists(game_path)) { - identifiers += "game.dll / " + get_game_identifier(game_path) + "\n"; + for (const auto& dll : getExtraDlls(avs::game::DLL_NAME)) { + std::string dll_path = (MODULE_PATH / dll).string(); + if (fileutils::file_exists(dll_path)) { + identifiers += dll + " / " + get_game_identifier(dll_path) + "\n"; } } @@ -1257,13 +1212,14 @@ namespace overlay::windows { bool PatchManager::load_from_new_patches_json(bool apply_patches) { bool ret = false; std::string firstDll = avs::game::DLL_NAME; - std::string secondDll = getSecondDll(firstDll); + auto extraDlls = getExtraDlls(firstDll); const size_t old_patches_size = patches.size(); - auto filter = [&firstDll, &secondDll](const PatchData& patch_data) { + auto filter = [&firstDll, &extraDlls](const PatchData& patch_data) { return patch_data.peIdentifier == get_game_identifier((MODULE_PATH / firstDll).string()) || - (!secondDll.empty() && patch_data.peIdentifier == get_game_identifier((MODULE_PATH / secondDll).string())); + std::ranges::any_of(extraDlls, [&patch_data](const std::string& dll) + { return patch_data.peIdentifier == get_game_identifier((MODULE_PATH / dll).string()); }); }; // possible locations of new format (PE header ID) JSON patches @@ -1349,29 +1305,29 @@ namespace overlay::windows { std::string first_id = get_game_identifier((MODULE_PATH / firstDll).string()); std::filesystem::path firstPath = fmt::format("patches/{}.json", first_id); - std::string secondDll = getSecondDll(firstDll); - std::string second_id = ""; - std::filesystem::path secondPath; - if (!secondDll.empty()) { - second_id = get_game_identifier((MODULE_PATH / secondDll).string()); - secondPath = fmt::format("patches/{}.json", second_id); - } + auto extraDlls = getExtraDlls(firstDll); + std::erase_if(extraDlls, [](const std::string& dll) { + auto identifier = get_game_identifier((MODULE_PATH / dll).string()); + return identifier.empty() || !fileutils::file_exists(fmt::format("patches/{}.json", identifier)); + }); - if (fileutils::file_exists(firstPath) || (!secondDll.empty() && fileutils::file_exists(secondPath))) { + if (fileutils::file_exists(firstPath) || !extraDlls.empty()) { if (fileutils::file_exists(firstPath)) { log_info("patchmanager", "loaded patches for {} from {}", firstDll, firstPath.string()); std::string content = fileutils::text_read(firstPath); append_patches(content, apply_patches, nullptr, first_id); ACTIVE_JSON_FILE = firstPath.string(); } - if (!secondDll.empty() && fileutils::file_exists(secondPath)) { - log_info("patchmanager", "loaded patches for {} from {}", secondDll, secondPath.string()); - std::string content = fileutils::text_read(secondPath); - append_patches(content, apply_patches, nullptr, second_id); + for (const std::string& dll : extraDlls) { + auto extraId = get_game_identifier((MODULE_PATH / dll).string()); + auto extraPath = std::filesystem::path(fmt::format("patches/{}.json", extraId)); + log_info("patchmanager", "loaded patches for {} from {}", dll, extraPath.string()); + std::string content = fileutils::text_read(extraPath); + append_patches(content, apply_patches, nullptr, extraId); if (ACTIVE_JSON_FILE.empty()) { - ACTIVE_JSON_FILE = secondPath.string(); + ACTIVE_JSON_FILE = extraPath.string(); } else { - ACTIVE_JSON_FILE += ", " + secondPath.string(); + ACTIVE_JSON_FILE += ", " + extraPath.string(); } } } else if (load_from_new_patches_json(apply_patches)) { @@ -1396,26 +1352,8 @@ namespace overlay::windows { import_remote_patches_for_dll(patch_url, avs::game::DLL_NAME); // check for additional patches based on module name - if (avs::game::DLL_NAME == "jubeat.dll") { - import_remote_patches_for_dll(patch_url, "music_db.dll"); - } else if (avs::game::DLL_NAME == "arkmdxp3.dll" || avs::game::DLL_NAME == "arkmdxp4.dll" || avs::game::DLL_NAME == "arkmdxbio2.dll") { - import_remote_patches_for_dll(patch_url, "gamemdx.dll"); - } else if (avs::game::DLL_NAME == "arkndd.dll") { - import_remote_patches_for_dll(patch_url, "gamendd.dll"); - } else if (avs::game::DLL_NAME == "arkkep.dll") { - import_remote_patches_for_dll(patch_url, "game.dll"); - } else if (avs::game::DLL_NAME == "arkjc9.dll") { - import_remote_patches_for_dll(patch_url, "gamejc9.dll"); - } else if (avs::game::DLL_NAME == "arkkdm.dll") { - import_remote_patches_for_dll(patch_url, "gamekdm.dll"); - } else if (avs::game::DLL_NAME == "arkmmd.dll") { - import_remote_patches_for_dll(patch_url, "gamemmd.dll"); - } else if (avs::game::DLL_NAME == "arkklp.dll") { - import_remote_patches_for_dll(patch_url, "lpac.dll"); - } else if (avs::game::DLL_NAME == "arknck.dll") { - import_remote_patches_for_dll(patch_url, "weac.dll"); - } else if (avs::game::DLL_NAME == "gdxg.dll") { - import_remote_patches_for_dll(patch_url, "game.dll"); + for (const std::string& dll : getExtraDlls(avs::game::DLL_NAME)) { + import_remote_patches_for_dll(patch_url, dll); } patches_initialized = true; -- 2.44.0.windows.1