Add cutscenes framerate unlock. Fog fix improvement. Code refactoring
This commit is contained in:
@@ -1,16 +1,11 @@
|
|||||||
#include <unordered_set>
|
#include "CommonHeaders.h"
|
||||||
#include "CommonHeaders.h"
|
|
||||||
#include "GameFixes.h"
|
|
||||||
#include "GameInformations.h"
|
|
||||||
#include "ObfuscateString.h"
|
|
||||||
#include "Memory.hpp"
|
|
||||||
#include "Maths.hpp"
|
|
||||||
#include "UEngine.hpp"
|
#include "UEngine.hpp"
|
||||||
#include "SDK/Basic.hpp"
|
#include "SDK/Basic.hpp"
|
||||||
#include "SDK/Engine_classes.hpp"
|
#include "SDK/Engine_classes.hpp"
|
||||||
|
#include "SDK/Cutscenes_classes.hpp"
|
||||||
|
#include "SDK/LevelSequence_classes.hpp"
|
||||||
|
|
||||||
using namespace SDK;
|
using namespace SDK;
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const std::string PLUGIN_NAME = "SilentHill22024";
|
const std::string PLUGIN_NAME = "SilentHill22024";
|
||||||
const std::string PLUGIN_LOG = PLUGIN_NAME + ".log";
|
const std::string PLUGIN_LOG = PLUGIN_NAME + ".log";
|
||||||
@@ -30,13 +25,17 @@ static bool g_Console = false;
|
|||||||
static bool g_fix_enabled = false;
|
static bool g_fix_enabled = false;
|
||||||
static bool g_fov_fix_enabled = false;
|
static bool g_fov_fix_enabled = false;
|
||||||
static bool g_ultrawide_fix_enabled = false;
|
static bool g_ultrawide_fix_enabled = false;
|
||||||
|
static bool g_CutscenesFPS_fix_enabled = false;
|
||||||
static bool g_camera_fix_enabled = false;
|
static bool g_camera_fix_enabled = false;
|
||||||
static bool g_DOF_fix_enabled = false;
|
static bool g_DOF_fix_enabled = false;
|
||||||
static bool g_CA_fix_enabled = false;
|
static bool g_CA_fix_enabled = false;
|
||||||
static bool g_Vignetting_fix_enabled = false;
|
static bool g_Vignetting_fix_enabled = false;
|
||||||
static bool g_Fog_fix_enabled = false;
|
static bool g_Fog_fix_enabled = false;
|
||||||
|
static float g_FogDensity = 0.15f;
|
||||||
|
static float g_FogOpacity = 1.f;
|
||||||
static int g_AdditionalFOVValue = 0;
|
static int g_AdditionalFOVValue = 0;
|
||||||
static float g_CameraDistanceValue = 1.f;
|
static float g_CameraDistanceValue = 1.f;
|
||||||
|
static bool user_inputs_logged = false;
|
||||||
|
|
||||||
// Shared values
|
// Shared values
|
||||||
static float g_FOV_In = 60.f;
|
static float g_FOV_In = 60.f;
|
||||||
@@ -53,21 +52,30 @@ static uint8_t* ProcessEventaddress = nullptr;
|
|||||||
|
|
||||||
// AOB Scan pointers
|
// AOB Scan pointers
|
||||||
static uint8_t* FOVaddress = nullptr;
|
static uint8_t* FOVaddress = nullptr;
|
||||||
|
static uint8_t* Binkaddress = nullptr;
|
||||||
static uint8_t* UltraWideaddress = nullptr;
|
static uint8_t* UltraWideaddress = nullptr;
|
||||||
static uint8_t* Cameraaddress = nullptr;
|
static uint8_t* Cameraaddress = nullptr;
|
||||||
|
static uint8_t* CutscenesFPSaddress = nullptr;
|
||||||
static uint8_t* DOFaddress = nullptr;
|
static uint8_t* DOFaddress = nullptr;
|
||||||
static uint8_t* CAaddress = nullptr;
|
static uint8_t* CAaddress = nullptr;
|
||||||
static uint8_t* Vignettingaddress = nullptr;
|
static uint8_t* Vignettingaddress = nullptr;
|
||||||
static uint8_t* Fogaddress = nullptr;
|
static uint8_t* FogDensityEngineaddress = nullptr;
|
||||||
|
static uint8_t* FogOpacityEngineaddress = nullptr;
|
||||||
|
|
||||||
// Hooking
|
// Hooking
|
||||||
static SafetyHookMid FOVHook{};
|
static SafetyHookMid FOVHook{};
|
||||||
|
static SafetyHookMid FogDensityHook{};
|
||||||
|
static SafetyHookMid FogOpacityHook{};
|
||||||
|
static SafetyHookMid BinkHook{};
|
||||||
static SafetyHookMid CameraHook{};
|
static SafetyHookMid CameraHook{};
|
||||||
|
static SafetyHookMid CutscenesFPSHook{};
|
||||||
static SafetyHookMid DOFHook{};
|
static SafetyHookMid DOFHook{};
|
||||||
|
static SafetyHookMid PEHook{};
|
||||||
|
|
||||||
// Prototypes
|
// Prototypes
|
||||||
static void FOVFixEnabled();
|
static void FOVFixEnabled();
|
||||||
static void UltraWideFixEnabled();
|
static void UltraWideFixEnabled();
|
||||||
|
static void CutsceneFPSFixEnabled();
|
||||||
static void CameraFixEnabled();
|
static void CameraFixEnabled();
|
||||||
static void DOFFixEnabled();
|
static void DOFFixEnabled();
|
||||||
static void CAFixEnabled();
|
static void CAFixEnabled();
|
||||||
@@ -75,148 +83,74 @@ static void VignettingFixEnabled();
|
|||||||
static void FogFixEnabled();
|
static void FogFixEnabled();
|
||||||
static void EnableConsole();
|
static void EnableConsole();
|
||||||
|
|
||||||
extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
|
extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
|
||||||
{
|
|
||||||
g_fix_enabled = enabled;
|
g_fix_enabled = enabled;
|
||||||
if (g_fix_enabled && !AOBScanDone) { // Unreal Engine 5.1.1
|
if (!AOBScanDone) { // Unreal Engine 5.1.1
|
||||||
|
uint8_t* baseModule = reinterpret_cast<uint8_t*>(GetModuleHandleA(nullptr)); // Get game base address
|
||||||
logger->info("--------------- AOB scan started ---------------");
|
logger->info("--------------- AOB scan started ---------------");
|
||||||
if (FOVaddress == nullptr) {
|
constexpr auto FOVStringObfuscated = make_obfuscated<0xF3>("77 ?? 48 8B ?? FF 90 ?? ?? ?? ?? F3 0F ?? ?? ?? 48");
|
||||||
constexpr auto FOVStringObfuscated = make_obfuscated<0x4A>("77 ?? 48 8B ?? FF 90 ?? ?? ?? ?? F3 0F ?? ?? ?? 48");
|
|
||||||
FOVaddress = Memory::AOBScan("", FOVStringObfuscated.decrypt(), PAGE_EXECUTE_READ, logger);
|
|
||||||
|
|
||||||
if (!FOVaddress)
|
|
||||||
logger->warn("FOV signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
|
||||||
else {
|
|
||||||
logger->info("FOV found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(FOVaddress));
|
|
||||||
FOVaddress += 0x10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UltraWideaddress == nullptr) {
|
|
||||||
constexpr auto UltraWideStringObfuscated = make_obfuscated<0x4A>("C7 47 ?? ?? ?? ?? ?? C7 83 ?? ?? ?? ?? ?? ?? ?? ?? 48 8B ?? ?? ?? 48 83");
|
constexpr auto UltraWideStringObfuscated = make_obfuscated<0x4A>("C7 47 ?? ?? ?? ?? ?? C7 83 ?? ?? ?? ?? ?? ?? ?? ?? 48 8B ?? ?? ?? 48 83");
|
||||||
UltraWideaddress = Memory::AOBScan("", UltraWideStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
constexpr auto CameraStringObfuscated = make_obfuscated<0x8D>("E8 ?? ?? ?? ?? F2 0F ?? ?? ?? ?? 48 8D ?? ?? F3 0F ?? ?? ?? ?? ?? ?? 48 8D");
|
||||||
|
constexpr auto CutscenesFPSStringObfuscated = make_obfuscated<0x9F>("FF 95 ?? ?? ?? ?? 48 8B ?? ?? ?? 48 8B ?? ?? ?? 48 89 9F ?? ?? ?? ?? 48 8B ?? ?? ?? 48 8B ?? ?? ?? 48 83 ?? ?? 41 ?? C3");
|
||||||
if (!UltraWideaddress)
|
constexpr auto DOFStringObfuscated = make_obfuscated<0x83>("83 ?? ?? ?? 0F 8E ?? ?? ?? ?? 0F 2F ?? ?? ?? ?? ?? 0F 83 ?? ?? ?? ?? 0F 2F ?? ?? ?? ?? ?? 0F 83");
|
||||||
logger->warn("Aspect ratio signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
|
||||||
else {
|
|
||||||
logger->info("Aspect ratio found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(UltraWideaddress));
|
|
||||||
UltraWideaddress += 0x3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Cameraaddress) {
|
|
||||||
constexpr auto DOFStringObfuscated = make_obfuscated<0x4A>("E8 ?? ?? ?? ?? F2 0F ?? ?? ?? ?? 48 8D ?? ?? F3 0F ?? ?? ?? ?? ?? ?? 48 8D");
|
|
||||||
Cameraaddress = Memory::AOBScan("", DOFStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
|
||||||
|
|
||||||
if (!Cameraaddress)
|
|
||||||
logger->warn("Camera signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
|
||||||
else {
|
|
||||||
logger->info("Camera signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(Cameraaddress));
|
|
||||||
Cameraaddress += 0x17;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DOFaddress) { //
|
|
||||||
// 48 ?? ?? 8B ?? ?? E8 ?? ?? ?? ?? 48 ?? ?? 48 6B ?? ?? 48 8D
|
|
||||||
constexpr auto DOFStringObfuscated = make_obfuscated<0x4A>("83 ?? ?? ?? 0F 8E ?? ?? ?? ?? 0F 2F ?? ?? ?? ?? ?? 0F 83 ?? ?? ?? ?? 0F 2F ?? ?? ?? ?? ?? 0F 83");
|
|
||||||
DOFaddress = Memory::AOBScan("", DOFStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
|
||||||
|
|
||||||
if (!DOFaddress)
|
|
||||||
logger->warn("DOF signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
|
||||||
else {
|
|
||||||
logger->info("DOF signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(DOFaddress));
|
|
||||||
//DOFaddress += 0x3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CAaddress) {
|
|
||||||
constexpr auto CAStringObfuscated = make_obfuscated<0x4A>("7F ?? 89 B3 ?? ?? ?? ?? 8B ?? ?? 39 05 ?? ?? ?? ?? 7E");
|
constexpr auto CAStringObfuscated = make_obfuscated<0x4A>("7F ?? 89 B3 ?? ?? ?? ?? 8B ?? ?? 39 05 ?? ?? ?? ?? 7E");
|
||||||
CAaddress = Memory::AOBScan("", CAStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
constexpr auto VignettingStringObfuscated = make_obfuscated<0xB3>("8B ?? 83 ?? ?? 7D ?? 89 B3 ?? ?? ?? ?? EB ?? 83");
|
||||||
|
constexpr auto FogDensityStringObfuscated = make_obfuscated<0xA0>("0F 2E ?? A0 02 ?? ?? 74 ?? F3 0F ?? ?? ?? ?? ?? ?? E9 ?? ?? ?? ?? C3");
|
||||||
|
constexpr auto FogOpacityStringObfuscated = make_obfuscated<0xBB>("0F 2E ?? 34 03 ?? ?? 74 ?? F3 0F ?? ?? ?? ?? ?? ?? E9 ?? ?? ?? ?? C3");
|
||||||
|
|
||||||
if (!CAaddress)
|
using AOBScan::Make;
|
||||||
logger->warn("Chromatic aberrations signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
using OffsetScan::Make;
|
||||||
else
|
// Prepare all data for scanning
|
||||||
logger->info("Chromatic aberrations signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(CAaddress));
|
std::vector<AOBScanEntry> signatures = {
|
||||||
}
|
Make(&FOVaddress, FOVStringObfuscated, "FOV"),
|
||||||
|
Make(&UltraWideaddress, UltraWideStringObfuscated, "Ultrawide"),
|
||||||
|
Make(&Cameraaddress, CameraStringObfuscated, "Camera"),
|
||||||
|
Make(&CutscenesFPSaddress, CutscenesFPSStringObfuscated, "Cutscene FPS"),
|
||||||
|
Make(&DOFaddress, DOFStringObfuscated, "DOF"),
|
||||||
|
Make(&CAaddress, CAStringObfuscated, "Chromatic aberrations"),
|
||||||
|
Make(&Vignettingaddress, VignettingStringObfuscated, "Vignetting"),
|
||||||
|
Make(&FogDensityEngineaddress, FogDensityStringObfuscated, "Fog density"),
|
||||||
|
Make(&FogOpacityEngineaddress, FogOpacityStringObfuscated, "Fog opacity")
|
||||||
|
};
|
||||||
|
// Scan all signature in a batch
|
||||||
|
Memory::AOBScanBatch(signatures, logger);
|
||||||
|
|
||||||
if (!Vignettingaddress) {
|
if (UltraWideaddress && FOVaddress && Cameraaddress && CutscenesFPSaddress && DOFaddress &&
|
||||||
constexpr auto CAStringObfuscated = make_obfuscated<0x4A>("8B ?? 83 ?? ?? 7D ?? 89 B3 ?? ?? ?? ?? EB ?? 83");
|
CAaddress && Vignettingaddress && FogDensityEngineaddress && FogOpacityEngineaddress)
|
||||||
Vignettingaddress = Memory::AOBScan("", CAStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
|
||||||
|
|
||||||
if (!Vignettingaddress)
|
|
||||||
logger->warn("Vignetting signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
|
||||||
else
|
|
||||||
logger->info("Vignetting signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(Vignettingaddress));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Fogaddress) {
|
|
||||||
constexpr auto FogStringObfuscated = make_obfuscated<0x4A>("75 ?? B3 ?? EB ?? 32 ?? 48 8B ?? ?? ?? 48 ?? ?? 74 ?? E8 ?? ?? ?? ?? 0F ?? ?? 48 8B");
|
|
||||||
Fogaddress = Memory::AOBScan("", FogStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
|
||||||
|
|
||||||
if (!Fogaddress)
|
|
||||||
logger->warn("Fog signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
|
||||||
else {
|
|
||||||
logger->info("Fog signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(Fogaddress));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UltraWideaddress && FOVaddress && Cameraaddress && DOFaddress && CAaddress && Vignettingaddress && Fogaddress) {
|
|
||||||
logger->info("All AOB signatures found. Ready to patch...");
|
logger->info("All AOB signatures found. Ready to patch...");
|
||||||
AOBScanDone = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GObjectsaddress || !AppendStringaddress || !ProcessEventaddress) {
|
if (!GObjectsaddress || !AppendStringaddress || !ProcessEventaddress) {
|
||||||
logger->info("------------ UEngine offsets search ------------");
|
logger->info("------------ UEngine offsets search ------------");
|
||||||
uint8_t* baseModule = reinterpret_cast<uint8_t*>(GetModuleHandleA(nullptr)); // Get game base address
|
|
||||||
|
|
||||||
constexpr auto GObjetcsStringObfuscated = make_obfuscated<0x4A>("48 8B ?? ?? ?? ?? ?? 48 8B ?? ?? 48 8D ?? ?? EB ?? 33");
|
constexpr auto GObjetcsStringObfuscated = make_obfuscated<0x8B>("48 8B ?? ?? ?? ?? ?? 48 8B ?? ?? 48 8D ?? ?? EB ?? 33");
|
||||||
GObjectsaddress = Memory::AOBScan("", GObjetcsStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
constexpr auto AppendStringStringObfuscated = make_obfuscated<0x3D>("48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 48 83 ?? ?? 80 3D ?? ?? ?? ?? ?? 48 ?? F2 8B ?? 48 ?? ?? 74 ?? 4C 8D ?? ?? ?? ?? ?? EB ?? 48 8D ?? ?? ?? ?? ?? E8 ?? ?? ?? ?? 4C");
|
||||||
constexpr auto AppendStringStringObfuscated = make_obfuscated<0x4A>("48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 48 83 ?? ?? 80 3D ?? ?? ?? ?? ?? 48 ?? F2 8B ?? 48 ?? ?? 74 ?? 4C 8D ?? ?? ?? ?? ?? EB ?? 48 8D ?? ?? ?? ?? ?? E8 ?? ?? ?? ?? 4C");
|
constexpr auto ProcessEventStringObfuscated = make_obfuscated<0x81>("40 ?? 56 57 41 ?? 41 ?? 41 ?? 41 ?? 48 81 ?? ?? ?? ?? ?? 48 8D ?? ?? ?? 48 89 ?? ?? ?? ?? ?? 48 8B ?? ?? ?? ?? ?? 48 ?? ?? 48 89 ?? ?? ?? ?? ?? 4D");
|
||||||
AppendStringaddress = Memory::AOBScan("", AppendStringStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
// Prepare all data for scanning
|
||||||
constexpr auto ProcessEventStringObfuscated = make_obfuscated<0x4A>("40 ?? 56 57 41 ?? 41 ?? 41 ?? 41 ?? 48 81 ?? ?? ?? ?? ?? 48 8D ?? ?? ?? 48 89 ?? ?? ?? ?? ?? 48 8B ?? ?? ?? ?? ?? 48 ?? ?? 48 89 ?? ?? ?? ?? ?? 4D");
|
std::vector<OffsetScanEntry> UEoffsetsScans = {
|
||||||
ProcessEventaddress = Memory::AOBScan("", ProcessEventStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
Make(&GObjectsaddress, GObjetcsStringObfuscated, "GObjects", OffsetCalcType::GetOffsetFromOpcode, &Offsets::GObjects, 0x3),
|
||||||
|
Make(&AppendStringaddress, AppendStringStringObfuscated, "AppendString", OffsetCalcType::UE_CalculateOffset, &Offsets::AppendString),
|
||||||
|
Make(&ProcessEventaddress, ProcessEventStringObfuscated, "ProcessEvent", OffsetCalcType::UE_CalculateOffset, &Offsets::ProcessEvent)
|
||||||
|
};
|
||||||
|
// Retrieve all Unreal Engine offsets in a batch
|
||||||
|
Memory::OffsetScanBatch(UEoffsetsScans, baseModule, logger, "");
|
||||||
|
|
||||||
if (!GObjectsaddress)
|
|
||||||
logger->warn("GObjects signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
|
||||||
else {
|
|
||||||
uint32_t gObjectsOffset = static_cast<uint32_t>(Memory::GetOffsetFromOpcode(GObjectsaddress + 0x3) - baseModule);
|
|
||||||
logger->info("GObjects offset is: 0x{:X}.", gObjectsOffset);
|
|
||||||
Offsets::GObjects = static_cast<UC::uint32>(gObjectsOffset); // Update GObjects offset
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!AppendStringaddress)
|
|
||||||
logger->warn("AppendString signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
|
||||||
else {
|
|
||||||
std::optional<uint32_t> gAppendStringOffsetOpt = UE::CalculateOffset("", AppendStringaddress);
|
|
||||||
uint32_t gAppendStringOffset = *gAppendStringOffsetOpt;
|
|
||||||
logger->info("AppendString offset is: 0x{:X}.", gAppendStringOffset);
|
|
||||||
Offsets::AppendString = static_cast<UC::uint32>(gAppendStringOffset);// Update AppendString
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ProcessEventaddress)
|
|
||||||
logger->warn("Process Event signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
|
||||||
else {
|
|
||||||
std::optional<uint32_t> gProcessEventOffsetOpt = UE::CalculateOffset("", ProcessEventaddress);
|
|
||||||
uint32_t gProcessEventOffset = *gProcessEventOffsetOpt;
|
|
||||||
logger->info("Process Event offset is: 0x{:X}.", gProcessEventOffset);
|
|
||||||
Offsets::ProcessEvent = static_cast<UC::uint32>(gProcessEventOffset);// Update ProcessEvent offset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logger->info("-------------- Fixes initialisation -------------");
|
logger->info("-------------- Fixes initialisation -------------");
|
||||||
}
|
}
|
||||||
|
AOBScanDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!init && FOVaddress) FOVFixEnabled();
|
if (!init && FOVaddress) FOVFixEnabled();
|
||||||
if (!init && UltraWideaddress) UltraWideFixEnabled();
|
if (!init && UltraWideaddress) UltraWideFixEnabled();
|
||||||
|
if (!init && CutscenesFPSaddress) CutsceneFPSFixEnabled();
|
||||||
if (!init && Cameraaddress) CameraFixEnabled();
|
if (!init && Cameraaddress) CameraFixEnabled();
|
||||||
if (!init && DOFaddress) DOFFixEnabled();
|
if (!init && DOFaddress) DOFFixEnabled();
|
||||||
if (!init && CAaddress) CAFixEnabled();
|
if (!init && CAaddress) CAFixEnabled();
|
||||||
if (!init && Vignettingaddress) VignettingFixEnabled();
|
if (!init && Vignettingaddress) VignettingFixEnabled();
|
||||||
if (!init && Fogaddress) FogFixEnabled();
|
if (!init && FogDensityEngineaddress && FogOpacityEngineaddress) FogFixEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters for Reshade addon call
|
// Setters for Reshade addon call
|
||||||
extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enabled)
|
extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enabled) { // Set each fix individually
|
||||||
{ // Set each fix individually
|
|
||||||
if (fix == GameFixes::DevConsole) { g_Console = enabled; EnableConsole(); }
|
if (fix == GameFixes::DevConsole) { g_Console = enabled; EnableConsole(); }
|
||||||
if (fix == GameFixes::FOV) { g_fov_fix_enabled = enabled; FOVFixEnabled(); }
|
if (fix == GameFixes::FOV) { g_fov_fix_enabled = enabled; FOVFixEnabled(); }
|
||||||
if (fix == GameFixes::UltraWide) { g_ultrawide_fix_enabled = enabled; UltraWideFixEnabled(); }
|
if (fix == GameFixes::UltraWide) { g_ultrawide_fix_enabled = enabled; UltraWideFixEnabled(); }
|
||||||
@@ -225,18 +159,25 @@ extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enable
|
|||||||
if (fix == GameFixes::ChromaticAberrations) { g_CA_fix_enabled = enabled; CAFixEnabled(); }
|
if (fix == GameFixes::ChromaticAberrations) { g_CA_fix_enabled = enabled; CAFixEnabled(); }
|
||||||
if (fix == GameFixes::Vignetting) { g_Vignetting_fix_enabled = enabled; VignettingFixEnabled(); }
|
if (fix == GameFixes::Vignetting) { g_Vignetting_fix_enabled = enabled; VignettingFixEnabled(); }
|
||||||
if (fix == GameFixes::Fog) { g_Fog_fix_enabled = enabled; FogFixEnabled(); }
|
if (fix == GameFixes::Fog) { g_Fog_fix_enabled = enabled; FogFixEnabled(); }
|
||||||
|
if (fix == GameFixes::Framerate) { g_CutscenesFPS_fix_enabled = enabled; CutsceneFPSFixEnabled(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" __declspec(dllexport) void SetFOV(int fov)
|
extern "C" __declspec(dllexport) void SetFOV(int fov) {
|
||||||
{
|
|
||||||
g_AdditionalFOVValue = fov;
|
g_AdditionalFOVValue = fov;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" __declspec(dllexport) void SetCameraDistance(float cameraDistance)
|
extern "C" __declspec(dllexport) void SetCameraDistance(float cameraDistance) {
|
||||||
{
|
|
||||||
g_CameraDistanceValue = cameraDistance;
|
g_CameraDistanceValue = cameraDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" __declspec(dllexport) void SetFogDensity(float fogDensity) {
|
||||||
|
g_FogDensity = fogDensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" __declspec(dllexport) void SetFogMaxOpacity(float fogMaxOpacity) {
|
||||||
|
g_FogOpacity = fogMaxOpacity;
|
||||||
|
}
|
||||||
|
|
||||||
// Getters for Reshade addon call
|
// Getters for Reshade addon call
|
||||||
extern "C" __declspec(dllexport) void GetGameInfos(GameInfos* infos) {
|
extern "C" __declspec(dllexport) void GetGameInfos(GameInfos* infos) {
|
||||||
if (!infos) return;
|
if (!infos) return;
|
||||||
@@ -249,11 +190,10 @@ extern "C" __declspec(dllexport) void GetGameInfos(GameInfos* infos) {
|
|||||||
infos->consoleEnabled = g_Console_Enabled;
|
infos->consoleEnabled = g_Console_Enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Code injection functions
|
|
||||||
static void FOVFixEnabled() {
|
static void FOVFixEnabled() {
|
||||||
if (g_fix_enabled && (g_fov_fix_enabled || g_ultrawide_fix_enabled) && FOVaddress) {
|
if (g_fix_enabled && (g_fov_fix_enabled || g_ultrawide_fix_enabled) && FOVaddress) {
|
||||||
if (!FOVHook) { // Hook only once
|
if (!FOVHook) { // Hook only once
|
||||||
FOVHook = safetyhook::create_mid(FOVaddress,
|
FOVHook = safetyhook::create_mid(FOVaddress + 0x10,
|
||||||
[](SafetyHookContext& ctx) {
|
[](SafetyHookContext& ctx) {
|
||||||
g_FOV_In = ctx.xmm0.f32[0];
|
g_FOV_In = ctx.xmm0.f32[0];
|
||||||
if (g_fix_enabled && g_ultrawide_fix_enabled)
|
if (g_fix_enabled && g_ultrawide_fix_enabled)
|
||||||
@@ -275,7 +215,7 @@ static void FOVFixEnabled() {
|
|||||||
static void CameraFixEnabled() {
|
static void CameraFixEnabled() {
|
||||||
if (g_fix_enabled && g_camera_fix_enabled && Cameraaddress) {
|
if (g_fix_enabled && g_camera_fix_enabled && Cameraaddress) {
|
||||||
if (!CameraHook) { // Hook only once
|
if (!CameraHook) { // Hook only once
|
||||||
CameraHook = safetyhook::create_mid(Cameraaddress,
|
CameraHook = safetyhook::create_mid(Cameraaddress + 0x17,
|
||||||
[](SafetyHookContext& ctx) {
|
[](SafetyHookContext& ctx) {
|
||||||
g_CameraIn = ctx.xmm1.f32[0];
|
g_CameraIn = ctx.xmm1.f32[0];
|
||||||
ctx.xmm1.f32[0] *= (g_fix_enabled && g_camera_fix_enabled ? g_CameraDistanceValue : 1.f);
|
ctx.xmm1.f32[0] *= (g_fix_enabled && g_camera_fix_enabled ? g_CameraDistanceValue : 1.f);
|
||||||
@@ -310,16 +250,68 @@ static void DOFFixEnabled() {
|
|||||||
logger->info("Depth of field fix disabled");
|
logger->info("Depth of field fix disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void CutsceneFPSFixEnabled() {
|
||||||
|
if (g_fix_enabled && g_CutscenesFPS_fix_enabled && CutscenesFPSaddress) {
|
||||||
|
if (!CutscenesFPSHook) {
|
||||||
|
CutscenesFPSHook = safetyhook::create_mid(CutscenesFPSaddress,
|
||||||
|
[](SafetyHookContext& ctx) {
|
||||||
|
if (!ctx.rcx) return;
|
||||||
|
// Unlock FPS in cinematics ALevelSequenceActor -> ULevelSequencePlayer -> UMovieSceneSequencePlayer -> SetFrameRate
|
||||||
|
ACutscenePlayer* cutscene = reinterpret_cast<ACutscenePlayer*>(ctx.rcx);
|
||||||
|
if (cutscene && cutscene->IsA(ACutscenePlayer::StaticClass())) {
|
||||||
|
if (cutscene->LevelSequenceActor && cutscene->LevelSequenceActor->SequencePlayer) {
|
||||||
|
FFrameRate framerate = { g_CutscenesFPS_fix_enabled ? 240 : 30 , 1 };
|
||||||
|
cutscene->LevelSequenceActor->SequencePlayer->SetFrameRate(framerate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
logger->info("Cutscenes FPS fix enabled");
|
||||||
|
}
|
||||||
|
if (!(g_fix_enabled && g_CutscenesFPS_fix_enabled) && CutscenesFPSaddress)
|
||||||
|
logger->info("Cutscenes FPS fix disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FogFixEnabled() {
|
||||||
|
if (g_fix_enabled && g_Fog_fix_enabled && FogDensityEngineaddress) {
|
||||||
|
if (!FogDensityHook) { // Hook only once
|
||||||
|
FogDensityHook = safetyhook::create_mid(FogDensityEngineaddress,
|
||||||
|
[](SafetyHookContext& ctx) {
|
||||||
|
ctx.xmm1.f32[0] = g_FogDensity;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else FogDensityHook.enable();
|
||||||
|
}
|
||||||
|
if (!(g_fix_enabled && g_Fog_fix_enabled) && FogDensityEngineaddress)
|
||||||
|
if (FogDensityHook) FogDensityHook.disable();
|
||||||
|
|
||||||
|
if (g_fix_enabled && g_Fog_fix_enabled && FogOpacityEngineaddress) {
|
||||||
|
if (!FogOpacityHook) { // Hook only once
|
||||||
|
FogOpacityHook = safetyhook::create_mid(FogOpacityEngineaddress,
|
||||||
|
[](SafetyHookContext& ctx) {
|
||||||
|
ctx.xmm1.f32[0] = g_FogOpacity;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else FogOpacityHook.enable();
|
||||||
|
}
|
||||||
|
if (!(g_fix_enabled && g_Fog_fix_enabled) && FogOpacityEngineaddress)
|
||||||
|
if (FogOpacityHook) FogOpacityHook.disable();
|
||||||
|
|
||||||
|
if (g_fix_enabled && g_Fog_fix_enabled && FogDensityEngineaddress && FogOpacityEngineaddress)
|
||||||
|
logger->info("Fog fix enabled");
|
||||||
|
if (!(g_fix_enabled && g_Fog_fix_enabled) && FogDensityEngineaddress && FogOpacityEngineaddress)
|
||||||
|
logger->info("Fog fix disabled");
|
||||||
|
}
|
||||||
|
|
||||||
// Memory patch fixes
|
// Memory patch fixes
|
||||||
static void UltraWideFixEnabled() {
|
static void UltraWideFixEnabled() {
|
||||||
if (g_fix_enabled && g_ultrawide_fix_enabled && UltraWideaddress) {
|
if (g_fix_enabled && g_ultrawide_fix_enabled && UltraWideaddress) {
|
||||||
const char* newAspectRatio = Memory::Float32ToHexBytes(aspectRatio); // Converts new apsect ratio in 4 char bytes
|
const char* newAspectRatio = Memory::Float32ToHexBytes(aspectRatio); // Converts new apsect ratio in 4 char bytes
|
||||||
Memory::PatchBytes(UltraWideaddress, newAspectRatio, 4); // mov[rdi + 48], 3FE38E39 <== patch here
|
Memory::PatchBytes(UltraWideaddress + 0x3, newAspectRatio, 4); // mov[rdi + 48], 3FE38E39 <== patch here
|
||||||
logger->info("Ultra wide fix enabled");
|
logger->info("Ultra wide fix enabled");
|
||||||
FOVFixEnabled();
|
|
||||||
}
|
}
|
||||||
if (!(g_fix_enabled && g_ultrawide_fix_enabled) && UltraWideaddress) {
|
if (!(g_fix_enabled && g_ultrawide_fix_enabled) && UltraWideaddress) {
|
||||||
Memory::RestoreBytes(UltraWideaddress);
|
Memory::RestoreBytes(UltraWideaddress + 0x3);
|
||||||
logger->info("Ultra wide fix disabled");
|
logger->info("Ultra wide fix disabled");
|
||||||
if (!g_fov_fix_enabled) FOVFixEnabled();
|
if (!g_fov_fix_enabled) FOVFixEnabled();
|
||||||
}
|
}
|
||||||
@@ -347,27 +339,17 @@ static void VignettingFixEnabled() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FogFixEnabled() {
|
|
||||||
if (g_fix_enabled && g_Fog_fix_enabled && Fogaddress) {
|
|
||||||
Memory::PatchBytes(Fogaddress, "\xEB", 1); // jmp r.Fog 0
|
|
||||||
logger->info("Fog fix enabled");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UE Console creation
|
// UE Console creation
|
||||||
static void EnableConsole()
|
static void EnableConsole() {
|
||||||
{
|
if (g_Console_Enabled || !g_Console || !GObjectsaddress || !AppendStringaddress || !ProcessEventaddress) {
|
||||||
if (!g_Console) {
|
if (!g_Console && !user_inputs_logged) {
|
||||||
logger->info("------------------ User inputs ------------------");
|
logger->info("------------------ User inputs ------------------");
|
||||||
|
user_inputs_logged = true;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger->info("-------------- Console re-enabling --------------");
|
logger->info("-------------- Console re-enabling --------------");
|
||||||
if (!GObjectsaddress || !AppendStringaddress || !ProcessEventaddress) {
|
|
||||||
logger->warn("Could not re-enable console");
|
|
||||||
logger->info("------------------ User inputs ------------------");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::thread([&]() {
|
std::thread([&]() {
|
||||||
auto start = std::chrono::high_resolution_clock::now(); // Measure the time to renable console
|
auto start = std::chrono::high_resolution_clock::now(); // Measure the time to renable console
|
||||||
@@ -388,8 +370,7 @@ static void EnableConsole()
|
|||||||
|
|
||||||
/* Creates a new UObject of class-type specified by Engine->ConsoleClass */
|
/* Creates a new UObject of class-type specified by Engine->ConsoleClass */
|
||||||
UObject* NewObject = UGameplayStatics::SpawnObject(Engine->ConsoleClass, Engine->GameViewport);
|
UObject* NewObject = UGameplayStatics::SpawnObject(Engine->ConsoleClass, Engine->GameViewport);
|
||||||
if (NewObject)
|
if (NewObject) {
|
||||||
{
|
|
||||||
logger->info("Successfully spawned console object");
|
logger->info("Successfully spawned console object");
|
||||||
// Set the console viewport so that it will be displayed
|
// Set the console viewport so that it will be displayed
|
||||||
Engine->GameViewport->ViewportConsole = static_cast<UConsole*>(NewObject);
|
Engine->GameViewport->ViewportConsole = static_cast<UConsole*>(NewObject);
|
||||||
@@ -398,23 +379,19 @@ static void EnableConsole()
|
|||||||
|
|
||||||
// Set the all the console shortkey to F2
|
// Set the all the console shortkey to F2
|
||||||
for (int i = 0; i < UInputSettings::GetDefaultObj()->ConsoleKeys.Num(); i++)
|
for (int i = 0; i < UInputSettings::GetDefaultObj()->ConsoleKeys.Num(); i++)
|
||||||
{
|
|
||||||
UInputSettings::GetDefaultObj()->ConsoleKeys[i].KeyName = UKismetStringLibrary::Conv_StringToName(L"F2");
|
UInputSettings::GetDefaultObj()->ConsoleKeys[i].KeyName = UKismetStringLibrary::Conv_StringToName(L"F2");
|
||||||
}
|
|
||||||
logger->info("Console fully reactivated in {:.3f}s and bound to key F2", elapsed.count());
|
logger->info("Console fully reactivated in {:.3f}s and bound to key F2", elapsed.count());
|
||||||
g_Console_Enabled = true;
|
g_Console_Enabled = true;
|
||||||
}
|
}
|
||||||
else
|
else logger->error("Could not spawn console object");
|
||||||
logger->error("Could not spawn console object");
|
|
||||||
|
|
||||||
logger->info("------------------ User inputs ------------------");
|
logger->info("------------------ User inputs ------------------");
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitializeLogger()
|
static void InitializeLogger() {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
std::filesystem::path log_path = std::filesystem::absolute(PLUGIN_LOG);
|
std::filesystem::path log_path = std::filesystem::absolute(PLUGIN_LOG);
|
||||||
if (std::filesystem::exists(log_path))
|
if (std::filesystem::exists(log_path))
|
||||||
std::filesystem::remove(log_path);
|
std::filesystem::remove(log_path);
|
||||||
@@ -422,23 +399,19 @@ static void InitializeLogger()
|
|||||||
logger->set_level(spdlog::level::debug);
|
logger->set_level(spdlog::level::debug);
|
||||||
logger->flush_on(spdlog::level::debug); // Flush automatically
|
logger->flush_on(spdlog::level::debug); // Flush automatically
|
||||||
}
|
}
|
||||||
catch (const spdlog::spdlog_ex& ex)
|
catch (const spdlog::spdlog_ex& ex) {
|
||||||
{
|
|
||||||
std::string plugin_error_message = "Could not open " + PLUGIN_LOG;
|
std::string plugin_error_message = "Could not open " + PLUGIN_LOG;
|
||||||
MessageBoxA(nullptr, plugin_error_message.c_str(), "Logger Error", MB_ICONERROR | MB_OK);
|
MessageBoxA(nullptr, plugin_error_message.c_str(), "Logger Error", MB_ICONERROR | MB_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard dll entry
|
// Standard dll entry
|
||||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID)
|
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID) {
|
||||||
{
|
if (reason == DLL_PROCESS_ATTACH) {
|
||||||
if (reason == DLL_PROCESS_ATTACH)
|
|
||||||
{
|
|
||||||
InitializeLogger();
|
InitializeLogger();
|
||||||
logger->info("Plugin {} loaded.", PLUGIN_NAME);
|
logger->info("Plugin {} loaded.", PLUGIN_NAME);
|
||||||
}
|
}
|
||||||
else if (reason == DLL_PROCESS_DETACH)
|
else if (reason == DLL_PROCESS_DETACH) {
|
||||||
{
|
|
||||||
logger->info("Plugin {} unloaded.", PLUGIN_NAME);
|
logger->info("Plugin {} unloaded.", PLUGIN_NAME);
|
||||||
spdlog::drop_all();
|
spdlog::drop_all();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user