Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmony-patch RA config can afford query to factor in unlock credit #2410

Merged
merged 1 commit into from
Aug 11, 2024
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
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 @@ -45,6 +45,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
Loading