Entrypoint.cs 742 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Reflection;
  5. namespace BepInEx.Bootstrap
  6. {
  7. public static class Entrypoint
  8. {
  9. public static void Init()
  10. {
  11. AppDomain.CurrentDomain.AssemblyResolve += ResolveBepInEx;
  12. Linker.StartBepInEx();
  13. }
  14. private static readonly string LocalDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
  15. private static Assembly ResolveBepInEx(object sender, ResolveEventArgs args)
  16. {
  17. string path = Path.Combine(LocalDirectory, $@"BepInEx\core\{new AssemblyName(args.Name).Name}.dll");
  18. if (!File.Exists(path))
  19. return null;
  20. try
  21. {
  22. return Assembly.LoadFile(path);
  23. }
  24. catch (Exception)
  25. {
  26. return null;
  27. }
  28. }
  29. }
  30. }