DllHelper.cs 1.5 KB
Newer Older
1 2 3 4 5 6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ILRuntime.CLR.Method;
using ILRuntime.CLR.TypeSystem;
T
tanghai 已提交
7
using Model;
8 9
using UnityEngine;

10
namespace Model
11 12 13 14 15 16 17 18 19 20 21 22
{
	public static class DllHelper
	{
		public static Assembly LoadHotfixAssembly()
		{
			GameObject code = (GameObject)Resources.Load("Code");
			byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
			byte[] mdbBytes = code.Get<TextAsset>("Hotfix.dll.mdb").bytes;
			Assembly assembly = Assembly.Load(assBytes, mdbBytes);
			return assembly;
		}

23
		public static Type[] GetHotfixTypes()
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
		{
			ILRuntime.Runtime.Enviorment.AppDomain appDomain = Init.Instance.AppDomain;
			if (appDomain == null)
			{
				return new Type[0];
			}
			
			List<Type> types = new List<Type>();
			foreach (IType type in appDomain.LoadedTypes.Values.ToArray())
			{
				types.Add(type.ReflectionType);
			}
			return types.ToArray();
		}

39 40
		public static Type[] GetMonoTypes()
		{
T
tanghai 已提交
41 42 43 44 45 46
			List<Type> types = new List<Type>();
			foreach (Assembly assembly in AssemblyManager.Instance.GetAll())
			{
				types.AddRange(assembly.GetTypes());
			}
			return types.ToArray();
47 48
		}

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
		public static IMethod[] GetMethodInfo(string typeName)
		{
			ILRuntime.Runtime.Enviorment.AppDomain appDomain = Init.Instance.AppDomain;
			if (appDomain == null)
			{
				return new IMethod[0];
			}
			
			return appDomain.GetType(typeName).GetMethods().ToArray();
		}

		public static IType GetType(string typeName)
		{
			return Init.Instance.AppDomain.GetType(typeName);
		}
	}
}