From e3d5ece1f2c58676acf41d52a2c1a92a33599abc Mon Sep 17 00:00:00 2001 From: netniV Date: Wed, 18 Nov 2026 11:39:25 +0000 Subject: [PATCH] Allow Settings shortcut during tutorials --- src/mod/features/features.h | 2 + src/mod/features/hotkeys.cc | 94 ++++++++++++++++++++++++++++++++++++- src/mod/features/screens.cc | 8 +++- src/mod/game/app.h | 55 ++++++++++++++++++++++ 4 files changed, 156 insertions(+), 3 deletions(-) diff --git a/src/mod/features/features.h b/src/mod/features/features.h index 8c43de8e6..f59ac4855 100644 --- a/src/mod/features/features.h +++ b/src/mod/features/features.h @@ -136,6 +136,8 @@ extern const Feature kHavenHistory; // hotkeys.cc extern const Feature kHotkeys; +// Arms the tutorial-input override before the Settings section transition begins. +void PrepareSettingsInput(); // The shortcut dispatch for one frame, run by the frame tick. True when the game's own ScreenManager.Update must // not run, so it does not handle the key as well. False until kHotkeys is installed. bool HandleShortcuts(); diff --git a/src/mod/features/hotkeys.cc b/src/mod/features/hotkeys.cc index ec68987b3..db7facce0 100644 --- a/src/mod/features/hotkeys.cc +++ b/src/mod/features/hotkeys.cc @@ -25,9 +25,81 @@ namespace // The frame tick dispatches shortcuts whether or not this feature installed; this says whether it did. bool hotkeys_installed = false; std::optional hotkeys_escape_first_press; +il2cpp::GcHandle suspended_tutorial_mask; +std::optional suspended_tutorial_active; +std::optional suspended_tutorial_input; +std::optional suspended_touch_block; +bool settings_input_requested = false; +bool settings_input_entered = false; +int settings_input_wait = 0; + +void RestoreTutorialInput() +{ + auto* object = suspended_tutorial_mask.Get(); + suspended_tutorial_mask.Reset(); + if (unity::Alive(object)) + object->SetActive(true); + if (suspended_tutorial_active) { + TutorialManager::SetActive(*suspended_tutorial_active); + suspended_tutorial_active.reset(); + } + if (suspended_tutorial_input) { + TutorialManager::SetBlockingInput(*suspended_tutorial_input); + suspended_tutorial_input.reset(); + } + if (suspended_touch_block) { + TouchKit::SetBlockTouch(*suspended_touch_block); + suspended_touch_block.reset(); + } +} + +void ReleaseSettingsInput() +{ + if (!suspended_tutorial_active) + suspended_tutorial_active = TutorialManager::Active(); + TutorialManager::SetActive(false); + if (!suspended_tutorial_input) + suspended_tutorial_input = TutorialManager::BlockingInput(); + TutorialManager::SetBlockingInput(false); + if (!suspended_touch_block) + suspended_touch_block = TouchKit::BlockTouch(); + TouchKit::SetBlockTouch(false); +} void ResetHotkeys() -{ hotkeys_escape_first_press.reset(); } +{ + RestoreTutorialInput(); + settings_input_requested = false; + settings_input_entered = false; + settings_input_wait = 0; + hotkeys_escape_first_press.reset(); +} + +void SettingsTutorialInputFrame() +{ + if (Hub::CurrentSection() != SectionID::GameSettings) { + if (settings_input_entered || (settings_input_requested && --settings_input_wait == 0)) { + RestoreTutorialInput(); + settings_input_requested = false; + settings_input_entered = false; + } + return; + } + settings_input_entered = true; + ReleaseSettingsInput(); + if (suspended_tutorial_mask) + return; + + auto* manager = Hub::Class::Get<"TutorialManager", TutorialManager*>(); + auto* loader = manager ? manager->loadAndShow() : nullptr; + auto* controller = loader ? loader->Controller() : nullptr; + auto* object = unity::ActiveAndEnabled(controller) ? controller->gameObject() : nullptr; + if (!object) + return; + + suspended_tutorial_mask = il2cpp::GcHandle::Strong(object); + object->SetActive(false); +} // --- Setting shortcuts --- @@ -118,10 +190,19 @@ void ShortcutsManager_InitializeActions_Hook(auto original, ShortcutsManager* _t original(_this); } +bool TutorialManager_get_IsBlockingInput_Hook(auto original) +{ + // A screen opened directly by a mod shortcut is not one of the tutorial's highlighted controls. Let Settings + // receive pointer input while it is open, then restore the tutorial's normal restriction as soon as it closes. + return settings_input_requested || Hub::CurrentSection() == SectionID::GameSettings ? false : original(); +} + bool InstallHotkeys() { il2cpp::HookSet hooks("Hotkeys"); IL2CPP_STAGE(hooks, ShortcutsManager::Class::Method("InitializeActions"), ShortcutsManager_InitializeActions_Hook); + IL2CPP_STAGE(hooks, TutorialManager::Class::StaticMethod("get_IsBlockingInput"), + TutorialManager_get_IsBlockingInput_Hook); // The badges only make sense when the game's own input actions are under the mod's control. if (hooks.Commit()) InstallKeybindBadges(); @@ -133,6 +214,14 @@ bool InstallHotkeys() } } // namespace +void PrepareSettingsInput() +{ + ReleaseSettingsInput(); + settings_input_requested = true; + settings_input_entered = false; + settings_input_wait = 300; +} + bool HandleShortcuts() { if (!hotkeys_installed) @@ -208,4 +297,5 @@ bool HandleShortcuts() return FleetActionShortcuts() || SwallowEscape(); } -const Feature kHotkeys{"Hotkeys", &Config::Patches::hotkeyhooks, InstallHotkeys, nullptr, ResetHotkeys}; +const Feature kHotkeys{"Hotkeys", &Config::Patches::hotkeyhooks, InstallHotkeys, SettingsTutorialInputFrame, + ResetHotkeys}; diff --git a/src/mod/features/screens.cc b/src/mod/features/screens.cc index 935f87e02..1f7a11293 100644 --- a/src/mod/features/screens.cc +++ b/src/mod/features/screens.cc @@ -66,6 +66,12 @@ void ShowCoordinateSearch() } } +void ShowSettings() +{ + PrepareSettingsInput(); + Hub::GotoSection(SectionID::GameSettings); +} + // Opens Manage Ships for the fleet selected in the fleet bar. False when none is selected. bool OpenManageShips() { @@ -202,7 +208,7 @@ constexpr ScreenShortcut kScreens[] = { {Action::kShowAlliance, Goto}, {Action::kShowAllianceHelp, Goto}, {Action::kShowAllianceArmada, Goto}, - {Action::kShowSettings, Goto}, + {Action::kShowSettings, ShowSettings}, {Action::kShowShips, [] { OpenManageShips(); }, false}, }; diff --git a/src/mod/game/app.h b/src/mod/game/app.h index edd24eabe..3a43a331f 100644 --- a/src/mod/game/app.h +++ b/src/mod/game/app.h @@ -4,6 +4,7 @@ // the services the mod touches that belong to no screen (tutorial gates, audio, the Windows window procedure). #include +#include #include #include @@ -261,6 +262,60 @@ struct Hub { } }; +// The tutorial mask is a full-screen canvas that routes pointer input only to the highlighted control. +struct TutorialMaskUILoader : unity::Behaviour { + using Class = il2cpp::Class<"Assembly-CSharp", "Digit.Prime.Tutorial", "TutorialMaskUILoader">; + + unity::Behaviour* Controller() + { + return Get<"Controller", unity::Behaviour*>(); + } +}; + +struct TutorialManager : il2cpp::Object { + using Class = il2cpp::Class<"Assembly-CSharp", "Digit.Prime.Tutorial", "TutorialManager">; + + static bool Active() + { + return Class::Field<"_isActive", bool>(); + } + + static void SetActive(bool active) + { + Class::SetField<"_isActive">(active); + } + + static bool BlockingInput() + { + return Class::Field<"_isBlockingInput", bool>(); + } + + static void SetBlockingInput(bool blocked) + { + Class::SetField<"_isBlockingInput">(blocked); + } + + TutorialMaskUILoader* loadAndShow() + { + return Field<"_loadAndShow", TutorialMaskUILoader*>(); + } +}; + +// TouchKit's global pointer-input gate. Tutorials hold it while only their highlighted control may receive input. +struct TouchKit { + using Class = il2cpp::Class<"TouchKit", "", "TouchKit">; + + static bool BlockTouch() + { + return Class::Field<"BlockTouch", bool>(); + } + + static void SetBlockTouch(bool blocked) + { + Class::SetField<"BlockTouch">(blocked); + } +}; + // Fabric.EventManager, the game's sound middleware. Its shorter PostEvent overloads funnel into the // seven-argument one. using AudioEventManager = il2cpp::Class<"Fabric.Core", "Fabric", "EventManager">;