Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
features-not-bugs committed Feb 21, 2021
1 parent 55509e3 commit 789e23e
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 156 deletions.
Binary file removed deps/0Harmony.dll
Binary file not shown.
Binary file removed deps/Rust.Harmony.dll
Binary file not shown.
Binary file added harmony2_override/0Harmony.dll
Binary file not shown.
Binary file added harmony2_override/Rust.Harmony.dll
Binary file not shown.
34 changes: 0 additions & 34 deletions src/RustServerMetrics/Harmony/TimeWarning/Dispose_Patch.cs

This file was deleted.

35 changes: 0 additions & 35 deletions src/RustServerMetrics/Harmony/TimeWarning/New_Patch.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using Harmony;
using HarmonyLib;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

namespace RustServerMetrics.Harmony.BasePlayer
namespace RustServerMetrics.HarmonyPatches
{
[HarmonyPatch(typeof(global::BasePlayer), nameof(global::BasePlayer.OnDisconnected))]
public class OnDisconnected_Patch
[HarmonyPatch(typeof(BasePlayer), nameof(BasePlayer.OnDisconnected))]
public class BasePlayer_OnDisconnected_Patch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> originalInstructions)
{
List<CodeInstruction> retList = new List<CodeInstruction>(originalInstructions);

var fieldInfo = typeof(SingletonComponent<MetricsLogger>)
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), BindingFlags.Static | BindingFlags.Public);

