diff --git a/SpongeBobTOTT/dllmain.cpp b/SpongeBobTOTT/dllmain.cpp index 76d3e45..c4487f7 100644 --- a/SpongeBobTOTT/dllmain.cpp +++ b/SpongeBobTOTT/dllmain.cpp @@ -2,13 +2,9 @@ #define IMGUI_HAS_DOCK 1 #include "CommonHeaders.h" -//#include "GameInformations.h" -//#include "GameFixes.h" -//#include "inicpp.h" -//#include -//#include -#include -#include +#include "HotkeysManager.h" +#include "OSDManager.h" +#include // Screen informations static int screenWidth = GetSystemMetrics(SM_CXSCREEN); @@ -16,16 +12,14 @@ static int screenHeight = GetSystemMetrics(SM_CYSCREEN); static float aspectRatio = (float)screenWidth / screenHeight; // Core game dll functions declarations -//typedef void (*SetBoolFn)(bool, bool); -//typedef void (*SetFixesFn)(GameFixes ,bool); -//typedef void (*SetIntFn)(int); typedef void (*SetBoolFn)(bool, bool); typedef void (*SetFixesFn)(GameFixes, bool); typedef void (*SetFloatFn)(GameSetting, float); static HMODULE fixLib = nullptr; static LONG g_coreInitialized = 0; -static SetBoolFn SetFixEnabled = nullptr; +static LONG g_hotkeysInitialized = 0; +static LONG g_uniformReseted = 0; static SetBoolFn SetFixEnabled = nullptr; static SetFixesFn SetFixes = nullptr; static SetFloatFn SetValues = nullptr; void SetFixesEnabled(GameFixes fix, bool value) { if (SetFixes) SetFixes(fix, value); } @@ -43,11 +37,14 @@ static bool Vignetting_fix_enabled = false; static bool Fog_fix_enabled = false; static bool fix_enabled = false; static bool Time_Dilation_fix_enabled = false; +static bool GodMode_fix_enabled = false; +static bool StealthMode_fix_enabled = false; static bool console = true; static int worldFOVvalue = 0; static int HUDOffsetValue = 0; static float worldTimeDilationValue = 1.f; static float AITimeDilationValue = 1.f; +static float OSD_duration = 3.f; // Overlays popups static bool popup_Informations = false; @@ -75,16 +72,15 @@ static FixToggle individualFixes[] = { }; static FixToggle cheatFixes[] = { - { "Time dilation", &Time_Dilation_fix_enabled, GameFixes::TimeDilation, "ALT + 1 (top keyboard row) to toggle" } - //{ "God mode", &GodMode_fix_enabled, GameFixes::GodMode, "ALT + 2 (top keyboard row) to toggle.\nPlayer health bar will restore." }, - //{ "Stealth mode",&StealthMode_fix_enabled, GameFixes::Stealth, "ALT + 3 (top keyboard row) to toggle.\nEnemies won't attack you." } + { "Time dilation", &Time_Dilation_fix_enabled, GameFixes::TimeDilation, "ALT + 1 (top keyboard row) to toggle" }, + { "God mode", &GodMode_fix_enabled, GameFixes::GodMode, "ALT + 2 (top keyboard row) to toggle.\nPlayer health won't decrease." }, + { "Stealh mode", &StealthMode_fix_enabled, GameFixes::Stealth, "ALT + 3 (top keyboard row) to toggle.\nEnemies will ignore you." } }; // Prepare array of sliders for ImGui static SliderFix2 sliders[4]; // Load and unload game core dll functions /!\ necessary -static void LoadFixDLL() -{ +static void LoadFixDLL() { if (InterlockedCompareExchange(&g_coreInitialized, 1, 0) != 0) return; @@ -101,7 +97,6 @@ static void LoadFixDLL() SetValues = (SetFloatFn)GetProcAddress(fixLib, "SetValues"); GetGameInfos = (GetGameInfosStruct)GetProcAddress(fixLib, "GetGameInfos"); - // Apply initial values loaded from settings // Apply initial values loaded from settings if (SetValues) { SetValues(GameSetting::FOV, worldFOVvalue); @@ -119,6 +114,8 @@ static void LoadFixDLL() SetFixes(GameFixes::Vignetting, Vignetting_fix_enabled); SetFixes(GameFixes::Fog, Fog_fix_enabled); SetFixes(GameFixes::TimeDilation, Time_Dilation_fix_enabled); + SetFixes(GameFixes::GodMode, GodMode_fix_enabled); + SetFixes(GameFixes::Stealth, StealthMode_fix_enabled); SetFixes(GameFixes::DevConsole, console); } @@ -150,10 +147,11 @@ static void SaveSettings() { pluginIniFile["2#Individual fix"]["Vignetting"] = Vignetting_fix_enabled; pluginIniFile["2#Individual fix"]["Fog"] = Fog_fix_enabled; pluginIniFile["2#Individual fix"]["Time dilation"] = Time_Dilation_fix_enabled; + pluginIniFile["2#Individual fix"]["God mode"] = GodMode_fix_enabled; + pluginIniFile["2#Individual fix"]["Stealth"] = StealthMode_fix_enabled; pluginIniFile["3#Fixes tuning"].setComment("Individual fix fine tune"); pluginIniFile["3#Fixes tuning"]["World FOV"] = worldFOVvalue; pluginIniFile["3#Fixes tuning"]["HUD scaling"] = HUDOffsetValue; - pluginIniFile["3#Fixes tuning"]["HUD scaling"] = HUDOffsetValue; pluginIniFile["3#Fixes tuning"]["World time dilation scale"] = worldTimeDilationValue; pluginIniFile["3#Fixes tuning"]["AI time dilation scale"] = AITimeDilationValue; @@ -174,6 +172,8 @@ static void LoadSettings() { Vignetting_fix_enabled = pluginIniFile["2#Individual fix"]["Vignetting"].as(); Fog_fix_enabled = pluginIniFile["2#Individual fix"]["Fog"].as(); Time_Dilation_fix_enabled = pluginIniFile["2#Individual fix"]["Time dilation"].as(); + GodMode_fix_enabled = pluginIniFile["2#Individual fix"]["God mode"].as(); + StealthMode_fix_enabled = pluginIniFile["2#Individual fix"]["Stealth"].as(); worldFOVvalue = pluginIniFile["3#Fixes tuning"]["World FOV"].as(); HUDOffsetValue = pluginIniFile["3#Fixes tuning"]["HUD scaling"].as(); worldTimeDilationValue = pluginIniFile["3#Fixes tuning"]["World time dilation scale"].as(); @@ -185,8 +185,7 @@ static void LoadSettings() { // Read plugin log file void read_log_file(const std::string& filename) { std::ifstream file(filename); - if (!file.is_open()) - { + if (!file.is_open()) { log_content = "Impossible to open file : " + filename; return; } @@ -296,7 +295,7 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime) { if (GetGameInfos) { GameInfos infos{}; GetGameInfos(&infos); - ImGui::TextColored(ImColor(48, 179, 25), "Player health: %.2f", infos.Health); + ImGui::TextColored(ImColor(48, 179, 25), "Player health: %.f", infos.Health); } } } @@ -317,10 +316,39 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime) { ImGui::PopStyleVar(); } +static void on_reshade_present(reshade::api::effect_runtime* runtime) { + static auto last = std::chrono::steady_clock::now(); + auto now = std::chrono::steady_clock::now(); + float dt = std::chrono::duration(now - last).count(); + last = now; + + ProcessHotkeys(runtime); + UpdateOSD(runtime, dt); +} + +// Retrieve all shader uniform variables +static void on_reshade_begin_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, + reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) { + if (!runtime) return; + FindAllUniformVariables(runtime, OSD_SHADER_NAME); // Find all uniforms and set their handle + + if (InterlockedCompareExchange(&g_uniformReseted, 1, 0) != 0) return; // reset OSD uniforms once + ResetAllUniformVariables(runtime, OSD_SHADER_NAME); + runtime->save_current_preset(); // Save shader preset +} + +static void InitializeHotkeys() { // Initialize hotkeys for cheats + if (InterlockedCompareExchange(&g_hotkeysInitialized, 1, 0) != 0) return; // Initialize hotkeys once + + RegisterHotkey('1', Modifier::Alt, [] { + ToggleOSD(Time_Dilation_fix_enabled, GameFixes::TimeDilation, u_td_show, u_td_enabled, OSD_duration, + { {u_td_world, worldTimeDilationValue}, {u_td_AI, AITimeDilationValue} }); }); + RegisterHotkey('2', Modifier::Alt, [] { ToggleOSD(GodMode_fix_enabled, GameFixes::GodMode, u_GodMode_show, u_GodMode_enabled, OSD_duration); }); + RegisterHotkey('3', Modifier::Alt, [] { ToggleOSD(StealthMode_fix_enabled, GameFixes::Stealth, u_Stealth_show, u_Stealth_enabled, OSD_duration); }); +} // Main dll intrance BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID) { - switch (ul_reason_for_call) - { + switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: if (!reshade::register_addon(hinstDLL)) return FALSE; @@ -330,9 +358,14 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID) { reshade::register_event( [](reshade::api::effect_runtime* runtime) { LoadFixDLL(); + InitializeHotkeys(); }); + reshade::register_event(&on_reshade_present); + reshade::register_event(&on_reshade_begin_effects); break; case DLL_PROCESS_DETACH: + reshade::unregister_event(&on_reshade_present); + reshade::unregister_event(&on_reshade_begin_effects); reshade::unregister_addon(hinstDLL); break; }