Skip to content

Commit

Permalink
Patch KSPWheel (moved from RP-1)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanKell committed Nov 6, 2023
1 parent cef1b65 commit 374df0e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Source/Harmony/KSPWheel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using HarmonyLib;
using System.Reflection;
using UnityEngine;
using System.Linq;

namespace RealismOverhaul.Harmony
{
[HarmonyPatch]
internal class PatchKSPWheel_KSPWheelDamage_wearUpdateSimple
{
internal static bool Prepare()
{
bool foundKSPWheel = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name.Equals("KSPWheel", System.StringComparison.OrdinalIgnoreCase)) != null;
return foundKSPWheel;
}

internal static MethodBase TargetMethod() => AccessTools.TypeByName("KSPWheel.KSPWheelDamage")?.GetMethod("wearUpdateSimple", AccessTools.all);

[HarmonyPrefix]
internal static bool Prefix_wearUpdateSimple(PartModule __instance, ref float ___load, ref float ___loadStress, ref float ___speed, ref float ___stressTime)
{
if (!HighLogic.LoadedSceneIsFlight)
return true;

if (__instance.vessel == null)
return true;

// We clobber prelaunch just in case there's kraken twitching.
// And we obviously clobber all the other situations
// so we only bail when Landed.
if (__instance.vessel.situation == Vessel.Situations.LANDED)
return true;

// Reset everything
___load = ___loadStress = ___speed = 0f;
// the method does this if load and speed are under limit
___stressTime = Mathf.Max(0f, ___stressTime - Time.fixedDeltaTime);
return false;
}
}
}
1 change: 1 addition & 0 deletions Source/RealismOverhaul.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<Compile Include="Harmony\ModuleEngines.cs" />
<Compile Include="Harmony\KSPUtil.cs" />
<Compile Include="Harmony\FlightGlobals.cs" />
<Compile Include="Harmony\KSPWheel.cs" />
<Compile Include="Harmony\Vessel.cs" />
<Compile Include="Harmony\PartLoader.cs" />
<Compile Include="Harmony\OrbitDriver.cs" />
Expand Down

0 comments on commit 374df0e

Please sign in to comment.