From 2ab2a5962b4a815897ee794073b6fcf94f1c2601 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sat, 24 Aug 2024 11:58:27 -0500 Subject: [PATCH 01/34] fix chat line break --- Patches/ChatPatch.cs | 4 +++- Patches/GameSettingMenuPatch.cs | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Patches/ChatPatch.cs b/Patches/ChatPatch.cs index 68e577d..5a564d8 100644 --- a/Patches/ChatPatch.cs +++ b/Patches/ChatPatch.cs @@ -125,7 +125,9 @@ class ChatPatch ChatBubble pooledBubble = __instance.GetPooledBubble(); try { - chatText = chatText.Replace("\n", ""); + if (sourcePlayer.BetterData().IsBetterUser && GameStates.IsBetterHostLobby) + chatText = chatText.Replace("\n", ""); + pooledBubble.transform.SetParent(__instance.scroller.Inner); pooledBubble.transform.localScale = Vector3.one; bool flag = sourcePlayer == PlayerControl.LocalPlayer; diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 357bd57..1588254 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -41,7 +41,7 @@ static class GameSettingMenuPatch { TitleList.Add(new BetterOptionTitleItem().Create(BetterSettingsTab, $"Host Only")); BetterGameSettings.WhenCheating = new BetterOptionStringItem().Create(100, BetterSettingsTab, "When a player is caught cheating", ["Do Nothing", "Kick", "Ban"], 2); - BetterGameSettings.InvalidFriendCode = new BetterOptionCheckboxItem().Create(200, BetterSettingsTab, "Allow invalid friendCodes", true); + BetterGameSettings.InvalidFriendCode = new BetterOptionCheckboxItem().Create(200, BetterSettingsTab, "Allow invalid FriendCodes", true); BetterGameSettings.UseBanPlayerList = new BetterOptionCheckboxItem().Create(300, BetterSettingsTab, "Use Ban Player List", true); BetterGameSettings.UseBanNameList = new BetterOptionCheckboxItem().Create(400, BetterSettingsTab, "Use Ban Name List", true); BetterGameSettings.UseBanWordList = new BetterOptionCheckboxItem().Create(500, BetterSettingsTab, "Use Ban Word List", true); @@ -90,7 +90,10 @@ static class GameSettingMenuPatch */ if (BetterSettingsTab != null) + { BetterSettingsTab.scrollBar.SetYBoundsMax(1.25f * BetterOptionItem.SpacingNum / 2); + BetterSettingsTab.InitializeControllerNavigation(); + } } private static void Initialize() From 792d380c51f4d5b6382d400d6c5539436f7d6775 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sat, 24 Aug 2024 16:32:07 -0500 Subject: [PATCH 02/34] more lobby info --- Modules/Utils.cs | 60 ++++++++++++++++++++++++++++ Patches/GamePlayManagerPatch.cs | 20 ++++++++++ Patches/MatchMakerGameButtonPatch.cs | 16 ++++++++ Patches/PingTrackerPatch.cs | 33 +++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 Patches/MatchMakerGameButtonPatch.cs diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 07c9046..dbea76f 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -289,4 +289,64 @@ public static class Utils return $"{Tag}: {PlatformName}"; } + + public static string GetPlatformName(Platforms platform, bool useTag = false) + { + string Tag = string.Empty; + + string PlatformName; + switch (platform) + { + case Platforms.StandaloneSteamPC: + PlatformName = "Steam"; + Tag = "PC"; + break; + case Platforms.StandaloneEpicPC: + PlatformName = "Epic Games"; + Tag = "PC"; + break; + case Platforms.StandaloneWin10: + PlatformName = "Microsoft Store"; + Tag = "PC"; + break; + case Platforms.StandaloneMac: + PlatformName = "Mac OS"; + Tag = "PC"; + break; + case Platforms.StandaloneItch: + PlatformName = "Itch.io"; + Tag = "PC"; + break; + case Platforms.Xbox: + PlatformName = "Xbox"; + Tag = "Console"; + break; + case Platforms.Playstation: + PlatformName = "Playstation"; + Tag = "Console"; + break; + case Platforms.Switch: + PlatformName = "Switch"; + Tag = "Console"; + break; + case Platforms.Android: + PlatformName = "Android"; + Tag = "Mobile"; + break; + case Platforms.IPhone: + PlatformName = "IPhone"; + Tag = "Mobile"; + break; + case Platforms.Unknown: + PlatformName = "None"; + break; + default: + return string.Empty; + } + + if (useTag == false) + return PlatformName; + + return $"{Tag}: {PlatformName}"; + } } \ No newline at end of file diff --git a/Patches/GamePlayManagerPatch.cs b/Patches/GamePlayManagerPatch.cs index 238d58a..d95bb02 100644 --- a/Patches/GamePlayManagerPatch.cs +++ b/Patches/GamePlayManagerPatch.cs @@ -61,6 +61,13 @@ class GamePlayManager } catch { } } + + [HarmonyPatch(nameof(LobbyBehaviour.RpcExtendLobbyTimer))] + [HarmonyPostfix] + private static void RpcExtendLobbyTimer_Postfix(/*LobbyBehaviour __instance*/) + { + GameStartManagerPatch.lobbyTimer += 30f; + } } [HarmonyPatch(typeof(IntroCutscene))] @@ -124,10 +131,23 @@ class GamePlayManager [HarmonyPatch(typeof(GameStartManager))] public class GameStartManagerPatch { + public static float lobbyTimer = 600f; + public static string lobbyTimerDisplay = ""; + [HarmonyPatch(nameof(GameStartManager.Start))] + [HarmonyPostfix] + private static void Start_Postfix(/*GameStartManager __instance*/) + { + lobbyTimer = 600f; + } [HarmonyPatch(nameof(GameStartManager.Update))] [HarmonyPrefix] private static void Update_Prefix(GameStartManager __instance) { + lobbyTimer = Mathf.Max(0f, lobbyTimer -= Time.deltaTime); + int minutes = (int)lobbyTimer / 60; + int seconds = (int)lobbyTimer % 60; + lobbyTimerDisplay = $"{minutes:00}:{seconds:00}"; + __instance.MinPlayers = 1; } [HarmonyPatch(nameof(GameStartManager.Update))] diff --git a/Patches/MatchMakerGameButtonPatch.cs b/Patches/MatchMakerGameButtonPatch.cs new file mode 100644 index 0000000..fe60923 --- /dev/null +++ b/Patches/MatchMakerGameButtonPatch.cs @@ -0,0 +1,16 @@ +using InnerNet; +using HarmonyLib; + +namespace BetterAmongUs; + +[HarmonyPatch(typeof(MatchMakerGameButton))] +class MatchMakerGameButtonPatch +{ + [HarmonyPatch(nameof(MatchMakerGameButton.SetGame))] + [HarmonyPostfix] + private static void SetGame_Postfix(MatchMakerGameButton __instance) + { + __instance.NameText.text = $"{__instance.myListing.HostName}\n"; + __instance.NameText.text += $"{Utils.GetPlatformName(__instance.myListing.Platform)} - {GameCode.IntToGameName(__instance.myListing.GameId)}"; + } +} \ No newline at end of file diff --git a/Patches/PingTrackerPatch.cs b/Patches/PingTrackerPatch.cs index 8d800ce..72dfb31 100644 --- a/Patches/PingTrackerPatch.cs +++ b/Patches/PingTrackerPatch.cs @@ -1,6 +1,7 @@ using HarmonyLib; using System.Text; using UnityEngine; +using static BetterAmongUs.Patches.GamePlayManager; namespace BetterAmongUs.Patches; @@ -23,6 +24,12 @@ public class PingTrackerPatch StringBuilder sb = new StringBuilder(); sb.AppendFormat("PING: {0}\n", GetPingColor(AmongUsClient.Instance.Ping)); + + if (GameStates.IsLobby && GameStates.IsHost && GameStates.IsVanillaServer && !GameStates.IsLocalGame) + { + sb.AppendFormat("Timer: {0}\n", GetTimeColor(GameStartManagerPatch.lobbyTimer)); + } + sb.Append($"BetterAmongUs {Main.GetVersionText(true)}\n"); sb.AppendFormat("{0}\n", Main.Github); @@ -76,4 +83,30 @@ public class PingTrackerPatch return newPing; } + + private static string GetTimeColor(float time) + { + float minutes = (int)time / 60 + 1f; + + string color; + switch (minutes) + { + case float n when n <= 1: + color = "#ff0000"; + break; + case float n when n <= 3.5f: + color = "#ffa200"; + break; + case float n when n <= 5f: + color = "#ffff00"; + break; + default: + color = "#00f04c"; + break; + } + + string newTime = $"{GameStartManagerPatch.lobbyTimerDisplay}"; + + return newTime; + } } From cf533d425879f50c5f180061c0fd0d76953acda3 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sat, 24 Aug 2024 17:31:31 -0500 Subject: [PATCH 03/34] better settings looks better :) --- Modules/OptionItems/BetterOptionCheckboxItem.cs | 8 ++++++++ Modules/OptionItems/BetterOptionFloatItem.cs | 8 ++++++++ Modules/OptionItems/BetterOptionIntItem.cs | 8 ++++++++ Modules/OptionItems/BetterOptionStringItem.cs | 8 ++++++++ Modules/OptionItems/NoneOption/BetterOptionTitleItem.cs | 8 ++++++++ 5 files changed, 40 insertions(+) diff --git a/Modules/OptionItems/BetterOptionCheckboxItem.cs b/Modules/OptionItems/BetterOptionCheckboxItem.cs index c638ed2..7bd6a75 100644 --- a/Modules/OptionItems/BetterOptionCheckboxItem.cs +++ b/Modules/OptionItems/BetterOptionCheckboxItem.cs @@ -26,6 +26,14 @@ public class BetterOptionCheckboxItem : BetterOptionItem optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); SpacingNum += StaticSpacingNumPlus; + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); + optionBehaviour.TitleText.enableAutoSizing = false; + optionBehaviour.TitleText.transform.SetLocalX(-1.5f); + optionBehaviour.TitleText.alignment = TMPro.TextAlignmentOptions.Right; + optionBehaviour.TitleText.enableWordWrapping = false; + optionBehaviour.TitleText.fontSize = 2.5f; + // Set data optionBehaviour.CheckMark.GetComponent().enabled = DefaultValue; TitleText = optionBehaviour.TitleText; diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index 860e4e8..8758aea 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -46,6 +46,14 @@ public class BetterOptionFloatItem : BetterOptionItem optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => Increase())); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => Decrease())); + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); + optionBehaviour.TitleText.enableAutoSizing = false; + optionBehaviour.TitleText.transform.SetLocalX(-1.5f); + optionBehaviour.TitleText.alignment = TMPro.TextAlignmentOptions.Right; + optionBehaviour.TitleText.enableWordWrapping = false; + optionBehaviour.TitleText.fontSize = 2.5f; + // Set data Tab = gameOptionsMenu; Name = name; diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index f0a8dee..f08149a 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -45,6 +45,14 @@ public class BetterOptionIntItem : BetterOptionItem optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => Increase())); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => Decrease())); + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); + optionBehaviour.TitleText.enableAutoSizing = false; + optionBehaviour.TitleText.transform.SetLocalX(-1.5f); + optionBehaviour.TitleText.alignment = TMPro.TextAlignmentOptions.Right; + optionBehaviour.TitleText.enableWordWrapping = false; + optionBehaviour.TitleText.fontSize = 2.5f; + // Set data Tab = gameOptionsMenu; Name = name; diff --git a/Modules/OptionItems/BetterOptionStringItem.cs b/Modules/OptionItems/BetterOptionStringItem.cs index 450ea60..a834c47 100644 --- a/Modules/OptionItems/BetterOptionStringItem.cs +++ b/Modules/OptionItems/BetterOptionStringItem.cs @@ -41,6 +41,14 @@ public class BetterOptionStringItem : BetterOptionItem optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => Increase())); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => Decrease())); + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); + optionBehaviour.TitleText.enableAutoSizing = false; + optionBehaviour.TitleText.transform.SetLocalX(-1.5f); + optionBehaviour.TitleText.alignment = TMPro.TextAlignmentOptions.Right; + optionBehaviour.TitleText.enableWordWrapping = false; + optionBehaviour.TitleText.fontSize = 2.5f; + // Set data TitleText = optionBehaviour.TitleText; Option = optionBehaviour; diff --git a/Modules/OptionItems/NoneOption/BetterOptionTitleItem.cs b/Modules/OptionItems/NoneOption/BetterOptionTitleItem.cs index 5c712be..a9a2d04 100644 --- a/Modules/OptionItems/NoneOption/BetterOptionTitleItem.cs +++ b/Modules/OptionItems/NoneOption/BetterOptionTitleItem.cs @@ -25,6 +25,14 @@ public class BetterOptionTitleItem : BetterOptionItem optionBehaviour.LabelBackground.color = new Color(0.6f, 0.6f, 0.6f, 1f); optionBehaviour.LabelBackground.transform.SetLocalZ(1f); + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); + optionBehaviour.TitleText.enableAutoSizing = false; + optionBehaviour.TitleText.transform.SetLocalX(-2.4f); + optionBehaviour.TitleText.alignment = TMPro.TextAlignmentOptions.Center; + optionBehaviour.TitleText.enableWordWrapping = false; + optionBehaviour.TitleText.fontSize = 2.5f; + // Set data Tab = gameOptionsMenu; Name = $"{name}"; From 62d94b7babd512b0d9eb1549a9397deafd46d5d6 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sat, 24 Aug 2024 17:43:12 -0500 Subject: [PATCH 04/34] modnews --- Resources/ModNews/BAU.v1.1.0.txt | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Resources/ModNews/BAU.v1.1.0.txt diff --git a/Resources/ModNews/BAU.v1.1.0.txt b/Resources/ModNews/BAU.v1.1.0.txt new file mode 100644 index 0000000..629eab0 --- /dev/null +++ b/Resources/ModNews/BAU.v1.1.0.txt @@ -0,0 +1,47 @@ +#Number:110002 +#Title:Better Among Us v1.1.0 +#SubTitle:Settings Galore! +#ShortTitle:BAU v1.1.0 +#Date:2024-8-24T00:00:00Z +#----------------------------- +We are thrilled to announce the release of BetterAmongUs v1.1.0 +# +BetterAmongUs comes packed with a variety of features designed to improve your gameplay experience: +# +Change Log +# +Client +New: Added new intro on boot up +New: Added ability to skip intro by clicking the left or right Mouse button +New: Added Better Option to have chat always visible +Fixed: All players appearing in the role intro +# +Lobby Settings +New: Added the ability to bypass number restrictions in lobby settings +New: Added Better Settings tab with new settings +New: Game Settings is now the default tab when opening lobby settings panel +New: Lobby Settings panel is now available for Non-Host but only Better Settings is editable +Hide And Seek +New: Added Better Setting to set imposter amount +Requires Better Role Algorithm +# +Anti-Cheat +Added list of Better Settings +1. When a player is caught cheating +2. Allow invalid friendCodes +3. Use Ban Player List +4. Use Ban Name List +5. Use Ban Word List +6. Detected player level = or > +7. Detect Cheat Clients +8. Detect Invalid RPCs +9. Detect Invalid Sabotages // Needs testing! +# +# +Issues & Bugs +# +- If you encounter any issues or have feedback, please report them on our Github Issues Page or Bug Reports channel in the BAU Discord Server. +# +Thank you for your support, and we hope you enjoy the new features of BetterAmongUs! +# +Discord Github From 1094e63eea7d3d894ccd7882825b598998864680 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 06:14:16 -0500 Subject: [PATCH 05/34] Not finished parent system for settings --- .../OptionItems/BetterOptionCheckboxItem.cs | 17 ++++++++++++++++- Modules/OptionItems/BetterOptionFloatItem.cs | 19 +++++++++++++++++-- Modules/OptionItems/BetterOptionIntItem.cs | 19 +++++++++++++++++-- Modules/OptionItems/BetterOptionItem.cs | 4 ++++ Modules/OptionItems/BetterOptionStringItem.cs | 19 +++++++++++++++++-- 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/Modules/OptionItems/BetterOptionCheckboxItem.cs b/Modules/OptionItems/BetterOptionCheckboxItem.cs index 7bd6a75..65e4a96 100644 --- a/Modules/OptionItems/BetterOptionCheckboxItem.cs +++ b/Modules/OptionItems/BetterOptionCheckboxItem.cs @@ -4,9 +4,12 @@ namespace BetterAmongUs; public class BetterOptionCheckboxItem : BetterOptionItem { + public BetterOptionItem? ThisParent; private ToggleOption? ThisOption; private bool? IsChecked; + public override bool ShowChildrenCondition() => IsChecked == true; + public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, bool DefaultValue = true, BetterOptionItem Parent = null) { Id = id; @@ -24,7 +27,6 @@ public class BetterOptionCheckboxItem : BetterOptionItem optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f); SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); - SpacingNum += StaticSpacingNumPlus; optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); @@ -43,6 +45,19 @@ public class BetterOptionCheckboxItem : BetterOptionItem Load(DefaultValue); BetterOptionItems.Add(this); + + if (Parent != null) + { + optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalZ(1f); + ThisParent = Parent; + Parent.ChildrenList.Add(this); + } + else + { + SpacingNum += StaticSpacingNumPlus; + } + return this; } diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index 8758aea..627b78c 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -5,13 +5,16 @@ namespace BetterAmongUs; public class BetterOptionFloatItem : BetterOptionItem { + public BetterOptionItem? ThisParent; + private NumberOption? ThisOption; public float CurrentValue; public FloatRange floatRange = new(0f, 180f); public float Increment = 2.5f; - private NumberOption? ThisOption; private string? PostFix; private string? PreFix; + public override bool ShowChildrenCondition() => CurrentValue > floatRange.min; + public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, float[] values, float DefaultValue, string preFix = "", string postFix = "", BetterOptionItem Parent = null) { Id = id; @@ -33,7 +36,6 @@ public class BetterOptionFloatItem : BetterOptionItem optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f); SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); - SpacingNum += StaticSpacingNumPlus; // Fix Game Crash foreach (RulesCategory rulesCategory in GameManager.Instance.GameSettingsList.AllCategories) @@ -67,6 +69,19 @@ public class BetterOptionFloatItem : BetterOptionItem AdjustButtonsActiveState(); BetterOptionItems.Add(this); + + if (Parent != null) + { + optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalZ(1f); + ThisParent = Parent; + Parent.ChildrenList.Add(this); + } + else + { + SpacingNum += StaticSpacingNumPlus; + } + return this; } diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index f08149a..183fba9 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -4,13 +4,16 @@ namespace BetterAmongUs; public class BetterOptionIntItem : BetterOptionItem { + public BetterOptionItem? ThisParent; + private NumberOption? ThisOption; public int CurrentValue; public IntRange intRange = new(0, 180); public int Increment = 1; - private NumberOption? ThisOption; private string? PostFix; private string? PreFix; + public override bool ShowChildrenCondition() => CurrentValue > intRange.min; + public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, int[] values, int DefaultValue, string preFix = "", string postFix = "", BetterOptionItem Parent = null) { Id = id; @@ -32,7 +35,6 @@ public class BetterOptionIntItem : BetterOptionItem optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f); SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); - SpacingNum += StaticSpacingNumPlus; // Fix Game Crash foreach (RulesCategory rulesCategory in GameManager.Instance.GameSettingsList.AllCategories) @@ -66,6 +68,19 @@ public class BetterOptionIntItem : BetterOptionItem AdjustButtonsActiveState(); BetterOptionItems.Add(this); + + if (Parent != null) + { + optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalZ(1f); + ThisParent = Parent; + Parent.ChildrenList.Add(this); + } + else + { + SpacingNum += StaticSpacingNumPlus; + } + return this; } diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index 6b8c937..9f5a6fc 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -17,6 +17,10 @@ public class BetterOptionItem public string? Name = "None"; public TextMeshPro? TitleText; + public bool IsParent => ChildrenList.Count > 0; + public List ChildrenList = []; + public virtual bool ShowChildrenCondition() => false; + public void SetUp(OptionBehaviour optionBehaviour) { SetData(optionBehaviour); diff --git a/Modules/OptionItems/BetterOptionStringItem.cs b/Modules/OptionItems/BetterOptionStringItem.cs index a834c47..311cf9c 100644 --- a/Modules/OptionItems/BetterOptionStringItem.cs +++ b/Modules/OptionItems/BetterOptionStringItem.cs @@ -4,9 +4,12 @@ namespace BetterAmongUs; public class BetterOptionStringItem : BetterOptionItem { + public BetterOptionItem? ThisParent; + private StringOption? ThisOption; public string[] Values = []; public int CurrentValue; - private StringOption? ThisOption; + + public override bool ShowChildrenCondition() => CurrentValue > 0; public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, string[] strings, int DefaultValue = 0, BetterOptionItem Parent = null) { @@ -28,7 +31,6 @@ public class BetterOptionStringItem : BetterOptionItem optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f); SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); - SpacingNum += StaticSpacingNumPlus; // Fix Game Crash foreach (RulesCategory rulesCategory in GameManager.Instance.GameSettingsList.AllCategories) @@ -58,6 +60,19 @@ public class BetterOptionStringItem : BetterOptionItem AdjustButtonsActiveState(); BetterOptionItems.Add(this); + + if (Parent != null) + { + optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalZ(1f); + ThisParent = Parent; + Parent.ChildrenList.Add(this); + } + else + { + SpacingNum += StaticSpacingNumPlus; + } + return this; } From 59088fdf93e7f6a2af6d06f6f215c83d486e1433 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 06:16:04 -0500 Subject: [PATCH 06/34] just > --- Modules/AntiCheat.cs | 2 +- Patches/GameSettingMenuPatch.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/AntiCheat.cs b/Modules/AntiCheat.cs index f7c2436..ade2d2d 100644 --- a/Modules/AntiCheat.cs +++ b/Modules/AntiCheat.cs @@ -247,7 +247,7 @@ class AntiCheat if (reader.BytesRemaining > 0) { uint level = reader.ReadPackedUInt32(); - if (level >= BetterGameSettings.DetectedLevelAbove.GetInt()) + if (level > BetterGameSettings.DetectedLevelAbove.GetInt()) { BetterNotificationManager.NotifyCheat(player, $"Invalid Level: {level}"); Logger.LogCheat($"{player.BetterData().RealName} {Enum.GetName((RpcCalls)callId)}: {level >= 200}"); diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 1588254..360f8c2 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -49,7 +49,7 @@ static class GameSettingMenuPatch } TitleList.Add(new BetterOptionTitleItem().Create(BetterSettingsTab, $"Detections")); - BetterGameSettings.DetectedLevelAbove = new BetterOptionIntItem().Create(600, BetterSettingsTab, "Detected player level = or >", [100, 5000, 5], 200, "Lv ", ""); + BetterGameSettings.DetectedLevelAbove = new BetterOptionIntItem().Create(600, BetterSettingsTab, "Detected player levels >", [100, 5000, 5], 200, "Lv ", ""); BetterGameSettings.DetectCheatClients = new BetterOptionCheckboxItem().Create(700, BetterSettingsTab, "Detect Cheat Clients", true); BetterGameSettings.DetectInvalidRPCs = new BetterOptionCheckboxItem().Create(800, BetterSettingsTab, "Detect Invalid RPCs", true); From 1953c178dc70dbd0bb0e152850cf982ed5919f9a Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 06:45:47 -0500 Subject: [PATCH 07/34] fix --- Patches/CommandsPatch.cs | 3 ++- Patches/GameSettingMenuPatch.cs | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Patches/CommandsPatch.cs b/Patches/CommandsPatch.cs index faa81dc..a37465f 100644 --- a/Patches/CommandsPatch.cs +++ b/Patches/CommandsPatch.cs @@ -246,8 +246,9 @@ class CommandsPatch { foreach (PlayerControl player in Main.AllPlayerControls) { + player.RpcExile(); player.roleAssigned = false; - player.RpcSetRole(RoleTypes.Crewmate, true); + player.RpcSetRole(RoleTypes.CrewmateGhost, true); } GameManager.Instance.RpcEndGame(GameOverReason.ImpostorByKill, false); return; diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 360f8c2..32b616a 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -41,7 +41,7 @@ static class GameSettingMenuPatch { TitleList.Add(new BetterOptionTitleItem().Create(BetterSettingsTab, $"Host Only")); BetterGameSettings.WhenCheating = new BetterOptionStringItem().Create(100, BetterSettingsTab, "When a player is caught cheating", ["Do Nothing", "Kick", "Ban"], 2); - BetterGameSettings.InvalidFriendCode = new BetterOptionCheckboxItem().Create(200, BetterSettingsTab, "Allow invalid FriendCodes", true); + BetterGameSettings.InvalidFriendCode = new BetterOptionCheckboxItem().Create(200, BetterSettingsTab, "Detected invalid FriendCodes", true); BetterGameSettings.UseBanPlayerList = new BetterOptionCheckboxItem().Create(300, BetterSettingsTab, "Use Ban Player List", true); BetterGameSettings.UseBanNameList = new BetterOptionCheckboxItem().Create(400, BetterSettingsTab, "Use Ban Name List", true); BetterGameSettings.UseBanWordList = new BetterOptionCheckboxItem().Create(500, BetterSettingsTab, "Use Ban Word List", true); @@ -272,6 +272,8 @@ static class NumberOptionPatch [HarmonyPrefix] public static bool Increase_Prefix(NumberOption __instance) { + if (GameStates.IsVanillaServer) return true; + int times = 1; if (Input.GetKey(KeyCode.LeftShift)) times = 5; @@ -280,6 +282,7 @@ static class NumberOptionPatch __instance.Value += __instance.Increment * times; __instance.UpdateValue(); + __instance.OnValueChanged.Invoke(__instance); return false; } @@ -287,6 +290,8 @@ static class NumberOptionPatch [HarmonyPrefix] public static bool Decrease_Prefix(NumberOption __instance) { + if (GameStates.IsVanillaServer) return true; + int times = 1; if (Input.GetKey(KeyCode.LeftShift)) times = 5; @@ -295,6 +300,7 @@ static class NumberOptionPatch __instance.Value -= __instance.Increment * times; __instance.UpdateValue(); + __instance.OnValueChanged.Invoke(__instance); return false; } @@ -302,6 +308,8 @@ static class NumberOptionPatch [HarmonyPrefix] public static bool UpdateValue_Prefix(NumberOption __instance) { + if (GameStates.IsVanillaServer) return true; + if (__instance.floatOptionName != FloatOptionNames.Invalid) { GameOptionsManager.Instance.CurrentGameOptions.SetFloat(__instance.floatOptionName, __instance.GetFloat()); @@ -319,6 +327,8 @@ static class NumberOptionPatch [HarmonyPrefix] public static bool FixedUpdate_Prefix(NumberOption __instance) { + if (GameStates.IsVanillaServer) return true; + try { if (__instance.MinusBtn != null && __instance.PlusBtn != null) From 7027f577221508afe51cb2e9234f55687572b503 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 07:25:25 -0500 Subject: [PATCH 08/34] reverted setting num bypass --- Patches/GameSettingMenuPatch.cs | 70 ++++++--------------------------- 1 file changed, 12 insertions(+), 58 deletions(-) diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 32b616a..774e01a 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -272,17 +272,20 @@ static class NumberOptionPatch [HarmonyPrefix] public static bool Increase_Prefix(NumberOption __instance) { - if (GameStates.IsVanillaServer) return true; - int times = 1; if (Input.GetKey(KeyCode.LeftShift)) times = 5; if (Input.GetKey(KeyCode.LeftControl)) times = 10; - __instance.Value += __instance.Increment * times; + if (__instance.Value + __instance.Increment * times > __instance.ValidRange.max) + { + return false; + } + __instance.Value = __instance.ValidRange.Clamp(__instance.Value + __instance.Increment * times); __instance.UpdateValue(); __instance.OnValueChanged.Invoke(__instance); + __instance.AdjustButtonsActiveState(); return false; } @@ -290,69 +293,20 @@ static class NumberOptionPatch [HarmonyPrefix] public static bool Decrease_Prefix(NumberOption __instance) { - if (GameStates.IsVanillaServer) return true; - int times = 1; if (Input.GetKey(KeyCode.LeftShift)) times = 5; if (Input.GetKey(KeyCode.LeftControl)) times = 10; - __instance.Value -= __instance.Increment * times; + if (__instance.Value - __instance.Increment * times < __instance.ValidRange.min) + { + return false; + } + __instance.Value = __instance.ValidRange.Clamp(__instance.Value - __instance.Increment * times); __instance.UpdateValue(); __instance.OnValueChanged.Invoke(__instance); - return false; - } - - [HarmonyPatch(nameof(NumberOption.UpdateValue))] - [HarmonyPrefix] - public static bool UpdateValue_Prefix(NumberOption __instance) - { - if (GameStates.IsVanillaServer) return true; - - if (__instance.floatOptionName != FloatOptionNames.Invalid) - { - GameOptionsManager.Instance.CurrentGameOptions.SetFloat(__instance.floatOptionName, __instance.GetFloat()); - return false; - } - if (__instance.intOptionName != Int32OptionNames.Invalid) - { - GameOptionsManager.Instance.CurrentGameOptions.SetInt(__instance.intOptionName, __instance.GetInt()); - return false; - } - return false; - } - - [HarmonyPatch(nameof(NumberOption.FixedUpdate))] - [HarmonyPrefix] - public static bool FixedUpdate_Prefix(NumberOption __instance) - { - if (GameStates.IsVanillaServer) return true; - - try - { - if (__instance.MinusBtn != null && __instance.PlusBtn != null) - { - __instance.MinusBtn.SetInteractable(true); - __instance.PlusBtn.SetInteractable(true); - } - - if (__instance.oldValue != __instance.Value) - { - __instance.oldValue = __instance.Value; - - if (__instance.Value > __instance.ValidRange.max || __instance.Value < __instance.ValidRange.min) - { - __instance.ValueText.text = $"{__instance.data.GetValueString(__instance.Value)}"; - } - else - { - __instance.ValueText.text = __instance.data.GetValueString(__instance.Value); - } - } - } - catch { } - + __instance.AdjustButtonsActiveState(); return false; } } \ No newline at end of file From 190bf4761b0eb81563a52c62d2bc2f8c3b37b35e Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 14:58:55 -0500 Subject: [PATCH 09/34] better host fixes --- Modules/BetterHostManager.cs | 103 ++++++++++++++++++----------------- Patches/ChatPatch.cs | 5 +- 2 files changed, 56 insertions(+), 52 deletions(-) diff --git a/Modules/BetterHostManager.cs b/Modules/BetterHostManager.cs index 550f3af..c5beebd 100644 --- a/Modules/BetterHostManager.cs +++ b/Modules/BetterHostManager.cs @@ -206,77 +206,80 @@ class BetterHostManager foreach (PlayerControl target in Main.AllPlayerControls) { - if (target == null || target == PlayerControl.LocalPlayer || target.BetterData().IsBetterUser) continue; + if (target == null || target == PlayerControl.LocalPlayer) continue; string NewName = player.CurrentOutfit.PlayerName; StringBuilder sbTopTag = new StringBuilder(); StringBuilder sbTopInfo = new StringBuilder(); - if (GameStates.IsLobby) + if (!player.BetterData().IsBetterUser) { - NewName = player.Data.PlayerName; - - if (player.IsHost()) - NewName = player.GetPlayerNameAndColor(); - - if (player.IsDev()) - sbTopTag.Append("(Dev)+++"); - - if (player == PlayerControl.LocalPlayer) - sbTopTag.Append($"Better Host+++"); - else if (player.BetterData().IsBetterUser) - sbTopTag.Append("Better User+++"); - } - else if (GameStates.IsInGamePlay && !GameStates.IsHideNSeek) - { - string Role = $"{player.GetRoleName()}"; - if (!player.IsImpostorTeam() && player.myTasks.Count > 0) + if (GameStates.IsLobby) { - Role += $" ({player.Data.Tasks.ToArray().Where(task => task.Complete).Count()}/{player.Data.Tasks.Count})"; + NewName = player.Data.PlayerName; + + if (player.IsHost()) + NewName = player.GetPlayerNameAndColor(); + + if (player.IsDev()) + sbTopTag.Append("(Dev)+++"); + + if (player == PlayerControl.LocalPlayer) + sbTopTag.Append($"Better Host+++"); + else if (player.BetterData().IsBetterUser) + sbTopTag.Append("Better User+++"); } - if (player.IsImpostorTeam() is false || target.IsImpostorTeam() is false) + else if (GameStates.IsInGamePlay && !GameStates.IsHideNSeek) { - if (target.IsAlive() && player != target) + string Role = $"{player.GetRoleName()}"; + if (!player.IsImpostorTeam() && player.myTasks.Count > 0) { - Role = ""; + Role += $" ({player.Data.Tasks.ToArray().Where(task => task.Complete).Count()}/{player.Data.Tasks.Count})"; + } + if (player.IsImpostorTeam() is false || target.IsImpostorTeam() is false) + { + if (target.IsAlive() && player != target) + { + Role = ""; + } + } + + sbTopTag.Append($"{Role}+++"); + } + + for (int i = 0; i < sbTopTag.ToString().Split("+++").Length; i++) + { + if (!string.IsNullOrEmpty(sbTopTag.ToString().Split("+++")[i])) + { + if (i < sbTopTag.ToString().Split("+++").Length) + { + sbTopInfo.Append(sbTopTag.ToString().Split("+++")[i]); + } + if (i != sbTopTag.ToString().Split("+++").Length - 2) + { + sbTopInfo.Append(" - "); + } } } - sbTopTag.Append($"{Role}+++"); - } + if (sbTopInfo.Length > 0) + NewName = $"{sbTopInfo}\n{NewName}"; + else + NewName = $"{NewName}"; - for (int i = 0; i < sbTopTag.ToString().Split("+++").Length; i++) - { - if (!string.IsNullOrEmpty(sbTopTag.ToString().Split("+++")[i])) + // Don't send rpc if name is the same! + if (player.BetterData().LastNameSetFor.TryGetValue(target.PlayerId, out var lastName)) { - if (i < sbTopTag.ToString().Split("+++").Length) + if (lastName == NewName || !force) { - sbTopInfo.Append(sbTopTag.ToString().Split("+++")[i]); - } - if (i != sbTopTag.ToString().Split("+++").Length - 2) - { - sbTopInfo.Append(" - "); + return; } } + + player.BetterData().LastNameSetFor[target.PlayerId] = NewName; } - if (sbTopInfo.Length > 0) - NewName = $"{sbTopInfo}\n{NewName}"; - else - NewName = $"{NewName}"; - - // Don't send rpc if name is the same! - if (player.BetterData().LastNameSetFor.TryGetValue(target.PlayerId, out var lastName)) - { - if (lastName == NewName || !force) - { - return; - } - } - - player.BetterData().LastNameSetFor[target.PlayerId] = NewName; - player.RpcSetNamePrivate(NewName, target); Logger.Log($"Set {player.Data.PlayerName} name to {NewName.Replace("\n", "-")} for {target.Data.PlayerName}", "RPC"); } diff --git a/Patches/ChatPatch.cs b/Patches/ChatPatch.cs index 5a564d8..22c9a53 100644 --- a/Patches/ChatPatch.cs +++ b/Patches/ChatPatch.cs @@ -175,9 +175,10 @@ class ChatPatch if (sourcePlayer.IsDev()) sbTag.Append("Dev+++"); - if (((sourcePlayer == PlayerControl.LocalPlayer && GameStates.IsHost && Main.BetterHost.Value) || sourcePlayer.BetterData().IsBetterHost) && !GameStates.IsInGamePlay) + if (((sourcePlayer == PlayerControl.LocalPlayer && GameStates.IsHost && Main.BetterHost.Value) + || (sourcePlayer != PlayerControl.LocalPlayer && sourcePlayer.BetterData().IsBetterHost && sourcePlayer.IsHost()))) sbTag.Append("Better Host+++"); - else if ((sourcePlayer == PlayerControl.LocalPlayer || sourcePlayer.BetterData().IsBetterUser) && !GameStates.IsInGamePlay) + else if ((sourcePlayer == PlayerControl.LocalPlayer || sourcePlayer.BetterData().IsBetterUser)) sbTag.Append("Better User+++"); if (!string.IsNullOrEmpty(hashPuid) && AntiCheat.SickoData.ContainsKey(hashPuid) || !string.IsNullOrEmpty(friendCode) && AntiCheat.SickoData.ContainsValue(friendCode)) From 1c9ffa7c13f350d3c0c4250cc42478872a857b90 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 15:01:47 -0500 Subject: [PATCH 10/34] rpc clean up --- Modules/ExtendedPlayerControl.cs | 5 ---- Modules/RPC.cs | 47 ++----------------------------- Patches/PlayerJoinAndLeftPatch.cs | 3 -- 3 files changed, 2 insertions(+), 53 deletions(-) diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index 312eee7..87bceb4 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -129,11 +129,6 @@ static class ExtendedPlayerControl } // RPCs - public static void RpcSendHostChat(this PlayerControl player, string text, string title = "(System Message)", bool sendToBetterUser = true) - { - if (player == null) return; - RPC.SendHostChatToPlayer(player, text, title, sendToBetterUser); - } public static void RpcSetNamePrivate(this PlayerControl player, string name, PlayerControl target) { if (player == null || target == null) return; diff --git a/Modules/RPC.cs b/Modules/RPC.cs index 9642569..92bd469 100644 --- a/Modules/RPC.cs +++ b/Modules/RPC.cs @@ -133,51 +133,6 @@ internal static class RPC player.Exiled(); } - public static void SendHostChatToPlayer(PlayerControl player, string text, string? title = "", bool sendToBetterUser = true) - { - if (!GameStates.IsHost) return; - - if (player.BetterData().IsBetterUser) - { - if (sendToBetterUser) - { - MessageWriter messageWriter2 = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, unchecked((byte)CustomRPC.AddChat), SendOption.None, player.GetClientId()); - messageWriter2.Write(text); - messageWriter2.Write(title); - AmongUsClient.Instance.FinishRpcImmediately(messageWriter2); - } - - return; - } - - /* - PlayerControl asPlayer = Main.AllPlayerControls.Where(pc => pc.IsAlive()).OrderBy(pc => pc == PlayerControl.LocalPlayer ? 0 : 1).First(); - - var oldName = asPlayer.CurrentOutfit.PlayerName; - if (title == "") - title = oldName; - - MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(asPlayer.NetId, (byte)RpcCalls.SetName, SendOption.None, player.GetClientId()); - writer.Write(asPlayer.Data.NetId); - writer.Write(title); - AmongUsClient.Instance.FinishRpcImmediately(writer); - - MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(asPlayer.NetId, (byte)RpcCalls.SendChat, SendOption.None, player.GetClientId()); - messageWriter.Write(text); - AmongUsClient.Instance.FinishRpcImmediately(messageWriter); - - _ = new LateTask(() => - { - MessageWriter writer2 = AmongUsClient.Instance.StartRpcImmediately(asPlayer.NetId, (byte)RpcCalls.SetName, SendOption.None, player.GetClientId()); - writer2.Write(asPlayer.Data.NetId); - writer2.Write(oldName); - AmongUsClient.Instance.FinishRpcImmediately(writer2); - - SyncAllNames(force: true); - }, 0.08f, shoudLog: false); - */ - } - public static void HandleCustomRPC(PlayerControl player, byte callId, MessageReader oldReader) { if (PlayerControl.LocalPlayer == null || player == null || player == PlayerControl.LocalPlayer || player.Data == null) return; @@ -201,6 +156,8 @@ internal static class RPC player.BetterData().IsBetterUser = SetBetterUser; player.BetterData().IsBetterHost = IsBetterHost; + + SyncAllNames(force: true); } break; case (byte)CustomRPC.AddChat: diff --git a/Patches/PlayerJoinAndLeftPatch.cs b/Patches/PlayerJoinAndLeftPatch.cs index 17e9a4e..9dc1a53 100644 --- a/Patches/PlayerJoinAndLeftPatch.cs +++ b/Patches/PlayerJoinAndLeftPatch.cs @@ -52,9 +52,6 @@ public static class OnPlayerJoinedPatch RPC.SyncAllNames(force: true); - if (Main.BetterHost.Value) - client.Character.RpcSendHostChat(HudManagerPatch.WelcomeMessage, sendToBetterUser: false); - // Auto ban player on ban list if (BetterGameSettings.UseBanPlayerList.GetBool()) { From a537db207fb0dad9052d090e100a4f5933bca6dd Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 15:07:20 -0500 Subject: [PATCH 11/34] Integrate better role algorithm --- BetterAmongUs.csproj | 6 ++++++ Patches/ClientOptionsPatch.cs | 6 ------ Patches/CommandsPatch.cs | 5 ----- Patches/GameSettingMenuPatch.cs | 10 ++-------- Patches/RoleManagerPatch.cs | 4 ---- main.cs | 2 -- 6 files changed, 8 insertions(+), 25 deletions(-) diff --git a/BetterAmongUs.csproj b/BetterAmongUs.csproj index 1d0bb6b..4da5c31 100644 --- a/BetterAmongUs.csproj +++ b/BetterAmongUs.csproj @@ -25,4 +25,10 @@ + + + + + + \ No newline at end of file diff --git a/Patches/ClientOptionsPatch.cs b/Patches/ClientOptionsPatch.cs index f811f98..8d94d53 100644 --- a/Patches/ClientOptionsPatch.cs +++ b/Patches/ClientOptionsPatch.cs @@ -10,7 +10,6 @@ public static class OptionsMenuBehaviourPatch { private static ClientOptionItem AntiCheat; private static ClientOptionItem BetterHost; - private static ClientOptionItem BetterRoleAlgorithma; private static ClientOptionItem BetterNotifications; private static ClientOptionItem ChatInGameplay; private static ClientOptionItem LobbyPlayerInfo; @@ -63,11 +62,6 @@ public static class OptionsMenuBehaviourPatch } } - if (BetterRoleAlgorithma == null || BetterRoleAlgorithma.ToggleButton == null) - { - BetterRoleAlgorithma = ClientOptionItem.Create("Better Role Algorithma", Main.BetterRoleAlgorithma, __instance, toggleCheck: () => !toggleCheckInGamePlay("Better Role Algorithma")); - } - if (BetterNotifications == null || BetterNotifications.ToggleButton == null) { BetterNotifications = ClientOptionItem.Create("Better Notifications", Main.BetterNotifications, __instance, BetterNotificationsToggle); diff --git a/Patches/CommandsPatch.cs b/Patches/CommandsPatch.cs index a37465f..b618e98 100644 --- a/Patches/CommandsPatch.cs +++ b/Patches/CommandsPatch.cs @@ -303,11 +303,6 @@ class CommandsPatch case "role" or "setrole": if (HandleIsHost(command) == true) { - if (!Main.BetterRoleAlgorithma.Value) - { - Utils.AddChatPrivate($"{error}\nBetter Role Algorithma in better options must be turned on to use this command"); - return; - } if (command[0][1..].ToLower().Trim() == "role") { var player = PlayerControl.LocalPlayer; diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 774e01a..8550b1c 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -69,14 +69,8 @@ static class GameSettingMenuPatch else if (IsPreload || GameStates.IsHideNSeek) { new BetterOptionHeaderItem().Create(BetterSettingsTab, "Hide & Seek Settings"); - - if (IsPreload || Main.BetterRoleAlgorithma.Value) - { - new BetterOptionTitleItem().Create(BetterSettingsTab, $"Better Role Algorithma"); - BetterOptionItem.SpacingNum += 0.2f; - new BetterOptionTitleItem().Create(BetterSettingsTab, $"Imposter"); - BetterGameSettings.HideAndSeekImpNum = new BetterOptionIntItem().Create(1000, BetterSettingsTab, "# Seekers", [1, 5, 1], 1, "", ""); - } + new BetterOptionTitleItem().Create(BetterSettingsTab, $"Imposter"); + BetterGameSettings.HideAndSeekImpNum = new BetterOptionIntItem().Create(1000, BetterSettingsTab, "# Seekers", [1, 5, 1], 1, "", ""); } } } diff --git a/Patches/RoleManagerPatch.cs b/Patches/RoleManagerPatch.cs index eb4ad5f..4c2c684 100644 --- a/Patches/RoleManagerPatch.cs +++ b/Patches/RoleManagerPatch.cs @@ -21,8 +21,6 @@ public class RoleManagerPatch [HarmonyPrefix] public static bool RoleManager_Prefix(/*RoleManager __instance*/) { - if (!Main.BetterRoleAlgorithma.Value) return true; - if (!GameStates.IsHideNSeek) { RegularBetterRoleAssignment(); @@ -377,8 +375,6 @@ public class RoleManagerPatch [HarmonyPrefix] public static bool AssignRoleOnDeath_Prefix(/*RoleManager __instance*/ [HarmonyArgument(0)] PlayerControl player) { - if (!Main.BetterRoleAlgorithma.Value) return true; - Dictionary GhostRoles = new() // Role, Amount { { RoleTypes.GuardianAngel, 0 }, diff --git a/main.cs b/main.cs index bbd2247..2db0077 100644 --- a/main.cs +++ b/main.cs @@ -174,7 +174,6 @@ public class Main : BasePlugin public static ConfigEntry AntiCheat { get; private set; } public static ConfigEntry BetterHost { get; private set; } - public static ConfigEntry BetterRoleAlgorithma { get; private set; } public static ConfigEntry BetterNotifications { get; private set; } public static ConfigEntry ChatInGameplay { get; private set; } public static ConfigEntry LobbyPlayerInfo { get; private set; } @@ -186,7 +185,6 @@ public class Main : BasePlugin { AntiCheat = Config.Bind("Better Options", "AntiCheat", true); BetterHost = Config.Bind("Better Options", "BetterHost", false); - BetterRoleAlgorithma = Config.Bind("Better Options", "BetterRoleAlgorithma", true); BetterNotifications = Config.Bind("Better Options", "BetterNotifications", true); ChatInGameplay = Config.Bind("Better Options", "ChatInGameplay", true); LobbyPlayerInfo = Config.Bind("Better Options", "LobbyPlayerInfo", true); From c28753654af8379031e7c17d63567aec9f34e973 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 15:08:13 -0500 Subject: [PATCH 12/34] Notify --- Patches/GameSettingMenuPatch.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 8550b1c..b8f2ce4 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -40,7 +40,7 @@ static class GameSettingMenuPatch if (IsPreload || GameStates.IsHost) { TitleList.Add(new BetterOptionTitleItem().Create(BetterSettingsTab, $"Host Only")); - BetterGameSettings.WhenCheating = new BetterOptionStringItem().Create(100, BetterSettingsTab, "When a player is caught cheating", ["Do Nothing", "Kick", "Ban"], 2); + BetterGameSettings.WhenCheating = new BetterOptionStringItem().Create(100, BetterSettingsTab, "When a player is caught cheating", ["Notify", "Kick", "Ban"], 2); BetterGameSettings.InvalidFriendCode = new BetterOptionCheckboxItem().Create(200, BetterSettingsTab, "Detected invalid FriendCodes", true); BetterGameSettings.UseBanPlayerList = new BetterOptionCheckboxItem().Create(300, BetterSettingsTab, "Use Ban Player List", true); BetterGameSettings.UseBanNameList = new BetterOptionCheckboxItem().Create(400, BetterSettingsTab, "Use Ban Name List", true); From d6d2372d396504244107dc8ff1aa2c4ed8cecad1 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 15:08:54 -0500 Subject: [PATCH 13/34] oops --- BetterAmongUs.csproj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/BetterAmongUs.csproj b/BetterAmongUs.csproj index 4da5c31..1d0bb6b 100644 --- a/BetterAmongUs.csproj +++ b/BetterAmongUs.csproj @@ -25,10 +25,4 @@ - - - - - - \ No newline at end of file From 4e3ae4d99a5a895ccc34a9692aef38d91e6842b7 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 17:43:39 -0500 Subject: [PATCH 14/34] Better StringBuilder --- Modules/BetterHostManager.cs | 32 +++++++++++++++++++++----------- Patches/PlayerControlPatch.cs | 24 ++++++++++++------------ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Modules/BetterHostManager.cs b/Modules/BetterHostManager.cs index c5beebd..5c094ef 100644 --- a/Modules/BetterHostManager.cs +++ b/Modules/BetterHostManager.cs @@ -211,7 +211,6 @@ class BetterHostManager string NewName = player.CurrentOutfit.PlayerName; StringBuilder sbTopTag = new StringBuilder(); - StringBuilder sbTopInfo = new StringBuilder(); if (!player.BetterData().IsBetterUser) { @@ -248,23 +247,34 @@ class BetterHostManager sbTopTag.Append($"{Role}+++"); } - for (int i = 0; i < sbTopTag.ToString().Split("+++").Length; i++) + // Put +++ at the end of each tag + static StringBuilder FormatInfo(StringBuilder source) { - if (!string.IsNullOrEmpty(sbTopTag.ToString().Split("+++")[i])) + var sb = new StringBuilder(); + if (source.Length > 0) { - if (i < sbTopTag.ToString().Split("+++").Length) + string text = source.ToString(); + string[] parts = text.Split("+++"); + for (int i = 0; i < parts.Length; i++) { - sbTopInfo.Append(sbTopTag.ToString().Split("+++")[i]); - } - if (i != sbTopTag.ToString().Split("+++").Length - 2) - { - sbTopInfo.Append(" - "); + if (!string.IsNullOrEmpty(Utils.RemoveHtmlText(parts[i]))) + { + sb.Append(parts[i]); + if (i != parts.Length - 2) + { + sb.Append(" - "); + } + } } } + + return sb; } - if (sbTopInfo.Length > 0) - NewName = $"{sbTopInfo}\n{NewName}"; + sbTopTag = FormatInfo(sbTopTag); + + if (sbTopTag.Length > 0) + NewName = $"{sbTopTag}\n{NewName}"; else NewName = $"{NewName}"; diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index dbf63fb..0e85158 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -128,11 +128,8 @@ class PlayerControlPatch } var sbTag = new StringBuilder(); - var sbInfo = new StringBuilder(); var sbTagTop = new StringBuilder(); - var sbInfoTop = new StringBuilder(); var sbTagBottom = new StringBuilder(); - var sbInfoBottom = new StringBuilder(); // Put +++ at the end of each tag if (!player.isDummy) @@ -194,8 +191,9 @@ class PlayerControlPatch } // Put +++ at the end of each tag - void AppendTagInfo(StringBuilder source, StringBuilder destination) + static StringBuilder FormatInfo(StringBuilder source) { + var sb = new StringBuilder(); if (source.Length > 0) { string text = source.ToString(); @@ -204,23 +202,25 @@ class PlayerControlPatch { if (!string.IsNullOrEmpty(Utils.RemoveHtmlText(parts[i]))) { - destination.Append(parts[i]); + sb.Append(parts[i]); if (i != parts.Length - 2) { - destination.Append(" - "); + sb.Append(" - "); } } } } + + return sb; } - AppendTagInfo(sbTag, sbInfo); - AppendTagInfo(sbTagTop, sbInfoTop); - AppendTagInfo(sbTagBottom, sbInfoBottom); + sbTag = FormatInfo(sbTag); + sbTagTop = FormatInfo(sbTagTop); + sbTagBottom = FormatInfo(sbTagBottom); - player.SetPlayerTextInfo(sbInfoTop.ToString()); - player.SetPlayerTextInfo(sbInfoBottom.ToString(), isBottom: true); - player.SetPlayerTextInfo(sbInfo.ToString(), isInfo: true); + player.SetPlayerTextInfo(sbTagTop.ToString()); + player.SetPlayerTextInfo(sbTagBottom.ToString(), isBottom: true); + player.SetPlayerTextInfo(sbTag.ToString(), isInfo: true); } catch (Exception ex) { From d8391b28e7ea10ad99cd397d49ae0342c88f491c Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 22:01:14 -0500 Subject: [PATCH 15/34] Support parent settings --- .../OptionItems/BetterOptionCheckboxItem.cs | 18 ++++++--- Modules/OptionItems/BetterOptionFloatItem.cs | 17 +++++--- Modules/OptionItems/BetterOptionIntItem.cs | 17 +++++--- Modules/OptionItems/BetterOptionItem.cs | 40 ++++++++++++++++++- Modules/OptionItems/BetterOptionStringItem.cs | 17 +++++--- .../NoneOption/BetterOptionDividerItem.cs | 7 ++-- .../NoneOption/BetterOptionHeaderItem.cs | 7 ++-- .../NoneOption/BetterOptionTitleItem.cs | 5 ++- Patches/GameSettingMenuPatch.cs | 27 ++++++++----- main.cs | 4 +- 10 files changed, 111 insertions(+), 48 deletions(-) diff --git a/Modules/OptionItems/BetterOptionCheckboxItem.cs b/Modules/OptionItems/BetterOptionCheckboxItem.cs index 65e4a96..45a5898 100644 --- a/Modules/OptionItems/BetterOptionCheckboxItem.cs +++ b/Modules/OptionItems/BetterOptionCheckboxItem.cs @@ -4,7 +4,6 @@ namespace BetterAmongUs; public class BetterOptionCheckboxItem : BetterOptionItem { - public BetterOptionItem? ThisParent; private ToggleOption? ThisOption; private bool? IsChecked; @@ -24,7 +23,7 @@ public class BetterOptionCheckboxItem : BetterOptionItem } ToggleOption optionBehaviour = UnityEngine.Object.Instantiate(gameOptionsMenu.checkboxOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); - optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f); + optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f, -2f); SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); @@ -45,6 +44,7 @@ public class BetterOptionCheckboxItem : BetterOptionItem Load(DefaultValue); BetterOptionItems.Add(this); + obj = optionBehaviour.gameObject; if (Parent != null) { @@ -53,10 +53,6 @@ public class BetterOptionCheckboxItem : BetterOptionItem ThisParent = Parent; Parent.ChildrenList.Add(this); } - else - { - SpacingNum += StaticSpacingNumPlus; - } return this; } @@ -102,5 +98,15 @@ public class BetterOptionCheckboxItem : BetterOptionItem { IsChecked = !IsChecked; BetterDataManager.SaveSetting(Id, IsChecked.ToString()); + + if (IsParent) + { + bool Bool = ShowChildrenCondition(); + foreach (var item in ChildrenList) + { + item.obj.SetActive(Bool); + } + UpdatePositions(); + } } } diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index 627b78c..ace3bf4 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -5,7 +5,6 @@ namespace BetterAmongUs; public class BetterOptionFloatItem : BetterOptionItem { - public BetterOptionItem? ThisParent; private NumberOption? ThisOption; public float CurrentValue; public FloatRange floatRange = new(0f, 180f); @@ -33,7 +32,7 @@ public class BetterOptionFloatItem : BetterOptionItem if (values.Length is < 3 or > 3) return null; NumberOption optionBehaviour = UnityEngine.Object.Instantiate(gameOptionsMenu.numberOptionOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); - optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f); + optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f, -2f); SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); @@ -69,6 +68,7 @@ public class BetterOptionFloatItem : BetterOptionItem AdjustButtonsActiveState(); BetterOptionItems.Add(this); + obj = optionBehaviour.gameObject; if (Parent != null) { @@ -77,10 +77,6 @@ public class BetterOptionFloatItem : BetterOptionItem ThisParent = Parent; Parent.ChildrenList.Add(this); } - else - { - SpacingNum += StaticSpacingNumPlus; - } return this; } @@ -197,5 +193,14 @@ public class BetterOptionFloatItem : BetterOptionItem public override void ValueChanged(int id, OptionBehaviour optionBehaviour) { + if (IsParent) + { + bool Bool = ShowChildrenCondition(); + foreach (var item in ChildrenList) + { + item.obj.SetActive(Bool); + } + UpdatePositions(); + } } } diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index 183fba9..759efd1 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -4,7 +4,6 @@ namespace BetterAmongUs; public class BetterOptionIntItem : BetterOptionItem { - public BetterOptionItem? ThisParent; private NumberOption? ThisOption; public int CurrentValue; public IntRange intRange = new(0, 180); @@ -32,7 +31,7 @@ public class BetterOptionIntItem : BetterOptionItem if (values.Length is < 3 or > 3) return null; NumberOption optionBehaviour = UnityEngine.Object.Instantiate(gameOptionsMenu.numberOptionOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); - optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f); + optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f, -2f); SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); @@ -68,6 +67,7 @@ public class BetterOptionIntItem : BetterOptionItem AdjustButtonsActiveState(); BetterOptionItems.Add(this); + obj = optionBehaviour.gameObject; if (Parent != null) { @@ -76,10 +76,6 @@ public class BetterOptionIntItem : BetterOptionItem ThisParent = Parent; Parent.ChildrenList.Add(this); } - else - { - SpacingNum += StaticSpacingNumPlus; - } return this; } @@ -196,5 +192,14 @@ public class BetterOptionIntItem : BetterOptionItem public override void ValueChanged(int id, OptionBehaviour optionBehaviour) { + if (IsParent) + { + bool Bool = ShowChildrenCondition(); + foreach (var item in ChildrenList) + { + item.obj.SetActive(Bool); + } + UpdatePositions(); + } } } diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index 9f5a6fc..61b5422 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -1,4 +1,5 @@ -using TMPro; +using BetterAmongUs.Patches; +using TMPro; using UnityEngine; namespace BetterAmongUs; @@ -16,11 +17,48 @@ public class BetterOptionItem public OptionBehaviour? Option; public string? Name = "None"; public TextMeshPro? TitleText; + public GameObject? obj; + public BetterOptionItem? ThisParent; public bool IsParent => ChildrenList.Count > 0; public List ChildrenList = []; public virtual bool ShowChildrenCondition() => false; + public static void UpdatePositions() + { + SpacingNum = 0f; + + foreach (var item in BetterOptionItems) + { + try + { + item.obj.transform.SetLocalY(2f); + + SpacingNum += item switch + { + BetterOptionHeaderItem => 0.1f, + BetterOptionDividerItem => 0.15f, + _ => 0f, + }; + + item.obj.transform.SetLocalY(2f - 1f * SpacingNum); + + if (item.obj.active == false) continue; + + SpacingNum += item switch + { + BetterOptionHeaderItem => 0.75f, + BetterOptionDividerItem => 0.45f, + _ => 0.45f, + }; + } + catch { } + } + + GameSettingMenuPatch.BetterSettingsTab.scrollBar.SetYBoundsMax(1.25f * SpacingNum / 2); + GameSettingMenuPatch.BetterSettingsTab.scrollBar.ScrollRelative(new(0f, 0f)); + } + public void SetUp(OptionBehaviour optionBehaviour) { SetData(optionBehaviour); diff --git a/Modules/OptionItems/BetterOptionStringItem.cs b/Modules/OptionItems/BetterOptionStringItem.cs index 311cf9c..41de076 100644 --- a/Modules/OptionItems/BetterOptionStringItem.cs +++ b/Modules/OptionItems/BetterOptionStringItem.cs @@ -4,7 +4,6 @@ namespace BetterAmongUs; public class BetterOptionStringItem : BetterOptionItem { - public BetterOptionItem? ThisParent; private StringOption? ThisOption; public string[] Values = []; public int CurrentValue; @@ -28,7 +27,7 @@ public class BetterOptionStringItem : BetterOptionItem } StringOption optionBehaviour = UnityEngine.Object.Instantiate(gameOptionsMenu.stringOptionOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); - optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f); + optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f, -2f); SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); @@ -60,6 +59,7 @@ public class BetterOptionStringItem : BetterOptionItem AdjustButtonsActiveState(); BetterOptionItems.Add(this); + obj = optionBehaviour.gameObject; if (Parent != null) { @@ -68,10 +68,6 @@ public class BetterOptionStringItem : BetterOptionItem ThisParent = Parent; Parent.ChildrenList.Add(this); } - else - { - SpacingNum += StaticSpacingNumPlus; - } return this; } @@ -165,5 +161,14 @@ public class BetterOptionStringItem : BetterOptionItem public override void ValueChanged(int id, OptionBehaviour optionBehaviour) { + if (IsParent) + { + bool Bool = ShowChildrenCondition(); + foreach (var item in ChildrenList) + { + item.obj.SetActive(Bool); + } + UpdatePositions(); + } } } diff --git a/Modules/OptionItems/NoneOption/BetterOptionDividerItem.cs b/Modules/OptionItems/NoneOption/BetterOptionDividerItem.cs index abdf623..26d794e 100644 --- a/Modules/OptionItems/NoneOption/BetterOptionDividerItem.cs +++ b/Modules/OptionItems/NoneOption/BetterOptionDividerItem.cs @@ -11,13 +11,11 @@ public class BetterOptionDividerItem : BetterOptionItem return this; } - SpacingNum += 0.15f; - Tab = gameOptionsMenu; Name = "Divider"; CategoryHeaderMasked categoryHeaderMasked = UnityEngine.Object.Instantiate(gameOptionsMenu.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f; - categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, 2f - StaticSpacingNum * SpacingNum, -2f); + categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, 2f, -2f); UnityEngine.Object.Destroy(categoryHeaderMasked.Background.gameObject); UnityEngine.Object.Destroy(categoryHeaderMasked.Title.gameObject); if (categoryHeaderMasked.Divider != null) @@ -25,7 +23,8 @@ public class BetterOptionDividerItem : BetterOptionItem categoryHeaderMasked.Divider.material.SetInt(PlayerMaterial.MaskLayer, maskLayer); } - SpacingNum += 0.45f; + BetterOptionItems.Add(this); + obj = categoryHeaderMasked.gameObject; return this; } diff --git a/Modules/OptionItems/NoneOption/BetterOptionHeaderItem.cs b/Modules/OptionItems/NoneOption/BetterOptionHeaderItem.cs index 34cae00..2f903f6 100644 --- a/Modules/OptionItems/NoneOption/BetterOptionHeaderItem.cs +++ b/Modules/OptionItems/NoneOption/BetterOptionHeaderItem.cs @@ -11,13 +11,11 @@ public class BetterOptionHeaderItem : BetterOptionItem return this; } - SpacingNum += 0.1f; - Tab = gameOptionsMenu; Name = name; CategoryHeaderMasked categoryHeaderMasked = UnityEngine.Object.Instantiate(gameOptionsMenu.categoryHeaderOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f; - categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, 2f - StaticSpacingNum * SpacingNum, -2f); + categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, 2f, -2f); categoryHeaderMasked.Title.text = name; categoryHeaderMasked.Background.material.SetInt(PlayerMaterial.MaskLayer, maskLayer); if (categoryHeaderMasked.Divider != null) @@ -27,7 +25,8 @@ public class BetterOptionHeaderItem : BetterOptionItem categoryHeaderMasked.Title.fontMaterial.SetFloat("_StencilComp", 3f); categoryHeaderMasked.Title.fontMaterial.SetFloat("_Stencil", maskLayer); - SpacingNum += 0.75f; + BetterOptionItems.Add(this); + obj = categoryHeaderMasked.gameObject; return this; } diff --git a/Modules/OptionItems/NoneOption/BetterOptionTitleItem.cs b/Modules/OptionItems/NoneOption/BetterOptionTitleItem.cs index a9a2d04..7b44c07 100644 --- a/Modules/OptionItems/NoneOption/BetterOptionTitleItem.cs +++ b/Modules/OptionItems/NoneOption/BetterOptionTitleItem.cs @@ -12,9 +12,8 @@ public class BetterOptionTitleItem : BetterOptionItem } ToggleOption optionBehaviour = UnityEngine.Object.Instantiate(gameOptionsMenu.checkboxOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); - optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f); + optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f, -2f); SetUp(optionBehaviour); - SpacingNum += StaticSpacingNumPlus; UnityEngine.Object.Destroy(optionBehaviour.CheckMark.transform.parent.gameObject); UnityEngine.Object.Destroy(optionBehaviour.GetComponent()); @@ -40,6 +39,8 @@ public class BetterOptionTitleItem : BetterOptionItem TitleText = optionBehaviour.TitleText; BetterOptionItems.Add(this); + obj = optionBehaviour.gameObject; + return this; } diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index b8f2ce4..aeaf7c1 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -29,7 +29,6 @@ static class GameSettingMenuPatch public static void SetupSettings(bool IsPreload = false) { - BetterOptionItem.SpacingNum = 0; BetterOptionItem.BetterOptionItems.Clear(); TitleList.Clear(); @@ -56,6 +55,10 @@ static class GameSettingMenuPatch TitleList.Add(new BetterOptionDividerItem().Create(BetterSettingsTab)); TitleList.Add(new BetterOptionTitleItem().Create(BetterSettingsTab, $"Experimental")); BetterGameSettings.ExperimentalDetectInvalidSabotage = new BetterOptionCheckboxItem().Create(100000, BetterSettingsTab, "Detect Invalid Sabotages", false); + new BetterOptionCheckboxItem().Create(10000, BetterSettingsTab, "CheckBox Test", true, BetterGameSettings.ExperimentalDetectInvalidSabotage); + new BetterOptionStringItem().Create(10001, BetterSettingsTab, "String Test", ["Test 1", "Test 2", "Test 3"], 0, BetterGameSettings.ExperimentalDetectInvalidSabotage); + new BetterOptionFloatItem().Create(10002, BetterSettingsTab, "Float Test 1", [0f, 180f, 2.5f], 0f, "", "", BetterGameSettings.ExperimentalDetectInvalidSabotage); + new BetterOptionIntItem().Create(10003, BetterSettingsTab, "Int Test", [0, 5, 1], 0, "", "", BetterGameSettings.ExperimentalDetectInvalidSabotage); } // Gameplay Settings @@ -76,18 +79,12 @@ static class GameSettingMenuPatch } /* - new BetterOptionCheckboxItem().Create(0, BetterSettingsTab, "CheckBox Test", true); - new BetterOptionStringItem().Create(1, BetterSettingsTab, "String Test", ["Test 1", "Test 2", "Test 3"]); - new BetterOptionFloatItem().Create(2, BetterSettingsTab, "Float Test 1", [0f, 180f, 2.5f], 0f, ""); - new BetterOptionIntItem().Create(5, BetterSettingsTab, "Int Test", [0, 5, 1], 0, ""); + new BetterOptionCheckboxItem().Create(10000, BetterSettingsTab, "CheckBox Test", true); + new BetterOptionStringItem().Create(10001, BetterSettingsTab, "String Test", ["Test 1", "Test 2", "Test 3"], 0); + new BetterOptionFloatItem().Create(10002, BetterSettingsTab, "Float Test 1", [0f, 180f, 2.5f], 0f, "", ""); + new BetterOptionIntItem().Create(10003, BetterSettingsTab, "Int Test", [0, 5, 1], 0, "", ""); new BetterOptionHeaderItem().Create(BetterSettingsTab, "Test Settings 2"); */ - - if (BetterSettingsTab != null) - { - BetterSettingsTab.scrollBar.SetYBoundsMax(1.25f * BetterOptionItem.SpacingNum / 2); - BetterSettingsTab.InitializeControllerNavigation(); - } } private static void Initialize() @@ -102,8 +99,15 @@ static class GameSettingMenuPatch { item.TitleText.text = item.Name; } + + if (item.ThisParent != null) + { + item.obj.SetActive(item.ThisParent.ShowChildrenCondition()); + } } } + + BetterOptionItem.UpdatePositions(); }, 0.005f, shoudLog: false); } @@ -156,6 +160,7 @@ static class GameSettingMenuPatch BetterSettingsButton.OnClick.AddListener(new Action(() => { __instance.ChangeTab(3, false); + BetterOptionItem.UpdatePositions(); })); BetterSettingsTab = UnityEngine.Object.Instantiate(__instance.GameSettingsTab, __instance.GameSettingsTab.transform.parent); diff --git a/main.cs b/main.cs index 2db0077..a5f722d 100644 --- a/main.cs +++ b/main.cs @@ -27,8 +27,8 @@ public class Main : BasePlugin public const string HotfixNum = "0"; public const bool IsHotFix = false; public const string PluginGuid = "com.d1gq.betteramongus"; - public const string PluginVersion = "1.1.0"; - public const string ReleaseDate = "08.24.2024"; // mm/dd/yyyy + public const string PluginVersion = "1.1.1"; + public const string ReleaseDate = "08.25.2024"; // mm/dd/yyyy public const string Github = "https://github.com/D1GQ/BetterAmongUs-Public"; public const string Discord = "https://discord.gg/vjYrXpzNAn"; From f8c09e62d306a697dbc7d21cf1ff9bf8535f44ea Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 22:04:03 -0500 Subject: [PATCH 16/34] remove test settings --- Patches/GameSettingMenuPatch.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index aeaf7c1..e23a316 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -55,10 +55,6 @@ static class GameSettingMenuPatch TitleList.Add(new BetterOptionDividerItem().Create(BetterSettingsTab)); TitleList.Add(new BetterOptionTitleItem().Create(BetterSettingsTab, $"Experimental")); BetterGameSettings.ExperimentalDetectInvalidSabotage = new BetterOptionCheckboxItem().Create(100000, BetterSettingsTab, "Detect Invalid Sabotages", false); - new BetterOptionCheckboxItem().Create(10000, BetterSettingsTab, "CheckBox Test", true, BetterGameSettings.ExperimentalDetectInvalidSabotage); - new BetterOptionStringItem().Create(10001, BetterSettingsTab, "String Test", ["Test 1", "Test 2", "Test 3"], 0, BetterGameSettings.ExperimentalDetectInvalidSabotage); - new BetterOptionFloatItem().Create(10002, BetterSettingsTab, "Float Test 1", [0f, 180f, 2.5f], 0f, "", "", BetterGameSettings.ExperimentalDetectInvalidSabotage); - new BetterOptionIntItem().Create(10003, BetterSettingsTab, "Int Test", [0, 5, 1], 0, "", "", BetterGameSettings.ExperimentalDetectInvalidSabotage); } // Gameplay Settings From af0bb71c771f007f4acc4a4598bef484c1ed5002 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 22:15:20 -0500 Subject: [PATCH 17/34] fix --- Modules/BetterDataManager.cs | 45 ++++++++++++++----- .../OptionItems/BetterOptionCheckboxItem.cs | 2 +- Modules/OptionItems/BetterOptionFloatItem.cs | 2 +- Modules/OptionItems/BetterOptionIntItem.cs | 2 +- Modules/OptionItems/BetterOptionStringItem.cs | 2 +- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/Modules/BetterDataManager.cs b/Modules/BetterDataManager.cs index 93418c6..18c3fb9 100644 --- a/Modules/BetterDataManager.cs +++ b/Modules/BetterDataManager.cs @@ -173,46 +173,67 @@ class BetterDataManager return false; } - public static bool LoadBoolSetting(int id) + public static bool LoadBoolSetting(int id, bool Default = false) { string filePath = SettingsFile; string json = File.ReadAllText(filePath); var jsonData = JsonSerializer.Deserialize>(json) ?? new Dictionary(); - if (jsonData.ContainsKey(id.ToString())) + try { - return bool.Parse(jsonData[id.ToString()]); + if (jsonData.ContainsKey(id.ToString())) + { + return bool.Parse(jsonData[id.ToString()]); + } + } + catch + { + SaveSetting(id, Default.ToString()); } - return false; + return Default; } - public static float LoadFloatSetting(int id) + public static float LoadFloatSetting(int id, float Default = 0f) { string filePath = SettingsFile; string json = File.ReadAllText(filePath); var jsonData = JsonSerializer.Deserialize>(json) ?? new Dictionary(); - if (jsonData.ContainsKey(id.ToString())) + try { - return float.Parse(jsonData[id.ToString()]); + if (jsonData.ContainsKey(id.ToString())) + { + return float.Parse(jsonData[id.ToString()]); + } + } + catch + { + SaveSetting(id, Default.ToString()); } - return -1f; + return Default; } - public static int LoadIntSetting(int id) + public static int LoadIntSetting(int id, int Default = 0) { string filePath = SettingsFile; string json = File.ReadAllText(filePath); var jsonData = JsonSerializer.Deserialize>(json) ?? new Dictionary(); - if (jsonData.ContainsKey(id.ToString())) + try { - return int.Parse(jsonData[id.ToString()]); + if (jsonData.ContainsKey(id.ToString())) + { + return int.Parse(jsonData[id.ToString()]); + } + } + catch + { + SaveSetting(id, Default.ToString()); } - return -1; + return Default; } public static void SaveBanList(string friendCode = "", string hashPUID = "") diff --git a/Modules/OptionItems/BetterOptionCheckboxItem.cs b/Modules/OptionItems/BetterOptionCheckboxItem.cs index 45a5898..140458d 100644 --- a/Modules/OptionItems/BetterOptionCheckboxItem.cs +++ b/Modules/OptionItems/BetterOptionCheckboxItem.cs @@ -63,7 +63,7 @@ public class BetterOptionCheckboxItem : BetterOptionItem { if (ThisOption == null) return; - var Bool = BetterDataManager.LoadBoolSetting(Id); + var Bool = BetterDataManager.LoadBoolSetting(Id, DefaultValue); ThisOption.CheckMark.GetComponent().enabled = Bool; IsChecked = Bool; } diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index ace3bf4..78e3875 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -142,7 +142,7 @@ public class BetterOptionFloatItem : BetterOptionItem { if (BetterDataManager.CanLoadSetting(Id)) { - var Float = BetterDataManager.LoadFloatSetting(Id); + var Float = BetterDataManager.LoadFloatSetting(Id, DefaultValue); if (Float > floatRange.max || Float < floatRange.min) { diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index 759efd1..7a726f8 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -141,7 +141,7 @@ public class BetterOptionIntItem : BetterOptionItem { if (BetterDataManager.CanLoadSetting(Id)) { - var Int = BetterDataManager.LoadIntSetting(Id); + var Int = BetterDataManager.LoadIntSetting(Id, DefaultValue); if (Int > intRange.max || Int < intRange.min) { diff --git a/Modules/OptionItems/BetterOptionStringItem.cs b/Modules/OptionItems/BetterOptionStringItem.cs index 41de076..132394a 100644 --- a/Modules/OptionItems/BetterOptionStringItem.cs +++ b/Modules/OptionItems/BetterOptionStringItem.cs @@ -122,7 +122,7 @@ public class BetterOptionStringItem : BetterOptionItem { if (BetterDataManager.CanLoadSetting(Id)) { - var Int = BetterDataManager.LoadIntSetting(Id); + var Int = BetterDataManager.LoadIntSetting(Id, DefaultValue); if (Int > Values.Length - 1 || Int < 0) { From 27566e5d1a24ebca1f20c5f2304984dfc74f0d2d Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 25 Aug 2024 22:48:52 -0500 Subject: [PATCH 18/34] fix --- Modules/OptionItems/BetterOptionFloatItem.cs | 2 ++ Modules/OptionItems/BetterOptionIntItem.cs | 2 ++ Modules/OptionItems/BetterOptionStringItem.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index 78e3875..eec5013 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -46,6 +46,8 @@ public class BetterOptionFloatItem : BetterOptionItem optionBehaviour.MinusBtn.OnClick.RemoveAllListeners(); optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => Increase())); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => Decrease())); + optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); + optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index 7a726f8..a0dd3c5 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -45,6 +45,8 @@ public class BetterOptionIntItem : BetterOptionItem optionBehaviour.MinusBtn.OnClick.RemoveAllListeners(); optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => Increase())); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => Decrease())); + optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); + optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); diff --git a/Modules/OptionItems/BetterOptionStringItem.cs b/Modules/OptionItems/BetterOptionStringItem.cs index 132394a..a8ef696 100644 --- a/Modules/OptionItems/BetterOptionStringItem.cs +++ b/Modules/OptionItems/BetterOptionStringItem.cs @@ -41,6 +41,8 @@ public class BetterOptionStringItem : BetterOptionItem optionBehaviour.MinusBtn.OnClick.RemoveAllListeners(); optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => Increase())); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => Decrease())); + optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); + optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); From 4cd1f794d0df6bf6f458e1e5356c46c1f1d2d678 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 11:01:42 -0500 Subject: [PATCH 19/34] Get Platform --- Patches/VersionShowerPatch.cs | 2 +- main.cs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Patches/VersionShowerPatch.cs b/Patches/VersionShowerPatch.cs index f3a489e..4bc0954 100644 --- a/Patches/VersionShowerPatch.cs +++ b/Patches/VersionShowerPatch.cs @@ -9,6 +9,6 @@ public class VersionShowerPatch [HarmonyPostfix] public static void Postfix(VersionShower __instance) { - __instance.text.text = $"♻BetterAmongUs♻ {Main.GetVersionText()} - " + __instance.text.text; + __instance.text.text = $"♻BetterAmongUs♻ {Main.GetVersionText()} ~ {Utils.GetPlatformName(Main.PlatformData.Platform)} " + __instance.text.text; } } diff --git a/main.cs b/main.cs index a5f722d..8db4991 100644 --- a/main.cs +++ b/main.cs @@ -84,6 +84,8 @@ public class Main : BasePlugin public static string BetterAmongUsVersion => PluginVersion; public static string AmongUsVersion => Application.version; + public static PlatformSpecificData PlatformData => Constants.GetPlatformData(); + public static List SupportedAmongUsVersions = [ "2024.8.13", @@ -143,7 +145,7 @@ public class Main : BasePlugin BetterDataManager.LoadData(); LoadOptions(); - if (File.Exists(Path.Combine($"{Environment.CurrentDirectory}/Among Us_Data/Plugins/x86", "steam_api.dll"))) + if (PlatformData.Platform == Platforms.StandaloneSteamPC) File.WriteAllText(Path.Combine(Environment.CurrentDirectory, "steam_appid.txt"), "945360"); if (File.Exists(Path.Combine(BetterDataManager.filePathFolder, "better-log.txt"))) @@ -164,7 +166,7 @@ public class Main : BasePlugin string SupportedVersions = string.Empty; foreach (string text in SupportedAmongUsVersions.ToArray()) SupportedVersions += $"{text} "; - BetterAmongUs.Logger.Log($"BetterAmongUs {BetterAmongUsVersion}-{ReleaseDate} - [{AmongUsVersion} --> {SupportedVersions.Substring(0, SupportedVersions.Length - 1)}]"); + BetterAmongUs.Logger.Log($"BetterAmongUs {BetterAmongUsVersion}-{ReleaseDate} - [{AmongUsVersion} --> {SupportedVersions.Substring(0, SupportedVersions.Length - 1)}] {Utils.GetPlatformName(PlatformData.Platform)}"); } catch (Exception ex) { From c75e7737969536fa784d8af37dcfb52d9e320661 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 12:00:30 -0500 Subject: [PATCH 20/34] Show self setting condition --- Modules/OptionItems/BetterOptionCheckboxItem.cs | 7 +++++-- Modules/OptionItems/BetterOptionFloatItem.cs | 7 +++++-- Modules/OptionItems/BetterOptionIntItem.cs | 7 +++++-- Modules/OptionItems/BetterOptionItem.cs | 1 + Modules/OptionItems/BetterOptionStringItem.cs | 7 +++++-- Patches/GameSettingMenuPatch.cs | 2 +- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Modules/OptionItems/BetterOptionCheckboxItem.cs b/Modules/OptionItems/BetterOptionCheckboxItem.cs index 140458d..254daa9 100644 --- a/Modules/OptionItems/BetterOptionCheckboxItem.cs +++ b/Modules/OptionItems/BetterOptionCheckboxItem.cs @@ -8,13 +8,16 @@ public class BetterOptionCheckboxItem : BetterOptionItem private bool? IsChecked; public override bool ShowChildrenCondition() => IsChecked == true; + public override bool SelfShowCondition() => ShowCondition != null ? ShowCondition() : base.SelfShowCondition(); + public Func? ShowCondition = null; - public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, bool DefaultValue = true, BetterOptionItem Parent = null) + public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, bool DefaultValue = true, BetterOptionItem? Parent = null, Func? selfShowCondition = null) { Id = id; Tab = gameOptionsMenu; Name = name; IsChecked = DefaultValue; + ShowCondition = selfShowCondition; if (gameOptionsMenu == null) { @@ -104,7 +107,7 @@ public class BetterOptionCheckboxItem : BetterOptionItem bool Bool = ShowChildrenCondition(); foreach (var item in ChildrenList) { - item.obj.SetActive(Bool); + item.obj.SetActive(Bool && item.SelfShowCondition()); } UpdatePositions(); } diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index eec5013..c7c25c6 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -13,8 +13,10 @@ public class BetterOptionFloatItem : BetterOptionItem private string? PreFix; public override bool ShowChildrenCondition() => CurrentValue > floatRange.min; + public override bool SelfShowCondition() => ShowCondition != null ? ShowCondition() : base.SelfShowCondition(); + public Func? ShowCondition = null; - public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, float[] values, float DefaultValue, string preFix = "", string postFix = "", BetterOptionItem Parent = null) + public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, float[] values, float DefaultValue, string preFix = "", string postFix = "", BetterOptionItem? Parent = null, Func? selfShowCondition = null) { Id = id; floatRange = new(values[0], values[1]); @@ -22,6 +24,7 @@ public class BetterOptionFloatItem : BetterOptionItem if (DefaultValue < floatRange.min) DefaultValue = floatRange.min; if (DefaultValue > floatRange.max) DefaultValue = floatRange.max; CurrentValue = DefaultValue; + ShowCondition = selfShowCondition; if (gameOptionsMenu == null) { @@ -200,7 +203,7 @@ public class BetterOptionFloatItem : BetterOptionItem bool Bool = ShowChildrenCondition(); foreach (var item in ChildrenList) { - item.obj.SetActive(Bool); + item.obj.SetActive(Bool && item.SelfShowCondition()); } UpdatePositions(); } diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index a0dd3c5..ffe2242 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -12,8 +12,10 @@ public class BetterOptionIntItem : BetterOptionItem private string? PreFix; public override bool ShowChildrenCondition() => CurrentValue > intRange.min; + public override bool SelfShowCondition() => ShowCondition != null ? ShowCondition() : base.SelfShowCondition(); + public Func? ShowCondition = null; - public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, int[] values, int DefaultValue, string preFix = "", string postFix = "", BetterOptionItem Parent = null) + public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, int[] values, int DefaultValue, string preFix = "", string postFix = "", BetterOptionItem? Parent = null, Func? selfShowCondition = null) { Id = id; intRange = new(values[0], values[1]); @@ -21,6 +23,7 @@ public class BetterOptionIntItem : BetterOptionItem if (DefaultValue < intRange.min) DefaultValue = intRange.min; if (DefaultValue > intRange.max) DefaultValue = intRange.max; CurrentValue = DefaultValue; + ShowCondition = selfShowCondition; if (gameOptionsMenu == null) { @@ -199,7 +202,7 @@ public class BetterOptionIntItem : BetterOptionItem bool Bool = ShowChildrenCondition(); foreach (var item in ChildrenList) { - item.obj.SetActive(Bool); + item.obj.SetActive(Bool && item.SelfShowCondition()); } UpdatePositions(); } diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index 61b5422..14c00c4 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -23,6 +23,7 @@ public class BetterOptionItem public bool IsParent => ChildrenList.Count > 0; public List ChildrenList = []; public virtual bool ShowChildrenCondition() => false; + public virtual bool SelfShowCondition() => true; public static void UpdatePositions() { diff --git a/Modules/OptionItems/BetterOptionStringItem.cs b/Modules/OptionItems/BetterOptionStringItem.cs index a8ef696..8306f33 100644 --- a/Modules/OptionItems/BetterOptionStringItem.cs +++ b/Modules/OptionItems/BetterOptionStringItem.cs @@ -9,8 +9,10 @@ public class BetterOptionStringItem : BetterOptionItem public int CurrentValue; public override bool ShowChildrenCondition() => CurrentValue > 0; + public override bool SelfShowCondition() => ShowCondition != null ? ShowCondition() : base.SelfShowCondition(); + public Func? ShowCondition = null; - public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, string[] strings, int DefaultValue = 0, BetterOptionItem Parent = null) + public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, string[] strings, int DefaultValue = 0, BetterOptionItem? Parent = null, Func? selfShowCondition = null) { Id = id; Values = strings; @@ -19,6 +21,7 @@ public class BetterOptionStringItem : BetterOptionItem if (DefaultValue < 0) DefaultValue = 0; if (DefaultValue > Values.Length) DefaultValue = Values.Length; CurrentValue = DefaultValue; + ShowCondition = selfShowCondition; if (gameOptionsMenu == null) { @@ -168,7 +171,7 @@ public class BetterOptionStringItem : BetterOptionItem bool Bool = ShowChildrenCondition(); foreach (var item in ChildrenList) { - item.obj.SetActive(Bool); + item.obj.SetActive(Bool && item.SelfShowCondition()); } UpdatePositions(); } diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index e23a316..b8c217f 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -98,7 +98,7 @@ static class GameSettingMenuPatch if (item.ThisParent != null) { - item.obj.SetActive(item.ThisParent.ShowChildrenCondition()); + item.obj.SetActive(item.ThisParent.ShowChildrenCondition() && item.SelfShowCondition()); } } } From 16d0168e39a683baa9533a4a779a8f715cada0cc Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 14:10:47 -0500 Subject: [PATCH 21/34] Add player option --- Modules/OptionItems/BetterOptionItem.cs | 2 + Modules/OptionItems/BetterOptionPlayerItem.cs | 169 ++++++++++++++++++ Patches/GameSettingMenuPatch.cs | 9 + 3 files changed, 180 insertions(+) create mode 100644 Modules/OptionItems/BetterOptionPlayerItem.cs diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index 14c00c4..7704504 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -8,6 +8,8 @@ public class BetterOptionItem { public float StaticSpacingNum => 1f; public float StaticSpacingNumPlus => 0.45f; + public static Dictionary TempPlayerOptionData = []; + public static int TempPlayerOptionDataNum = 0; public static List BetterOptionItems = []; public static float SpacingNum = 0; diff --git a/Modules/OptionItems/BetterOptionPlayerItem.cs b/Modules/OptionItems/BetterOptionPlayerItem.cs new file mode 100644 index 0000000..6c86813 --- /dev/null +++ b/Modules/OptionItems/BetterOptionPlayerItem.cs @@ -0,0 +1,169 @@ +using System.Dynamic; +using UnityEngine; + +namespace BetterAmongUs; + +public class BetterOptionPlayerItem : BetterOptionItem +{ + private PlayerOption? ThisOption; + public int CurrentIndex = -1; + + public override bool ShowChildrenCondition() => CurrentIndex > -1; + public override bool SelfShowCondition() => ShowCondition != null ? ShowCondition() : base.SelfShowCondition(); + public Func? ShowCondition = null; + + public BetterOptionItem Create(GameOptionsMenu gameOptionsMenu, string name, BetterOptionItem? Parent = null, Func? selfShowCondition = null) + { + Id = TempPlayerOptionDataNum + 1; + Tab = gameOptionsMenu; + Name = name; + ShowCondition = selfShowCondition; + + if (gameOptionsMenu == null) + { + return this; + } + + PlayerOption optionBehaviour = UnityEngine.Object.Instantiate(gameOptionsMenu.playerOptionOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); + optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f, -2f); + SetUp(optionBehaviour); + optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(0, option)); + + // Fix Game Crash + foreach (RulesCategory rulesCategory in GameManager.Instance.GameSettingsList.AllCategories) + { + optionBehaviour.data = rulesCategory.AllGameSettings.ToArray().FirstOrDefault(item => item.Type == OptionTypes.Player); + } + + optionBehaviour.PlusBtn.OnClick.RemoveAllListeners(); + optionBehaviour.MinusBtn.OnClick.RemoveAllListeners(); + optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => Increase())); + optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => Decrease())); + optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => ValueChanged(Id, optionBehaviour))); + optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => ValueChanged(Id, optionBehaviour))); + + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); + optionBehaviour.TitleText.enableAutoSizing = false; + optionBehaviour.TitleText.transform.SetLocalX(-1.5f); + optionBehaviour.TitleText.alignment = TMPro.TextAlignmentOptions.Right; + optionBehaviour.TitleText.enableWordWrapping = false; + optionBehaviour.TitleText.fontSize = 2.5f; + + // Set data + TitleText = optionBehaviour.TitleText; + Option = optionBehaviour; + ThisOption = optionBehaviour; + + BetterOptionItems.Add(this); + obj = optionBehaviour.gameObject; + + if (Parent != null) + { + optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + optionBehaviour.LabelBackground.transform.SetLocalZ(1f); + ThisParent = Parent; + Parent.ChildrenList.Add(this); + } + + TempPlayerOptionDataNum++; + + return this; + } + + private void AdjustButtonsActiveState() + { + if (ThisOption == null) return; + + if (CurrentIndex >= 0) + { + ThisOption.ValueText.text = Utils.PlayerFromId(CurrentIndex).GetPlayerNameAndColor(); + } + else + { + ThisOption.ValueText.text = "Random"; + } + + if (CurrentIndex >= Main.AllPlayerControls.Length - 1) + { + ThisOption.PlusBtn.SetInteractable(false); + ThisOption.MinusBtn.SetInteractable(true); + } + else if (CurrentIndex <= -1) + { + ThisOption.PlusBtn.SetInteractable(true); + ThisOption.MinusBtn.SetInteractable(false); + } + else + { + ThisOption.PlusBtn.SetInteractable(true); + ThisOption.MinusBtn.SetInteractable(true); + } + + TempPlayerOptionData[Id] = CurrentIndex; + } + + public void Increase() + { + if (CurrentIndex < Main.AllPlayerControls.Length) + { + CurrentIndex++; + AdjustButtonsActiveState(); + } + } + + public void Decrease() + { + if (CurrentIndex > -1) + { + CurrentIndex--; + AdjustButtonsActiveState(); + } + } + + public int Load() + { + if (TempPlayerOptionData.ContainsKey(Id)) + { + var saveindex = TempPlayerOptionData[Id]; + + if (saveindex != -1 && Utils.PlayerFromId(saveindex) == null) + saveindex = Main.AllPlayerControls.Length - 1; + + CurrentIndex = saveindex; + } + else + { + TempPlayerOptionData[Id] = -1; + CurrentIndex = TempPlayerOptionData[Id]; + } + + AdjustButtonsActiveState(); + + return CurrentIndex; + } + + public override int GetValue() => Load(); + + public override void SetData(OptionBehaviour optionBehaviour) + { + optionBehaviour.data = new BaseGameSetting + { + Title = StringNames.None, + Type = OptionTypes.Player, + }; + } + + public override void ValueChanged(int id, OptionBehaviour optionBehaviour) + { + if (IsParent) + { + bool Bool = ShowChildrenCondition(); + foreach (var item in ChildrenList) + { + item.obj.SetActive(Bool && item.SelfShowCondition()); + } + UpdatePositions(); + } + } +} diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index b8c217f..5807615 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -30,6 +30,7 @@ static class GameSettingMenuPatch public static void SetupSettings(bool IsPreload = false) { BetterOptionItem.BetterOptionItems.Clear(); + BetterOptionItem.TempPlayerOptionDataNum = 0; TitleList.Clear(); // Anti-Cheat Settings @@ -100,6 +101,14 @@ static class GameSettingMenuPatch { item.obj.SetActive(item.ThisParent.ShowChildrenCondition() && item.SelfShowCondition()); } + + if (item is BetterOptionPlayerItem player) + { + _ = new LateTask(() => + { + player.Load(); + }, 0.03f, shoudLog: false); + } } } From f7f7ff19b3397456bac6e85aad008efd8d841af7 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 14:42:35 -0500 Subject: [PATCH 22/34] fixes --- Modules/OptionItems/BetterOptionIntItem.cs | 2 +- Modules/OptionItems/BetterOptionItem.cs | 9 +++++++-- Modules/OptionItems/BetterOptionPlayerItem.cs | 7 ++++--- Patches/GameSettingMenuPatch.cs | 8 -------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index ffe2242..09e0fbf 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -191,7 +191,7 @@ public class BetterOptionIntItem : BetterOptionItem optionBehaviour.data = new BaseGameSetting { Title = StringNames.None, - Type = OptionTypes.Float, + Type = OptionTypes.Int, }; } diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index 7704504..319dc56 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -37,6 +37,13 @@ public class BetterOptionItem { item.obj.transform.SetLocalY(2f); + if (item.obj.active == false) continue; + + if (item is BetterOptionPlayerItem player) + { + player.Load(); + } + SpacingNum += item switch { BetterOptionHeaderItem => 0.1f, @@ -46,8 +53,6 @@ public class BetterOptionItem item.obj.transform.SetLocalY(2f - 1f * SpacingNum); - if (item.obj.active == false) continue; - SpacingNum += item switch { BetterOptionHeaderItem => 0.75f, diff --git a/Modules/OptionItems/BetterOptionPlayerItem.cs b/Modules/OptionItems/BetterOptionPlayerItem.cs index 6c86813..bd9be23 100644 --- a/Modules/OptionItems/BetterOptionPlayerItem.cs +++ b/Modules/OptionItems/BetterOptionPlayerItem.cs @@ -5,7 +5,7 @@ namespace BetterAmongUs; public class BetterOptionPlayerItem : BetterOptionItem { - private PlayerOption? ThisOption; + private NumberOption? ThisOption; public int CurrentIndex = -1; public override bool ShowChildrenCondition() => CurrentIndex > -1; @@ -24,7 +24,7 @@ public class BetterOptionPlayerItem : BetterOptionItem return this; } - PlayerOption optionBehaviour = UnityEngine.Object.Instantiate(gameOptionsMenu.playerOptionOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); + NumberOption optionBehaviour = UnityEngine.Object.Instantiate(gameOptionsMenu.numberOptionOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer); optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f, -2f); SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(0, option)); @@ -55,6 +55,7 @@ public class BetterOptionPlayerItem : BetterOptionItem Option = optionBehaviour; ThisOption = optionBehaviour; + Load(); BetterOptionItems.Add(this); obj = optionBehaviour.gameObject; @@ -150,7 +151,7 @@ public class BetterOptionPlayerItem : BetterOptionItem optionBehaviour.data = new BaseGameSetting { Title = StringNames.None, - Type = OptionTypes.Player, + Type = OptionTypes.Int, }; } diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 5807615..8d05a0d 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -101,14 +101,6 @@ static class GameSettingMenuPatch { item.obj.SetActive(item.ThisParent.ShowChildrenCondition() && item.SelfShowCondition()); } - - if (item is BetterOptionPlayerItem player) - { - _ = new LateTask(() => - { - player.Load(); - }, 0.03f, shoudLog: false); - } } } From 0243f75bfb1b7929f3d3dfe2f52842aadec85345 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 15:25:55 -0500 Subject: [PATCH 23/34] Set seekers setting --- Patches/GameSettingMenuPatch.cs | 24 ++++++++++++++++++++++++ Patches/RoleManagerPatch.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 8d05a0d..0599abd 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -20,6 +20,14 @@ class BetterGameSettings public static BetterOptionItem? ExperimentalDetectInvalidSabotage; } +class BetterGameSettingsTemp +{ + public static BetterOptionItem? HideAndSeekImp2; + public static BetterOptionItem? HideAndSeekImp3; + public static BetterOptionItem? HideAndSeekImp4; + public static BetterOptionItem? HideAndSeekImp5; +} + [HarmonyPatch(typeof(GameSettingMenu))] static class GameSettingMenuPatch { @@ -71,6 +79,22 @@ static class GameSettingMenuPatch new BetterOptionHeaderItem().Create(BetterSettingsTab, "Hide & Seek Settings"); new BetterOptionTitleItem().Create(BetterSettingsTab, $"Imposter"); BetterGameSettings.HideAndSeekImpNum = new BetterOptionIntItem().Create(1000, BetterSettingsTab, "# Seekers", [1, 5, 1], 1, "", ""); + BetterGameSettingsTemp.HideAndSeekImp2 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker 2", BetterGameSettings.HideAndSeekImpNum, new Func(() => + { + return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 1; + })); + BetterGameSettingsTemp.HideAndSeekImp3 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker 3", BetterGameSettings.HideAndSeekImpNum, new Func(() => + { + return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 2; + })); + BetterGameSettingsTemp.HideAndSeekImp4 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker 4", BetterGameSettings.HideAndSeekImpNum, new Func(() => + { + return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 3; + })); + BetterGameSettingsTemp.HideAndSeekImp5 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker 5", BetterGameSettings.HideAndSeekImpNum, new Func(() => + { + return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 4; + })); } } } diff --git a/Patches/RoleManagerPatch.cs b/Patches/RoleManagerPatch.cs index 4c2c684..4139265 100644 --- a/Patches/RoleManagerPatch.cs +++ b/Patches/RoleManagerPatch.cs @@ -288,6 +288,32 @@ public class RoleManagerPatch } } + var betterImpostorSettings = new int[] + { + -1, + BetterGameSettingsTemp.HideAndSeekImp2.GetValue(), + BetterGameSettingsTemp.HideAndSeekImp3.GetValue(), + BetterGameSettingsTemp.HideAndSeekImp4.GetValue(), + BetterGameSettingsTemp.HideAndSeekImp5.GetValue() + }; + + for (int i = 1; i < BetterGameSettings.HideAndSeekImpNum.GetInt(); i++) + { + int tempSetImpostor = betterImpostorSettings[i]; + + if (tempSetImpostor >= 0) + { + var player = Utils.PlayerFromId(tempSetImpostor); + if (player != null) + { + Impostors.Add(player); + player.RpcSetRole(RoleTypes.Impostor); + player.roleAssigned = true; + Logger.Log($"Settings Assigned {Utils.GetRoleName(RoleTypes.Impostor)} role to {player.Data.PlayerName}", "RoleManager"); + } + } + } + // Override player role assignment if (SetPlayerRole.Keys.Any()) { From 35f507cbd2419242e2b5fd5001441b68db4df971 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 16:05:08 -0500 Subject: [PATCH 24/34] fix --- Patches/RoleManagerPatch.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Patches/RoleManagerPatch.cs b/Patches/RoleManagerPatch.cs index 4139265..e3eea5b 100644 --- a/Patches/RoleManagerPatch.cs +++ b/Patches/RoleManagerPatch.cs @@ -306,10 +306,13 @@ public class RoleManagerPatch var player = Utils.PlayerFromId(tempSetImpostor); if (player != null) { - Impostors.Add(player); - player.RpcSetRole(RoleTypes.Impostor); - player.roleAssigned = true; - Logger.Log($"Settings Assigned {Utils.GetRoleName(RoleTypes.Impostor)} role to {player.Data.PlayerName}", "RoleManager"); + if (!Impostors.Contains(player)) + { + Impostors.Add(player); + player.RpcSetRole(RoleTypes.Impostor); + player.roleAssigned = true; + Logger.Log($"Settings Assigned {Utils.GetRoleName(RoleTypes.Impostor)} role to {player.Data.PlayerName}", "RoleManager"); + } } } } From af4b349573e4694f1d205ee10221fcda8dcf6081 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 16:24:24 -0500 Subject: [PATCH 25/34] fixs --- Modules/BetterHostManager.cs | 2 +- Modules/RPC.cs | 16 ++++++++++++++++ Patches/PlayerControlPatch.cs | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Modules/BetterHostManager.cs b/Modules/BetterHostManager.cs index 5c094ef..ec96af5 100644 --- a/Modules/BetterHostManager.cs +++ b/Modules/BetterHostManager.cs @@ -229,7 +229,7 @@ class BetterHostManager else if (player.BetterData().IsBetterUser) sbTopTag.Append("Better User+++"); } - else if (GameStates.IsInGamePlay && !GameStates.IsHideNSeek) + else if (GameStates.IsInGamePlay) { string Role = $"{player.GetRoleName()}"; if (!player.IsImpostorTeam() && player.myTasks.Count > 0) diff --git a/Modules/RPC.cs b/Modules/RPC.cs index 92bd469..0348b23 100644 --- a/Modules/RPC.cs +++ b/Modules/RPC.cs @@ -92,6 +92,22 @@ public static class MessageReaderUpdateSystemPatch internal static class RPC { + public static void RpcSyncSettings() + { + if (!AmongUsClient.Instance.AmHost) + { + return; + } + + foreach (var player in Main.AllPlayerControls.Where(pc => pc != PlayerControl.LocalPlayer)) + { + var optionsByteArray = GameOptionsManager.Instance.gameOptionsFactory.ToBytes(GameOptionsManager.Instance.CurrentGameOptions, false); + MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.SyncSettings, SendOption.None, player.GetClientId()); + messageWriter.WriteBytesAndSize(optionsByteArray); + AmongUsClient.Instance.FinishRpcImmediately(messageWriter); + } + } + public static void SendBetterCheck() { var flag = GameStates.IsHost && Main.BetterHost.Value; diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index 0e85158..5933a86 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -167,7 +167,7 @@ class PlayerControlPatch sbTagBottom.Append($"{friendCode}+++"); } - else if ((GameStates.IsInGame || GameStates.IsFreePlay) && !GameStates.IsHideNSeek) + else if (GameStates.IsInGame || GameStates.IsFreePlay) { if (player.IsImpostorTeammate() || player == PlayerControl.LocalPlayer || !PlayerControl.LocalPlayer.IsAlive() || DebugMenu.RevealRoles) { From e468d4fe29f885a26dcde423b3f967e824bbfb51 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 16:32:51 -0500 Subject: [PATCH 26/34] fixes to H&S --- Modules/BetterHostManager.cs | 16 +++++++++++++++- Patches/PlayerControlPatch.cs | 16 +++++++++++++++- Patches/RoleManagerPatch.cs | 4 +++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Modules/BetterHostManager.cs b/Modules/BetterHostManager.cs index ec96af5..d34d4bd 100644 --- a/Modules/BetterHostManager.cs +++ b/Modules/BetterHostManager.cs @@ -229,7 +229,7 @@ class BetterHostManager else if (player.BetterData().IsBetterUser) sbTopTag.Append("Better User+++"); } - else if (GameStates.IsInGamePlay) + else if (GameStates.IsInGamePlay && !GameStates.IsHideNSeek) { string Role = $"{player.GetRoleName()}"; if (!player.IsImpostorTeam() && player.myTasks.Count > 0) @@ -246,6 +246,20 @@ class BetterHostManager sbTopTag.Append($"{Role}+++"); } + else if (GameStates.IsInGamePlay) + { + if (player == target) + { + if (player.IsImpostorTeam()) + { + sbTopTag.Append($"Seeker+++"); + } + else + { + sbTopTag.Append($"Hider+++"); + } + } + } // Put +++ at the end of each tag static StringBuilder FormatInfo(StringBuilder source) diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index 5933a86..aa5a9b8 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -167,7 +167,7 @@ class PlayerControlPatch sbTagBottom.Append($"{friendCode}+++"); } - else if (GameStates.IsInGame || GameStates.IsFreePlay) + else if ((GameStates.IsInGame || GameStates.IsFreePlay) && !GameStates.IsHideNSeek) { if (player.IsImpostorTeammate() || player == PlayerControl.LocalPlayer || !PlayerControl.LocalPlayer.IsAlive() || DebugMenu.RevealRoles) { @@ -179,6 +179,20 @@ class PlayerControlPatch sbTagTop.Append($"{Role}+++"); } } + else if (GameStates.IsInGame || GameStates.IsFreePlay) + { + if (player == PlayerControl.LocalPlayer) + { + if (player.IsImpostorTeam()) + { + sbTagTop.Append($"Seeker+++"); + } + else + { + sbTagTop.Append($"Hider+++"); + } + } + } if (player.IsImpostorTeammate() && player != PlayerControl.LocalPlayer) { diff --git a/Patches/RoleManagerPatch.cs b/Patches/RoleManagerPatch.cs index e3eea5b..b6e5ec4 100644 --- a/Patches/RoleManagerPatch.cs +++ b/Patches/RoleManagerPatch.cs @@ -284,6 +284,7 @@ public class RoleManagerPatch Impostors.Add(player); player.RpcSetRole(RoleTypes.Impostor); player.roleAssigned = true; + NumImpostors--; Logger.Log($"Settings Assigned {Utils.GetRoleName(RoleTypes.Impostor)} role to {player.Data.PlayerName}", "RoleManager"); } } @@ -306,11 +307,12 @@ public class RoleManagerPatch var player = Utils.PlayerFromId(tempSetImpostor); if (player != null) { - if (!Impostors.Contains(player)) + if (NumImpostors > 0 && !Impostors.Contains(player)) { Impostors.Add(player); player.RpcSetRole(RoleTypes.Impostor); player.roleAssigned = true; + NumImpostors--; Logger.Log($"Settings Assigned {Utils.GetRoleName(RoleTypes.Impostor)} role to {player.Data.PlayerName}", "RoleManager"); } } From 7a4ab2d52b01a9e2dcd13f67fb808f087cbc0845 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 17:19:29 -0500 Subject: [PATCH 27/34] fix --- Modules/OptionItems/BetterOptionItem.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index 319dc56..835bf4a 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -59,11 +59,18 @@ public class BetterOptionItem BetterOptionDividerItem => 0.45f, _ => 0.45f, }; + + var parent = BetterOptionItems.FirstOrDefault(op => op.IsParent && op.ChildrenList.Contains(item)); + + if (parent != null && parent.ChildrenList.Last(op => op.Option.gameObject.active) == item) + { + SpacingNum += 0.25f; + } } catch { } } - GameSettingMenuPatch.BetterSettingsTab.scrollBar.SetYBoundsMax(1.25f * SpacingNum / 2); + GameSettingMenuPatch.BetterSettingsTab.scrollBar.SetYBoundsMax(1.5f * SpacingNum / 2); GameSettingMenuPatch.BetterSettingsTab.scrollBar.ScrollRelative(new(0f, 0f)); } From 4efc67547d02e90a68674f66a09b5456c30f0457 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 20:55:36 -0500 Subject: [PATCH 28/34] update settings looks --- .../OptionItems/BetterOptionCheckboxItem.cs | 20 +++++++++++++++-- Modules/OptionItems/BetterOptionFloatItem.cs | 2 +- Modules/OptionItems/BetterOptionIntItem.cs | 2 +- Modules/OptionItems/BetterOptionItem.cs | 2 +- Modules/OptionItems/BetterOptionPlayerItem.cs | 22 +++++++++++++++++-- Modules/OptionItems/BetterOptionStringItem.cs | 2 +- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Modules/OptionItems/BetterOptionCheckboxItem.cs b/Modules/OptionItems/BetterOptionCheckboxItem.cs index 254daa9..c8a6ac5 100644 --- a/Modules/OptionItems/BetterOptionCheckboxItem.cs +++ b/Modules/OptionItems/BetterOptionCheckboxItem.cs @@ -30,7 +30,7 @@ public class BetterOptionCheckboxItem : BetterOptionItem SetUp(optionBehaviour); optionBehaviour.OnValueChanged = new Action((option) => ValueChanged(id, option)); - optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 0.78f); optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); optionBehaviour.TitleText.enableAutoSizing = false; optionBehaviour.TitleText.transform.SetLocalX(-1.5f); @@ -51,7 +51,23 @@ public class BetterOptionCheckboxItem : BetterOptionItem if (Parent != null) { - optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + int Index = 1; + var TempParent = Parent; + + while (true) + { + if (TempParent.ThisParent != null) + { + TempParent = TempParent.ThisParent; + Index++; + } + else + { + break; + } + } + + optionBehaviour.LabelBackground.GetComponent().color -= new Color(0.1f, 0.1f, 0.1f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; Parent.ChildrenList.Add(this); diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index c7c25c6..ebd9df3 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -52,7 +52,7 @@ public class BetterOptionFloatItem : BetterOptionItem optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); - optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 0.78f); optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); optionBehaviour.TitleText.enableAutoSizing = false; optionBehaviour.TitleText.transform.SetLocalX(-1.5f); diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index 09e0fbf..658ebaa 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -51,7 +51,7 @@ public class BetterOptionIntItem : BetterOptionItem optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); - optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 0.78f); optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); optionBehaviour.TitleText.enableAutoSizing = false; optionBehaviour.TitleText.transform.SetLocalX(-1.5f); diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index 835bf4a..b4f340b 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -56,7 +56,7 @@ public class BetterOptionItem SpacingNum += item switch { BetterOptionHeaderItem => 0.75f, - BetterOptionDividerItem => 0.45f, + BetterOptionTitleItem => 0.50f, _ => 0.45f, }; diff --git a/Modules/OptionItems/BetterOptionPlayerItem.cs b/Modules/OptionItems/BetterOptionPlayerItem.cs index bd9be23..71ec9e7 100644 --- a/Modules/OptionItems/BetterOptionPlayerItem.cs +++ b/Modules/OptionItems/BetterOptionPlayerItem.cs @@ -42,7 +42,7 @@ public class BetterOptionPlayerItem : BetterOptionItem optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => ValueChanged(Id, optionBehaviour))); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => ValueChanged(Id, optionBehaviour))); - optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 0.78f); optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); optionBehaviour.TitleText.enableAutoSizing = false; optionBehaviour.TitleText.transform.SetLocalX(-1.5f); @@ -61,7 +61,25 @@ public class BetterOptionPlayerItem : BetterOptionItem if (Parent != null) { - optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + int Index = 1; + var TempParent = Parent; + + while (true) + { + if (TempParent.ThisParent != null) + { + TempParent = TempParent.ThisParent; + Index++; + } + else + { + break; + } + } + + optionBehaviour.LabelBackground.GetComponent().color -= new Color(0.25f, 0.25f, 0.25f, 0f) * Index; + optionBehaviour.LabelBackground.transform.localScale -= new Vector3(0.04f, 0f, 0f) * Index; + optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; Parent.ChildrenList.Add(this); diff --git a/Modules/OptionItems/BetterOptionStringItem.cs b/Modules/OptionItems/BetterOptionStringItem.cs index 8306f33..015d34b 100644 --- a/Modules/OptionItems/BetterOptionStringItem.cs +++ b/Modules/OptionItems/BetterOptionStringItem.cs @@ -47,7 +47,7 @@ public class BetterOptionStringItem : BetterOptionItem optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => ValueChanged(id, optionBehaviour))); - optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f); + optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 0.78f); optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f); optionBehaviour.TitleText.enableAutoSizing = false; optionBehaviour.TitleText.transform.SetLocalX(-1.5f); From 0ed96ab270e22855b53c81ae362e23cc572c98fb Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 21:35:13 -0500 Subject: [PATCH 29/34] sub settings --- Modules/OptionItems/BetterOptionItem.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index b4f340b..873713d 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -37,6 +37,12 @@ public class BetterOptionItem { item.obj.transform.SetLocalY(2f); + // Need to fix name not setting + if (item.ThisParent != null) + { + item.obj.SetActive(item.ThisParent.ShowChildrenCondition() && item.SelfShowCondition() && item.ThisParent.Option.gameObject.active); + } + if (item.obj.active == false) continue; if (item is BetterOptionPlayerItem player) @@ -64,7 +70,10 @@ public class BetterOptionItem if (parent != null && parent.ChildrenList.Last(op => op.Option.gameObject.active) == item) { - SpacingNum += 0.25f; + if (parent.ThisParent == null && !item.ChildrenList.Any(i => i.SelfShowCondition() == true)) + { + SpacingNum += 0.25f; + } } } catch { } From 025fd6d33b70639f64e65830fa027fae492a4181 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 23:16:08 -0500 Subject: [PATCH 30/34] fixes --- .../OptionItems/BetterOptionCheckboxItem.cs | 19 +++++++------------ Modules/OptionItems/BetterOptionFloatItem.cs | 13 ++++++++++++- Modules/OptionItems/BetterOptionIntItem.cs | 13 ++++++++++++- Modules/OptionItems/BetterOptionItem.cs | 9 ++++++--- Modules/OptionItems/BetterOptionPlayerItem.cs | 15 ++++----------- Modules/OptionItems/BetterOptionStringItem.cs | 13 ++++++++++++- Patches/GameSettingMenuPatch.cs | 7 ++----- 7 files changed, 55 insertions(+), 34 deletions(-) diff --git a/Modules/OptionItems/BetterOptionCheckboxItem.cs b/Modules/OptionItems/BetterOptionCheckboxItem.cs index c8a6ac5..8b15557 100644 --- a/Modules/OptionItems/BetterOptionCheckboxItem.cs +++ b/Modules/OptionItems/BetterOptionCheckboxItem.cs @@ -52,22 +52,17 @@ public class BetterOptionCheckboxItem : BetterOptionItem if (Parent != null) { int Index = 1; - var TempParent = Parent; + var tempParent = Parent; - while (true) + while (tempParent.ThisParent != null) { - if (TempParent.ThisParent != null) - { - TempParent = TempParent.ThisParent; - Index++; - } - else - { - break; - } + tempParent = tempParent.ThisParent; + Index++; } - optionBehaviour.LabelBackground.GetComponent().color -= new Color(0.1f, 0.1f, 0.1f, 0f) * Index; + optionBehaviour.LabelBackground.GetComponent().color -= new Color(0.25f, 0.25f, 0.25f, 0f) * Index; + optionBehaviour.LabelBackground.transform.localScale -= new Vector3(0.04f, 0f, 0f) * Index; + optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; Parent.ChildrenList.Add(this); diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index ebd9df3..73b2ee1 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -77,7 +77,18 @@ public class BetterOptionFloatItem : BetterOptionItem if (Parent != null) { - optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + int Index = 1; + var tempParent = Parent; + + while (tempParent.ThisParent != null) + { + tempParent = tempParent.ThisParent; + Index++; + } + + optionBehaviour.LabelBackground.GetComponent().color -= new Color(0.25f, 0.25f, 0.25f, 0f) * Index; + optionBehaviour.LabelBackground.transform.localScale -= new Vector3(0.04f, 0f, 0f) * Index; + optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; Parent.ChildrenList.Add(this); diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index 658ebaa..03931e3 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -76,7 +76,18 @@ public class BetterOptionIntItem : BetterOptionItem if (Parent != null) { - optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + int Index = 1; + var tempParent = Parent; + + while (tempParent.ThisParent != null) + { + tempParent = tempParent.ThisParent; + Index++; + } + + optionBehaviour.LabelBackground.GetComponent().color -= new Color(0.25f, 0.25f, 0.25f, 0f) * Index; + optionBehaviour.LabelBackground.transform.localScale -= new Vector3(0.04f, 0f, 0f) * Index; + optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; Parent.ChildrenList.Add(this); diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index 873713d..2a4c37b 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -40,11 +40,14 @@ public class BetterOptionItem // Need to fix name not setting if (item.ThisParent != null) { - item.obj.SetActive(item.ThisParent.ShowChildrenCondition() && item.SelfShowCondition() && item.ThisParent.Option.gameObject.active); + _ = new LateTask(() => + { + item.obj.SetActive(item.ThisParent.ShowChildrenCondition() && item.SelfShowCondition() && item.ThisParent.Option.gameObject.active); + }, 0.005f, shoudLog: false); + if (!(item.ThisParent.ShowChildrenCondition() && item.SelfShowCondition() && item.ThisParent.Option.gameObject.active)) + continue; } - if (item.obj.active == false) continue; - if (item is BetterOptionPlayerItem player) { player.Load(); diff --git a/Modules/OptionItems/BetterOptionPlayerItem.cs b/Modules/OptionItems/BetterOptionPlayerItem.cs index 71ec9e7..97054d5 100644 --- a/Modules/OptionItems/BetterOptionPlayerItem.cs +++ b/Modules/OptionItems/BetterOptionPlayerItem.cs @@ -62,19 +62,12 @@ public class BetterOptionPlayerItem : BetterOptionItem if (Parent != null) { int Index = 1; - var TempParent = Parent; + var tempParent = Parent; - while (true) + while (tempParent.ThisParent != null) { - if (TempParent.ThisParent != null) - { - TempParent = TempParent.ThisParent; - Index++; - } - else - { - break; - } + tempParent = tempParent.ThisParent; + Index++; } optionBehaviour.LabelBackground.GetComponent().color -= new Color(0.25f, 0.25f, 0.25f, 0f) * Index; diff --git a/Modules/OptionItems/BetterOptionStringItem.cs b/Modules/OptionItems/BetterOptionStringItem.cs index 015d34b..067b999 100644 --- a/Modules/OptionItems/BetterOptionStringItem.cs +++ b/Modules/OptionItems/BetterOptionStringItem.cs @@ -68,7 +68,18 @@ public class BetterOptionStringItem : BetterOptionItem if (Parent != null) { - optionBehaviour.LabelBackground.GetComponent().color = new Color(0.85f, 0.85f, 0.85f, 1f); + int Index = 1; + var tempParent = Parent; + + while (tempParent.ThisParent != null) + { + tempParent = tempParent.ThisParent; + Index++; + } + + optionBehaviour.LabelBackground.GetComponent().color -= new Color(0.25f, 0.25f, 0.25f, 0f) * Index; + optionBehaviour.LabelBackground.transform.localScale -= new Vector3(0.04f, 0f, 0f) * Index; + optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; Parent.ChildrenList.Add(this); diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 0599abd..4eba4c5 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -116,15 +116,12 @@ static class GameSettingMenuPatch { if (item != null) { + item.obj.SetActive(true); + if (item.TitleText != null) { item.TitleText.text = item.Name; } - - if (item.ThisParent != null) - { - item.obj.SetActive(item.ThisParent.ShowChildrenCondition() && item.SelfShowCondition()); - } } } From f943b64205bc0d03277a94d9bd9f1bd7cb838095 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Mon, 26 Aug 2024 23:49:52 -0500 Subject: [PATCH 31/34] fix --- .../OptionItems/BetterOptionCheckboxItem.cs | 3 ++- Modules/OptionItems/BetterOptionFloatItem.cs | 3 ++- Modules/OptionItems/BetterOptionIntItem.cs | 3 ++- Modules/OptionItems/BetterOptionItem.cs | 11 +--------- Modules/OptionItems/BetterOptionPlayerItem.cs | 15 ++++++++++++-- Modules/OptionItems/BetterOptionStringItem.cs | 3 ++- Patches/GameSettingMenuPatch.cs | 20 ++++++++++++------- 7 files changed, 35 insertions(+), 23 deletions(-) diff --git a/Modules/OptionItems/BetterOptionCheckboxItem.cs b/Modules/OptionItems/BetterOptionCheckboxItem.cs index 8b15557..b8695a0 100644 --- a/Modules/OptionItems/BetterOptionCheckboxItem.cs +++ b/Modules/OptionItems/BetterOptionCheckboxItem.cs @@ -65,6 +65,7 @@ public class BetterOptionCheckboxItem : BetterOptionItem optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; + IsChild = true; Parent.ChildrenList.Add(this); } @@ -113,7 +114,7 @@ public class BetterOptionCheckboxItem : BetterOptionItem IsChecked = !IsChecked; BetterDataManager.SaveSetting(Id, IsChecked.ToString()); - if (IsParent) + if (IsParent || IsChild) { bool Bool = ShowChildrenCondition(); foreach (var item in ChildrenList) diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index 73b2ee1..80bd1a8 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -91,6 +91,7 @@ public class BetterOptionFloatItem : BetterOptionItem optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; + IsChild = true; Parent.ChildrenList.Add(this); } @@ -209,7 +210,7 @@ public class BetterOptionFloatItem : BetterOptionItem public override void ValueChanged(int id, OptionBehaviour optionBehaviour) { - if (IsParent) + if (IsParent || IsChild) { bool Bool = ShowChildrenCondition(); foreach (var item in ChildrenList) diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index 03931e3..9f7e521 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -90,6 +90,7 @@ public class BetterOptionIntItem : BetterOptionItem optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; + IsChild = true; Parent.ChildrenList.Add(this); } @@ -208,7 +209,7 @@ public class BetterOptionIntItem : BetterOptionItem public override void ValueChanged(int id, OptionBehaviour optionBehaviour) { - if (IsParent) + if (IsParent || IsChild) { bool Bool = ShowChildrenCondition(); foreach (var item in ChildrenList) diff --git a/Modules/OptionItems/BetterOptionItem.cs b/Modules/OptionItems/BetterOptionItem.cs index 2a4c37b..cc57b3b 100644 --- a/Modules/OptionItems/BetterOptionItem.cs +++ b/Modules/OptionItems/BetterOptionItem.cs @@ -22,6 +22,7 @@ public class BetterOptionItem public GameObject? obj; public BetterOptionItem? ThisParent; + public bool IsChild = false; public bool IsParent => ChildrenList.Count > 0; public List ChildrenList = []; public virtual bool ShowChildrenCondition() => false; @@ -68,16 +69,6 @@ public class BetterOptionItem BetterOptionTitleItem => 0.50f, _ => 0.45f, }; - - var parent = BetterOptionItems.FirstOrDefault(op => op.IsParent && op.ChildrenList.Contains(item)); - - if (parent != null && parent.ChildrenList.Last(op => op.Option.gameObject.active) == item) - { - if (parent.ThisParent == null && !item.ChildrenList.Any(i => i.SelfShowCondition() == true)) - { - SpacingNum += 0.25f; - } - } } catch { } } diff --git a/Modules/OptionItems/BetterOptionPlayerItem.cs b/Modules/OptionItems/BetterOptionPlayerItem.cs index 97054d5..a270a5c 100644 --- a/Modules/OptionItems/BetterOptionPlayerItem.cs +++ b/Modules/OptionItems/BetterOptionPlayerItem.cs @@ -75,6 +75,7 @@ public class BetterOptionPlayerItem : BetterOptionItem optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; + IsChild = true; Parent.ChildrenList.Add(this); } @@ -155,7 +156,17 @@ public class BetterOptionPlayerItem : BetterOptionItem return CurrentIndex; } - public override int GetValue() => Load(); + public override int GetValue() + { + if (SelfShowCondition()) + { + return Load(); + } + else + { + return -1; + } + } public override void SetData(OptionBehaviour optionBehaviour) { @@ -168,7 +179,7 @@ public class BetterOptionPlayerItem : BetterOptionItem public override void ValueChanged(int id, OptionBehaviour optionBehaviour) { - if (IsParent) + if (IsParent || IsChild) { bool Bool = ShowChildrenCondition(); foreach (var item in ChildrenList) diff --git a/Modules/OptionItems/BetterOptionStringItem.cs b/Modules/OptionItems/BetterOptionStringItem.cs index 067b999..fa49fbf 100644 --- a/Modules/OptionItems/BetterOptionStringItem.cs +++ b/Modules/OptionItems/BetterOptionStringItem.cs @@ -82,6 +82,7 @@ public class BetterOptionStringItem : BetterOptionItem optionBehaviour.LabelBackground.transform.position += new Vector3(0.04f, 0f, 0f) * Index; optionBehaviour.LabelBackground.transform.SetLocalZ(1f); ThisParent = Parent; + IsChild = true; Parent.ChildrenList.Add(this); } @@ -177,7 +178,7 @@ public class BetterOptionStringItem : BetterOptionItem public override void ValueChanged(int id, OptionBehaviour optionBehaviour) { - if (IsParent) + if (IsParent || IsChild) { bool Bool = ShowChildrenCondition(); foreach (var item in ChildrenList) diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 4eba4c5..2e0dc6b 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -79,21 +79,27 @@ static class GameSettingMenuPatch new BetterOptionHeaderItem().Create(BetterSettingsTab, "Hide & Seek Settings"); new BetterOptionTitleItem().Create(BetterSettingsTab, $"Imposter"); BetterGameSettings.HideAndSeekImpNum = new BetterOptionIntItem().Create(1000, BetterSettingsTab, "# Seekers", [1, 5, 1], 1, "", ""); - BetterGameSettingsTemp.HideAndSeekImp2 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker 2", BetterGameSettings.HideAndSeekImpNum, new Func(() => + BetterGameSettingsTemp.HideAndSeekImp2 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker", BetterGameSettings.HideAndSeekImpNum, new Func(() => { return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 1; })); - BetterGameSettingsTemp.HideAndSeekImp3 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker 3", BetterGameSettings.HideAndSeekImpNum, new Func(() => + BetterGameSettingsTemp.HideAndSeekImp3 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker", BetterGameSettings.HideAndSeekImpNum, new Func(() => { - return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 2; + return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 2 + && BetterGameSettingsTemp.HideAndSeekImp2 is BetterOptionPlayerItem betterOption2 && betterOption2.CurrentIndex > -1; })); - BetterGameSettingsTemp.HideAndSeekImp4 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker 4", BetterGameSettings.HideAndSeekImpNum, new Func(() => + BetterGameSettingsTemp.HideAndSeekImp4 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker", BetterGameSettings.HideAndSeekImpNum, new Func(() => { - return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 3; + return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 3 + && BetterGameSettingsTemp.HideAndSeekImp2 is BetterOptionPlayerItem betterOption2 && betterOption2.CurrentIndex > -1 + && BetterGameSettingsTemp.HideAndSeekImp3 is BetterOptionPlayerItem betterOption3 && betterOption3.CurrentIndex > -1; })); - BetterGameSettingsTemp.HideAndSeekImp5 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker 5", BetterGameSettings.HideAndSeekImpNum, new Func(() => + BetterGameSettingsTemp.HideAndSeekImp5 = new BetterOptionPlayerItem().Create(BetterSettingsTab, "Seeker", BetterGameSettings.HideAndSeekImpNum, new Func(() => { - return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 4; + return BetterGameSettings.HideAndSeekImpNum is BetterOptionIntItem betterOption && betterOption.CurrentValue > 4 + && BetterGameSettingsTemp.HideAndSeekImp2 is BetterOptionPlayerItem betterOption2 && betterOption2.CurrentIndex > -1 + && BetterGameSettingsTemp.HideAndSeekImp3 is BetterOptionPlayerItem betterOption3 && betterOption3.CurrentIndex > -1 + && BetterGameSettingsTemp.HideAndSeekImp4 is BetterOptionPlayerItem betterOption4 && betterOption4.CurrentIndex > -1; })); } } From 119b3ec6ea820512050d9aa08343ced63cff32fc Mon Sep 17 00:00:00 2001 From: D1GQ Date: Tue, 27 Aug 2024 11:49:19 -0500 Subject: [PATCH 32/34] Role Algorithm Settings --- Patches/GameSettingMenuPatch.cs | 9 ++++ Patches/RoleManagerPatch.cs | 83 ++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 27 deletions(-) diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 2e0dc6b..8330bf6 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -16,6 +16,8 @@ class BetterGameSettings public static BetterOptionItem? DetectedLevelAbove; public static BetterOptionItem? DetectCheatClients; public static BetterOptionItem? DetectInvalidRPCs; + public static BetterOptionItem? RoleRandomizer; + public static BetterOptionItem? DesyncRoles; public static BetterOptionItem? ExperimentalDetectInvalidSabotage; } @@ -66,6 +68,13 @@ static class GameSettingMenuPatch BetterGameSettings.ExperimentalDetectInvalidSabotage = new BetterOptionCheckboxItem().Create(100000, BetterSettingsTab, "Detect Invalid Sabotages", false); } + if (IsPreload || GameStates.IsHost) + { + TitleList.Add(new BetterOptionHeaderItem().Create(BetterSettingsTab, "Role Algorithm Settings")); + BetterGameSettings.RoleRandomizer = new BetterOptionStringItem().Create(1100, BetterSettingsTab, "Randomizer", ["System.Random", "UnityEngine.Random"], 0); + BetterGameSettings.DesyncRoles = new BetterOptionCheckboxItem().Create(1200, BetterSettingsTab, "Desync Roles To Other Clients", true); + } + // Gameplay Settings { if (IsPreload || GameStates.IsHost) diff --git a/Patches/RoleManagerPatch.cs b/Patches/RoleManagerPatch.cs index b6e5ec4..7b67c8e 100644 --- a/Patches/RoleManagerPatch.cs +++ b/Patches/RoleManagerPatch.cs @@ -138,19 +138,22 @@ public class RoleManagerPatch player.RpcSetRole(role); // Desync role to other clients to prevent revealing the true role - if (IsImpostorRole(role) && role is not RoleTypes.Phantom) + if (BetterGameSettings.DesyncRoles.GetBool()) { - List messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId(), clientCheck); - messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Impostor)); - messageWriter.ForEach(mW => mW.Write(false)); - AmongUsClient.Instance.FinishRpcDesync(messageWriter); - } - else if (role is not RoleTypes.Noisemaker) - { - List messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId(), clientCheck); - messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Crewmate)); - messageWriter.ForEach(mW => mW.Write(false)); - AmongUsClient.Instance.FinishRpcDesync(messageWriter); + if (IsImpostorRole(role) && role is not RoleTypes.Phantom) + { + List messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId(), clientCheck); + messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Impostor)); + messageWriter.ForEach(mW => mW.Write(false)); + AmongUsClient.Instance.FinishRpcDesync(messageWriter); + } + else if (role is not RoleTypes.Noisemaker) + { + List messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId(), clientCheck); + messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Crewmate)); + messageWriter.ForEach(mW => mW.Write(false)); + AmongUsClient.Instance.FinishRpcDesync(messageWriter); + } } player.roleAssigned = true; @@ -190,14 +193,19 @@ public class RoleManagerPatch ImpostorRoles[kvp.Key]--; Impostors.Add(pc); pc.RpcSetRole(kvp.Key); + // Desync role to other clients to prevent revealing the true role - if (kvp.Key is not RoleTypes.Phantom) + if (BetterGameSettings.DesyncRoles.GetBool()) { - List messageWriter = AmongUsClient.Instance.StartRpcDesync(pc.NetId, (byte)RpcCalls.SetRole, SendOption.None, pc.GetClientId(), clientCheck); - messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Impostor)); - messageWriter.ForEach(mW => mW.Write(false)); - AmongUsClient.Instance.FinishRpcDesync(messageWriter); + if (kvp.Key is not RoleTypes.Phantom) + { + List messageWriter = AmongUsClient.Instance.StartRpcDesync(pc.NetId, (byte)RpcCalls.SetRole, SendOption.None, pc.GetClientId(), clientCheck); + messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Impostor)); + messageWriter.ForEach(mW => mW.Write(false)); + AmongUsClient.Instance.FinishRpcDesync(messageWriter); + } } + pc.roleAssigned = true; Logger.Log($"Assigned {Utils.GetRoleName(kvp.Key)} role to {pc.Data.PlayerName}", "RoleManager"); break; @@ -224,14 +232,19 @@ public class RoleManagerPatch CrewmateRoles[kvp.Key]--; Crewmates.Add(pc); pc.RpcSetRole(kvp.Key); + // Desync role to other clients to prevent revealing the true role - if (kvp.Key is not RoleTypes.Noisemaker) + if (BetterGameSettings.DesyncRoles.GetBool()) { - List messageWriter = AmongUsClient.Instance.StartRpcDesync(pc.NetId, (byte)RpcCalls.SetRole, SendOption.None, pc.GetClientId(), clientCheck); - messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Crewmate)); - messageWriter.ForEach(mW => mW.Write(false)); - AmongUsClient.Instance.FinishRpcDesync(messageWriter); + if (kvp.Key is not RoleTypes.Noisemaker) + { + List messageWriter = AmongUsClient.Instance.StartRpcDesync(pc.NetId, (byte)RpcCalls.SetRole, SendOption.None, pc.GetClientId(), clientCheck); + messageWriter.ForEach(mW => mW.Write((ushort)RoleTypes.Crewmate)); + messageWriter.ForEach(mW => mW.Write(false)); + AmongUsClient.Instance.FinishRpcDesync(messageWriter); + } } + pc.roleAssigned = true; Logger.Log($"Assigned {Utils.GetRoleName(kvp.Key)} role to {pc.Data.PlayerName}", "RoleManager"); break; @@ -438,11 +451,16 @@ public class RoleManagerPatch if (kvp.Value > 0 && RNG() <= GameOptionsManager.Instance.CurrentGameOptions.RoleOptions.GetChancePerGame(kvp.Key)) { player.RpcSetRole(kvp.Key); + // Desync role to other clients to prevent revealing the true role - List messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId(), clientCheck); - messageWriter.ForEach(mW => mW.Write((ushort)player.Data.Role.DefaultGhostRole)); - messageWriter.ForEach(mW => mW.Write(false)); - AmongUsClient.Instance.FinishRpcDesync(messageWriter); + if (BetterGameSettings.DesyncRoles.GetBool()) + { + List messageWriter = AmongUsClient.Instance.StartRpcDesync(player.NetId, (byte)RpcCalls.SetRole, SendOption.None, player.GetClientId(), clientCheck); + messageWriter.ForEach(mW => mW.Write((ushort)player.Data.Role.DefaultGhostRole)); + messageWriter.ForEach(mW => mW.Write(false)); + AmongUsClient.Instance.FinishRpcDesync(messageWriter); + } + return false; } } @@ -477,5 +495,16 @@ public class RoleManagerPatch return shuffledDictionary; } - private static int RNG() => random.Next(0, 100); + public static int RNG() + { + switch (BetterGameSettings.RoleRandomizer.GetValue()) + { + case 1: + return UnityEngine.Random.Range(0, 100); + + default: + Random Random = new Random(); + return Random.Next(0, 100); + } + } } \ No newline at end of file From 3b353977e6c9f7673495cbc21032d3f65db60712 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Tue, 27 Aug 2024 16:14:20 -0500 Subject: [PATCH 33/34] better ver text --- Patches/VersionShowerPatch.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Patches/VersionShowerPatch.cs b/Patches/VersionShowerPatch.cs index 4bc0954..16c03e5 100644 --- a/Patches/VersionShowerPatch.cs +++ b/Patches/VersionShowerPatch.cs @@ -9,6 +9,6 @@ public class VersionShowerPatch [HarmonyPostfix] public static void Postfix(VersionShower __instance) { - __instance.text.text = $"♻BetterAmongUs♻ {Main.GetVersionText()} ~ {Utils.GetPlatformName(Main.PlatformData.Platform)} " + __instance.text.text; + __instance.text.text = $"♻BetterAmongUs♻ {Main.GetVersionText()} ~ {Utils.GetPlatformName(Main.PlatformData.Platform)} v{Main.AmongUsVersion}"; } } From dc4a3ae079d8d6f6115f00f5cecb008628f38dc9 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Wed, 28 Aug 2024 14:05:32 -0500 Subject: [PATCH 34/34] fix --- Modules/OptionItems/BetterOptionFloatItem.cs | 8 ++++++++ Modules/OptionItems/BetterOptionIntItem.cs | 8 ++++++++ Patches/GameSettingMenuPatch.cs | 14 ++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Modules/OptionItems/BetterOptionFloatItem.cs b/Modules/OptionItems/BetterOptionFloatItem.cs index 80bd1a8..39f3e5e 100644 --- a/Modules/OptionItems/BetterOptionFloatItem.cs +++ b/Modules/OptionItems/BetterOptionFloatItem.cs @@ -135,6 +135,10 @@ public class BetterOptionFloatItem : BetterOptionItem { CurrentValue += Increment * times; } + else + { + CurrentValue = floatRange.max; + } AdjustButtonsActiveState(); } @@ -151,6 +155,10 @@ public class BetterOptionFloatItem : BetterOptionItem { CurrentValue -= Increment * times; } + else + { + CurrentValue = floatRange.min; + } AdjustButtonsActiveState(); } diff --git a/Modules/OptionItems/BetterOptionIntItem.cs b/Modules/OptionItems/BetterOptionIntItem.cs index 9f7e521..2fcfa41 100644 --- a/Modules/OptionItems/BetterOptionIntItem.cs +++ b/Modules/OptionItems/BetterOptionIntItem.cs @@ -134,6 +134,10 @@ public class BetterOptionIntItem : BetterOptionItem { CurrentValue += Increment * times; } + else + { + CurrentValue = intRange.max; + } AdjustButtonsActiveState(); } @@ -150,6 +154,10 @@ public class BetterOptionIntItem : BetterOptionItem { CurrentValue -= Increment * times; } + else + { + CurrentValue = intRange.min; + } AdjustButtonsActiveState(); } diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 8330bf6..34d0d43 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -312,9 +312,12 @@ static class NumberOptionPatch if (__instance.Value + __instance.Increment * times > __instance.ValidRange.max) { - return false; + __instance.Value = __instance.ValidRange.max; + } + else + { + __instance.Value = __instance.ValidRange.Clamp(__instance.Value + __instance.Increment * times); } - __instance.Value = __instance.ValidRange.Clamp(__instance.Value + __instance.Increment * times); __instance.UpdateValue(); __instance.OnValueChanged.Invoke(__instance); __instance.AdjustButtonsActiveState(); @@ -333,9 +336,12 @@ static class NumberOptionPatch if (__instance.Value - __instance.Increment * times < __instance.ValidRange.min) { - return false; + __instance.Value = __instance.ValidRange.min; + } + else + { + __instance.Value = __instance.ValidRange.Clamp(__instance.Value - __instance.Increment * times); } - __instance.Value = __instance.ValidRange.Clamp(__instance.Value - __instance.Increment * times); __instance.UpdateValue(); __instance.OnValueChanged.Invoke(__instance); __instance.AdjustButtonsActiveState();