diff --git a/GameData/KSPCommunityFixes/Settings.cfg b/GameData/KSPCommunityFixes/Settings.cfg index c990842..8a93c7c 100644 --- a/GameData/KSPCommunityFixes/Settings.cfg +++ b/GameData/KSPCommunityFixes/Settings.cfg @@ -109,6 +109,9 @@ KSP_COMMUNITY_FIXES // causing loss of vessel effects audio and random volume or left/right channel weirdness. LostSoundAfterSceneSwitch = true + // Fix DoubleCurve flattening the tangents of the first keyframe regardless of whether tangents are supplied. + DoubleCurvePreserveTangents = true + // Fix recovery of EVAing kerbals either causing their inventory to be recovered twice or the // science data they carry not being recovered, depending on the EVA kerbal variant/suit. EVAKerbalRecovery = true diff --git a/KSPCommunityFixes/BugFixes/DoubleCurvePreserveTangents.cs b/KSPCommunityFixes/BugFixes/DoubleCurvePreserveTangents.cs new file mode 100644 index 0000000..6e8fa32 --- /dev/null +++ b/KSPCommunityFixes/BugFixes/DoubleCurvePreserveTangents.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using HarmonyLib; +using System.Reflection.Emit; + +namespace KSPCommunityFixes.BugFixes +{ + class DoubleCurvePreserveTangents : BasePatch + { + protected override Version VersionMin => new Version(1, 8, 0); + + protected override void ApplyPatches(List patches) + { + patches.Add(new PatchInfo( + PatchMethodType.Transpiler, + AccessTools.Method(typeof(DoubleCurve), nameof(DoubleCurve.RecomputeTangents)), + this)); + } + + static IEnumerable DoubleCurve_RecomputeTangents_Transpiler(IEnumerable instructions) + { + // The existing function has a test if ( count == 1 ) and, if true, it + // will flatten the tangents of the key regardless of if it is + // set to autotangent or not. Since the tangents of a single-key + // curve don't matter, let's just make the test always false, + // by making it if ( count == -1 ). + List code = new List(instructions); + for (int i = 1; i < code.Count; ++i) + { + if (code[i].opcode == OpCodes.Ldc_I4_1 && code[i-1].opcode == OpCodes.Ldloc_1) + { + code[i].opcode = OpCodes.Ldc_I4_M1; + break; + } + } + + return code; + } + } +} diff --git a/KSPCommunityFixes/KSPCommunityFixes.csproj b/KSPCommunityFixes/KSPCommunityFixes.csproj index 51b398f..3977fa5 100644 --- a/KSPCommunityFixes/KSPCommunityFixes.csproj +++ b/KSPCommunityFixes/KSPCommunityFixes.csproj @@ -95,6 +95,7 @@ +