Skip to content

Commit 74e731d

Browse files
authored
IMGUITextCursorFix (#7)
1 parent 7828ea0 commit 74e731d

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net35</TargetFramework>
4+
</PropertyGroup>
5+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
using System.Reflection.Emit;
3+
using HarmonyLib;
4+
using UnityEngine;
5+
6+
namespace BepInEx
7+
{
8+
[BepInPlugin(GUID, PluginName, Version)]
9+
public class IMGUITextCursorFix : BaseUnityPlugin
10+
{
11+
public const string GUID = "BepInEx.IMGUITextCursorFix";
12+
public const string PluginName = "IMGUITextCursorFix";
13+
public const string Version = "1.0";
14+
15+
private void Awake()
16+
{
17+
Harmony.CreateAndPatchAll(typeof(Hooks));
18+
}
19+
20+
private static class Hooks
21+
{
22+
// Patch created by jshepler
23+
[HarmonyTranspiler, HarmonyPatch(typeof(TextEditor), "position", MethodType.Setter)]
24+
private static IEnumerable<CodeInstruction> TextEditor_set_position(IEnumerable<CodeInstruction> instructions)
25+
{
26+
var scrollOffset = typeof(TextEditor).GetField("scrollOffset");
27+
28+
var cm = new CodeMatcher(instructions)
29+
.MatchForward(false, new CodeMatch(OpCodes.Stfld, scrollOffset))
30+
.Advance(-1)
31+
.RemoveInstructions(3);
32+
33+
return cm.InstructionEnumeration();
34+
}
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Reflection;
2+
using static BepInEx.IMGUITextCursorFix;
3+
4+
[assembly: AssemblyTitle(GUID)]
5+
[assembly: AssemblyProduct(GUID)]
6+
[assembly: AssemblyDescription(PluginName)]
7+
[assembly: AssemblyVersion(Version)]
8+
[assembly: AssemblyFileVersion(Version)]

BepInEx.Utility.sln

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2626
EndProject
2727
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.ResourceUnloadOptimizations", "BepInEx.ResourceUnloadOptimizations\BepInEx.ResourceUnloadOptimizations.csproj", "{68B7E221-202D-4E4E-BCDB-E138F143B140}"
2828
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.IMGUITextCursorFix", "BepInEx.IMGUITextCursorFix\BepInEx.IMGUITextCursorFix.csproj", "{A9E89941-06A7-4471-AE48-E5E5906FD15E}"
30+
EndProject
2931
Global
3032
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3133
Debug|Any CPU = Debug|Any CPU
@@ -68,6 +70,10 @@ Global
6870
{68B7E221-202D-4E4E-BCDB-E138F143B140}.Debug|Any CPU.Build.0 = Debug|Any CPU
6971
{68B7E221-202D-4E4E-BCDB-E138F143B140}.Release|Any CPU.ActiveCfg = Release|Any CPU
7072
{68B7E221-202D-4E4E-BCDB-E138F143B140}.Release|Any CPU.Build.0 = Release|Any CPU
73+
{A9E89941-06A7-4471-AE48-E5E5906FD15E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
74+
{A9E89941-06A7-4471-AE48-E5E5906FD15E}.Debug|Any CPU.Build.0 = Debug|Any CPU
75+
{A9E89941-06A7-4471-AE48-E5E5906FD15E}.Release|Any CPU.ActiveCfg = Release|Any CPU
76+
{A9E89941-06A7-4471-AE48-E5E5906FD15E}.Release|Any CPU.Build.0 = Release|Any CPU
7177
EndGlobalSection
7278
GlobalSection(SolutionProperties) = preSolution
7379
HideSolutionNode = FALSE

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ Reduce unnecessary GC allocations of Unity's IMGUI (OnGUI) interface system. It
4242

4343
## ResourceUnloadOptimizations
4444
Improves loading times and reduces or eliminates stutter in games that abuse Resources.UnloadUnusedAssets and/or GC.Collect.
45+
46+
## IMGUITextCursorFix
47+
This plugin addresses a bug present in certain Unity versions, starting around version 2019, which locks the IMGUI text box position at the beginning, preventing the cursor from being visible when the text exceeds the display area.

0 commit comments

Comments
 (0)