AutoStart + Small Fixes/Improvements

This commit is contained in:
Ape committed 2025-12-10 20:43:17 +01:00
1 parent 9712afa27b
commit 48920aad75
7 files changed
+73 -10

No files matched your search

+1
View File
@@ -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
{
+10 -3
View File
@@ -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)
+28 -5
View File
@@ -51,14 +51,38 @@ namespace HNSRevamped
{
private static void Postfix(VersionShower __instance)
{
Main.CredentialsText = $"<color=#FFD700>Hide And Seek Revamped</color><color=#c0c0c0> v0.1.0</color>";
OnGameJoinedPatch.AutoStartCheck = false;
Main.CredentialsText = $"<color=#FFD700>Hide And Seek Revamped</color><color=#ffffff> {Main.ModVersion}</color>";
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;
+1 -1
View File
@@ -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);
+12 -1
View File
@@ -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);
}
}
}
+19
View File
@@ -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");
}
}
}
+2
View File
@@ -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()}");
}
}
}