ModMessageHelper()
        {
            modMessageHandlers = new Dictionary <string, ModMessage>();
            IEnumerable <PulsarPlugin> pluginList = PluginManager.Instance.GetAllPlugins();

            foreach (PulsarPlugin plugin in pluginList)
            {
                Assembly asm        = plugin.GetType().Assembly;
                Type     modMessage = typeof(ModMessage);
                if (plugin.MPFunctionality > 2)
                {
                    ServerHasMPMods = true;
                }
                foreach (Type t in asm.GetTypes())
                {
                    if (modMessage.IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface)
                    {
                        ModMessage modMessageHandler = (ModMessage)Activator.CreateInstance(t);
                        modMessageHandlers.Add(plugin.HarmonyIdentifier() + "#" + modMessageHandler.GetIdentifier(), modMessageHandler);
                    }
                }
            }
            ModMessage publicCommands = new Chat.Extensions.HandlePublicCommands();

            modMessageHandlers.Add("#" + publicCommands.GetIdentifier(), publicCommands);
        }
Ejemplo n.º 2
0
 public static Tuple <string, string[][]>[] getPublicCommands()
 {
     if (!publicCached)
     {
         HandlePublicCommands.RequestPublicCommands();
         return(new Tuple <string, string[][]> [0]);
     }
     return(publicCommands);
 }
Ejemplo n.º 3
0
 static void Postfix()
 {
     ChatHelper.publicCached = false;
     HandlePublicCommands.RequestPublicCommands();
 }
Ejemplo n.º 4
0
        public static string AutoComplete(string text, int cursorPos)
        {
            if (text[0] != '!' && text[0] != '/')
            {
                return(text);
            }
            bool publicCommand = text[0] == '!';

            if (publicCommand && !publicCached)
            {
                HandlePublicCommands.RequestPublicCommands();
                return(text);
            }
            string[] split = text.Substring(1).Split(' ');

            //Autocomplete command
            if (split.Length == 1 || (split.Length > 1 && cursorPos >= (text.Length - 1) - split[0].Length))
            {
                int    cursor    = cursorPos - (text.Length - 1) + split[0].Length;
                string splitText = split[0];
                string extraText = string.Empty;
                if (cursor > 0)
                {
                    splitText = split[0].Substring(0, split[0].Length - cursor);
                    extraText = split[0].Substring(split[0].Length - cursor);
                }
                string        match = Match(splitText, new string[] { "%command" }, publicCommand);
                StringBuilder sb    = new StringBuilder();
                sb.Append(text[0]);
                sb.Append(match);
                sb.Append(extraText);
                for (int i = 1; i < split.Length; i++)
                {
                    sb.Append(' ');
                    sb.Append(split[i]);
                }
                return(sb.ToString());
            }

            //Autocomplete argument
            else if (split.Length > 1)
            {
                int commandIndex = -1;
                Tuple <string, string[][]>[] t = publicCommand ? getPublicCommands() : getCommands();
                for (int i = 0; i < t.Length; i++)
                {
                    if (t[i].Item1.ToLower() == split[0].ToLower())
                    {
                        commandIndex = i;
                        break;
                    }
                }
                if (commandIndex == -1)
                {
                    return(text);
                }
                string[][] arguments = t[commandIndex].Item2;
                if (arguments == null)
                {
                    return(text);
                }
                int cursor = cursorPos;
                int index  = split.Length - 1;
                while (index > 0)
                {
                    if (cursor > split[index].Length)
                    {
                        cursor -= split[index].Length + 1;
                        index--;
                    }
                    else
                    {
                        break;
                    }
                }
                if (arguments.Length >= index)
                {
                    string splitText = split[index];
                    string extraText = string.Empty;
                    if (cursor > 0)
                    {
                        splitText = split[index].Substring(0, split[index].Length - cursor);
                        extraText = split[index].Substring(split[index].Length - cursor);
                    }
                    string        match = Match(splitText, arguments[index - 1], publicCommand);
                    StringBuilder sb    = new StringBuilder();
                    sb.Append(text[0]);
                    for (int i = 0; i < index; i++)
                    {
                        sb.Append(split[i]);
                        sb.Append(' ');
                    }
                    sb.Append(match);
                    sb.Append(extraText);
                    for (int i = index + 1; i < split.Length; i++)
                    {
                        sb.Append(' ');
                        sb.Append(split[i]);
                    }
                    return(sb.ToString());
                }
                else
                {
                    return(text);
                }
            }
            else
            {
                return(text);
            }
        }
        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();
                        }
                    }
                }
            }
        }