Add camera fix auto disabling when performing benchmark

This commit is contained in:
2025-12-31 14:25:27 +01:00
parent f93c85534b
commit 82439e5b0b

View File

@@ -49,6 +49,7 @@ static float g_LastCameraDeltaTime = 1.f / 60.f; // fallback
static float g_HUDLeft = 0.f; static float g_HUDLeft = 0.f;
static float g_HUDRight = 1.f; static float g_HUDRight = 1.f;
static bool g_Console = false; static bool g_Console = false;
static bool bIsInBenchmarkMode = false;
static bool bIsInventoryOpen = false; static bool bIsInventoryOpen = false;
static bool bIsInCinematicMode = false; static bool bIsInCinematicMode = false;
static bool bIsInPrinterMode = false; static bool bIsInPrinterMode = false;
@@ -78,6 +79,7 @@ static uint8_t* CAaddress = nullptr;
static uint8_t* Vignettingaddress = nullptr; static uint8_t* Vignettingaddress = nullptr;
static uint8_t* Fogaddress = nullptr; static uint8_t* Fogaddress = nullptr;
static uint8_t* WorldTimedilationaddress = nullptr; static uint8_t* WorldTimedilationaddress = nullptr;
static uint8_t* SetBenchmarkModeaddress = nullptr;
// Hooking // Hooking
static SafetyHookMid FOVHook{}; static SafetyHookMid FOVHook{};
@@ -85,6 +87,7 @@ static SafetyHookMid CameraHook{};
static SafetyHookMid HUDHook{}; static SafetyHookMid HUDHook{};
static SafetyHookMid FogHook{}; static SafetyHookMid FogHook{};
static SafetyHookMid WorldTimeDilationHook{}; static SafetyHookMid WorldTimeDilationHook{};
static SafetyHookMid BenchmarkHook{};
static SafetyHookMid PEHook{}; static SafetyHookMid PEHook{};
// Prototypes // Prototypes
@@ -139,6 +142,16 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
logger->info("Camera signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(Cameraaddress)); logger->info("Camera signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(Cameraaddress));
} }
if (!SetBenchmarkModeaddress) {
constexpr auto BenchMarkStringObfuscated = make_obfuscated<0x4A>("88 86 58 03 ?? ?? 48 8B ?? ?? ?? 48 83 ?? ?? 5F C3");
SetBenchmarkModeaddress = Memory::AOBScan("", BenchMarkStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
if (!SetBenchmarkModeaddress)
logger->warn("Set BenchMark mode signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else
logger->info("Set BenchMark mode signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(SetBenchmarkModeaddress));
}
if (!HUDaddress) { if (!HUDaddress) {
constexpr auto HUDStringObfuscated = make_obfuscated<0x4A>("FF ?? 48 8B ?? ?? ?? 0F ?? ?? 48 ?? ?? 0F ?? ?? 48 83"); constexpr auto HUDStringObfuscated = make_obfuscated<0x4A>("FF ?? 48 8B ?? ?? ?? 0F ?? ?? 48 ?? ?? 0F ?? ?? 48 83");
HUDaddress = Memory::AOBScan("", HUDStringObfuscated.decrypt(), PAGE_EXECUTE_READ); HUDaddress = Memory::AOBScan("", HUDStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
@@ -189,7 +202,8 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
logger->info("World time dilation signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(WorldTimedilationaddress)); logger->info("World time dilation signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(WorldTimedilationaddress));
} }
if (FOVaddress && Cameraaddress && HUDaddress && CAaddress && Vignettingaddress && Fogaddress && WorldTimedilationaddress) if (FOVaddress && Cameraaddress && SetBenchmarkModeaddress && HUDaddress &&
CAaddress && Vignettingaddress && Fogaddress && WorldTimedilationaddress)
logger->info("All AOB signatures found. Ready to patch..."); logger->info("All AOB signatures found. Ready to patch...");
AOBScanDone = true; AOBScanDone = true;
@@ -273,8 +287,7 @@ extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enable
if (fix == GameFixes::WorldTimeDilation) { g_TimeDilation_fix_enabled = enabled; TimeDilation(); } if (fix == GameFixes::WorldTimeDilation) { g_TimeDilation_fix_enabled = enabled; TimeDilation(); }
} }
extern "C" __declspec(dllexport) void SetFOV(int fov) extern "C" __declspec(dllexport) void SetFOV(int fov) {
{
g_AdditionalFOVValue = fov; g_AdditionalFOVValue = fov;
} }
@@ -303,10 +316,8 @@ extern "C" __declspec(dllexport) void SetCameraSmoothness(float smoothness) {
// Unreal Engine functions // Unreal Engine functions
/** /**
* @brief Converts a rotator (Pitch, Yaw) to a forward direction vector. * @brief Converts a rotator (Pitch, Yaw) to a forward direction vector.
*
* Computes a normalized forward vector from the given FRotator, * Computes a normalized forward vector from the given FRotator,
* using Pitch and Yaw angles (in degrees). * using Pitch and Yaw angles (in degrees).
*
* @param rotator Input rotation (degrees). * @param rotator Input rotation (degrees).
* @return Forward direction vector. * @return Forward direction vector.
*/ */
@@ -390,27 +401,30 @@ static void CameraFixEnabled() {
if (object && func) { if (object && func) {
std::string funcName = func->GetName(); std::string funcName = func->GetName();
std::string objectName = object->GetFullName(); std::string objectName = object->GetName();
std::string objectFullName = object->GetFullName();
static auto start = std::chrono::high_resolution_clock::now(); static auto start = std::chrono::high_resolution_clock::now();
// Detect when benchmark or performance test is not launched
if (objectName.contains("WBP_MainMenu_C") && funcName == "OnInitialized")
bIsInBenchmarkMode = false;
// Detect cinematics to disable temporarily camera fix // Detect cinematics to disable temporarily camera fix
if (objectName.contains("CineCameraComponent") && funcName == "SetCurrentFocalLength") { if (objectFullName.contains("CineCameraComponent") && funcName == "SetCurrentFocalLength") {
bIsInCinematicMode = true; bIsInCinematicMode = true;
LastCineCallTime = NowSeconds(); LastCineCallTime = NowSeconds();
} }
// Detect reforge station interactions to disable temporarily camera fix // Detect reforge station interactions to disable temporarily camera fix
if (objectName.contains("BP_PrinterTabs_C")) { if (objectFullName.contains("BP_PrinterTabs_C")) {
if (funcName == "Show") bIsInPrinterMode = true; if (funcName == "Show") bIsInPrinterMode = true;
if (funcName == "Hide") bIsInPrinterMode = false; if (funcName == "Hide") bIsInPrinterMode = false;
} }
// Detect inventory interactions to disable temporarily camera fix // Detect inventory interactions to disable temporarily camera fix
if (objectName.contains("BP_State_Inventory_C")) { if (objectFullName.contains("BP_State_Inventory_C")) {
if (funcName == "OnBegin") bIsInventoryOpen = true; if (funcName == "OnBegin") bIsInventoryOpen = true;
if (funcName == "OnEnd") bIsInventoryOpen = false; if (funcName == "OnEnd") bIsInventoryOpen = false;
} }
// Detect camera collisions to avoid world to vanish ending in character death // Detect camera collisions to avoid world to vanish ending in character death
if (objectName.contains("CameraModifier_PhxCameraRig") && funcName == "BlueprintModifyCamera") if (objectFullName.contains("CameraModifier_PhxCameraRig") && funcName == "BlueprintModifyCamera")
{ {
auto* cameraParams = reinterpret_cast<BlueprintModifyCamera_Params*>(ctx.r8); auto* cameraParams = reinterpret_cast<BlueprintModifyCamera_Params*>(ctx.r8);
if (!cameraParams) return; if (!cameraParams) return;
@@ -446,7 +460,7 @@ static void CameraFixEnabled() {
g_NativeCameraDistance = engineBackDist; g_NativeCameraDistance = engineBackDist;
FVector backComponent = backward * engineBackDist; FVector backComponent = backward * engineBackDist;
if (bIsInCinematicMode || bIsAiming) return; if (bIsInBenchmarkMode || bIsInCinematicMode || bIsAiming) return;
// What we KEEP (height + lateral) // What we KEEP (height + lateral)
FVector preservedOffset = engineOffset - backComponent; FVector preservedOffset = engineOffset - backComponent;
@@ -522,9 +536,8 @@ static void CameraFixEnabled() {
} }
else PEHook.enable(); else PEHook.enable();
} }
if (!(g_fix_enabled && g_camera_fix_enabled) && ProcessEventaddress) { if (!(g_fix_enabled && g_camera_fix_enabled) && ProcessEventaddress)
if (PEHook) PEHook.disable(); if (PEHook) PEHook.disable();
}
if (g_fix_enabled && g_camera_fix_enabled && Cameraaddress) { if (g_fix_enabled && g_camera_fix_enabled && Cameraaddress) {
if (!CameraHook) { if (!CameraHook) {
@@ -537,9 +550,7 @@ static void CameraFixEnabled() {
} }
float dt = g_LastCameraDeltaTime; float dt = g_LastCameraDeltaTime;
float fadeInSpeed = g_CameraSmoothnessValue; // Camera speed when it's getting closer // Secure
float fadeOutSpeed = g_CameraSmoothnessValue; // Camera speed when it moves away
// sécurité
if (dt <= 0.f || dt > 0.1f) dt = 1.f / 60.f; if (dt <= 0.f || dt > 0.1f) dt = 1.f / 60.f;
float targetOffset = g_CameraOffset; float targetOffset = g_CameraOffset;
@@ -547,10 +558,8 @@ static void CameraFixEnabled() {
if (bIsInventoryOpen) targetOffset = INVENTORY_CAM_OFFSET; if (bIsInventoryOpen) targetOffset = INVENTORY_CAM_OFFSET;
else if (bIsInPrinterMode) targetOffset = FORGE_CAM_OFFSET; else if (bIsInPrinterMode) targetOffset = FORGE_CAM_OFFSET;
float interpSpeed = (targetOffset < g_TransitionCameraOffset) ? fadeInSpeed : fadeOutSpeed;
g_TransitionCameraOffset = UKismetMathLibrary::FInterpTo(g_TransitionCameraOffset, g_TransitionCameraOffset = UKismetMathLibrary::FInterpTo(g_TransitionCameraOffset,
targetOffset,dt,interpSpeed); targetOffset,dt, g_CameraSmoothnessValue);
}); });
} }
else CameraHook.enable(); else CameraHook.enable();
@@ -560,6 +569,18 @@ static void CameraFixEnabled() {
if (CameraHook) CameraHook.disable(); if (CameraHook) CameraHook.disable();
logger->info("Camera fix disabled"); logger->info("Camera fix disabled");
} }
if (g_fix_enabled && g_camera_fix_enabled && SetBenchmarkModeaddress) {
if (!BenchmarkHook) {
BenchmarkHook = safetyhook::create_mid(SetBenchmarkModeaddress,
[](SafetyHookContext& ctx) {
bIsInBenchmarkMode = true;
});
}
else BenchmarkHook.enable();
}
if (!(g_fix_enabled && g_camera_fix_enabled) && SetBenchmarkModeaddress)
if (BenchmarkHook) BenchmarkHook.disable();
} }
static void HUDFixEnabled() { static void HUDFixEnabled() {
@@ -598,13 +619,11 @@ static void TimeDilation() {
APawn* pawn = GetPawnFromWorld(world); APawn* pawn = GetPawnFromWorld(world);
if (!pawn) return; if (!pawn) return;
for (int i = 0; i < world->Levels.Num(); i++) // Loop through level to find actors for (int i = 0; i < world->Levels.Num(); i++) { // Loop through level to find actors
{
ULevel* Level = world->Levels[i]; ULevel* Level = world->Levels[i];
if (!Level) continue; if (!Level) continue;
for (int j = 0; j < Level->Actors.Num(); j++) // Loop through actors for (int j = 0; j < Level->Actors.Num(); j++) { // Loop through actors
{
AActor* actor = Level->Actors[j]; AActor* actor = Level->Actors[j];
if (!actor) continue; if (!actor) continue;
if (actor == pawn) continue; // We don't want to affect Jacob if (actor == pawn) continue; // We don't want to affect Jacob
@@ -630,7 +649,7 @@ static void UltraWideFixEnabled() {
static void CAFixEnabled() { static void CAFixEnabled() {
if (g_fix_enabled && g_CA_fix_enabled && CAaddress) { if (g_fix_enabled && g_CA_fix_enabled && CAaddress) {
Memory::PatchBytes(CAaddress, "\x90\x90", 2); // NOP jg "HellIsUs-Win64-Shipping.exe"+3D73BD5 r.SceneColorFringeQuality = 0 Memory::PatchBytes(CAaddress, "\x90\x90", 2); // NOP jg r.SceneColorFringeQuality = 0
logger->info("Chromatic aberrations fix enabled"); logger->info("Chromatic aberrations fix enabled");
} }
if (!(g_fix_enabled && g_CA_fix_enabled) && CAaddress) { if (!(g_fix_enabled && g_CA_fix_enabled) && CAaddress) {