mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
fix modded handshake + compile problems
This commit is contained in:
1 parent
7b7ba31e94
commit
db452bf7e4
10 files changed
+50
-88
No files matched your search
@@ -1 +1 @@
|
||||
global using AmongUsClient_CoFindGame = AmongUsClient._CoFindGame_d__6;
|
||||
global using AmongUsClient_CoFindGame = AmongUsClient._CoFindGame_d__54;
|
||||
@@ -33,11 +33,6 @@ public sealed class MethodRpcAttribute : Attribute
|
||||
/// </summary>
|
||||
public RpcLocalHandling LocalHandling { get; set; } = RpcLocalHandling.Before;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the rpc should be sent immediately.
|
||||
/// </summary>
|
||||
public bool SendImmediately { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MethodRpcAttribute"/> class.
|
||||
/// </summary>
|
||||
@@ -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<ReactorPlugin>.Instance.CustomRpcManager.Register(customRpc);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -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<InnerNetObject>();
|
||||
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<PlayerControl>.NativeClassPtr)
|
||||
if (AmongUsClient.Instance.ClientId != __instance.ownerId && __instance.NetObjectType == Il2CppType.Of<PlayerControl>())
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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))]
|
||||
|
||||
@@ -56,11 +56,10 @@ public abstract class CustomRpc<TPlugin, TInnerNetObject, TData> : UnsafeCustomR
|
||||
/// </summary>
|
||||
/// <param name="innerNetObject">The <see cref="InnerNetObject"/> to send the rpc on.</param>
|
||||
/// <param name="data">The data to send.</param>
|
||||
/// <param name="immediately">Whether to send it immediately.</param>
|
||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -72,7 +71,7 @@ public abstract class CustomRpc<TPlugin, TInnerNetObject, TData> : UnsafeCustomR
|
||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||
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<TPlugin, TInnerNetObject> : UnsafeCustomRpc wher
|
||||
/// Sends this custom rpc on the specified <paramref name="innerNetObject"/>.
|
||||
/// </summary>
|
||||
/// <param name="innerNetObject">The <see cref="InnerNetObject"/> to send the rpc on.</param>
|
||||
/// <param name="immediately">Whether to send it immediately.</param>
|
||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -136,6 +134,6 @@ public abstract class CustomRpc<TPlugin, TInnerNetObject> : UnsafeCustomRpc wher
|
||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||
public void SendTo(InnerNetObject innerNetObject, int targetClientId, Action? ackCallback = null)
|
||||
{
|
||||
UnsafeSend(innerNetObject, null, true, targetClientId, ackCallback);
|
||||
UnsafeSend(innerNetObject, null, targetClientId, ackCallback);
|
||||
}
|
||||
}
|
||||
@@ -32,13 +32,11 @@ public class MethodRpc : UnsafeCustomRpc
|
||||
/// <param name="id">The id of the rpc.</param>
|
||||
/// <param name="option">The send option of the rpc.</param>
|
||||
/// <param name="localHandling">The local handling method of the rpc.</param>
|
||||
/// <param name="sendImmediately">The value indicating whether the rpc should be sent immediately.</param>
|
||||
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
|
||||
/// <inheritdoc />
|
||||
public override SendOption SendOption { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the method rpc should be sent immediately.
|
||||
/// </summary>
|
||||
public bool SendImmediately { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void UnsafeWrite(MessageWriter writer, object? data)
|
||||
{
|
||||
@@ -134,7 +127,7 @@ public class MethodRpc : UnsafeCustomRpc
|
||||
/// <param name="args">The arguments to serialize and send.</param>
|
||||
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));
|
||||
|
||||
@@ -19,11 +19,10 @@ public abstract class PlayerCustomRpc<TPlugin, TData> : CustomRpc<TPlugin, Playe
|
||||
/// Sends this custom rpc on the local player with the specified <paramref name="data"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data to send.</param>
|
||||
/// <param name="immediately">Whether to send it immediately.</param>
|
||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,11 +51,10 @@ public abstract class PlayerCustomRpc<TPlugin> : CustomRpc<TPlugin, PlayerContro
|
||||
/// <summary>
|
||||
/// Sends this custom rpc on the local player.
|
||||
/// </summary>
|
||||
/// <param name="immediately">Whether to send it immediately.</param>
|
||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||
public void Send(bool immediately = false, Action? ackCallback = null)
|
||||
public void Send(Action? ackCallback = null)
|
||||
{
|
||||
Send(PlayerControl.LocalPlayer, immediately, ackCallback);
|
||||
Send(PlayerControl.LocalPlayer, ackCallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -91,10 +91,9 @@ public abstract class UnsafeCustomRpc
|
||||
/// </summary>
|
||||
/// <param name="innerNetObject">The <see cref="InnerNetObject"/> to send the rpc on.</param>
|
||||
/// <param name="data">The data to send.</param>
|
||||
/// <param name="immediately">Whether to send it immediately.</param>
|
||||
/// <param name="targetClientId">Target client id, defaults to broadcast.</param>
|
||||
/// <param name="ackCallback">The callback to invoke when this packet is acknowledged.</param>
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user