diff --git a/src/OWML.ModHelper.Events/HarmonyHelper.cs b/src/OWML.ModHelper.Events/HarmonyHelper.cs index 35da5f52..4e939b19 100644 --- a/src/OWML.ModHelper.Events/HarmonyHelper.cs +++ b/src/OWML.ModHelper.Events/HarmonyHelper.cs @@ -97,7 +97,7 @@ public void Unpatch(string methodName, PatchType patchType = PatchType.All) { _console.WriteLine($"Unpatching {typeof(T).Name}.{methodName}", MessageType.Debug); - var sharedState = (Dictionary)typeof(HarmonySharedState).GetAnyMethod("GetState").Invoke(null, null); // todo TypeExtension + var sharedState = Utils.TypeExtensions.Invoke>(typeof(HarmonySharedState), "GetState"); var method = sharedState.Keys.First(m => m.DeclaringType == typeof(T) && m.Name == methodName); var patchInfo = PatchInfoSerialization.Deserialize(sharedState.GetValueSafe(method)); diff --git a/src/OWML.Utils/TypeExtensions.cs b/src/OWML.Utils/TypeExtensions.cs index ffff2fbb..2f840458 100644 --- a/src/OWML.Utils/TypeExtensions.cs +++ b/src/OWML.Utils/TypeExtensions.cs @@ -44,5 +44,8 @@ public static void Invoke(this object obj, string name, params object[] paramete public static T Invoke(this object obj, string name, params object[] parameters) => (T)obj.GetType().GetAnyMethod(name)?.Invoke(obj, parameters); + + public static T Invoke(this Type type, string name, params object[] parameters) => + (T)type.GetAnyMethod(name).Invoke(null, parameters); } } \ No newline at end of file