Skip to content

Commit

Permalink
Added Ctrl+arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
18107 committed Apr 24, 2021
1 parent 25c87d2 commit e6dfcb5
Showing 1 changed file with 119 additions and 65 deletions.
184 changes: 119 additions & 65 deletions PulsarPluginLoader/Chat/Extensions/HarmonyHandleChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,108 +51,162 @@ private static bool TagFound(string str, PLNetworkManager networkManager, int po
return tagFound;
}

static void Prefix(PLInGameUI __instance, ref bool ___evenChatString, ref string __state)
private static bool Test(string chatText, char[] match, int pos)
{
PLNetworkManager networkManager = PLNetworkManager.Instance;
if (networkManager.IsTyping)
foreach (char c in match)
{
___evenChatString = false;
__state = networkManager.CurrentChatText;
if (chatText[pos] == c)
{
return true;
}
}
return false;
}

if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
private static int Search(string chatText, char[] match, bool left)
{
int pos = chatText.Length - cursorPos;
bool last;

if (left)
{
pos--;
bool current = Test(chatText, match, pos);
while (pos > 0)
{
if (cursorPos2 == -1)
last = current;
current = Test(chatText, match, pos);
if (current && !last)
{
cursorPos2 = cursorPos;
return chatText.Length - pos - 1;
}
pos--;
}
return chatText.Length;
}
else
{
bool current = Test(chatText, match, pos);
while (pos < chatText.Length)
{
last = current;
current = Test(chatText, match, pos);
if (current && !last)
{
return chatText.Length - pos;
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
pos++;
}
return 0;
}
}

private static void HandleArrows(string chatText)
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
lastTimeLeft = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250;
if (cursorPos < chatText.Length)
{
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
lastTimeLeft = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250;
if (cursorPos < __state.Length)
{
cursorPos++;
}
cursorPos = Search(chatText, new char[] { ' ', '>' }, true);
}
if (Input.GetKeyDown(KeyCode.RightArrow))
else
{
lastTimeRight = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250;
if (cursorPos > 0)
{
cursorPos--;
}
cursorPos++;
}
if (Input.GetKeyDown(KeyCode.Home))
}
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
lastTimeRight = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250;
if (cursorPos > 0)
{
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
cursorPos = __state.Length;
cursorPos = Search(chatText, new char[] { ' ', '<' }, false);
}
if (Input.GetKeyDown(KeyCode.End))
else
{
cursorPos = 0;
cursorPos--;
}
if (Input.GetKey(KeyCode.LeftArrow) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeLeft)
}
}
if (Input.GetKey(KeyCode.LeftArrow) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeLeft)
{
lastTimeLeft += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
if (cursorPos < chatText.Length)
{
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
lastTimeLeft += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
if (cursorPos < __state.Length)
{
cursorPos++;
}
cursorPos = Search(chatText, new char[] { ' ', '>' }, true);
}
if (Input.GetKey(KeyCode.RightArrow) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeRight)
else
{
lastTimeRight += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
if (cursorPos > 0)
{
cursorPos--;
}
cursorPos++;
}
}
else
}
if (Input.GetKey(KeyCode.RightArrow) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeRight)
{
lastTimeRight += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
if (cursorPos > 0)
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
cursorPos2 = -1;
lastTimeLeft = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + 500 /*(SystemInformation.KeyboardDelay + 1) * 250*/;
if (cursorPos < __state.Length)
{
cursorPos++;
}
cursorPos = Search(chatText, new char[] { ' ', '<' }, false);
}
if (Input.GetKeyDown(KeyCode.RightArrow))
else
{
cursorPos2 = -1;
lastTimeRight = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + 500 /*(SystemInformation.KeyboardDelay + 1) * 250*/;
if (cursorPos > 0)
{
cursorPos--;
}
cursorPos--;
}
}
}
}

static void Prefix(PLInGameUI __instance, ref bool ___evenChatString, ref string __state)
{
PLNetworkManager networkManager = PLNetworkManager.Instance;
if (networkManager.IsTyping)
{
___evenChatString = false;
__state = networkManager.CurrentChatText;

if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
if (cursorPos2 == -1)
{
cursorPos2 = cursorPos;
}
HandleArrows(__state);
if (Input.GetKeyDown(KeyCode.Home))
{
cursorPos2 = -1;
cursorPos = __state.Length;
}
if (Input.GetKeyDown(KeyCode.End))
{
cursorPos2 = -1;
cursorPos = 0;
}
if (Input.GetKey(KeyCode.LeftArrow) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeLeft)
}
else
{
if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow) ||
(Input.GetKey(KeyCode.LeftArrow) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeLeft) ||
(Input.GetKey(KeyCode.RightArrow) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeRight))
{
cursorPos2 = -1;
HandleArrows(__state);
}
if (Input.GetKeyDown(KeyCode.Home))
{
cursorPos2 = -1;
lastTimeLeft += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
if (cursorPos < __state.Length)
{
cursorPos++;
}
cursorPos = __state.Length;
}
if (Input.GetKey(KeyCode.RightArrow) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeRight)
if (Input.GetKeyDown(KeyCode.End))
{
cursorPos2 = -1;
lastTimeRight += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/;
if (cursorPos > 0)
{
cursorPos--;
}
cursorPos = 0;
}
}

Expand Down

0 comments on commit e6dfcb5

Please sign in to comment.