Skip to content

Commit

Permalink
Update SDK offsets to be dynamic. Should add resiliency against futur…
Browse files Browse the repository at this point in the history
…e patches breaking things.
  • Loading branch information
Lyall committed Aug 29, 2024
1 parent 19a275d commit 5d3db07
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 40 deletions.
12 changes: 6 additions & 6 deletions src/SDK/Basic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ using namespace UC;
*/
namespace Offsets
{
constexpr int32 GObjects = 0x1D76CC30;
constexpr int32 AppendString = 0x0CD72A90;
constexpr int32 GNames = 0x1D6CDC00;
constexpr int32 GWorld = 0x1D8CF0F0;
constexpr int32 ProcessEvent = 0x0CF09080;
constexpr int32 ProcessEventIdx = 0x0000004A;
inline int32 GObjects = 0x0; // 0x1D76CC30;
inline int32 AppendString = 0x0; // 0x0CD72A90;
inline int32 GNames = 0x0; // 0x1D6CDC00;
inline int32 GWorld = 0x0; // 0x1D8CF0F0;
inline int32 ProcessEvent = 0x0; // 0x0CF09080;
inline int32 ProcessEventIdx = 0x0000004A;
}

namespace InSDKUtils
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Engine_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14474,7 +14474,7 @@ void UStreamableRenderAsset::SetForceMipLevelsToBeResident(float Seconds, int32

class UWorld* UWorld::GetWorld()
{
if constexpr (Offsets::GWorld != 0)
if (Offsets::GWorld != 0)
return *reinterpret_cast<UWorld**>(InSDKUtils::GetImageBase() + Offsets::GWorld);

if (UEngine* Engine = UEngine::GetEngine())
Expand Down
109 changes: 76 additions & 33 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,53 +238,58 @@ void EnableConsole()
{
// Enable developer console
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 < 300) { // 30s
engine = SDK::UEngine::GetEngine();
int i = 0;
while (i < 300) { // 30s
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 30 seconds.");
return;
}
if (i == 100) {
spdlog::error("Construct Console: Failed to find GEngine address after 30 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<SDK::UConsole*>(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<SDK::UConsole*>(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());
// 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::warn("Console enabled but no console key is bound.\nAdd this to %LOCALAPPDATA%\\b1\\Saved\\Config\\Windows\\Input.ini -\n[/Script/Engine.InputSettings]\nConsoleKeys = Tilde");
}
}
else {
spdlog::warn("Console enabled but no console key is bound.\nAdd this to %LOCALAPPDATA%\\b1\\Saved\\Config\\Windows\\Input.ini -\n[/Script/Engine.InputSettings]\nConsoleKeys = Tilde");
spdlog::error("Construct Console: GObjects or AppendString offset invalid.");
}
}
}
Expand Down Expand Up @@ -476,10 +481,48 @@ void AspectFOV()
}
}

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 ?? ?? ?? 57 48 83 ?? ?? 80 3D ?? ?? ?? ?? 00 48 8B ?? 48 8B ?? 74 ?? 4C 8D ?? ?? ?? ?? ?? EB ?? 48 8D ?? ?? ?? ?? ?? E8 ?? ?? ?? ?? 4C ?? ?? C6 ?? ?? ?? ?? ?? 01 8B ?? 8B ?? 0F ?? ?? C1 ?? 10 89 ?? ?? ?? 89 ?? ?? ?? 48 8B ?? ?? ?? 48 ?? ?? ?? 8D ?? ?? 49 ?? ?? ?? ?? 48 8B ?? 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 ?? ?? ?? ?? ?? ?? 48 8D ?? ?? ?? 48 89 ?? ?? ?? ?? ?? 48 8B ?? ?? ?? ?? ?? 48 ?? ?? 48 89 ?? ?? ?? ?? ?? 4D ?? ?? 48 ?? ?? 4C ?? ?? 48 ?? ??");
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.");
}
}

DWORD __stdcall Main(void*)
{
Logging();
Configuration();
UpdateOffsets();
CurrentResolution();
EnableConsole();
GetCVARs();
Expand Down

0 comments on commit 5d3db07

Please sign in to comment.