DllHelper.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using ILRuntime.CLR.Method;
  6. using ILRuntime.CLR.TypeSystem;
  7. using UnityEngine;
  8. namespace Model
  9. {
  10. public static class DllHelper
  11. {
  12. public static Assembly LoadHotfixAssembly()
  13. {
  14. GameObject code = (GameObject)Resources.Load("Code");
  15. byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
  16. byte[] mdbBytes = code.Get<TextAsset>("Hotfix.dll.mdb").bytes;
  17. Assembly assembly = Assembly.Load(assBytes, mdbBytes);
  18. return assembly;
  19. }
  20. public static Type[] GetAllTypes()
  21. {
  22. ILRuntime.Runtime.Enviorment.AppDomain appDomain = Init.Instance.AppDomain;
  23. if (appDomain == null)
  24. {
  25. return new Type[0];
  26. }
  27. List<Type> types = new List<Type>();
  28. foreach (IType type in appDomain.LoadedTypes.Values.ToArray())
  29. {
  30. types.Add(type.ReflectionType);
  31. }
  32. return types.ToArray();
  33. }
  34. public static IMethod[] GetMethodInfo(string typeName)
  35. {
  36. ILRuntime.Runtime.Enviorment.AppDomain appDomain = Init.Instance.AppDomain;
  37. if (appDomain == null)
  38. {
  39. return new IMethod[0];
  40. }
  41. return appDomain.GetType(typeName).GetMethods().ToArray();
  42. }
  43. public static IType GetType(string typeName)
  44. {
  45. return Init.Instance.AppDomain.GetType(typeName);
  46. }
  47. }
  48. }