Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 8853beb

Browse files
authored
Upgrading Harmony to 2.x for the May 2024 update (#19)
* quick work around to get post-start patches working with harmony 2.x * small message edit * fix oxide spam if not running oxide
1 parent 4ccee57 commit 8853beb

18 files changed

Lines changed: 143 additions & 38 deletions

src/RustServerMetrics/HarmonyPatches/BasePlayer_OnDisconnected_Patch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Harmony;
1+
using HarmonyLib;
22
using System.Collections.Generic;
33
using System.Reflection;
44
using System.Reflection.Emit;

src/RustServerMetrics/HarmonyPatches/BasePlayer_PerformanceReport_Patch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Harmony;
1+
using HarmonyLib;
22
using Newtonsoft.Json;
33
using System;
44
using System.Collections.Generic;

src/RustServerMetrics/HarmonyPatches/BasePlayer_PlayerInit_Patch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Harmony;
1+
using HarmonyLib;
22
using System;
33
using System.Collections.Generic;
44
using System.Reflection;

src/RustServerMetrics/HarmonyPatches/Bootstrap_StartServer_Patch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Harmony;
1+
using HarmonyLib;
22
using System.Collections.Generic;
33
using System.Reflection;
44
using System.Reflection.Emit;

src/RustServerMetrics/HarmonyPatches/Delayed/ConsoleSystem_Internal_Patch.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
using Harmony;
1+
using HarmonyLib;
22
using RustServerMetrics.HarmonyPatches.Utility;
33
using System;
44
using System.Collections.Generic;
55
using System.Reflection;
6+
using UnityEngine;
67

78
namespace RustServerMetrics.HarmonyPatches.Delayed
89
{
910
[DelayedHarmonyPatch]
11+
[HarmonyPatch]
1012
internal class ConsoleSystem_Internal_Patch
1113
{
14+
[HarmonyPrepare]
15+
public static bool Prepare()
16+
{
17+
if (!RustServerMetricsLoader.__serverStarted)
18+
{
19+
Debug.Log("Note: Cannot patch ConsoleSystem_Internal_Patch yet. We will patch it upon server start.");
20+
return false;
21+
}
22+
23+
return true;
24+
}
25+
1226
[HarmonyTargetMethods]
13-
public static IEnumerable<MethodBase> TargetMethods(HarmonyInstance harmonyInstance)
27+
public static IEnumerable<MethodBase> TargetMethods(Harmony harmonyInstance)
1428
{
1529
yield return AccessTools.DeclaredMethod(typeof(ConsoleSystem), nameof(ConsoleSystem.Internal));
1630
}

src/RustServerMetrics/HarmonyPatches/Delayed/InvokeHandlerBase_DoTick_Patch.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
using Harmony;
1+
using HarmonyLib;
22
using RustServerMetrics.HarmonyPatches.Utility;
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Reflection;
77
using System.Reflection.Emit;
8+
using UnityEngine;
89

910
namespace RustServerMetrics.HarmonyPatches.Delayed
1011
{
1112
[DelayedHarmonyPatch]
13+
[HarmonyPatch]
1214
internal static class InvokeHandlerBase_DoTick_Patch
1315
{
1416
static System.Diagnostics.Stopwatch _stopwatch = new System.Diagnostics.Stopwatch();
@@ -21,8 +23,20 @@ internal static class InvokeHandlerBase_DoTick_Patch
2123
new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(Action), nameof(Action.Invoke)))
2224
};
2325

26+
[HarmonyPrepare]
27+
public static bool Prepare()
28+
{
29+
if (!RustServerMetricsLoader.__serverStarted)
30+
{
31+
Debug.Log("Note: Cannot patch InvokeHandlerBase_DoTick_Patch yet. We will patch it upon server start.");
32+
return false;
33+
}
34+
35+
return true;
36+
}
37+
2438
[HarmonyTargetMethods]
25-
public static IEnumerable<MethodBase> TargetMethods(HarmonyInstance harmonyInstance)
39+
public static IEnumerable<MethodBase> TargetMethods(Harmony harmonyInstance)
2640
{
2741
yield return AccessTools.DeclaredMethod(typeof(InvokeHandlerBase<InvokeHandler>), nameof(InvokeHandlerBase<InvokeHandler>.DoTick));
2842
}

src/RustServerMetrics/HarmonyPatches/Delayed/ObjectWorkQueue_RunJob_Patch.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Harmony;
1+
using HarmonyLib;
22
using RustServerMetrics.HarmonyPatches.Utility;
33
using System;
44
using System.Collections.Generic;
@@ -10,10 +10,23 @@
1010
namespace RustServerMetrics.HarmonyPatches.Delayed
1111
{
1212
[DelayedHarmonyPatch]
13+
[HarmonyPatch]
1314
internal static class ObjectWorkQueue_RunJob_Patch
1415
{
16+
[HarmonyPrepare]
17+
public static bool Prepare()
18+
{
19+
if (!RustServerMetricsLoader.__serverStarted)
20+
{
21+
Debug.Log("Note: Cannot patch ObjectWorkQueue_RunJob_Patch yet. We will patch it upon server start.");
22+
return false;
23+
}
24+
25+
return true;
26+
}
27+
1528
[HarmonyTargetMethods]
16-
public static IEnumerable<MethodBase> TargetMethods(HarmonyInstance harmonyInstance)
29+
public static IEnumerable<MethodBase> TargetMethods(Harmony harmonyInstance)
1730
{
1831
var assemblyCSharp = typeof(BaseNetworkable).Assembly;
1932
Stack<Type> typesToScan = new Stack<Type>(assemblyCSharp.GetTypes());

src/RustServerMetrics/HarmonyPatches/Delayed/RPCServer_Attribute_Method_Patch.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Harmony;
1+
using HarmonyLib;
22
using RustServerMetrics.HarmonyPatches.Utility;
33
using System;
44
using System.Collections.Generic;
@@ -10,10 +10,23 @@
1010
namespace RustServerMetrics.HarmonyPatches.Delayed
1111
{
1212
[DelayedHarmonyPatch]
13+
[HarmonyPatch]
1314
internal class RPCServer_Attribute_Method_Patch
1415
{
16+
[HarmonyPrepare]
17+
public static bool Prepare()
18+
{
19+
if (!RustServerMetricsLoader.__serverStarted)
20+
{
21+
Debug.Log("Note: Cannot patch RPCServer_Attribute_Method_Patch yet. We will patch it upon server start.");
22+
return false;
23+
}
24+
25+
return true;
26+
}
27+
1528
[HarmonyTargetMethods]
16-
public static IEnumerable<MethodBase> TargetMethods(HarmonyInstance harmonyInstance)
29+
public static IEnumerable<MethodBase> TargetMethods(Harmony harmonyInstance)
1730
{
1831
var baseNetworkableType = typeof(BaseNetworkable);
1932
var baseNetworkableAssembly = baseNetworkableType.Assembly;

src/RustServerMetrics/HarmonyPatches/Delayed/ServerMgr_Metrics_Patches.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,30 @@
33
using System.Linq;
44
using System.Reflection;
55
using System.Reflection.Emit;
6-
using Harmony;
6+
using HarmonyLib;
77
using RustServerMetrics.HarmonyPatches.Utility;
88
using UnityEngine;
99

1010
namespace RustServerMetrics.HarmonyPatches.Delayed;
1111

1212
[DelayedHarmonyPatch]
13+
[HarmonyPatch]
1314
internal static class ServerMgr_Metrics_Patches
1415
{
16+
[HarmonyPrepare]
17+
public static bool Prepare()
18+
{
19+
if (!RustServerMetricsLoader.__serverStarted)
20+
{
21+
Debug.Log("Note: Cannot patch ServerMgr_Metrics_Patches yet. We will patch it upon server start.");
22+
return false;
23+
}
24+
25+
return true;
26+
}
27+
1528
[HarmonyTargetMethods]
16-
public static IEnumerable<MethodBase> TargetMethods(HarmonyInstance harmonyInstance)
29+
public static IEnumerable<MethodBase> TargetMethods(Harmony harmonyInstance)
1730
{
1831
yield return AccessTools.Method(typeof(ServerMgr), nameof(ServerMgr.Update));
1932
yield return AccessTools.Method(typeof(ServerBuildingManager), nameof(ServerBuildingManager.Cycle));

src/RustServerMetrics/HarmonyPatches/NetWrite_PacketID_Patch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Harmony;
1+
using HarmonyLib;
22
using Network;
33

44
namespace RustServerMetrics.HarmonyPatches

0 commit comments

Comments
 (0)