DllHelper.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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[] GetHotfixTypes()
  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 Type[] GetMonoTypes()
  35. {
  36. List<Type> types = new List<Type>();
  37. foreach (Assembly assembly in AssemblyManager.Instance.GetAll())
  38. {
  39. types.AddRange(assembly.GetTypes());
  40. }
  41. return types.ToArray();
  42. }
  43. public static IMethod[] GetMethodInfo(string typeName)
  44. {
  45. ILRuntime.Runtime.Enviorment.AppDomain appDomain = Init.Instance.AppDomain;
  46. if (appDomain == null)
  47. {
  48. return new IMethod[0];
  49. }
  50. return appDomain.GetType(typeName).GetMethods().ToArray();
  51. }
  52. public static IType GetType(string typeName)
  53. {
  54. return Init.Instance.AppDomain.GetType(typeName);
  55. }
  56. }
  57. }