Files
ReshadePluginsCore/StyxBladesOfGreed/dllmain.cpp

506 lines
27 KiB
C++

#include "CommonHeaders.h"
#include "CommonUEHeaders.h"
#include "SDK/UI_Settings_classes.hpp"
#include "SDK/UI_Profile_classes.hpp"
#include "SDK/UI_MainMenu_classes.hpp"
#include "SDK/UI_Difficulty_classes.hpp"
#include "SDK/UI_InGameMenu_classes.hpp"
#include "SDK/UI_PauseMenu_classes.hpp"
#include "SDK/UI_Saves_classes.hpp"
#include "SDK/UI_Upgrades_classes.hpp"
#include "SDK/Styx3_classes.hpp"
using namespace SDK;
// Constants
const std::string PLUGIN_NAME = "Styx";
const std::string PLUGIN_LOG = PLUGIN_NAME + ".log";
constexpr ULONGLONG DEFAULT_DELAY_BETWEEN_TICK = 500; // 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);
float g_AspectRatio = (float)screenWidth / screenHeight;
float g_BaseAspectRatio = 2.39f;
// Plugin states
static bool AOBScanDone = false;
static bool g_Console = false;
static std::atomic<bool> g_fix_enabled = false;
static std::atomic<bool> g_fov_fix_enabled = false;
static std::atomic<bool> g_ultrawide_fix_enabled = false;
static std::atomic<bool> g_HUD_fix_enabled = false;
static std::atomic<bool> g_Camera_fix_enabled = false;
static std::atomic<bool> g_DOF_fix_enabled = false;
static std::atomic<bool> g_CA_fix_enabled = false;
static std::atomic<bool> g_Vignetting_fix_enabled = false;
static std::atomic<bool> g_Fog_fix_enabled = false;
static std::atomic<bool> g_TimeDilation_fix_enabled = false;
static std::atomic<bool> g_GodMode_fix_enabled = false;
static std::atomic<bool> g_Amber_fix_enabled = false;
static std::atomic<bool> g_Stealth_fix_enabled = false;
static int g_AdditionalFOVValue = 0;
static float g_CameraMultiplier = 1.f;
static float g_WorldTimeDilationValue = 1.f;
static float g_AITimeDilationValue = 1.f;
static int g_HUDOffsets = 0;
static int g_UIOffsets = 0;
static float g_PlayerHealth = 0.f;
static float g_PlayerAmber = 0.f;
static bool user_inputs_logged = false;
// Shared values
static float g_FOV_In = 60.f;
static float g_CompensatedFOV = 60.f;
static float g_FOV_Out = 60.f;
static float g_CameraIn = 200.f;
static float g_CameraOut = 200.f;
// AOB Scan pointers
static uint8_t* CameraComponentaddress = nullptr;
static uint8_t* CameraDistanceaddress = nullptr;
static uint8_t* WorldTimedilationaddress = nullptr;
static uint8_t* Timedilationaddress = nullptr;
// Hooking
static SafetyHookMid FOVHook{};
static SafetyHookMid CameraHook{};
static SafetyHookMid UltraWideHook1{};
static SafetyHookMid UltraWideHook2{};
static SafetyHookMid PEHook{};
static SafetyHookMid WorldTimeDilationHook{};
static SafetyHookMid TimeDilationHook{};
// Prototypes
static void FOVFixEnabled();
static void UltraWideFixEnabled();
static void CameraDistanceFixEnabled();
static void HUDUpdate(bool writeLog);
static void EnableConsole();
static void EnableCheats(Cheat cheat);
static void ProcessEvent();
// UEngine variable
static UUserWidget* g_UIMainMenuWidget = nullptr;
static UUserWidget* g_UISettingsWidget = nullptr;
static UUserWidget* g_DifficultyWidget = nullptr;
static UUserWidget* g_ProfileWidget = nullptr;
static UUserWidget* g_InGameMenuWidget = nullptr;
static UUserWidget* g_PauseWidget = nullptr;
static UUserWidget* g_SavesWidget = nullptr;
static UUserWidget* g_MapWidget = nullptr;
static UUserWidget* g_GameOverWidget = nullptr;
static UUserWidget* g_LoadingWidget = nullptr;
static UUserWidget* g_UpgradeWidget = nullptr;
static UWidget* g_StatusWidget = nullptr;
static UWidget* g_GaugesWidget = nullptr;
static UWidget* g_ChangeWheelWidget = nullptr;
static UWidget* g_AbilityWheelWidget = nullptr;
static UUserWidget* g_CraftingWidget = nullptr;
static UWidget* g_QuestWidget = nullptr;
static UWidget* g_LootWidget = nullptr;
static AStyx3PlayerCharacter* g_Player = nullptr;
extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
g_fix_enabled = enabled;
if (init) {
logger = InitializeLogger("Styx: Blades Of Green", PLUGIN_LOG);
logger->info("Plugin {} loaded.", PLUGIN_NAME);
}
if (!AOBScanDone) { // Unreal Engine 5.6
logger->info("--------------- AOB scan started ---------------");
constexpr auto CameraComponentStringObfuscated = make_obfuscated<0xF3>("EB ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 8B 83 ?? ?? ?? ?? 89");
constexpr auto CameraDistanceStringObfuscated = make_obfuscated<0x66>("0F ?? ?? F3 0F ?? ?? 0F ?? ?? 0F 11 ?? ?? ?? 0F 10 ?? ?? ?? 66 0F ?? ?? F2 0F");
constexpr auto WorldTimeDilationStringObfuscated = make_obfuscated<0xF6>("F6 81 ?? ?? ?? ?? ?? 74 ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? ?? ?? ?? C3");
constexpr auto TimeDilationStringObfuscated = make_obfuscated<0x44>("F3 0F ?? ?? ?? EB ?? F3 0F ?? ?? ?? ?? ?? ?? 48 8B ?? ?? 4C ?? ?? F3 0F ?? ?? 44");
using AOBScan::Make;
using OffsetScan::Make;
// Prepare all data for scanning
std::vector<AOBScanEntry> signatures = {
Make(&CameraComponentaddress, CameraComponentStringObfuscated, "FOV"),
Make(&CameraDistanceaddress, CameraDistanceStringObfuscated, "Camera distance"),
Make(&WorldTimedilationaddress, WorldTimeDilationStringObfuscated, "World time dilation"),
Make(&Timedilationaddress, TimeDilationStringObfuscated, "Actor time dilation"),
};
// Scan all signature in a batch
Memory::AOBScanBatch(signatures, logger);
if (CameraComponentaddress && CameraDistanceaddress && WorldTimedilationaddress && Timedilationaddress)
logger->info("All AOB signatures found. Ready to patch...");
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<0x5B>("48 89 1D ?? ?? ?? ?? 48 8D 05 ?? ?? ?? ?? 48 83 ?? ?? 5B C3");
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;
}
ProcessEvent();
if (init) return;
FOVFixEnabled();
UltraWideFixEnabled();
CameraDistanceFixEnabled();
HUDUpdate(true);
gPendingDOF = true;
gPendingCA = true;
gPendingVignetting = true;
gPendingFog = true;
LogFixToggle(GameFixes::None, g_fix_enabled);
}
// Setters for Reshade addon call
extern "C" __declspec(dllexport) void SetFixesEnabled(GameFixes fix, bool enabled) { // Set each fix individually
bool bVisual = g_fix_enabled && enabled;
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::Camera) { g_Camera_fix_enabled = enabled; CameraDistanceFixEnabled(); }
if (fix == GameFixes::DOF) { g_DOF_fix_enabled = enabled; gPendingDOF = true; LogFixToggle(fix, bVisual); }
if (fix == GameFixes::ChromaticAberrations) { g_CA_fix_enabled = enabled; gPendingCA = true; LogFixToggle(fix, bVisual); }
if (fix == GameFixes::Vignetting) { g_Vignetting_fix_enabled = enabled; gPendingVignetting = true; LogFixToggle(fix, bVisual); }
if (fix == GameFixes::Fog) { g_Fog_fix_enabled = enabled; gPendingFog = true; LogFixToggle(fix, bVisual); }
if (fix == GameFixes::HUD) { g_HUD_fix_enabled = enabled; HUDUpdate(true); }
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::Mana) { g_Amber_fix_enabled = enabled; EnableCheats(Cheat::Mana); }
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::CameraDistance) g_CameraMultiplier = value;
if (setting == GameSetting::HUD) {
g_HUDOffsets = ((int)value * screenWidth) / 100;
HUDUpdate(false);
}
if (setting == GameSetting::UI) {
g_UIOffsets = ((int)value * screenWidth) / 100;
HUDUpdate(false);
}
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->cameraIn = g_CameraIn;
infos->cameraOut = g_CameraOut;
infos->CompensatedFOV = g_CompensatedFOV;
infos->Health = g_PlayerHealth;
infos->Mana = g_PlayerAmber;
infos->screenWidth = screenWidth;
infos->screenHeight = screenHeight;
infos->aspectRatio = (float)screenWidth / screenHeight;
infos->consoleEnabled = g_Console_Enabled;
}
// -- Code injection functions --
static ULONGLONG lastScanTick = 0; // Last time tick was called
static void ProcessEvent() {
if (!PEHook && ProcessEventaddress) {
PEHook = safetyhook::create_mid(ProcessEventaddress + 0xc,
[](SafetyHookContext& ctx) {
ULONGLONG now = GetTickCount64();
if (now - lastScanTick >= DEFAULT_DELAY_BETWEEN_TICK) { // Delay between each tick to avoid ProcessEvent stuttering
lastScanTick = now;
GetResolution(screenWidth, screenHeight, g_AspectRatio);
}
UObject* object = (UObject*)ctx.rcx;
UFunction* func = (UFunction*)ctx.rdx;
if (!object || !func) return;
std::string funcName = func->GetName();
// Full stealth fix: disable AI perception.
if (object->IsA(AStyx3AIController::StaticClass()) && funcName == "OnPerceptionIntensityUpdated") {
auto* AIController = static_cast<AStyx3AIController*>(object);
if (g_Player && AIController->PerceptionGaugeComponent) {
if (g_Stealth_fix_enabled) {
AIController->PerceptionGaugeComponent->ResetGauges(g_Player);
if (g_Player) g_Player->bIsPerceptible = false;
}
else {
AIController->PerceptionGaugeComponent->SetActiveBufferDetection(g_Player, true);
if (g_Player) g_Player->bIsPerceptible = true;
}
}
}
if (object->IsA(UUserWidget::StaticClass()) && (funcName == "Construct" || funcName == "Destruct" || funcName == "Tick")) {
std::string objectName = object->GetName();
// UI scaling
auto HandleWidget = [&](auto* typedWidget, auto*& gWidgetPtr) { // Lambda to initialize pointers on Construct and nullify them on Destruct
if (funcName == "Construct") {
gWidgetPtr = typedWidget;
HUDUpdate(false);
}
else if (funcName == "Destruct") gWidgetPtr = nullptr;
};
if (object->IsA(UUI_Settings_C::StaticClass()))
HandleWidget(static_cast<UUI_Settings_C*>(object), g_UISettingsWidget);
else if (object->IsA(UUI_Difficulty_C::StaticClass()))
HandleWidget(static_cast<UUI_Difficulty_C*>(object), g_DifficultyWidget);
else if (object->IsA(UUI_InGameMenu_C::StaticClass()))
HandleWidget(static_cast<UUI_InGameMenu_C*>(object), g_InGameMenuWidget);
else if (object->IsA(UUI_PauseMenu_C::StaticClass()))
HandleWidget(static_cast<UUI_PauseMenu_C*>(object), g_PauseWidget);
else if (object->IsA(UUI_Profile_C::StaticClass()))
HandleWidget(static_cast<UUI_Profile_C*>(object), g_ProfileWidget);
else if (object->IsA(UUI_MainMenu_C::StaticClass()))
HandleWidget(static_cast<UUI_MainMenu_C*>(object), g_UIMainMenuWidget);
else if (object->IsA(UUI_Saves_C::StaticClass()))
HandleWidget(static_cast<UUI_Saves_C*>(object), g_SavesWidget);
else if (object->IsA(UUI_Upgrades_C::StaticClass()))
HandleWidget(static_cast<UUI_Upgrades_C*>(object), g_UpgradeWidget);
else if (objectName.rfind("UI_Map_C", 0) == 0)
HandleWidget(static_cast<UUserWidget*>(object), g_MapWidget);
else if (objectName.rfind("UI_GameOver_C", 0) == 0)
HandleWidget(static_cast<UUserWidget*>(object), g_GameOverWidget);
else if (objectName.rfind("UI_Loading_C", 0) == 0)
HandleWidget(static_cast<UUserWidget*>(object), g_LoadingWidget);
else {
std::function<void(SDK::UWidget*)> FindWidgets;
FindWidgets = [&](SDK::UWidget* Widget) { // Find all HUD important widgets in container
if (!Widget) return;
const std::string widgetName = Widget->GetName();
const std::string className = Widget->Class ? Widget->Class->GetName() : "";
auto match = [&](const std::string& pattern) {
return widgetName.find(pattern) != std::string::npos || className.find(pattern) != std::string::npos;
};
if (!g_StatusWidget && match("StatusWidget")) g_StatusWidget = Widget;
else if (!g_GaugesWidget && match("Gauges")) g_GaugesWidget = Widget;
else if (!g_ChangeWheelWidget && match("ChangeWheel")) g_ChangeWheelWidget = Widget;
else if (!g_AbilityWheelWidget && match("AbilityWheel")) g_AbilityWheelWidget = Widget; // g_QuestWidget
else if (!g_QuestWidget && match("Notifications_Missions")) g_QuestWidget = Widget;
else if (!g_LootWidget && match("Notifications_Loot")) g_LootWidget = Widget;
// Stop early if everything found-
if (g_StatusWidget && g_GaugesWidget && g_ChangeWheelWidget && g_AbilityWheelWidget && g_QuestWidget && g_LootWidget)
return;
// Descend Panel children
if (Widget->IsA(SDK::UPanelWidget::StaticClass())) {
auto* Panel = static_cast<SDK::UPanelWidget*>(Widget);
for (int i = 0; i < Panel->GetChildrenCount(); ++i)
FindWidgets(Panel->GetChildAt(i));
}
// Descend UserWidget root
if (Widget->IsA(SDK::UUserWidget::StaticClass())) {
auto* UW = static_cast<SDK::UUserWidget*>(Widget);
if (UW->WidgetTree && UW->WidgetTree->RootWidget)
FindWidgets(UW->WidgetTree->RootWidget);
}
};
if (objectName.rfind("Crafting", 0) == 0) {
if (funcName == "Construct") {
g_CraftingWidget = static_cast<UUserWidget*>(object);
HUDUpdate(false);
}
else if (funcName == "Destruct") g_CraftingWidget = nullptr;
}
else if (objectName.rfind("HUD_Widget_C", 0) == 0) {
auto* HUDWidget = static_cast<UUserWidget*>(object);
if (funcName == "Construct") {
if (HUDWidget && HUDWidget->Class) {
FindWidgets(HUDWidget->WidgetTree->RootWidget);
HUDUpdate(false);
}
}
else if (funcName == "Destruct") {
g_QuestWidget = nullptr;
g_LootWidget = nullptr;
g_StatusWidget = nullptr;
g_GaugesWidget = nullptr;
g_ChangeWheelWidget = nullptr;
g_AbilityWheelWidget = nullptr;
}
}
}
}
});
}
}
// -- HUD positionning --
static void HUDUpdate(bool writeLog) {
if (writeLog) logger->info("HUD & UI scaling fix {}", g_fix_enabled && g_HUD_fix_enabled ? "enabled" : "disabled");
float UIoffset = (g_fix_enabled && g_HUD_fix_enabled) ? g_UIOffsets : 0.f;
float HUDoffset = (g_fix_enabled && g_HUD_fix_enabled) ? g_HUDOffsets : 0.f;
float compensation = (g_fix_enabled && g_HUD_fix_enabled) ? -0.f : 0.f;
float targetWidth = 1920.f;
float targetHeight = 1080.f;
CenterWidget(g_UIMainMenuWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
CenterWidget(g_UISettingsWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
CenterWidget(g_ProfileWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
CenterWidget(g_DifficultyWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
CenterWidget(g_InGameMenuWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
CenterWidget(g_PauseWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
CenterWidget(g_SavesWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
CenterWidget(g_MapWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
CenterWidget(g_GameOverWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
CenterWidget(g_UpgradeWidget, UIoffset, screenWidth, screenHeight, targetWidth, targetHeight, compensation);
ApplyOffsetsSmart(g_StatusWidget, HUDoffset, 0.f, 1);
ApplyOffsetsSmart(g_GaugesWidget, 0, HUDoffset + 690.f, 1); // Use original left and right offset + for Anchors of type 1, 1, 1, 1
ApplyOffsetsSmart(g_AbilityWheelWidget, 0, HUDoffset + 78.f, 1); // Use original left and right offset + for Anchors of type 1, 1, 1, 1
ApplyOffsetsSmart(g_ChangeWheelWidget, 0, HUDoffset + 24.f, 1); // Use original left and right offset for Anchors of type 1, 1, 1, 1
ApplyPositionOffset(g_CraftingWidget, UIoffset, FVector2D(0.5f, 0.5f)); // for widgets that only display at left (nothing at right)
ApplyTransformOffset(g_LootWidget, HUDoffset);
ApplyTransformOffset(g_QuestWidget, HUDoffset);
}
static void FOVFixEnabled() {
if (!CameraComponentaddress) return;
if (!FOVHook) { // Hook only once
FOVHook = safetyhook::create_mid(CameraComponentaddress + 0xa,
[](SafetyHookContext& ctx) {
g_FOV_In = ctx.xmm0.f32[0];
if (g_fix_enabled && g_ultrawide_fix_enabled)
ctx.xmm0.f32[0] = Maths::CompensateHorizontalFOV(g_FOV_In, g_BaseAspectRatio, g_AspectRatio);
g_CompensatedFOV = ctx.xmm0.f32[0];
ctx.xmm0.f32[0] += g_fix_enabled && g_fov_fix_enabled ? g_AdditionalFOVValue : 0.f;
g_FOV_Out = ctx.xmm0.f32[0];
});
}
logger->info("FOV fix {}", g_fix_enabled && g_fov_fix_enabled ? "enabled" : "disabled");
}
static void UltraWideFixEnabled() {
if (!CameraComponentaddress) return;
if (g_fix_enabled && g_ultrawide_fix_enabled) {
if (!UltraWideHook1) { // Hook only once
UltraWideHook1 = safetyhook::create_mid(CameraComponentaddress + 0x15,
[](SafetyHookContext& ctx) {
g_BaseAspectRatio = std::bit_cast<float>(static_cast<uint32_t>(ctx.rax)); // Retrieve in real time desired aspect ratio
ctx.rax = std::bit_cast<uint32_t>(g_AspectRatio); // Force our aspect ratio
});
}
else UltraWideHook1.enable();
if (!UltraWideHook2) {
UltraWideHook2 = safetyhook::create_mid(CameraComponentaddress + 0x39,
[](SafetyHookContext& ctx) {
ctx.rdx = 0; // bOverrideAspectRatioAxisConstraint = 0
});
}
else UltraWideHook2.enable();
}
else {
if (UltraWideHook1) UltraWideHook1.disable();
if (UltraWideHook2) UltraWideHook2.disable();
}
logger->info("Ultrawide fix {}", g_fix_enabled && g_ultrawide_fix_enabled ? "enabled" : "disabled");
}
static void CameraDistanceFixEnabled() {
if (!CameraDistanceaddress) return;
if (g_fix_enabled && g_Camera_fix_enabled) {
if (!CameraHook) { // Hook only once
CameraHook = safetyhook::create_mid(CameraDistanceaddress,
[](SafetyHookContext& ctx) {
g_CameraIn = -ctx.xmm0.f32[0];
ctx.xmm0.f32[0] *= g_CameraMultiplier;
g_CameraOut = -ctx.xmm0.f32[0];
});
}
else CameraHook.enable();
}
else if (CameraHook) CameraHook.disable();
logger->info("Camera distance fix {}", g_fix_enabled && g_Camera_fix_enabled ? "enabled" : "disabled");
}
// -- Cheats --
static void EnableCheats(Cheat cheat) {
if (WorldTimedilationaddress && !WorldTimeDilationHook) {
WorldTimeDilationHook = safetyhook::create_mid(WorldTimedilationaddress + 0x19,
[](SafetyHookContext& ctx) { // From AWorldSettings retrieved from world->K2_GetWorldSettings()
ctx.xmm0.f32[0] *= g_TimeDilation_fix_enabled ? g_WorldTimeDilationValue : 1.f;
// Apply visual effects only in hook main thread to ensure they will be applied correctly
if (!g_Console_Enabled) return; // It relies on dev console being reactivated
if (gPendingFog.exchange(false))
ApplyVisualEffect(GameFixes::Fog, g_fix_enabled && g_Fog_fix_enabled);
if (gPendingDOF.exchange(false))
ApplyVisualEffect(GameFixes::DOF, g_fix_enabled && g_DOF_fix_enabled);
if (gPendingCA.exchange(false))
ApplyVisualEffect(GameFixes::ChromaticAberrations, g_fix_enabled && g_CA_fix_enabled);
if (gPendingVignetting.exchange(false))
ApplyVisualEffect(GameFixes::Vignetting, g_fix_enabled && g_Vignetting_fix_enabled);
});
}
// Enemies time dilation
if (Timedilationaddress && !TimeDilationHook) {
TimeDilationHook = safetyhook::create_mid(Timedilationaddress,
[](SafetyHookContext& ctx) {
if (!ctx.rbx) return;
UObject* object = (UObject*)ctx.rbx;
if (!object || !object->Class) return;
if (object->IsA(AStyx3PlayerCharacter::StaticClass())) {
g_Player = static_cast<AStyx3PlayerCharacter*>(object);
g_PlayerHealth = g_Player->CurrentHealth;
if (g_GodMode_fix_enabled) {
float percentageHealth = g_Player->GetHealthPercent();
if (percentageHealth > 0.0001f)
g_Player->CurrentHealth = g_Player->CurrentHealth / percentageHealth;
}
g_PlayerAmber = g_Player->CurrentAmber;
if (g_Amber_fix_enabled) g_Player->CurrentAmber = g_Player->MaxAmber;
}
if (object->IsA(AStyx3AICharacter::StaticClass())) {
AStyx3AICharacter* enemy = static_cast<AStyx3AICharacter*>(object);
if (enemy) enemy->CustomTimeDilation = g_TimeDilation_fix_enabled ? g_AITimeDilationValue : 1.f; // Enemy time dilation
}
});
}
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::Mana) logger->info("Amber cheat {}", g_Amber_fix_enabled ? "enabled" : "disabled");
if (cheat == Cheat::Stealth) logger->info("Stealth cheat {}", g_Stealth_fix_enabled ? "enabled" : "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_DETACH) {
logger->info("Plugin {} unloaded.", PLUGIN_NAME);
spdlog::drop_all();
}
return TRUE;
}