Finalized WuchangFF Reshade addon.

This commit is contained in:
2025-08-08 10:55:54 +02:00
parent e58d31e544
commit 6f560959ae

View File

@@ -1,4 +1,4 @@
#define IMGUI_DISABLE_INCLUDE_IMCONFIG_H
#define IMGUI_DISABLE_INCLUDE_IMCONFIG_H
#define IMGUI_HAS_DOCK 1
#include <imgui.h>
@@ -17,42 +17,67 @@ typedef void (*InitDLL)();
static HMODULE fixLib = nullptr;
static SetBoolFn SetFixEnabled = nullptr;
static SetBoolFn SetFOVFixEnabled = nullptr;
static SetBoolFn SetAspectRatioFixEnabled = nullptr;
static SetBoolFn SetARAxisConstrainFixEnabled = nullptr;
static SetBoolFn SetDOFFixEnabled = nullptr;
static SetIntFn SetFOV = nullptr;
static GetFloatFn GetFOVIn = nullptr;
static GetFloatFn GetCompensadedFOV = nullptr;
static GetFloatFn GetFOVOut = nullptr;
static SetBoolFn SetVignettingFixEnabled = nullptr;
static SetBoolFn SetFogFixEnabled = nullptr;
static InitDLL InitializeLogger = nullptr;
// Plugin variables for checkboxes and sliders
static bool fov_fix_enabled = false;
static bool aspect_ratio_fix_enabled = false;
static bool AR_Axis_constrain_fix_enabled = false;
static bool DOF_fix_enabled = false;
static bool Vignetting_fix_enabled = false;
static bool Fog_fix_enabled = false;
static bool fix_enabled = false;
static int worldFOVvalue = 0;
static bool popup_Informations = false;
// Plugin settings
const char* SETTINGS_FILE = "PluginSettings.ini";
const char* GENERAL_FIX_SETTING = "GeneralFIX=";
const char* WORLD_FOV_FIX_SETTING = "WorldFOVFIX=";
const char* ASPECT_FIX_SETTING = "AspectFIX=";
const char* AR_AXIS_CONSTRAIN_FIX_SETTING = "ARAxisConstrainFIX=";
const char* DOF_FIX_SETTING = "DOFFIX=";
const char* WORLD_FOV_SETTING = "WorldFOV=";
const char* VIGNETTING_FIX_SETTING = "VignettingFIX=";
const char* FOG_FIX_SETTING = "FogFIX=";
const char* FIX_VERSION = "1.0.1";
const char* FIX_INFORMATIONS = "This fix allows to:\n - Control in game FOV.\n - Force aspect ratio.\n - Disable depth of field.\r\nFOV will be compensated when aspect fix is checked.";
const char* FIX_INFORMATIONS = "This fix allows to:\n - Enable HOR+.\n - Disable depth of field.\n - Disable vignetting.\n - Disbale FOG.\n\nEnabling HOR + may over compensate FOV in game.\nDisabling Fog will not entirely remove it.";
const char* DONATION_URL = "https://buymeacoffee.com/k4sh44";
// Ensure that our Core DLL will be called only once
bool IsAlreadyInitialized()
{
// Declare a lock
HANDLE hMap = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, "Local\\WuchangFixSharedSection");
// If lock is not yet initialized
if (hMap == nullptr)
{
// We create the lock only once
hMap = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, 1, "Local\\WuchangFixSharedSection");
if (hMap == nullptr) // We ensure the lock is valid
return true;
return false; // First time created we return false
}
// Otherwise we return true
CloseHandle(hMap);
return true;
}
// Load and unload game core dll functions /!\ necessary
static void LoadFixDLL()
{
MessageBoxA(nullptr, "LoadFixDll", "Logger Error", MB_ICONERROR | MB_OK);
if (IsAlreadyInitialized())
return; // déjà lancé dans un autre chargement
std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(8000)); // Game process is not ready at launch and memory is not yet initialized
// Game process is not ready at launch and memory is not yet initialized
// We do want the core dll to be called and initialized a few seconds after game launch
std::this_thread::sleep_for(std::chrono::milliseconds(6000));
if (GetModuleHandleA("WuchangFFCore.dll") == nullptr) {
MessageBoxA(nullptr, "Appel dll", "Logger Error", MB_ICONERROR | MB_OK);
fixLib = LoadLibraryA("WuchangFFCore.dll");
if (!fixLib) {
@@ -61,22 +86,19 @@ static void LoadFixDLL()
}
SetFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFixEnabled");
SetFOVFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFOVFixEnabled");
SetAspectRatioFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetAspectRatioFixEnabled");
SetARAxisConstrainFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetARAxisConstrainFixEnabled");
SetDOFFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetDOFFixEnabled");
SetFOV = (SetIntFn)GetProcAddress(fixLib, "SetFOV");
GetFOVIn = (GetFloatFn)GetProcAddress(fixLib, "GetFOVIn");
GetCompensadedFOV = (GetFloatFn)GetProcAddress(fixLib, "GetCompensatedFOV");
GetFOVOut = (GetFloatFn)GetProcAddress(fixLib, "GetFOVOut");;
SetVignettingFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetVignettingFixEnabled");
SetFogFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFogFixEnabled");
// Apply initial values loaded from settings
if (SetFOV) SetFOV(worldFOVvalue);
//if (SetFOVFixEnabled) SetFOVFixEnabled(fov_fix_enabled, true);
//if (SetAspectRatioFixEnabled) SetAspectRatioFixEnabled(aspect_ratio_fix_enabled, true);
//if (SetDOFFixEnabled) SetDOFFixEnabled(DOF_fix_enabled, true);
if (SetARAxisConstrainFixEnabled) SetARAxisConstrainFixEnabled(AR_Axis_constrain_fix_enabled, true);
if (SetDOFFixEnabled) SetDOFFixEnabled(DOF_fix_enabled, true);
if (SetVignettingFixEnabled) SetVignettingFixEnabled(Vignetting_fix_enabled, true);
if (SetFogFixEnabled) SetFogFixEnabled(Fog_fix_enabled, true);
if (SetFixEnabled) SetFixEnabled(fix_enabled, true);
}
}).detach(); // on le détache pour quil tourne indépendamment
}).detach(); // This thread will not block others
}
// Addon functions
@@ -86,10 +108,10 @@ static void SaveSettings()
if (file.is_open())
{
file << GENERAL_FIX_SETTING << (fix_enabled ? "1" : "0") << "\n";
file << WORLD_FOV_FIX_SETTING << (fov_fix_enabled ? "1" : "0") << "\n";
file << ASPECT_FIX_SETTING << (aspect_ratio_fix_enabled ? "1" : "0") << "\n";
file << AR_AXIS_CONSTRAIN_FIX_SETTING << (AR_Axis_constrain_fix_enabled ? "1" : "0") << "\n";
file << DOF_FIX_SETTING << (DOF_fix_enabled ? "1" : "0") << "\n";
file << WORLD_FOV_SETTING << worldFOVvalue << "\n";
file << VIGNETTING_FIX_SETTING << (Vignetting_fix_enabled ? "1" : "0") << "\n";
file << FOG_FIX_SETTING << (Fog_fix_enabled ? "1" : "0") << "\n";
file.close();
}
}
@@ -107,23 +129,26 @@ static void LoadSettings()
std::string val = line.substr(strlen(GENERAL_FIX_SETTING));
fix_enabled = (val == "1" || val == "true");
}
else if (line.find(WORLD_FOV_FIX_SETTING) == 0)
else if (line.find(AR_AXIS_CONSTRAIN_FIX_SETTING) == 0)
{
std::string val = line.substr(strlen(WORLD_FOV_FIX_SETTING));
fov_fix_enabled = (val == "1" || val == "true");
}
else if (line.find(ASPECT_FIX_SETTING) == 0)
{
std::string val = line.substr(strlen(ASPECT_FIX_SETTING));
aspect_ratio_fix_enabled = (val == "1" || val == "true");
std::string val = line.substr(strlen(AR_AXIS_CONSTRAIN_FIX_SETTING));
AR_Axis_constrain_fix_enabled = (val == "1" || val == "true");
}
else if (line.find(DOF_FIX_SETTING) == 0)
{
std::string val = line.substr(strlen(DOF_FIX_SETTING));
DOF_fix_enabled = (val == "1" || val == "true");
}
else if (line.find(WORLD_FOV_SETTING) == 0)
worldFOVvalue = std::stoi(line.substr(strlen(WORLD_FOV_SETTING)));
else if (line.find(VIGNETTING_FIX_SETTING) == 0)
{
std::string val = line.substr(strlen(VIGNETTING_FIX_SETTING));
Vignetting_fix_enabled = (val == "1" || val == "true");
}
else if (line.find(FOG_FIX_SETTING) == 0)
{
std::string val = line.substr(strlen(FOG_FIX_SETTING));
Fog_fix_enabled = (val == "1" || val == "true");
}
}
file.close();
}
@@ -174,51 +199,33 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
}
ImGui::EndChild();
// FOV adjustment
ImGui::SetCursorPos(ImVec2(10, 120));
ImGui::BeginChild("FOVHeader", ImVec2(220, 0), false);
if (ImGui::CollapsingHeader("In game additional FOV", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::SetCursorPos(ImVec2(5, 30));
ImGui::SetNextItemWidth(150.0f);
if (ImGui::SliderInt("", &worldFOVvalue, -20, 50)) {}
if (ImGui::IsItemDeactivatedAfterEdit()) {
if (SetFOV) SetFOV(worldFOVvalue);
SaveSettings();
}
}
ImGui::EndChild();
// Individual fixes
ImGui::SetCursorPos(ImVec2(240, 60));
ImGui::BeginChild("IndividualFixesHeader", ImVec2(250, 0), false);
if (ImGui::CollapsingHeader("Individual fixes", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::SetCursorPos(ImVec2(5, 30));
if (ImGui::Checkbox("Enable FOV Fix", &fov_fix_enabled)) {
if (SetFOVFixEnabled) SetFOVFixEnabled(fov_fix_enabled, false);
if (ImGui::Checkbox("Enable HOR+", &AR_Axis_constrain_fix_enabled)) {
if (SetARAxisConstrainFixEnabled) SetARAxisConstrainFixEnabled(AR_Axis_constrain_fix_enabled, false);
SaveSettings();
}
ImGui::SetCursorPos(ImVec2(5, 55));
if (ImGui::Checkbox("Enable aspect Ratio Fix", &aspect_ratio_fix_enabled)) {
if (SetAspectRatioFixEnabled) SetAspectRatioFixEnabled(aspect_ratio_fix_enabled, false);
SaveSettings();
}
ImGui::SetCursorPos(ImVec2(5, 80));
if (ImGui::Checkbox("Depth of field Fix", &DOF_fix_enabled)) {
if (SetDOFFixEnabled) SetDOFFixEnabled(DOF_fix_enabled, false);
SaveSettings();
}
}
ImGui::EndChild();
// Fix status
ImGui::SetCursorPos(ImVec2(10, 200));
ImGui::BeginChild("INFOSHeader", ImVec2(480, 80), true); // true = border
if (ImGui::CollapsingHeader("Fix informations", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::SetCursorPos(ImVec2(5, 30));
if (GetFOVIn && GetCompensadedFOV && GetFOVOut)
ImGui::Text("FOV In: %.2f, Compensated : %.2f, Out : %.2f", GetFOVIn(), GetCompensadedFOV(), GetFOVOut());
ImGui::SetCursorPos(ImVec2(5, 80));
if (ImGui::Checkbox("Vignetting Fix", &Vignetting_fix_enabled)) {
if (SetVignettingFixEnabled) SetVignettingFixEnabled(Vignetting_fix_enabled, false);
SaveSettings();
}
ImGui::SetCursorPos(ImVec2(5, 105));
if (ImGui::Checkbox("Fog Fix", &Fog_fix_enabled)) {
if (SetFogFixEnabled) SetFogFixEnabled(Fog_fix_enabled, false);
SaveSettings();
}
}
ImGui::EndChild();
}
@@ -238,10 +245,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID)
[](reshade::api::effect_runtime* runtime) {
LoadFixDLL();
});
//reshade::register_event<reshade::addon_event::init_command_queue>(
// [](reshade::api::command_queue *queue) {
// LoadFixDLL();
// });
break;
case DLL_PROCESS_DETACH:
reshade::unregister_addon(hinstDLL);