From 80e9b82f6b84f1b042a48a38be622311630f31f1 Mon Sep 17 00:00:00 2001 From: Lyall Stamper Date: Thu, 29 Aug 2024 11:52:01 +0100 Subject: [PATCH] Switch to dynamic offsets for SDK. --- src/SDK/Basic.hpp | 12 ++-- src/SDK/Engine_functions.cpp | 2 +- src/dllmain.cpp | 112 ++++++++++++++++++++++++----------- 3 files changed, 83 insertions(+), 43 deletions(-) diff --git a/src/SDK/Basic.hpp b/src/SDK/Basic.hpp index b3ce7ab..9edcb30 100644 --- a/src/SDK/Basic.hpp +++ b/src/SDK/Basic.hpp @@ -31,12 +31,12 @@ using namespace UC; */ namespace Offsets { - constexpr int32 GObjects = 0x043F9320; - constexpr int32 AppendString = 0x00EBA200; - constexpr int32 GNames = 0x043BCFC0; - constexpr int32 GWorld = 0x0453D030; - constexpr int32 ProcessEvent = 0x010B2340; - constexpr int32 ProcessEventIdx = 0x00000044; + inline int32 GObjects = 0x0; // 0x043F9320; + inline int32 AppendString = 0x0; // 0x00EBA200; + inline int32 GNames = 0x0; // 0x043BCFC0; + inline int32 GWorld = 0x0; // 0x0453D030; + inline int32 ProcessEvent = 0x0; // 0x010B2340; + inline int32 ProcessEventIdx = 0x00000044; } namespace InSDKUtils diff --git a/src/SDK/Engine_functions.cpp b/src/SDK/Engine_functions.cpp index 52a93d6..ca36495 100644 --- a/src/SDK/Engine_functions.cpp +++ b/src/SDK/Engine_functions.cpp @@ -77714,7 +77714,7 @@ void UKismetGuidLibrary::Parse_StringToGuid(const class FString& GuidString, str class UWorld* UWorld::GetWorld() { - if constexpr (Offsets::GWorld != 0) + if (Offsets::GWorld != 0) return *reinterpret_cast(InSDKUtils::GetImageBase() + Offsets::GWorld); if (UEngine* Engine = UEngine::GetEngine()) diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 032ed7a..b22520c 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -25,7 +25,7 @@ HMODULE baseModule = GetModuleHandle(NULL); // Version std::string sFixName = "SMTVFix"; -std::string sFixVer = "0.9.4"; +std::string sFixVer = "0.9.5"; std::string sLogFile = sFixName + ".log"; // Logger @@ -336,6 +336,43 @@ void ReadConfig() CalculateAspectRatio(); } +void UpdateOffsets() +{ + // GObjects + uint8_t* GObjectsScanResult = Memory::PatternScan(baseModule, "48 8B ?? ?? ?? ?? ?? 48 8B ?? ?? 48 8D ?? ?? EB ?? 33 ?? 8B ?? ?? C1 ??"); + if (GObjectsScanResult) { + spdlog::info("Offsets: GObjects: Address is {:s}+{:x}", sExeName.c_str(), (uintptr_t)GObjectsScanResult - (uintptr_t)baseModule); + uintptr_t GObjectsAddr = Memory::GetAbsolute((uintptr_t)GObjectsScanResult + 0x3); + SDK::Offsets::GObjects = (uintptr_t)GObjectsAddr - (uintptr_t)baseModule; + spdlog::info("Offsets: GObjects: Offset: {:x}", SDK::Offsets::GObjects); + } + else if (!GObjectsScanResult) { + spdlog::error("Offsets: GObjects: Pattern scan failed."); + } + + // AppendString + uint8_t* AppendStringScanResult = Memory::PatternScan(baseModule, "48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 48 83 ?? ?? 8B ?? 48 8B ?? 8B ?? 44 0F ?? ?? C1 ?? 10 48 8B ?? 80 3D ?? ?? ?? ?? 00 89 ?? ?? ?? 44 89 ?? ?? ?? 74 ?? 4C 8D ?? ?? ?? ?? ?? EB ?? 48 8D ?? ?? ?? ?? ?? E8 ?? ?? ?? ?? 4C ?? ?? C6 ?? ?? ?? ?? ?? 01 48 8B ?? ?? ?? 48 8B ?? 48 ?? ?? ?? 8D ?? ?? 49 ?? ?? ?? ?? E8 ?? ?? ?? ?? 83 ?? ?? 00"); + if (AppendStringScanResult) { + spdlog::info("Offsets: AppendString: Address is {:s}+{:x}", sExeName.c_str(), (uintptr_t)AppendStringScanResult - (uintptr_t)baseModule); + SDK::Offsets::AppendString = (uintptr_t)AppendStringScanResult - (uintptr_t)baseModule; + spdlog::info("Offsets: AppendString: Offset: {:x}", SDK::Offsets::AppendString); + } + else if (!AppendStringScanResult) { + spdlog::error("Offsets: AppendString: Pattern scan failed."); + } + + // ProcessEvent + uint8_t* ProcessEventScanResult = Memory::PatternScan(baseModule, "40 ?? 56 57 41 ?? 41 ?? 41 ?? 41 ?? 48 81 ?? ?? ?? ?? ?? 48 8D ?? ?? ?? 48 89 ?? ?? ?? ?? ?? 48 8B ?? ?? ?? ?? ?? 48 33 ?? 48 89 ?? ?? ?? ?? ?? 8B ?? ?? 45 33 ??"); + if (ProcessEventScanResult) { + spdlog::info("Offsets: ProcessEvent: Address is {:s}+{:x}", sExeName.c_str(), (uintptr_t)ProcessEventScanResult - (uintptr_t)baseModule); + SDK::Offsets::ProcessEvent = (uintptr_t)ProcessEventScanResult - (uintptr_t)baseModule; + spdlog::info("Offsets: ProcessEvent: Offset: {:x}", SDK::Offsets::ProcessEvent); + } + else if (!ProcessEventScanResult) { + spdlog::error("Offsets: ProcessEvent: Pattern scan failed."); + } +} + void GetCVARs() { // Get console objects @@ -1012,53 +1049,55 @@ void EnableConsole() { if (bEnableConsole) { - // Get GEngine - SDK::UEngine* engine = nullptr; + if (SDK::Offsets::GObjects && SDK::Offsets::AppendString) { + // Get GEngine + SDK::UEngine* engine = nullptr; - int i = 0; - while (i < 100) { // 10s - engine = SDK::UEngine::GetEngine(); + int i = 0; + while (i < 100) { // 10s + engine = SDK::UEngine::GetEngine(); - if (engine) { - if (engine->ConsoleClass && engine->GameViewport) { - break; + if (engine) { + if (engine->ConsoleClass && engine->GameViewport) { + break; + } } - } - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - i++; - } + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + i++; + } - if (i == 100) { - spdlog::error("Construct Console: Failed to find GEngine address after 10 seconds."); - return; - } + if (i == 100) { + spdlog::error("Construct Console: Failed to find GEngine address after 10 seconds."); + return; + } - spdlog::info("Construct Console: GEngine address = {:x}", (uintptr_t)engine); + spdlog::info("Construct Console: GEngine address = {:x}", (uintptr_t)engine); - // Construct console - if (engine->ConsoleClass && engine->GameViewport) { - SDK::UObject* NewObject = SDK::UGameplayStatics::SpawnObject(engine->ConsoleClass, engine->GameViewport); - if (NewObject) { - engine->GameViewport->ViewportConsole = static_cast(NewObject); - spdlog::info("Construct Console: Console object constructed."); + // Construct console + if (engine->ConsoleClass && engine->GameViewport) { + SDK::UObject* NewObject = SDK::UGameplayStatics::SpawnObject(engine->ConsoleClass, engine->GameViewport); + if (NewObject) { + engine->GameViewport->ViewportConsole = static_cast(NewObject); + spdlog::info("Construct Console: Console object constructed."); + } + else { + spdlog::error("Construct Console: Failed to construct console object."); + return; + } } else { - spdlog::error("Construct Console: Failed to construct console object."); + spdlog::error("Construct Console: Failed to construct console object - ConsoleClass or GameViewport is null."); return; } - } - else { - spdlog::error("Construct Console: Failed to construct console object - ConsoleClass or GameViewport is null."); - return; - } - // Log console key - if (SDK::UInputSettings::GetInputSettings()->ConsoleKeys && SDK::UInputSettings::GetInputSettings()->ConsoleKeys.Num() > 0) { - spdlog::info("Construct Console: Console enabled - access it using key: {}.", SDK::UInputSettings::GetInputSettings()->ConsoleKeys[0].KeyName.ToString()); - } - else { - spdlog::error("Console enabled but no console key is bound.\nAdd this to %LOCALAPPDATA%\\SMT5V\\Saved\\Config\\WindowsNoEditor\\Input.ini -\n[/Script/Engine.InputSettings]\nConsoleKeys = Tilde"); + // Log console key + if (SDK::UInputSettings::GetInputSettings()->ConsoleKeys && SDK::UInputSettings::GetInputSettings()->ConsoleKeys.Num() > 0) { + spdlog::info("Construct Console: Console enabled - access it using key: {}.", SDK::UInputSettings::GetInputSettings()->ConsoleKeys[0].KeyName.ToString()); + } + else { + spdlog::error("Console enabled but no console key is bound.\nAdd this to %LOCALAPPDATA%\\SMT5V\\Saved\\Config\\WindowsNoEditor\\Input.ini -\n[/Script/Engine.InputSettings]\nConsoleKeys = Tilde"); + } } } } @@ -1186,6 +1225,7 @@ DWORD __stdcall Main(void*) { Logging(); ReadConfig(); + UpdateOffsets(); CurrentResolution(); GetCVARs(); IntroSkip();