add plugin name patch to prevent game from logging plugin wrapper type
This commit is contained in:
23
CringeLauncher/Patches/PluginNamePatch.cs
Normal file
23
CringeLauncher/Patches/PluginNamePatch.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
using Sandbox;
|
||||
|
||||
namespace CringeLauncher.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(MySandboxGame), nameof(MySandboxGame.Run))]
|
||||
public static class PluginNamePatch
|
||||
{
|
||||
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
// replaces $"Plugin Init: {plugin.GetType()}"
|
||||
// to be just $"Plugin Init: {plugin}"
|
||||
// so you could override .ToString
|
||||
// doesn't change default behavior since base .ToString is .GetType().ToString()
|
||||
|
||||
return new CodeMatcher(instructions)
|
||||
.SearchForward(b => b.Is(OpCodes.Ldstr, "Plugin Init: "))
|
||||
.Advance(2)
|
||||
.Set(OpCodes.Callvirt, AccessTools.DeclaredMethod(typeof(object), nameof(ToString)))
|
||||
.InstructionEnumeration();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user