add unloading for mod assemblies

This commit is contained in:
zznty
2022-10-29 00:26:23 +07:00
parent 0035d12789
commit 7204815c0c
2 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
using System.Reflection;
using HarmonyLib;
using MonoMod.Utils;
namespace CringeLauncher.Utils;
public static class MethodTools
{
public static MethodInfo AsyncMethodBody(MethodInfo method)
{
var (_, operand) = PatchProcessor.ReadMethodBody(method).First();
if (operand is not LocalVariableInfo localVar)
throw new InvalidOperationException($"Method {method.GetID()} does not contain a valid async state machine");
return AccessTools.Method(localVar.LocalType, "MoveNext") ??
throw new InvalidOperationException(
$"Async State machine of method {method.GetID()} does not contain a valid MoveNext method");
}
}