Add Unreal Engine console re-enabling

This commit is contained in:
2025-09-07 18:46:41 +02:00
parent c4bd16ab69
commit 64c93f5557

View File

@@ -1,12 +1,16 @@
#include "Memory.hpp";
#include "Maths.hpp";
#include "ObfuscateString.h"
#include <string> #include <string>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <spdlog/sinks/rotating_file_sink.h> #include <spdlog/sinks/rotating_file_sink.h>
#include <filesystem> #include <filesystem>
#include <thread> #include <thread>
#include <safetyhook.hpp> #include <safetyhook.hpp>
#include <chrono>
#include "Memory.hpp";
#include "Maths.hpp";
#include "ObfuscateString.h"
#include "SDK/Engine_classes.hpp"
using namespace SDK;
// Constants // Constants
const std::string PLUGIN_NAME = "CronosTND"; const std::string PLUGIN_NAME = "CronosTND";
@@ -22,10 +26,6 @@ static int screenWidth = GetSystemMetrics(SM_CXSCREEN);
static int screenHeight = GetSystemMetrics(SM_CYSCREEN); static int screenHeight = GetSystemMetrics(SM_CYSCREEN);
static float aspectRatio = (float)screenWidth / screenHeight; static float aspectRatio = (float)screenWidth / screenHeight;
// Transform screen width into bytes little-endian
//float floatWidth = static_cast<float>(screenWidth);
//char* bytesWidth = reinterpret_cast<char*>(&floatWidth);
// Plugin states // Plugin states
static bool AOBScanDone = false; static bool AOBScanDone = false;
static bool g_fix_enabled = 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_FOV_In = 0;
static float g_Compensated_FOV = 0; static float g_Compensated_FOV = 0;
static float g_FOV_Out = 0; static float g_FOV_Out = 0;
static bool g_Console_Enabled = false;
// AOB Scan pointers // AOB Scan pointers
static uint8_t* FOVaddress = nullptr; static uint8_t* FOVaddress = nullptr;
@@ -60,6 +61,7 @@ static void AspectFixEnabled(bool fix_enabled);
static void DOFFixEnabled(bool fix_enabled); static void DOFFixEnabled(bool fix_enabled);
static void VignettingFixEnabled(bool fix_enabled); static void VignettingFixEnabled(bool fix_enabled);
static void FogFixEnabled(bool fix_enabled); static void FogFixEnabled(bool fix_enabled);
static void EnableConsole();
uint8_t* basePtr = reinterpret_cast<uint8_t*>(GetModuleHandleA(nullptr)); uint8_t* basePtr = reinterpret_cast<uint8_t*>(GetModuleHandleA(nullptr));
@@ -158,8 +160,9 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
AOBScanDone = true; AOBScanDone = true;
} }
logger->info("--------------- AOB scan finished ---------------"); logger->info("-------------- Fixes initialisation -------------");
} }
if (g_fix_enabled) { if (g_fix_enabled) {
if (FOVaddress) FOVFixEnabled(g_fov_fix_enabled || g_aspect_fix_enabled); if (FOVaddress) FOVFixEnabled(g_fov_fix_enabled || g_aspect_fix_enabled);
if (Aspectaddress) AspectFixEnabled(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 (DOFaddress) DOFFixEnabled(false);
if (Vignettingaddress) VignettingFixEnabled(false); if (Vignettingaddress) VignettingFixEnabled(false);
if (Fogaddress) FogFixEnabled(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; g_AdditionalFOVValue = fov;
} }
extern "C" __declspec(dllexport) void SetConsole()
{
EnableConsole();
}
// Getters for Reshade addon calls // Getters for Reshade addon calls
extern "C" __declspec(dllexport) float GetFOVIn() { extern "C" __declspec(dllexport) float GetFOVIn() {
return g_FOV_In; return g_FOV_In;
@@ -226,6 +234,10 @@ extern "C" __declspec(dllexport) float GetFOVOut() {
return g_FOV_Out; return g_FOV_Out;
} }
extern "C" __declspec(dllexport) bool GetConsoleEnabled() {
return g_Console_Enabled;
}
// Code injection functions // Code injection functions
static void FOVFixEnabled(bool fix_enabled) { static void FOVFixEnabled(bool fix_enabled) {
if (g_fix_enabled && fix_enabled && FOVaddress) { 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<UConsole*>(NewObject);
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> 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 // Logging
static void InitializeLogger() static void InitializeLogger()
{ {
@@ -325,8 +380,11 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID)
{ {
if (reason == DLL_PROCESS_ATTACH) if (reason == DLL_PROCESS_ATTACH)
{ {
InitializeLogger(); if (reason == DLL_PROCESS_ATTACH)
logger->info("Plugin {} loaded.", PLUGIN_NAME); {
InitializeLogger();
logger->info("Plugin {} loaded.", PLUGIN_NAME);
}
} }
} }
else if (reason == DLL_PROCESS_DETACH) else if (reason == DLL_PROCESS_DETACH)