From 20068a8ad7285bf34b6a684b6cc08b501b5b6a87 Mon Sep 17 00:00:00 2001 From: Zetrith Date: Sat, 21 Oct 2023 17:23:14 +0200 Subject: [PATCH] Fix some mod compatibility issues --- Source/Client/MultiplayerStatic.cs | 1 - Source/Client/Patches/ThingMethodPatches.cs | 6 ++--- Source/Common/Native.cs | 8 +++--- Source/Common/Version.cs | 2 +- Source/TestsOnMono/Program.cs | 30 ++++++++++++--------- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Source/Client/MultiplayerStatic.cs b/Source/Client/MultiplayerStatic.cs index 062c7140..ebb02eb7 100644 --- a/Source/Client/MultiplayerStatic.cs +++ b/Source/Client/MultiplayerStatic.cs @@ -376,7 +376,6 @@ void LogError(string str) ("Tick", Type.EmptyTypes), ("TickRare", Type.EmptyTypes), ("TickLong", Type.EmptyTypes), - ("SpawnSetup", new[]{ typeof(Map), typeof(bool) }), ("TakeDamage", new[]{ typeof(DamageInfo) }), ("Kill", new[]{ typeof(DamageInfo?), typeof(Hediff) }) }; diff --git a/Source/Client/Patches/ThingMethodPatches.cs b/Source/Client/Patches/ThingMethodPatches.cs index 1e161520..44c94575 100644 --- a/Source/Client/Patches/ThingMethodPatches.cs +++ b/Source/Client/Patches/ThingMethodPatches.cs @@ -134,15 +134,15 @@ public static void Prefix(Thing __instance, ref Container? __state) } [HarmonyPriority(MpPriority.MpFirst)] - public static void Prefix_SpawnSetup(Thing __instance, Map map, ref Container? __state) + public static void Prefix_SpawnSetup(Thing __instance, Map __0, ref Container? __state) { if (Multiplayer.Client == null) return; - __state = map; + __state = __0; ThingContext.Push(__instance); if (__instance.def.CanHaveFaction) - map.PushFaction(__instance.Faction); + __0.PushFaction(__instance.Faction); } [HarmonyPriority(MpPriority.MpLast)] diff --git a/Source/Common/Native.cs b/Source/Common/Native.cs index 76db753e..915e232a 100644 --- a/Source/Common/Native.cs +++ b/Source/Common/Native.cs @@ -95,7 +95,7 @@ public static unsafe void InitLmfPtr(NativeOS os) return string.IsNullOrEmpty(name) ? null : name; } - private static ConstructorInfo RuntimeMethodHandleCtor = AccessTools.Constructor(typeof(RuntimeMethodHandle), new[]{typeof(IntPtr)}); + private static ConstructorInfo runtimeMethodHandleCtor = AccessTools.Constructor(typeof(RuntimeMethodHandle), new[]{typeof(IntPtr)}); public static bool GetMethodAggressiveInlining(long addr) { @@ -105,8 +105,10 @@ public static bool GetMethodAggressiveInlining(long addr) if (ji == IntPtr.Zero) return false; var methodHandle = mono_jit_info_get_method(ji); - var methodInfo = - MethodBase.GetMethodFromHandle((RuntimeMethodHandle)RuntimeMethodHandleCtor.Invoke(new[] { (object)methodHandle })); + var rmh = (RuntimeMethodHandle)runtimeMethodHandleCtor.Invoke(new[] { (object)methodHandle }); + var rth = new RuntimeTypeHandle(); + var methodInfo = MethodBase.GetMethodFromHandle(rmh, rth); + if (methodInfo == null) return false; return (methodInfo.MethodImplementationFlags & MethodImplAttributes.AggressiveInlining) != 0; } diff --git a/Source/Common/Version.cs b/Source/Common/Version.cs index 132182a9..7796b9a7 100644 --- a/Source/Common/Version.cs +++ b/Source/Common/Version.cs @@ -2,7 +2,7 @@ namespace Multiplayer.Common { public static class MpVersion { - public const string Version = "0.9.1"; + public const string Version = "0.9.2"; public const int Protocol = 35; public const string ApiAssemblyName = "0MultiplayerAPI"; diff --git a/Source/TestsOnMono/Program.cs b/Source/TestsOnMono/Program.cs index ac302a1e..c6b48e1a 100644 --- a/Source/TestsOnMono/Program.cs +++ b/Source/TestsOnMono/Program.cs @@ -13,23 +13,27 @@ public static void Main(string[] args) Native.InitLmfPtr(Native.NativeOS.Dummy); Native.EarlyInit(Native.NativeOS.Dummy); - Test1(); + TestClass.Test1(); + TestClass.Test(); } - public static void Test() + class TestClass { - int hash = 0; - long[] trace = new long[8]; - DeferredStackTracingImpl.TraceImpl(trace, ref hash); - Console.WriteLine(hash); + public static void Test() + { + int hash = 0; + long[] trace = new long[8]; + DeferredStackTracingImpl.TraceImpl(trace, ref hash); + Console.WriteLine(hash); - foreach (long l in trace) - Console.WriteLine(Native.MethodNameFromAddr(l, false)); - } + foreach (long l in trace) + Console.WriteLine(Native.MethodNameFromAddr(l, false)); + } - [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.NoInlining)] - public static void Test1() - { - Test(); + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.NoInlining)] + public static void Test1() + { + Test(); + } } }