From ed589123916503095c11746e33f0abcfa4075f48 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Tue, 2 Jun 2026 11:45:23 +0200 Subject: [PATCH] some fixes --- Modules/CustomRpcSender.cs | 2 +- Modules/CustomTeamManager.cs | 3 -- .../PlayerGameOptionsSender.cs | 2 +- Modules/PetsHelper.cs | 2 +- Modules/Utils.cs | 49 +++++-------------- Patches/IntroPatch.cs | 30 +++++------- Patches/NotificationPopperPatch.cs | 7 ++- Patches/PlayerControlPatch.cs | 12 ----- Roles/Standard/Crewmate/Chaos/Car.cs | 9 ++++ Roles/Standard/Crewmate/Chaos/Tree.cs | 6 +-- 10 files changed, 47 insertions(+), 75 deletions(-) diff --git a/Modules/CustomRpcSender.cs b/Modules/CustomRpcSender.cs index 4404fad63..25146f2d3 100644 --- a/Modules/CustomRpcSender.cs +++ b/Modules/CustomRpcSender.cs @@ -532,7 +532,7 @@ public class CustomRpcSender public static class CustomRpcSenderExtensions { - public static void RpcSetName(ref CustomRpcSender sender, PlayerControl player, string name, PlayerControl seer = null) + public static void RpcSetName(ref CustomRpcSender sender, PlayerControl player, PlayerControl seer, string name) { bool seerIsNull = !seer; int targetClientId = seerIsNull ? -1 : seer.OwnerId; diff --git a/Modules/CustomTeamManager.cs b/Modules/CustomTeamManager.cs index 5a5105d2c..a320dc824 100644 --- a/Modules/CustomTeamManager.cs +++ b/Modules/CustomTeamManager.cs @@ -144,7 +144,6 @@ internal static class CustomTeamManager msg.WritePacked(EnabledCustomTeams.Count); EnabledCustomTeams.Do(x => x.Serialize(msg)); AmongUsClient.Instance.FinishRpcImmediately(msg); - msg.Recycle(); msg = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.CTA, SendOption.Reliable); msg.WritePacked(2); @@ -158,7 +157,6 @@ internal static class CustomTeamManager } AmongUsClient.Instance.FinishRpcImmediately(msg); - msg.Recycle(); msg = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.CTA, SendOption.Reliable); msg.WritePacked(3); @@ -172,7 +170,6 @@ internal static class CustomTeamManager } AmongUsClient.Instance.FinishRpcImmediately(msg); - msg.Recycle(); } return; diff --git a/Modules/GameOptionsSender/PlayerGameOptionsSender.cs b/Modules/GameOptionsSender/PlayerGameOptionsSender.cs index b6028773f..047192586 100644 --- a/Modules/GameOptionsSender/PlayerGameOptionsSender.cs +++ b/Modules/GameOptionsSender/PlayerGameOptionsSender.cs @@ -262,6 +262,7 @@ public sealed class PlayerGameOptionsSender(PlayerControl player) : GameOptionsS { if (PackedWriter == null) // Single write { + Logger.Info("Enqueue complete for single write", "SendOptionsArray"); DataFlagRateLimiter.Enqueue(() => { MessageWriter writer = MessageWriter.Get(SendOption.Reliable); @@ -289,7 +290,6 @@ public sealed class PlayerGameOptionsSender(PlayerControl player) : GameOptionsS writer.Recycle(); Logger.Info("Queue finished and sent for single write", "SendOptionsArray"); }); - Logger.Info("Enqueue complete for single write", "SendOptionsArray"); return; } diff --git a/Modules/PetsHelper.cs b/Modules/PetsHelper.cs index 5660c7caa..74d0242e5 100644 --- a/Modules/PetsHelper.cs +++ b/Modules/PetsHelper.cs @@ -7,7 +7,7 @@ public static class PetsHelper public static void RpcRemovePet(PlayerControl pc) { const string petId = ""; - if (!GameStates.IsInGame || !Options.RemovePetsAtDeadPlayers.GetBool() || pc == null || !pc.Data.IsDead || pc.IsAlive() || pc.CurrentOutfit.PetId == petId) return; + if (!GameStates.IsInGame || !Options.RemovePetsAtDeadPlayers.GetBool() || !pc || !pc.Data.IsDead || pc.IsAlive() || pc.CurrentOutfit.PetId == petId) return; SetPet(pc, petId); } diff --git a/Modules/Utils.cs b/Modules/Utils.cs index bb35c1ea5..f2fdbbd97 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -2793,7 +2793,7 @@ public static class Utils var hasValue = false; var sender = CustomRpcSender.Create("NotifyRoles", SendOption, log: false); - sender.StartPackedMessage(); + if (!ForMeeting || !Magistrate.CallCourtNextMeeting) sender.StartPackedMessage(); for (byte seerIndex = 0; seerIndex < SeerList.Count; seerIndex++) { @@ -2830,40 +2830,23 @@ public static class Utils sender ??= CustomRpcSender.Create("NotifyRoles", sendOption); - // During the intro scene, set the team name for non-modded clients and skip the rest. string selfName; Team seerTeam = seer.GetTeam(); CustomRoles seerRole = seer.GetCustomRole(); - if (SetUpRoleTextPatch.IsInIntro && (seerRole.IsDesyncRole() || seer.Is(CustomRoles.Bloodlust)) && Options.CurrentGameMode == CustomGameMode.Standard) - { - const string iconTextLeft = "\u21e8"; - const string iconTextRight = "\u21e6"; - const string roleNameUp = "\n \n"; - - var selfTeamName = $"{iconTextLeft} {ColorString(seerTeam.GetColor(), $"{seerTeam}")} {iconTextRight}\n \n"; - selfName = $"{selfTeamName}\r\n{seerRole.ToColoredString()}{roleNameUp}"; - - CustomRpcSenderExtensions.RpcSetName(ref sender, seer, selfName, seer); - return true; - } + if (SetUpRoleTextPatch.IsInIntro) + return false; if (seer.Is(CustomRoles.Car) && !forMeeting && !GameStates.IsEnded) - { - CustomRpcSenderExtensions.RpcSetName(ref sender, seer, Car.Name); - return true; - } + return false; - if (Main.PlayerStates.TryGetValue(seer.PlayerId, out var seerState) && seerState.Role is Tree { TreeSpriteActive: true } && !forMeeting && !GameStates.IsEnded) - { - CustomRpcSenderExtensions.RpcSetName(ref sender, seer, Tree.Sprite); - return true; - } + if (Main.PlayerStates.TryGetValue(seer.PlayerId, out var seerState) && seerState.Role is Tree { TreeSpriteActive: true } && !forMeeting && !GameStates.IsEnded) + return false; if (forMeeting && Magistrate.CallCourtNextMeeting) { selfName = seer.Is(CustomRoles.Magistrate) ? GetString("Magistrate.CourtName") : GetString("Magistrate.JuryName"); - CustomRpcSenderExtensions.RpcSetName(ref sender, seer, selfName); + CustomRpcSenderExtensions.RpcSetName(ref sender, seer, null, selfName); return true; } @@ -3189,7 +3172,7 @@ public static class Utils if (selfName.EndsWith("")) selfName = selfName.Remove(selfName.Length - 7); if (selfName.EndsWith("")) selfName = selfName.Remove(selfName.Length - 8); - CustomRpcSenderExtensions.RpcSetName(ref sender, seer, selfName, seer); + CustomRpcSenderExtensions.RpcSetName(ref sender, seer, seer, selfName); hasValue = true; bool onlySelfNameUpdateRequired = Options.CurrentGameMode switch @@ -3220,25 +3203,19 @@ public static class Utils if (target.PlayerId == seer.PlayerId) continue; if ((IsActive(SystemTypes.MushroomMixupSabotage) || mushroomMixup) && !forMeeting && target.IsAlive() && !seer.Is(CustomRoleTypes.Impostor) && seer.HasDesyncRole()) - CustomRpcSenderExtensions.RpcSetName(ref sender, target, "", seer); + CustomRpcSenderExtensions.RpcSetName(ref sender, target, seer, ""); else { if (target.Is(CustomRoles.Car) && !forMeeting && !GameStates.IsEnded) - { - CustomRpcSenderExtensions.RpcSetName(ref sender, target, Car.Name, seer); continue; - } - if (Main.PlayerStates.TryGetValue(target.PlayerId, out var targetState) && targetState.Role is Tree { TreeSpriteActive: true } && !forMeeting && !GameStates.IsEnded) - { - CustomRpcSenderExtensions.RpcSetName(ref sender, target, Tree.Sprite, seer); + if (Main.PlayerStates.TryGetValue(target.PlayerId, out var targetState) && targetState.Role is Tree { TreeSpriteActive: true } && !forMeeting && !GameStates.IsEnded) continue; - } if (forMeeting && Magistrate.CallCourtNextMeeting) { - CustomRpcSenderExtensions.RpcSetName(ref sender, target, GetString(target.Is(CustomRoles.Magistrate) ? "Magistrate.CourtName" : "Magistrate.JuryName"), seer); - return true; + CustomRpcSenderExtensions.RpcSetName(ref sender, target, seer, GetString(target.Is(CustomRoles.Magistrate) ? "Magistrate.CourtName" : "Magistrate.JuryName")); + continue; } TargetMark.Clear(); @@ -3506,7 +3483,7 @@ public static class Utils if (targetName.EndsWith("")) targetName = targetName.Remove(targetName.Length - 7); if (targetName.EndsWith("")) targetName = targetName.Remove(targetName.Length - 8); - CustomRpcSenderExtensions.RpcSetName(ref sender, target, targetName, seer); + CustomRpcSenderExtensions.RpcSetName(ref sender, target, seer, targetName); hasValue = true; senderWasCleared = false; } diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index 721bfb4cf..83b6a006c 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -1149,6 +1149,19 @@ internal static class IntroCutsceneDestroyPatch if (AmongUsClient.Instance.AmHost) { LateTask.New(() => apc.DoIf(x => x && ((x.AmOwner && Main.GM.Value) || ChatCommands.Spectators.Contains(x.PlayerId)), x => x.RpcSetCustomRole(CustomRoles.GM)), 8f); + + try + { + System.Collections.Generic.List spectators = ChatCommands.Spectators.ToValidPlayers().ToList(); + if (Main.GM.Value) spectators.Add(PlayerControl.LocalPlayer); + + spectators.ForEach(x => + { + x.RpcExileV2(); + Main.PlayerStates[x.PlayerId].SetDead(); + }); + } + catch (Exception e) { Utils.ThrowException(e); } var aapc = Main.AllAlivePlayerControlsToList; @@ -1244,8 +1257,6 @@ internal static class IntroCutsceneDestroyPatch } } - Main.ProcessShapeshifts = false; - LateTask.New(GrantPetForEveryone, 3f, "Grant Pet For Everyone"); LateTask.New(() => @@ -1276,23 +1287,8 @@ internal static class IntroCutsceneDestroyPatch sender.SendMessage(dispose: !hasValue); }, 4f, "Show Pet For Everyone"); - - LateTask.New(() => Main.ProcessShapeshifts = true, 2f, "Enable SS Processing"); } - try - { - System.Collections.Generic.List spectators = ChatCommands.Spectators.ToValidPlayers().ToList(); - if (Main.GM.Value) spectators.Add(PlayerControl.LocalPlayer); - - spectators.ForEach(x => - { - x.RpcExileV2(); - Main.PlayerStates[x.PlayerId].SetDead(); - }); - } - catch (Exception e) { Utils.ThrowException(e); } - if (Options.RandomSpawn.GetBool() && Main.CurrentMap != MapNames.Airship && !Main.LIMap && AmongUsClient.Instance.AmHost && Options.CurrentGameMode is not CustomGameMode.CaptureTheFlag and not CustomGameMode.KingOfTheZones and not CustomGameMode.BedWars and not CustomGameMode.Deathrace) { var map = RandomSpawn.SpawnMap.GetSpawnMap(); diff --git a/Patches/NotificationPopperPatch.cs b/Patches/NotificationPopperPatch.cs index d31a8c597..8e25c21bb 100644 --- a/Patches/NotificationPopperPatch.cs +++ b/Patches/NotificationPopperPatch.cs @@ -73,6 +73,11 @@ internal static class NotificationPopperPatch private static void SendRpc(byte typeId, int optionId, CustomRoles customRole = CustomRoles.NotAssigned, bool playSound = true) { if (Options.HideGameSettings.GetBool()) return; - Utils.SendRPC(CustomRPC.NotificationPopper, typeId, optionId, (int)customRole, playSound); + var msg = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.NotificationPopper, Hazel.SendOption.None); + msg.Write(typeId); + msg.Write(optionId); + msg.Write((int)customRole); + msg.Write(playSound); + AmongUsClient.Instance.FinishRpcImmediately(msg); } } \ No newline at end of file diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index 09959c184..25f9c4139 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -2640,18 +2640,6 @@ public static class PlayerControlFixMixedUpOutfitPatch } } -[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.ShouldProcessRpc))] -internal static class ShouldProcessRpcPatch -{ - // Since the stupid AU code added a check for RPC processing for outfit players, we need to patch this - // Always return true because the check is absolutely pointless - public static bool Prefix(ref bool __result) - { - __result = true; - return false; - } -} - [HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.RpcBootFromVent))] internal static class BootFromVentPatch { diff --git a/Roles/Standard/Crewmate/Chaos/Car.cs b/Roles/Standard/Crewmate/Chaos/Car.cs index 3a148af80..49805230c 100644 --- a/Roles/Standard/Crewmate/Chaos/Car.cs +++ b/Roles/Standard/Crewmate/Chaos/Car.cs @@ -15,6 +15,7 @@ public class Car : RoleBase private int Count; private HashSet CurrentlyPropelling; private Vector2 LastPosition; + private byte CarId; public static string Name => ".<#0000>WWWWWW<#0000>WW\nWWWWWWW<#0000>W\nWWWWWWWW\nWWWWWWWW\nWW<#0000>WWWWW<#0000>W\nWWWWW<#0000>WWW"; @@ -40,6 +41,7 @@ public class Car : RoleBase LastPosition = Utils.GetPlayerById(playerId).Pos(); Count = 0; CurrentlyPropelling = []; + CarId = playerId; } public override void OnFixedUpdate(PlayerControl pc) @@ -120,6 +122,13 @@ public class Car : RoleBase CurrentlyPropelling.Remove(target.PlayerId); } + public override void AfterMeetingTasks() + { + var pc = CarId.GetPlayer(); + if (!pc || !pc.IsAlive()) return; + pc.RpcSetName(Name); + } + private enum Direction { Left, diff --git a/Roles/Standard/Crewmate/Chaos/Tree.cs b/Roles/Standard/Crewmate/Chaos/Tree.cs index e3e295fc2..ad0de3d72 100644 --- a/Roles/Standard/Crewmate/Chaos/Tree.cs +++ b/Roles/Standard/Crewmate/Chaos/Tree.cs @@ -61,7 +61,7 @@ public class Tree : RoleBase if (treeSpriteVisible) { TreeSpriteActive = true; - Utils.NotifyRoles(SpecifyTarget: pc); + pc.RpcSetName(Sprite); } else pc.RpcMakeInvisible(); @@ -69,7 +69,7 @@ public class Tree : RoleBase LateTask.New(() => { Main.AllPlayerSpeed[pc.PlayerId] = Main.RealOptionsData.GetFloat(FloatOptionNames.PlayerSpeedMod); - if (!GameStates.IsInTask || ExileController.Instance || AntiBlackout.SkipTasks || pc == null || !pc.IsAlive()) return; + if (!GameStates.IsInTask || ExileController.Instance || AntiBlackout.SkipTasks || !pc || !pc.IsAlive()) return; pc.MarkDirtySettings(); if (treeSpriteVisible) @@ -97,7 +97,7 @@ public class Tree : RoleBase LateTask.New(() => { Main.AllPlayerSpeed[x.PlayerId] = Main.RealOptionsData.GetFloat(FloatOptionNames.PlayerSpeedMod); - if (!GameStates.IsInTask || ExileController.Instance || AntiBlackout.SkipTasks || pc == null || !pc.IsAlive()) return; + if (!GameStates.IsInTask || ExileController.Instance || AntiBlackout.SkipTasks || !pc || !pc.IsAlive()) return; x.MarkDirtySettings(); }, FallStunDuration.GetFloat(), log: false); }