Add HUD scaling fix
This commit is contained in:
@@ -19,11 +19,13 @@ 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;
|
||||
static std::atomic<bool> g_HUD_fix_enabled = false;
|
||||
static std::atomic<bool> g_camera_fix_enabled = false;
|
||||
static std::atomic<bool> g_DOF_fix_enabled = false;
|
||||
static std::atomic<bool> g_vignetting_fix_enabled = false;
|
||||
static int g_AdditionalFOVValue = 0;
|
||||
static float g_cameraDistanceMultiplier = 1.f;
|
||||
static float g_HUDOffset = 0.f;
|
||||
|
||||
// Shared values
|
||||
static float g_FOV_In = 80.f;
|
||||
@@ -35,6 +37,8 @@ static float g_Camera_Out = 3.f;
|
||||
static uint8_t* FOVaddress = nullptr;
|
||||
static uint8_t* Ultrawideaddress = nullptr;
|
||||
static uint8_t* Cutscenesaddress = nullptr;
|
||||
static uint8_t* HUD1address = nullptr;
|
||||
static uint8_t* HUD2address = nullptr;
|
||||
static uint8_t* Cameraaddress = nullptr;
|
||||
static uint8_t* DOFaddress = nullptr;
|
||||
static uint8_t* Vignetteaddress = nullptr;
|
||||
@@ -44,11 +48,13 @@ static uint8_t* PSNCheckaddress = nullptr;
|
||||
static SafetyHookMid FOVHook{};
|
||||
static SafetyHookMid CameraHook{};
|
||||
static SafetyHookMid UWHook{};
|
||||
static SafetyHookMid HUDHook{};
|
||||
static SafetyHookMid VignetteHook{};
|
||||
|
||||
// Prototypes
|
||||
static void FOVFixEnabled();
|
||||
static void UltraWideFixEnabled();
|
||||
static void HUDFixEnabled();
|
||||
static void CameraFixEnabled();
|
||||
static void DOFFixEnabled();
|
||||
static void VignetteFixEnabled();
|
||||
@@ -57,16 +63,19 @@ static void PSNCheckRemoval();
|
||||
extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
|
||||
g_fix_enabled = enabled;
|
||||
if (!AOBScanDone) { // Decima Engine
|
||||
logger = InitializeLogger("Death Stranding 2: On The Beach", PLUGIN_LOG);
|
||||
logger->info("Plugin {} loaded.", PLUGIN_NAME);
|
||||
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");
|
||||
constexpr auto HUD1StringObfuscated = make_obfuscated<0x3D>("C5 E8 ?? ?? ?? ?? ?? ?? ?? C5 F9 ?? ?? 25 ?? ?? ?? ?? 3D ?? ?? ?? ?? 74 ?? C5 F8 11 ?? ?? ?? ?? ?? 48 ?? ?? 48 ?? ?? FF ?? ?? 48 83");
|
||||
constexpr auto HUD2StringObfuscated = make_obfuscated<0x3D>("7A ?? 75 ?? C5 F8 ?? ?? ?? ?? ?? ?? 7A ?? 75 ?? 39 83 ?? ?? ?? ?? 0F 84");
|
||||
constexpr auto CameraStringObfuscated = make_obfuscated<0x84>("C5 FA 10 ?? ?? ?? ?? ?? 40 38 ?? ?? ?? ?? ?? 0F 84 ?? ?? ?? ?? C5 FA 10");
|
||||
constexpr auto DOFStringObfuscated = make_obfuscated<0x84>("48 83 ?? ?? C4 C1 ?? ?? ?? C5 FA ?? ?? C5 F8 ?? ?? C5 F8 ?? ?? ?? ?? C5 F8 ?? ?? ?? C5 F8 ?? ?? 76");
|
||||
constexpr auto VignetteStringObfuscated = make_obfuscated<0x83>("C5 FA ?? ?? ?? 48 83 ?? ?? 0F 85 ?? ?? ?? ?? C5 F8 ?? ?? ?? ?? 48 8B ?? ?? ?? ?? ?? ?? C6 43");
|
||||
constexpr auto CameraStringObfuscated = make_obfuscated<0x84>("C5 FA 10 ?? ?? ?? ?? ?? 40 38 ?? ?? ?? ?? ?? 0F 84 ?? ?? ?? ?? C5 FA 10");
|
||||
constexpr auto PSNCheckStringObfuscated = make_obfuscated<0x8A>("E8 ?? ?? ?? ?? 48 89 ?? ?? ?? ?? ?? ?? 48 81 ?? ?? ?? ?? ?? E9 ?? ?? ?? ?? 0F 8A ?? ?? ?? ?? EB");
|
||||
|
||||
|
||||
using AOBScan::Make;
|
||||
using OffsetScan::Make;
|
||||
// Prepare all data for scanning
|
||||
@@ -74,6 +83,8 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
|
||||
Make(&FOVaddress, FOVStringObfuscated, "FOV"),
|
||||
Make(&Ultrawideaddress, AspectStringObfuscated, "Ultrawide"),
|
||||
Make(&Cutscenesaddress, AspectCutscenesStringObfuscated, "Cutscenes"),
|
||||
Make(&HUD1address, HUD1StringObfuscated, "HUD"),
|
||||
Make(&HUD2address, HUD2StringObfuscated, "HUD"),
|
||||
Make(&Cameraaddress, CameraStringObfuscated, "Camera"),
|
||||
Make(&DOFaddress, DOFStringObfuscated, "Depth of field"),
|
||||
Make(&Vignetteaddress, VignetteStringObfuscated, "Vignette"),
|
||||
@@ -83,25 +94,28 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
|
||||
};
|
||||
// Scan all signature in a batch
|
||||
Memory::AOBScanBatch(signatures, logger);
|
||||
if (FOVaddress && Ultrawideaddress && Cutscenesaddress && Cameraaddress && DOFaddress && Vignetteaddress)
|
||||
if (FOVaddress && Ultrawideaddress && HUD1address && HUD2address && Cutscenesaddress && Cameraaddress && DOFaddress && Vignetteaddress)
|
||||
logger->info("All AOB signatures found. Ready to patch...");
|
||||
|
||||
logger->info("-------------- Fixes initialisation -------------");
|
||||
AOBScanDone = true;
|
||||
}
|
||||
|
||||
if (!init && FOVaddress) FOVFixEnabled();
|
||||
if (!init && Ultrawideaddress) UltraWideFixEnabled();
|
||||
if (!init && Cameraaddress) CameraFixEnabled();
|
||||
if (!init && DOFaddress) DOFFixEnabled();
|
||||
if (!init && Vignetteaddress) VignetteFixEnabled();
|
||||
PSNCheckRemoval();
|
||||
if (init) return;
|
||||
FOVFixEnabled();
|
||||
UltraWideFixEnabled();
|
||||
HUDFixEnabled();
|
||||
CameraFixEnabled();
|
||||
DOFFixEnabled();
|
||||
VignetteFixEnabled();
|
||||
}
|
||||
|
||||
// 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(); }
|
||||
if (fix == GameFixes::HUD) { g_HUD_fix_enabled = enabled; HUDFixEnabled(); }
|
||||
if (fix == GameFixes::Camera) { g_camera_fix_enabled = enabled; CameraFixEnabled(); }
|
||||
if (fix == GameFixes::DOF) { g_DOF_fix_enabled = enabled; DOFFixEnabled(); }
|
||||
if (fix == GameFixes::Vignetting) { g_vignetting_fix_enabled = enabled; VignetteFixEnabled(); }
|
||||
@@ -111,6 +125,7 @@ extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enable
|
||||
extern "C" __declspec(dllexport) void SetValues(GameSetting setting, float value) {
|
||||
if (setting == GameSetting::FOV) g_AdditionalFOVValue = (int)(value);
|
||||
if (setting == GameSetting::CameraDistance) g_cameraDistanceMultiplier = value;
|
||||
if (setting == GameSetting::HUD) g_HUDOffset = (value * screenWidth) / (float)100;
|
||||
}
|
||||
|
||||
// Getters for Reshade addon call
|
||||
@@ -128,7 +143,8 @@ extern "C" __declspec(dllexport) void GetGameInfos(GameInfos* infos) {
|
||||
|
||||
// Code injection functions
|
||||
static void FOVFixEnabled() {
|
||||
if (g_fix_enabled && g_fov_fix_enabled && FOVaddress) {
|
||||
if (!FOVaddress) return;
|
||||
if (g_fix_enabled && g_fov_fix_enabled) {
|
||||
if (!FOVHook) { // Hook only once
|
||||
FOVHook = safetyhook::create_mid(FOVaddress + 0x1e,
|
||||
[](SafetyHookContext& ctx) {
|
||||
@@ -139,8 +155,7 @@ static void FOVFixEnabled() {
|
||||
}
|
||||
else FOVHook.enable();
|
||||
}
|
||||
if (!(g_fix_enabled && g_fov_fix_enabled) && FOVaddress)
|
||||
if (FOVHook) FOVHook.disable();
|
||||
else if (FOVHook) FOVHook.disable();
|
||||
|
||||
logger->info("FOV fix {}", g_fix_enabled && g_fov_fix_enabled ? "enabled" : "disabled");
|
||||
}
|
||||
@@ -165,6 +180,28 @@ static void UltraWideFixEnabled() {
|
||||
logger->info("Ultrawide fix {}", g_fix_enabled && g_ultrawide_fix_enabled ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
float aspect = (g_AspectRatio > 16.f / 9.f) ? 2.370370388f : 16.f / 9.f;
|
||||
static float initialHUDOffset = (1920.f - (screenHeight * aspect)) / 2.f;
|
||||
static std::vector<uint8_t> memoryOffset = {};
|
||||
static int32_t offset = 0;
|
||||
static void HUDFixEnabled() {
|
||||
if (!HUD1address || !HUD2address) return;
|
||||
if (!HUDHook) { // Hook only once
|
||||
if (memoryOffset.empty()) {
|
||||
memoryOffset = Memory::ReadBytes(HUD1address + 4, 4); // Retrieve the offset used to access the HUD
|
||||
offset = *reinterpret_cast<uint32_t*>(memoryOffset.data()); // Convert it to a usable int32 offset
|
||||
}
|
||||
HUDHook = safetyhook::create_mid(HUD1address,
|
||||
[](SafetyHookContext& ctx) {
|
||||
*reinterpret_cast<float*>(ctx.rax + offset) = g_fix_enabled && g_HUD_fix_enabled ? initialHUDOffset + g_HUDOffset : initialHUDOffset;
|
||||
});
|
||||
}
|
||||
Memory::PatchBytes(HUD1address + 0x19, "\x90\x90\x90\x90\x90\x90\x90\x90", 8); // Prevent rax+0xD0 from being overridden
|
||||
Memory::PatchBytes(HUD2address, "\xEB", 1); // Force the engine to reapply the new HUD position every frame
|
||||
|
||||
logger->info("HUD fix {}", g_fix_enabled && g_HUD_fix_enabled ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static void CameraFixEnabled() {
|
||||
if (!Cameraaddress) return;
|
||||
if (g_fix_enabled && g_camera_fix_enabled) {
|
||||
@@ -214,11 +251,7 @@ static void PSNCheckRemoval() {
|
||||
|
||||
// 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) {
|
||||
if (reason == DLL_PROCESS_DETACH) {
|
||||
logger->info("Plugin {} unloaded.", PLUGIN_NAME);
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user