From 904c4239ab34d8c8ca0ca4fdccdb71e80cceb11c Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sat, 17 Aug 2024 09:19:08 -0500 Subject: [PATCH] fix better rpc --- Modules/DebugMenu.cs | 5 +++++ Modules/RPC.cs | 12 ++++++------ Patches/GamePlayManagerPatch.cs | 1 + Patches/PlayerControlPatch.cs | 3 ++- Patches/PlayerJoinAndLeftPatch.cs | 11 ++--------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Modules/DebugMenu.cs b/Modules/DebugMenu.cs index 547edb7..6af6a2a 100644 --- a/Modules/DebugMenu.cs +++ b/Modules/DebugMenu.cs @@ -53,6 +53,11 @@ public class DebugMenu : MonoBehaviour BetterDataManager.ClearCheatData(); }); + AddButtonToTab(Main, "Send Better RPC", () => + { + RPC.SendBetterCheck(); + }, true); + AddButtonToTab(HostOnly, "Sync All Names", () => { RPC.SyncAllNames(); diff --git a/Modules/RPC.cs b/Modules/RPC.cs index b981b31..10c8fea 100644 --- a/Modules/RPC.cs +++ b/Modules/RPC.cs @@ -81,8 +81,8 @@ internal static class RPC public static void SendBetterCheck() { var flag = GameStates.IsHost && Main.BetterHost.Value; - MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, unchecked((byte)CustomRPC.BetterCheck), SendOption.None, -1); - messageWriter.Write((byte)PlayerControl.LocalPlayer.NetId); + MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.BetterCheck, SendOption.None, -1); + messageWriter.Write(true); messageWriter.Write(flag); messageWriter.Write(Main.GetVersionText().Replace(" ", "")); AmongUsClient.Instance.FinishRpcImmediately(messageWriter); @@ -91,7 +91,7 @@ internal static class RPC public static void SetNamePrivate(PlayerControl player, string name, PlayerControl target) { MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.SetName, SendOption.Reliable, target.GetClientId()); - writer.Write(player.NetId); + writer.Write(player.Data.NetId); writer.Write(name); AmongUsClient.Instance.FinishRpcImmediately(writer); } @@ -167,17 +167,17 @@ internal static class RPC switch (callId) { case (byte)CustomRPC.BetterCheck: - if (reader.ReadByte() == player.Data.NetId) { + var SetBetterUser = reader.ReadBoolean(); var IsBetterHost = reader.ReadBoolean(); if (!player.IsHost() && IsBetterHost) { - BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)} called as BetterHost"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((CustomRPC)callId)} called as BetterHost"); break; } - player.BetterData().IsBetterUser = true; + player.BetterData().IsBetterUser = SetBetterUser; player.BetterData().IsBetterHost = IsBetterHost; } break; diff --git a/Patches/GamePlayManagerPatch.cs b/Patches/GamePlayManagerPatch.cs index a8fca09..e8a3ae6 100644 --- a/Patches/GamePlayManagerPatch.cs +++ b/Patches/GamePlayManagerPatch.cs @@ -46,6 +46,7 @@ class GamePlayManager if (GameStates.IsInGame) { RPC.SyncAllNames(force: true); + RPC.SendBetterCheck(); } }, 1.5f, "LobbyBehaviourPatch SyncAllNames"); } diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index 54d2d62..8085820 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -160,7 +160,8 @@ class PlayerControlPatch if (player.IsDev() && !GameStates.IsInGamePlay) sbTag.Append("(Dev)+++"); - if (((player == PlayerControl.LocalPlayer && GameStates.IsHost && Main.BetterHost.Value) || player.BetterData().IsBetterHost) && !GameStates.IsInGamePlay) + if (((player == PlayerControl.LocalPlayer && GameStates.IsHost && Main.BetterHost.Value) + || (player != PlayerControl.LocalPlayer && player.BetterData().IsBetterHost && player.IsHost())) && !GameStates.IsInGamePlay) sbTag.Append("Better Host+++"); else if ((player == PlayerControl.LocalPlayer || player.BetterData().IsBetterUser) && !GameStates.IsInGamePlay) sbTag.Append("Better User+++"); diff --git a/Patches/PlayerJoinAndLeftPatch.cs b/Patches/PlayerJoinAndLeftPatch.cs index 5cc63ab..6fa34fa 100644 --- a/Patches/PlayerJoinAndLeftPatch.cs +++ b/Patches/PlayerJoinAndLeftPatch.cs @@ -11,6 +11,8 @@ class OnGameJoinedPatch { try { + PlayerControlExtensions.playerInfo.Clear(); + PlayerControlPatch.infotime = 0f; AntiCheat.PauseAntiCheat(); @@ -23,15 +25,6 @@ class OnGameJoinedPatch host.SetColor(host.CurrentOutfit.ColorId); } - _ = new LateTask(() => - { - // Send Better Among Us Check RPC - if (GameStates.IsInGame) - { - RPC.SendBetterCheck(); - } - }, 1.5f, "OnGameJoinedPatch"); - Logger.Log($"Successfully joined {GameCode.IntToGameName(AmongUsClient.Instance.GameId)}", "OnGameJoinedPatch"); } catch { };