HarmonyFixes.cs 858 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Diagnostics;
  3. using HarmonyLib;
  4. namespace BepInEx.Preloader.RuntimeFixes
  5. {
  6. internal static class HarmonyFixes
  7. {
  8. public static void Apply()
  9. {
  10. try
  11. {
  12. var harmony = new HarmonyLib.Harmony("BepInEx.Preloader.RuntimeFixes.HarmonyFixes");
  13. harmony.Patch(AccessTools.Method(typeof(Traverse), nameof(Traverse.GetValue), new Type[0]), null, new HarmonyMethod(typeof(HarmonyFixes), nameof(GetValue)));
  14. }
  15. catch (Exception e)
  16. {
  17. Logging.Logger.LogError(e);
  18. }
  19. }
  20. private static void GetValue(Traverse __instance)
  21. {
  22. if (!__instance.FieldExists() && !__instance.MethodExists() && !__instance.TypeExists())
  23. 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());
  24. }
  25. }
  26. }