diff --git a/Cronos The New Dawn/dllmain.cpp b/Cronos The New Dawn/dllmain.cpp index 330bd70..f109195 100644 --- a/Cronos The New Dawn/dllmain.cpp +++ b/Cronos The New Dawn/dllmain.cpp @@ -1,8 +1,10 @@ #include "CommonHeaders.h" #include "UEngine.hpp"; +#include "UETools.hpp" #include "UEvars.hpp" +#include "SDK/Basic.hpp" #include "SDK/Engine_classes.hpp" -#include "SDK/GameBase_classes.hpp" +#include "SDK/Cronos_classes.hpp" using namespace SDK; @@ -10,6 +12,7 @@ using namespace SDK; const std::string PLUGIN_NAME = "CronosTND"; const std::string PLUGIN_LOG = PLUGIN_NAME + ".log"; const float baseAspect = 1.7777778; +constexpr ULONGLONG DEFAULT_ACTORS_SCAN_BETWEEN_TICKS = 300; // Used for enemies time dilation // Logger std::shared_ptr logger; @@ -30,8 +33,14 @@ static bool g_Vignetting_fix_enabled = false; static bool g_Fog_fix_enabled = false; static bool g_cam_distance_fix_enabled = false; static bool g_SkipIntro_fix_enabled = false; +static bool g_TimeDilation_fix_enabled = false; +static bool g_GodeMode_fix_enabled = false; +static bool g_IgnoreHits_fix_enabled = false; +static bool g_Stealth_fix_enabled = false; static int g_AdditionalFOVValue = 0; static float g_cameraDistanceMultiplier = 1.f; +static float g_WorldTimeDilationValue = 1.f; +static float g_AITimeDilationValue = 1.f; static bool user_inputs_logged = false; // Shared values @@ -40,7 +49,6 @@ static float g_Compensated_FOV = 0; static float g_FOV_Out = 0; static float g_Camera_In = 180; static float g_Camera_Out = 180; -static bool g_Console_Enabled = false; // AOB Scan pointers static uint8_t* FOVaddress = nullptr; @@ -48,24 +56,32 @@ static uint8_t* Aspectaddress = nullptr; static uint8_t* DOFaddress = nullptr; static uint8_t* Vignettingaddress = nullptr; static uint8_t* Fogaddress = nullptr; +static uint8_t* FogOpacityEngineaddress = nullptr; static uint8_t* CameraDistanceaddress = nullptr; +static uint8_t* WorldTimedilationaddress = nullptr; +static uint8_t* GodModeaddress = nullptr; +static uint8_t* StealthModeaddress = nullptr; // Hooking static SafetyHookMid FOVHook{}; static SafetyHookMid AspectHook{}; static SafetyHookMid FogHook{}; +static SafetyHookMid FogMaxOpacityHook{}; static SafetyHookMid CameraDistanceHook{}; static SafetyHookMid PEHook{}; +static SafetyHookMid WorldTimeDilationHook{}; +static SafetyHookMid StealthHook{}; // Prototypes static void FOVFixEnabled(); -static void AspectFixEnabled(); +static void UltrawideFixEnabled(); static void DOFFixEnabled(); static void VignettingFixEnabled(); static void FogFixEnabled(); static void CameraDistanceFixEnabled(); static void EnableConsole(); static void ProcessEvent(); +static void EnableCheats(Cheat cheat); extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) { @@ -80,8 +96,12 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) constexpr auto AspectStringObfuscated = make_obfuscated<0x39>("C7 43 ?? 39 8E E3 3F C7 87 ?? ?? ?? ?? 39 8E E3 3F 48 83 ?? ?? ?? ?? ?? ?? 75"); constexpr auto DOFStringObfuscated = make_obfuscated<0x0F>("74 ?? 48 ?? ?? 8B ?? ?? 48 ?? ?? E8 ?? ?? ?? ?? 0F"); constexpr auto VignettingStringObfuscated = make_obfuscated<0x7D>("8B ?? 83 ?? ?? 7D ?? 44 89"); - constexpr auto FogStringObfuscated = make_obfuscated<0xB3>("F6 ?? ?? ?? ?? 74 ?? 48 8B ?? ?? ?? ?? ?? 83 78 ?? ?? 75 ?? B3"); + constexpr auto FogStringObfuscated = make_obfuscated<0x35>("40 ?? 48 83 ?? ?? 48 8B ?? ?? ?? ?? ?? 48 ?? ?? 48 89 ?? ?? ?? 48 8D ?? ?? 48 8D ?? ?? ?? E8"); + constexpr auto FogOpacityStringObfuscated = make_obfuscated<0xB3>("0F 2E ?? C4 02 ?? ?? 74 ?? F3 0F ?? ?? ?? ?? ?? ?? E9 ?? ?? ?? ?? C3"); constexpr auto CamDistanceStringObfuscated = make_obfuscated<0xF2>("E8 ?? ?? ?? ?? F2 0F ?? ?? ?? ?? 48 8D ?? ?? F3 0F ?? ?? ?? ?? ?? ?? 48 8D ?? ?? ?? ?? ?? 0F"); + constexpr auto WorldTimeDilationStringObfuscated = make_obfuscated<0X59>("F3 0F 10 ?? ?? ?? ?? ?? F3 0F 59 ?? ?? ?? ?? ?? F3 0F 59 ?? ?? ?? ?? ?? C3"); + constexpr auto GodModeStringObfuscated = make_obfuscated<0XB8>("F3 41 0F ?? ?? 80 B8 ?? ?? ?? ?? ?? F3 0F ?? ?? F3 0F ?? ?? 74"); + constexpr auto StealthStringObfuscated = make_obfuscated<0XDB>("FF 90 C0 04 ?? ?? 48 8B ?? ?? ?? 48 ?? ?? 74 ?? E8 ?? ?? ?? ?? 48 8B ?? ?? ?? 48 8B ?? ?? ?? 48 83 ?? ?? 5F C3"); // Prepare all data for scanning std::vector signatures = { Make(&FOVaddress, FOVStringObfuscated, "FOV"), @@ -89,12 +109,17 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) Make(&CameraDistanceaddress, CamDistanceStringObfuscated, "Camera distance"), Make(&DOFaddress, DOFStringObfuscated, "DOF"), Make(&Vignettingaddress, VignettingStringObfuscated, "Vignetting"), - Make(&Fogaddress, FogStringObfuscated, "Fog") + Make(&Fogaddress, FogStringObfuscated, "Fog"), + Make(&FogOpacityEngineaddress, FogOpacityStringObfuscated, "Fog opacity"), + Make(&WorldTimedilationaddress, WorldTimeDilationStringObfuscated, "World time dilation"), + Make(&GodModeaddress, GodModeStringObfuscated, "God mode"), + Make(&StealthModeaddress, StealthStringObfuscated, "Stealth") }; // Scan all signature in a batch Memory::AOBScanBatch(signatures, logger); - if (FOVaddress && Aspectaddress && DOFaddress && Vignettingaddress && Fogaddress && CameraDistanceaddress) + if (FOVaddress && Aspectaddress && DOFaddress && Vignettingaddress && FogOpacityEngineaddress && CameraDistanceaddress && + WorldTimedilationaddress && GodModeaddress && StealthModeaddress) logger->info("All AOB signatures found. Ready to patch..."); // Unreal Engine Offsets updates (needed when the game reveives an update and to prevent the fix from crashing the game) @@ -103,12 +128,14 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) uint8_t* baseModule = reinterpret_cast(GetModuleHandleA(nullptr)); // Get game base address constexpr auto GObjetcsStringObfuscated = make_obfuscated<0x33>("48 8B ?? ?? ?? ?? ?? 48 8B ?? ?? 48 8D ?? ?? EB ?? 33"); + constexpr auto GWorldStringObfuscated = make_obfuscated<0x5B>("48 8B 05 ?? ?? ?? ?? 48 ?? ?? 75 ?? 48 83 ?? ?? 5B C3"); constexpr auto AppendStringStringObfuscated = make_obfuscated<0x80>("48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 48 83 ?? ?? 80 3D ?? ?? ?? ?? ?? 48 8B F2 8B"); constexpr auto ProcessEventStringObfuscated = make_obfuscated<0x56>("40 ?? 56 57 41 ?? 41 ?? 41 ?? 41 ?? 48 81 ?? ?? ?? ?? ?? 48 8D ?? ?? ?? 48 89 ?? ?? ?? ?? ?? 48 8B ?? ?? ?? ?? ?? 48 33 ?? 48 89 ?? ?? ?? ?? ?? 4D ?? ?? 48"); // Prepare all data for scanning std::vector UEoffsetsScans = { Make(&GObjectsaddress, GObjetcsStringObfuscated, "GObjects", OffsetCalcType::GetOffsetFromOpcode, &Offsets::GObjects, 0x3), + Make(&GWorldaddress, GWorldStringObfuscated, "GWorld", OffsetCalcType::GetOffsetFromOpcode, &Offsets::GWorld, 0x3), Make(&AppendStringaddress, AppendStringStringObfuscated, "AppendString", OffsetCalcType::UE_CalculateOffset, &Offsets::AppendString), Make(&ProcessEventaddress, ProcessEventStringObfuscated, "ProcessEvent", OffsetCalcType::UE_CalculateOffset, &Offsets::ProcessEvent) }; @@ -120,11 +147,18 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) } if (!init && FOVaddress) FOVFixEnabled(); - if (!init && Aspectaddress) AspectFixEnabled(); + if (!init && Aspectaddress) UltrawideFixEnabled(); if (!init && DOFaddress) DOFFixEnabled(); if (!init && Vignettingaddress) VignettingFixEnabled(); - if (!init && Fogaddress) FogFixEnabled(); + if (!init && Fogaddress && FogOpacityEngineaddress) FogFixEnabled(); if (!init && CameraDistanceaddress) CameraDistanceFixEnabled(); + if (!init && WorldTimedilationaddress) { + EnableCheats(Cheat::TimeDilation); + EnableCheats(Cheat::GodMode); + EnableCheats(Cheat::IgnoreHits); + EnableCheats(Cheat::Stealth); + } + ProcessEvent(); } @@ -132,13 +166,16 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enabled) { // Set each fix individually if (fix == GameFixes::DevConsole) { g_Console = enabled; EnableConsole(); } if (fix == GameFixes::FOV) { g_fov_fix_enabled = enabled; FOVFixEnabled(); } - if (fix == GameFixes::UltraWide) { g_aspect_fix_enabled = enabled; AspectFixEnabled(); } + if (fix == GameFixes::UltraWide) { g_aspect_fix_enabled = enabled; UltrawideFixEnabled(); } if (fix == GameFixes::Camera) { g_cam_distance_fix_enabled = enabled; CameraDistanceFixEnabled(); } if (fix == GameFixes::DOF) { g_DOF_fix_enabled = enabled; DOFFixEnabled(); } if (fix == GameFixes::Vignetting) { g_Vignetting_fix_enabled = enabled; VignettingFixEnabled(); } if (fix == GameFixes::Fog) { g_Fog_fix_enabled = enabled; FogFixEnabled(); } if (fix == GameFixes::SkipIntro) { g_SkipIntro_fix_enabled = enabled; } - + if (fix == GameFixes::TimeDilation) { g_TimeDilation_fix_enabled = enabled; EnableCheats(Cheat::TimeDilation); } + if (fix == GameFixes::GodMode) { g_GodeMode_fix_enabled = enabled; EnableCheats(Cheat::GodMode); } + if (fix == GameFixes::IgnoreHits) { g_IgnoreHits_fix_enabled = enabled; EnableCheats(Cheat::IgnoreHits); } + if (fix == GameFixes::Stealth) { g_Stealth_fix_enabled = enabled; EnableCheats(Cheat::Stealth); } } extern "C" __declspec(dllexport) void SetFOV(int fov) { @@ -149,6 +186,14 @@ extern "C" __declspec(dllexport) void SetCameraDistance(float cameraDistance) { g_cameraDistanceMultiplier = cameraDistance; } +extern "C" __declspec(dllexport) void SetWorldTimeDilation(float timeDilation) { + g_WorldTimeDilationValue = timeDilation; +} + +extern "C" __declspec(dllexport) void SetAITimeDilation(float timeDilation) { + g_AITimeDilationValue = timeDilation; +} + // Getters for Reshade addon calls extern "C" __declspec(dllexport) void GetGameInfos(GameInfos* infos) { if (!infos) return; @@ -201,7 +246,6 @@ static void FOVFixEnabled() { }); } else FOVHook.enable(); - logger->info("FOV fix enabled"); } if (!(g_fix_enabled && (g_fov_fix_enabled || g_aspect_fix_enabled)) && FOVaddress) { @@ -210,8 +254,100 @@ static void FOVFixEnabled() { } } +static UExponentialHeightFogComponent* fogComponent = nullptr; +static UWorld* previousWorld = nullptr; +static void FogFixEnabled() { + if (FogOpacityEngineaddress) { + if (!FogMaxOpacityHook) FogMaxOpacityHook = safetyhook::create_mid(FogOpacityEngineaddress, + [](SafetyHookContext& ctx) { + if (ctx.rcx) fogComponent = reinterpret_cast(ctx.rcx); + ctx.xmm1.f32[0] = g_fix_enabled && g_Fog_fix_enabled ? 0.f : 1.f; + }); + } + if (Fogaddress) { + if (!FogHook) FogHook = safetyhook::create_mid(Fogaddress + 0x5c, // Generic hook for fogs fixes + [](SafetyHookContext& ctx) { + UWorld* world = UWorld::GetWorld(); + if (world != previousWorld) { + previousWorld = world; + fogComponent = nullptr; + } + if (fogComponent) { + fogComponent->SetFogMaxOpacity(g_fix_enabled && g_Fog_fix_enabled ? 0.f : 1.f); + } + }); + } + if (g_fix_enabled && g_Fog_fix_enabled && FogOpacityEngineaddress) + logger->info("Fog fix enabled"); + if (!(g_fix_enabled && g_Fog_fix_enabled) && FogOpacityEngineaddress) + logger->info("Fog fix disabled"); +} + +// Cheats +static UWorld* LastWorld = nullptr; +static ULONGLONG lastScanTick = 0; // Last time Actors were scanned for enemies time dilation +static void EnableCheats(Cheat cheat) { + if (WorldTimedilationaddress && !WorldTimeDilationHook) { + WorldTimeDilationHook = safetyhook::create_mid(WorldTimedilationaddress + 0x10, + [](SafetyHookContext& ctx) { + // From AWorldSettings retrieved from world->K2_GetWorldSettings() + ctx.xmm0.f32[0] *= g_TimeDilation_fix_enabled ? g_WorldTimeDilationValue : 1.f; + UWorld* world = UWorld::GetWorld(); + if (!world || !world->OwningGameInstance) return; + if (world != LastWorld) { + LastWorld = world; + } + APawn* playerPawn = GetPawnFromWorld(world); + + ULONGLONG now = GetTickCount64(); + if (now - lastScanTick < DEFAULT_ACTORS_SCAN_BETWEEN_TICKS) return; + lastScanTick = now; + + if (world->Levels.Num() == 0) return; + // Enemies time dilation & stealth + 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 j = 0; j < Level->Actors.Num(); j++) { // Loop through actors + AActor* actor = Level->Actors[j]; + if (!actor || !playerPawn || actor == playerPawn) continue; // We don't want to affect Traveler + if (!actor->IsA(ACronosBaseEnemyCharacter::StaticClass())) continue; // actor is enemy + // Set enemy alert + ACronosBaseEnemyCharacter* enemy = static_cast(actor); + if (!enemy) continue; + + enemy->CustomTimeDilation = g_TimeDilation_fix_enabled ? g_AITimeDilationValue : 1.f; // Enemy time dilation + } + } + // ignore hits + AActor* traveler = static_cast(playerPawn); + if (traveler) traveler->bCanBeDamaged = !g_IgnoreHits_fix_enabled; // Traveler won't be hurt + }); + } + + if (StealthModeaddress && !StealthHook) { // Hook function UAIPerceptionComponent -> GetPerceivedHostileActors + StealthHook = safetyhook::create_mid(StealthModeaddress - 0x86, + [](SafetyHookContext& ctx) { + if (!g_Stealth_fix_enabled || !ctx.rcx) return; + auto perception = reinterpret_cast(ctx.rcx); + + if (!perception) return; + perception->ForgetAll(); + }); + } + if (g_GodeMode_fix_enabled && GodModeaddress) + Memory::PatchBytes(GodModeaddress, "\x90\x90\x90\x90\x90", 5); // subss xmm6,xmm9 + if (!g_GodeMode_fix_enabled && GodModeaddress) Memory::RestoreBytes(GodModeaddress); + + if (cheat == Cheat::TimeDilation) logger->info("Time dilation cheat {}", g_TimeDilation_fix_enabled ? "enabled" : "disabled"); + if (cheat == Cheat::GodMode) logger->info("God mode cheat {}", g_GodeMode_fix_enabled ? "enabled" : "disabled"); + if (cheat == Cheat::IgnoreHits) logger->info("Ignore hits cheat {}", g_IgnoreHits_fix_enabled ? "enabled" : "disabled"); + if (cheat == Cheat::Stealth) logger->info("Stealth cheat {}", g_Stealth_fix_enabled ? "enabled" : "disabled"); +} + // Memory patch fixes -static void AspectFixEnabled() { +static void UltrawideFixEnabled() { if (g_fix_enabled && g_aspect_fix_enabled && Aspectaddress) { const char* newAspectRatio = Memory::Float32ToHexBytes(aspectRatio); // Converts new apsect ratio in 4 char bytes Memory::PatchBytes(Aspectaddress + 0x3, newAspectRatio, 4); // mov [rdi+00000254],3FE38E39 <= patched @@ -245,17 +381,6 @@ static void VignettingFixEnabled() { } } -static void FogFixEnabled() { - if (g_fix_enabled && g_Fog_fix_enabled && Fogaddress) { - if (!FogHook) { // Hook only once - FogHook = safetyhook::create_mid(Fogaddress + 0x12, - [](SafetyHookContext& ctx) { - ctx.rflags &= ~0x40; // ZF=0 - }); - } - logger->info("Fog fix enabled"); - } -} static void CameraDistanceFixEnabled() { if (g_fix_enabled && g_cam_distance_fix_enabled && CameraDistanceaddress) { @@ -288,42 +413,7 @@ static void EnableConsole() { } logger->info("-------------- Console re-enabling --------------"); - - std::thread([&]() { - auto start = std::chrono::high_resolution_clock::now(); // Measure the time to renable console - UEngine* Engine = nullptr; - - for (int i = 0; i < 100; ++i) { // gives 10 seconds to find UE Engine - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - Engine = UEngine::GetEngine(); - - if (Engine && Engine->ConsoleClass && Engine->GameViewport) - break; - } - - if (!Engine || !Engine->ConsoleClass || !Engine->GameViewport) { - logger->error("Console could not be found in engine."); - return; - } - logger->info("Console found in engine"); - - /* Creates a new UObject of class-type specified by Engine->ConsoleClass */ - UObject* NewObject = UGameplayStatics::SpawnObject(Engine->ConsoleClass, Engine->GameViewport); - if (NewObject) { - logger->info("Successfully spawned console object"); - // Set the console viewport so that it will be displayed - Engine->GameViewport->ViewportConsole = static_cast(NewObject); - auto end = std::chrono::high_resolution_clock::now(); - std::chrono::duration elapsed = end - start; - - logger->info("Console fully reactivated in {:.3f}s and bound to key Tilde", elapsed.count()); - logger->info("------------------ User inputs ------------------"); - g_Console_Enabled = true; - } - else { - logger->error("Could not spawn console object"); - } - }).detach(); + ReactivateDevConsole(logger); } // Logging