DllHelper.cs 1.3 KB

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