Add HUD fix. Code refactoring

This commit is contained in:
2026-02-27 22:23:59 +01:00
parent 64f9b8d145
commit 0bf85322ec

View File

@@ -1,13 +1,7 @@
#define IMGUI_DISABLE_INCLUDE_IMCONFIG_H
#define IMGUI_HAS_DOCK 1
#include "GameInformations.h"
#include "GameFixes.h"
#include "inicpp.h"
#include <imgui.h>
#include <reshade.hpp>
#include <string>
#include <Windows.h>
#include "CommonHeaders.h"
// Screen informations
static int screenWidth = GetSystemMetrics(SM_CXSCREEN);
@@ -15,23 +9,24 @@ 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 (*SetFloatFn)(float);
using SetBoolFn = void (*)(bool, bool);
using SetFixesFn = void (*)(GameFixes, bool);
using SetFloatFn = void (*)(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 camera_fix_enabled = false;
static bool HUD_fix_enabled = false;
static bool DOF_fix_enabled = false;
static bool CA_fix_enabled = false;
static bool Vignetting_fix_enabled = false;
@@ -42,6 +37,7 @@ static bool console = true;
static int worldFOVvalue = 0;
static float cameraDistance = 1.f;
static int HUDvalue = 0;
// Overlays popups
static bool popup_Informations = false;
@@ -50,20 +46,35 @@ static std::string log_content;
// Plugin settings
const std::string SETTINGS_FILE = "./pluginsettings.ini";
const char* FIX_VERSION = "1.0.2.1";
const char* FIX_INFORMATIONS = "This fix allows to:\n - Control FOV in game.\n - Enable ultrawide.\n - Control camera distance.\n - Disable depth of field.\n - Disable chromatic aberrations.\n - Disable vignetting.\n - Disable fog & volumetric fog.\n - Re enable dev console.";
const char* FIX_VERSION = "1.0.3";
const char* FIX_INFORMATIONS = "This fix allows to:\n - Control FOV in game.\n - Enable ultrawide.\n - Control HUD scaling.\n - Control camera distance.\n - Disable depth of field.\n - Disable chromatic aberrations.\n - Disable vignetting.\n - Disable fog & volumetric fog.\n - Re enable dev console.";
const char* DONATION_URL = "https://buymeacoffee.com/k4sh44";
// Prepare arrays of checkboxes for ImGui
static FixToggle individualFixes[] = {
{ "FOV", &fov_fix_enabled, GameFixes::FOV },
{ "Camera", &camera_fix_enabled, GameFixes::Camera },
{ "Vignetting", &Vignetting_fix_enabled, GameFixes::Vignetting },
{ "Fog", &Fog_fix_enabled, GameFixes::Fog },
{ "Ultrawide", &ultrawide_fix_enabled, GameFixes::UltraWide },
{ "HUD", &HUD_fix_enabled, GameFixes::HUD },
{ "Depth of field", &DOF_fix_enabled, GameFixes::DOF },
{ "Chromatic aberrations", &CA_fix_enabled, GameFixes::ChromaticAberrations },
{ "Volumetric fog", &VolumetricFog_fix_enabled, GameFixes::VolumetricFog },
};
// Reshade addon name and description
extern "C" __declspec(dllexport) const char* NAME = "Eternal Strands";
extern "C" __declspec(dllexport) const char* DESCRIPTION = "Reshade addon to re-enable console, enable ultrawide, control FOV, camera distance and some effects.";
// Scaling factor based on screen resolution
float scale = 1.f;
float scale = (float)screenHeight / 1200;
// Prepare array of sliders for ImGui
static SliderFix2 sliders[3];
// Load and unload game core dll functions /!\ necessary
static void LoadFixDLL()
{
static void LoadFixDLL() {
if (InterlockedCompareExchange(&g_coreInitialized, 1, 0) != 0)
return;
@@ -76,32 +87,39 @@ static void LoadFixDLL()
}
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(cameraDistance);
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::VolumetricFog, VolumetricFog_fix_enabled);
SetFixesEnabled(GameFixes::DevConsole, console);
if (SetValues) {
SetValues(GameSetting::FOV, worldFOVvalue);
SetValues(GameSetting::CameraDistance, cameraDistance);
SetValues(GameSetting::HUD, HUDvalue);
}
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::VolumetricFog, VolumetricFog_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, &cameraDistance, 0, 4, GameSetting::CameraDistance, SetValues, "%.1f",
"Value is a multiplier." };
sliders[2] = { "HUD scaling", "##HUDValue", SliderType::Int, &HUDvalue, 0, 40, GameSetting::HUD, SetValues, nullptr, "This will only affect HUD" };
}
}
// Settings functions
static void SaveSettings()
{
static void SaveSettings() {
ini::IniFile pluginIniFile;
pluginIniFile["1#General fix"].setComment(std::vector<std::string>{ "The following sections are saved by plugin",
"You should not need to modify them",
@@ -114,6 +132,7 @@ 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;
@@ -122,12 +141,12 @@ static void SaveSettings()
pluginIniFile["3#Fixes tuning"].setComment("Individual fix fine tune");
pluginIniFile["3#Fixes tuning"]["World FOV"] = worldFOVvalue;
pluginIniFile["3#Fixes tuning"]["Camera distance"] = cameraDistance;
pluginIniFile["3#Fixes tuning"]["HUD scaling"] = HUDvalue;
pluginIniFile.save(SETTINGS_FILE);
}
static void LoadSettings()
{
static void LoadSettings() {
ini::IniFile pluginIniFile;
try {
pluginIniFile.load(SETTINGS_FILE);
@@ -136,6 +155,7 @@ static void LoadSettings()
fov_fix_enabled = pluginIniFile["2#Individual fix"]["FOV"].as<bool>();
ultrawide_fix_enabled = pluginIniFile["2#Individual fix"]["UltraWide"].as<bool>();
camera_fix_enabled = pluginIniFile["2#Individual fix"]["Camera"].as<bool>();
HUD_fix_enabled = pluginIniFile["2#Individual fix"]["HUD"].as<bool>();
DOF_fix_enabled = pluginIniFile["2#Individual fix"]["DOF"].as<bool>();
CA_fix_enabled = pluginIniFile["2#Individual fix"]["Chromatic aberrations"].as<bool>();
Vignetting_fix_enabled = pluginIniFile["2#Individual fix"]["Vignetting"].as<bool>();
@@ -143,6 +163,7 @@ static void LoadSettings()
VolumetricFog_fix_enabled = pluginIniFile["2#Individual fix"]["Volumetric fog"].as<bool>();
worldFOVvalue = pluginIniFile["3#Fixes tuning"]["World FOV"].as<int>();
cameraDistance = pluginIniFile["3#Fixes tuning"]["Camera distance"].as<float>();
HUDvalue = pluginIniFile["3#Fixes tuning"]["HUD scaling"].as<int>();
}
catch (const std::exception& e) {}
}
@@ -162,8 +183,7 @@ void read_log_file(const std::string& filename) {
}
// Initialize ImGui widgets for Reshade
static void on_overlay_draw(reshade::api::effect_runtime* runtime)
{
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
@@ -186,16 +206,14 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
show_log_overlay = true; // Fix information
}
if (popup_Informations)
{
if (popup_Informations) {
ImGui::Begin("Informations", &popup_Informations, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("Version : %s", FIX_VERSION);
ImGui::Text(FIX_INFORMATIONS);
ImGui::End();
}
if (show_log_overlay)
{
if (show_log_overlay) {
ImGui::Begin("Game log", &show_log_overlay, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::TextUnformatted(log_content.c_str());
ImGui::End();
@@ -214,30 +232,6 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
SaveSettings();
}
// Sliders
ImGui::TableSetColumnIndex(0);
if (ImGui::CollapsingHeader("In game additional FOV", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::SetNextItemWidth(180 * scale);
if (ImGui::SliderInt("##FOVValue", &worldFOVvalue, -20, 70)) {
if (SetFOV) SetFOV(worldFOVvalue);
SaveSettings();
}
}
if (ImGui::CollapsingHeader("Camera distance (*)", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::SetNextItemWidth(150 * scale);
if (ImGui::SliderFloat("##CameraDistanceValue", &cameraDistance, 0, 3, "%.2f")) {
if (SetCameraDistance) SetCameraDistance(cameraDistance); 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)) {
@@ -247,55 +241,25 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
ImGui::TableNextRow();
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::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("This fix will disable all fogs including volumetric fog.");
ImGui::EndTooltip();
}
for (int i = 0; i < 4; ++i) DrawFixCheckbox(individualFixes[i]);
ImGui::TableSetColumnIndex(1);
if (ImGui::Checkbox("Ultrawide", &ultrawide_fix_enabled)) {
if (SetFixesEnabled) SetFixesEnabled(GameFixes::UltraWide, ultrawide_fix_enabled);
SaveSettings();
}
if (ImGui::Checkbox("Depth of field", &DOF_fix_enabled)) {
if (SetFixesEnabled) SetFixesEnabled(GameFixes::DOF, DOF_fix_enabled);
SaveSettings();
}
if (ImGui::Checkbox("Chromatic aberrations", &CA_fix_enabled)) {
if (SetFixesEnabled) SetFixesEnabled(GameFixes::ChromaticAberrations ,CA_fix_enabled);
SaveSettings();
}
if (ImGui::Checkbox("Volumetric fog", &VolumetricFog_fix_enabled)) {
if (SetFixesEnabled) SetFixesEnabled(GameFixes::VolumetricFog, VolumetricFog_fix_enabled);
SaveSettings();
}
for (int i = 4; i < IM_ARRAYSIZE(individualFixes); ++i) DrawFixCheckbox(individualFixes[i]);
ImGui::EndTable();
ImGui::EndTable();
}
}
ImGui::EndTable();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 2);
if (ImGui::BeginTable("FixesSliders", 2, ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
DrawSlider2(sliders[0], 200);
DrawSlider2(sliders[1], 200);
ImGui::TableSetColumnIndex(1);
DrawSlider2(sliders[2], 200);
ImGui::EndTable();
}
}
// Fix status
@@ -305,7 +269,7 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
GameInfos infos{};
GetGameInfos(&infos);
if (infos.consoleEnabled)
ImGui::Text("Console enabled and bound to key Tilde");
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);
}
@@ -313,8 +277,7 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
}
// Main dll intrance
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID)
{
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID) {
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH: