Skip to content

Commit

Permalink
Fix some mod compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetrith committed Oct 21, 2023
1 parent 5adfff6 commit 20068a8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
1 change: 0 additions & 1 deletion Source/Client/MultiplayerStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
};
Expand Down
6 changes: 3 additions & 3 deletions Source/Client/Patches/ThingMethodPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ public static void Prefix(Thing __instance, ref Container<Map>? __state)
}

[HarmonyPriority(MpPriority.MpFirst)]
public static void Prefix_SpawnSetup(Thing __instance, Map map, ref Container<Map>? __state)
public static void Prefix_SpawnSetup(Thing __instance, Map __0, ref Container<Map>? __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)]
Expand Down
8 changes: 5 additions & 3 deletions Source/Common/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
30 changes: 17 additions & 13 deletions Source/TestsOnMono/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@ public static void Main(string[] args)
Native.InitLmfPtr(Native.NativeOS.Dummy);
Native.EarlyInit(Native.NativeOS.Dummy);

Test1();
TestClass<int>.Test1<int>();
TestClass<int>.Test();
}

public static void Test()
class TestClass<S>
{
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<T>()
{
Test();
}
}
}

0 comments on commit 20068a8

Please sign in to comment.