From b7423d81095c542bdfe06ffaa535be70f40c043a Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 28 Feb 2022 21:18:27 +0100 Subject: [PATCH] Add dvar & flag to disable shader caching --- src/client/component/console.cpp | 2 ++ src/client/component/dvars.cpp | 26 +++++++++++++++++ src/client/component/dvars.hpp | 1 + src/client/component/shaders.cpp | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 src/client/component/shaders.cpp diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index dd9b7e1e..557f47b5 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -105,8 +105,10 @@ namespace console this->console_thread_.join(); } +#ifndef NATIVE_CONSOLE _close(this->handles_[0]); _close(this->handles_[1]); +#endif messages.access([&](message_queue& msgs) { diff --git a/src/client/component/dvars.cpp b/src/client/component/dvars.cpp index d8221d67..1f46d4db 100644 --- a/src/client/component/dvars.cpp +++ b/src/client/component/dvars.cpp @@ -144,6 +144,7 @@ namespace dvars static std::unordered_map set_float_overrides; static std::unordered_map set_int_overrides; static std::unordered_map set_string_overrides; + static std::unordered_map set_from_string_overrides; void register_bool(const std::string& name, const bool value, const unsigned int flags) { @@ -228,6 +229,11 @@ namespace dvars { set_string_overrides[name] = value; } + + void set_from_string(const std::string& name, const std::string& value) + { + set_from_string_overrides[name] = value; + } } utils::hook::detour dvar_register_bool_hook; @@ -241,6 +247,7 @@ namespace dvars utils::hook::detour dvar_set_float_hook; utils::hook::detour dvar_set_int_hook; utils::hook::detour dvar_set_string_hook; + utils::hook::detour dvar_set_from_string_hook; game::dvar_t* dvar_register_bool(const int hash, const char* name, bool value, unsigned int flags) { @@ -395,6 +402,24 @@ namespace dvars return dvar_set_string_hook.invoke(dvar, string); } + void dvar_set_from_string(game::dvar_t* dvar, const char* string, game::DvarSetSource source) + { + const auto disabled = find_dvar(disable::set_string_disables, dvar->hash); + if (disabled) + { + return; + } + + auto* var = find_dvar(override::set_from_string_overrides, dvar->hash); + if (var) + { + printf("fucker\n"); + string = var->data(); + } + + return dvar_set_from_string_hook.invoke(dvar, string, source); + } + class component final : public component_interface { public: @@ -411,6 +436,7 @@ namespace dvars dvar_set_float_hook.create(SELECT_VALUE(0x1403C7420, 0x1404FD360), &dvar_set_float); dvar_set_int_hook.create(SELECT_VALUE(0x1403C76C0, 0x1404FD5E0), &dvar_set_int); dvar_set_string_hook.create(SELECT_VALUE(0x1403C7900, 0x1404FD8D0), &dvar_set_string); + dvar_set_from_string_hook.create(SELECT_VALUE(0, 0x1404FD520), &dvar_set_from_string); } }; } diff --git a/src/client/component/dvars.hpp b/src/client/component/dvars.hpp index 057c4d1b..66d6912d 100644 --- a/src/client/component/dvars.hpp +++ b/src/client/component/dvars.hpp @@ -23,5 +23,6 @@ namespace dvars void set_float(const std::string& name, float fl); void set_int(const std::string& name, int integer); void set_string(const std::string& name, const std::string& string); + void set_from_string(const std::string& name, const std::string& value); } } diff --git a/src/client/component/shaders.cpp b/src/client/component/shaders.cpp new file mode 100644 index 00000000..ec632115 --- /dev/null +++ b/src/client/component/shaders.cpp @@ -0,0 +1,50 @@ +#include +#include "loader/component_loader.hpp" + +#include "scheduler.hpp" +#include "dvars.hpp" + +#include "game/game.hpp" +#include "game/dvars.hpp" + +#include +#include +#include + +namespace shaders +{ + namespace + { + game::dvar_t* disable_shader_caching = nullptr; + + bool shader_should_show_dialog_stub() + { + return !disable_shader_caching->current.enabled; + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + if (!game::environment::is_mp()) + { + return; + } + + const auto has_flag = utils::flags::has_flag("noshadercaching"); + + disable_shader_caching = dvars::register_bool("disable_shader_caching", has_flag, game::DVAR_FLAG_SAVED, true); + if (has_flag) + { + dvars::override::set_bool("disable_shader_caching", 1); + dvars::override::set_from_string("disable_shader_caching", "1"); + } + + utils::hook::jump(0x14007E710, shader_should_show_dialog_stub); + } + }; +} + +REGISTER_COMPONENT(shaders::component)