示例#1
0
        ModMessageHelper()
        {
            modMessageHandlers = new Dictionary <string, ModMessage>();
            IEnumerable <PulsarMod> modList = ModManager.Instance.GetAllMods();

            foreach (PulsarMod mod in modList)
            {
                Assembly asm        = mod.GetType().Assembly;
                Type     modMessage = typeof(ModMessage);
                if (mod.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(mod.HarmonyIdentifier() + "#" + modMessageHandler.GetIdentifier(), modMessageHandler);
                    }
                }
            }
            ModMessage publicCommands = new Chat.Extensions.HandlePublicCommands();

            modMessageHandlers.Add("#" + publicCommands.GetIdentifier(), publicCommands);
        }
示例#2
0
 public static Tuple <string, string[][]>[] getPublicCommands()
 {
     if (!publicCached)
     {
         HandlePublicCommands.RequestPublicCommands();
         return(new Tuple <string, string[][]> [0]);
     }
     return(publicCommands);
 }
示例#3
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);
            }
        }
示例#4
0
 static void Postfix()
 {
     ChatHelper.publicCached = false;
     HandlePublicCommands.RequestPublicCommands();
 }
示例#5
0
        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();
                        }
                    }
                }
            }
        }