Skip to content

Commit

Permalink
Fix a bug in the UpgradesBugs patch where the upgrades field on a Par…
Browse files Browse the repository at this point in the history
…tModule could be left null in some cases. This is true only for PartModules that are added via code, and only on the prefab itself it appears.
  • Loading branch information
NathanKell committed Aug 6, 2022
1 parent b902241 commit 3fbc7a6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions KSPCommunityFixes/BugFixes/UpgradeBugs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class UpgradeBugs : BasePatch

protected override void ApplyPatches(List<PatchInfo> patches)
{
patches.Add(new PatchInfo(
PatchMethodType.Postfix,
AccessTools.Constructor(typeof(PartModule)),
this, "PartModule_ctor_Postfix"));

patches.Add(new PatchInfo(
PatchMethodType.Prefix,
AccessTools.Method(typeof(PartListTooltip), nameof(PartListTooltip.SetupUpgradeInfo)),
Expand Down Expand Up @@ -72,6 +77,11 @@ protected override void ApplyPatches(List<PatchInfo> patches)
"GetUsedBy_Prefix"));
}

static void PartModule_ctor_Postfix(PartModule __instance)
{
__instance.upgrades = new List<ConfigNode>();
}

// This was doing weird stuff with PartStatsUpgradeModules where it only applied its upgrades' costs.
// and added an extendedInfo entry for just that.
// We'll handle everything in CreateExtendedInfo instead.
Expand Down

0 comments on commit 3fbc7a6

Please sign in to comment.