Merge pull request #717 from diamante0018/main

feat: custom players folder
This commit is contained in:
Maurice Heumann 2023-05-16 20:30:50 +02:00 committed by GitHub
commit c808ead05c
9 changed files with 97 additions and 10 deletions

View File

@ -4,7 +4,9 @@
#include "scheduler.hpp"
#include <game/game.hpp>
#include <utils/hook.hpp>
#include <utils/io.hpp>
#include <mmeapi.h>
@ -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<void>(0x1422A2AF0_g, path, "boiii_players");
}
// TODO: Remove me after some time
void migrate_if_needed()
{
std::error_code e;
// Folder does not exist. Nothing to migrate
if (!std::filesystem::is_directory("players", e))
{
return;
}
// Folder does exist. 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<uint8_t>(0x14134762E_g, 0xEB); // ^^
utils::hook::call(0x1413477EE_g, fs_f_open_file_write_to_dir_stub); // ??
utils::hook::set<uint8_t>(0x1413477CD_g, 0xEB); // ^^
utils::hook::call(0x141C20A1F_g, fs_f_open_file_write_to_dir_stub); // ??
utils::hook::set<uint8_t>(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<uint8_t>(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<uint8_t>(0x14228F5DC_g, 0xEB);
patch_players_folder_name();
}
};
}

View File

@ -1,8 +1,8 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include <game/game.hpp>
#include <game/utils.hpp>
#include "game/game.hpp"
#include "game/utils.hpp"
#include "scheduler.hpp"
#include "getinfo.hpp"
#include "console.hpp"

View File

@ -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)

View File

@ -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);
}

View File

@ -25,7 +25,7 @@ namespace profile_infos
std::optional<profile_info> 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<const char*>(&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

View File

@ -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()

View File

@ -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

View File

@ -634,6 +634,8 @@ namespace game
void* errorData;
};
typedef void* fileHandle_t;
typedef uint32_t dvarStrHash_t;
enum dvarType_t

View File

@ -232,6 +232,12 @@ namespace game
// FS
WEAK symbol<char*(int bytes)> FS_AllocMem{0x1422AC9F0, 0x14056C340};
WEAK symbol<fileHandle_t(const char* filename, const char* dir, const char* osbasepath)> FS_FOpenFileWriteToDir{
0x1422A35D0
};
WEAK symbol<fileHandle_t(const char* filename, const char* dir, const char* osbasepath)> FS_FOpenFileReadFromDir{
0x1422A3510
};
// Lobby
WEAK symbol<int(LobbyType lobbyType, LobbyClientType clientType)> LobbyHost_GetClientCount{
@ -240,6 +246,7 @@ namespace game
// Utils
WEAK symbol<const char*(char* str)> I_CleanStr{0x1422E9050, 0x140580E80};
WEAK symbol<int(const char* s0, const char* s1)> I_stricmp{0x1422E9530};
WEAK symbol<void(char* dest, size_t destsize, const char* src)> I_strcpy{
0x1422E9410, 0x1405811E0
};