Add ini library. Minors improvements

This commit is contained in:
2025-10-11 22:25:28 +02:00
parent 714a3c5c38
commit aae37745ff

View File

@@ -1,9 +1,10 @@
#define IMGUI_DISABLE_INCLUDE_IMCONFIG_H #define IMGUI_DISABLE_INCLUDE_IMCONFIG_H
#define IMGUI_HAS_DOCK 1 #define IMGUI_HAS_DOCK 1
#include "GameInformations.h"
#include "inicpp.h"
#include <imgui.h> #include <imgui.h>
#include <reshade.hpp> #include <reshade.hpp>
#include <fstream>
#include <string> #include <string>
#include <Windows.h> #include <Windows.h>
@@ -34,11 +35,7 @@ static SetIntFn SetFOV = nullptr;
static SetFloatFn SetCameraDistance = nullptr; static SetFloatFn SetCameraDistance = nullptr;
static SetIntFn SetCameraHeight = nullptr; static SetIntFn SetCameraHeight = nullptr;
static SetIntFn SetHUD = nullptr; static SetIntFn SetHUD = nullptr;
static GetGameInfosStruct GetGameInfos = nullptr;
static GetFloatFn GetFOVIn = nullptr;
static GetFloatFn GetCompensadedFOV = nullptr;
static GetFloatFn GetFOVOut = nullptr;
static GetBoolFn GetConsoleEnabled = nullptr;
// Plugin variables for checkboxes and sliders // Plugin variables for checkboxes and sliders
static bool fov_fix_enabled = false; static bool fov_fix_enabled = false;
@@ -55,25 +52,15 @@ static float cameraDistancevalue = 1.f;
static int cameraHeightvalue = -15; static int cameraHeightvalue = -15;
static int HUDvalue = 0; static int HUDvalue = 0;
// Overlay popup
static bool show_log_overlay = false;
static std::string log_content;
static bool popup_Informations = false; static bool popup_Informations = false;
// Plugin settings // Plugin settings
const char* SETTINGS_FILE = "PluginSettings.ini"; const char* SETTINGS_FILE = "pluginSettings.ini";
const char* GENERAL_FIX_SETTING = "GeneralFIX="; const char* FIX_VERSION = "1.0.8";
const char* WORLD_FOV_FIX_SETTING = "WorldFOVFIX="; const char* FIX_INFORMATIONS = "This fix allows to:\n - Control FOV in game.\n - Disable pillar boxing in cutscences.\n - Control camera distance and height.\n - Control HUD safezone.\n - Disable depth of field.\n - Disable chromatic aberrations.\n - Disable vignetting.\n - Disable fog.\n - Re enable console.\n\nDisabling pillar boxing will compensate FOV\nfor main menu and cutscenes.";
const char* ASPECT_FIX_SETTING = "AspectFIX=";
const char* CAMERA_FIX_SETTING = "CameraFIX=";
const char* HUD_FIX_SETTING = "HUDFIX=";
const char* DOF_FIX_SETTING = "DOFFIX=";
const char* CA_FIX_SETTING = "CAFIX=";
const char* VIGNETTING_FIX_SETTING = "VignettingFIX=";
const char* FOG_FIX_SETTING = "FogFIX=";
const char* WORLD_FOV_SETTING = "WorldFOV=";
const char* CAMERA_DISTANCE_SETTING = "CameraDistance=";
const char* CAMERA_HEIGHT_SETTING = "CameraHeight=";
const char* HUD_SETTING = "HUDValue=";
const char* FIX_VERSION = "1.0.7";
const char* FIX_INFORMATIONS = "This fix allows to:\n - Control FOV in game.\n - Disable pillar boxing in cutscences.\n - Control camera.\n - Control HUD safezone.\n - Disable depth of field.\n - Disable chromatic aberrations.\n - Disable vignetting.\n - Disable FOG.\n - Re enable console.\n\nDisabling pillar boxing will compensate FOV\nfor main menu and cutscenes.\nDisabling Fog will not entirely remove it.";
const char* DONATION_URL = "https://buymeacoffee.com/k4sh44"; const char* DONATION_URL = "https://buymeacoffee.com/k4sh44";
// Scaling factor based on screen resolution // Scaling factor based on screen resolution
@@ -106,10 +93,7 @@ static void LoadFixDLL()
SetCameraDistance = (SetFloatFn)GetProcAddress(fixLib, "SetCameraDistance"); SetCameraDistance = (SetFloatFn)GetProcAddress(fixLib, "SetCameraDistance");
SetCameraHeight = (SetIntFn)GetProcAddress(fixLib, "SetCameraHeight"); SetCameraHeight = (SetIntFn)GetProcAddress(fixLib, "SetCameraHeight");
SetHUD = (SetIntFn)GetProcAddress(fixLib, "SetHUD"); SetHUD = (SetIntFn)GetProcAddress(fixLib, "SetHUD");
GetFOVIn = (GetFloatFn)GetProcAddress(fixLib, "GetFOVIn"); GetGameInfos = (GetGameInfosStruct)GetProcAddress(fixLib, "GetGameInfos");
GetCompensadedFOV = (GetFloatFn)GetProcAddress(fixLib, "GetCompensatedFOV");
GetFOVOut = (GetFloatFn)GetProcAddress(fixLib, "GetFOVOut");;
GetConsoleEnabled = (GetBoolFn)GetProcAddress(fixLib, "GetConsoleEnabled");
// Apply initial values loaded from settings // Apply initial values loaded from settings
if (SetFOV) SetFOV(worldFOVvalue); if (SetFOV) SetFOV(worldFOVvalue);
@@ -131,90 +115,64 @@ static void LoadFixDLL()
// Settings functions // Settings functions
static void SaveSettings() static void SaveSettings()
{ {
std::ofstream file(SETTINGS_FILE); ini::IniFile pluginIniFile;
if (file.is_open()) pluginIniFile["1#General fix"].setComment(std::vector<std::string>{ "The following sections are saved by plugin",
{ "You should not need to modify them",
file << GENERAL_FIX_SETTING << (fix_enabled ? "1" : "0") << "\n"; " ",
file << WORLD_FOV_FIX_SETTING << (fov_fix_enabled ? "1" : "0") << "\n"; "Controls if fix mod (globally) is enabled" });
file << ASPECT_FIX_SETTING << (Aspect_fix_enabled ? "1" : "0") << "\n"; pluginIniFile["1#General fix"]["Enabled"] = fix_enabled;
file << CAMERA_FIX_SETTING << (camera_fix_enabled ? "1" : "0") << "\n"; pluginIniFile["2#Individual fix"].setComment("Controls each fix individually");
file << HUD_FIX_SETTING << (HUD_fix_enabled ? "1" : "0") << "\n"; pluginIniFile["2#Individual fix"]["FOV"] = fov_fix_enabled;
file << DOF_FIX_SETTING << (DOF_fix_enabled ? "1" : "0") << "\n"; pluginIniFile["2#Individual fix"]["Aspect ratio"] = Aspect_fix_enabled;
file << CA_FIX_SETTING << (CA_fix_enabled ? "1" : "0") << "\n"; pluginIniFile["2#Individual fix"]["Camera"] = camera_fix_enabled;
file << VIGNETTING_FIX_SETTING << (Vignetting_fix_enabled ? "1" : "0") << "\n"; pluginIniFile["2#Individual fix"]["HUD"] = HUD_fix_enabled;
file << FOG_FIX_SETTING << (Fog_fix_enabled ? "1" : "0") << "\n"; pluginIniFile["2#Individual fix"]["DOF"] = DOF_fix_enabled;
file << WORLD_FOV_SETTING << worldFOVvalue << "\n"; pluginIniFile["2#Individual fix"]["Chromatic aberrations"] = CA_fix_enabled;
file << CAMERA_DISTANCE_SETTING << cameraDistancevalue << "\n"; pluginIniFile["2#Individual fix"]["Vignetting"] = Vignetting_fix_enabled;
file << CAMERA_HEIGHT_SETTING << cameraHeightvalue << "\n"; pluginIniFile["2#Individual fix"]["Fog"] = Fog_fix_enabled;
file << HUD_SETTING << HUDvalue << "\n"; pluginIniFile["3#Fixes tuning"].setComment("Individual fix fine tune");
file.close(); pluginIniFile["3#Fixes tuning"]["World FOV"] = worldFOVvalue;
} pluginIniFile["3#Fixes tuning"]["Camera distance"] = cameraDistancevalue;
pluginIniFile["3#Fixes tuning"]["Camera height"] = cameraHeightvalue;
pluginIniFile["3#Fixes tuning"]["HUD"] = HUDvalue;
pluginIniFile.save(SETTINGS_FILE);
} }
static void LoadSettings() static void LoadSettings()
{ {
std::ifstream file(SETTINGS_FILE); ini::IniFile pluginIniFile;
if (file.is_open()) try {
{ pluginIniFile.load(SETTINGS_FILE);
std::string line; fix_enabled = pluginIniFile["1#General fix"]["Enabled"].as<bool>();
while (std::getline(file, line)) fov_fix_enabled = pluginIniFile["2#Individual fix"]["FOV"].as<bool>();
{ Aspect_fix_enabled = pluginIniFile["2#Individual fix"]["Aspect ratio"].as<bool>();
if (line.find(GENERAL_FIX_SETTING) == 0) camera_fix_enabled = pluginIniFile["2#Individual fix"]["Camera"].as<bool>();
{ HUD_fix_enabled = pluginIniFile["2#Individual fix"]["HUD"].as<bool>();
std::string val = line.substr(strlen(GENERAL_FIX_SETTING)); DOF_fix_enabled = pluginIniFile["2#Individual fix"]["DOF"].as<bool>();
fix_enabled = (val == "1" || val == "true"); CA_fix_enabled = pluginIniFile["2#Individual fix"]["Chromatic aberrations"].as<bool>();
} Vignetting_fix_enabled = pluginIniFile["2#Individual fix"]["Vignetting"].as<bool>();
else if (line.find(WORLD_FOV_FIX_SETTING) == 0) Fog_fix_enabled = pluginIniFile["2#Individual fix"]["Fog"].as<bool>();
{ worldFOVvalue = pluginIniFile["3#Fixes tuning"]["World FOV"].as<int>();
std::string val = line.substr(strlen(WORLD_FOV_FIX_SETTING)); cameraDistancevalue = pluginIniFile["3#Fixes tuning"]["Camera distance"].as<float>();
fov_fix_enabled = (val == "1" || val == "true"); cameraHeightvalue = pluginIniFile["3#Fixes tuning"]["Camera height"].as<float>();
} HUDvalue = pluginIniFile["3#Fixes tuning"]["HUD"].as<int>();
else if (line.find(CAMERA_FIX_SETTING) == 0)
{
std::string val = line.substr(strlen(CAMERA_FIX_SETTING));
camera_fix_enabled = (val == "1" || val == "true");
}
else if (line.find(HUD_FIX_SETTING) == 0)
{
std::string val = line.substr(strlen(HUD_FIX_SETTING));
HUD_fix_enabled = (val == "1" || val == "true");
}
else if (line.find(ASPECT_FIX_SETTING) == 0)
{
std::string val = line.substr(strlen(ASPECT_FIX_SETTING));
Aspect_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(CA_FIX_SETTING) == 0)
{
std::string val = line.substr(strlen(CA_FIX_SETTING));
CA_fix_enabled = (val == "1" || val == "true");
}
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");
}
else if (line.find(WORLD_FOV_SETTING) == 0)
worldFOVvalue = std::stoi(line.substr(strlen(WORLD_FOV_SETTING)));
else if (line.find(CAMERA_DISTANCE_SETTING) == 0)
cameraDistancevalue = std::stof(line.substr(strlen(CAMERA_DISTANCE_SETTING)));
else if (line.find(CAMERA_HEIGHT_SETTING) == 0)
cameraHeightvalue = std::stoi(line.substr(strlen(CAMERA_HEIGHT_SETTING)));
else if (line.find(HUD_SETTING) == 0)
HUDvalue = std::stoi(line.substr(strlen(HUD_SETTING)));
}
file.close();
} }
catch (const std::exception& e) {}
}
// Read plugin log file
void read_log_file(const std::string& filename) {
std::ifstream file(filename);
if (!file.is_open())
{
log_content = "Impossible to open file : " + filename;
return;
}
std::ostringstream ss;
ss << file.rdbuf();
log_content = ss.str();
} }
// Initialize ImGui widgets for Reshade // Initialize ImGui widgets for Reshade
@@ -228,18 +186,35 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
ImGui::SetNextWindowSize(ImVec2(350 * scale, 150 * scale), ImGuiCond_Once); ImGui::SetNextWindowSize(ImVec2(350 * scale, 150 * scale), ImGuiCond_Once);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.84f, 0.12f, 0.51f, 1.0f)); // pink
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.84f, 0.12f, 0.51f, 1.0f)); // pink
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.84f, 0.2f, 0.51f, 1.0f)); // pink
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.8f, 1.f, 1.f, 1.f)); // white
if (ImGui::Button("Like my work ? Consider donation")) ShellExecuteA(NULL, "open", DONATION_URL, NULL, NULL, SW_SHOWNORMAL); // Donation if (ImGui::Button("Like my work ? Consider donation")) ShellExecuteA(NULL, "open", DONATION_URL, NULL, NULL, SW_SHOWNORMAL); // Donation
ImGui::PopStyleColor(4); // Restore color
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Fix informations")) popup_Informations = true; // Fix information if (ImGui::Button("Fix informations")) popup_Informations = true; // Fix information
ImGui::SameLine();
if (ImGui::Button("View logs")) {
read_log_file("HellIsUs.log");
show_log_overlay = true; // Fix information
}
if (popup_Informations) if (popup_Informations)
{ {
ImGui::Begin("Informations", &popup_Informations); ImGui::Begin("Informations", &popup_Informations, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("Version : %s", FIX_VERSION); ImGui::Text("Version : %s", FIX_VERSION);
ImGui::Text(FIX_INFORMATIONS); ImGui::Text(FIX_INFORMATIONS);
ImGui::End(); ImGui::End();
} }
if (show_log_overlay)
{
ImGui::Begin("Game log", &show_log_overlay, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::TextUnformatted(log_content.c_str());
ImGui::End();
}
if (ImGui::BeginTable("FixesTable", 2, ImGuiTableFlags_SizingStretchSame)) { if (ImGui::BeginTable("FixesTable", 2, ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableSetupColumn("LeftFix", ImGuiTableColumnFlags_WidthStretch, 0.4f); ImGui::TableSetupColumn("LeftFix", ImGuiTableColumnFlags_WidthStretch, 0.4f);
ImGui::TableSetupColumn("RightFix", ImGuiTableColumnFlags_WidthStretch, 0.6f); ImGui::TableSetupColumn("RightFix", ImGuiTableColumnFlags_WidthStretch, 0.6f);
@@ -266,7 +241,7 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
if (ImGui::CollapsingHeader("Camera distance (*)", ImGuiTreeNodeFlags_DefaultOpen)) if (ImGui::CollapsingHeader("Camera distance (*)", ImGuiTreeNodeFlags_DefaultOpen))
{ {
ImGui::SetNextItemWidth(150 * scale); ImGui::SetNextItemWidth(150 * scale);
if (ImGui::SliderFloat("##CameraDistanceValue", &cameraDistancevalue, 0, 3)) { if (ImGui::SliderFloat("##CameraDistanceValue", &cameraDistancevalue, 0, 3, "%.2f")) {
if (SetCameraDistance) SetCameraDistance(cameraDistancevalue); SaveSettings(); if (SetCameraDistance) SetCameraDistance(cameraDistancevalue); SaveSettings();
} }
} }
@@ -381,10 +356,14 @@ static void on_overlay_draw(reshade::api::effect_runtime* runtime)
// Fix status // Fix status
if (ImGui::CollapsingHeader("Fix informations", ImGuiTreeNodeFlags_DefaultOpen)) { if (ImGui::CollapsingHeader("Fix informations", ImGuiTreeNodeFlags_DefaultOpen)) {
ImGui::Text("Screen width: %d, height: %d, aspect ratio: %.2f", screenWidth, screenHeight, aspectRatio); ImGui::Text("Screen width: %d, height: %d, aspect ratio: %.2f", screenWidth, screenHeight, aspectRatio);
if (GetConsoleEnabled && GetConsoleEnabled()) if (GetGameInfos) {
ImGui::Text("Console enabled and bound to key F2"); GameInfos infos{};
if (GetFOVIn && GetCompensadedFOV && GetFOVOut) GetGameInfos(&infos);
ImGui::TextColored(ImColor(48, 179, 25), "FOV In: %.2f, Compensated: %.2f, Out: %.2f", GetFOVIn(), GetCompensadedFOV(), GetFOVOut()); if (infos.consoleEnabled)
ImGui::Text("Console enabled and bound to key F2");
ImGui::TextColored(ImColor(48, 179, 25), "FOV In: %.2f, Compensated: %.2f, Out: %.2f", infos.FOVIn, infos.CompensatedFOV, infos.FOVOut);
ImGui::TextColored(ImColor(48, 179, 25), "Camera distance In: %.2f, Out: %.2f", infos.cameraIn, infos.cameraOut);
}
} }
} }