diff --git a/docs/FEATURES.md b/docs/FEATURES.md index ecf743d41..21de5b260 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -22,6 +22,7 @@ Features depend on the game client. A client update can break a hook until the m | Haven | Extend camera range while keeping road surfaces above the ground. `graphics.haven_zoom = 0.0` uses the native range. | | Fleet labels | Choose native, expanded, compact, or zoom-threshold detail separately for player and non-player fleets. | | Window and cursor | Resize the game window freely on Windows and control whether the game replaces the system cursor. | +| Mirror space timer | Show the earliest remaining ship countdown in the viewed Mirror system, below Help All, Engage and Claim. Enable `mirror_space_timer` in `[graphics]`. Disabled by default. | | Anomaly timer | Show the remaining time in a Galactic Anomaly system. Disabled by default. | `fr_scale` scales system-view backdrop renderables. diff --git a/docs/configuration/example_community_patch_settings_en.toml b/docs/configuration/example_community_patch_settings_en.toml index 02487b13e..822f8dff6 100644 --- a/docs/configuration/example_community_patch_settings_en.toml +++ b/docs/configuration/example_community_patch_settings_en.toml @@ -235,6 +235,10 @@ free_resize = true # Show the remaining Galactic Anomaly time below Help All, Engage, and Claim galactic_anomaly_timer = false +# Show the earliest Mirror space ship countdown in the viewed system in the same HUD panel. +# Both HUD timers use [patches] galacticanomalytimerhooks. +mirror_space_timer = false + # After using a zoom preset it will be set as default zoom use_presets_as_default = true diff --git a/src/mod/config.cc b/src/mod/config.cc index 8e4df4531..37c20381e 100644 --- a/src/mod/config.cc +++ b/src/mod/config.cc @@ -642,6 +642,7 @@ void Config::Read(const toml::table& file, toml::table& effective, bool log_valu r.Read("graphics", "loader_logo_scale", g.loader_logo_scale); r.Read("graphics", "loader_tip_enabled", g.loader_tip_enabled); r.Read("graphics", "galactic_anomaly_timer", g.galactic_anomaly_timer); + r.Read("graphics", "mirror_space_timer", g.mirror_space_timer); // [buffs] r.Read("buffs", "use_out_of_dock_power", buffs.use_out_of_dock_power); diff --git a/src/mod/config.h b/src/mod/config.h index 572881870..b68f9aab5 100644 --- a/src/mod/config.h +++ b/src/mod/config.h @@ -243,6 +243,7 @@ class Config final float loader_logo_scale = 1.0f; bool loader_tip_enabled = true; bool galactic_anomaly_timer = false; + bool mirror_space_timer = false; } graphics; struct Buffs { diff --git a/src/mod/features/anomaly_timer.cc b/src/mod/features/anomaly_timer.cc index 621925bd7..88710fd77 100644 --- a/src/mod/features/anomaly_timer.cc +++ b/src/mod/features/anomaly_timer.cc @@ -1,5 +1,6 @@ // [graphics] galactic_anomaly_timer: a countdown for the active galactic anomaly in the viewed system, under the HUD's -// Help All / Engage / Claim drawer. All Unity work runs on the frame tick; there are no detours of its own. +// Help All / Engage / Claim drawer. [graphics] mirror_space_timer shows the earliest fleet countdown in the viewed +// Mirror system in the same panel. All Unity work runs on the frame tick; there are no detours of its own. #include "config.h" #include "features/features.h" @@ -68,6 +69,32 @@ int64_t AnomalyRemainingTicks(HudNavigationViewController* nav) return timer ? timer->RemainingTime().ticks : 0; } +int64_t MirrorRemainingTicks(HudNavigationViewController* nav) +{ + auto* context = nav->CanvasContext(); + auto* address = context ? context->ViewingAddress() : nullptr; + auto* bar = unity::Newest(); + auto* fleets = bar ? bar->CanvasContext() : nullptr; + if (!address || !fleets) + return 0; + + int64_t remaining = 0; + for (auto* fleet : il2cpp::Items(fleets->FleetData())) { + if (!fleet || !fleet->IsInMirrorUniverse()) + continue; + auto* location = fleet->Address(); + StatusEffect* effect = nullptr; + if (!location || location->System() != address->System() + || !fleet->TryGetStatusEffectData(StatusEffectType::MirrorUniverseTimer, effect) || !effect + || !effect->IsStatusActive()) + continue; + const int64_t ticks = effect->GetRemainingTimespan().ticks; + if (ticks > 0 && (remaining == 0 || ticks < remaining)) + remaining = ticks; + } + return remaining; +} + // Builds the panel: the native rounded sprite twice, with a narrow inset making the border, and a countdown in the // system-name font. A missing sprite still gives a visible frame. Null while the drawer or the HUD's font is not up // yet; the next tick tries again. @@ -128,11 +155,14 @@ void AnomalyTimerFrame() return; // View only returns a HUD that is up on a visible canvas, so nothing about it needs holding between ticks. - auto* nav = Config::Get().graphics.galactic_anomaly_timer && Hub::CurrentSection() == SectionID::Navigation_System - ? ScreenManager::View() - : nullptr; - const int64_t ticks = nav && nav->CanShowGalacticAnomaly() ? AnomalyRemainingTicks(nav) : 0; - auto* label = anomaly_label.Get(); + auto* nav = (Config::Get().graphics.galactic_anomaly_timer || Config::Get().graphics.mirror_space_timer) + && Hub::CurrentSection() == SectionID::Navigation_System + ? ScreenManager::View() + : nullptr; + int64_t ticks = nav && Config::Get().graphics.mirror_space_timer ? MirrorRemainingTicks(nav) : 0; + if (ticks <= 0 && nav && Config::Get().graphics.galactic_anomaly_timer && nav->CanShowGalacticAnomaly()) + ticks = AnomalyRemainingTicks(nav); + auto* label = anomaly_label.Get(); if (!unity::Alive(label)) label = nullptr; if (ticks <= 0) { diff --git a/src/mod/game/fleet.h b/src/mod/game/fleet.h index 57ffdbc56..5a92038f3 100644 --- a/src/mod/game/fleet.h +++ b/src/mod/game/fleet.h @@ -231,9 +231,63 @@ struct ForbiddenTechManager : MonoSingleton { } }; +// Client status effects, including the per-fleet Mirror space countdown. +enum class StatusEffectType : int32_t { + Invalid = 0, + Cloaked = 1, + Supported = 2, + Debuffed = 3, + WarShieldActivated = 4, + ArmadaSupported = 5, + WeaponDamageActivated = 6, + WeaponPenetrationActivated = 7, + WeaponShotsActivated = 8, + CriticalDamageActivated = 9, + Detected = 10, + SystemWideBuffed = 11, + SystemWideSupremeBuffed = 12, + IsoDamageBoosted = 14, + DamageToExplorersBoosted = 15, + DamageToBattleshipsBoosted = 16, + DamageToInterceptorsBoosted = 17, + CuttingBeamHit = 18, + SystemPeek = 19, + WormholeInstaRecallAvailable = 20, + MirrorUniverseTimer = 21, + Indestructible = 22, + PostWormholeBuff = 70001, + TauntAsaActivated = 71001, + Static = 75001, + Charged = 75002, + Weakened = 77001, + ChainShotImmunityActivated = 78001, + AutoHuntingActivated = 83001, + Enhanced = 86001, + BorgProtocolActivated = 89001, + Amplified = 91001, + TempAutoHuntingActivated = 96001, + NoEffect = -1, +}; + +struct StatusEffect : il2cpp::Object { + using Class = il2cpp::Class<"Digit.Client.PrimeLib.Runtime", "Digit.PrimeServer.Models", "StatusEffect">; + + bool IsStatusActive() + { return Get<"IsStatusActive", bool>(); } + unity::TimeSpan GetRemainingTimespan() + { return Call<"GetRemainingTimespan", unity::TimeSpan>(); } +}; + struct FleetPlayerData : il2cpp::Object { using Class = il2cpp::Class<"Digit.Client.PrimeLib.Runtime", "Digit.PrimeServer.Models", "FleetPlayerData">; + bool IsInMirrorUniverse() + { return Get<"IsInMirrorUniverse", bool>(); } + NodeAddress* Address() + { return Get<"Address", NodeAddress*>(); } + bool TryGetStatusEffectData(StatusEffectType type, StatusEffect*& effect) + { return Call<"TryGetStatusEffectData", bool(StatusEffectType, StatusEffect*&)>(type, effect); } + // No property for the mining timer, so read the private field. ITimerData* miningSlotTimer() { return Field<"_miningSlotTimer", ITimerData*>(); }