diff --git a/HNSRevamped.cs b/HNSRevamped.cs index 71121da..248cbc7 100644 --- a/HNSRevamped.cs +++ b/HNSRevamped.cs @@ -27,6 +27,7 @@ public partial class Main : BasePlugin public static bool HasArgumentException; public static string CredentialsText; + public const string ModVersion = "v0.2.0"; public static PlayerControl[] AllPlayerControls { diff --git a/Modules/CustomOptionsHolder.cs b/Modules/CustomOptionsHolder.cs index a1fad5c..30c27b4 100644 --- a/Modules/CustomOptionsHolder.cs +++ b/Modules/CustomOptionsHolder.cs @@ -32,6 +32,9 @@ namespace HNSRevamped public static OptionItem ApplyModeratorList; public static OptionItem AutoRejoinLobby; + public static OptionItem AutoStartTimer; + public static OptionItem WaitAutoStart; + public static OptionItem PlayerAutoStart; public static OptionItem NoGameEnd; @@ -47,13 +50,12 @@ namespace HNSRevamped { if (IsLoaded) return; - //Main settings + //System Settings KickLowLevelPlayer = IntegerOptionItem.Create(60050, "Kick Players Under Level", new(0, 100, 1), 0, TabGroup.SystemSettings, false) .SetValueFormat(OptionFormat.Level) .SetHeader(true); TempBanLowLevelPlayer = BooleanOptionItem.Create(60051, "Ban Instead Of Kick", false, TabGroup.SystemSettings, false) - .SetParent(KickLowLevelPlayer) - .SetValueFormat(OptionFormat.Times); + .SetParent(KickLowLevelPlayer); KickInvalidFriendCodes = BooleanOptionItem.Create(60080, "Kick Invalid FriendCodes", true, TabGroup.SystemSettings, false); TempBanInvalidFriendCodes = BooleanOptionItem.Create(60081, "Ban Instead Of Kick", false, TabGroup.SystemSettings, false) @@ -63,6 +65,11 @@ namespace HNSRevamped ApplyModeratorList = BooleanOptionItem.Create(60120, "Apply ModeratorList", false, TabGroup.SystemSettings, false); AutoRejoinLobby = BooleanOptionItem.Create(60210, "Auto Rejoin Lobby", false, TabGroup.SystemSettings, false); + AutoStartTimer = IntegerOptionItem.Create(44420, "Countdown For AutoStart", new(1, 600, 1), 5, TabGroup.SystemSettings, false) + .SetValueFormat(OptionFormat.Seconds); + WaitAutoStart = IntegerOptionItem.Create(44421, "AutoStart After", new(10, 600, 10), 5, TabGroup.SystemSettings, false) + .SetValueFormat(OptionFormat.Seconds); + PlayerAutoStart = IntegerOptionItem.Create(44422, "PlayerAutoStart", new(1, 15, 1), 5, TabGroup.SystemSettings, false); NoGameEnd = BooleanOptionItem.Create(60380, "No Game End", false, TabGroup.SystemSettings, false) .SetColor(Color.red) diff --git a/Patches/CredentialsPatch.cs b/Patches/CredentialsPatch.cs index 96b9c0e..b547025 100644 --- a/Patches/CredentialsPatch.cs +++ b/Patches/CredentialsPatch.cs @@ -51,14 +51,38 @@ namespace HNSRevamped { private static void Postfix(VersionShower __instance) { - Main.CredentialsText = $"Hide And Seek Revamped v0.1.0"; + + OnGameJoinedPatch.AutoStartCheck = false; + + Main.CredentialsText = $"Hide And Seek Revamped {Main.ModVersion}"; + + var credentials = UnityEngine.Object.Instantiate(__instance.text); + credentials.text = Main.CredentialsText; + credentials.alignment = TextAlignmentOptions.Right; + credentials.transform.position = new Vector3(1f, 2.67f, -2f); + credentials.fontSize = credentials.fontSizeMax = credentials.fontSizeMin = 2f; ErrorText.Create(__instance.text); - if (Main.HasArgumentException && ErrorText.Instance != null) { ErrorText.Instance.AddError(ErrorCode.Main_DictionaryError); } + + GameObject t = GameObject.Find("Tint"); + if (t != null) + { + t.SetActive(false); + } + GameObject b = GameObject.Find("BackgroundTexture"); + if (b != null) + { + b.SetActive(false); + } + GameObject w = GameObject.Find("WindowShine"); + if (w != null) + { + w.SetActive(false); + } } } @@ -74,7 +98,8 @@ namespace HNSRevamped { FpsSampler.TickFrame(); - PingTracker instance = Instance ?? __instance; + if (!Instance) Instance = __instance; + var instance = Instance; if (AmongUsClient.Instance == null) return false; @@ -91,8 +116,6 @@ namespace HNSRevamped instance.text.text = Sb.ToString(); } - if (Instance == null) Instance = __instance; - long now = Utils.TimeStamp; if (now == LastUpdate) return false; LastUpdate = now; diff --git a/Patches/EndGamePatches.cs b/Patches/EndGamePatches.cs index c677379..a6b583b 100644 --- a/Patches/EndGamePatches.cs +++ b/Patches/EndGamePatches.cs @@ -10,6 +10,7 @@ public static class EndGameManagerPatch { public static void Postfix(EndGameManager __instance) { + OnGameJoinedPatch.AutoStartCheck = false; EndGameNavigation navigation = __instance.Navigation; if (!AmongUsClient.Instance.AmHost || __instance == null || navigation == null || !Options.AutoRejoinLobby.GetBool()) return; navigation.NextGame(); @@ -41,7 +42,6 @@ internal class ControllerManagerUpdatePatch { if (Input.GetKey(KeyCode.L) && Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Return)) { - // Instead of a gigantic custom RPC, the game can just be ended in 3 lines of code MessageWriter writer = AmongUsClient.Instance.StartEndGame(); writer.Write((byte)GameOverReason.ImpostorDisconnect); AmongUsClient.Instance.FinishEndGame(writer); diff --git a/Patches/GameStartManagerPatch.cs b/Patches/GameStartManagerPatch.cs index 99e9a4e..93d40a1 100644 --- a/Patches/GameStartManagerPatch.cs +++ b/Patches/GameStartManagerPatch.cs @@ -1,10 +1,21 @@ -namespace HNSRevamped; +using System; + +namespace HNSRevamped; [HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Update))] public static class GameStartManagerUpdatePatch { public static void Prefix(GameStartManager __instance) { + if (!AmongUsClient.Instance.AmHost || AmongUsClient.Instance == null) return; + __instance.MinPlayers = 1; + + if (Main.AutoStart.Value && OnGameJoinedPatch.AutoStartCheck && GameStartManager.InstanceExists && GameStartManager.Instance.startState != GameStartManager.StartingStates.Countdown && GameData.Instance?.PlayerCount >= Options.PlayerAutoStart.GetInt()) + { + GameStartManager.Instance.startState = GameStartManager.StartingStates.Countdown; + GameStartManager.Instance.countDownTimer = Options.AutoStartTimer.GetFloat(); + GameStartManager.Instance?.StartButton.gameObject.SetActive(false); + } } } \ No newline at end of file diff --git a/Patches/JoinAndLeavePatches.cs b/Patches/JoinAndLeavePatches.cs index 48eb6e2..82e13ed 100644 --- a/Patches/JoinAndLeavePatches.cs +++ b/Patches/JoinAndLeavePatches.cs @@ -7,6 +7,23 @@ using UnityEngine; namespace HNSRevamped; +[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnGameJoined))] +internal static class OnGameJoinedPatch +{ + public static bool AutoStartCheck; + public static void Postfix(AmongUsClient __instance) + { + if (!AmongUsClient.Instance.AmHost || !Main.AutoStart.Value) return; + + LateTask.Tasks.Clear(); + + new LateTask(() => + { + AutoStartCheck = true; + }, Options.AutoStartTimer.GetFloat(), "AutoStartTimer"); + } +} + [HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnPlayerJoined))] class OnPlayerJoinedPatch { @@ -46,11 +63,13 @@ class OnPlayerJoinedPatch { AmongUsClient.Instance.KickPlayer(Client.Id, false); Logger.Info($" {Client.PlayerName} Was kicked for having an invalid FriendCode", "KickInvalidFriendCode"); + Logger.SendInGame($" {Client.PlayerName} Was kicked for having an invalid FriendCode"); } else { AmongUsClient.Instance.KickPlayer(Client.Id, true); Logger.Info($" {Client.PlayerName} Was banned for having an invalid FriendCode", "BanInvalidFriendCode"); + Logger.SendInGame($" {Client.PlayerName} Was banned for having an invalid FriendCode"); } } } diff --git a/Patches/PlayerControlPatches.cs b/Patches/PlayerControlPatches.cs index 4dcd5dc..4c53067 100644 --- a/Patches/PlayerControlPatches.cs +++ b/Patches/PlayerControlPatches.cs @@ -18,11 +18,13 @@ class FixedUpdateInGamePatch { AmongUsClient.Instance.KickPlayer(__instance.Data.ClientId, false); Logger.Info($" {__instance.Data.PlayerName} was kicked for being under level {Options.KickLowLevelPlayer.GetInt()}", "KickLowLevelPlayer"); + Logger.SendInGame($" {__instance.Data.PlayerName} was kicked for being under level {Options.KickLowLevelPlayer.GetInt()}"); } else { AmongUsClient.Instance.KickPlayer(__instance.Data.ClientId, true); Logger.Info($" {__instance.Data.PlayerName} was banned for being under level {Options.KickLowLevelPlayer.GetInt()} ", "BanLowLevelPlayer"); + Logger.SendInGame($" {__instance.Data.PlayerName} was banned for being under level {Options.KickLowLevelPlayer.GetInt()}"); } } }