From 7e5e8221264a1b8271bfea8c85d347f968a9be5c Mon Sep 17 00:00:00 2001 From: FutureRave Date: Tue, 16 May 2023 19:16:20 +0100 Subject: [PATCH 1/2] feat: migrate from players to boiii_players folder --- src/client/component/client_patches.cpp | 82 ++++++++++++++++++- src/client/component/dedicated_info.cpp | 4 +- src/client/component/dvars.cpp | 2 +- src/client/component/patches.cpp | 2 +- src/client/component/profile_infos.cpp | 4 +- src/client/component/server_list.cpp | 2 +- .../game/demonware/services/bdStorage.cpp | 2 +- src/client/game/structs.hpp | 2 + src/client/game/symbols.hpp | 7 ++ 9 files changed, 97 insertions(+), 10 deletions(-) diff --git a/src/client/component/client_patches.cpp b/src/client/component/client_patches.cpp index f8a9a9b5..7f7f89c1 100644 --- a/src/client/component/client_patches.cpp +++ b/src/client/component/client_patches.cpp @@ -4,7 +4,9 @@ #include "scheduler.hpp" #include + #include +#include #include @@ -37,11 +39,11 @@ namespace client_patches }, scheduler::main, 15s); } - void preload_map_stub(int localClientNum, const char* mapname, const char* gametype) + void preload_map_stub(int local_client_num, const char* mapname, const char* gametype) { game::Com_GametypeSettings_SetGametype(gametype, true); stop_intro_if_needed(); - preload_map_hook.invoke(localClientNum, mapname, gametype); + preload_map_hook.invoke(local_client_num, mapname, gametype); } void reduce_process_affinity() @@ -107,11 +109,85 @@ namespace client_patches utils::hook::call(address, is_mod_loaded_stub); } } + + game::fileHandle_t fs_f_open_file_write_to_dir_stub(const char* filename, [[maybe_unused]] const char* dir, + const char* os_base_path) + { + return game::FS_FOpenFileWriteToDir(filename, "boiii_players", os_base_path); + } + + game::fileHandle_t fs_f_open_file_read_from_dir_stub(const char* filename, [[maybe_unused]] const char* dir, + const char* os_base_path) + { + return game::FS_FOpenFileReadFromDir(filename, "boiii_players", os_base_path); + } + + int i_stricmp_stub(const char* s0, [[maybe_unused]] const char* s1) + { + return game::I_stricmp(s0, "boiii_players"); + } + + void fs_add_game_directory_stub(const char* path, [[maybe_unused]] const char* dir) + { + utils::hook::invoke(0x1422A2AF0_g, path, "boiii_players"); + } + + // TODO: Remove me after some time + void migrate_if_needed() + { + std::error_code e; + + // Folder does not exists. Nothing to migrate + if (!std::filesystem::is_directory("players", e)) + { + return; + } + + // Folder does exists. Already migrated + if (std::filesystem::is_directory("boiii_players", e)) + { + return; + } + + utils::io::create_directory("boiii_players"); + + std::filesystem::copy("players", "boiii_players", std::filesystem::copy_options::recursive, e); + } + + void patch_players_folder_name() + { + // Override 'players' folder + utils::hook::call(0x14134764F_g, fs_f_open_file_write_to_dir_stub); // ?? + utils::hook::set(0x14134762E_g, 0xEB); // ^^ + + utils::hook::call(0x1413477EE_g, fs_f_open_file_write_to_dir_stub); // ?? + utils::hook::set(0x1413477CD_g, 0xEB); // ^^ + + utils::hook::call(0x141C20A1F_g, fs_f_open_file_write_to_dir_stub); // ?? + utils::hook::set(0x141C209FE_g, 0xEB); // ^^ + + utils::hook::call(0x1422F391E_g, fs_f_open_file_write_to_dir_stub); // ?? + + utils::hook::call(0x141C2090F_g, fs_f_open_file_read_from_dir_stub); // ?? + utils::hook::set(0x141C208EE_g, 0xEB); // ^^ + + utils::hook::call(0x1422F3773_g, fs_f_open_file_read_from_dir_stub); // ?? + + utils::hook::call(0x1422A2A61_g, i_stricmp_stub); // ?? + utils::hook::call(0x1422A2C82_g, i_stricmp_stub); // FS_AddGameDirectory + + utils::hook::call(0x1422A45A4_g, fs_add_game_directory_stub); // FS_Startup + } } class component final : public client_component { public: + component() + { + migrate_if_needed(); // TODO: Remove me after some time + } + void post_unpack() override { fix_amd_cpu_stuttering(); @@ -133,6 +209,8 @@ namespace client_patches // Always get loadscreen gametype from s_gametype utils::hook::set(0x14228F5DC_g, 0xEB); + + patch_players_folder_name(); } }; } diff --git a/src/client/component/dedicated_info.cpp b/src/client/component/dedicated_info.cpp index 95089a2d..df37929c 100644 --- a/src/client/component/dedicated_info.cpp +++ b/src/client/component/dedicated_info.cpp @@ -1,8 +1,8 @@ #include #include "loader/component_loader.hpp" +#include +#include -#include "game/game.hpp" -#include "game/utils.hpp" #include "scheduler.hpp" #include "getinfo.hpp" #include "console.hpp" diff --git a/src/client/component/dvars.cpp b/src/client/component/dvars.cpp index c6e7ee38..16fde569 100644 --- a/src/client/component/dvars.cpp +++ b/src/client/component/dvars.cpp @@ -104,7 +104,7 @@ namespace dvars std::string get_config_file_path() { - return "players/user/config.cfg"; + return "boiii_players/user/config.cfg"; } bool is_archive_dvar(const game::dvar_t* dvar) diff --git a/src/client/component/patches.cpp b/src/client/component/patches.cpp index 2407d3ff..e9842c11 100644 --- a/src/client/component/patches.cpp +++ b/src/client/component/patches.cpp @@ -20,7 +20,7 @@ namespace patches { va_list ap; va_start(ap, fmt); - vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap); + vsnprintf_s(buffer, _TRUNCATE, fmt, ap); va_end(ap); } diff --git a/src/client/component/profile_infos.cpp b/src/client/component/profile_infos.cpp index e1faf09e..9edd3bb7 100644 --- a/src/client/component/profile_infos.cpp +++ b/src/client/component/profile_infos.cpp @@ -25,7 +25,7 @@ namespace profile_infos std::optional load_profile_info() { std::string data{}; - if (!utils::io::read_file("players/user/profile_info", &data)) + if (!utils::io::read_file("boiii_players/user/profile_info", &data)) { return {}; } @@ -237,7 +237,7 @@ namespace profile_infos data.append(reinterpret_cast(&info.version), sizeof(info.version)); data.append(info.ddl); - utils::io::write_file("players/user/profile_info", data); + utils::io::write_file("boiii_players/user/profile_info", data); } struct component final : generic_component diff --git a/src/client/component/server_list.cpp b/src/client/component/server_list.cpp index 174e7c6a..f7cae3d5 100644 --- a/src/client/component/server_list.cpp +++ b/src/client/component/server_list.cpp @@ -93,7 +93,7 @@ namespace server_list std::string get_favorite_servers_file_path() { - return "players/user/favorite_servers.txt"; + return "boiii_players/user/favorite_servers.txt"; } void write_favorite_servers() diff --git a/src/client/game/demonware/services/bdStorage.cpp b/src/client/game/demonware/services/bdStorage.cpp index 165e724d..487a5b89 100644 --- a/src/client/game/demonware/services/bdStorage.cpp +++ b/src/client/game/demonware/services/bdStorage.cpp @@ -173,7 +173,7 @@ namespace demonware std::string bdStorage::get_user_file_path(const std::string& name) { - return "players/user/" + name; + return "boiii_players/user/" + name; } void bdStorage::upload_files(service_server* server, byte_buffer* buffer) const diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index 2f80831c..a6b94825 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -634,6 +634,8 @@ namespace game void* errorData; }; + typedef void* fileHandle_t; + typedef uint32_t dvarStrHash_t; enum dvarType_t diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index be4d20cd..69248c4f 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -232,6 +232,12 @@ namespace game // FS WEAK symbol FS_AllocMem{0x1422AC9F0, 0x14056C340}; + WEAK symbol FS_FOpenFileWriteToDir{ + 0x1422A35D0 + }; + WEAK symbol FS_FOpenFileReadFromDir{ + 0x1422A3510 + }; // Lobby WEAK symbol LobbyHost_GetClientCount{ @@ -240,6 +246,7 @@ namespace game // Utils WEAK symbol I_CleanStr{0x1422E9050, 0x140580E80}; + WEAK symbol I_stricmp{0x1422E9530}; WEAK symbol I_strcpy{ 0x1422E9410, 0x1405811E0 }; From 36b979494c2c3bda0999fbf8c53fdf6a06e703e5 Mon Sep 17 00:00:00 2001 From: Edo Date: Tue, 16 May 2023 19:23:02 +0100 Subject: [PATCH 2/2] fix(client_patches): my non-existent grammar --- src/client/component/client_patches.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/component/client_patches.cpp b/src/client/component/client_patches.cpp index 7f7f89c1..0f2227db 100644 --- a/src/client/component/client_patches.cpp +++ b/src/client/component/client_patches.cpp @@ -137,13 +137,13 @@ namespace client_patches { std::error_code e; - // Folder does not exists. Nothing to migrate + // Folder does not exist. Nothing to migrate if (!std::filesystem::is_directory("players", e)) { return; } - // Folder does exists. Already migrated + // Folder does exist. Already migrated if (std::filesystem::is_directory("boiii_players", e)) { return;