| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #define ILRuntime
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- #if ILRuntime
- using System.Linq;
- #endif
- namespace ET
- {
- public class CodeLoader
- {
- public static CodeLoader Instance = new CodeLoader();
- public Action Update;
- public Action LateUpdate;
- public Action OnApplicationQuit;
-
- private Type[] hotfixTypes;
- private CodeLoader()
- {
- }
-
- public void Start()
- {
- Dictionary<string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");
- byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes;
- byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes;
- #if ILRuntime
- ILRuntime.Runtime.Enviorment.AppDomain appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
- System.IO.MemoryStream assStream = new System.IO.MemoryStream(assBytes);
- System.IO.MemoryStream pdbStream = new System.IO.MemoryStream(pdbBytes);
- appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());
-
- ILHelper.InitILRuntime(appDomain);
-
- this.hotfixTypes = Type.EmptyTypes;
- this.hotfixTypes = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
- IStaticMethod start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0);
- #else
- System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(assBytes, pdbBytes);
- hotfixTypes = assembly.GetTypes();
- IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
- #endif
-
- start.Run();
- }
- public Type[] GetHotfixTypes()
- {
- return this.hotfixTypes;
- }
- }
- }
|