2026-03-22 17:25:36 +01:00
|
|
|
|
#include "CommonHeaders.h"
|
|
|
|
|
|
#include "UEngine.hpp"
|
|
|
|
|
|
#include "Logger.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
|
|
const std::string PLUGIN_NAME = "DeathStranding2";
|
|
|
|
|
|
const std::string PLUGIN_LOG = PLUGIN_NAME + ".log";
|
|
|
|
|
|
|
|
|
|
|
|
// Logger
|
|
|
|
|
|
std::shared_ptr<spdlog::logger> logger;
|
|
|
|
|
|
|
|
|
|
|
|
// Screen informations
|
|
|
|
|
|
static int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
|
|
static int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
|
|
static float g_AspectRatio = (float)screenWidth / screenHeight;
|
|
|
|
|
|
|
|
|
|
|
|
// Plugin states
|
|
|
|
|
|
static bool AOBScanDone = false;
|
|
|
|
|
|
static std::atomic<bool> g_fix_enabled = false;
|
|
|
|
|
|
static std::atomic<bool> g_fov_fix_enabled = false;
|
|
|
|
|
|
static std::atomic<bool> g_ultrawide_fix_enabled = false;
|
2026-03-22 22:34:54 +01:00
|
|
|
|
static std::atomic<bool> g_camera_fix_enabled = false;
|
2026-03-22 17:25:36 +01:00
|
|
|
|
static int g_AdditionalFOVValue = 0;
|
2026-03-22 22:34:54 +01:00
|
|
|
|
static float g_cameraDistanceMultiplier = 1.f;
|
2026-03-22 17:25:36 +01:00
|
|
|
|
|
|
|
|
|
|
// Shared values
|
|
|
|
|
|
static float g_FOV_In = 80.f;
|
|
|
|
|
|
static float g_FOV_Out = 80.f;
|
2026-03-22 22:34:54 +01:00
|
|
|
|
static float g_Camera_In = 3.f;
|
|
|
|
|
|
static float g_Camera_Out = 3.f;
|
2026-03-22 17:25:36 +01:00
|
|
|
|
|
|
|
|
|
|
// AOB Scan pointers
|
|
|
|
|
|
static uint8_t* FOVaddress = nullptr;
|
|
|
|
|
|
static uint8_t* Ultrawideaddress = nullptr;
|
|
|
|
|
|
static uint8_t* Cutscenesaddress = nullptr;
|
2026-03-22 22:34:54 +01:00
|
|
|
|
static uint8_t* Cameraaddress = nullptr;
|
2026-03-22 17:25:36 +01:00
|
|
|
|
|
|
|
|
|
|
// Hooking
|
|
|
|
|
|
static SafetyHookMid FOVHook{};
|
2026-03-22 22:34:54 +01:00
|
|
|
|
static SafetyHookMid CameraHook{};
|
2026-03-22 17:25:36 +01:00
|
|
|
|
static SafetyHookMid UWHook{};
|
|
|
|
|
|
|
|
|
|
|
|
// Prototypes
|
|
|
|
|
|
static void FOVFixEnabled();
|
|
|
|
|
|
static void UltraWideFixEnabled();
|
2026-03-22 22:34:54 +01:00
|
|
|
|
static void CameraFixEnabled();
|
2026-03-22 17:25:36 +01:00
|
|
|
|
|
|
|
|
|
|
extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
|
|
|
|
|
|
g_fix_enabled = enabled;
|
|
|
|
|
|
if (!AOBScanDone) { // Decima Engine
|
|
|
|
|
|
logger->info("--------------- AOB scan started ---------------");
|
|
|
|
|
|
constexpr auto FOVStringObfuscated = make_obfuscated<0xFA>("C5 F8 ?? ?? ?? ?? C5 F8 ?? ?? ?? ?? C5 78 ?? ?? ?? ?? C5 FA ?? ?? C5 F2 59 ?? ?? ?? ?? ?? 48 83 ?? ?? C3"); // +0x1e
|
|
|
|
|
|
constexpr auto AspectStringObfuscated = make_obfuscated<0x8B>("C5 FA 10 ?? ?? C5 F2 ?? ?? C5 CA ?? ?? E9 ?? ?? ?? ?? C5 FA 10 ?? ?? ?? ?? ?? C5");
|
|
|
|
|
|
constexpr auto AspectCutscenesStringObfuscated = make_obfuscated<0x9D>("0F 84 ?? ?? ?? ?? 49 8B 9D ?? ?? ?? ?? 49 63 85 ?? ?? ?? ?? 48 6B ?? ?? 48 ?? ?? 48 ?? ?? 0F 84");
|
2026-03-22 22:34:54 +01:00
|
|
|
|
constexpr auto CameraStringObfuscated = make_obfuscated<0x84>("C5 FA 10 ?? ?? ?? ?? ?? 40 38 ?? ?? ?? ?? ?? 0F 84 ?? ?? ?? ?? C5 FA 10");
|
2026-03-22 17:25:36 +01:00
|
|
|
|
|
|
|
|
|
|
using AOBScan::Make;
|
|
|
|
|
|
using OffsetScan::Make;
|
|
|
|
|
|
// Prepare all data for scanning
|
|
|
|
|
|
std::vector<AOBScanEntry> signatures = {
|
|
|
|
|
|
Make(&FOVaddress, FOVStringObfuscated, "FOV"),
|
|
|
|
|
|
Make(&Ultrawideaddress, AspectStringObfuscated, "Ultrawide"),
|
|
|
|
|
|
Make(&Cutscenesaddress, AspectCutscenesStringObfuscated, "Cutscenes"),
|
2026-03-22 22:34:54 +01:00
|
|
|
|
Make(&Cameraaddress, CameraStringObfuscated, "Camera"),
|
2026-03-22 17:25:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
// Scan all signature in a batch
|
|
|
|
|
|
Memory::AOBScanBatch(signatures, logger);
|
2026-03-22 22:34:54 +01:00
|
|
|
|
if (FOVaddress && Ultrawideaddress && Cutscenesaddress && Cameraaddress)
|
2026-03-22 17:25:36 +01:00
|
|
|
|
logger->info("All AOB signatures found. Ready to patch...");
|
|
|
|
|
|
|
|
|
|
|
|
logger->info("-------------- Fixes initialisation -------------");
|
|
|
|
|
|
AOBScanDone = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-22 22:34:54 +01:00
|
|
|
|
if (!init && FOVaddress) FOVFixEnabled();
|
2026-03-22 17:25:36 +01:00
|
|
|
|
if (!init && Ultrawideaddress) UltraWideFixEnabled();
|
2026-03-22 22:34:54 +01:00
|
|
|
|
if (!init && Cameraaddress) CameraFixEnabled();
|
2026-03-22 17:25:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Setters for Reshade addon call
|
|
|
|
|
|
extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enabled) { // Set each fix individually
|
|
|
|
|
|
if (fix == GameFixes::FOV) { g_fov_fix_enabled = enabled; FOVFixEnabled(); }
|
|
|
|
|
|
if (fix == GameFixes::UltraWide) { g_ultrawide_fix_enabled = enabled; UltraWideFixEnabled(); }
|
2026-03-22 22:34:54 +01:00
|
|
|
|
if (fix == GameFixes::Camera) { g_camera_fix_enabled = enabled; CameraFixEnabled(); }
|
2026-03-22 22:53:41 +01:00
|
|
|
|
if (fix == GameFixes::None) logger->info("------------------ User inputs ------------------");
|
2026-03-22 17:25:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" __declspec(dllexport) void SetValues(GameSetting setting, float value) {
|
|
|
|
|
|
if (setting == GameSetting::FOV) g_AdditionalFOVValue = (int)(value);
|
2026-03-22 22:34:54 +01:00
|
|
|
|
if (setting == GameSetting::CameraDistance) g_cameraDistanceMultiplier = value;
|
2026-03-22 17:25:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
// Getters for Reshade addon call
|
|
|
|
|
|
extern "C" __declspec(dllexport) void GetGameInfos(GameInfos* infos) {
|
|
|
|
|
|
if (!infos) return;
|
|
|
|
|
|
|
|
|
|
|
|
infos->FOVIn = g_FOV_In;
|
|
|
|
|
|
infos->FOVOut = g_FOV_Out;
|
2026-03-22 22:34:54 +01:00
|
|
|
|
infos->cameraIn = g_Camera_In;
|
|
|
|
|
|
infos->cameraOut = g_Camera_Out;
|
2026-03-22 17:25:36 +01:00
|
|
|
|
infos->screenWidth = screenWidth;
|
|
|
|
|
|
infos->screenHeight = screenHeight;
|
|
|
|
|
|
infos->aspectRatio = (float)screenWidth / screenHeight;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Code injection functions
|
|
|
|
|
|
static void FOVFixEnabled() {
|
|
|
|
|
|
if (g_fix_enabled && g_fov_fix_enabled && FOVaddress) {
|
|
|
|
|
|
if (!FOVHook) { // Hook only once
|
|
|
|
|
|
FOVHook = safetyhook::create_mid(FOVaddress + 0x1e,
|
|
|
|
|
|
[](SafetyHookContext& ctx) {
|
|
|
|
|
|
g_FOV_In = ctx.xmm0.f32[0];
|
|
|
|
|
|
ctx.xmm0.f32[0] += (g_fix_enabled && g_fov_fix_enabled ? g_AdditionalFOVValue : 0);
|
|
|
|
|
|
g_FOV_Out = ctx.xmm0.f32[0];
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else FOVHook.enable();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!(g_fix_enabled && g_fov_fix_enabled) && FOVaddress)
|
|
|
|
|
|
if (FOVHook) FOVHook.disable();
|
|
|
|
|
|
|
|
|
|
|
|
logger->info("FOV fix {}", g_fix_enabled && g_fov_fix_enabled ? "enabled" : "disabled");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void UltraWideFixEnabled() {
|
|
|
|
|
|
if (!Ultrawideaddress || !Cutscenesaddress) return;
|
|
|
|
|
|
if (g_fix_enabled && g_ultrawide_fix_enabled) {
|
|
|
|
|
|
if (!UWHook) {
|
2026-03-23 20:48:01 +01:00
|
|
|
|
UWHook = safetyhook::create_mid(Ultrawideaddress,
|
|
|
|
|
|
[](SafetyHookContext& ctx) {
|
|
|
|
|
|
ctx.xmm0.f32[0] = g_AspectRatio;
|
|
|
|
|
|
});
|
2026-03-22 17:25:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
else UWHook.enable();
|
|
|
|
|
|
Memory::PatchBytes(Cutscenesaddress, "\x90\xE9", 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
if (UWHook) UWHook.disable();
|
|
|
|
|
|
Memory::RestoreBytes(Cutscenesaddress);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logger->info("Ultrawide fix {}", g_fix_enabled && g_ultrawide_fix_enabled ? "enabled" : "disabled");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-22 22:34:54 +01:00
|
|
|
|
static void CameraFixEnabled() {
|
|
|
|
|
|
if (!Cameraaddress) return;
|
|
|
|
|
|
if (g_fix_enabled && g_camera_fix_enabled) {
|
|
|
|
|
|
if (!CameraHook) {
|
|
|
|
|
|
CameraHook = safetyhook::create_mid(Cameraaddress + 0x8,
|
|
|
|
|
|
[](SafetyHookContext& ctx) {
|
|
|
|
|
|
g_Camera_In = ctx.xmm0.f32[0];
|
|
|
|
|
|
ctx.xmm0.f32[0] *= g_cameraDistanceMultiplier;;
|
|
|
|
|
|
g_Camera_Out = ctx.xmm0.f32[0];
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else CameraHook.enable();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (CameraHook) CameraHook.disable();
|
|
|
|
|
|
|
|
|
|
|
|
logger->info("Camera fix {}", g_fix_enabled && g_camera_fix_enabled ? "enabled" : "disabled");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-22 17:25:36 +01:00
|
|
|
|
// Standard dll entry
|
|
|
|
|
|
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID) {
|
|
|
|
|
|
if (reason == DLL_PROCESS_ATTACH) {
|
|
|
|
|
|
logger = InitializeLogger("Death Stranding 2: On The Beach", PLUGIN_LOG);
|
|
|
|
|
|
logger->info("Plugin {} loaded.", PLUGIN_NAME);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (reason == DLL_PROCESS_DETACH) {
|
|
|
|
|
|
logger->info("Plugin {} unloaded.", PLUGIN_NAME);
|
|
|
|
|
|
spdlog::drop_all();
|
|
|
|
|
|
}
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|