Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions example_community_patch_settings_en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions mods/src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions mods/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> daily_bulk_claim_factions;

Expand Down
1 change: 1 addition & 0 deletions mods/src/defaultconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 35 additions & 1 deletion mods/src/patches/parts/forbidden_tech_confirmation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace
{
constexpr int32_t ConfirmButtonResult = 1;
constexpr int32_t YesButtonResult = 3;

const FieldInfo* on_selection_field = nullptr;

Expand All @@ -26,6 +27,19 @@ bool IsForbiddenTechConfirmation(const Il2CppDelegate* callback)
strcmp(callback->method->name, "<RequestAction>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, "<RequestAction>b__0") == 0;
}

bool ConfirmForbiddenTechUpgrade(Il2CppDelegate* callback)
{
if (!Config::Get().auto_confirm_ft_upgrade || !IsForbiddenTechConfirmation(callback)) {
Expand All @@ -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) {
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion mods/src/patches/patches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down
Loading