-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix DoubleCurve to no longer flatten the first key's tangent.
- Loading branch information
1 parent
ef6f5d9
commit b97e8e5
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PatchInfo> patches) | ||
{ | ||
patches.Add(new PatchInfo( | ||
PatchMethodType.Transpiler, | ||
AccessTools.Method(typeof(DoubleCurve), nameof(DoubleCurve.RecomputeTangents)), | ||
this)); | ||
} | ||
|
||
static IEnumerable<CodeInstruction> DoubleCurve_RecomputeTangents_Transpiler(IEnumerable<CodeInstruction> 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<CodeInstruction> code = new List<CodeInstruction>(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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters