Skip to content

Commit

Permalink
1.24.2 : Hotfix for issue #114
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmachine committed Jan 30, 2023
1 parent ec1ca4c commit 91a741d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion GameData/KSPCommunityFixes/KSPCommunityFixes.version
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
32 changes: 30 additions & 2 deletions KSPCommunityFixes/Performance/FastLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal class KSPCFFastLoader : MonoBehaviour
private Dictionary<string, CachedTextureInfo> textureCacheData;
private HashSet<uint> textureDataIds;
private bool cacheUpdated = false;

private void Awake()
{
if (KSPCommunityFixes.KspVersion < new Version(1, 12, 0))
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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;
}
Expand All @@ -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<CodeInstruction> DragCubeSystem_RenderDragCubes_MoveNext_Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> code = new List<CodeInstruction>(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
Expand Down
4 changes: 2 additions & 2 deletions KSPCommunityFixes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 91a741d

Please sign in to comment.