Add HUD scaling. Add cheats. Code refactoring

This commit is contained in:
2026-02-08 11:04:45 +01:00
parent 06feca037d
commit 5ee8425c3b

View File

@@ -1,45 +1,53 @@
#include <unordered_set>
#include "CommonHeaders.h"
#include "GameFixes.h"
#include "GameInformations.h"
#include "ObfuscateString.h"
#include "Memory.hpp"
#include "Maths.hpp"
#include "CommonHeaders.h"
#include "UEngine.hpp"
#include "UETools.hpp"
#include "UEvars.hpp"
#include "Logger.hpp"
#include "SDK/Basic.hpp"
#include "SDK/Engine_classes.hpp"
#include "SDK/Ghost_classes.hpp"
#include "SDK/WBP_InGameHUDLayout_classes.hpp"
#include "SDK/UIExtension_classes.hpp"
using namespace SDK;
// Constants
const std::string PLUGIN_NAME = "SpongeBobTOTT";
const std::string PLUGIN_LOG = PLUGIN_NAME + ".log";
constexpr ULONGLONG DEFAULT_ACTORS_SCAN_BETWEEN_TICKS = 300; // Used for enemies time dilation
// Logger
std::shared_ptr<spdlog::logger> logger;
// Screen informations
static int screenWidth = GetSystemMetrics(SM_CXSCREEN);
static int screenHeight = GetSystemMetrics(SM_CYSCREEN);
// Plugin states
static bool AOBScanDone = false;
static bool g_Console = false;
static bool g_fix_enabled = false;
static bool g_fov_fix_enabled = false;
static bool g_ultrawide_fix_enabled = false;
static bool g_HUD_fix_enabled = false;
static bool g_Camera_fix_enabled = false;
static bool g_DOF_fix_enabled = false;
static bool g_CA_fix_enabled = false;
static bool g_Vignetting_fix_enabled = false;
static bool g_Fog_fix_enabled = false;
static bool g_TimeDilation_fix_enabled = false;
static bool g_GodMode_fix_enabled = false;
static bool g_Stealth_fix_enabled = false;
static int g_AdditionalFOVValue = 0;
static float g_WorldTimeDilationValue = 1.f;
static float g_AITimeDilationValue = 1.f;
static int g_HUDOffsets = 0.f;
static float g_PlayerHealth = 0.f;
static bool user_inputs_logged = false;
// Shared values
static float g_FOV_In = 60.f;
static float g_FOV_Out = 60.f;
static bool g_Console_Enabled = false;
// AOB Unreal Engine offsets addresses
static uint8_t* GObjectsaddress = nullptr;
static uint8_t* AppendStringaddress = nullptr;
static uint8_t* ProcessEventaddress = nullptr;
// AOB Scan pointers
static uint8_t* FOVaddress = nullptr;
@@ -50,81 +58,59 @@ static uint8_t* Vignettingaddress = nullptr;
static uint8_t* Fogaddress = nullptr;
static uint8_t* CameraComponentaddress = nullptr;
static uint8_t* ConstrainAspectRatioaddress = nullptr;
static uint8_t* WorldTimedilationaddress = nullptr;
static uint8_t* Stealthaddress = nullptr;
// Hooking
static SafetyHookMid FOVHook{};
static SafetyHookMid PEHook{};
static SafetyHookMid WorldTimeDilationHook{};
static SafetyHookMid StealthHook{};
// Prototypes
static void FOVFixEnabled();
static void UltraWideFixEnabled();
static void HUDFixEnabled();
static void LogHUD();
static void DOFFixEnabled();
static void CAFixEnabled();
static void VignettingFixEnabled();
static void FogFixEnabled();
static void EnableConsole();
static void EnableCheats(Cheat cheat);
static void ProcessEvent();
extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
{
extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
g_fix_enabled = enabled;
if (g_fix_enabled && !AOBScanDone) { // Unreal Engine 5.6
if (!AOBScanDone) { // Unreal Engine 5.6
logger->info("--------------- AOB scan started ---------------");
if (CameraComponentaddress == nullptr) { // Unreal Engine 5.3.2
constexpr auto FOVStringObfuscated = make_obfuscated<0x4A>("EB ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 8B 83 ?? ?? ?? ?? 89");
CameraComponentaddress = Memory::AOBScan("", FOVStringObfuscated.decrypt(), PAGE_EXECUTE_READ, logger);
constexpr auto FOVStringObfuscated = make_obfuscated<0xF3>("EB ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 8B 83 ?? ?? ?? ?? 89");
constexpr auto DOFStringObfuscated = make_obfuscated<0xC1>("8B ?? ?? 48 ?? ?? E8 ?? ?? ?? ?? 0F ?? ?? 48 8D ?? ?? ?? ?? ?? 48 C1");
constexpr auto CAStringObfuscated = make_obfuscated<0x39>("7F ?? 44 89 ?? ?? ?? ?? ?? 43 8B ?? ?? 39 05 ?? ?? ?? ?? 0F 8F");
constexpr auto VignettingStringObfuscated = make_obfuscated<0xEB>("8B ?? 83 ?? ?? 7D ?? 44 89 ?? ?? ?? ?? ?? EB");
constexpr auto FogStringObfuscated = make_obfuscated<0x75>("74 ?? 48 8B ?? ?? ?? ?? ?? 83 ?? ?? ?? 75 ?? 40 ?? ?? EB ?? 40 ?? ?? 48");
constexpr auto WorldTimeDilationStringObfuscated = make_obfuscated<0xF6>("F6 81 ?? ?? ?? ?? ?? 74 ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? C3");
constexpr auto targetPerceptionStringObfuscated = make_obfuscated<0xF6>("48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 41 ?? 41 ?? 48 81 EC ?? ?? ?? ?? 33 FF 48 ?? ?? 48 89 BC");
if (!CameraComponentaddress)
logger->warn("Camera component signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else {
logger->info("Camera component found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(CameraComponentaddress));
FOVaddress = CameraComponentaddress +0xa;
ConstrainAspectRatioaddress = CameraComponentaddress +0x18;
}
}
if (!DOFaddress) {
constexpr auto DOFStringObfuscated = make_obfuscated<0x4A>("8B ?? ?? 48 ?? ?? E8 ?? ?? ?? ?? 0F ?? ?? 48 8D ?? ?? ?? ?? ?? 48 C1");
DOFaddress = Memory::AOBScan("", DOFStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
if (!DOFaddress)
logger->warn("DOF signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else
logger->info("DOF signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(DOFaddress));
}
if (!CAaddress) {
constexpr auto CAStringObfuscated = make_obfuscated<0x4A>("7F ?? 44 89 ?? ?? ?? ?? ?? 43 8B ?? ?? 39 05 ?? ?? ?? ?? 0F 8F");
CAaddress = Memory::AOBScan("", CAStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
if (!CAaddress)
logger->warn("Chromatic aberrations signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else
logger->info("Chromatic aberrations signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(CAaddress));
}
if (!Vignettingaddress) {
constexpr auto CAStringObfuscated = make_obfuscated<0x4A>("8B ?? 83 ?? ?? 7D ?? 44 89 ?? ?? ?? ?? ?? EB");
Vignettingaddress = Memory::AOBScan("", CAStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
if (!Vignettingaddress)
logger->warn("Vignetting signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else
logger->info("Vignetting signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(Vignettingaddress));
}
if (!Fogaddress) {
constexpr auto FogStringObfuscated = make_obfuscated<0x4A>("74 ?? 48 8B ?? ?? ?? ?? ?? 83 ?? ?? ?? 75 ?? 40 ?? ?? EB ?? 40 ?? ?? 48");
Fogaddress = Memory::AOBScan("", FogStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
if (!Fogaddress)
logger->warn("Fog signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else {
logger->info("Fog signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(Fogaddress));
Fogaddress += 0xd;
}
}
using AOBScan::Make;
using OffsetScan::Make;
// Prepare all data for scanning
std::vector<AOBScanEntry> signatures = {
Make(&CameraComponentaddress, FOVStringObfuscated, "FOV"),
Make(&DOFaddress, DOFStringObfuscated, "DOF"),
Make(&CAaddress, CAStringObfuscated, "Chromatic aberrations"),
Make(&Vignettingaddress, VignettingStringObfuscated, "Vignetting"),
Make(&Fogaddress, FogStringObfuscated, "Fog"),
Make(&WorldTimedilationaddress, WorldTimeDilationStringObfuscated, "World time dilation"),
Make(&Stealthaddress, targetPerceptionStringObfuscated, "Stealth"),
};
// Scan all signature in a batch
Memory::AOBScanBatch(signatures, logger);
FOVaddress = CameraComponentaddress + 0xa;
ConstrainAspectRatioaddress = CameraComponentaddress + 0x18;
if (CameraComponentaddress && FOVaddress && DOFaddress && CAaddress && Vignettingaddress &&
Fogaddress && ConstrainAspectRatioaddress) {
Fogaddress && ConstrainAspectRatioaddress && WorldTimedilationaddress && Stealthaddress) {
logger->info("All AOB signatures found. Ready to patch...");
AOBScanDone = true;
}
@@ -133,53 +119,45 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init)
logger->info("------------ UEngine offsets search ------------");
uint8_t* baseModule = reinterpret_cast<uint8_t*>(GetModuleHandleA(nullptr)); // Get game base address
constexpr auto GObjetcsStringObfuscated = make_obfuscated<0x4A>("48 8B ?? ?? ?? ?? ?? 48 8B ?? ?? 48 8D ?? ?? EB ?? 33");
GObjectsaddress = Memory::AOBScan("", GObjetcsStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
constexpr auto AppendStringStringObfuscated = make_obfuscated<0x4A>("48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 48 83 ?? ?? 80 3D ?? ?? ?? ?? ?? 48 ?? F2 8B ?? 48 ?? ?? 74 ?? 4C 8D ?? ?? ?? ?? ?? EB ?? 48 8D ?? ?? ?? ?? ?? E8 ?? ?? ?? ?? 4C");
AppendStringaddress = Memory::AOBScan("", AppendStringStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
constexpr auto ProcessEventStringObfuscated = make_obfuscated<0x4A>("40 ?? 56 57 41 ?? 41 ?? 41 ?? 41 ?? 48 81 ?? ?? ?? ?? ?? 48 8D ?? ?? ?? 48 89 ?? ?? ?? ?? ?? 48 8B ?? ?? ?? ?? ?? 48 ?? ?? 48 89 ?? ?? ?? ?? ?? 8B 41");
ProcessEventaddress = Memory::AOBScan("", ProcessEventStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
constexpr auto GObjetcsStringObfuscated = make_obfuscated<0x8D>("48 8B ?? ?? ?? ?? ?? 48 8B ?? ?? 48 8D ?? ?? EB ?? 33");
constexpr auto GWorldStringObfuscated = make_obfuscated<0x83>("48 8B 05 ?? ?? ?? ?? 48 ?? ?? 75 ?? 48 83 ?? ?? 5B");
constexpr auto AppendStringStringObfuscated = make_obfuscated<0x80>("48 89 ?? ?? ?? 48 89 ?? ?? ?? 57 48 83 ?? ?? 80 3D ?? ?? ?? ?? ?? 48 ?? F2 8B ?? 48 ?? ?? 74 ?? 4C 8D ?? ?? ?? ?? ?? EB ?? 48 8D ?? ?? ?? ?? ?? E8 ?? ?? ?? ?? 4C");
constexpr auto ProcessEventStringObfuscated = make_obfuscated<0x56>("40 ?? 56 57 41 ?? 41 ?? 41 ?? 41 ?? 48 81 ?? ?? ?? ?? ?? 48 8D ?? ?? ?? 48 89 ?? ?? ?? ?? ?? 48 8B ?? ?? ?? ?? ?? 48 ?? ?? 48 89 ?? ?? ?? ?? ?? 8B 41");
if (!GObjectsaddress)
logger->warn("GObjects signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else {
uint32_t gObjectsOffset = static_cast<uint32_t>(Memory::GetOffsetFromOpcode(GObjectsaddress + 0x3) - baseModule);
logger->info("GObjects offset is: 0x{:X}.", gObjectsOffset);
Offsets::GObjects = static_cast<UC::uint32>(gObjectsOffset); // Update GObjects offset
}
if (!AppendStringaddress)
logger->warn("AppendString signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else {
std::optional<uint32_t> gAppendStringOffsetOpt = UE::CalculateOffset("", AppendStringaddress);
uint32_t gAppendStringOffset = *gAppendStringOffsetOpt;
logger->info("AppendString offset is: 0x{:X}.", gAppendStringOffset);
Offsets::AppendString = static_cast<UC::uint32>(gAppendStringOffset);// Update AppendString
}
if (!ProcessEventaddress)
logger->warn("Process Event signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
else {
std::optional<uint32_t> gProcessEventOffsetOpt = UE::CalculateOffset("", ProcessEventaddress);
uint32_t gProcessEventOffset = *gProcessEventOffsetOpt;
logger->info("Process Event offset is: 0x{:X}.", gProcessEventOffset);
Offsets::ProcessEvent = static_cast<UC::uint32>(gProcessEventOffset);// Update ProcessEvent offset
}
// Prepare all data for scanning
std::vector<OffsetScanEntry> UEoffsetsScans = {
Make(&GObjectsaddress, GObjetcsStringObfuscated, "GObjects", OffsetCalcType::GetOffsetFromOpcode, &Offsets::GObjects, 0x3),
Make(&GWorldaddress, GWorldStringObfuscated, "GWorld", OffsetCalcType::GetOffsetFromOpcode, &Offsets::GWorld, 0x3),
Make(&AppendStringaddress, AppendStringStringObfuscated, "AppendString", OffsetCalcType::UE_CalculateOffset, &Offsets::AppendString),
Make(&ProcessEventaddress, ProcessEventStringObfuscated, "ProcessEvent", OffsetCalcType::UE_CalculateOffset, &Offsets::ProcessEvent)
};
// Retrieve all Unreal Engine offsets in a batch
Memory::OffsetScanBatch(UEoffsetsScans, baseModule, logger, "");
}
logger->info("-------------- Fixes initialisation -------------");
AOBScanDone = true;
}
if (!init && FOVaddress) FOVFixEnabled();
if (!init && ConstrainAspectRatioaddress) UltraWideFixEnabled();
if (!init) {
HUDFixEnabled();
LogHUD();
}
if (!init && DOFaddress) DOFFixEnabled();
if (!init && CAaddress) CAFixEnabled();
if (!init && Vignettingaddress) VignettingFixEnabled();
if (!init && Fogaddress) FogFixEnabled();
if (!init && WorldTimedilationaddress) {
EnableCheats(Cheat::TimeDilation);
EnableCheats(Cheat::GodMode);
EnableCheats(Cheat::Stealth);
}
ProcessEvent();
}
// Setters for Reshade addon call
extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enabled)
{ // Set each fix individually
extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enabled) { // Set each fix individually
if (fix == GameFixes::DevConsole) { g_Console = enabled; EnableConsole(); }
if (fix == GameFixes::FOV) { g_fov_fix_enabled = enabled; FOVFixEnabled(); }
if (fix == GameFixes::UltraWide) { g_ultrawide_fix_enabled = enabled; UltraWideFixEnabled(); }
@@ -187,27 +165,134 @@ extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enable
if (fix == GameFixes::ChromaticAberrations) { g_CA_fix_enabled = enabled; CAFixEnabled(); }
if (fix == GameFixes::Vignetting) { g_Vignetting_fix_enabled = enabled; VignettingFixEnabled(); }
if (fix == GameFixes::Fog) { g_Fog_fix_enabled = enabled; FogFixEnabled(); }
if (fix == GameFixes::HUD) { g_HUD_fix_enabled = enabled; HUDFixEnabled(); LogHUD(); }
if (fix == GameFixes::TimeDilation) { g_TimeDilation_fix_enabled = enabled; EnableCheats(Cheat::TimeDilation); }
if (fix == GameFixes::GodMode) { g_GodMode_fix_enabled = enabled; EnableCheats(Cheat::GodMode); }
if (fix == GameFixes::Stealth) { g_Stealth_fix_enabled = enabled; EnableCheats(Cheat::Stealth); }
}
extern "C" __declspec(dllexport) void SetFOV(int fov)
{
g_AdditionalFOVValue = fov;
extern "C" __declspec(dllexport) void SetValues(GameSetting setting, float value) {
if (setting == GameSetting::FOV) g_AdditionalFOVValue = (int)(value);
if (setting == GameSetting::HUD) {
g_HUDOffsets = ((int)value * screenWidth) / 100;
HUDFixEnabled();
}
if (setting == GameSetting::WorldTimeDilation) g_WorldTimeDilationValue = value;
if (setting == GameSetting::AITimeDilation) g_AITimeDilationValue = value;
}
// Getters for Reshade addon call
extern "C" __declspec(dllexport) void GetGameInfos(GameInfos* infos) {
if (!infos) return;
infos->FOVIn = g_FOV_In;
infos->FOVOut = g_FOV_Out;
infos->Health = g_PlayerHealth;
infos->consoleEnabled = g_Console_Enabled;
}
static UWBP_InGameHUDLayout_C* HUDLayout = nullptr;
static bool g_GameReady = false;
// Code injection functions
static void ProcessEvent() {
if (!PEHook && ProcessEventaddress) {
PEHook = safetyhook::create_mid(ProcessEventaddress + 0xc,
[](SafetyHookContext& ctx) {
UObject* object = (UObject*)ctx.rcx;
UFunction* func = (UFunction*)ctx.rdx;
if (object && func) {
std::string funcName = func->GetName();
std::string objectName = object->GetName();
if (!objectName.contains("WBP_InGameHUDLayout_C")) return;
UWBP_InGameHUDLayout_C* hudWidget = static_cast<UWBP_InGameHUDLayout_C*>(object);
if (!hudWidget) return;
ULocalPlayer* lp = nullptr;
UGameViewportClient* viewport = lp->ViewportClient;
if (funcName == "Construct") {
HUDLayout = hudWidget;
g_GameReady = true;
HUDFixEnabled(); // Enable live HUD scaling
}
if (funcName == "Destruct") {
g_GameReady = false;
HUDLayout = nullptr;
}
}
});
}
}
// HUD positionning
FMargin initialCurrency = {};
FMargin initialSubtitles = {};
FMargin initialPlayerHealth = {};
FMargin initialPlayerInfo = {};
FMargin initialObjectives = {};
FMargin initialGameActionBar = {};
FMargin initialHints = {};
static bool g_offsetsInitialized = false;
static void HUDFixEnabled() {
if (!HUDLayout) return;
auto ApplyOrGetOffset = [](UUIExtensionPointWidget* widget, float left = 0, float right = 0) -> FMargin {
if (!widget || !widget->Slot) return FMargin();
// Browse up to CanvasPanelSlot
UWidget* current = widget;
while (current) {
if (current->Slot && current->Slot->IsA(UCanvasPanelSlot::StaticClass())) {
UCanvasPanelSlot* slot = static_cast<UCanvasPanelSlot*>(current->Slot);
FMargin offsets = slot->GetOffsets();
if (left != 0) offsets.Left = left;
if (right != 0) offsets.Right = right;
if (g_offsetsInitialized) slot->SetOffsets(offsets);
return offsets;
}
if (!current->Slot) return FMargin();
current = current->Slot->Parent;
}
return FMargin();
};
// Get initial offsets
if (!g_offsetsInitialized) {
initialCurrency = ApplyOrGetOffset(HUDLayout->Currency);
initialSubtitles = ApplyOrGetOffset(HUDLayout->Subtitles);
initialPlayerHealth = ApplyOrGetOffset(HUDLayout->PlayerHealth);
initialPlayerInfo = ApplyOrGetOffset(HUDLayout->PlayerInfo);
initialObjectives = ApplyOrGetOffset(HUDLayout->Objectives);
initialGameActionBar = ApplyOrGetOffset(HUDLayout->GameActionBar);
initialHints = ApplyOrGetOffset(HUDLayout->Hints);
g_offsetsInitialized = true;
}
if (g_HUD_fix_enabled) { // Set new HUD position
ApplyOrGetOffset(HUDLayout->Currency, -g_HUDOffsets);
ApplyOrGetOffset(HUDLayout->Subtitles, 0.f, g_HUDOffsets); // Fix subtitles offsets
ApplyOrGetOffset(HUDLayout->PlayerHealth, g_HUDOffsets + initialPlayerHealth.Left - initialPlayerInfo.Left);
ApplyOrGetOffset(HUDLayout->PlayerInfo, g_HUDOffsets);
ApplyOrGetOffset(HUDLayout->Objectives, g_HUDOffsets);
ApplyOrGetOffset(HUDLayout->GameActionBar, g_HUDOffsets);
ApplyOrGetOffset(HUDLayout->Hints, g_HUDOffsets);
}
else { // Restore HUD position
ApplyOrGetOffset(HUDLayout->Currency, initialCurrency.Left);
ApplyOrGetOffset(HUDLayout->Subtitles, initialSubtitles.Left, initialSubtitles.Right);
ApplyOrGetOffset(HUDLayout->PlayerHealth, initialPlayerHealth.Left);
ApplyOrGetOffset(HUDLayout->PlayerInfo, initialPlayerInfo.Left);
ApplyOrGetOffset(HUDLayout->Objectives, initialObjectives.Left);
ApplyOrGetOffset(HUDLayout->GameActionBar, initialGameActionBar.Left);
ApplyOrGetOffset(HUDLayout->Hints, initialHints.Left);
}
}
static void LogHUD() { // Log toggle state
if (g_HUD_fix_enabled) logger->info("HUD fix enabled");
else logger->info("HUD fix disabled");
}
static void FOVFixEnabled() {
if (g_fix_enabled && g_fov_fix_enabled && FOVaddress) {
if (g_fix_enabled && g_fov_fix_enabled && CameraComponentaddress) {
if (!FOVHook) { // Hook only once
FOVHook = safetyhook::create_mid(FOVaddress,
FOVHook = safetyhook::create_mid(CameraComponentaddress + 0xa,
[](SafetyHookContext& ctx) {
g_FOV_In = ctx.xmm0.f32[0];
ctx.xmm0.f32[0] += (g_fix_enabled && g_fov_fix_enabled ? g_AdditionalFOVValue : g_FOV_In);
@@ -217,12 +302,82 @@ static void FOVFixEnabled() {
else FOVHook.enable();
logger->info("FOV fix enabled");
}
if (!(g_fix_enabled && g_fov_fix_enabled) && FOVaddress) {
if (!(g_fix_enabled && g_fov_fix_enabled) && CameraComponentaddress) {
if (FOVHook) FOVHook.disable();
logger->info("FOV fix disabled");
}
}
// Cheats
static UWorld* LastWorld = nullptr;
static ULONGLONG lastScanTick = 0; // Last time Actors were scanned for enemies time dilation
static void EnableCheats(Cheat cheat) {
if (WorldTimedilationaddress && !WorldTimeDilationHook) {
WorldTimeDilationHook = safetyhook::create_mid(WorldTimedilationaddress + 0x19,
[](SafetyHookContext& ctx) {
if (!g_GameReady) return;
// From AWorldSettings retrieved from world->K2_GetWorldSettings()
ctx.xmm0.f32[0] *= g_TimeDilation_fix_enabled ? g_WorldTimeDilationValue : 1.f;
UWorld* world = UWorld::GetWorld();
if (!world || !world->OwningGameInstance) return;
if (world != LastWorld) {
LastWorld = world;
}
APawn* playerPawn = GetPawnFromWorld(world);
ULONGLONG now = GetTickCount64();
if (now - lastScanTick < DEFAULT_ACTORS_SCAN_BETWEEN_TICKS) return;
lastScanTick = now;
if (!playerPawn || world->Levels.Num() == 0) return;
AGG_PlayerCharacter* player = static_cast<AGG_PlayerCharacter*>(playerPawn);
if (player && player->Class && player->WeaponSpongeBob && player->WeaponPatrick) {
auto* asc = player->AbilitySystemComponent;
if (!asc) return;
UPL_HealthAttributeSet* healthSet = (UPL_HealthAttributeSet*)asc->GetAttributeSet(UPL_HealthAttributeSet::StaticClass());
if (!healthSet) return;
g_PlayerHealth = healthSet->Health.CurrentValue; // For UI information
if (g_GodMode_fix_enabled) { // Set health to current max health
healthSet->Health.CurrentValue = healthSet->MaxHealth.BaseValue;
healthSet->Health.BaseValue = healthSet->MaxHealth.BaseValue;
}
}
// Enemies time dilation
for (int i = 0; i < world->Levels.Num(); i++) { // Loop through level to find actors
ULevel* Level = world->Levels[i];
if (!Level) continue;
for (int j = 0; j < Level->Actors.Num(); j++) { // Loop through actors
AActor* actor = Level->Actors[j];
if (!actor || !playerPawn || actor == playerPawn) continue; // We don't want to affect player
if (!actor->IsA(AGG_Enemy::StaticClass())) continue; // actor is enemy
AGG_Enemy* enemy = static_cast<AGG_Enemy*>(actor);
if (!enemy) continue;
enemy->CustomTimeDilation = g_TimeDilation_fix_enabled ? g_AITimeDilationValue : 1.f; // Enemy time dilation
}
}
});
}
if (Stealthaddress && !StealthHook) { // Hook AGG_NpcCharacter -> OnTargetPerceptionUpdated
StealthHook = safetyhook::create_mid(Stealthaddress,
[](SafetyHookContext& ctx) {
if (!g_Stealth_fix_enabled || !ctx.rcx) return;
AGG_Enemy* npc = (AGG_Enemy*)ctx.rcx;
if (!npc) return;
AGG_EnemyController* controller = static_cast<AGG_EnemyController*>(npc->Controller);
if (controller && controller->Class && controller->PerceptionComponent)
controller->PerceptionComponent->ForgetAll();
});
}
if (cheat == Cheat::TimeDilation) logger->info("Time dilation cheat {}", g_TimeDilation_fix_enabled ? "enabled" : "disabled");
if (cheat == Cheat::GodMode) logger->info("God mode cheat {}", g_GodMode_fix_enabled ? "enabled" : "disabled");
if (cheat == Cheat::Stealth) logger->info("Stealth cheat {}", g_Stealth_fix_enabled ? "enabled" : "disabled");
}
// Memory patch fixes
static void UltraWideFixEnabled() {
if (g_fix_enabled && g_ultrawide_fix_enabled && ConstrainAspectRatioaddress) {
@@ -270,100 +425,34 @@ static void VignettingFixEnabled() {
static void FogFixEnabled() {
if (g_fix_enabled && g_Fog_fix_enabled && Fogaddress) {
Memory::PatchBytes(Fogaddress, "\xEB", 1); // jmp r.Fog 0
Memory::PatchBytes(Fogaddress + 0xd, "\xEB", 1); // jmp -> r.Fog 0
logger->info("Fog fix enabled");
}
if (!(g_fix_enabled && g_Fog_fix_enabled) && Fogaddress) {
Memory::RestoreBytes(Fogaddress);
Memory::RestoreBytes(Fogaddress + 0xd);
logger->info("Fog fix disabled");
}
}
// UE Console creation
static void EnableConsole()
{
if (!g_Console) {
logger->info("------------------ User inputs ------------------");
static void EnableConsole() {
if (g_Console_Enabled || !g_Console || !GObjectsaddress || !AppendStringaddress || !ProcessEventaddress) {
if (!g_Console && !user_inputs_logged) {
logger->info("------------------ User inputs ------------------");
user_inputs_logged = true;
}
return;
}
logger->info("-------------- Console re-enabling --------------");
if (!GObjectsaddress || !AppendStringaddress || !ProcessEventaddress) {
logger->warn("Could not re-enable console");
logger->info("------------------ User inputs ------------------");
return;
}
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;
// Set the all the console shortkey to F2
for (int i = 0; i < UInputSettings::GetDefaultObj()->ConsoleKeys.Num(); i++)
{
UInputSettings::GetDefaultObj()->ConsoleKeys[i].KeyName = UKismetStringLibrary::Conv_StringToName(L"F2");
}
logger->info("Console fully reactivated in {:.3f}s and bound to key F2", elapsed.count());
g_Console_Enabled = true;
}
else
logger->error("Could not spawn console object");
logger->info("------------------ User inputs ------------------");
}).detach();
ReactivateDevConsole(logger);
}
static void InitializeLogger()
{
try
{
std::filesystem::path log_path = std::filesystem::absolute(PLUGIN_LOG);
if (std::filesystem::exists(log_path))
std::filesystem::remove(log_path);
logger = std::make_shared<spdlog::logger>("SpongeBob SquarePants: TOTT", std::make_shared<spdlog::sinks::rotating_file_sink_st>(PLUGIN_LOG, 10 * 1024 * 1024, 1));
logger->set_level(spdlog::level::debug);
logger->flush_on(spdlog::level::debug); // Flush automatically
}
catch (const spdlog::spdlog_ex& ex)
{
std::string plugin_error_message = "Could not open " + PLUGIN_LOG;
MessageBoxA(nullptr, plugin_error_message.c_str(), "Logger Error", MB_ICONERROR | MB_OK);
}
}
// Standard dll entry
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID)
{
if (reason == DLL_PROCESS_ATTACH)
{
InitializeLogger();
BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID) {
if (reason == DLL_PROCESS_ATTACH) {
logger = InitializeLogger("SpongeBob SquarePants: TOTT", PLUGIN_LOG);
logger->info("Plugin {} loaded.", PLUGIN_NAME);
}
else if (reason == DLL_PROCESS_DETACH)
{
else if (reason == DLL_PROCESS_DETACH) {
logger->info("Plugin {} unloaded.", PLUGIN_NAME);
spdlog::drop_all();
}