#include "UETools.hpp" #include "Engine_classes.hpp" #include "UMG_classes.hpp" SDK::APawn* GetPawnFromWorld(SDK::UWorld* world) { if (!world) world = SDK::UWorld::GetWorld(); if (!world) return nullptr; SDK::UGameInstance* gameInstance = world->OwningGameInstance; if (!gameInstance || gameInstance->LocalPlayers.Num() == 0) return nullptr; SDK::ULocalPlayer* localPlayer = gameInstance->LocalPlayers[0]; if (!localPlayer) return nullptr; SDK::APlayerController* pc = localPlayer->PlayerController; if (!pc) return nullptr; SDK::APawn* pawn = pc->AcknowledgedPawn; return pawn; } void ReactivateDevConsole(std::shared_ptr logger) { std::thread([logger]() { auto start = std::chrono::high_resolution_clock::now(); // Measure the time to renable console SDK::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 = SDK::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 */ SDK::UObject* NewObject = SDK::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; // Set the all the console shortkey to F2 for (int i = 0; i < SDK::UInputSettings::GetDefaultObj()->ConsoleKeys.Num(); i++) { SDK::UInputSettings::GetDefaultObj()->ConsoleKeys[i].KeyName = SDK::UKismetStringLibrary::Conv_StringToName(L"F2"); } logger->info("Console fully reactivated in {:.3f}s and bound to key F2", elapsed.count()); logger->info("------------------ User inputs ------------------"); g_Console_Enabled.store(true, std::memory_order_release); return; } else { logger->error("Could not spawn console object"); return; } }).detach(); } void ApplyOffsetsRecursive(SDK::UWidget* widget, float left, float right) { if (widget && widget->Slot && widget->Slot->IsA(SDK::UCanvasPanelSlot::StaticClass())) { auto* slot = (SDK::UCanvasPanelSlot*)widget->Slot; if (!slot) return; SDK::FMargin offsets = slot->GetOffsets(); if (offsets.Left != left || offsets.Right != right) { offsets.Left = left; offsets.Right = right; slot->SetOffsets(offsets); } } // Go down if UPanelWidget if (widget && widget->IsA(SDK::UPanelWidget::StaticClass())) { if (auto* panel = (SDK::UPanelWidget*)widget) for (int i = 0; i < panel->GetChildrenCount(); ++i) ApplyOffsetsRecursive(panel->GetChildAt(i), left, right); } }