-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New KSP bugfix: PropellantFlowDescription. Propellant's GetFlowModeDe…
…scription ignores the class potentially overriding the base flow mode. This fixes that.
- Loading branch information
1 parent
7a6a5a5
commit 10c9c91
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using HarmonyLib; | ||
using System.Collections.Generic; | ||
|
||
namespace KSPCommunityFixes.BugFixes | ||
{ | ||
class PropellantFlowDescription : BasePatch | ||
{ | ||
protected override Version VersionMin => new Version(1, 8, 0); | ||
|
||
protected override void ApplyPatches(List<PatchInfo> patches) | ||
{ | ||
patches.Add(new PatchInfo( | ||
PatchMethodType.Prefix, | ||
AccessTools.Method(typeof(Propellant), nameof(Propellant.GetFlowModeDescription)), | ||
this)); | ||
|
||
patches.Add(new PatchInfo( | ||
PatchMethodType.Postfix, | ||
AccessTools.Method(typeof(Propellant), nameof(Propellant.GetFlowModeDescription)), | ||
this)); | ||
} | ||
|
||
// doing this this way rather than via __state | ||
// so we don't have to pass around structs or the like | ||
private static PartResourceDefinition _def; | ||
private static ResourceFlowMode _mode; | ||
|
||
static void Propellant_GetFlowModeDescription_Prefix(Propellant __instance) | ||
{ | ||
if (__instance.flowMode == ResourceFlowMode.NULL) | ||
return; | ||
var resDef = PartResourceLibrary.Instance.GetDefinition(__instance.id); | ||
if (resDef == null) | ||
return; | ||
|
||
_def = resDef; | ||
_mode = _def.resourceFlowMode; | ||
_def._resourceFlowMode = __instance.flowMode; | ||
} | ||
|
||
static void Propellant_GetFlowModeDescription_Postfix(Propellant __instance) | ||
{ | ||
if (_def != null) | ||
_def._resourceFlowMode = _mode; | ||
|
||
_def = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters