diff --git a/Metal Gear Solid Delta/dllmain.cpp b/Metal Gear Solid Delta/dllmain.cpp index c1a742b..1f8d0ee 100644 --- a/Metal Gear Solid Delta/dllmain.cpp +++ b/Metal Gear Solid Delta/dllmain.cpp @@ -16,8 +16,10 @@ static float aspectRatio = (float)screenWidth / screenHeight; typedef void (*SetBoolFn)(bool, bool); typedef void (*SetIntFn)(int); typedef float (*GetFloatFn)(); +typedef bool (*GetBoolFn)(); static HMODULE fixLib = nullptr; +static LONG g_coreInitialized = 0; static SetBoolFn SetFixEnabled = nullptr; static SetBoolFn SetFOVFixEnabled = nullptr; static SetBoolFn SetFPSFixEnabled = nullptr; @@ -28,9 +30,11 @@ static SetBoolFn SetCAFixEnabled = nullptr; static SetBoolFn SetVignettingFixEnabled = nullptr; static SetBoolFn SetFogFixEnabled = nullptr; static SetIntFn SetFOV = nullptr; + static GetFloatFn GetFOVIn = nullptr; static GetFloatFn GetCompensadedFOV = nullptr; static GetFloatFn GetFOVOut = nullptr; +static GetBoolFn GetConsoleEnabled = nullptr; // Plugin variables for checkboxes and sliders static bool fov_fix_enabled = false; @@ -58,8 +62,8 @@ const char* CA_FIX_SETTING = "ChromaticAberrationsFIX="; const char* VIGNETTING_FIX_SETTING = "VignettingFIX="; const char* FOG_FIX_SETTING = "FogFIX="; const char* WORLD_FOV_SETTING = "WorldFOV="; -const char* FIX_VERSION = "1.0.3"; -const char* FIX_INFORMATIONS = "This fix allows to:\n - Control FOV in game.\n - Unlock ultrawide resolutions.\n - Remove pillar boxing.\n - Unlock FPS.\n - Disable depth of field.\n - Disable chromatic aberrations.\n - Disable vignetting.\n - Disable FOG."; +const char* FIX_VERSION = "1.0.4"; +const char* FIX_INFORMATIONS = "This fix allows to:\n - Control FOV in game.\n - Unlock ultrawide resolutions.\n - Remove pillar boxing.\n - Unlock FPS.\n - Disable depth of field.\n - Disable chromatic aberrations.\n - Disable vignetting.\n - Disable FOG.\n - Enable dev console."; const char* DONATION_URL = "https://buymeacoffee.com/k4sh44"; // Scaling factor based vertical resolution @@ -68,40 +72,44 @@ float scale = 1.f; // Load and unload game core dll functions /!\ necessary static void LoadFixDLL() { - if (fixLib) return; - - fixLib = LoadLibraryA("MGSDSECore.dll"); - - if (!fixLib) { - MessageBoxA(nullptr, "Impossible to load game core dll", "Erreur", MB_OK); + if (InterlockedCompareExchange(&g_coreInitialized, 1, 0) != 0) return; + + if (GetModuleHandleA("MGSDSECore.dll") == nullptr) { + fixLib = LoadLibraryA("MGSDSECore.dll"); + + if (!fixLib) { + MessageBoxA(nullptr, "Impossible to load game core dll", "Erreur", MB_OK); + return; + } + + SetFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFixEnabled"); + SetFOVFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFOVFixEnabled"); + SetFPSFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFPSFixEnabled"); + SetResolutionFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetResolutionFixEnabled"); + SetAspectRatioFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetAspectRatioFixEnabled"); + SetDOFFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetDOFFixEnabled"); + SetCAFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetCAFixEnabled"); + SetVignettingFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetVignettingFixEnabled"); + SetFogFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFogFixEnabled"); + SetFOV = (SetIntFn)GetProcAddress(fixLib, "SetFOV"); + GetFOVIn = (GetFloatFn)GetProcAddress(fixLib, "GetFOVIn"); + GetCompensadedFOV = (GetFloatFn)GetProcAddress(fixLib, "GetCompensatedFOV"); + GetFOVOut = (GetFloatFn)GetProcAddress(fixLib, "GetFOVOut");; + GetConsoleEnabled = (GetBoolFn)GetProcAddress(fixLib, "GetConsoleEnabled"); + + // Apply initial values loaded from settings + if (SetFOV) SetFOV(worldFOVvalue); + if (SetFOVFixEnabled) SetFOVFixEnabled(fov_fix_enabled, true); + if (SetFPSFixEnabled) SetFPSFixEnabled(FPS_fix_enabled, true); + if (SetResolutionFixEnabled) SetResolutionFixEnabled(Resolution_fix_enabled, true); + if (SetAspectRatioFixEnabled) SetAspectRatioFixEnabled(Aspect_fix_enabled, true); + if (SetDOFFixEnabled) SetDOFFixEnabled(DOF_fix_enabled, true); + if (SetCAFixEnabled) SetCAFixEnabled(CA_fix_enabled, true); + if (SetVignettingFixEnabled) SetVignettingFixEnabled(Vignetting_fix_enabled, true); + if (SetFogFixEnabled) SetFogFixEnabled(Fog_fix_enabled, true); + if (SetFixEnabled) SetFixEnabled(fix_enabled, true); } - - SetFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFixEnabled"); - SetFOVFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFOVFixEnabled"); - SetFPSFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFPSFixEnabled"); - SetResolutionFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetResolutionFixEnabled"); - SetAspectRatioFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetAspectRatioFixEnabled"); - SetDOFFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetDOFFixEnabled"); - SetCAFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetCAFixEnabled"); - SetVignettingFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetVignettingFixEnabled"); - SetFogFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFogFixEnabled"); - SetFOV = (SetIntFn)GetProcAddress(fixLib, "SetFOV"); - GetFOVIn = (GetFloatFn)GetProcAddress(fixLib, "GetFOVIn"); - GetCompensadedFOV = (GetFloatFn)GetProcAddress(fixLib, "GetCompensatedFOV"); - GetFOVOut = (GetFloatFn)GetProcAddress(fixLib, "GetFOVOut");; - - // Apply initial values loaded from settings - if (SetFOV) SetFOV(worldFOVvalue); - if (SetFOVFixEnabled) SetFOVFixEnabled(fov_fix_enabled, true); - if (SetFPSFixEnabled) SetFPSFixEnabled(FPS_fix_enabled, true); - if (SetResolutionFixEnabled) SetResolutionFixEnabled(Resolution_fix_enabled, true); - if (SetAspectRatioFixEnabled) SetAspectRatioFixEnabled(Aspect_fix_enabled, true); - if (SetDOFFixEnabled) SetDOFFixEnabled(DOF_fix_enabled, true); - if (SetCAFixEnabled) SetCAFixEnabled(CA_fix_enabled, true); - if (SetVignettingFixEnabled) SetVignettingFixEnabled(Vignetting_fix_enabled, true); - if (SetFogFixEnabled) SetFogFixEnabled(Fog_fix_enabled, true); - if (SetFixEnabled) SetFixEnabled(fix_enabled, true); } // Settings functions @@ -301,6 +309,8 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime) // Fix status if (ImGui::CollapsingHeader("Fix informations", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Text("Screen width: %d, height: %d, aspect ratio: %.2f", screenWidth, screenHeight, aspectRatio); + if (GetConsoleEnabled && GetConsoleEnabled()) + ImGui::Text("Console enabled and bound to key Tilde"); if (GetFOVIn && GetCompensadedFOV && GetFOVOut) ImGui::TextColored(ImColor(48, 179, 25), "FOV In: %.2f, Compensated: %.2f, Out: %.2f", GetFOVIn(), GetCompensadedFOV(), GetFOVOut()); }