DllHelper.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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[] GetHotfixTypes()
  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 Type[] GetMonoTypes()
  36. {
  37. return typeof(Game).Assembly.GetTypes();
  38. }
  39. public static IMethod[] GetMethodInfo(string typeName)
  40. {
  41. ILRuntime.Runtime.Enviorment.AppDomain appDomain = Init.Instance.AppDomain;
  42. if (appDomain == null)
  43. {
  44. return new IMethod[0];
  45. }
  46. return appDomain.GetType(typeName).GetMethods().ToArray();
  47. }
  48. public static IType GetType(string typeName)
  49. {
  50. return Init.Instance.AppDomain.GetType(typeName);
  51. }
  52. }
  53. }