public override void HandleRPC(object[] arguments, PhotonMessageInfo sender) { if ((int)arguments[1] != version) { Logger.Info($"Recieved invalid version for command list. Expected {version}, got {(int)arguments[1]}"); return; } if ((bool)arguments[0]) { if (PLNetworkManager.Instance.LocalPlayer.GetPhotonPlayer().IsMasterClient) { string[] aliases = GetPublicCommands(); if (aliases.Length <= 1) { return; } string[][][] commandArguments = new string[aliases.Length][][]; for (int i = 0; i < aliases.Length; i++) { commandArguments[i] = ChatCommandRouter.Instance.GetPublicCommand(aliases[i]).Item1.Arguments(); } List <object> o = new List <object>(); o.Add(false); o.Add(version); o.Add(aliases); for (int i = 0; i < aliases.Length; i++) { o.Add(commandArguments[i]); } SendRPC(harmonyIdentifier, handlerIdentifier, sender.sender, o.ToArray()); } } else { if (((string[])arguments[2]).Length > 0) { string[] aliases = (string[])arguments[2]; ChatHelper.publicCommands = new Tuple <string, string[][]> [aliases.Length]; for (int i = 0; i < aliases.Length; i++) { ChatHelper.publicCommands[i] = new Tuple <string, string[][]>(aliases[i], (string[][])arguments[i + 3]); } ChatHelper.publicCached = true; if (PLNetworkManager.Instance.IsTyping && PLNetworkManager.Instance.CurrentChatText.StartsWith("!")) { string chatText = ChatHelper.AutoComplete(PLNetworkManager.Instance.CurrentChatText, ChatHelper.cursorPos); if (chatText != PLNetworkManager.Instance.CurrentChatText) { PLNetworkManager.Instance.CurrentChatText = chatText; ChatHelper.cursorPos2 = -1; } } } } }
private static void DeleteSelected() { ChatHelper.UpdateTypingHistory(currentChatText, false, true); int pos; int length; if (cursorPos < cursorPos2) { pos = currentChatText.Length - cursorPos2; length = cursorPos2 - cursorPos; } else { pos = currentChatText.Length - cursorPos; length = cursorPos - cursorPos2; cursorPos = cursorPos2; } cursorPos2 = -1; currentChatText = currentChatText.Remove(pos, length); }
static void Prefix(PLNetworkManager __instance) { currentChatText = __instance.CurrentChatText; if (__instance.IsTyping) { foreach (char c in Input.inputString) { if (c == "\b"[0]) { if (cursorPos2 != -1 && cursorPos2 != cursorPos) { DeleteSelected(); ChatHelper.UpdateTypingHistory(currentChatText, false, true); } else { if (cursorPos != currentChatText.Length) { ChatHelper.UpdateTypingHistory(currentChatText, false); currentChatText = currentChatText.Remove(currentChatText.Length - cursorPos - 1, 1); } } } else if (c == '\n' || c == '\r') { //Do nothing } else { if (cursorPos2 != -1 && cursorPos2 != cursorPos) { DeleteSelected(); } ChatHelper.UpdateTypingHistory(currentChatText, true); currentChatText = currentChatText.Insert(currentChatText.Length - cursorPos, c.ToString()); } } if (Input.GetKeyDown(KeyCode.Delete)) { lastTimeDelete = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250; if (cursorPos2 != -1 && cursorPos2 != cursorPos) { DeleteSelected(); ChatHelper.UpdateTypingHistory(currentChatText, false, true); } else { ChatHelper.UpdateTypingHistory(currentChatText, false); if (cursorPos > 0) { currentChatText = currentChatText.Remove(currentChatText.Length - cursorPos, 1); cursorPos--; } } } if (Input.GetKey(KeyCode.Delete) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeDelete) { ChatHelper.UpdateTypingHistory(currentChatText, false); lastTimeDelete += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/; if (cursorPos > 0) { currentChatText = currentChatText.Remove(currentChatText.Length - cursorPos, 1); cursorPos--; } } if (Input.GetKeyDown(KeyCode.Tab)) { if (currentChatText.StartsWith("/")) { string chatText = AutoComplete(currentChatText, cursorPos); if (chatText != currentChatText) { ChatHelper.UpdateTypingHistory(currentChatText, true, true); currentChatText = chatText; cursorPos2 = -1; } } else if (currentChatText.StartsWith("!")) { if (publicCached) { string chatText = AutoComplete(currentChatText, cursorPos); if (chatText != currentChatText) { ChatHelper.UpdateTypingHistory(currentChatText, true, true); currentChatText = chatText; cursorPos2 = -1; } } else { HandlePublicCommands.RequestPublicCommands(); } } } } }
static void Postfix(PLNetworkManager __instance) { if (!__instance.IsTyping) { currentHistory = null; return; } if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { if (Input.GetKeyDown(KeyCode.Z)) { lastTimeRedo = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250; ChatHelper.Redo(ref currentChatText); } if (Input.GetKey(KeyCode.Z) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeRedo) { lastTimeRedo += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/; ChatHelper.Redo(ref currentChatText); } } else { if (Input.GetKeyDown(KeyCode.Z)) { lastTimeUndo = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250; ChatHelper.Undo(ref currentChatText); } if (Input.GetKey(KeyCode.Z) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeUndo) { lastTimeUndo += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/; ChatHelper.Undo(ref currentChatText); } } if (Input.GetKeyDown(KeyCode.Y)) { lastTimeRedo = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250; ChatHelper.Redo(ref currentChatText); } if (Input.GetKey(KeyCode.Y) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimeRedo) { lastTimeRedo += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/; ChatHelper.Redo(ref currentChatText); } if (Input.GetKeyDown(KeyCode.V)) { ChatHelper.UpdateTypingHistory(currentChatText, true, true); lastTimePaste = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + /*(SystemInformation.KeyboardDelay + 1) **/ 250; if (cursorPos2 != -1 && cursorPos2 != cursorPos) { DeleteSelected(); } currentChatText = currentChatText.Insert(currentChatText.Length - cursorPos, GUIUtility.systemCopyBuffer); ChatHelper.UpdateTypingHistory(currentChatText, true, true); } if (Input.GetKey(KeyCode.V) && DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond > lastTimePaste) { ChatHelper.UpdateTypingHistory(currentChatText, true, true); lastTimePaste += 30 /*(long)(1 / ((SystemInformation.KeyboardSpeed + 1) * 0.859375))*/; currentChatText = currentChatText.Insert(currentChatText.Length - cursorPos, GUIUtility.systemCopyBuffer); ChatHelper.UpdateTypingHistory(currentChatText, true, true); } if (Input.GetKeyDown(KeyCode.C) && cursorPos2 != -1 && cursorPos2 != cursorPos) { int pos; int length; if (cursorPos < cursorPos2) { pos = currentChatText.Length - cursorPos2; length = cursorPos2 - cursorPos; } else { pos = currentChatText.Length - cursorPos; length = cursorPos - cursorPos2; } GUIUtility.systemCopyBuffer = currentChatText.Substring(pos, length); } if (Input.GetKeyDown(KeyCode.X) && cursorPos2 != -1 && cursorPos2 != cursorPos) { ChatHelper.UpdateTypingHistory(currentChatText, false, true); int pos; int length; if (cursorPos < cursorPos2) { pos = currentChatText.Length - cursorPos2; length = cursorPos2 - cursorPos; } else { pos = currentChatText.Length - cursorPos; length = cursorPos - cursorPos2; } GUIUtility.systemCopyBuffer = currentChatText.Substring(pos, length); DeleteSelected(); ChatHelper.UpdateTypingHistory(currentChatText, false, true); } if (Input.GetKeyDown(KeyCode.A)) { cursorPos = 0; cursorPos2 = currentChatText.Length; } } __instance.CurrentChatText = currentChatText; if (Input.GetKeyDown(KeyCode.UpArrow)) { cursorPos = 0; cursorPos2 = -1; if (currentHistory == null) { ChatHelper.UpdateTypingHistory(currentChatText, true, true); currentHistory = chatHistory.Last; } else { currentHistory = currentHistory.Previous; } SetChat(__instance); } if (Input.GetKeyDown(KeyCode.DownArrow)) { cursorPos = 0; cursorPos2 = -1; if (currentHistory == null) { currentHistory = chatHistory.First; } else { currentHistory = currentHistory.Next; } SetChat(__instance); } }