var methodInfo = typeof(MetricsLogger)
.GetMethod(nameof(MetricsLogger.OnPlayerDisconnected), System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
.GetMethod(nameof(MetricsLogger.OnPlayerDisconnected), BindingFlags.Instance | BindingFlags.NonPublic);

retList.InsertRange(0, new List<CodeInstruction>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using Harmony;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

namespace RustServerMetrics.Harmony.BasePlayer
namespace RustServerMetrics.HarmonyPatches
{
[HarmonyPatch(typeof(global::BasePlayer), nameof(global::BasePlayer.PlayerInit))]
public class PlayerInit_Patch
[HarmonyPatch(typeof(BasePlayer), nameof(BasePlayer.PlayerInit))]
public class BasePlayer_PlayerInit_Patch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> originalInstructions)
{
List<CodeInstruction> retList = new List<CodeInstruction>(originalInstructions);

var fieldInfo = typeof(SingletonComponent<MetricsLogger>)
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), BindingFlags.Static | BindingFlags.Public);

var methodInfo = typeof(MetricsLogger)
.GetMethod(nameof(MetricsLogger.OnPlayerInit), System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
.GetMethod(nameof(MetricsLogger.OnPlayerInit), BindingFlags.Instance | BindingFlags.NonPublic);

var idx = retList.FindIndex(x => x.opcode == OpCodes.Call && x.operand is MethodInfo methodInfo1 && methodInfo1.DeclaringType.Name == "EACServer" && methodInfo1.Name == "OnStartLoading");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
using Harmony;
using System;
using HarmonyLib;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace RustServerMetrics.Harmony.Bootstrap
namespace RustServerMetrics.HarmonyPatches
{
[HarmonyPatch(typeof(global::Bootstrap), nameof(global::Bootstrap.StartServer))]
public class StartServer_Patch
[HarmonyPatch(typeof(Bootstrap), nameof(Bootstrap.StartServer))]
public class Bootstrap_StartServer_Patch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> originalInstructions)
{
List<CodeInstruction> retList = new List<CodeInstruction>(originalInstructions);

var methodInfo = typeof(MetricsLogger)
.GetMethod(nameof(MetricsLogger.Initialize), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
.GetMethod(nameof(MetricsLogger.Initialize), BindingFlags.Static | BindingFlags.NonPublic);

retList.InsertRange(0, new List<CodeInstruction>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using Harmony;
using HarmonyLib;
using Network;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

namespace RustServerMetrics.Harmony.NetWrite
namespace RustServerMetrics.HarmonyPatches
{
[HarmonyPatch(typeof(Network.NetWrite), nameof(Network.NetWrite.PacketID))]
public class PacketID_Patch
[HarmonyPatch(typeof(NetWrite), nameof(NetWrite.PacketID))]
public class NetWrite_PacketID_Patch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> originalInstructions)
{
List<CodeInstruction> retList = new List<CodeInstruction>(originalInstructions);

var fieldInfo = typeof(SingletonComponent<MetricsLogger>)
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), BindingFlags.Static | BindingFlags.Public);

var methodInfo = typeof(MetricsLogger)
.GetMethod(nameof(MetricsLogger.OnNetWritePacketID), System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
.GetMethod(nameof(MetricsLogger.OnNetWritePacketID), BindingFlags.Instance | BindingFlags.NonPublic);

retList.InsertRange(retList.Count - 1, new List<CodeInstruction>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using Harmony;
using HarmonyLib;
using Network;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

namespace RustServerMetrics.Harmony.NetWrite
namespace RustServerMetrics.HarmonyPatches
{
[HarmonyPatch(typeof(Network.NetWrite), nameof(Network.NetWrite.Send))]
public class Send_Patch
[HarmonyPatch(typeof(NetWrite), nameof(NetWrite.Send))]
public class NetWrite_Send_Patch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> originalInstructions)
{
List<CodeInstruction> retList = new List<CodeInstruction>(originalInstructions);

var fieldInfo = typeof(SingletonComponent<MetricsLogger>)
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), BindingFlags.Static | BindingFlags.Public);

var methodInfo = typeof(MetricsLogger)
.GetMethod(nameof(MetricsLogger.OnNetWriteSend), System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
.GetMethod(nameof(MetricsLogger.OnNetWriteSend), BindingFlags.Instance | BindingFlags.NonPublic);

retList.InsertRange(retList.Count - 1, new List<CodeInstruction>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using Harmony;
using HarmonyLib;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

namespace RustServerMetrics.Harmony.Performance
namespace RustServerMetrics.HarmonyPatches
{
[HarmonyPatch(typeof(global::Performance), "FPSTimer")]
public class FPSTimer_Patch
[HarmonyPatch(typeof(Performance), "FPSTimer")]
public class Performance_FPSTimer_Patch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> originalInstructions)
{
List<CodeInstruction> retList = new List<CodeInstruction>(originalInstructions);

var fieldInfo = typeof(SingletonComponent<MetricsLogger>)
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
.GetField(nameof(SingletonComponent<MetricsLogger>.Instance), BindingFlags.Static | BindingFlags.Public);

var methodInfo = typeof(MetricsLogger)
.GetMethod(nameof(MetricsLogger.OnPerformanceReportGenerated), System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
.GetMethod(nameof(MetricsLogger.OnPerformanceReportGenerated), BindingFlags.Instance | BindingFlags.NonPublic);

retList.InsertRange(retList.Count - 1, new List<CodeInstruction>
{
Expand Down
25 changes: 25 additions & 0 deletions src/RustServerMetrics/HarmonyPatches/TimeWarning_Dispose_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using HarmonyLib;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

namespace RustServerMetrics.HarmonyPatches
{
[HarmonyPatch(typeof(TimeWarning), nameof(TimeWarning.Dispose))]
public static class TimeWarning_Dispose_Patch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> originalInstructions)
{
var methodInfo = typeof(MetricsTimeWarning)
.GetMethod(nameof(MetricsTimeWarning.DisposeTimeWarning), BindingFlags.Static | BindingFlags.Public);

return new CodeInstruction[]
{
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Call, methodInfo),
new CodeInstruction(OpCodes.Ret)
};
}
}
}
26 changes: 26 additions & 0 deletions src/RustServerMetrics/HarmonyPatches/TimeWarning_New_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using HarmonyLib;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;

namespace RustServerMetrics.HarmonyPatches
{
[HarmonyPatch(typeof(TimeWarning), nameof(TimeWarning.New))]
public static class TimeWarning_New_Patch
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> originalInstructions)
{
var methodInfo = typeof(MetricsTimeWarning)
.GetMethod(nameof(MetricsTimeWarning.GetTimeWarning), BindingFlags.Static | BindingFlags.Public);

return new List<CodeInstruction>
{
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldarg_1),
new CodeInstruction(OpCodes.Call, methodInfo),
new CodeInstruction(OpCodes.Ret)
};
}
}
}
Loading

0 comments on commit 789e23e

Please sign in to comment.