Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions Reactor/Networking/Rpc/MethodRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Reactor.Networking.Rpc;
/// <summary>
/// Provides a custom rpc for method rpc.
/// </summary>
public class MethodRpc : UnsafeCustomRpc
public class MethodRpc : UnsafeCustomRpc, IDisposable
{
private delegate object HandleDelegate(InnerNetObject innerNetObject, object[] args);

Expand Down Expand Up @@ -154,12 +154,29 @@ public void Send(InnerNetObject innerNetObject, object[] args)

private static readonly MethodInfo _sendMethod = AccessTools.Method(typeof(MethodRpc), nameof(Send));

// ReSharper disable once NotAccessedField.Local
private Hook? _hook;

/// <summary>
/// Hooks the <paramref name="method"/> rpc with a dynamic method that sends it.
/// </summary>
private HandleDelegate Hook(MethodInfo method, ParameterInfo[] parameters, bool isStatic)
{
var detour = new Detour(method, GenerateSender());
// MonoMod Hook is used instead of Detour because Starlight
// uses the "reorg" branch which no longer includes Detour.
// Hook is still present with the same signature.
// DMD is a workaround since reorganized Hook doesn't contain a
// function to make a trampoline.

// Create a copy of the original method with DMD
var dmd = new DynamicMethodDefinition(method);
var originalTrampoline = dmd.Generate();

// Hook the method to send the RPC
_hook = new Hook(method, GenerateSender());

// Return the generated Handler method
return GenerateHandler(originalTrampoline);

// Used as target when hooking, sends the method rpc
DynamicMethod GenerateSender()
Expand Down Expand Up @@ -244,7 +261,7 @@ DynamicMethod GenerateSender()
}

// Proxy translating object array to trampoline method args, used by MethodRpc to invoke original handling
HandleDelegate GenerateHandler(DynamicMethod trampoline)
HandleDelegate GenerateHandler(MethodInfo trampoline)
{
var dynamicMethod = new DynamicMethod($"Handler<{method.GetID(simple: true)}>", typeof(object), new[] { typeof(InnerNetObject), typeof(object[]) });
dynamicMethod.DefineParameter(0, ParameterAttributes.None, "innerNetObject");
Expand Down Expand Up @@ -280,7 +297,12 @@ HandleDelegate GenerateHandler(DynamicMethod trampoline)

return dynamicMethod.CreateDelegate<HandleDelegate>();
}
}

return GenerateHandler((DynamicMethod) detour.GenerateTrampoline());
/// <inheritdoc />
public void Dispose()
{
GC.SuppressFinalize(this);
_hook?.Dispose();
}
}
9 changes: 0 additions & 9 deletions Reactor/Patches/Miscellaneous/SplashSkipPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,4 @@ private static void RemoveMinimumWait(SplashManager __instance)
{
__instance.minimumSecondsBeforeSceneChange = 0;
}

[HarmonyPatch(typeof(SplashManager), nameof(SplashManager.Update))]
[HarmonyPrefix]
private static bool WaitForLogin(SplashManager __instance)
{
if (__instance.startedSceneLoad) return true;

return true;
}
}
6 changes: 3 additions & 3 deletions Reactor/Patches/Miscellaneous/StandaloneSteamPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public static MethodBase TargetMethod()

public static bool Prefix(out bool __result)
{
const string file = "steam_appid.txt";
const string AppIdFile = "steam_appid.txt";

if (!File.Exists(file))
if (!File.Exists(AppIdFile))
{
File.WriteAllText(file, "945360");
File.WriteAllText(AppIdFile, "945360");
}

return __result = false;
Expand Down
Loading