Add legacy custom RPC reading for compatibility

This commit is contained in:
D1GQ committed 2026-02-01 07:05:56 -06:00
1 parent 8a0e42f43e
commit 9bb98b7bc7
3 files changed
+62 -5

No files matched your search

+8 -1
View File
@@ -275,7 +275,7 @@ internal static class NetworkManager
{
if (rpcCall == (byte)RpcCalls.SetNamePlateStr)
{
RPC.HandleCustomRPC(player, reader);
RPC.HandleCustomRPCPacked(player, reader);
}
}
@@ -283,6 +283,13 @@ internal static class NetworkManager
{
innerNetObject?.HandleRpc(rpcCall, reader);
}
else
{
if (innerNetObject is PlayerControl player2 && player2 != null)
{
RPC.HandleCustomRPCLegacy(player2, rpcCall, reader);
}
}
break;
}
+2 -2
View File
@@ -72,7 +72,7 @@ internal sealed class HandshakeHandler
if (HasSendSharedSecret) return;
HasSendSharedSecret = true;
RPC.SendCustomRpc(CustomRPC.SendSecretToPlayer, writer =>
RPC.SendCustomRpcPacked(CustomRPC.SendSecretToPlayer, writer =>
{
writer.WriteBytes(SharedSecret.GetPublicKey());
writer.Write(SharedSecret.GetTempKey());
@@ -118,7 +118,7 @@ internal sealed class HandshakeHandler
int hash = SharedSecret.GetSharedSecretHash();
// Logger.Log($"Sending secret hash: {hash} (tempKey: {tempKey})");
RPC.SendCustomRpc(CustomRPC.CheckSecretHashFromPlayer, writer =>
RPC.SendCustomRpcPacked(CustomRPC.CheckSecretHashFromPlayer, writer =>
{
writer.Write(tempKey);
writer.Write(hash);
+52 -2
View File
@@ -1,6 +1,7 @@
using AmongUs.Data;
using BetterAmongUs.Enums;
using BetterAmongUs.Helpers;
using BetterAmongUs.Modules;
using BetterAmongUs.Mono;
using Hazel;
@@ -26,7 +27,7 @@ internal static class RPC
/// <param name="customRPC">The custom RPC type to send.</param>
/// <param name="action">A delegate that writes the custom RPC payload to the message writer.</param>
/// <param name="targetClientId">The specific client ID to target, or -1 to broadcast to all clients.</param>
internal static void SendCustomRpc(CustomRPC customRPC, Action<MessageWriter> action, int targetClientId = -1)
internal static void SendCustomRpcPacked(CustomRPC customRPC, Action<MessageWriter> action, int targetClientId = -1)
{
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)RpcCalls.SetNamePlateStr, SendOption.Reliable, targetClientId);
@@ -45,7 +46,7 @@ internal static class RPC
/// </summary>
/// <param name="player">The player who sent the RPC message.</param>
/// <param name="oldReader">The message reader containing the RPC data.</param>
internal static void HandleCustomRPC(PlayerControl player, MessageReader oldReader)
internal static void HandleCustomRPCPacked(PlayerControl player, MessageReader oldReader)
{
if (player == null || player.IsLocalPlayer() || player.Data == null) return;
@@ -75,6 +76,55 @@ internal static class RPC
reader.Recycle();
}
/// <summary>
/// Processes custom RPC messages received from other players.
/// </summary>
/// <param name="player">The player who sent the RPC.</param>
/// <param name="callId">The ID of the RPC call.</param>
/// <param name="oldReader">The message reader containing the RPC data.</param>
/// <remarks>
/// Handles both defined custom RPCs and protects against unknown RPCs in modded lobbies.
/// </remarks>
internal static void HandleCustomRPCLegacy(PlayerControl player, byte callId, MessageReader oldReader)
{
if (player == null || player.IsLocalPlayer() || player.Data == null || Enum.IsDefined(typeof(RpcCalls), callId)) return;
if (Enum.IsDefined(typeof(CustomRPC), (int)unchecked(callId)))
{
MessageReader reader = MessageReader.Get(oldReader);
switch (callId)
{
case (byte)CustomRPC.SendSecretToPlayer:
{
player.BetterData().HandshakeHandler.HandleSecretFromSender(reader);
}
break;
case (byte)CustomRPC.CheckSecretHashFromPlayer:
{
player.BetterData().HandshakeHandler.HandleSecretHashFromPlayer(reader);
}
break;
}
}
else if (!Enum.IsDefined(typeof(CustomRPC), (int)unchecked(callId)))
{
try
{
if (!GameState.IsHost)
{
if (player.IsHost())
{
var Icon = Translator.GetString("BAUMark");
var BAU = $"<color=#278720>{Icon}</color><color=#0ed400><b>{Translator.GetString("BAU")}</b></color><color=#278720>{Icon}</color>";
Utils.DisconnectSelf(string.Format(Translator.GetString("ModdedLobbyMsg"), BAU));
}
}
}
catch { }
}
}
/// <summary>
/// Determines whether a MessageReader contains a packed custom RPC message.
/// </summary>