コード例 #1
0
ファイル: GenericPatches.cs プロジェクト: XtraCube/CrowdedMod
            public static void Postfix(CreateOptionsPicker __instance)
            {
                var offset = __instance.MaxPlayerButtons[1].transform.position.x -
                             __instance.MaxPlayerButtons[0].transform.position.x;
                var playerButtons = __instance.MaxPlayerButtons.ToList();

                var plusButton = Object.Instantiate(playerButtons.Last(), playerButtons.Last().transform.parent);

                plusButton.GetComponentInChildren <TextRenderer>().Text = "+";
                plusButton.name = "255";
                plusButton.transform.position = playerButtons.Last().transform.position + new Vector3(offset * 2, 0, 0);
                var passiveButton = plusButton.GetComponent <PassiveButton>();

                passiveButton.OnClick.m_PersistentCalls.Clear();
                passiveButton.OnClick.AddListener((UnityAction)plusListener);
                void plusListener()
                {
                    var targetOptions = __instance.GetTargetOptions();

                    targetOptions.MaxPlayers = Mathf.Clamp(targetOptions.MaxPlayers + 1, 4, 20);
                    plusButton.name          = targetOptions.MaxPlayers.ToString();
                    __instance.SetMaxPlayersButtons(targetOptions.MaxPlayers);
                }

                var minusButton = Object.Instantiate(playerButtons.Last(), playerButtons.Last().transform.parent);

                minusButton.GetComponentInChildren <TextRenderer>().Text = "-";
                minusButton.name = "255";
                minusButton.transform.position = playerButtons.First().transform.position;
                var minusPassiveButton = minusButton.GetComponent <PassiveButton>();

                minusPassiveButton.OnClick.m_PersistentCalls.Clear();
                minusPassiveButton.OnClick.AddListener((UnityAction)listener);
                void listener()
                {
                    var targetOptions = __instance.GetTargetOptions();

                    targetOptions.MaxPlayers = Mathf.Clamp(targetOptions.MaxPlayers - 1, 4, 20);
                    minusButton.name         = targetOptions.MaxPlayers.ToString();
                    __instance.SetMaxPlayersButtons(targetOptions.MaxPlayers);
                }

                playerButtons.ForEach(x => x.transform.position += new Vector3(offset, 0, 0));
                playerButtons.Insert(0, minusButton);
                playerButtons.Add(plusButton);
                __instance.MaxPlayerButtons = playerButtons.ToArray();
            }
コード例 #2
0
            public static void Postfix(CreateOptionsPicker __instance)
            {
                List <SpriteRenderer> maxPlayerButtons = __instance.MaxPlayerButtons.ToList();

                if (maxPlayerButtons == null || maxPlayerButtons.Count <= 2)
                {
                    return;
                }
                additionalButtons = new List <SpriteRenderer>();

                for (int i = 1; i < 6; i++)
                {
                    SpriteRenderer nextButton = Object.Instantiate(maxPlayerButtons.Last(), maxPlayerButtons.Last().transform.parent);
                    additionalButtons.Add(nextButton);
                    nextButton.enabled         = false;
                    nextButton.gameObject.name = "1" + i;
                    TMPro.TMP_Text text = nextButton.gameObject.GetComponentInChildren <TMPro.TMP_Text>();
                    text.text  = "1" + i;
                    text.color = Helpers.isCustomServer() ? Color.white : Palette.EGHCBLDNCGP;

                    nextButton.transform.position = nextButton.transform.position + new Vector3(i * (maxPlayerButtons[1].transform.position.x - maxPlayerButtons[0].transform.position.x), 0, 0);
                    var passiveButton = nextButton.GetComponent <PassiveButton>();
                    passiveButton.OnClick.RemoveAllListeners();

                    void onClick()
                    {
                        bool isCustom = Helpers.isCustomServer();

                        foreach (SpriteRenderer renderer in additionalButtons)
                        {
                            if (renderer != null && renderer.gameObject != null)
                            {
                                renderer.enabled = false;
                                renderer.gameObject.GetComponentInChildren <TMPro.TMP_Text>().color = isCustom ? Color.white : Palette.EGHCBLDNCGP;
                            }
                        }

                        if (!isCustom)
                        {
                            return;
                        }

                        nextButton.enabled = true;

                        byte value         = byte.Parse(nextButton.name);
                        var  targetOptions = __instance.GetTargetOptions();

                        if (value <= targetOptions.DIGMGCJMGDB)
                        {
                            targetOptions.DIGMGCJMGDB = value - 1;
                            __instance.SetImpostorButtons(targetOptions.DIGMGCJMGDB);
                        }
                        __instance.SetMaxPlayersButtons(value);
                    }

                    passiveButton.OnClick.AddListener((UnityEngine.Events.UnityAction)onClick);
                }
            }
