Files
ReshadePluginsAddon/SilentHillf/dllmain.cpp

396 lines
18 KiB
C++
Raw Normal View History

2025-09-27 20:47:10 +02:00
#define IMGUI_DISABLE_INCLUDE_IMCONFIG_H
#define IMGUI_HAS_DOCK 1
#include "GameInformations.h"
#include "inicpp.h"
2025-09-27 20:47:10 +02:00
#include <imgui.h>
#include <reshade.hpp>
#include <string>
#include <Windows.h>
// Screen informations
static int screenWidth = GetSystemMetrics(SM_CXSCREEN);
static int screenHeight = GetSystemMetrics(SM_CYSCREEN);
static float aspectRatio = (float)screenWidth / screenHeight;
// Core game dll functions declarations
typedef void (*SetBoolFn)(bool, bool);
typedef void (*SetIntFn)(int);
typedef void (*SetFloatFn)(float);
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 SetDOFFixEnabled = nullptr;
static SetBoolFn SetCAFixEnabled = nullptr;
static SetBoolFn SetVignettingFixEnabled = nullptr;
static SetBoolFn SetCameraFixEnabled = nullptr;
static SetBoolFn SetCutscenesFixEnabled = nullptr;
static SetBoolFn SetCutscenesFPSFixEnabled = nullptr;
2025-10-01 14:06:52 +02:00
static SetBoolFn SetVolumetricFogFixEnabled = nullptr;
static SetBoolFn SetFogDensityFixEnabled = nullptr;
static SetBoolFn SetFogMaxOpacityFixEnabled = nullptr;
2025-09-27 20:47:10 +02:00
static SetIntFn SetFOV = nullptr;
static SetFloatFn SetCameraDistance = nullptr;
2025-10-01 14:06:52 +02:00
static SetFloatFn SetFogDensity = nullptr;
static SetFloatFn SetFogMaxOpacity = nullptr;
static GetGameInfosStruct GetGameInfos = nullptr;
2025-09-27 20:47:10 +02:00
// Plugin variables for checkboxes and sliders
static bool fov_fix_enabled = false;
static bool DOF_fix_enabled = false;
static bool CA_fix_enabled = false;
static bool Vignetting_fix_enabled = false;
static bool camera_fix_enabled = false;
static bool cutscenes_fix_enabled = false;
static bool cutscenes_FPS_fix_enabled = false;
2025-10-01 14:06:52 +02:00
static bool volumetric_fog_fix_enabled = false;
static bool Fog_density_fix_enabled = false;
static bool Fog_max_opacity_fix_enabled = false;
2025-09-27 20:47:10 +02:00
static bool fix_enabled = false;
static int worldFOVvalue = 0;
static float cameraDistanceValue = 1.f;
static float fogDensityValue = 0.1f;
static float fogMaxOpacityValue = 1.f;
2025-09-27 20:47:10 +02:00
static bool popup_Informations = false;
// Plugin settings
const std::string SETTINGS_FILE = "./pluginsettings.ini";
const char* FIX_VERSION = "1.0.4";
const char* FIX_INFORMATIONS = "This fix allows to:\n - Control FOV in game.\n - Control camera distance.\n - Unlock cutscenes FPS and enable ultrawide.\n - Disable depth of field.\n - Disable chromatic aberrations.\n - Disable vignetting.\n - Control fog.\n - Re enable console.\n\nDisabling Fog will not entirely remove it.";
2025-09-27 20:47:10 +02:00
const char* DONATION_URL = "https://buymeacoffee.com/k4sh44";
// Scaling factor based on screen resolution
float scale = 1.f;
inline std::string toStringPrecision(float value, int precision) {
char buffer[64];
std::snprintf(buffer, sizeof(buffer), ("%." + std::to_string(precision) + "f").c_str(), value);
return std::string(buffer);
}
2025-09-27 20:47:10 +02:00
// Load and unload game core dll functions /!\ necessary
static void LoadFixDLL()
{
if (InterlockedCompareExchange(&g_coreInitialized, 1, 0) != 0)
return;
if (GetModuleHandleA("SilentHillfCore.dll") == nullptr) {
fixLib = LoadLibraryA("SilentHillfCore.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");
SetDOFFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetDOFFixEnabled");
SetCAFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetCAFixEnabled");
SetVignettingFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetVignettingFixEnabled");
2025-10-01 14:06:52 +02:00
SetVolumetricFogFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetVolumetricFogFixEnabled");
SetFogDensityFixEnabled = (SetBoolFn)GetProcAddress(fixLib,"SetFogDensityFixEnabled");
SetFogMaxOpacityFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetFogMaxOpacityFixEnabled");
SetCameraFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetCameraFixEnabled");
SetCutscenesFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetCutscenesFixEnabled");
SetCutscenesFPSFixEnabled = (SetBoolFn)GetProcAddress(fixLib, "SetCutscenesFPSFixEnabled");
2025-09-27 20:47:10 +02:00
SetFOV = (SetIntFn)GetProcAddress(fixLib, "SetFOV");
SetCameraDistance = (SetFloatFn)GetProcAddress(fixLib, "SetCameraDistance");
2025-10-01 14:06:52 +02:00
SetFogDensity = (SetFloatFn)GetProcAddress(fixLib,"SetFogDensity");
SetFogMaxOpacity = (SetFloatFn)GetProcAddress(fixLib, "SetFogMaxOpacity");
GetGameInfos = (GetGameInfosStruct)GetProcAddress(fixLib, "GetGameInfos");
2025-09-27 20:47:10 +02:00
// Apply initial values loaded from settings
if (SetFOV) SetFOV(worldFOVvalue);
if (SetCameraDistance) SetCameraDistance(cameraDistanceValue);
2025-10-01 14:06:52 +02:00
if (SetFogDensity) SetFogDensity(fogDensityValue);
if (SetFogMaxOpacity) SetFogMaxOpacity(fogMaxOpacityValue);
2025-09-27 20:47:10 +02:00
if (SetFOVFixEnabled) SetFOVFixEnabled(fov_fix_enabled, true);
if (SetCameraFixEnabled) SetCameraFixEnabled(camera_fix_enabled, true);
if (SetCutscenesFixEnabled) SetCutscenesFixEnabled(cutscenes_fix_enabled, true);
if (SetCutscenesFPSFixEnabled) SetCutscenesFPSFixEnabled(cutscenes_FPS_fix_enabled, true);
2025-09-27 20:47:10 +02:00
if (SetDOFFixEnabled) SetDOFFixEnabled(DOF_fix_enabled, true);
if (SetCAFixEnabled) SetCAFixEnabled(CA_fix_enabled, true);
if (SetVignettingFixEnabled) SetVignettingFixEnabled(Vignetting_fix_enabled, true);
2025-10-01 14:06:52 +02:00
if (SetVolumetricFogFixEnabled) SetVolumetricFogFixEnabled(volumetric_fog_fix_enabled, true);
if (SetFogDensityFixEnabled) SetFogDensityFixEnabled(Fog_density_fix_enabled, true);
if (SetFogMaxOpacityFixEnabled) SetFogMaxOpacityFixEnabled(Fog_max_opacity_fix_enabled, true);
2025-09-27 20:47:10 +02:00
if (SetFixEnabled) SetFixEnabled(fix_enabled, true);
}
}
// Settings functions
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",
" ",
"Controls if fix mod (globally) is enabled" });
pluginIniFile["1#General fix"]["Enabled"] = fix_enabled;
pluginIniFile["2#Individual fix"].setComment("Controls each fix individually");
pluginIniFile["2#Individual fix"]["FOV"] = fov_fix_enabled;
pluginIniFile["2#Individual fix"]["Camera"] = camera_fix_enabled;
pluginIniFile["2#Individual fix"]["Cutscenes"] = cutscenes_fix_enabled;
pluginIniFile["2#Individual fix"]["CutscenesFPS"] = cutscenes_FPS_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"]["Volumetric fog"] = volumetric_fog_fix_enabled;
pluginIniFile["2#Individual fix"]["Fog density"] = Fog_density_fix_enabled;
pluginIniFile["2#Individual fix"]["Fog opacity"] = Fog_max_opacity_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"]["Fog density"] = fogDensityValue;
pluginIniFile["3#Fixes tuning"]["Fog opacity"] = fogMaxOpacityValue;
pluginIniFile.save(SETTINGS_FILE);
2025-09-27 20:47:10 +02:00
}
static void LoadSettings()
{
ini::IniFile pluginIniFile;
try {
pluginIniFile.load(SETTINGS_FILE);
fix_enabled = pluginIniFile["1#General fix"]["Enabled"].as<bool>();
fov_fix_enabled = pluginIniFile["2#Individual fix"]["FOV"].as<bool>();
camera_fix_enabled = pluginIniFile["2#Individual fix"]["Camera"].as<bool>();
cutscenes_fix_enabled = pluginIniFile["2#Individual fix"]["Cutscenes"].as<bool>();
cutscenes_FPS_fix_enabled = pluginIniFile["2#Individual fix"]["CutscenesFPS"].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>();
volumetric_fog_fix_enabled = pluginIniFile["2#Individual fix"]["Volumetric fog"].as<bool>();
Fog_density_fix_enabled = pluginIniFile["2#Individual fix"]["Fog density"].as<bool>();
Fog_max_opacity_fix_enabled = pluginIniFile["2#Individual fix"]["Fog opacity"].as<bool>();
worldFOVvalue = pluginIniFile["3#Fixes tuning"]["World FOV"].as<int>();
cameraDistanceValue = pluginIniFile["3#Fixes tuning"]["Camera distance"].as<float>();
fogDensityValue = pluginIniFile["3#Fixes tuning"]["Fog density"].as<float>();
fogMaxOpacityValue = pluginIniFile["3#Fixes tuning"]["Fog opacity"].as<float>();
2025-09-27 20:47:10 +02:00
}
catch (const std::exception& e) {}
2025-09-27 20:47:10 +02:00
}
// 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
ImGui::SetNextWindowSize(ImVec2(350 * scale, 150 * scale), ImGuiCond_Once);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.84f, 0.12f, 0.51f, 1.0f)); // red
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.84f, 0.12f, 0.51f, 1.0f)); // red
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.84f, 0.2f, 0.51f, 1.0f)); // red
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.8f, 1.f, 1.f, 1.f)); // white
2025-09-27 20:47:10 +02:00
if (ImGui::Button("Like my work ? Consider donation")) ShellExecuteA(NULL, "open", DONATION_URL, NULL, NULL, SW_SHOWNORMAL); // Donation
ImGui::PopStyleColor(4); // Restore color
2025-09-27 20:47:10 +02:00
ImGui::SameLine();
if (ImGui::Button("Fix informations")) popup_Informations = true; // Fix information
if (popup_Informations)
{
ImGui::Begin("Informations", &popup_Informations);
ImGui::Text("Version : %s", FIX_VERSION);
ImGui::Text(FIX_INFORMATIONS);
ImGui::End();
}
if (ImGui::BeginTable("FixesTable", 2, ImGuiTableFlags_SizingStretchSame)) {
2025-10-01 14:06:52 +02:00
ImGui::TableSetupColumn("LeftFix", ImGuiTableColumnFlags_WidthStretch, 0.3f);
ImGui::TableSetupColumn("RightFix", ImGuiTableColumnFlags_WidthStretch, 0.7f);
2025-09-27 20:47:10 +02:00
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();
}
// 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);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
if (ImGui::Checkbox("FOV", &fov_fix_enabled)) {
if (SetFOVFixEnabled) SetFOVFixEnabled(fov_fix_enabled, false);
SaveSettings();
}
if (ImGui::Checkbox("Cutscenes", &cutscenes_fix_enabled)) {
if (SetCutscenesFixEnabled) SetCutscenesFixEnabled(cutscenes_fix_enabled, false);
SaveSettings();
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("Must be enabled before playing cutscenes.");
ImGui::EndTooltip();
}
2025-09-27 20:47:10 +02:00
if (ImGui::Checkbox("Vignetting", &Vignetting_fix_enabled)) {
if (SetVignettingFixEnabled) SetVignettingFixEnabled(Vignetting_fix_enabled, false);
SaveSettings();
}
2025-10-01 14:06:52 +02:00
if (ImGui::Checkbox("Fog density", &Fog_density_fix_enabled)) {
if (SetFogDensityFixEnabled) SetFogDensityFixEnabled(Fog_density_fix_enabled, false);
2025-09-27 20:47:10 +02:00
SaveSettings();
}
2025-10-01 14:06:52 +02:00
if (ImGui::Checkbox("Fog opacity", &Fog_max_opacity_fix_enabled)) {
if (SetFogMaxOpacityFixEnabled) SetFogMaxOpacityFixEnabled(Fog_max_opacity_fix_enabled, false);
SaveSettings();
2025-09-27 20:47:10 +02:00
}
ImGui::TableSetColumnIndex(1);
if (ImGui::Checkbox("Camera", &camera_fix_enabled)) {
if (SetCameraFixEnabled) SetCameraFixEnabled(camera_fix_enabled, false);
SaveSettings();
}
if (ImGui::Checkbox("Cutscenes FPS", &cutscenes_FPS_fix_enabled)) {
if (SetCutscenesFPSFixEnabled) SetCutscenesFPSFixEnabled(cutscenes_FPS_fix_enabled, false);
SaveSettings();
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("Must be enabled before playing cutscenes.");
ImGui::EndTooltip();
}
2025-09-27 20:47:10 +02:00
if (ImGui::Checkbox("Depth of field", &DOF_fix_enabled)) {
if (SetDOFFixEnabled) SetDOFFixEnabled(DOF_fix_enabled, false);
SaveSettings();
}
if (ImGui::Checkbox("Chromatic aberrations", &CA_fix_enabled)) {
if (SetCAFixEnabled) SetCAFixEnabled(CA_fix_enabled, false);
SaveSettings();
}
2025-10-01 14:06:52 +02:00
if (ImGui::Checkbox("Volumetric fog", &volumetric_fog_fix_enabled)) {
if (SetVolumetricFogFixEnabled) SetVolumetricFogFixEnabled(volumetric_fog_fix_enabled, false);
SaveSettings();
}
2025-09-27 20:47:10 +02:00
ImGui::EndTable();
}
}
ImGui::EndTable();
}
2025-10-01 14:06:52 +02:00
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 2 * style.ItemSpacing.y);
if (ImGui::BeginTable("FixesSliders", 2, ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableNextRow();
// Sliders
ImGui::TableSetColumnIndex(0);
if (ImGui::CollapsingHeader("In game additional FOV", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::SetNextItemWidth(180 * scale);
if (ImGui::SliderInt("##FOVValue", &worldFOVvalue, -20, 50)) {
if (SetFOV) SetFOV(worldFOVvalue);
SaveSettings();
}
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("This will affect in game FOV only.");
ImGui::EndTooltip();
}
if (ImGui::CollapsingHeader("Camera distance (*)", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::SetNextItemWidth(180 * scale);
if (ImGui::SliderFloat("##CameraDistanceValue", &cameraDistanceValue, 0, 3, "%.2f")) {
2025-10-01 14:06:52 +02:00
if (SetCameraDistance) SetCameraDistance(cameraDistanceValue);
SaveSettings();
}
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("Value is a multiplier.");
ImGui::EndTooltip();
}
ImGui::TableSetColumnIndex(1);
if (ImGui::CollapsingHeader("Fog density (*)", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::SetNextItemWidth(180 * scale);
if (ImGui::SliderFloat("##FogDensityValue", &fogDensityValue, 0, 5, "%.2f")) {
2025-10-01 14:06:52 +02:00
if (SetFogDensity) SetFogDensity(fogDensityValue);
SaveSettings();
}
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("This will override engine dynamic value.");
ImGui::EndTooltip();
}
if (ImGui::CollapsingHeader("Fog opacity (*)", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::SetNextItemWidth(180 * scale);
if (ImGui::SliderFloat("##FogOpacityValue", &fogMaxOpacityValue, 0, 1, "%.2f")) {
2025-10-01 14:06:52 +02:00
if (SetFogMaxOpacity) SetFogMaxOpacity(fogMaxOpacityValue);
SaveSettings();
}
}
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("This will override engine dynamic value.");
ImGui::EndTooltip();
}
ImGui::EndTable();
}
2025-09-27 20:47:10 +02:00
// 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 Tilde");
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);
2025-10-01 14:06:52 +02:00
ImGui::TextColored(ImColor(48, 179, 25), "Default fog density: %.3f, opacity: %3.f", infos.defaultFogDensity, infos.fogMaxOpacity);
}
2025-09-27 20:47:10 +02:00
}
}
// Main dll intrance
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;
LoadSettings();
reshade::register_overlay("Silent Hill f", &on_overlay_draw);
reshade::register_event<reshade::addon_event::init_effect_runtime>(
[](reshade::api::effect_runtime* runtime) {
LoadFixDLL();
});
break;
case DLL_PROCESS_DETACH:
reshade::unregister_addon(hinstDLL);
break;
}
return TRUE;
}