Add new cheats. Add cheatmanager enabling. Code refactoring

This commit is contained in:
2026-01-04 19:33:02 +01:00
parent a94385dad8
commit 75e008b2cd

View File

@@ -1,11 +1,6 @@
#define NOMINMAX #define NOMINMAX
#include <algorithm> #include <algorithm>
#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 "UEMath.hpp" #include "UEMath.hpp"
#include "SDK/Basic.hpp" #include "SDK/Basic.hpp"
@@ -40,6 +35,8 @@ 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 bool g_TimeDilation_fix_enabled = false; static bool g_TimeDilation_fix_enabled = false;
static bool g_GodMode_fix_enabled = false;
static bool g_Invulnerable_fix_enabled = false;
static int g_AdditionalFOVValue = 0; static int g_AdditionalFOVValue = 0;
static int g_CameraOffset = 0; static int g_CameraOffset = 0;
static float g_WorldTimeDilationValue = 1.f; static float g_WorldTimeDilationValue = 1.f;
@@ -75,13 +72,13 @@ static uint8_t* ProcessEventaddress = nullptr;
static uint8_t* FOVaddress = nullptr; static uint8_t* FOVaddress = nullptr;
static uint8_t* ConstrainAspectaddress = nullptr; static uint8_t* ConstrainAspectaddress = nullptr;
static uint8_t* Cameraaddress = nullptr; static uint8_t* Cameraaddress = nullptr;
static uint8_t* CameraObjectaddress = nullptr;
static uint8_t* HUDaddress = nullptr; static uint8_t* HUDaddress = 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* Fogaddress = nullptr;
static uint8_t* WorldTimedilationaddress = nullptr; static uint8_t* WorldTimedilationaddress = nullptr;
static uint8_t* SetBenchmarkModeaddress = nullptr; static uint8_t* SetBenchmarkModeaddress = nullptr;
static uint8_t* CheatManageraddress = nullptr;
// Hooking // Hooking
static SafetyHookMid FOVHook{}; static SafetyHookMid FOVHook{};
@@ -91,6 +88,7 @@ static SafetyHookMid FogHook{};
static SafetyHookMid WorldTimeDilationHook{}; static SafetyHookMid WorldTimeDilationHook{};
static SafetyHookMid BenchmarkHook{}; static SafetyHookMid BenchmarkHook{};
static SafetyHookMid PEHook{}; static SafetyHookMid PEHook{};
static SafetyHookMid CheatsHook{};
// Prototypes // Prototypes
static void FOVFixEnabled(); static void FOVFixEnabled();
@@ -101,8 +99,8 @@ static void DOFFixEnabled();
static void CAFixEnabled(); static void CAFixEnabled();
static void VignettingFixEnabled(); static void VignettingFixEnabled();
static void FogFixEnabled(); static void FogFixEnabled();
static void TimeDilation();
static void EnableConsole(); static void EnableConsole();
static void EnableCheats(Cheat cheat);
// Unreal Engine camera struct // Unreal Engine camera struct
struct BlueprintModifyCamera_Params struct BlueprintModifyCamera_Params
@@ -126,7 +124,6 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
using AOBScan::Make; using AOBScan::Make;
using OffsetScan::Make; using OffsetScan::Make;
constexpr auto FOVStringObfuscated = make_obfuscated<0x4A>("EB ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 8B"); constexpr auto FOVStringObfuscated = make_obfuscated<0x4A>("EB ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 8B");
constexpr auto CameraStringObfuscated = make_obfuscated<0x2F>("49 8B ?? ?? ?? ?? ?? 48 ?? ?? 74 ?? 48 8D ?? ?? ?? E8 ?? ?? ?? ?? 49 8B ?? ?? ?? ?? ?? EB"); constexpr auto CameraStringObfuscated = make_obfuscated<0x2F>("49 8B ?? ?? ?? ?? ?? 48 ?? ?? 74 ?? 48 8D ?? ?? ?? E8 ?? ?? ?? ?? 49 8B ?? ?? ?? ?? ?? EB");
constexpr auto BenchMarkStringObfuscated = make_obfuscated<0xC3>("88 86 58 03 ?? ?? 48 8B ?? ?? ?? 48 83 ?? ?? 5F C3"); constexpr auto BenchMarkStringObfuscated = make_obfuscated<0xC3>("88 86 58 03 ?? ?? 48 8B ?? ?? ?? 48 83 ?? ?? 5F C3");
@@ -135,6 +132,7 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
constexpr auto VignettingStringObfuscated = make_obfuscated<0x97>("8B ?? 83 ?? ?? 7D ?? 89 B3"); constexpr auto VignettingStringObfuscated = make_obfuscated<0x97>("8B ?? 83 ?? ?? 7D ?? 89 B3");
constexpr auto FogStringObfuscated = make_obfuscated<0x46>("83 ?? ?? ?? 75 ?? B3 ?? EB ?? 32 ?? 48 8B ?? ?? ?? 48 ?? ?? 74 ?? E8"); constexpr auto FogStringObfuscated = make_obfuscated<0x46>("83 ?? ?? ?? 75 ?? B3 ?? EB ?? 32 ?? 48 8B ?? ?? ?? 48 ?? ?? 74 ?? E8");
constexpr auto WorldTimeDilationStringObfuscated = make_obfuscated<0x6E>("F3 0F 10 ?? ?? ?? ?? ?? F3 0F 10 ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? C3"); constexpr auto WorldTimeDilationStringObfuscated = make_obfuscated<0x6E>("F3 0F 10 ?? ?? ?? ?? ?? F3 0F 10 ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? C3");
constexpr auto CheatManagerStringObfuscated = make_obfuscated<0xAB>("FF 90 ?? ?? ?? ?? 84 ?? 75 ?? 84 ?? 0F 84 ?? ?? ?? ?? 48 89");
// Prepare all data for scanning // Prepare all data for scanning
std::vector<AOBScanEntry> signatures = { std::vector<AOBScanEntry> signatures = {
Make(&FOVaddress, FOVStringObfuscated, "FOV"), Make(&FOVaddress, FOVStringObfuscated, "FOV"),
@@ -144,13 +142,14 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
Make(&CAaddress, CAStringObfuscated, "Chromatic aberrations"), Make(&CAaddress, CAStringObfuscated, "Chromatic aberrations"),
Make(&Vignettingaddress, VignettingStringObfuscated, "Vignetting"), Make(&Vignettingaddress, VignettingStringObfuscated, "Vignetting"),
Make(&Fogaddress, FogStringObfuscated, "Fog"), Make(&Fogaddress, FogStringObfuscated, "Fog"),
Make(&WorldTimedilationaddress, WorldTimeDilationStringObfuscated, "World time dilation") Make(&WorldTimedilationaddress, WorldTimeDilationStringObfuscated, "World time dilation"),
Make(&CheatManageraddress, CheatManagerStringObfuscated, "Cheat manager"),
}; };
// Scan all signature in a batch // Scan all signature in a batch
Memory::AOBScanBatch(signatures, logger); Memory::AOBScanBatch(signatures, logger);
if (FOVaddress && Cameraaddress && SetBenchmarkModeaddress && HUDaddress && if (FOVaddress && Cameraaddress && SetBenchmarkModeaddress && HUDaddress &&
CAaddress && Vignettingaddress && Fogaddress && WorldTimedilationaddress) CAaddress && Vignettingaddress && Fogaddress && WorldTimedilationaddress && CheatManageraddress)
logger->info("All AOB signatures found. Ready to patch..."); logger->info("All AOB signatures found. Ready to patch...");
AOBScanDone = true; AOBScanDone = true;
@@ -184,7 +183,6 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
if (!init && CAaddress) CAFixEnabled(); if (!init && CAaddress) CAFixEnabled();
if (!init && Vignettingaddress) VignettingFixEnabled(); if (!init && Vignettingaddress) VignettingFixEnabled();
if (!init && Fogaddress) FogFixEnabled(); if (!init && Fogaddress) FogFixEnabled();
if (!init && WorldTimedilationaddress) TimeDilation();
if (!init && GObjectsaddress && AppendStringaddress && ProcessEventaddress) EnableConsole(); if (!init && GObjectsaddress && AppendStringaddress && ProcessEventaddress) EnableConsole();
if (FOVaddress) UltraWideFixEnabled(); if (FOVaddress) UltraWideFixEnabled();
} }
@@ -198,7 +196,9 @@ 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::WorldTimeDilation) { g_TimeDilation_fix_enabled = enabled; TimeDilation(); } if (fix == GameFixes::TimeDilation) { g_TimeDilation_fix_enabled = enabled; EnableCheats(Cheat::TimeDilation); }
if (fix == GameFixes::GodMode) { g_GodMode_fix_enabled = enabled; EnableCheats(Cheat::GodMode); }
if (fix == GameFixes::Invulnerable) { g_Invulnerable_fix_enabled = enabled; EnableCheats(Cheat::Invulnerability); }
} }
extern "C" __declspec(dllexport) void SetFOV(int fov) { extern "C" __declspec(dllexport) void SetFOV(int fov) {
@@ -248,6 +248,17 @@ static APawn* GetPawnFromWorld(UWorld* world = nullptr) {
return pawn; return pawn;
} }
static APhxCharacter* GetPhxCharacterFromPawn(APawn* pawn) {
void* inventoryComp = *(void**)((uintptr_t)pawn + 0x6d8); // inventoryComp offset from SDK
void* moveComp = *(void**)((uintptr_t)pawn + 0x908); // moveComp offset FROM SDK
if (inventoryComp && moveComp) {
APhxCharacter* phxChar = static_cast<APhxCharacter*>(pawn);
if (phxChar) return phxChar;
}
return nullptr;
}
// Miscellaneous functions // Miscellaneous functions
static inline double NowSeconds() static inline double NowSeconds()
{ {
@@ -333,13 +344,9 @@ static void CameraFixEnabled() {
APawn* pawn = GetPawnFromWorld(world); APawn* pawn = GetPawnFromWorld(world);
if (!pawn) return; if (!pawn) return;
// Retrieve Character class // Retrieve PhxCharacter class
void* inventoryComp = *(void**)((uintptr_t)pawn + 0x6d8); // inventoryComp offset from SDK APhxCharacter* phxChar = GetPhxCharacterFromPawn(pawn);
void* moveComp = *(void**)((uintptr_t)pawn + 0x908); // moveComp offset FROM SDK if (phxChar) bIsAiming = phxChar->bIsAiming; // Is player aiming ?
if (inventoryComp && moveComp) {
APhxCharacter* phxChar = static_cast<APhxCharacter*>(pawn);
if (phxChar) bIsAiming = phxChar->bIsAiming; // Is player aiming ?
}
// --- Positions --- // --- Positions ---
FVector pawnPos = pawn->K2_GetActorLocation(); FVector pawnPos = pawn->K2_GetActorLocation();
@@ -490,42 +497,47 @@ static void HUDFixEnabled() {
} }
} }
static void TimeDilation() { static void EnableCheats(Cheat cheat) {
if (g_fix_enabled && g_TimeDilation_fix_enabled && WorldTimedilationaddress) { if (WorldTimedilationaddress && !WorldTimeDilationHook) {
if (!WorldTimeDilationHook) { WorldTimeDilationHook = safetyhook::create_mid(WorldTimedilationaddress + 0x20,
WorldTimeDilationHook = safetyhook::create_mid(WorldTimedilationaddress + 0x20, [](SafetyHookContext& ctx) {
[](SafetyHookContext& ctx) { // From AWorldSettings retrieved from world->K2_GetWorldSettings()
ctx.xmm0.f32[0] = g_TimeDilation_fix_enabled ? g_WorldTimeDilationValue : 1.f; ctx.xmm0.f32[0] = g_TimeDilation_fix_enabled ? g_WorldTimeDilationValue : 1.f;
ULONGLONG now = GetTickCount64(); ULONGLONG now = GetTickCount64();
if (now - lastScanTick < DEFAULT_ACTORS_SCAN_BETWEEN_TICKS) return; if (now - lastScanTick < DEFAULT_ACTORS_SCAN_BETWEEN_TICKS) return;
lastScanTick = now; lastScanTick = now;
UWorld* world = UWorld::GetWorld(); UWorld* world = UWorld::GetWorld();
if (!world) return; if (!world) return;
APawn* pawn = GetPawnFromWorld(world); APawn* pawn = GetPawnFromWorld(world);
if (!pawn) return; if (!pawn) return;
// Enemies time dilation,
for (int i = 0; i < world->Levels.Num(); i++) { // Loop through level to find actors
ULevel* Level = world->Levels[i];
if (!Level) continue;
for (int i = 0; i < world->Levels.Num(); i++) { // Loop through level to find actors for (int j = 0; j < Level->Actors.Num(); j++) { // Loop through actors
ULevel* Level = world->Levels[i]; AActor* actor = Level->Actors[j];
if (!Level) continue; if (!actor) continue;
if (actor == pawn) continue; // We don't want to affect Jacob
if (!actor->IsA(ACharacter::StaticClass()) && !actor->IsA(APawn::StaticClass()))
continue; // We want to affect only enemies
for (int j = 0; j < Level->Actors.Num(); j++) { // Loop through actors actor->CustomTimeDilation = g_TimeDilation_fix_enabled ? g_AITimeDilationValue : 1.f;
AActor* actor = Level->Actors[j];
if (!actor) continue;
if (actor == pawn) continue; // We don't want to affect Jacob
if (!actor->IsA(ACharacter::StaticClass()) && !actor->IsA(APawn::StaticClass()))
continue; // We want to affect only enemies
actor->CustomTimeDilation = g_TimeDilation_fix_enabled ? g_AITimeDilationValue : 1.f;
}
} }
}); }
} // God mode
logger->info("Time dilation fix enabled"); AActor* jacob = static_cast<AActor*>(pawn);
if (jacob) jacob->bCanBeDamaged = g_GodMode_fix_enabled ? false : true; // Jacob won't be hurt
// Invulnerability
APhxCharacter* phxChar = GetPhxCharacterFromPawn(pawn);
if (phxChar) phxChar->bInvulnerable = g_Invulnerable_fix_enabled ? true : false; // Make Jacob invulnerable
});
} }
if (!(g_fix_enabled && g_TimeDilation_fix_enabled) && WorldTimedilationaddress) if (cheat == Cheat::TimeDilation) logger->info("Time dilation cheat {}", g_TimeDilation_fix_enabled ? "enabled" : "disabled");
logger->info("Time dilation fix disabled"); if (cheat == Cheat::GodMode) logger->info("God mode cheat {}", g_GodMode_fix_enabled ? "enabled" : "disabled");
if (cheat == Cheat::Invulnerability) logger->info("Ignore hits cheat {}", g_Invulnerable_fix_enabled ? "enabled" : "disabled");
} }
static void FogFixEnabled() { static void FogFixEnabled() {
@@ -619,6 +631,10 @@ static void EnableConsole()
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());
logger->info("------------------ User inputs ------------------"); logger->info("------------------ User inputs ------------------");
// Enable cheat commands through console
if (CheatManageraddress)
Memory::PatchBytes(CheatManageraddress, "\xB0\x01\x90\x90\x90\x90", 6); // mov al,1
g_Console_Enabled = true; g_Console_Enabled = true;
} }
else { else {