From 899f8d27a6ee7006b10e5899fb440c7ab18b179d Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 17 Jul 2022 21:33:07 +0200 Subject: [PATCH] Add overridedvarint & removedvarintoverride --- src/client/component/scripting.cpp | 19 +++++++++++++++++++ src/client/component/scripting.hpp | 2 ++ src/client/game/scripting/lua/context.cpp | 10 ++++++++++ src/client/game/symbols.hpp | 2 ++ 4 files changed, 33 insertions(+) diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index f47559e9..40e7ac62 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -22,6 +22,8 @@ namespace scripting std::unordered_map> script_function_table; utils::concurrency::container shared_table; + std::unordered_map get_dvar_int_overrides; + namespace { utils::hook::detour vm_notify_hook; @@ -79,6 +81,7 @@ namespace scripting void clear_scheduled_notifies() { + get_dvar_int_overrides.clear(); scheduled_notifies.access([](notify_list& list) { list.clear(); @@ -218,6 +221,20 @@ namespace scripting scr_run_current_threads_hook.invoke(); } + + utils::hook::detour scr_get_dvar_int_hook; + void scr_get_dvar_int_stub() + { + const auto dvar = game::Scr_GetString(0); + + if (get_dvar_int_overrides.find(dvar) != get_dvar_int_overrides.end()) + { + game::Scr_AddInt(get_dvar_int_overrides[dvar]); + return; + } + + scr_get_dvar_int_hook.invoke(); + } } class component final : public component_interface @@ -241,6 +258,8 @@ namespace scripting scr_run_current_threads_hook.create(0x1405C8370, scr_run_current_threads_stub); + scr_get_dvar_int_hook.create(0x1404F0730, scr_get_dvar_int_stub); + scheduler::loop([]() { lua::engine::run_frame(); diff --git a/src/client/component/scripting.hpp b/src/client/component/scripting.hpp index 5794bff2..91b4e8a7 100644 --- a/src/client/component/scripting.hpp +++ b/src/client/component/scripting.hpp @@ -8,4 +8,6 @@ namespace scripting extern std::unordered_map> fields_table; extern std::unordered_map> script_function_table; extern utils::concurrency::container shared_table; + + extern std::unordered_map get_dvar_int_overrides; } \ No newline at end of file diff --git a/src/client/game/scripting/lua/context.cpp b/src/client/game/scripting/lua/context.cpp index 2b8eefd7..b16c4dfd 100644 --- a/src/client/game/scripting/lua/context.cpp +++ b/src/client/game/scripting/lua/context.cpp @@ -766,6 +766,16 @@ namespace scripting::lua { localized_strings::override(string, value, true); }; + + game_type["overridedvarint"] = [](const game&, const std::string& dvar, const int value) + { + scripting::get_dvar_int_overrides[dvar] = value; + }; + + game_type["removedvarintoverride"] = [](const game&, const std::string& dvar) + { + scripting::get_dvar_int_overrides.erase(dvar); + }; } } diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index 502cfb05..8b3cd8b5 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -111,6 +111,8 @@ namespace game WEAK symbol Scr_NotifyId{0x1405C8240}; WEAK symbol Scr_GetSelf{0x1405C57C0}; WEAK symbol Scr_ErrorInternal{0x1405C6EC0}; + WEAK symbol Scr_GetString{0x1405C7C20}; + WEAK symbol Scr_AddInt{0x1405C69A0}; WEAK symbol VM_Execute{0x1405C8DB0};