DllHelper.cs 1.5 KB

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