From b4a04d6346d10f18ce0560c5a317b9bc6fa8c16b Mon Sep 17 00:00:00 2001 From: Emmanuel AYME Date: Mon, 5 Jan 2026 21:16:02 +0100 Subject: [PATCH] Add cheat toggle function --- includes/OSDManager.h | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/includes/OSDManager.h b/includes/OSDManager.h index f2e2aea..1ba1daf 100644 --- a/includes/OSDManager.h +++ b/includes/OSDManager.h @@ -2,10 +2,15 @@ #include #include +#include "GameFixes.h" +constexpr auto OSD_SHADER_NAME = "OSD.fx"; using OSDUpdateFn = std::function; using OSDEndFn = std::function; +extern void SetFixesEnabled(GameFixes fix, bool value); +extern void SaveSettings(); + /** * @brief Displays an On-Screen Display (OSD) for a specified duration. * @@ -23,7 +28,6 @@ using OSDEndFn = std::function; */ void ShowOSD(float duration, OSDUpdateFn onUpdate, OSDEndFn onEnd); - /** * @brief Updates the OSD system each frame and executes callbacks if needed. * @@ -47,3 +51,45 @@ void UpdateOSD(reshade::api::effect_runtime* runtime, float deltaTime); * @param effect_name File name of the effect file to enumerate uniform variables from (eg. myfile.fx) */ void ResetAllUniformVariables(reshade::api::effect_runtime* runtime, const char* effect_name); + +/** + * @brief Toggle cheats. + * + * This function must be called once, typically in `init_effect_runtime`, + * using an atomic compare-and-exchange operation + * @param cheatEnabled cheat variable. + * @param fix cheat type to toggle (TimeDilation, God Mode ...) + * @param showUniform the Reshade uniform variable to show/hide the cheat on OSD + * @param enabledUniform the cheat state (enabled or not) + * @param duration the default OSD display duration (default 3 s) + * @param effect_name File name of the effect file to enumerate uniform variables from (eg. myfile.fx) + * @param extraFloats extra Reshade uniform variable (float) to initialize + */ +template +void ToggleOSD(T& cheatEnabled, GameFixes fix, + reshade::api::effect_uniform_variable showUniform, + reshade::api::effect_uniform_variable enabledUniform, + float duration = 3.f, + std::initializer_list> extraFloats = {}) { + + cheatEnabled = !cheatEnabled; + SetFixesEnabled(fix, cheatEnabled); + SaveSettings(); + + std::vector> stableFloats(extraFloats); + + ShowOSD(duration, + [=, stableFloats = std::move(stableFloats)](reshade::api::effect_runtime* rt) { + ResetAllUniformVariables(rt, OSD_SHADER_NAME); + rt->set_uniform_value_bool(showUniform, true); + rt->set_uniform_value_bool(enabledUniform, cheatEnabled); + + for (auto& uniform : stableFloats) + if (uniform.first.handle) + rt->set_uniform_value_float(uniform.first, uniform.second); + }, + [=](reshade::api::effect_runtime* rt) { + rt->set_uniform_value_bool(showUniform, false); + }); +} +