コード例 #3
0
            public static void Postfix(CreateOptionsPicker __instance)
            {
                if (__instance.mode != SettingsMode.Host)
                {
                    return;
                }
                var offset = __instance.MaxPlayerButtons[1].transform.position.x - __instance.MaxPlayerButtons[0].transform.position.x;

                #region MaxPlayers stuff

                List <SpriteRenderer> playerButtons = __instance.MaxPlayerButtons.ToList();

                SpriteRenderer plusButton = Object.Instantiate(playerButtons.Last(), playerButtons.Last().transform.parent);
                plusButton.GetComponentInChildren <TextMeshPro>().text = "+";
                plusButton.name = "255";
                plusButton.transform.position = playerButtons.Last().transform.position + new Vector3(offset * 2, 0, 0);
                var passiveButton = plusButton.GetComponent <PassiveButton>();
                passiveButton.OnClick.RemoveAllListeners();
                passiveButton.OnClick.AddListener((UnityAction)plusListener);

                void plusListener()
                {
                    byte curHighest = byte.Parse(playerButtons[__instance.MaxPlayerButtons.Length - 2].name);
                    int  delta      = Mathf.Clamp(curHighest + 7, curHighest, maxPlayers) - curHighest;

                    if (delta == 0)
                    {
                        return;             // fast skip
                    }
                    for (byte i = 1; i < 8; i++)
                    {
                        SpriteRenderer button = __instance.MaxPlayerButtons[i];
                        button.name =
                            button.GetComponentInChildren <TextMeshPro>().text =
                                (byte.Parse(button.name) + delta).ToString();
                    }
                    __instance.SetMaxPlayersButtons(__instance.GetTargetOptions().MaxPlayers);
                }

                SpriteRenderer minusButton = Object.Instantiate(playerButtons.Last(), playerButtons.Last().transform.parent);
                minusButton.GetComponentInChildren <TextMeshPro>().text = "-";
                minusButton.name = "255";
                minusButton.transform.position = playerButtons.First().transform.position;
                var minusPassiveButton = minusButton.GetComponent <PassiveButton>();
                minusPassiveButton.OnClick.RemoveAllListeners();
                minusPassiveButton.OnClick.AddListener((UnityAction)minusListener);

                void minusListener()
                {
                    byte curLowest = byte.Parse(playerButtons[1].name);
                    int  delta     = curLowest - Mathf.Clamp(curLowest - 7, 4, curLowest);

                    if (delta == 0)
                    {
                        return;             // fast skip
                    }
                    for (byte i = 1; i < 8; i++)
                    {
                        SpriteRenderer button = __instance.MaxPlayerButtons[i];
                        button.name =
                            button.GetComponentInChildren <TextMeshPro>().text =
                                (byte.Parse(button.name) - delta).ToString();
                    }
                    __instance.SetMaxPlayersButtons(__instance.GetTargetOptions().MaxPlayers);
                }

                playerButtons.ForEach(b =>
                {
                    var button = b.GetComponent <PassiveButton>();
                    button.OnClick.RemoveAllListeners();
                    void defaultListener()
                    {
                        byte value        = byte.Parse(button.name);
                        var targetOptions = __instance.GetTargetOptions();
                        if (value <= targetOptions.NumImpostors)
                        {
                            targetOptions.NumImpostors = value - 1;
                            __instance.UpdateImpostorsButtons(targetOptions.NumImpostors);
                        }
                        __instance.SetMaxPlayersButtons(value);
                    }
                    button.OnClick.AddListener((UnityAction)defaultListener);
                    button.transform.position += new Vector3(offset, 0, 0);
                });

                playerButtons.Insert(0, minusButton);
                playerButtons.Add(plusButton);
                __instance.MaxPlayerButtons = playerButtons.ToArray();

                #endregion

                #region Impostor stuff

                var impostorButtons = __instance.ImpostorButtons.ToList();

                for (byte i = 4; i < 11; i++)
                {
                    SpriteRenderer button = Object.Instantiate(impostorButtons.Last(), impostorButtons.Last().transform.parent);
                    button.GetComponent <PassiveButton>().name = button.GetComponentInChildren <TextMeshPro>().text = i.ToString();
                    button.transform.position += new Vector3(offset, 0, 0);
                    impostorButtons.Add(button);
                }

                impostorButtons.ForEach(b =>
                {
                    var button = b.GetComponent <PassiveButton>();
                    button.OnClick.RemoveAllListeners();
                    void defaultListener()
                    {
                        byte value = byte.Parse(button.name);
                        if (value >= __instance.GetTargetOptions().MaxPlayers)
                        {
                            return;
                        }
                        __instance.SetImpostorButtons(byte.Parse(button.name));
                    }
                    button.OnClick.AddListener((UnityAction)defaultListener);
                });

                __instance.ImpostorButtons = impostorButtons.ToArray();
                __instance.SetImpostorButtons(__instance.GetTargetOptions().NumImpostors);

                #endregion
            }
