diff --git a/Source/Harmony/KSPWheel.cs b/Source/Harmony/KSPWheel.cs new file mode 100644 index 0000000000..a2156c0d81 --- /dev/null +++ b/Source/Harmony/KSPWheel.cs @@ -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; + } + } +} diff --git a/Source/RealismOverhaul.csproj b/Source/RealismOverhaul.csproj index db2c6ae5cb..8074603aa7 100644 --- a/Source/RealismOverhaul.csproj +++ b/Source/RealismOverhaul.csproj @@ -40,6 +40,7 @@ +