Пример #1
0
        internal void RPCSendConsoleMessage(string message, NetworkMessageInfo info)
        {
            if (string.IsNullOrEmpty(message))
            {
                return;
            }
            if (message.Length > 1 && message[0] == '/')
            {
                string command = GadgetConsole.ParseArgs(message.Substring(1))[0];
                if (GadgetConsole.IsCommandExecuteBlacklisted(command))
                {
                    GadgetConsole.Print($"{GadgetNetwork.GetNameByNetworkPlayer(info.sender) ?? GadgetCoreAPI.GetPlayerName()} attempted to force you to execute the blacklisted command: {message}", null, GadgetConsole.MessageSeverity.WARN);
                    return;
                }
            }
            bool isOperator = GadgetConsole.IsOperator(GadgetCoreAPI.GetPlayerName());

            if (isOperator)
            {
                if (message.Length > 1 && message[0] == '/')
                {
                    GadgetConsole.Print($"{GadgetNetwork.GetNameByNetworkPlayer(info.sender) ?? GadgetCoreAPI.GetPlayerName()} forced you to execute the command: {message}");
                }
                else
                {
                    GadgetConsole.Print($"{GadgetNetwork.GetNameByNetworkPlayer(info.sender) ?? GadgetCoreAPI.GetPlayerName()} forced you to say: {message}");
                }
            }
            GadgetConsole.SendConsoleMessage(message, GadgetCoreAPI.GetPlayerName(), isOperator, true);
        }
Пример #2
0
 /// <summary>
 /// Lists all NetworkViews, their IDs, and their names in the console.
 /// </summary>
 public static void ListNetworkViews()
 {
     foreach (NetworkView view in UnityEngine.Object.FindObjectsOfType <NetworkView>().OrderBy(x => x.viewID.ToString()))
     {
         GadgetConsole.Print($"NetworkView ID: ({view.viewID}), Name: ({view.name})", "ListNetworkViews");
     }
 }
Пример #3
0
 internal void RPCSetOp(string name, bool op)
 {
     if (op)
     {
         if (!GadgetConsole.operators.Contains(name))
         {
             GadgetConsole.operators.Add(name);
             if (name == GadgetCoreAPI.GetPlayerName())
             {
                 GadgetConsole.Print("You are now an operator!", null, GadgetConsole.MessageSeverity.INFO);
             }
         }
     }
     else
     {
         if (GadgetConsole.operators.Contains(name))
         {
             GadgetConsole.operators.Remove(name);
             if (name == GadgetCoreAPI.GetPlayerName())
             {
                 GadgetConsole.Print("You are no longer an operator!", null, GadgetConsole.MessageSeverity.WARN);
             }
         }
     }
 }
Пример #4
0
        internal void RPCBroadcastConsoleMessage(int index, string text, string sender, int severity, float sendTime)
        {
            int messageIndex = GadgetConsole.Print(text, sender, (GadgetConsole.MessageSeverity)severity);

            GadgetConsole.GetMessage(messageIndex).SendTime = sendTime;
            broadcastMessageIndices[index] = messageIndex;
        }
Пример #5
0
        public static void Prefix(GameScript __instance, NetworkPlayer pl)
        {
            string name = GadgetNetwork.GetNameByNetworkPlayer(pl);

            if (!string.IsNullOrEmpty(name))
            {
                GadgetConsole.Print($"{name} has left the game.");
            }
        }
Пример #6
0
 internal void RPCReplaceConsoleBroadcast(int index, string text, string sender, int severity, float sendTime)
 {
     index = broadcastMessageIndices[index];
     GadgetConsole.ReplaceMessage(index, new GadgetConsole.GadgetConsoleMessage(text, sender, (GadgetConsole.MessageSeverity)severity));
     if (sendTime >= 0)
     {
         GadgetConsole.GetMessage(index).SendTime = sendTime;
     }
 }