コード例 #4
0
            public static unsafe void Postfix(CreateOptionsPicker __instance)
            {
                if (__instance.mode != SettingsMode.Host)
                {
                    return;
                }

                // thank you dnf and that person in BepInEx discord
                // ReSharper disable once CollectionNeverUpdated.Local
                var theHackyHackButtons = new Il2CppReferenceArray <SpriteRenderer>(*(IntPtr *)__instance.MaxPlayerButtons._items.Pointer);
                var offset = theHackyHackButtons[1].transform.position.x - theHackyHackButtons[0].transform.position.x;

                #region MaxPlayers stuff

                var playerButtons = __instance.MaxPlayerButtons.ToArray().ToList(); // cringe but works

                var plusButton = Object.Instantiate(playerButtons.Last(), playerButtons.Last().transform.parent);
                plusButton.GetComponentInChildren <TextMeshPro>().text = "+";
                plusButton.name = "255";
                plusButton.transform.position = playerButtons.Last().transform.position + new Vector3(offset * 2, 0, 0);
                var passiveButton = plusButton.GetComponent <PassiveButton>();
                passiveButton.OnClick.RemoveAllListeners();
                passiveButton.OnClick.AddListener((UnityAction)plusListener);

                void plusListener()
                {
                    var curHighest = byte.Parse(playerButtons[__instance.MaxPlayerButtons.Count - 2].name);
                    var delta      = Mathf.Clamp(curHighest + 12, curHighest, maxPlayers) - curHighest;

                    if (delta == 0)
                    {
                        return;             // fast skip
                    }
                    for (byte i = 1; i < 13; i++)
                    {
                        var button = theHackyHackButtons[i];
                        button.name =
                            button.GetComponentInChildren <TextMeshPro>().text =
                                (byte.Parse(button.name) + delta).ToString();
                    }
                    __instance.SetMaxPlayersButtons(__instance.GetTargetOptions().MaxPlayers);
                }

                var minusButton = Object.Instantiate(playerButtons.Last(), playerButtons.Last().transform.parent);
                minusButton.GetComponentInChildren <TextMeshPro>().text = "-";
                minusButton.name = "255";
                minusButton.transform.position = playerButtons.First().transform.position;
                var minusPassiveButton = minusButton.GetComponent <PassiveButton>();
                minusPassiveButton.OnClick.RemoveAllListeners();
                minusPassiveButton.OnClick.AddListener((UnityAction)minusListener);

                void minusListener()
                {
                    var curLowest = byte.Parse(playerButtons[1].name);
                    var delta     = curLowest - Mathf.Clamp(curLowest - 12, 4, curLowest);

                    if (delta == 0)
                    {
                        return;             // fast skip
                    }
                    for (byte i = 1; i < 13; i++)
                    {
                        var button = theHackyHackButtons[i];
                        button.name =
                            button.GetComponentInChildren <TextMeshPro>().text =
                                (byte.Parse(button.name) - delta).ToString();
                    }
                    __instance.SetMaxPlayersButtons(__instance.GetTargetOptions().MaxPlayers);
                }

                playerButtons.ForEach(b =>
                {
                    var button = b.GetComponent <PassiveButton>();
                    button.OnClick.RemoveAllListeners();
                    void defaultListener()
                    {
                        var value         = byte.Parse(button.name);
                        var targetOptions = __instance.GetTargetOptions();
                        if (value <= targetOptions.NumImpostors)
                        {
                            targetOptions.NumImpostors = value - 1;
                            __instance.UpdateImpostorsButtons(targetOptions.NumImpostors);
                        }
                        __instance.SetMaxPlayersButtons(value);
                    }
                    button.OnClick.AddListener((UnityAction)defaultListener);
                    button.transform.position += new Vector3(offset, 0, 0);
                });

                playerButtons.Insert(0, minusButton);
                playerButtons.Add(plusButton);
                __instance.MaxPlayerButtons.Clear();
                playerButtons.ForEach(b => __instance.MaxPlayerButtons.Add(b));

                #endregion

                #region Impostor stuff

                var impostorButtons = __instance.ImpostorButtons.ToList();

                for (byte i = 4; i < 11; i++)
                {
                    var button = Object.Instantiate(impostorButtons.Last(), impostorButtons.Last().transform.parent);
                    button.GetComponent <PassiveButton>().name = button.GetComponentInChildren <TextMeshPro>().text = i.ToString();
                    button.transform.position += new Vector3(offset, 0, 0);
                    impostorButtons.Add(button);
                }

                impostorButtons.ForEach(b =>
                {
                    var button = b.GetComponent <PassiveButton>();
                    button.OnClick.RemoveAllListeners();
                    void defaultListener()
                    {
                        var value = byte.Parse(button.name);
                        if (value >= __instance.GetTargetOptions().MaxPlayers)
                        {
                            return;
                        }
                        __instance.SetImpostorButtons(byte.Parse(button.name));
                    }
                    button.OnClick.AddListener((UnityAction)defaultListener);
                });

                __instance.ImpostorButtons = impostorButtons.ToArray();
                __instance.SetImpostorButtons(__instance.GetTargetOptions().NumImpostors);

                #endregion
            }