472 lines
23 KiB
C++
472 lines
23 KiB
C++
#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_HUDHide_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;
|
|
|
|
// AOB Scan pointers
|
|
static uint8_t* FOVaddress = nullptr;
|
|
static uint8_t* Cameraaddress = nullptr;
|
|
static uint8_t* DOFaddress = nullptr;
|
|
static uint8_t* CAaddress = nullptr;
|
|
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(GameFixes fix);
|
|
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) {
|
|
g_fix_enabled = enabled;
|
|
if (!AOBScanDone) { // Unreal Engine 5.6
|
|
logger->info("--------------- AOB scan started ---------------");
|
|
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");
|
|
|
|
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 && WorldTimedilationaddress && Stealthaddress) {
|
|
logger->info("All AOB signatures found. Ready to patch...");
|
|
AOBScanDone = true;
|
|
}
|
|
|
|
if (!GObjectsaddress || !AppendStringaddress || !ProcessEventaddress) {
|
|
logger->info("------------ UEngine offsets search ------------");
|
|
uint8_t* baseModule = reinterpret_cast<uint8_t*>(GetModuleHandleA(nullptr)); // Get game base address
|
|
|
|
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");
|
|
|
|
// 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(GameFixes::HUD);
|
|
LogHUD(GameFixes::HUDHide);
|
|
}
|
|
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
|
|
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(); }
|
|
if (fix == GameFixes::DOF) { g_DOF_fix_enabled = enabled; DOFFixEnabled(); }
|
|
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(GameFixes::HUD); }
|
|
if (fix == GameFixes::HUDHide) { g_HUDHide_fix_enabled = enabled; HUDFixEnabled(); LogHUD(GameFixes::HUDHide); }
|
|
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 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 (object->Class->GetName().contains("UPL_LocationAlongArm")) {
|
|
logger->debug("{} {}", object->Class->GetName(), funcName);
|
|
}
|
|
if (!objectName.contains("WBP_InGameHUDLayout_C")) return;
|
|
UWBP_InGameHUDLayout_C* hudWidget = static_cast<UWBP_InGameHUDLayout_C*>(object);
|
|
if (!hudWidget) return;
|
|
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;
|
|
// Hide or show HUD
|
|
HUDLayout->Currency->SetVisibility(g_HUDHide_fix_enabled ? ESlateVisibility::Collapsed : ESlateVisibility::Visible);
|
|
HUDLayout->PlayerHealth->SetVisibility(g_HUDHide_fix_enabled ? ESlateVisibility::Collapsed : ESlateVisibility::Visible);
|
|
HUDLayout->PlayerInfo->SetVisibility(g_HUDHide_fix_enabled ? ESlateVisibility::Collapsed : ESlateVisibility::Visible);
|
|
HUDLayout->Objectives->SetVisibility(g_HUDHide_fix_enabled ? ESlateVisibility::Collapsed : ESlateVisibility::Visible);
|
|
HUDLayout->GameActionBar->SetVisibility(g_HUDHide_fix_enabled ? ESlateVisibility::Collapsed : ESlateVisibility::Visible);
|
|
HUDLayout->Hints->SetVisibility(g_HUDHide_fix_enabled ? ESlateVisibility::Collapsed : ESlateVisibility::Visible);
|
|
HUDLayout->BossHealthBar->SetVisibility(g_HUDHide_fix_enabled ? ESlateVisibility::Collapsed : ESlateVisibility::Visible);
|
|
if (g_HUDHide_fix_enabled) 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, initialGameActionBar.Left - 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(GameFixes fix) { // Log toggle state
|
|
if (fix == GameFixes::HUD) logger->info("HUD fix {}", g_HUD_fix_enabled ? "enabled" : "disabled");
|
|
if (fix == GameFixes::HUDHide) logger->info("HUD hide fix {}", g_HUDHide_fix_enabled ? "enabled" : "disabled");
|
|
}
|
|
|
|
static void FOVFixEnabled() {
|
|
if (g_fix_enabled && g_fov_fix_enabled && CameraComponentaddress) {
|
|
if (!FOVHook) { // Hook only once
|
|
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);
|
|
g_FOV_Out = ctx.xmm0.f32[0];
|
|
});
|
|
}
|
|
else FOVHook.enable();
|
|
logger->info("FOV fix enabled");
|
|
}
|
|
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) {
|
|
Memory::PatchBytes(ConstrainAspectRatioaddress, "\x31\xC9\x90\x90\x90\x90\x90", 7); // bConstrainAspectRatio = 0
|
|
logger->info("Ultra wide fix enabled");
|
|
}
|
|
if (!(g_fix_enabled && g_ultrawide_fix_enabled) && ConstrainAspectRatioaddress) {
|
|
Memory::RestoreBytes(ConstrainAspectRatioaddress);
|
|
logger->info("Ultra wide fix disabled");
|
|
}
|
|
}
|
|
|
|
static void DOFFixEnabled() {
|
|
if (g_fix_enabled && g_DOF_fix_enabled && DOFaddress) {
|
|
Memory::PatchBytes(DOFaddress, "\x31\xFF\x90", 3); // xor edi,edi r.DepthOfFieldQuality = 0
|
|
logger->info("Depth of field fix enabled");
|
|
}
|
|
if (!(g_fix_enabled && g_DOF_fix_enabled) && DOFaddress) {
|
|
Memory::RestoreBytes(DOFaddress);
|
|
logger->info("Depth of field fix disabled");
|
|
}
|
|
}
|
|
|
|
static void CAFixEnabled() {
|
|
if (g_fix_enabled && g_CA_fix_enabled && CAaddress) {
|
|
Memory::PatchBytes(CAaddress, "\x90\x90", 2); // NOP x 2 r.SceneColorFringeQuality = 0
|
|
logger->info("Chromatics aberrations fix enabled");
|
|
}
|
|
if (!(g_fix_enabled && g_CA_fix_enabled) && CAaddress) {
|
|
Memory::RestoreBytes(CAaddress);
|
|
logger->info("Chromatics aberrations fix disabled");
|
|
}
|
|
}
|
|
|
|
static void VignettingFixEnabled() {
|
|
if (g_fix_enabled && g_Vignetting_fix_enabled && Vignettingaddress) {
|
|
Memory::PatchBytes(Vignettingaddress, "\x31\xC9", 2); // xor ecx,ecx r.Tonemapper.Quality=0
|
|
logger->info("Vignetting fix enabled");
|
|
}
|
|
if (!(g_fix_enabled && g_Vignetting_fix_enabled) && Vignettingaddress) {
|
|
Memory::RestoreBytes(Vignettingaddress);
|
|
logger->info("Vignetting fix disabled");
|
|
}
|
|
}
|
|
|
|
static void FogFixEnabled() {
|
|
if (g_fix_enabled && g_Fog_fix_enabled && Fogaddress) {
|
|
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 + 0xd);
|
|
logger->info("Fog fix disabled");
|
|
}
|
|
}
|
|
// UE Console creation
|
|
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 --------------");
|
|
ReactivateDevConsole(logger);
|
|
}
|
|
// Standard dll entry
|
|
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) {
|
|
logger->info("Plugin {} unloaded.", PLUGIN_NAME);
|
|
spdlog::drop_all();
|
|
}
|
|
return TRUE;
|
|
} |