mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
49
DotNet/Loader/CodeLoader.cs
Normal file
49
DotNet/Loader/CodeLoader.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user