From 19c664eb88e2bb387fcc0c01c7d3b6f9b060bc97 Mon Sep 17 00:00:00 2001 From: siimav <1120038+siimav@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:36:32 +0300 Subject: [PATCH] Harmony-patch RA config can afford query to factor in unlock credit (#2410) --- Source/RP0/Harmony/RealAntennas.cs | 28 ++++++++++++++++++++++++++++ Source/RP0/RP0.csproj | 1 + 2 files changed, 29 insertions(+) create mode 100644 Source/RP0/Harmony/RealAntennas.cs diff --git a/Source/RP0/Harmony/RealAntennas.cs b/Source/RP0/Harmony/RealAntennas.cs new file mode 100644 index 00000000000..e15ed0d755c --- /dev/null +++ b/Source/RP0/Harmony/RealAntennas.cs @@ -0,0 +1,28 @@ +using HarmonyLib; + +namespace RP0.Harmony +{ + [HarmonyPatch(typeof(RealAntennas.ModuleRealAntenna))] + internal class RAPartModulePatcher + { + [HarmonyPrepare] + internal static bool Prepare() + { + var m = AccessTools.Method(typeof(RealAntennas.ModuleRealAntenna), "CanAffordEntryCost", new System.Type[] { typeof(float) }); + return m != null; + } + + [HarmonyPrefix] + [HarmonyPatch("CanAffordEntryCost")] + internal static bool Prefix_CanAffordEntryCost(float cost, ref bool __result) + { + var cmq = CurrencyModifierQueryRP0.RunQuery(TransactionReasonsRP0.PartOrUpgradeUnlock, -cost, 0d, 0d); + double postCMQcost = -cmq.GetTotal(CurrencyRP0.Funds, false); + double credit = UnlockCreditHandler.Instance.TotalCredit; + cmq.AddPostDelta(CurrencyRP0.Funds, credit, true); + __result = cmq.CanAfford(); + + return false; + } + } +} diff --git a/Source/RP0/RP0.csproj b/Source/RP0/RP0.csproj index bd7bc826e41..d7d6b807ad3 100644 --- a/Source/RP0/RP0.csproj +++ b/Source/RP0/RP0.csproj @@ -49,6 +49,7 @@ +