From 6bf124a1965ae696a5f00b2f0d9677731cb6550e Mon Sep 17 00:00:00 2001 From: GingerNinja Date: Sat, 17 Oct 2026 19:17:30 +0200 Subject: [PATCH] feat: auto-confirm the alliance max-level contribution warning Add a ui.auto_confirm_alliance_contribution TOML setting (default false) that skips the level-60 warning popup shown before contributing to a max-level alliance. The warning's MessageBox callback (AllianceContributionViewController.<>c__DisplayClass72_0.b__0) only proceeds on MessageBox.ButtonResult.Yes (= 3, verified against the client disassembly), so the existing shared MessageBox.Show detours now invoke it with Yes instead of showing the popup. The detours are consolidated behind the existing install gate, which now triggers on either the Forbidden Tech or the new setting. Cherry-picked from stfc-mod-personal (3f202ff). Adapted to this tree's design: the MessageBox hooks stay installed unconditionally via the [patches] installForbiddenTechConfirmationHooks toggle with the feature setting checked inside the hook, and the patch entry label is renamed to MessageBoxConfirmations since the detours now own two auto-confirm behaviors. --- example_community_patch_settings_en.toml | 3 ++ mods/src/config.cc | 3 ++ mods/src/config.h | 1 + mods/src/defaultconfig.h | 1 + .../parts/forbidden_tech_confirmation.cc | 36 ++++++++++++++++++- mods/src/patches/patches.cc | 2 +- 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/example_community_patch_settings_en.toml b/example_community_patch_settings_en.toml index fdb54c7d1..7de155ccb 100644 --- a/example_community_patch_settings_en.toml +++ b/example_community_patch_settings_en.toml @@ -739,6 +739,9 @@ reverse_haven_history = true # Confirm Forbidden Tech level and tier upgrades automatically auto_confirm_ft_upgrade = false +# Automatically confirm the max-level warning shown when contributing to an alliance that has reached level 60 +auto_confirm_alliance_contribution = false + # Instant-warp action to confirm automatically: none, warp, or jump # "none" - Do not choose an action automatically; show the confirmation dialog # "warp" - Automatically choose regular warp diff --git a/mods/src/config.cc b/mods/src/config.cc index 3fc11d19d..b6798af09 100644 --- a/mods/src/config.cc +++ b/mods/src/config.cc @@ -1204,6 +1204,9 @@ void Config::Load() this->auto_confirm_reveal_ability = get_config_or_default(config, parsed, "ui", "auto_confirm_reveal_ability", DCU::auto_confirm_reveal_ability, write_config); + this->auto_confirm_alliance_contribution = + get_config_or_default(config, parsed, "ui", "auto_confirm_alliance_contribution", + DCU::auto_confirm_alliance_contribution, write_config); this->extend_chest_purchase_max = get_config_or_default(config, parsed, "ui", "extend_chest_purchase_max", DCU::extend_chest_purchase_max, write_config); diff --git a/mods/src/config.h b/mods/src/config.h index 398bdc752..cf19f9982 100644 --- a/mods/src/config.h +++ b/mods/src/config.h @@ -234,6 +234,7 @@ class Config final bool auto_open_bulk_claim_flyout; bool auto_confirm_ft_upgrade; bool auto_confirm_reveal_ability; + bool auto_confirm_alliance_contribution; std::vector daily_bulk_claim_factions; diff --git a/mods/src/defaultconfig.h b/mods/src/defaultconfig.h index 3b9f855d0..fd80ebf78 100644 --- a/mods/src/defaultconfig.h +++ b/mods/src/defaultconfig.h @@ -268,6 +268,7 @@ namespace UI constexpr bool auto_confirm_discovery = true; constexpr bool auto_confirm_ft_upgrade = false; constexpr bool auto_confirm_reveal_ability = false; + constexpr bool auto_confirm_alliance_contribution = false; constexpr bool auto_open_bulk_claim_flyout = false; constexpr const char* daily_bulk_claim_factions = ""; constexpr bool daily_bulk_claim_toggle_default_on = false; diff --git a/mods/src/patches/parts/forbidden_tech_confirmation.cc b/mods/src/patches/parts/forbidden_tech_confirmation.cc index fdd617f26..11d03980c 100644 --- a/mods/src/patches/parts/forbidden_tech_confirmation.cc +++ b/mods/src/patches/parts/forbidden_tech_confirmation.cc @@ -10,6 +10,7 @@ namespace { constexpr int32_t ConfirmButtonResult = 1; +constexpr int32_t YesButtonResult = 3; const FieldInfo* on_selection_field = nullptr; @@ -26,6 +27,19 @@ bool IsForbiddenTechConfirmation(const Il2CppDelegate* callback) strcmp(callback->method->name, "b__0") == 0; } +bool IsAllianceContributionMaxLevelWarning(const Il2CppDelegate* callback) +{ + if (callback == nullptr || callback->target == nullptr || callback->method == nullptr) { + return false; + } + + const auto* target_class = callback->target->klass; + const auto* owner_class = target_class == nullptr ? nullptr : target_class->declaringType; + + return owner_class != nullptr && strcmp(owner_class->name, "AllianceContributionViewController") == 0 + && strcmp(callback->method->name, "b__0") == 0; +} + bool ConfirmForbiddenTechUpgrade(Il2CppDelegate* callback) { if (!Config::Get().auto_confirm_ft_upgrade || !IsForbiddenTechConfirmation(callback)) { @@ -45,6 +59,26 @@ bool ConfirmForbiddenTechUpgrade(Il2CppDelegate* callback) return true; } +bool ConfirmAllianceContribution(Il2CppDelegate* callback) +{ + if (!Config::Get().auto_confirm_alliance_contribution || !IsAllianceContributionMaxLevelWarning(callback)) { + return false; + } + + int32_t result = YesButtonResult; + void* args[] = {&result}; + Il2CppException* exception = nullptr; + il2cpp_runtime_invoke(callback->method, callback->target, args, &exception); + + if (exception != nullptr) { + spdlog::warn("AllianceContributionConfirmation: failed to invoke the confirmation callback"); + return false; + } + + spdlog::debug("AllianceContributionConfirmation: auto-confirmed the max-level contribution warning"); + return true; +} + Il2CppDelegate* GetSelectionCallback(void* context) { if (context == nullptr || on_selection_field == nullptr) { @@ -63,7 +97,7 @@ void MessageBox_Show_Hook(auto original, void* context) void MessageBox_ShowWithCallback_Hook(auto original, void* context, Il2CppDelegate* callback) { - if (!ConfirmForbiddenTechUpgrade(callback)) { + if (!ConfirmForbiddenTechUpgrade(callback) && !ConfirmAllianceContribution(callback)) { original(context, callback); } } diff --git a/mods/src/patches/patches.cc b/mods/src/patches/patches.cc index 2560e3d38..7a3083607 100644 --- a/mods/src/patches/patches.cc +++ b/mods/src/patches/patches.cc @@ -177,7 +177,7 @@ __int64 il2cpp_init_hook(auto original, const char* domain_name) {"PinnedShipClick", {InstallPinnedShipClickHooks, &cfg.installPinnedShipClickToggle}}, {"DoubleClickAssignShip", {InstallDoubleClickAssignShipHooks, &cfg.installDoubleClickAssignShipHooks}}, {"InstantWarpConfirm", {InstallInstantWarpConfirmationHooks, &cfg.installInstantWarpConfirmationHooks}}, - {"ForbiddenTechConfirm", {InstallForbiddenTechConfirmationHooks, &cfg.installForbiddenTechConfirmationHooks}}, + {"MessageBoxConfirmations", {InstallForbiddenTechConfirmationHooks, &cfg.installForbiddenTechConfirmationHooks}}, {"RevealConfirm", {InstallRevealConfirmationHooks, &cfg.installRevealConfirmationHooks}}, {"AudioEvents", {InstallAudioEventHooks, &cfg.installAudioEventHooks}}, {"ActionQueueRecovery", {InstallActionQueueRecovery, &cfg.installActionQueueRecoveryHooks}},