Remove spdlog initialization. Fixed and issue with GetPawnFromWorld crashing in some occasions. Add a function to apply cvars visual effects. Add a fallback function to retrieve GWorld.
This commit is contained in:
@@ -1,8 +1,44 @@
|
||||
#include "UETools.hpp"
|
||||
#pragma once
|
||||
|
||||
#include "UETools.hpp"
|
||||
#include "Engine_classes.hpp"
|
||||
|
||||
std::shared_ptr<spdlog::logger> g_logger;
|
||||
// UE settings
|
||||
// Visual effects toggle
|
||||
void ApplyVisualEffect(GameFixes fix, bool enabled) {
|
||||
SDK::UWorld* world = SDK::UWorld::GetWorld();
|
||||
SDK::APawn* pawn = nullptr;
|
||||
SDK::APlayerController* pc = nullptr;
|
||||
|
||||
if (world) {
|
||||
pawn = GetPawnFromWorld(world);
|
||||
if (pawn && pawn->Controller)
|
||||
pc = static_cast<SDK::APlayerController*>(pawn->Controller);
|
||||
}
|
||||
|
||||
SDK::FString cmd = GetCommand(fix, enabled);
|
||||
if (!cmd) return;
|
||||
|
||||
SDK::UKismetSystemLibrary::ExecuteConsoleCommand(world, SDK::FString(cmd), pc);
|
||||
}
|
||||
|
||||
UC::FString GetCommand(GameFixes fix, bool enabled) {
|
||||
switch (fix) {
|
||||
case GameFixes::Fog:
|
||||
return enabled ? L"r.Fog 0" : L"r.Fog 1";
|
||||
case GameFixes::DOF:
|
||||
return enabled ? L"r.DepthOfFieldQuality 0" : L"r.DepthOfFieldQuality 1";
|
||||
case GameFixes::FilmGrain:
|
||||
return enabled ? L"r.FilmGrain 0" : L"r.FilmGrain 1";
|
||||
case GameFixes::Vignetting:
|
||||
return enabled ? L"r.Tonemapper.Quality 0" : L"r.Tonemapper.Quality 5";
|
||||
case GameFixes::ChromaticAberrations:
|
||||
return enabled ? L"r.SceneColorFringeQuality 0" : L"r.SceneColorFringeQuality 1";
|
||||
default:
|
||||
return SDK::FString();
|
||||
}
|
||||
}
|
||||
|
||||
// UE settings (resolution ...)
|
||||
void GetResolution(int& outWidth, int& outHeight, float& outAspectRatio) {
|
||||
SDK::UEngine* Engine = SDK::UEngine::GetEngine();
|
||||
if (!Engine || !Engine->GameUserSettings) return;
|
||||
@@ -15,27 +51,45 @@ void GetResolution(int& outWidth, int& outHeight, float& outAspectRatio) {
|
||||
outHeight = (int)Res.Y;
|
||||
outAspectRatio = (float)outWidth / outHeight;
|
||||
}
|
||||
// UE objects
|
||||
|
||||
// Objects retrieval functions
|
||||
SDK::UWorld* GetWorldFromContext(uintptr_t ptr) {
|
||||
SDK::UObject* obj = reinterpret_cast<SDK::UObject*>(ptr);
|
||||
|
||||
while (obj) {
|
||||
if (obj->IsA(SDK::UWorld::StaticClass())) return (SDK::UWorld*)obj;
|
||||
obj = obj->Outer;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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 (!gameInstance) return nullptr;
|
||||
|
||||
auto& localPlayers = gameInstance->LocalPlayers;
|
||||
if (!localPlayers.IsValid() || !localPlayers.IsValidIndex(0)) return nullptr;
|
||||
|
||||
SDK::ULocalPlayer* localPlayer = localPlayers[0];
|
||||
if (!localPlayer) return nullptr;
|
||||
|
||||
SDK::APlayerController* pc = localPlayer->PlayerController;
|
||||
if (!pc) return nullptr;
|
||||
SDK::APawn* pawn = pc->AcknowledgedPawn;
|
||||
|
||||
SDK::APawn* pawn = pc->AcknowledgedPawn;
|
||||
return pawn;
|
||||
}
|
||||
|
||||
SDK::APawn* GetPawnFromObject(SDK::UObject* object) {
|
||||
auto* actor = static_cast<SDK::AActor*> (object);
|
||||
if (!actor || !actor->Class || !actor->IsA(SDK::APawn::StaticClass())) return nullptr;
|
||||
|
||||
auto* pawn = static_cast<SDK::APawn*>(actor);
|
||||
if (!pawn) return nullptr;
|
||||
|
||||
auto* controller = pawn->Controller;
|
||||
if (!controller || !controller->IsA(SDK::APlayerController::StaticClass())) return nullptr;
|
||||
|
||||
@@ -43,7 +97,6 @@ SDK::APawn* GetPawnFromObject(SDK::UObject* object) {
|
||||
}
|
||||
// Console
|
||||
void ReactivateDevConsole(std::shared_ptr<spdlog::logger> logger) {
|
||||
g_logger = logger;
|
||||
std::thread([logger]() {
|
||||
auto start = std::chrono::high_resolution_clock::now(); // Measure the time to renable console
|
||||
SDK::UEngine* Engine = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user