Skip to content

Commit

Permalink
IMGUITextCursorFix (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keelhauled authored Aug 8, 2024
1 parent 7828ea0 commit 74e731d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions BepInEx.IMGUITextCursorFix/BepInEx.IMGUITextCursorFix.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net35</TargetFramework>
</PropertyGroup>
</Project>
37 changes: 37 additions & 0 deletions BepInEx.IMGUITextCursorFix/IMGUITextCursorFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using System.Reflection.Emit;
using HarmonyLib;
using UnityEngine;

namespace BepInEx
{
[BepInPlugin(GUID, PluginName, Version)]
public class IMGUITextCursorFix : BaseUnityPlugin
{
public const string GUID = "BepInEx.IMGUITextCursorFix";
public const string PluginName = "IMGUITextCursorFix";
public const string Version = "1.0";

private void Awake()
{
Harmony.CreateAndPatchAll(typeof(Hooks));
}

private static class Hooks
{
// Patch created by jshepler
[HarmonyTranspiler, HarmonyPatch(typeof(TextEditor), "position", MethodType.Setter)]
private static IEnumerable<CodeInstruction> TextEditor_set_position(IEnumerable<CodeInstruction> instructions)
{
var scrollOffset = typeof(TextEditor).GetField("scrollOffset");

var cm = new CodeMatcher(instructions)
.MatchForward(false, new CodeMatch(OpCodes.Stfld, scrollOffset))
.Advance(-1)
.RemoveInstructions(3);

return cm.InstructionEnumeration();
}
}
}
}
8 changes: 8 additions & 0 deletions BepInEx.IMGUITextCursorFix/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Reflection;
using static BepInEx.IMGUITextCursorFix;

[assembly: AssemblyTitle(GUID)]
[assembly: AssemblyProduct(GUID)]
[assembly: AssemblyDescription(PluginName)]
[assembly: AssemblyVersion(Version)]
[assembly: AssemblyFileVersion(Version)]
6 changes: 6 additions & 0 deletions BepInEx.Utility.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.ResourceUnloadOptimizations", "BepInEx.ResourceUnloadOptimizations\BepInEx.ResourceUnloadOptimizations.csproj", "{68B7E221-202D-4E4E-BCDB-E138F143B140}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx.IMGUITextCursorFix", "BepInEx.IMGUITextCursorFix\BepInEx.IMGUITextCursorFix.csproj", "{A9E89941-06A7-4471-AE48-E5E5906FD15E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -68,6 +70,10 @@ Global
{68B7E221-202D-4E4E-BCDB-E138F143B140}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68B7E221-202D-4E4E-BCDB-E138F143B140}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68B7E221-202D-4E4E-BCDB-E138F143B140}.Release|Any CPU.Build.0 = Release|Any CPU
{A9E89941-06A7-4471-AE48-E5E5906FD15E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A9E89941-06A7-4471-AE48-E5E5906FD15E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A9E89941-06A7-4471-AE48-E5E5906FD15E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A9E89941-06A7-4471-AE48-E5E5906FD15E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ Reduce unnecessary GC allocations of Unity's IMGUI (OnGUI) interface system. It

## ResourceUnloadOptimizations
Improves loading times and reduces or eliminates stutter in games that abuse Resources.UnloadUnusedAssets and/or GC.Collect.

## IMGUITextCursorFix
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 comments on commit 74e731d

Please sign in to comment.