From db452bf7e4e2217e0b62e0d7d4195ab8db592cea Mon Sep 17 00:00:00 2001
From: XtraCube <72575280+XtraCube@users.noreply.github.com>
Date: Tue, 20 May 2025 18:24:22 -0400
Subject: [PATCH] fix modded handshake + compile problems
---
Reactor/GlobalUsings.cs | 2 +-
.../Attributes/MethodRpcAttribute.cs | 7 +--
Reactor/Networking/Patches/ClientPatches.cs | 54 +++++++------------
Reactor/Networking/Patches/HttpPatches.cs | 6 ++-
.../Networking/Patches/ReactorConnection.cs | 10 ++--
Reactor/Networking/Rpc/CustomRpc.cs | 14 +++--
Reactor/Networking/Rpc/MethodRpc.cs | 11 +---
Reactor/Networking/Rpc/PlayerCustomRpc.cs | 10 ++--
Reactor/Networking/Rpc/UnsafeCustomRpc.cs | 18 ++-----
.../Miscellaneous/CustomServersPatch.cs | 6 +--
10 files changed, 50 insertions(+), 88 deletions(-)
diff --git a/Reactor/GlobalUsings.cs b/Reactor/GlobalUsings.cs
index 8f021b9..bb00b4a 100644
--- a/Reactor/GlobalUsings.cs
+++ b/Reactor/GlobalUsings.cs
@@ -1 +1 @@
-global using AmongUsClient_CoFindGame = AmongUsClient._CoFindGame_d__6;
+global using AmongUsClient_CoFindGame = AmongUsClient._CoFindGame_d__54;
diff --git a/Reactor/Networking/Attributes/MethodRpcAttribute.cs b/Reactor/Networking/Attributes/MethodRpcAttribute.cs
index 0f336dd..bd5dc8a 100644
--- a/Reactor/Networking/Attributes/MethodRpcAttribute.cs
+++ b/Reactor/Networking/Attributes/MethodRpcAttribute.cs
@@ -33,11 +33,6 @@ public sealed class MethodRpcAttribute : Attribute
///
public RpcLocalHandling LocalHandling { get; set; } = RpcLocalHandling.Before;
- ///
- /// Gets or sets a value indicating whether the rpc should be sent immediately.
- ///
- public bool SendImmediately { get; set; }
-
///
/// Initializes a new instance of the class.
///
@@ -71,7 +66,7 @@ public sealed class MethodRpcAttribute : Attribute
try
{
- var customRpc = new MethodRpc(plugin, method, attribute.Id, attribute.SendOption, attribute.LocalHandling, attribute.SendImmediately);
+ var customRpc = new MethodRpc(plugin, method, attribute.Id, attribute.SendOption, attribute.LocalHandling);
PluginSingleton.Instance.CustomRpcManager.Register(customRpc);
}
catch (Exception e)
diff --git a/Reactor/Networking/Patches/ClientPatches.cs b/Reactor/Networking/Patches/ClientPatches.cs
index 321e343..6b83e14 100644
--- a/Reactor/Networking/Patches/ClientPatches.cs
+++ b/Reactor/Networking/Patches/ClientPatches.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using AmongUs.Data;
+using AmongUs.InnerNet.GameDataMessages;
using BepInEx.Unity.IL2CPP.Utils;
using HarmonyLib;
using Hazel;
@@ -29,10 +30,10 @@ internal static class ClientPatches
}
}
- [HarmonyPatch(typeof(InnerNetClient._HandleGameDataInner_d__41), nameof(InnerNetClient._HandleGameDataInner_d__41.MoveNext))]
+ [HarmonyPatch(typeof(InnerNetClient._HandleGameDataInner_d__165), nameof(InnerNetClient._HandleGameDataInner_d__165.MoveNext))]
public static class HandleGameDataInnerPatch
{
- public static bool Prefix(InnerNetClient._HandleGameDataInner_d__41 __instance, ref bool __result)
+ public static bool Prefix(InnerNetClient._HandleGameDataInner_d__165 __instance, ref bool __result)
{
var innerNetClient = __instance.__4__this;
var reader = __instance.reader;
@@ -63,7 +64,7 @@ internal static class ClientPatches
return false;
}
- if (reader.Tag == InnerNetClient.SceneChangeFlag && ReactorConnection.Instance?.Syncer == Syncer.Host)
+ if (reader.Tag == (byte) GameDataTypes.SceneChangeFlag && ReactorConnection.Instance?.Syncer == Syncer.Host)
{
var clientId = reader.ReadPackedInt32();
var clientData = innerNetClient.FindClientById(clientId);
@@ -126,7 +127,7 @@ internal static class ClientPatches
: chatText;
// Write SendChat directly instead of using RpcSendChat so we can call AddChat ourselves
- var messageWriter = AmongUsClient.Instance.StartRpc(PlayerControl.LocalPlayer.NetId, (byte) RpcCalls.SendChat);
+ var messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) RpcCalls.SendChat, SendOption.Reliable);
messageWriter.Write(truncatedChatText);
messageWriter.EndMessage();
}
@@ -161,10 +162,10 @@ internal static class ClientPatches
}
}
- [HarmonyPatch(typeof(InnerNetClient._CoSendSceneChange_d__32), nameof(InnerNetClient._CoSendSceneChange_d__32.MoveNext))]
+ [HarmonyPatch(typeof(InnerNetClient._CoSendSceneChange_d__156), nameof(InnerNetClient._CoSendSceneChange_d__156.MoveNext))]
public static class CoSendSceneChangePatch
{
- public static bool Prefix(InnerNetClient._CoSendSceneChange_d__32 __instance, ref bool __result)
+ public static bool Prefix(InnerNetClient._CoSendSceneChange_d__156 __instance, ref bool __result)
{
if (ReactorConnection.Instance!.Syncer != Syncer.Host) return true;
@@ -181,7 +182,7 @@ internal static class ClientPatches
var writer = MessageWriter.Get(SendOption.Reliable);
writer.StartMessage(Tags.GameData);
writer.Write(innerNetClient.GameId);
- writer.StartMessage(InnerNetClient.SceneChangeFlag);
+ writer.StartMessage((byte) GameDataTypes.SceneChangeFlag);
writer.WritePacked(innerNetClient.ClientId);
writer.Write(__instance.sceneName);
@@ -209,10 +210,10 @@ internal static class ClientPatches
}
}
- [HarmonyPatch(typeof(InnerNetClient._CoHandleSpawn_d__42), nameof(InnerNetClient._CoHandleSpawn_d__42.MoveNext))]
+ [HarmonyPatch(typeof(InnerNetClient._CoHandleSpawn_d__166), nameof(InnerNetClient._CoHandleSpawn_d__166.MoveNext))]
public static class CoHandleSpawnPatch
{
- public static void Postfix(InnerNetClient._CoHandleSpawn_d__42 __instance, bool __result)
+ public static void Postfix(InnerNetClient._CoHandleSpawn_d__166 __instance, bool __result)
{
if (ReactorConnection.Instance!.Syncer != Syncer.Host) return;
@@ -236,38 +237,18 @@ internal static class ClientPatches
}
}
- [HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.WriteSpawnMessage))]
+ [HarmonyPatch(typeof(SpawnGameDataMessage), nameof(SpawnGameDataMessage.SerializeValues))]
public static class WriteSpawnMessagePatch
{
- public static bool Prefix(InnerNetClient __instance, InnerNetObject netObjParent, int ownerId, SpawnFlags flags, MessageWriter msg)
+ public static bool Prefix(SpawnGameDataMessage __instance, MessageWriter msg)
{
- if (ReactorConnection.Instance!.Syncer != Syncer.Host) return true;
-
- msg.StartMessage(4);
- msg.WritePacked(netObjParent.SpawnId);
- msg.WritePacked(ownerId);
- msg.Write((byte) flags);
- InnerNetObject[] componentsInChildren = netObjParent.GetComponentsInChildren();
- msg.WritePacked(componentsInChildren.Length);
- foreach (var innerNetObject in componentsInChildren)
+ if (ReactorConnection.Instance!.Syncer != Syncer.Host)
{
- innerNetObject.OwnerId = ownerId;
- innerNetObject.SpawnFlags = flags;
- if (innerNetObject.NetId == 0)
- {
- innerNetObject.NetId = __instance.NetIdCnt++;
- __instance.allObjects.Add(innerNetObject);
- __instance.allObjectsFast.Add(innerNetObject.NetId, innerNetObject);
- }
-
- msg.WritePacked(innerNetObject.NetId);
- msg.StartMessage(1);
- innerNetObject.Serialize(msg, initialState: true);
- msg.EndMessage();
+ return true;
}
// PATCH - Inject ReactorHandshakeS2C
- if (__instance.ClientId != ownerId && IL2CPP.il2cpp_object_get_class(netObjParent.Pointer) == Il2CppClassPointerStore.NativeClassPtr)
+ if (AmongUsClient.Instance.ClientId != __instance.ownerId && __instance.NetObjectType == Il2CppType.Of())
{
Debug("Injecting ReactorHandshakeS2C to WriteSpawnMessage");
ReactorHeader.Write(msg);
@@ -285,7 +266,10 @@ internal static class ClientPatches
{
public static bool Prefix(InnerNetClient __instance, [HarmonyArgument(0)] MessageReader reader)
{
- if (__instance.NetworkMode == NetworkModes.FreePlay) return true;
+ if (__instance.NetworkMode == NetworkModes.FreePlay)
+ {
+ return true;
+ }
var isFirst = false;
diff --git a/Reactor/Networking/Patches/HttpPatches.cs b/Reactor/Networking/Patches/HttpPatches.cs
index 7e1668a..0f15d32 100644
--- a/Reactor/Networking/Patches/HttpPatches.cs
+++ b/Reactor/Networking/Patches/HttpPatches.cs
@@ -54,7 +54,8 @@ internal static class HttpPatches
public static void Prefix(UnityWebRequest __instance)
{
- var path = __instance.uri.AbsolutePath;
+ // new Uri() is necessary because uri property got stripped.
+ var path = new Uri(__instance.url).AbsolutePath;
// Innersloth changed /api/games to /api/games/filtered
// We may want to keep support for /api/games though.
if (path.Contains("/api/games"))
@@ -66,7 +67,8 @@ internal static class HttpPatches
public static void Postfix(UnityWebRequest __instance, UnityWebRequestAsyncOperation __result)
{
- var path = __instance.uri.AbsolutePath;
+ // new Uri() is necessary because uri property got stripped.
+ var path = new Uri(__instance.url).AbsolutePath;
// Innersloth changed /api/games to /api/games/filtered
// We may want to keep support for /api/games though.
if (path.Contains("/api/games"))
diff --git a/Reactor/Networking/Patches/ReactorConnection.cs b/Reactor/Networking/Patches/ReactorConnection.cs
index c5e4af0..ffbcd5e 100644
--- a/Reactor/Networking/Patches/ReactorConnection.cs
+++ b/Reactor/Networking/Patches/ReactorConnection.cs
@@ -23,12 +23,16 @@ public class ReactorConnection
[HarmonyPatch]
private static class Patches
{
- [HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.CoConnect), typeof(string))]
+ // CoConnect(string) was inlined, so we patch the MoveNext method instead.
+ [HarmonyPatch(typeof(InnerNetClient._CoConnect_d__65), nameof(InnerNetClient._CoConnect_d__65.MoveNext))]
[HarmonyPrefix]
public static void CoConnect()
{
- Debug("New ReactorConnection created");
- Instance = new ReactorConnection();
+ if (Instance == null)
+ {
+ Debug("New ReactorConnection created");
+ Instance = new ReactorConnection();
+ }
}
[HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.DisconnectInternal))]
diff --git a/Reactor/Networking/Rpc/CustomRpc.cs b/Reactor/Networking/Rpc/CustomRpc.cs
index fe161eb..38aac99 100644
--- a/Reactor/Networking/Rpc/CustomRpc.cs
+++ b/Reactor/Networking/Rpc/CustomRpc.cs
@@ -56,11 +56,10 @@ public abstract class CustomRpc : UnsafeCustomR
///
/// The to send the rpc on.
/// The data to send.
- /// Whether to send it immediately.
/// The callback to invoke when this packet is acknowledged.
- public void Send(InnerNetObject innerNetObject, TData data, bool immediately = false, Action? ackCallback = null)
+ public void Send(InnerNetObject innerNetObject, TData data, Action? ackCallback = null)
{
- UnsafeSend(innerNetObject, data, immediately, ackCallback: ackCallback);
+ UnsafeSend(innerNetObject, data, ackCallback: ackCallback);
}
///
@@ -72,7 +71,7 @@ public abstract class CustomRpc : UnsafeCustomR
/// The callback to invoke when this packet is acknowledged.
public void SendTo(InnerNetObject innerNetObject, int targetClientId, TData data, Action? ackCallback = null)
{
- UnsafeSend(innerNetObject, data, true, targetClientId, ackCallback);
+ UnsafeSend(innerNetObject, data, targetClientId, ackCallback);
}
}
@@ -121,11 +120,10 @@ public abstract class CustomRpc : UnsafeCustomRpc wher
/// Sends this custom rpc on the specified .
///
/// The to send the rpc on.
- /// Whether to send it immediately.
/// The callback to invoke when this packet is acknowledged.
- public void Send(InnerNetObject innerNetObject, bool immediately = false, Action? ackCallback = null)
+ public void Send(InnerNetObject innerNetObject, Action? ackCallback = null)
{
- UnsafeSend(innerNetObject, immediately, ackCallback: ackCallback);
+ UnsafeSend(innerNetObject, ackCallback);
}
///
@@ -136,6 +134,6 @@ public abstract class CustomRpc : UnsafeCustomRpc wher
/// The callback to invoke when this packet is acknowledged.
public void SendTo(InnerNetObject innerNetObject, int targetClientId, Action? ackCallback = null)
{
- UnsafeSend(innerNetObject, null, true, targetClientId, ackCallback);
+ UnsafeSend(innerNetObject, null, targetClientId, ackCallback);
}
}
diff --git a/Reactor/Networking/Rpc/MethodRpc.cs b/Reactor/Networking/Rpc/MethodRpc.cs
index 46e2266..3f1bd61 100644
--- a/Reactor/Networking/Rpc/MethodRpc.cs
+++ b/Reactor/Networking/Rpc/MethodRpc.cs
@@ -32,13 +32,11 @@ public class MethodRpc : UnsafeCustomRpc
/// The id of the rpc.
/// The send option of the rpc.
/// The local handling method of the rpc.
- /// The value indicating whether the rpc should be sent immediately.
- public MethodRpc(BasePlugin plugin, MethodInfo method, uint id, SendOption option, RpcLocalHandling localHandling, bool sendImmediately) : base(plugin, id)
+ public MethodRpc(BasePlugin plugin, MethodInfo method, uint id, SendOption option, RpcLocalHandling localHandling) : base(plugin, id)
{
Method = method;
LocalHandling = localHandling;
SendOption = option;
- SendImmediately = sendImmediately;
var parameters = method.GetParameters();
@@ -88,11 +86,6 @@ public class MethodRpc : UnsafeCustomRpc
///
public override SendOption SendOption { get; }
- ///
- /// Gets a value indicating whether the method rpc should be sent immediately.
- ///
- public bool SendImmediately { get; }
-
///
public override void UnsafeWrite(MessageWriter writer, object? data)
{
@@ -134,7 +127,7 @@ public class MethodRpc : UnsafeCustomRpc
/// The arguments to serialize and send.
public void Send(InnerNetObject innerNetObject, object[] args)
{
- UnsafeSend(innerNetObject, args, SendImmediately);
+ UnsafeSend(innerNetObject, args);
}
private static readonly MethodInfo _sendMethod = AccessTools.Method(typeof(MethodRpc), nameof(Send));
diff --git a/Reactor/Networking/Rpc/PlayerCustomRpc.cs b/Reactor/Networking/Rpc/PlayerCustomRpc.cs
index 47c9d8a..77b2684 100644
--- a/Reactor/Networking/Rpc/PlayerCustomRpc.cs
+++ b/Reactor/Networking/Rpc/PlayerCustomRpc.cs
@@ -19,11 +19,10 @@ public abstract class PlayerCustomRpc : CustomRpc.
///
/// The data to send.
- /// Whether to send it immediately.
/// The callback to invoke when this packet is acknowledged.
- public void Send(TData data, bool immediately = false, Action? ackCallback = null)
+ public void Send(TData data, Action? ackCallback = null)
{
- Send(PlayerControl.LocalPlayer, data, immediately, ackCallback);
+ Send(PlayerControl.LocalPlayer, data, ackCallback);
}
///
@@ -52,11 +51,10 @@ public abstract class PlayerCustomRpc : CustomRpc
/// Sends this custom rpc on the local player.
///
- /// Whether to send it immediately.
/// The callback to invoke when this packet is acknowledged.
- public void Send(bool immediately = false, Action? ackCallback = null)
+ public void Send(Action? ackCallback = null)
{
- Send(PlayerControl.LocalPlayer, immediately, ackCallback);
+ Send(PlayerControl.LocalPlayer, ackCallback);
}
///
diff --git a/Reactor/Networking/Rpc/UnsafeCustomRpc.cs b/Reactor/Networking/Rpc/UnsafeCustomRpc.cs
index 80e390d..3a7d65a 100644
--- a/Reactor/Networking/Rpc/UnsafeCustomRpc.cs
+++ b/Reactor/Networking/Rpc/UnsafeCustomRpc.cs
@@ -91,10 +91,9 @@ public abstract class UnsafeCustomRpc
///
/// The to send the rpc on.
/// The data to send.
- /// Whether to send it immediately.
/// Target client id, defaults to broadcast.
/// The callback to invoke when this packet is acknowledged.
- public void UnsafeSend(InnerNetObject innerNetObject, object? data, bool immediately = false, int targetClientId = -1, Action? ackCallback = null)
+ public void UnsafeSend(InnerNetObject innerNetObject, object? data, int targetClientId = -1, Action? ackCallback = null)
{
ArgumentNullException.ThrowIfNull(innerNetObject);
@@ -108,11 +107,7 @@ public abstract class UnsafeCustomRpc
UnsafeHandle(innerNetObject, data);
}
- var writer = immediately switch
- {
- false => AmongUsClient.Instance.StartRpc(innerNetObject.NetId, CustomRpcManager.CallId, SendOption),
- true => AmongUsClient.Instance.StartRpcImmediately(innerNetObject.NetId, CustomRpcManager.CallId, SendOption, targetClientId),
- };
+ var writer = AmongUsClient.Instance.StartRpcImmediately(innerNetObject.NetId, CustomRpcManager.CallId, SendOption, targetClientId);
writer.Write(Mod);
writer.WritePacked(Id);
@@ -127,14 +122,7 @@ public abstract class UnsafeCustomRpc
AckCallbacks.TryAdd(writer, ackCallback);
}
- if (immediately)
- {
- AmongUsClient.Instance.FinishRpcImmediately(writer);
- }
- else
- {
- writer.EndMessage();
- }
+ AmongUsClient.Instance.FinishRpcImmediately(writer);
if (LocalHandling == RpcLocalHandling.After)
{
diff --git a/Reactor/Patches/Miscellaneous/CustomServersPatch.cs b/Reactor/Patches/Miscellaneous/CustomServersPatch.cs
index 8a37141..3e10387 100644
--- a/Reactor/Patches/Miscellaneous/CustomServersPatch.cs
+++ b/Reactor/Patches/Miscellaneous/CustomServersPatch.cs
@@ -30,15 +30,15 @@ internal static class CustomServersPatch
return false;
}
- [HarmonyPatch(typeof(AmongUsClient._CoJoinOnlinePublicGame_d__1), nameof(AmongUsClient._CoJoinOnlinePublicGame_d__1.MoveNext))]
+ [HarmonyPatch(typeof(AmongUsClient._CoJoinOnlinePublicGame_d__49), nameof(AmongUsClient._CoJoinOnlinePublicGame_d__49.MoveNext))]
[HarmonyPrefix]
- public static void EnableUdpMatchmaking(AmongUsClient._CoJoinOnlinePublicGame_d__1 __instance)
+ public static void EnableUdpMatchmaking(AmongUsClient._CoJoinOnlinePublicGame_d__49 __instance)
{
// Skip to state 1 which just calls CoJoinOnlineGameDirect
if (__instance.__1__state == 0 && !ServerManager.Instance.IsHttp)
{
__instance.__1__state = 1;
- __instance.__8__1 = new AmongUsClient.__c__DisplayClass1_0
+ __instance.__8__1 = new AmongUsClient.__c__DisplayClass49_0
{
matchmakerToken = string.Empty,
};