All checks were successful
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 4m4s
Build / Build Nuget package (NuGet) (push) Successful in 4m7s
Build / Build Nuget package (SharedCringe) (push) Successful in 4m5s
Build / Build Nuget package (CringePlugins) (push) Successful in 4m25s
Build / Build Launcher (push) Successful in 5m12s
Also ran cleanup
23 lines
830 B
C#
23 lines
830 B
C#
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();
|
|
}
|
|
} |