diff --git a/GameData/KSPCommunityFixes/KSPCommunityFixes.version b/GameData/KSPCommunityFixes/KSPCommunityFixes.version index b47c680..bffda64 100644 --- a/GameData/KSPCommunityFixes/KSPCommunityFixes.version +++ b/GameData/KSPCommunityFixes/KSPCommunityFixes.version @@ -2,7 +2,7 @@ "NAME": "KSPCommunityFixes", "URL": "https://raw.githubusercontent.com/KSPModdingLibs/KSPCommunityFixes/master/GameData/KSPCommunityFixes/KSPCommunityFixes.version", "DOWNLOAD": "https://github.com/KSPModdingLibs/KSPCommunityFixes/releases", - "VERSION": {"MAJOR": 1, "MINOR": 24, "PATCH": 1, "BUILD": 0}, + "VERSION": {"MAJOR": 1, "MINOR": 24, "PATCH": 2, "BUILD": 0}, "KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 5}, "KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 8, "PATCH": 0}, "KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 5} diff --git a/KSPCommunityFixes/Performance/FastLoader.cs b/KSPCommunityFixes/Performance/FastLoader.cs index 3a3cd03..60187c6 100644 --- a/KSPCommunityFixes/Performance/FastLoader.cs +++ b/KSPCommunityFixes/Performance/FastLoader.cs @@ -76,7 +76,7 @@ internal class KSPCFFastLoader : MonoBehaviour private Dictionary textureCacheData; private HashSet textureDataIds; private bool cacheUpdated = false; - + private void Awake() { if (KSPCommunityFixes.KspVersion < new Version(1, 12, 0)) @@ -107,6 +107,11 @@ private void Awake() PatchStartCoroutineInCoroutine(AccessTools.Method(typeof(DragCubeSystem), nameof(DragCubeSystem.SetupDragCubeCoroutine), new[] { typeof(Part) })); PatchStartCoroutineInCoroutine(AccessTools.Method(typeof(DragCubeSystem), nameof(DragCubeSystem.RenderDragCubesCoroutine))); + // Fix for issue #114 : Drag cubes are incorrectly calculated with KSPCF 1.24.1 + MethodInfo m_DragCubeSystem_RenderDragCubes_MoveNext = AccessTools.EnumeratorMoveNext(AccessTools.Method(typeof(DragCubeSystem), nameof(DragCubeSystem.RenderDragCubes))); + MethodInfo m_DragCubeSystem_RenderDragCubes_MoveNext_Transpiler = AccessTools.Method(typeof(KSPCFFastLoader), nameof(DragCubeSystem_RenderDragCubes_MoveNext_Transpiler)); + harmony.Patch(m_DragCubeSystem_RenderDragCubes_MoveNext, null, null, new HarmonyMethod(m_DragCubeSystem_RenderDragCubes_MoveNext_Transpiler)); + configPath = ConfigPath; textureCachePath = Path.Combine(ModPath, "PluginData", "TextureCache"); @@ -1654,8 +1659,9 @@ static IEnumerator FrameUnlockedCoroutine(IEnumerator coroutine) while (moveNext) { - if (Time.realtimeSinceStartup > nextFrameTime) + if (frameSkipRequested || Time.realtimeSinceStartup > nextFrameTime) { + frameSkipRequested = false; nextFrameTime = Time.realtimeSinceStartup + minFrameTime; yield return null; } @@ -1680,6 +1686,28 @@ static IEnumerator FrameUnlockedCoroutine(IEnumerator coroutine) } } + // Fix for issue #114 : Drag cubes are incorrectly calculated with KSPCF 1.24.1 + private static bool frameSkipRequested; + public static void RequestFrameSkip() => frameSkipRequested = true; + + private static IEnumerable DragCubeSystem_RenderDragCubes_MoveNext_Transpiler(IEnumerable instructions) + { + List code = new List(instructions); + MethodInfo m_IMultipleDragCube_AssumeDragCubePosition = AccessTools.Method(typeof(IMultipleDragCube), nameof(IMultipleDragCube.AssumeDragCubePosition)); + MethodInfo m_KSPCFFastLoader_RequestFrameSkip = AccessTools.Method(typeof(KSPCFFastLoader), nameof(RequestFrameSkip)); + + for (int i = 0; i < code.Count; i++) + { + if (code[i].opcode == OpCodes.Callvirt && ReferenceEquals(code[i].operand, m_IMultipleDragCube_AssumeDragCubePosition)) + { + code.Insert(i + 1, new CodeInstruction(OpCodes.Call, m_KSPCFFastLoader_RequestFrameSkip)); + break; + } + } + + return code; + } + #endregion #region PNG texture cache diff --git a/KSPCommunityFixes/Properties/AssemblyInfo.cs b/KSPCommunityFixes/Properties/AssemblyInfo.cs index 0aed4d8..14892c7 100644 --- a/KSPCommunityFixes/Properties/AssemblyInfo.cs +++ b/KSPCommunityFixes/Properties/AssemblyInfo.cs @@ -30,7 +30,7 @@ // Revision // [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.24.1.0")] +[assembly: AssemblyFileVersion("1.24.2.0")] -[assembly: KSPAssembly("KSPCommunityFixes", 1, 24, 1)] +[assembly: KSPAssembly("KSPCommunityFixes", 1, 24, 2)] [assembly: KSPAssemblyDependency("MultipleModulePartAPI", 1, 0, 0)] diff --git a/README.md b/README.md index cce4888..898d15d 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,9 @@ If doing so in the `Debug` configuration and if your KSP install is modified to ### Changelog +##### 1.24.2 +- Fixed [issue #11](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/114) : Drag cubes are incorrectly calculated on modules using `IMultipleDragCube.AssumeDragCubePosition()` due to FastLoader patch not skipping a frame to let the part animation(s) plays + ##### 1.24.1 - Fixed [issue #112](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/112) : Cannot dismiss or disable FastLoader opt-in popup on KSP < 1.12.0