Пример #7
0
 /// <summary>
 /// Logs an error as a line of text into the log file.
 /// </summary>
 public void LogError(object text, bool includeConsole = true)
 {
     if (includeConsole)
     {
         GadgetConsole.Print(text?.ToString() ?? "null", LoggerName, GadgetConsole.MessageSeverity.ERROR);
     }
     foreach (string line in (text?.ToString() ?? "null").Replace('\r', '\n').Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
     {
         streamWriter.WriteLine("[" + DateTime.Now + "]" + (!string.IsNullOrEmpty(LoggerName) ? "[" + LoggerName + "]" : "") + "[Error] " + line);
     }
 }
Пример #8
0
        /// <summary>
        /// Logs a line of text to both the in-game console, as well as the log file.
        /// </summary>
        public void LogConsole(object text, GadgetConsole.MessageSeverity severity = GadgetConsole.MessageSeverity.INFO)
        {
            switch (severity)
            {
            case GadgetConsole.MessageSeverity.WARN:
                LogWarning(text);
                break;

            case GadgetConsole.MessageSeverity.ERROR:
                LogError(text);
                break;

            default:
                GadgetConsole.Print(text?.ToString() ?? "null", LoggerName, severity);
                Log(text);
                break;
            }
        }
Пример #9
0
 internal static void DisableQueuedGadgets()
 {
     Logger.Log("Unloading Gadgets...");
     foreach (GadgetInfo gadget in QueuedGadgets)
     {
         Logger.Log("Unloading Gadget '" + gadget.Attribute.Name + "'");
         gadget.Gadget.UnloadInternal();
         LootTables.RemoveModEntries(gadget.Gadget.ModID);
         GadgetCoreAPI.RemoveModResources(gadget.Gadget.ModID);
         GadgetCoreAPI.UnregisterGadgetRPCs(gadget.Gadget.ModID);
         GadgetCoreAPI.UnregisterStatModifiers(gadget.Gadget.ModID);
         GadgetConsole.UnregisterGadgetCommands(gadget.Gadget.ModID);
         GadgetNetwork.UnregisterSyncVars(gadget.Gadget.ModID);
         PlanetRegistry.UnregisterGadget(gadget.Gadget.ModID);
         DialogChains.UnregisterGadgetChains(gadget.Gadget.ModID);
         foreach (Registry reg in GameRegistry.ListAllRegistries())
         {
             reg.UnregisterGadget(gadget);
         }
     }
     Logger.Log("Done unloading Gadgets.");
     Logger.Log("Unpatching Gadgets...");
     foreach (GadgetInfo gadget in QueuedGadgets.ToList())
     {
         if (gadget.Gadget.HarmonyInstance == null)
         {
             continue;
         }
         Logger.Log("Unpatching Gadget '" + gadget.Attribute.Name + "'");
         try
         {
             gadget.Gadget.HarmonyInstance.UnpatchAll(gadget.Mod.Name + "." + gadget.Attribute.Name + ".gadget");
         }
         catch (Exception e)
         {
             Logger.LogError("Exception Unpatching Gadget '" + gadget.Attribute.Name + "':" + Environment.NewLine + e.ToString());
         }
     }
     Logger.Log("Done unpatching Gadgets.");
     Logger.Log("Sorting Gadgets...");
     Gadgets.SortGadgets();
     Logger.Log("Done sorting Gadgets.");
     QueuedGadgets.Clear();
 }
Пример #10
0
 internal void RPCRemoveConsoleBroadcast(float sendTime)
 {
     GadgetConsole.RemoveMessage(sendTime);
 }
Пример #11
0
 internal void RPCBroadcastConsoleMessage(string text, string sender, int severity, float sendTime)
 {
     GadgetConsole.GetMessage(GadgetConsole.Print(text, sender, (GadgetConsole.MessageSeverity)severity)).SendTime = sendTime;
 }
Пример #12
0
        private static void BuildPersistantCanvas()
        {
            GadgetCore.CoreLogger.Log("Building Persistant Canvas");
            EventSystem eventSystem = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule)).GetComponent <EventSystem>();

            UnityEngine.Object.DontDestroyOnLoad(eventSystem.gameObject);
            StandaloneInputModule inputModule = eventSystem.GetComponent <StandaloneInputModule>();

            inputModule.horizontalAxis = "Horizontal1";
            inputModule.verticalAxis   = "Vertical1";
            inputModule.submitButton   = "Jump";
            inputModule.cancelButton   = "Cancel";

            PersistantCanvas = new GameObject("Persistant Canvas", typeof(RectTransform), typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster), typeof(CanvasGroup)).GetComponent <Canvas>();
            UnityEngine.Object.DontDestroyOnLoad(PersistantCanvas.gameObject);
            PersistantCanvas.GetComponent <CanvasGroup>().alpha          = 1;
            PersistantCanvas.GetComponent <CanvasGroup>().interactable   = true;
            PersistantCanvas.GetComponent <CanvasGroup>().blocksRaycasts = true;
            PersistantCanvas.GetComponent <RectTransform>().pivot        = new Vector2(0.5f, 0.5f);
            PersistantCanvas.sortingOrder = 100;
            PersistantCanvas.renderMode   = RenderMode.ScreenSpaceOverlay;
            PersistantCanvas.pixelPerfect = true;
            CanvasScaler scaler = PersistantCanvas.GetComponent <CanvasScaler>();

            scaler.uiScaleMode            = CanvasScaler.ScaleMode.ConstantPixelSize;
            scaler.referencePixelsPerUnit = 100;

            GadgetConsole console = new GameObject("Console", typeof(RectTransform), typeof(GadgetConsole)).GetComponent <GadgetConsole>();

            console.gameObject.SetActive(false);
            console.transform.SetParent(PersistantCanvas.transform);
            console.GetComponent <RectTransform>().anchorMin = new Vector2(0f, 0f);
            console.GetComponent <RectTransform>().anchorMax = new Vector2(1f, 1f);
            console.GetComponent <RectTransform>().offsetMin = new Vector2(10f, 10f);
            console.GetComponent <RectTransform>().offsetMax = new Vector2(-10f, -10f);
            console.InputField = new GameObject("Input Field", typeof(RectTransform), typeof(InputField), typeof(CanvasRenderer), typeof(Image)).GetComponent <InputField>();
            console.InputField.GetComponent <RectTransform>().SetParent(console.transform);
            console.InputField.GetComponent <RectTransform>().anchorMin = new Vector2(0.1f, 0.1f);
            console.InputField.GetComponent <RectTransform>().anchorMax = new Vector2(0.9f, 0.1f);
            console.InputField.GetComponent <RectTransform>().offsetMin = new Vector2(0f, 0f);
            console.InputField.GetComponent <RectTransform>().offsetMax = new Vector2(0f, 50f);
            console.InputField.GetComponent <Image>().sprite            = BoxSprite;
            console.InputField.GetComponent <Image>().type       = Image.Type.Sliced;
            console.InputField.GetComponent <Image>().fillCenter = true;
            Text inputText = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();

            inputText.rectTransform.SetParent(console.InputField.transform);
            inputText.rectTransform.anchorMin = new Vector2(0f, 0f);
            inputText.rectTransform.anchorMax = new Vector2(1f, 1f);
            inputText.rectTransform.offsetMin = new Vector2(10f, 0f);
            inputText.rectTransform.offsetMax = new Vector2(-10f, 0f);
            inputText.alignment          = TextAnchor.MiddleLeft;
            inputText.horizontalOverflow = HorizontalWrapMode.Overflow;
            inputText.font     = ModMenuPanel.descText.font;
            inputText.fontSize = 24;
            console.InputField.textComponent = inputText;

            ScrollRect scrollableChat = new GameObject("Scrollable Chat", typeof(RectTransform), typeof(ScrollRect)).GetComponent <ScrollRect>();

            scrollableChat.GetComponent <RectTransform>().SetParent(console.transform);
            scrollableChat.GetComponent <RectTransform>().anchorMin = new Vector2(0.1f, 0.1f);
            scrollableChat.GetComponent <RectTransform>().anchorMax = new Vector2(0.9f, 1f);
            scrollableChat.GetComponent <RectTransform>().offsetMin = new Vector2(0f, 50f);
            scrollableChat.GetComponent <RectTransform>().offsetMax = new Vector2(0f, 0f);
            scrollableChat.GetComponent <RectTransform>().pivot     = new Vector2(0.5f, 0.5f);
            scrollableChat.inertia                     = false;
            scrollableChat.horizontal                  = false;
            scrollableChat.scrollSensitivity           = 5;
            scrollableChat.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
            scrollableChat.movementType                = ScrollRect.MovementType.Clamped;
            Scrollbar chatScrollBar = new GameObject("Scrollbar", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Scrollbar)).GetComponent <Scrollbar>();

            chatScrollBar.GetComponent <RectTransform>().SetParent(console.transform);
            chatScrollBar.GetComponent <RectTransform>().anchorMin = new Vector2(1f, 0.1f);
            chatScrollBar.GetComponent <RectTransform>().anchorMax = new Vector2(1f, 1f);
            chatScrollBar.GetComponent <RectTransform>().offsetMin = new Vector2(-50f, 0f);
            chatScrollBar.GetComponent <RectTransform>().offsetMax = new Vector2(0f, 0f);
            chatScrollBar.GetComponent <Image>().sprite            = BoxSprite;
            chatScrollBar.GetComponent <Image>().type       = Image.Type.Sliced;
            chatScrollBar.GetComponent <Image>().fillCenter = true;
            RectTransform charScrollBarHandle = new GameObject("Handle", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image)).GetComponent <RectTransform>();

            charScrollBarHandle.SetParent(chatScrollBar.transform);
            charScrollBarHandle.anchorMin = new Vector2(0.05f, 0.05f);
            charScrollBarHandle.anchorMax = new Vector2(0.95f, 0.95f);
            charScrollBarHandle.offsetMin = Vector2.zero;
            charScrollBarHandle.offsetMax = Vector2.zero;
            charScrollBarHandle.GetComponent <Image>().sprite     = BoxSprite;
            charScrollBarHandle.GetComponent <Image>().type       = Image.Type.Sliced;
            charScrollBarHandle.GetComponent <Image>().fillCenter = true;
            chatScrollBar.targetGraphic = charScrollBarHandle.GetComponent <Image>();
            chatScrollBar.handleRect    = charScrollBarHandle;
            chatScrollBar.direction     = Scrollbar.Direction.BottomToTop;
            Mask chatViewport = new GameObject("Viewport", typeof(RectTransform), typeof(Mask), typeof(CanvasRenderer), typeof(Image)).GetComponent <Mask>();

            chatViewport.rectTransform.SetParent(scrollableChat.transform);
            chatViewport.rectTransform.anchorMin           = new Vector2(0f, 0f);
            chatViewport.rectTransform.anchorMax           = new Vector2(1f, 1f);
            chatViewport.rectTransform.offsetMin           = new Vector2(0f, 0f);
            chatViewport.rectTransform.offsetMax           = new Vector2(0f, 0f);
            chatViewport.rectTransform.pivot               = Vector2.zero;
            chatViewport.showMaskGraphic                   = false;
            chatViewport.GetComponent <Image>().sprite     = BoxSprite;
            chatViewport.GetComponent <Image>().type       = Image.Type.Sliced;
            chatViewport.GetComponent <Image>().fillCenter = true;
            console.TextPanel = new GameObject("Content", typeof(RectTransform), typeof(VerticalLayoutGroup), typeof(ContentSizeFitter)).GetComponent <RectTransform>();
            console.TextPanel.SetParent(chatViewport.rectTransform);
            console.TextPanel.anchorMin = new Vector2(0f, 0f);
            console.TextPanel.anchorMax = new Vector2(1f, 1f);
            console.TextPanel.offsetMin = new Vector2(0f, 0f);
            console.TextPanel.offsetMax = new Vector2(0f, 0f);
            console.TextPanel.pivot     = Vector2.zero;
            console.TextPanel.GetComponent <VerticalLayoutGroup>().padding                = new RectOffset(10, 10, 10, 10);
            console.TextPanel.GetComponent <VerticalLayoutGroup>().spacing                = 10;
            console.TextPanel.GetComponent <VerticalLayoutGroup>().childAlignment         = TextAnchor.LowerLeft;
            console.TextPanel.GetComponent <VerticalLayoutGroup>().childControlWidth      = true;
            console.TextPanel.GetComponent <VerticalLayoutGroup>().childControlHeight     = true;
            console.TextPanel.GetComponent <VerticalLayoutGroup>().childForceExpandWidth  = true;
            console.TextPanel.GetComponent <VerticalLayoutGroup>().childForceExpandHeight = true;
            console.TextPanel.GetComponent <ContentSizeFitter>().horizontalFit            = ContentSizeFitter.FitMode.Unconstrained;
            console.TextPanel.GetComponent <ContentSizeFitter>().verticalFit              = ContentSizeFitter.FitMode.PreferredSize;
            scrollableChat.verticalScrollbar = chatScrollBar;
            scrollableChat.viewport          = chatViewport.rectTransform;
            scrollableChat.content           = console.TextPanel;
            console.AlwaysActivePanel        = new GameObject("Always Active Content", typeof(RectTransform), typeof(VerticalLayoutGroup), typeof(ContentSizeFitter)).GetComponent <RectTransform>();
            console.AlwaysActivePanel.SetParent(PersistantCanvas.transform);
            console.AlwaysActivePanel.anchorMin = new Vector2(0.1f, 0.1f);
            console.AlwaysActivePanel.anchorMax = new Vector2(0.9f, 1f);
            console.AlwaysActivePanel.offsetMin = new Vector2(10f, 60f);
            console.AlwaysActivePanel.offsetMax = new Vector2(-10f, -10f);
            console.AlwaysActivePanel.pivot     = Vector2.zero;
            console.AlwaysActivePanel.GetComponent <VerticalLayoutGroup>().padding                = new RectOffset(10, 10, 10, 10);
            console.AlwaysActivePanel.GetComponent <VerticalLayoutGroup>().spacing                = 10;
            console.AlwaysActivePanel.GetComponent <VerticalLayoutGroup>().childAlignment         = TextAnchor.LowerLeft;
            console.AlwaysActivePanel.GetComponent <VerticalLayoutGroup>().childControlWidth      = true;
            console.AlwaysActivePanel.GetComponent <VerticalLayoutGroup>().childControlHeight     = true;
            console.AlwaysActivePanel.GetComponent <VerticalLayoutGroup>().childForceExpandWidth  = true;
            console.AlwaysActivePanel.GetComponent <VerticalLayoutGroup>().childForceExpandHeight = true;
            console.AlwaysActivePanel.GetComponent <ContentSizeFitter>().horizontalFit            = ContentSizeFitter.FitMode.Unconstrained;
            console.AlwaysActivePanel.GetComponent <ContentSizeFitter>().verticalFit              = ContentSizeFitter.FitMode.PreferredSize;

            GadgetConsole.PrintQueuedMessages();

            ConfirmationDialog = new GameObject("Confirmation Dialog", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image));
            ConfirmationDialog.GetComponent <RectTransform>().SetParent(PersistantCanvas.transform);
            ConfirmationDialog.GetComponent <RectTransform>().anchorMin = new Vector2(0.25f, 0.25f);
            ConfirmationDialog.GetComponent <RectTransform>().anchorMax = new Vector2(0.75f, 0.75f);
            ConfirmationDialog.GetComponent <RectTransform>().offsetMin = new Vector2(10, 10);
            ConfirmationDialog.GetComponent <RectTransform>().offsetMax = new Vector2(-10, -10);
            ConfirmationDialog.GetComponent <Image>().sprite            = BoxSprite;
            ConfirmationDialog.GetComponent <Image>().type       = Image.Type.Sliced;
            ConfirmationDialog.GetComponent <Image>().fillCenter = true;
            ConfirmationDialog.SetActive(false);
            Button yesButton = new GameObject("Yes Button", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button)).GetComponent <Button>();

            yesButton.GetComponent <RectTransform>().SetParent(ConfirmationDialog.transform);
            yesButton.GetComponent <RectTransform>().anchorMin = new Vector2(0f, 0f);
            yesButton.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 0.25f);
            yesButton.GetComponent <RectTransform>().offsetMin = new Vector2(10, 10);
            yesButton.GetComponent <RectTransform>().offsetMax = new Vector2(-10, -10);
            yesButton.GetComponent <Image>().sprite            = BoxSprite;
            yesButton.GetComponent <Image>().type       = Image.Type.Sliced;
            yesButton.GetComponent <Image>().fillCenter = true;
            yesButton.targetGraphic = yesButton.GetComponent <Image>();
            ConfirmationYesText     = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();
            ConfirmationYesText.rectTransform.SetParent(yesButton.transform);
            ConfirmationYesText.rectTransform.anchorMin = new Vector2(0f, 0f);
            ConfirmationYesText.rectTransform.anchorMax = new Vector2(1f, 1f);
            ConfirmationYesText.rectTransform.offsetMin = Vector2.zero;
            ConfirmationYesText.rectTransform.offsetMax = Vector2.zero;
            ConfirmationYesText.alignment = TextAnchor.MiddleCenter;
            ConfirmationYesText.font      = ModMenuPanel.descText.font;
            ConfirmationYesText.fontSize  = 24;
            ConfirmationYesText.text      = "Yes";
            Button noButton = new GameObject("No Button", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button)).GetComponent <Button>();

            noButton.GetComponent <RectTransform>().SetParent(ConfirmationDialog.transform);
            noButton.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 0f);
            noButton.GetComponent <RectTransform>().anchorMax = new Vector2(1f, 0.25f);
            noButton.GetComponent <RectTransform>().offsetMin = new Vector2(10, 10);
            noButton.GetComponent <RectTransform>().offsetMax = new Vector2(-10, -10);
            noButton.GetComponent <Image>().sprite            = BoxSprite;
            noButton.GetComponent <Image>().type       = Image.Type.Sliced;
            noButton.GetComponent <Image>().fillCenter = true;
            noButton.targetGraphic = noButton.GetComponent <Image>();
            ConfirmationNoText     = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();
            ConfirmationNoText.rectTransform.SetParent(noButton.transform);
            ConfirmationNoText.rectTransform.anchorMin = new Vector2(0f, 0f);
            ConfirmationNoText.rectTransform.anchorMax = new Vector2(1f, 1f);
            ConfirmationNoText.rectTransform.offsetMin = Vector2.zero;
            ConfirmationNoText.rectTransform.offsetMax = Vector2.zero;
            ConfirmationNoText.alignment = TextAnchor.MiddleCenter;
            ConfirmationNoText.font      = ModMenuPanel.descText.font;
            ConfirmationNoText.fontSize  = 24;
            ConfirmationNoText.text      = "No";
            yesButton.onClick.AddListener(() => {
                GadgetCoreAPI.CloseDialog();
                ConfirmationYesAction?.Invoke();
            });
            noButton.onClick.AddListener(() => {
                GadgetCoreAPI.CloseDialog();
                ConfirmationNoAction?.Invoke();
            });
            ConfirmationText = new GameObject("Text", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent <Text>();
            ConfirmationText.rectTransform.SetParent(ConfirmationDialog.transform);
            ConfirmationText.rectTransform.anchorMin = new Vector2(0f, 0.25f);
            ConfirmationText.rectTransform.anchorMax = new Vector2(1f, 1f);
            ConfirmationText.rectTransform.offsetMin = Vector2.zero;
            ConfirmationText.rectTransform.offsetMax = Vector2.zero;
            ConfirmationText.alignment = TextAnchor.MiddleCenter;
            ConfirmationText.font      = ModMenuPanel.descText.font;
            ConfirmationText.fontSize  = 24;
            ConfirmationText.text      = "";
        }
