diff --git a/Hogwarts Legacy/dllmain.cpp b/Hogwarts Legacy/dllmain.cpp index 035ffd0..250d5c2 100644 --- a/Hogwarts Legacy/dllmain.cpp +++ b/Hogwarts Legacy/dllmain.cpp @@ -1,12 +1,10 @@ #define IMGUI_DISABLE_INCLUDE_IMCONFIG_H #define IMGUI_HAS_DOCK 1 -#include "GameInformations.h" -#include "GameFixes.h" -#include "inicpp.h" -#include -#include -#include +#include "CommonHeaders.h" +#include "HotkeysManager.h" +#include "OSDManager.h" +#include #include // Screen informations @@ -18,28 +16,38 @@ static float aspectRatio = (float)screenWidth / screenHeight; typedef void (*SetBoolFn)(bool, bool); typedef void (*SetFixesFn)(GameFixes, bool); typedef void (*SetIntFn)(int); -typedef void (*SetFloatFn)(float); +typedef void (*SetFloatFn)(GameSetting, float); static HMODULE fixLib = nullptr; static LONG g_coreInitialized = 0; +static LONG g_hotkeysInitialized = 0; +static LONG g_uniformReseted = 0; static SetBoolFn SetFixEnabled = nullptr; -static SetFixesFn SetFixesEnabled = nullptr; -static SetIntFn SetFOV = nullptr; -static SetFloatFn SetCameraDistance = nullptr; +static SetFixesFn SetFixes = nullptr; +static SetFloatFn SetValues = nullptr; static GetGameInfosStruct GetGameInfos = nullptr; +void SetFixesEnabled(GameFixes fix, bool value) { if (SetFixes) SetFixes(fix, value); } // Plugin variables for checkboxes and sliders static bool fov_fix_enabled = false; static bool ultrawide_fix_enabled = false; +static bool HUD_fix_enabled = false; static bool camera_fix_enabled = false; static bool DOF_fix_enabled = false; static bool CA_fix_enabled = false; 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 float cameraDistancevalue = 1.f; +static int HUDOffsetValue = 0; +static float worldTimeDilationValue = 1.f; +static float AITimeDilationValue = 1.f; +static float OSD_duration = 3.f; // Overlay popup static bool show_log_overlay = false; @@ -48,51 +56,87 @@ static bool popup_Informations = false; // Plugin settings const char* SETTINGS_FILE = "pluginSettings.ini"; -const char* FIX_VERSION = "1.0.1"; +const char* FIX_VERSION = "1.0.2"; const char* FIX_INFORMATIONS = "This fix allows to:\n - Control FOV in game.\n - Camera distance.\n - Enable ultrawide.\n - Disable depth of field.\n - Disable chromatic aberrations.\n - Disable vignetting.\n - Disable fog.\n - Re enable console."; const char* DONATION_URL = "https://buymeacoffee.com/k4sh44"; +// Prepare arrays of checkboxes for ImGui +static FixToggle individualFixes[] = { + { "FOV", &fov_fix_enabled, GameFixes::FOV }, + { "HUD scaling", &HUD_fix_enabled, GameFixes::HUD }, + { "Vignetting", &Vignetting_fix_enabled, GameFixes::Vignetting }, + { "Fog", &Fog_fix_enabled, GameFixes::Fog }, + { "Ultrawide", &ultrawide_fix_enabled, GameFixes::UltraWide, "This fix must be enabled before playing cutscenes\n" + "to fully remove letter & pillar boxing." }, + { "Camera distance", &camera_fix_enabled, GameFixes::Camera }, + { "Depth of field", &DOF_fix_enabled, GameFixes::DOF }, + { "Chromatic aberrations", &CA_fix_enabled, GameFixes::ChromaticAberrations } +}; + +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." } +}; + // Scaling factor based on screen resolution float scale = (float)screenHeight / 1200; +// Prepare array of sliders for ImGui +static SliderFix2 sliders[5]; + // Reshade addon name and description extern "C" __declspec(dllexport) const char* NAME = "Hogwarts Legacy"; -extern "C" __declspec(dllexport) const char* DESCRIPTION = "Reshade addon to re-enable console, enable ultrawide, control FOV, camera distance and some effects."; +extern "C" __declspec(dllexport) const char* DESCRIPTION = "Reshade addon to re-enable console, enable ultrawide, control FOV, camera distance and some effects. Enable cheats."; // Load and unload game core dll functions /!\ necessary -static void LoadFixDLL() -{ // Ensure the Core dll is loaded only once +static void LoadFixDLL() { // Ensure the Core dll is loaded only once if (InterlockedCompareExchange(&g_coreInitialized, 1, 0) != 0) return; if (GetModuleHandleA("HogwartsLegacyCore.dll") == nullptr) { fixLib = LoadLibraryA("HogwartsLegacyCore.dll"); - if (!fixLib) { MessageBoxA(nullptr, "Impossible to load game core dll", "Erreur", MB_OK); return; } SetFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFixEnabled"); - SetFixesEnabled = (SetFixesFn)GetProcAddress(fixLib, "SetFixesEnabled"); - SetFOV = (SetIntFn)GetProcAddress(fixLib, "SetFOV"); - SetCameraDistance = (SetFloatFn)GetProcAddress(fixLib, "SetCameraDistance"); + SetFixes = (SetFixesFn)GetProcAddress(fixLib, "SetFixesEnabled"); + SetValues = (SetFloatFn)GetProcAddress(fixLib, "SetValues"); GetGameInfos = (GetGameInfosStruct)GetProcAddress(fixLib, "GetGameInfos"); // Apply initial values loaded from settings - if (SetFOV) SetFOV(worldFOVvalue); - if (SetCameraDistance) SetCameraDistance(cameraDistancevalue); - if (SetFixEnabled) SetFixEnabled(fix_enabled, true); - if (SetFixesEnabled) { - SetFixesEnabled(GameFixes::FOV, fov_fix_enabled); - SetFixesEnabled(GameFixes::UltraWide, ultrawide_fix_enabled); - SetFixesEnabled(GameFixes::Camera, camera_fix_enabled); - SetFixesEnabled(GameFixes::DOF, DOF_fix_enabled); - SetFixesEnabled(GameFixes::ChromaticAberrations, CA_fix_enabled); - SetFixesEnabled(GameFixes::Vignetting, Vignetting_fix_enabled); - SetFixesEnabled(GameFixes::Fog, Fog_fix_enabled); - SetFixesEnabled(GameFixes::DevConsole, console); + if (SetValues) { + SetValues(GameSetting::FOV, worldFOVvalue); + SetValues(GameSetting::CameraDistance, cameraDistancevalue); + SetValues(GameSetting::HUD, HUDOffsetValue); + SetValues(GameSetting::WorldTimeDilation, worldTimeDilationValue); + SetValues(GameSetting::AITimeDilation, AITimeDilationValue); } + + if (SetFixEnabled) SetFixEnabled(fix_enabled, true); + if (SetFixes) { + SetFixes(GameFixes::FOV, fov_fix_enabled); + SetFixes(GameFixes::UltraWide, ultrawide_fix_enabled); + SetFixes(GameFixes::Camera, camera_fix_enabled); + SetFixes(GameFixes::HUD, HUD_fix_enabled); + SetFixes(GameFixes::DOF, DOF_fix_enabled); + SetFixes(GameFixes::ChromaticAberrations, CA_fix_enabled); + 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); + } + sliders[0] = { "In game additional FOV", "##FOVValue", SliderType::Int, &worldFOVvalue, -20, 70, GameSetting::FOV, SetValues }; + sliders[1] = { "Camera distance (*)", "##CameraOffset", SliderType::Float, &cameraDistancevalue, 0, 4, GameSetting::CameraDistance, SetValues, "%.2f", "Value is a multiplier." }; + sliders[2] = { "HUD scaling", "##HUDValue", SliderType::Int, &HUDOffsetValue, 0, 30, GameSetting::HUD, SetValues }; + sliders[3] = { "World time dilation", "##WorldTimeDilationValue", SliderType::Float, &worldTimeDilationValue, 0.f, 2.f,GameSetting::WorldTimeDilation , SetValues, nullptr, + "Will affect everything in the world.\nDefault value is 1." }; + sliders[4] = { "AI time dilation", "##AITimeDilationValue", SliderType::Float, &AITimeDilationValue, 0.f, 2.f, GameSetting::AITimeDilation, SetValues, nullptr, + "Will affect only enemies in the world.\nDefault value is 1." }; } } @@ -111,13 +155,20 @@ static void SaveSettings() pluginIniFile["2#Individual fix"]["FOV"] = fov_fix_enabled; pluginIniFile["2#Individual fix"]["Ultrawide"] = ultrawide_fix_enabled; pluginIniFile["2#Individual fix"]["Camera"] = camera_fix_enabled; + pluginIniFile["2#Individual fix"]["HUD"] = HUD_fix_enabled; pluginIniFile["2#Individual fix"]["DOF"] = DOF_fix_enabled; pluginIniFile["2#Individual fix"]["Chromatic aberrations"] = CA_fix_enabled; 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"]["Camera distance"] = cameraDistancevalue; + 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; pluginIniFile.save(SETTINGS_FILE); } @@ -127,17 +178,24 @@ static void LoadSettings() ini::IniFile pluginIniFile; try { pluginIniFile.load(SETTINGS_FILE); - fix_enabled = pluginIniFile["1#General fix"]["Enabled"].as(); - console = pluginIniFile["1#General fix"]["Console"].as(); - fov_fix_enabled = pluginIniFile["2#Individual fix"]["FOV"].as(); - ultrawide_fix_enabled = pluginIniFile["2#Individual fix"]["Ultrawide"].as(); - camera_fix_enabled = pluginIniFile["2#Individual fix"]["Camera"].as(); - DOF_fix_enabled = pluginIniFile["2#Individual fix"]["DOF"].as(); - CA_fix_enabled = pluginIniFile["2#Individual fix"]["Chromatic aberrations"].as(); - Vignetting_fix_enabled = pluginIniFile["2#Individual fix"]["Vignetting"].as(); - Fog_fix_enabled = pluginIniFile["2#Individual fix"]["Fog"].as(); - worldFOVvalue = pluginIniFile["3#Fixes tuning"]["World FOV"].as(); - cameraDistancevalue = pluginIniFile["3#Fixes tuning"]["Camera distance"].as(); + fix_enabled = pluginIniFile["1#General fix"]["Enabled"].as(); + console = pluginIniFile["1#General fix"]["Console"].as(); + fov_fix_enabled = pluginIniFile["2#Individual fix"]["FOV"].as(); + ultrawide_fix_enabled = pluginIniFile["2#Individual fix"]["Ultrawide"].as(); + camera_fix_enabled = pluginIniFile["2#Individual fix"]["Camera"].as(); + HUD_fix_enabled = pluginIniFile["2#Individual fix"]["HUD"].as(); + DOF_fix_enabled = pluginIniFile["2#Individual fix"]["DOF"].as(); + CA_fix_enabled = pluginIniFile["2#Individual fix"]["Chromatic aberrations"].as(); + 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(); + cameraDistancevalue = pluginIniFile["3#Fixes tuning"]["Camera distance"].as(); + HUDOffsetValue = pluginIniFile["3#Fixes tuning"]["HUD scaling"].as(); + worldTimeDilationValue = pluginIniFile["3#Fixes tuning"]["World time dilation scale"].as(); + AITimeDilationValue = pluginIniFile["3#Fixes tuning"]["AI time dilation scale"].as(); } catch (const std::exception& e) {} } @@ -145,8 +203,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; } @@ -157,14 +214,7 @@ void read_log_file(const std::string& filename) { } // Initialize ImGui widgets for Reshade -static void on_overlay_draw(reshade::api::effect_runtime* runtime) -{ - ImGuiStyle& style = ImGui::GetStyle(); - style.ItemSpacing = ImVec2(8 * scale, 8 * scale); // Spacing between widgets - style.FramePadding = ImVec2(3 * scale, 3 * scale); // Widgets padding - style.WindowPadding = ImVec2(10 * scale, 10 * scale); // Overlay padding - style.CellPadding = ImVec2(10 * scale, 10 * scale); // Table cells padding - +static void on_overlay_draw(reshade::api::effect_runtime* runtime) { ImGui::SetNextWindowSize(ImVec2(350 * scale, 150 * scale), ImGuiCond_Once); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.84f, 0.12f, 0.51f, 1.0f)); // pink @@ -196,120 +246,130 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime) ImGui::End(); } - ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(10 * scale, 10 * scale)); - if (ImGui::BeginTable("FixesTable", 2, ImGuiTableFlags_SizingStretchSame)) { - ImGui::TableSetupColumn("LeftFix", ImGuiTableColumnFlags_WidthStretch, 0.4f); - ImGui::TableSetupColumn("RightFix", ImGuiTableColumnFlags_WidthStretch, 0.6f); - ImGui::TableNextRow(); - - // Drawing a left column with slider and general fix - ImGui::TableSetColumnIndex(0); - if (ImGui::CollapsingHeader("Enable fixes", ImGuiTreeNodeFlags_DefaultOpen)) - if (ImGui::Checkbox("Fix enabled", &fix_enabled)) { - if (SetFixEnabled) SetFixEnabled(fix_enabled, false); - SaveSettings(); - } - - // Sliders - if (ImGui::CollapsingHeader("In game additional FOV", ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::SetNextItemWidth(150 * scale); - if (ImGui::SliderInt("##FOVValue", &worldFOVvalue, -20, 50)) { - if (SetFOV) SetFOV(worldFOVvalue); - SaveSettings(); - } - } - - if (ImGui::CollapsingHeader("Camera distance (*)", ImGuiTreeNodeFlags_DefaultOpen)) - { - ImGui::SetNextItemWidth(150 * scale); - if (ImGui::SliderFloat("##CameraValue", &cameraDistancevalue, 0, 2, "%.2f")) { - if (SetCameraDistance) SetCameraDistance(cameraDistancevalue); - SaveSettings(); - } - } - if (ImGui::IsItemHovered()) { - ImGui::BeginTooltip(); - ImGui::Text("Value is a multiplier."); - ImGui::EndTooltip(); - } - - // Individual fixes - ImGui::TableSetColumnIndex(1); - if (ImGui::CollapsingHeader("Individual fixes", ImGuiTreeNodeFlags_DefaultOpen)) { - if (ImGui::BeginTable("IndividualFixesTable", 2, ImGuiTableFlags_SizingStretchSame)) { - ImGui::TableSetupColumn("IndFix1", ImGuiTableColumnFlags_WidthStretch, 0.35f); - ImGui::TableSetupColumn("IndFix2", ImGuiTableColumnFlags_WidthStretch, 0.65f); + if (ImGui::BeginTabBar("MainTabs")) { + if (ImGui::BeginTabItem("Fixes")) { + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(10 * scale, 10 * scale)); + if (ImGui::BeginTable("FixesTable", 2, ImGuiTableFlags_SizingStretchSame)) { + ImGui::TableSetupColumn("LeftFix", ImGuiTableColumnFlags_WidthStretch, 0.4f); + ImGui::TableSetupColumn("RightFix", ImGuiTableColumnFlags_WidthStretch, 0.6f); ImGui::TableNextRow(); + // Drawing a left column with slider and general fix ImGui::TableSetColumnIndex(0); - if (ImGui::Checkbox("FOV", &fov_fix_enabled)) { - if (SetFixesEnabled) SetFixesEnabled(GameFixes::FOV, fov_fix_enabled); - SaveSettings(); - } - - if (ImGui::Checkbox("Camera", &camera_fix_enabled)) { - if (SetFixesEnabled) SetFixesEnabled(GameFixes::Camera, camera_fix_enabled); - SaveSettings(); - } - - if (ImGui::Checkbox("Vignetting", &Vignetting_fix_enabled)) { - if (SetFixesEnabled) SetFixesEnabled(GameFixes::Vignetting, Vignetting_fix_enabled); - SaveSettings(); - } - - if (ImGui::Checkbox("Fog", &Fog_fix_enabled)) { - if (SetFixesEnabled) SetFixesEnabled(GameFixes::Fog, Fog_fix_enabled); - SaveSettings(); - } - + if (ImGui::CollapsingHeader("Enable fixes", ImGuiTreeNodeFlags_DefaultOpen)) + if (ImGui::Checkbox("Fix enabled", &fix_enabled)) { + if (SetFixEnabled) SetFixEnabled(fix_enabled, false); + SaveSettings(); + } + // Individual fixes ImGui::TableSetColumnIndex(1); - if (ImGui::Checkbox("Ultrawide", &ultrawide_fix_enabled)) { - if (SetFixesEnabled) SetFixesEnabled(GameFixes::UltraWide, ultrawide_fix_enabled); - SaveSettings(); - } - if (ImGui::IsItemHovered()) { - ImGui::BeginTooltip(); - ImGui::Text("This fix must be enabled before playing cutscenes"); - ImGui::Text("to fully remove letter & pillar boxing."); - ImGui::EndTooltip(); - } + if (ImGui::CollapsingHeader("Individual fixes", ImGuiTreeNodeFlags_DefaultOpen)) { + if (ImGui::BeginTable("IndividualFixesTable", 2, ImGuiTableFlags_SizingStretchSame)) { + ImGui::TableSetupColumn("IndFix1", ImGuiTableColumnFlags_WidthStretch, 0.4f); + ImGui::TableSetupColumn("IndFix2", ImGuiTableColumnFlags_WidthStretch, 0.6f); + ImGui::TableNextRow(); - if (ImGui::Checkbox("Depth of field", &DOF_fix_enabled)) { - if (SetFixesEnabled) SetFixesEnabled(GameFixes::DOF, DOF_fix_enabled); - SaveSettings(); - } + ImGui::TableSetColumnIndex(0); + for (int i = 0; i < 4; ++i) DrawFixCheckbox(individualFixes[i]); - if (ImGui::Checkbox("Chromatic aberrations", &CA_fix_enabled)) { - if (SetFixesEnabled) SetFixesEnabled(GameFixes::ChromaticAberrations, CA_fix_enabled); - SaveSettings(); + ImGui::TableSetColumnIndex(1); + for (int i = 4; i < IM_ARRAYSIZE(individualFixes); ++i) DrawFixCheckbox(individualFixes[i]); + + ImGui::EndTable(); + } } ImGui::EndTable(); } + + ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 2 /** 1 style.ItemSpacing.y*/); + if (ImGui::BeginTable("FixesSliders", 2, ImGuiTableFlags_SizingStretchSame)) { + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + for (int i = 0; i < 2; ++i) DrawSlider2(sliders[i], 200); + ImGui::TableSetColumnIndex(1); + for (int i = 2; i < 3; ++i) DrawSlider2(sliders[i], 200); + ImGui::EndTable(); + } + ImGui::PopStyleVar(); + ImGui::EndTabItem(); + } + + if (ImGui::BeginTabItem("Cheats")) { + for (const auto& cheat : cheatFixes) DrawFixCheckbox(cheat); + + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(10 * scale, 10 * scale)); + if (ImGui::BeginTable("SlidersTable", 2, ImGuiTableFlags_SizingStretchSame)) { + ImGui::TableSetupColumn("LeftSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f); + ImGui::TableSetupColumn("RightSliders", ImGuiTableColumnFlags_WidthStretch, 0.5f); + ImGui::TableNextRow(); + + ImGui::TableSetColumnIndex(0); + DrawSlider2(sliders[3], 180); + ImGui::TableSetColumnIndex(1); + DrawSlider2(sliders[4], 180); + ImGui::EndTable(); + } + ImGui::PopStyleVar(); + ImGui::EndTabItem(); + if (ImGui::CollapsingHeader("Cheat informations", ImGuiTreeNodeFlags_DefaultOpen)) { + if (GetGameInfos) { + GameInfos infos{}; + GetGameInfos(&infos); + ImGui::TextColored(ImColor(48, 179, 25), "Player health: %.2f", infos.Health); + } + } + } + ImGui::EndTabBar(); + + // Fix status + if (ImGui::CollapsingHeader("Fix informations", ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::Text("Screen width: %d, height: %d, aspect ratio: %.2f", screenWidth, screenHeight, aspectRatio); + if (GetGameInfos) { + GameInfos infos{}; + GetGameInfos(&infos); + if (infos.consoleEnabled) + ImGui::Text("Console enabled and bound to key F2"); + ImGui::TextColored(ImColor(48, 179, 25), "FOV In: %.2f, Out: %.2f", infos.FOVIn, infos.FOVOut); + ImGui::TextColored(ImColor(48, 179, 25), "Camera distance In: %.2f, Out: %.2f", infos.cameraIn, infos.cameraOut); + } } - ImGui::EndTable(); } ImGui::PopStyleVar(); - - // Fix status - if (ImGui::CollapsingHeader("Fix informations", ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::Text("Screen width: %d, height: %d, aspect ratio: %.2f", screenWidth, screenHeight, aspectRatio); - if (GetGameInfos) { - GameInfos infos{}; - GetGameInfos(&infos); - if (infos.consoleEnabled) - ImGui::Text("Console enabled and bound to key F2"); - ImGui::TextColored(ImColor(48, 179, 25), "FOV In: %.2f, Out: %.2f", infos.FOVIn, infos.FOVOut); - ImGui::TextColored(ImColor(48, 179, 25), "Camera distance In: %.2f, Out: %.2f", infos.cameraIn, infos.cameraOut); - } - } } +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) - { +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID) { + switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: if (!reshade::register_addon(hinstDLL)) return FALSE; @@ -319,9 +379,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; }