From 2360a29bcfff8dbeac34565c53ff8a43fb7bcb7f Mon Sep 17 00:00:00 2001 From: FutureRave Date: Fri, 3 Feb 2023 01:13:35 +0000 Subject: [PATCH] add back warning --- src/game/game.cpp | 4 ++ src/game/game.hpp | 2 + src/main.cpp | 2 +- src/module/fastfiles.cpp | 2 +- src/module/patches.cpp | 90 ++++++++++++++++++++++++++++++---------- 5 files changed, 76 insertions(+), 24 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 91a333a..6d1748e 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -145,6 +145,8 @@ namespace game float* com_codeTimeScale; + int* com_frameTime; + RTL_CRITICAL_SECTION* s_criticalSection; int* logfile; @@ -873,6 +875,8 @@ namespace game native::com_codeTimeScale = reinterpret_cast(SELECT_VALUE(0x1769F1C, 0x1CEF554)); + native::com_frameTime = reinterpret_cast(SELECT_VALUE(0x0, 0x1CF0B88)); + native::s_criticalSection = reinterpret_cast(SELECT_VALUE(0x1CD5638, 0x5A91048)); native::logfile = reinterpret_cast(SELECT_VALUE(0x176B534, 0x1CF0B78)); diff --git a/src/game/game.hpp b/src/game/game.hpp index d2fbb04..3f48a4e 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -278,6 +278,8 @@ namespace game extern float* com_codeTimeScale; + extern int* com_frameTime; + extern RTL_CRITICAL_SECTION* s_criticalSection; extern int* logfile; diff --git a/src/main.cpp b/src/main.cpp index 1d2acf6..b64ec17 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -90,7 +90,7 @@ int main() FARPROC entry_point; enable_dpi_awareness(); - std::srand(uint32_t(time(nullptr))); + std::srand(static_cast(time(nullptr)) ^ ~(GetTickCount() * GetCurrentProcessId())); { auto premature_shutdown = true; diff --git a/src/module/fastfiles.cpp b/src/module/fastfiles.cpp index 0963fea..8639399 100644 --- a/src/module/fastfiles.cpp +++ b/src/module/fastfiles.cpp @@ -29,7 +29,7 @@ namespace void dump_gsc_script(const std::string& name, game::native::XAssetHeader header) { - if (g_dump_scripts->current.enabled) + if (!g_dump_scripts->current.enabled) { return; } diff --git a/src/module/patches.cpp b/src/module/patches.cpp index 47a672f..6f7d752 100644 --- a/src/module/patches.cpp +++ b/src/module/patches.cpp @@ -4,6 +4,70 @@ #include +#include "console.hpp" + +namespace +{ + __declspec(noreturn) void long_jump_stub(jmp_buf buf, const int value) noexcept(false) + { +#ifdef _DEBUG + { + printf("Unwinding the stack...\n"); + } +#endif + + longjmp(buf, value); + } + + const game::native::dvar_t* dvar_register_com_max_fps(const char* dvarName, int value, + int min, int /*max*/, unsigned __int16 /*flags*/, const char* description) + { + return game::native::Dvar_RegisterInt(dvarName, value, min, 1000, game::native::DVAR_ARCHIVE, description); + } + + const char* live_get_local_client_name_stub() + { + return game::native::Dvar_FindVar("name")->current.string; + } + + void com_clamp_msec(const int msec) + { + if (msec > 500 && msec < 500000) + { + console::warn("Hitch warning: %i msec frame time\n", msec); + } + } + + __declspec(naked) void com_clamp_msec_stub() + { + using namespace game::native; + + __asm + { + pushad + + push esi + call com_clamp_msec + add esp, 0x4 + + popad + + // Game's code + cmp esi, eax + jle label_5565DA + + mov esi, eax + + push 0x5565D6 + ret + + label_5565DA: + push 0x5565DA + ret + } + } +} + class patches final : public module { public: @@ -56,6 +120,10 @@ private: utils::hook(0x5C9980, &live_get_local_client_name_stub, HOOK_JUMP).install()->quick(); + // Add back warning + utils::hook(0x5565D0, &com_clamp_msec_stub, HOOK_JUMP).install()->quick(); // Com_Frame_Try_Block_Function + utils::hook::nop(0x5565D0 + 5, 1); + // Unpure client detected utils::hook::set(0x57228C, 0xEB); @@ -76,28 +144,6 @@ private: utils::hook::nop(0x47EB9D, 5); utils::hook::nop(0x47EBC9, 5); } - - static __declspec(noreturn) void long_jump_stub(jmp_buf buf, const int value) noexcept(false) - { -#ifdef _DEBUG - { - printf("Unwinding the stack...\n"); - } -#endif - - longjmp(buf, value); - } - - static const game::native::dvar_t* dvar_register_com_max_fps(const char* dvarName, int value, - int min, int /*max*/, unsigned __int16 /*flags*/, const char* description) - { - return game::native::Dvar_RegisterInt(dvarName, value, min, 1000, game::native::DVAR_ARCHIVE, description); - } - - static const char* live_get_local_client_name_stub() - { - return game::native::Dvar_FindVar("name")->current.string; - } }; REGISTER_MODULE(patches)