From 8379b23ec8d24110b146504b24abf4a20eca7332 Mon Sep 17 00:00:00 2001 From: JerryALT Date: Mon, 3 Jun 2024 17:54:41 +0300 Subject: [PATCH] [CommonPatch]: Changed the loading the files from miles. --- src/Components/Modules/CommonPatch.cpp | 57 ++++++++++++++++++++++++++ src/Components/Modules/CommonPatch.hpp | 3 ++ 2 files changed, 60 insertions(+) diff --git a/src/Components/Modules/CommonPatch.cpp b/src/Components/Modules/CommonPatch.cpp index ff074e3..6dac29c 100644 --- a/src/Components/Modules/CommonPatch.cpp +++ b/src/Components/Modules/CommonPatch.cpp @@ -246,6 +246,60 @@ namespace Components TextRenderer::UpdateGameFontsAndText(); } + bool CommonPatch::CheckMilesFiles() + { + if (!Utils::IO::DirectoryExists("iw3sp_data/miles")) + { + MessageBoxA(nullptr, "The 'iw3sp_data/miles' folder does not exist.", nullptr, MB_ICONERROR); + Utils::Library::Terminate(); + return false; + } + + std::vector requiredFiles = + { + "milesEq.flt", + "mssds3d.flt", + "mssdsp.flt", + "msseax.flt", + "mssmp3.asi", + "mssvoice.asi" + }; + + std::filesystem::path basePath = std::filesystem::path(Dvars::Functions::Dvar_FindVar("fs_basepath")->current.string) / "iw3sp_data" / "miles"; + const auto path = (basePath).generic_string(); + const auto files = Utils::IO::ListFiles(path); + + std::vector unexpectedFiles; + for (const auto& file : files) + { + auto fileName = std::filesystem::path(file).filename().string(); + if (std::find(requiredFiles.begin(), requiredFiles.end(), fileName) == requiredFiles.end()) + { + unexpectedFiles.push_back(file); + } + } + + if (!unexpectedFiles.empty()) + { + std::string errorMessage = "In COD4 ROOT iw3sp_data/miles folder was spotted custom .asi files:\n"; + for (const auto& file : unexpectedFiles) + { + errorMessage += file + "\n"; + } + errorMessage += "For run the IW3SP-MOD need remove the above .asi files."; + MessageBoxA(nullptr, errorMessage.c_str(), nullptr, MB_ICONERROR); + Utils::Library::Terminate(); + return false; + } + + return true; + } + + const char* __stdcall CommonPatch::AIL_set_redist_directory_Stub(const char* directory) + { + return Utils::Hook::Call(0x63F7EA)("iw3sp_data/miles"); + } + void CommonPatch::RunModStub() { char mod[260]; @@ -468,6 +522,9 @@ namespace Components Dvars::allowCompactFolderForMod = Dvars::Register::Dvar_RegisterBool("allowCompactFolderForMod", "Enable/Disable compact loading of the mod files.", false, Game::saved); }); + // Change the folder for loading files from miles + Utils::Hook(0x591D15, AIL_set_redist_directory_Stub, HOOK_CALL).install()->quick(); + // Hook for correct works the latched dvars Utils::Hook(0x5F68DB, R_RegisterSunDvarsStub, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/CommonPatch.hpp b/src/Components/Modules/CommonPatch.hpp index 0e5e77e..07ec6aa 100644 --- a/src/Components/Modules/CommonPatch.hpp +++ b/src/Components/Modules/CommonPatch.hpp @@ -24,5 +24,8 @@ namespace Components static void RegisterConColorStub4(); static void RegisterConColorStub5(); static void LanguageSetValueConfig(int langIndex); + + static bool CheckMilesFiles(); + static const char* __stdcall AIL_set_redist_directory_Stub(const char* directory); }; } \ No newline at end of file