| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using UnityEngine;
- namespace Model
- {
- 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.pdb").bytes;
- Assembly assembly = Assembly.Load(assBytes, mdbBytes);
- return assembly;
- }
- public static Type[] GetMonoTypes()
- {
- List<Type> types = new List<Type>();
- Assembly[] assemblies = Game.EntityEventManager.GetAssemblies();
- foreach (Assembly assembly in assemblies)
- {
- Type[] t = assembly.GetTypes();
- types.AddRange(t);
- }
- return types.ToArray();
- }
- public static Type[] GetHotfixTypes()
- {
- ILRuntime.Runtime.Enviorment.AppDomain appDomain = Game.EntityEventManager.AppDomain;
- if (appDomain == null)
- {
- return new Type[0];
- }
- return appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
- }
- public static object CreateHotfixObject(Type type)
- {
- object obj = Game.EntityEventManager.AppDomain.Instantiate(type.FullName);
- return obj;
- }
- public static T CreateHotfixObject<T>(Type type) where T: class
- {
- T obj = Game.EntityEventManager.AppDomain.Instantiate<T>(type.FullName);
- return obj;
- }
- }
- }
|