Add cheat toggle function
This commit is contained in:
@@ -2,10 +2,15 @@
|
||||
|
||||
#include <reshade.hpp>
|
||||
#include <functional>
|
||||
#include "GameFixes.h"
|
||||
|
||||
constexpr auto OSD_SHADER_NAME = "OSD.fx";
|
||||
using OSDUpdateFn = std::function<void(reshade::api::effect_runtime*)>;
|
||||
using OSDEndFn = std::function<void(reshade::api::effect_runtime*)>;
|
||||
|
||||
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(reshade::api::effect_runtime*)>;
|
||||
*/
|
||||
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<typename T>
|
||||
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<std::pair<reshade::api::effect_uniform_variable, float>> extraFloats = {}) {
|
||||
|
||||
cheatEnabled = !cheatEnabled;
|
||||
SetFixesEnabled(fix, cheatEnabled);
|
||||
SaveSettings();
|
||||
|
||||
std::vector<std::pair<reshade::api::effect_uniform_variable, float>> 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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user