diff --git a/StyxBladesOfGreed/dllmain.cpp b/StyxBladesOfGreed/dllmain.cpp index da46286..506c796 100644 --- a/StyxBladesOfGreed/dllmain.cpp +++ b/StyxBladesOfGreed/dllmain.cpp @@ -157,10 +157,7 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) { UltraWideFixEnabled(); CameraDistanceFixEnabled(); HUDUpdate(true); - gPendingDOF = true; - gPendingCA = true; - gPendingVignetting = true; - gPendingFog = true; + SetAllEffectsToBeToggled(); LogFixToggle(GameFixes::None, g_fix_enabled); } @@ -219,7 +216,11 @@ static void ProcessEvent() { 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 + static UC::int32 NAME_Construct = -1; + static UC::int32 NAME_Destruct = -1; + static UC::int32 NAME_PerceptionTick = -1; + + if (now - lastScanTick >= DEFAULT_DELAY_BETWEEN_TICK) { // Delay between each tick to avoid ProcessEvent stuttering lastScanTick = now; GetResolution(screenWidth, screenHeight, g_AspectRatio); } @@ -228,113 +229,118 @@ static void ProcessEvent() { UFunction* func = (UFunction*)ctx.rdx; if (!object || !func) return; - std::string funcName = func->GetName(); + UC::int32 comparisonIndex = func->Name.ComparisonIndex; // Make function comparision faster than allocating std::srting + if (NAME_PerceptionTick == -1 && func->Name.ToString() == "OnPerceptionIntensityUpdated") + NAME_PerceptionTick = comparisonIndex; // Full stealth fix: disable AI perception. - if (object->IsA(AStyx3AIController::StaticClass()) && funcName == "OnPerceptionIntensityUpdated") { + if (NAME_PerceptionTick == comparisonIndex && object->IsA(AStyx3AIController::StaticClass())) { auto* AIController = static_cast(object); + if (g_Player && AIController->PerceptionGaugeComponent) { - if (g_Stealth_fix_enabled) { + 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; - } + else AIController->PerceptionGaugeComponent->SetActiveBufferDetection(g_Player, true); + + g_Player->bIsPerceptible = !g_Stealth_fix_enabled; } } - if (object->IsA(UUserWidget::StaticClass()) && (funcName == "Construct" || funcName == "Destruct" || funcName == "Tick")) { - std::string objectName = object->GetName(); + if (object->IsA(UUserWidget::StaticClass())) { + if (NAME_Construct == -1 && func->Name.ToString() == "Construct") NAME_Construct = func->Name.ComparisonIndex; + if (NAME_Destruct == -1 && func->Name.ToString() == "Destruct") NAME_Destruct = func->Name.ComparisonIndex; // 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(object), g_UISettingsWidget); - else if (object->IsA(UUI_Difficulty_C::StaticClass())) - HandleWidget(static_cast(object), g_DifficultyWidget); - else if (object->IsA(UUI_InGameMenu_C::StaticClass())) - HandleWidget(static_cast(object), g_InGameMenuWidget); - else if (object->IsA(UUI_PauseMenu_C::StaticClass())) - HandleWidget(static_cast(object), g_PauseWidget); - else if (object->IsA(UUI_Profile_C::StaticClass())) - HandleWidget(static_cast(object), g_ProfileWidget); - else if (object->IsA(UUI_MainMenu_C::StaticClass())) - HandleWidget(static_cast(object), g_UIMainMenuWidget); - else if (object->IsA(UUI_Saves_C::StaticClass())) - HandleWidget(static_cast(object), g_SavesWidget); - else if (object->IsA(UUI_Upgrades_C::StaticClass())) - HandleWidget(static_cast(object), g_UpgradeWidget); - else if (objectName.rfind("UI_Map_C", 0) == 0) - HandleWidget(static_cast(object), g_MapWidget); - else if (objectName.rfind("UI_GameOver_C", 0) == 0) - HandleWidget(static_cast(object), g_GameOverWidget); - else if (objectName.rfind("UI_Loading_C", 0) == 0) - HandleWidget(static_cast(object), g_LoadingWidget); - else { - std::function 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(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(Widget); - if (UW->WidgetTree && UW->WidgetTree->RootWidget) - FindWidgets(UW->WidgetTree->RootWidget); - } - }; - - if (objectName.rfind("Crafting", 0) == 0) { - if (funcName == "Construct") { - g_CraftingWidget = static_cast(object); + if (NAME_Construct == comparisonIndex || NAME_Destruct == comparisonIndex) { + std::string objectName = object->GetName(); + // Lambda to initialize pointers on Construct and nullify them on Destruct + auto HandleWidget = [&](auto* typedWidget, auto*& gWidgetPtr) { + if (NAME_Construct == comparisonIndex) { + gWidgetPtr = typedWidget; HUDUpdate(false); } - else if (funcName == "Destruct") g_CraftingWidget = nullptr; - } - else if (objectName.rfind("HUD_Widget_C", 0) == 0) { - auto* HUDWidget = static_cast(object); - if (funcName == "Construct") { - if (HUDWidget && HUDWidget->Class) { - FindWidgets(HUDWidget->WidgetTree->RootWidget); + else if (NAME_Destruct == comparisonIndex) gWidgetPtr = nullptr; + }; + + if (object->IsA(UUI_Settings_C::StaticClass())) + HandleWidget(static_cast(object), g_UISettingsWidget); + else if (object->IsA(UUI_Difficulty_C::StaticClass())) + HandleWidget(static_cast(object), g_DifficultyWidget); + else if (object->IsA(UUI_InGameMenu_C::StaticClass())) + HandleWidget(static_cast(object), g_InGameMenuWidget); + else if (object->IsA(UUI_PauseMenu_C::StaticClass())) + HandleWidget(static_cast(object), g_PauseWidget); + else if (object->IsA(UUI_Profile_C::StaticClass())) + HandleWidget(static_cast(object), g_ProfileWidget); + else if (object->IsA(UUI_MainMenu_C::StaticClass())) + HandleWidget(static_cast(object), g_UIMainMenuWidget); + else if (object->IsA(UUI_Saves_C::StaticClass())) + HandleWidget(static_cast(object), g_SavesWidget); + else if (object->IsA(UUI_Upgrades_C::StaticClass())) + HandleWidget(static_cast(object), g_UpgradeWidget); + else if (objectName.rfind("UI_Map_C", 0) == 0) + HandleWidget(static_cast(object), g_MapWidget); + else if (objectName.rfind("UI_GameOver_C", 0) == 0) + HandleWidget(static_cast(object), g_GameOverWidget); + else if (objectName.rfind("UI_Loading_C", 0) == 0) + HandleWidget(static_cast(object), g_LoadingWidget); + else { + std::function 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; + 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(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(Widget); + if (UW->WidgetTree && UW->WidgetTree->RootWidget) + FindWidgets(UW->WidgetTree->RootWidget); + } + }; + + if (objectName.rfind("Crafting", 0) == 0) { + if (NAME_Construct == comparisonIndex) { + g_CraftingWidget = static_cast(object); HUDUpdate(false); } + else if (NAME_Destruct == comparisonIndex) g_CraftingWidget = nullptr; } - else if (funcName == "Destruct") { - g_QuestWidget = nullptr; - g_LootWidget = nullptr; - g_StatusWidget = nullptr; - g_GaugesWidget = nullptr; - g_ChangeWheelWidget = nullptr; - g_AbilityWheelWidget = nullptr; + else if (objectName.rfind("HUD_Widget_C", 0) == 0) { + auto* HUDWidget = static_cast(object); + if (NAME_Construct == comparisonIndex) { + if (HUDWidget && HUDWidget->Class) { + FindWidgets(HUDWidget->WidgetTree->RootWidget); + HUDUpdate(false); + } + } + else if (NAME_Destruct == comparisonIndex) { + g_QuestWidget = nullptr; + g_LootWidget = nullptr; + g_StatusWidget = nullptr; + g_GaugesWidget = nullptr; + g_ChangeWheelWidget = nullptr; + g_AbilityWheelWidget = nullptr; + } } } }