mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Runtime.Loader;
|
|
|
|
namespace ET
|
|
{
|
|
|
|
public class CodeLoader: Singleton<CodeLoader>, ISingletonAwake
|
|
{
|
|
private AssemblyLoadContext assemblyLoadContext;
|
|
|
|
private Assembly model;
|
|
|
|
public void Awake()
|
|
{
|
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
|
foreach (Assembly assembly in assemblies)
|
|
{
|
|
if (assembly.GetName().Name == "Model")
|
|
{
|
|
this.model = assembly;
|
|
break;
|
|
}
|
|
}
|
|
this.LoadHotfix();
|
|
|
|
IStaticMethod start = new StaticMethod(this.model, "ET.Entry", "Start");
|
|
start.Run();
|
|
}
|
|
|
|
public void LoadHotfix()
|
|
{
|
|
assemblyLoadContext?.Unload();
|
|
GC.Collect();
|
|
assemblyLoadContext = new AssemblyLoadContext("Hotfix", true);
|
|
byte[] dllBytes = File.ReadAllBytes("./Hotfix.dll");
|
|
byte[] pdbBytes = File.ReadAllBytes("./Hotfix.pdb");
|
|
Assembly hotfixAssembly = assemblyLoadContext.LoadFromStream(new MemoryStream(dllBytes), new MemoryStream(pdbBytes));
|
|
|
|
Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(Assembly.GetEntryAssembly(), typeof(Init).Assembly, typeof (Fiber).Assembly, this.model, hotfixAssembly);
|
|
|
|
World.Instance.AddSingleton<EventSystem, Dictionary<string, Type>>(types);
|
|
|
|
World.Instance.Load();
|
|
}
|
|
}
|
|
} |