Пример #13
0
        public static void Prefix(PlayerScript __instance, ref string n)
        {
            PlayerScript existingPlayer = null;
            bool         isSelf         = n == Menuu.curName;

            if (isSelf)
            {
                existingPlayer = GadgetCoreAPI.GetPlayerByName(n);
                if (existingPlayer != null && existingPlayer != __instance)
                {
                    existingPlayer.GetComponent <NetworkView>().RPC("SetName", RPCMode.AllBuffered, new object[]
                    {
                        n + "-1"
                    });
                    foreach (KeyValuePair <string, PlayerScript> entry in GadgetCoreAPI.playersByName.Where(x => x.Value == existingPlayer).ToList())
                    {
                        GadgetCoreAPI.playersByName.Remove(entry.Key);
                        GadgetNetwork.NetworkPlayersByName.Remove(entry.Key);
                        GadgetNetwork.NamesByNetworkPlayer.Remove(entry.Value.GetComponent <NetworkView>().owner);
                    }
                    if (InstanceTracker.PlayerScript == __instance)
                    {
                        GadgetCoreAPI.playerName = n + "-1";
                    }
                    GadgetCoreAPI.playersByName[n + "-1"]        = existingPlayer;
                    GadgetNetwork.NetworkPlayersByName[n + "-1"] = existingPlayer.GetComponent <NetworkView>().owner;
                    GadgetNetwork.NamesByNetworkPlayer[existingPlayer.GetComponent <NetworkView>().owner] = n + "-1";
                }
            }
            else
            {
                bool wasOp = false;
                foreach (KeyValuePair <string, PlayerScript> entry in GadgetCoreAPI.playersByName.Where(x => x.Value == __instance).ToList())
                {
                    if (GadgetConsole.operators.Contains(entry.Key))
                    {
                        GadgetConsole.operators.Remove(entry.Key);
                        wasOp = true;
                    }
                }
                if (wasOp)
                {
                    GadgetConsole.operators.Add(n);
                }
            }
            if (existingPlayer == null)
            {
                existingPlayer = GadgetCoreAPI.GetPlayerByName(n + "-1");
            }
            if (existingPlayer != null && existingPlayer != __instance)
            {
                int num = 2;
                while (GadgetCoreAPI.GetPlayerByName(n + "-" + num) != null)
                {
                    num++;
                }
                n = n + "-" + num;
            }
            else
            {
                existingPlayer = __instance;
            }
            foreach (KeyValuePair <string, PlayerScript> entry in GadgetCoreAPI.playersByName.Where(x => x.Value == __instance).ToList())
            {
                GadgetCoreAPI.playersByName.Remove(entry.Key);
                GadgetNetwork.NetworkPlayersByName.Remove(entry.Key);
                GadgetNetwork.NamesByNetworkPlayer.Remove(entry.Value.GetComponent <NetworkView>().owner);
            }
            if (InstanceTracker.PlayerScript == __instance)
            {
                GadgetCoreAPI.playerName = n;
            }
            GadgetCoreAPI.playersByName[n]        = __instance;
            GadgetNetwork.NetworkPlayersByName[n] = existingPlayer.GetComponent <NetworkView>().owner;
            GadgetNetwork.NamesByNetworkPlayer[existingPlayer.GetComponent <NetworkView>().owner] = n;
            if (__instance.GetComponent <NetworkView>().owner == RPCHooks.Singleton.GetComponent <NetworkView>().owner)
            {
                GadgetNetwork.ServerPlayerName = n;
            }
            if (!isSelf)
            {
                GadgetConsole.Print($"{n} has joined the game.");
            }
        }