Skip to content

Commit

Permalink
Fix Propellant's GetFlowModeDescription (#165)
Browse files Browse the repository at this point in the history
* New KSP bugfix: PropellantFlowDescription. Propellant's GetFlowModeDescription ignores the class potentially overriding the base flow mode. This fixes that.

* Update readme for PR link

---------

Co-authored-by: gotmachine <24925209+gotmachine@users.noreply.github.com>
  • Loading branch information
NathanKell and gotmachine committed Dec 6, 2023
1 parent 798d44f commit 691a0f6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions KSPCommunityFixes/BugFixes/PropellantFlowDescription.cs
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;
}
}
}
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<Compile Include="BugFixes\AsteroidInfiniteMining.cs" />
<Compile Include="BugFixes\ChutePhantomSymmetry.cs" />
<Compile Include="BugFixes\CorrectDragForFlags.cs" />
<Compile Include="BugFixes\PropellantFlowDescription.cs" />
<Compile Include="BugFixes\LadderToggleableLight.cs" />
<Compile Include="BugFixes\MapSOCorrectWrapping.cs" />
<Compile Include="BugFixes\FixGetUnivseralTime.cs" />
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ User options are available from the "ESC" in-game settings menu :<br/><img src="
- [**ThumbnailSpotlight**](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/149) [KSP 1.12.0 - 1.12.5], fix rogue spotlight staying in the scene when a part thumbnail fails to be generated.
- [**FixGetUnivseralTime**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/155) [KSP 1.8.0 - 1.12.5]<br/>Fix Planetarium.GetUniversalTime returning bad values in the editor.
- [**DockingPortConserveMomentum**](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/160) [KSP 1.12.3 - 1.12.5]<br/>Make docking ports conserve momentum by averaging the acquire force between the two ports. Notably, docking port Kraken drives will no longer work.
- [**PropellantFlowDescription**](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/165) [KSP 1.8.0 - KSP 1.12.5]<br/>Fix printing the resource's base flow mode instead of the (potentially overridden) propellant's flow mode when printing propellants in an engine's info panel in the Part Tooltip.
- [**ModuleAnimateGenericCrewModSpawnIVA**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/169) [KSP 1.8.0 - 1.12.5]<br/>Fix IVA & crew portrait not spawning/despawning when ModuleAnimateGeneric is used to change the part crew capacity. Notably affect the stock inflatable airlock.
- [**TimeWarpOrbitShift**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/170) [KSP 1.8.0 - 1.12.5]<br/>Fix active vessel orbit moving randomly when engaging timewarp while under heavy CPU load.

Expand Down

0 comments on commit 691a0f6

Please sign in to comment.