Skip to content

Commit f3d292e

Browse files
authored
New ksp bug fix patch : DebugConsoleDontStealInput (#329)
New ksp bug fix patch : DebugConsoleDontStealInput, fix the Alt+F12 console input field stealing input when a console entry is added
1 parent 7c0859f commit f3d292e

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
### Changelog
22

3+
##### 1.39.0
4+
**New/improved patches**
5+
- New KSP bugfix : **DebugConsoleDontStealInput**, fix the Alt+F12 console input field stealing input when a console entry is added.
6+
37
##### 1.38.1
48
**Bug fixes**
59
- **ModuleColorChangerOptimization** : Fixed externally controlled ModuleColorChanger modules state being wrongly reset on startup, notably causing the stock heat shield to start in the charred / black state in the editor.

GameData/KSPCommunityFixes/Settings.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ KSP_COMMUNITY_FIXES
233233
// Fix exception spam when a radiator set to `parentCoolingOnly` is detached from the vessel
234234
ModuleActiveRadiatorNoParentException = true
235235
236+
// Fix the Alt+F12 console input field stealing input when a console entry is added
237+
DebugConsoleDontStealInput = true
238+
236239
// ##########################
237240
// Obsolete bugfixes
238241
// ##########################
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using HarmonyLib;
2+
using KSP.UI.Screens.DebugToolbar;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.Reflection;
6+
using System.Reflection.Emit;
7+
using UnityEngine.EventSystems;
8+
9+
namespace KSPCommunityFixes.BugFixes
10+
{
11+
internal class DebugConsoleDontStealInput : BasePatch
12+
{
13+
protected override void ApplyPatches()
14+
{
15+
AddPatch(PatchType.Transpiler, typeof(DebugScreenConsole), nameof(DebugScreenConsole.OnEnable), nameof(ScrollDownTranspiler));
16+
AddPatch(PatchType.Transpiler, typeof(DebugScreenConsole), nameof(DebugScreenConsole.SubmitCommand), nameof(ScrollDownTranspiler));
17+
AddPatch(PatchType.Transpiler, typeof(DebugScreenConsole), nameof(DebugScreenConsole.OnMemoryLogUpdated), nameof(ScrollDownTranspiler));
18+
}
19+
20+
private static IEnumerable<CodeInstruction> ScrollDownTranspiler(IEnumerable<CodeInstruction> instructions)
21+
{
22+
MethodInfo mScrollDownOriginal = AccessTools.Method(typeof(DebugScreenConsole), nameof(DebugScreenConsole.ScrollDown));
23+
MethodInfo mScrollDownPatched = AccessTools.Method(typeof(DebugConsoleDontStealInput), nameof(ScrollDownPatched));
24+
25+
foreach (CodeInstruction il in instructions)
26+
{
27+
if (il.opcode == OpCodes.Call && ReferenceEquals(il.operand, mScrollDownOriginal))
28+
il.operand = mScrollDownPatched;
29+
30+
yield return il;
31+
}
32+
}
33+
34+
private static IEnumerator ScrollDownPatched(DebugScreenConsole console)
35+
{
36+
yield return null;
37+
38+
if (console.scrollRect != null)
39+
console.scrollRect.verticalNormalizedPosition = 0f;
40+
41+
EventSystem.current.SetSelectedGameObject(console.inputField.gameObject, null);
42+
//console.inputField.OnPointerClick(new PointerEventData(EventSystem.current));
43+
}
44+
}
45+
}

KSPCommunityFixes/KSPCommunityFixes.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<Compile Include="BugFixes\AsteroidInfiniteMining.cs" />
127127
<Compile Include="BugFixes\ChutePhantomSymmetry.cs" />
128128
<Compile Include="BugFixes\CorrectDragForFlags.cs" />
129+
<Compile Include="BugFixes\DebugConsoleDontStealInput.cs" />
129130
<Compile Include="BugFixes\DragCubeLoadException.cs" />
130131
<Compile Include="BugFixes\EVAConstructionMass.cs" />
131132
<Compile Include="BugFixes\InventoryPartMass.cs" />

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ User options are available from the "ESC" in-game settings menu :<br/><img src="
9494
- [**DragCubeLoadException**](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/232) [KSP 1.8.0 - 1.12.5]<br/>Fix loading of drag cubes without a name failing with an IndexOutOfRangeException
9595
- [**TimeWarpBodyCollision**](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/259) [KSP 1.12.0 - 1.12.5]<br/>Fix timewarp rate not always being limited on SOI transistions, sometimes resulting in failure to detect an encounter/collision with the body in the next SOI.
9696
- [**ModuleActiveRadiatorNoParentException**](https://github.com/KSPModdingLibs/KSPCommunityFixes/issues/249) [KSP 1.12.3 - 1.12.5]<br/>Fix exception spam when a radiator set to `parentCoolingOnly` is detached from the vessel
97+
- **DebugConsoleDontStealInput** [KSP 1.12.3 - 1.12.5]<br/>Fix the Alt+F12 console input field stealing input when a console entry is added
9798

9899
#### Quality of Life tweaks
99100

0 commit comments

Comments
 (0)