Skip to content
Permalink
Browse files

Added Traverse.SetValue warning hook

  • Loading branch information
ManlyMarco committed Nov 30, 2019
1 parent 92dd69e commit 8a65fc9c624408dab3fd1db26f4776627c453877
Showing with 9 additions and 1 deletion.
  1. +9 −1 BepInEx.Preloader/RuntimeFixes/HarmonyFixes.cs
@@ -12,7 +12,8 @@ public static void Apply()
{
var harmony = new HarmonyLib.Harmony("BepInEx.Preloader.RuntimeFixes.HarmonyFixes");
harmony.Patch(AccessTools.Method(typeof(Traverse), nameof(Traverse.GetValue), new Type[0]), null, new HarmonyMethod(typeof(HarmonyFixes), nameof(GetValue)));
}
harmony.Patch(AccessTools.Method(typeof(Traverse), nameof(Traverse.SetValue), new []{ typeof(object) }), null, new HarmonyMethod(typeof(HarmonyFixes), nameof(SetValue)));
}
catch (Exception e)
{
Logging.Logger.LogError(e);
@@ -24,5 +25,12 @@ private static void GetValue(Traverse __instance)
if (!__instance.FieldExists() && !__instance.MethodExists() && !__instance.TypeExists())
Logging.Logger.LogWarning("Traverse.GetValue was called while not pointing at an existing Field, Property, Method or Type. The return value can be unexpected.\n" + new StackTrace());
}

private static void SetValue(Traverse __instance)
{
// If method exists it will crash inside traverse so only need to mention the field missing
if (!__instance.FieldExists() && !__instance.MethodExists())
Logging.Logger.LogWarning("Traverse.SetValue was called while not pointing at an existing Field or Property. The call will have no effect.\n" + new StackTrace());
}
}
}

0 comments on commit 8a65fc9

Please sign in to comment.
You can’t perform that action at this time.