Skip to content

Commit

Permalink
Harmony-patch RA config can afford query to factor in unlock credit (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav authored Aug 11, 2024
1 parent 38a5015 commit 19c664e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Source/RP0/Harmony/RealAntennas.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions Source/RP0/RP0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Compile Include="ConfigurableStart\Utilities.cs" />
<Compile Include="Harmony\FlightInputHandler.cs" />
<Compile Include="Harmony\ModuleRCS.cs" />
<Compile Include="Harmony\RealAntennas.cs" />
<Compile Include="ModIntegrations\KSCSwitcherInterop.cs" />
<Compile Include="ModIntegrations\TFInterop.cs" />
<Compile Include="Singletons\LeaderNotifications.cs" />
Expand Down

0 comments on commit 19c664e

Please sign in to comment.