diff --git a/GameData/KSPCommunityFixes/Settings.cfg b/GameData/KSPCommunityFixes/Settings.cfg index 1679d44..5f321a7 100644 --- a/GameData/KSPCommunityFixes/Settings.cfg +++ b/GameData/KSPCommunityFixes/Settings.cfg @@ -179,6 +179,12 @@ KSP_COMMUNITY_FIXES // Fix leaking a camera and spotlight created by the thumbnail system on certain failures ThumbnailSpotlight = true + // Fix Propellant's GetFlowModeDescription (used when generating ModuleEngines ModuleInfo + // where it describes propellants) to use the propellant's flow mode, not the base resource + // flow mode. + PropellantFlowDescription = true + + // Make docking ports converve momentum by averaging acquire forces between the two ports. // Notably, docking port Kraken drives will no longer work. DockingPortConserveMomentum = true diff --git a/KSPCommunityFixes/BugFixes/PropellantFlowDescription.cs b/KSPCommunityFixes/BugFixes/PropellantFlowDescription.cs new file mode 100644 index 0000000..4e7e332 --- /dev/null +++ b/KSPCommunityFixes/BugFixes/PropellantFlowDescription.cs @@ -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 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; + } + } +} diff --git a/KSPCommunityFixes/KSPCommunityFixes.csproj b/KSPCommunityFixes/KSPCommunityFixes.csproj index bcd5053..a26a4a1 100644 --- a/KSPCommunityFixes/KSPCommunityFixes.csproj +++ b/KSPCommunityFixes/KSPCommunityFixes.csproj @@ -103,6 +103,7 @@ + diff --git a/README.md b/README.md index c5d5518..0813491 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ User options are available from the "ESC" in-game settings menu :