From 64c93f555729d3ac2c769abd1cbf35f7c6ea53b0 Mon Sep 17 00:00:00 2001 From: Emmanuel AYME Date: Sun, 7 Sep 2025 18:46:41 +0200 Subject: [PATCH] Add Unreal Engine console re-enabling --- Cronos The New Dawn/dllmain.cpp | 80 ++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 11 deletions(-) diff --git a/Cronos The New Dawn/dllmain.cpp b/Cronos The New Dawn/dllmain.cpp index a40e1e4..d7743db 100644 --- a/Cronos The New Dawn/dllmain.cpp +++ b/Cronos The New Dawn/dllmain.cpp @@ -1,12 +1,16 @@ -#include "Memory.hpp"; -#include "Maths.hpp"; -#include "ObfuscateString.h" #include #include #include #include #include #include +#include +#include "Memory.hpp"; +#include "Maths.hpp"; +#include "ObfuscateString.h" +#include "SDK/Engine_classes.hpp" + +using namespace SDK; // Constants const std::string PLUGIN_NAME = "CronosTND"; @@ -22,10 +26,6 @@ static int screenWidth = GetSystemMetrics(SM_CXSCREEN); static int screenHeight = GetSystemMetrics(SM_CYSCREEN); static float aspectRatio = (float)screenWidth / screenHeight; -// Transform screen width into bytes little-endian -//float floatWidth = static_cast(screenWidth); -//char* bytesWidth = reinterpret_cast(&floatWidth); - // Plugin states static bool AOBScanDone = false; static bool g_fix_enabled = false; @@ -40,6 +40,7 @@ static int g_AdditionalFOVValue = 0; static float g_FOV_In = 0; static float g_Compensated_FOV = 0; static float g_FOV_Out = 0; +static bool g_Console_Enabled = false; // AOB Scan pointers static uint8_t* FOVaddress = nullptr; @@ -60,6 +61,7 @@ static void AspectFixEnabled(bool fix_enabled); static void DOFFixEnabled(bool fix_enabled); static void VignettingFixEnabled(bool fix_enabled); static void FogFixEnabled(bool fix_enabled); +static void EnableConsole(); uint8_t* basePtr = reinterpret_cast(GetModuleHandleA(nullptr)); @@ -158,8 +160,9 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) AOBScanDone = true; } - logger->info("--------------- AOB scan finished ---------------"); + logger->info("-------------- Fixes initialisation -------------"); } + if (g_fix_enabled) { if (FOVaddress) FOVFixEnabled(g_fov_fix_enabled || g_aspect_fix_enabled); if (Aspectaddress) AspectFixEnabled(g_aspect_fix_enabled); @@ -173,7 +176,7 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) if (DOFaddress) DOFFixEnabled(false); if (Vignettingaddress) VignettingFixEnabled(false); if (Fogaddress) FogFixEnabled(false); - logger->info("All fixes disabled."); + logger->info("All fixes disabled"); } } @@ -213,6 +216,11 @@ extern "C" __declspec(dllexport) void SetFOV(int fov) g_AdditionalFOVValue = fov; } +extern "C" __declspec(dllexport) void SetConsole() +{ + EnableConsole(); +} + // Getters for Reshade addon calls extern "C" __declspec(dllexport) float GetFOVIn() { return g_FOV_In; @@ -226,6 +234,10 @@ extern "C" __declspec(dllexport) float GetFOVOut() { return g_FOV_Out; } +extern "C" __declspec(dllexport) bool GetConsoleEnabled() { + return g_Console_Enabled; +} + // Code injection functions static void FOVFixEnabled(bool fix_enabled) { if (g_fix_enabled && fix_enabled && FOVaddress) { @@ -300,6 +312,49 @@ static void FogFixEnabled(bool fix_enabled) { } } +// UE Console creation +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 binded to key Tilde", elapsed.count()); + logger->info("------------------ User inputs ------------------"); + g_Console_Enabled = true; + } + else { + logger->error("Could not spawn console object"); + } + }).detach(); +} + // Logging static void InitializeLogger() { @@ -325,8 +380,11 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID) { if (reason == DLL_PROCESS_ATTACH) { - InitializeLogger(); - logger->info("Plugin {} loaded.", PLUGIN_NAME); + if (reason == DLL_PROCESS_ATTACH) + { + InitializeLogger(); + logger->info("Plugin {} loaded.", PLUGIN_NAME); + } } } else if (reason == DLL_PROCESS_DETACH)