From fccdba87250f383ee2ce2a0132ed164c97b8a867 Mon Sep 17 00:00:00 2001 From: Rex109 Date: Sat, 27 Jul 2024 17:08:12 +0200 Subject: [PATCH] Implemented contitional data, fixed steam auth --- cod4qol/commands.cpp | 21 +++++++++++++-------- cod4qol/game.cpp | 6 +++--- cod4qol/offsets.cpp | 34 +++++++++++++++++++++++++++++++--- cod4qol/offsets.hpp | 16 +++++++++++++--- 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/cod4qol/commands.cpp b/cod4qol/commands.cpp index 15ff4df..626a461 100644 --- a/cod4qol/commands.cpp +++ b/cod4qol/commands.cpp @@ -222,21 +222,26 @@ void commands::ToggleLoadingInfoUpdate() void commands::ToggleSteamAuthUpdate() { - //game::cod4x_entry + 0x1A70A - //game::cod4x_entry + 0x1A717 + static const DWORD steam_auth_a = offsets::GetOffset("steam_auth_a"); + static const DWORD steam_auth_b = offsets::GetOffset("steam_auth_b"); + + static const offsets::data_t steam_auth_a_bytes = offsets::GetData("steam_auth_a"); + static const offsets::data_t steam_auth_b_bytes = offsets::GetData("steam_auth_b"); + + static const offsets::data_t steam_auth_a_bytes_disabled = offsets::GetData("steam_auth_a_disabled"); + static const offsets::data_t steam_auth_b_bytes_disabled = offsets::GetData("steam_auth_b_disabled"); + - /* if (commands::qol_disable_steam_auth->current.enabled) { - hooks::write_addr(game::cod4x_entry + 0x10982, "\x90\x90", 2); - hooks::write_addr(game::cod4x_entry + 0x1098B, "\x90\x90\x90\x90\x90\x90", 6); + hooks::write_addr(steam_auth_a, steam_auth_a_bytes.data.c_str(), steam_auth_a_bytes.size); + hooks::write_addr(steam_auth_b, steam_auth_b_bytes.data.c_str(), steam_auth_b_bytes.size); } else { - hooks::write_addr(game::cod4x_entry + 0x10982, "\x75\x0D", 2); - hooks::write_addr(game::cod4x_entry + 0x1098B, "\x0F\x84\xBF\x01\x00\x00", 6); + hooks::write_addr(steam_auth_a, steam_auth_a_bytes_disabled.data.c_str(), steam_auth_a_bytes_disabled.size); + hooks::write_addr(steam_auth_b, steam_auth_b_bytes_disabled.data.c_str(), steam_auth_b_bytes_disabled.size); } - */ } diff --git a/cod4qol/game.cpp b/cod4qol/game.cpp index 28c27b2..f37af16 100644 --- a/cod4qol/game.cpp +++ b/cod4qol/game.cpp @@ -26,11 +26,11 @@ HMODULE game::GetCurrentModule() bool game::LoadLocalizedIWD(const char* pakfile, const char* basename, const char* gamename) { - static const DWORD iwd_cheat_flag = offsets::GetOffset("iwd_cheat_flag"); + static const DWORD iwd_flag = offsets::GetOffset("iwd_flag"); - hooks::write_addr(iwd_cheat_flag, "\x01", 1); + hooks::write_addr(iwd_flag, "\x01", 1); bool result = FS_AddSingleIwdFileForGameDirectory(pakfile, basename, gamename); - hooks::write_addr(iwd_cheat_flag, "\x00", 1); + hooks::write_addr(iwd_flag, "\x00", 1); return result; } diff --git a/cod4qol/offsets.cpp b/cod4qol/offsets.cpp index 4768a63..d388ea8 100644 --- a/cod4qol/offsets.cpp +++ b/cod4qol/offsets.cpp @@ -5,7 +5,9 @@ #include "game.hpp" #include "defines.hpp" -std::unordered_map offset_map; +std::unordered_map offset_map; +std::unordered_map data_map; + std::string current_crc32; void offsets::InitOffsets() @@ -19,8 +21,10 @@ void offsets::InitOffsets() //General AddOffset("hwnd", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x443BA00)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x43FE9A0)} }); - AddOffset("iwd_cheat_flag", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x2E366)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x386E2)} }); + AddOffset("iwd_flag", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x2E366)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x386E2)} }); AddOffset("ss_switch", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0xB21FB)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0xEA62B)} }); + AddOffset("steam_auth_a", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x10982)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x1A70A)} }); + AddOffset("steam_auth_b", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x1098B)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x1A717)} }); //Functions AddOffset("Cmd_AddCommand_fnc", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x639B0)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x2116C)} }); @@ -29,9 +33,15 @@ void offsets::InitOffsets() AddOffset("Cvar_RegisterEnum", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x60640)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x2DCAF)} }); AddOffset("Cvar_RegisterString", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x60960)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x2D87D)} }); AddOffset("FS_AddSingleIwdFileForGameDirectory", { {COD4QOL_COD4X_CRC32_212, (game::cod4x_entry + 0x2E310)}, {COD4QOL_COD4X_CRC32_211, (game::cod4x_entry + 0x3867C)} }); + + //Strings + AddData("steam_auth_a", { {COD4QOL_COD4X_CRC32_212, {"\x90\x90", 2}}, {COD4QOL_COD4X_CRC32_211, {"\x90\x90\x90\x90\x90\x90", 6}} }); + AddData("steam_auth_b", { {COD4QOL_COD4X_CRC32_212, {"\xE9\xC0\x01\x00\x00\x90", 6}}, {COD4QOL_COD4X_CRC32_211, {"\x90\x90\x90\x90\x90\x90", 6}} }); + AddData("steam_auth_a_disabled", { {COD4QOL_COD4X_CRC32_212, {"\x75\x0D", 2}}, {COD4QOL_COD4X_CRC32_211, {"\x0F\x85\xDB\x00\x00\x00", 6}} }); + AddData("steam_auth_b_disabled", { {COD4QOL_COD4X_CRC32_212, {"\x0F\x84\xBF\x01\x00\x00", 6}}, {COD4QOL_COD4X_CRC32_211, {"\x0F\x85\xCE\x00\x00\x00", 6}} }); } -void offsets::AddOffset(std::string id, offsets::offset offset) +void offsets::AddOffset(std::string id, offsets::offset_set offset) { assert(offset_map.find(id) == offset_map.end()); @@ -50,6 +60,24 @@ DWORD offsets::GetOffset(std::string id) return offset; } +void offsets::AddData(std::string id, offsets::data_set data) +{ + assert(data_map.find(id) == data_map.end()); + + data_map[id] = data; +} + +offsets::data_t offsets::GetData(std::string id) +{ + assert(data_map.find(id) != data_map.end()); + + offsets::data_t data = data_map[id][current_crc32]; + + std::cout << "Requested data for " << id << std::endl; + + return data; +} + void offsets::SetCRC32(std::string crc32) { assert(std::find(supported_cod4x_crc32.begin(), supported_cod4x_crc32.end(), crc32) != supported_cod4x_crc32.end()); diff --git a/cod4qol/offsets.hpp b/cod4qol/offsets.hpp index e75944e..e03ee89 100644 --- a/cod4qol/offsets.hpp +++ b/cod4qol/offsets.hpp @@ -5,10 +5,20 @@ namespace offsets { - typedef std::unordered_map offset; + typedef std::unordered_map offset_set; + + typedef struct + { + std::string data; + size_t size; + }data_t; + + typedef std::unordered_map data_set; void InitOffsets(); - void AddOffset(std::string name, offsets::offset offset); - DWORD GetOffset(std::string name); + void AddOffset(std::string id, offset_set offset); + DWORD GetOffset(std::string id); + void AddData(std::string id, data_set data); + data_t GetData(std::string id); void SetCRC32(std::string crc32); } \ No newline at end of file