[+] 接入ET8服务端

[+] 接入ET8服务端
This commit is contained in:
ALEXTANG
2023-07-13 12:23:48 +08:00
parent e0be062006
commit 336d4b2eb9
1316 changed files with 130657 additions and 626 deletions

29
DotNet/App/Program.cs Normal file
View File

@@ -0,0 +1,29 @@
using System;
using System.Threading;
namespace ET
{
public static class Program
{
public static void Main()
{
Entry.Init();
Init init = new();
init.Start();
while (true)
{
Thread.Sleep(1);
try
{
init.Update();
init.LateUpdate();
}
catch (Exception e)
{
Log.Error(e);
}
}
// ReSharper disable once FunctionNeverReturns
}
}
}

View File

@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<LangVersion>11.0</LangVersion>
<NoWarn>0169,0649,3021,8981</NoWarn>
</PropertyGroup>
</Project>

File diff suppressed because it is too large Load Diff

View 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();
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace ET
{
[Invoke]
public class GetAllConfigBytes: AInvokeHandler<ConfigComponent.GetAllConfigBytes, Dictionary<Type, byte[]>>
{
public override Dictionary<Type, byte[]> Handle(ConfigComponent.GetAllConfigBytes args)
{
Dictionary<Type, byte[]> output = new Dictionary<Type, byte[]>();
List<string> startConfigs = new List<string>()
{
"StartMachineConfigCategory",
"StartProcessConfigCategory",
"StartSceneConfigCategory",
"StartZoneConfigCategory",
};
HashSet<Type> configTypes = EventSystem.Instance.GetTypes(typeof (ConfigAttribute));
foreach (Type configType in configTypes)
{
string configFilePath;
if (startConfigs.Contains(configType.Name))
{
configFilePath = $"../Config/Excel/s/{Options.Instance.StartConfig}/{configType.Name}.bytes";
}
else
{
configFilePath = $"../Config/Excel/s/{configType.Name}.bytes";
}
output[configType] = File.ReadAllBytes(configFilePath);
}
return output;
}
}
[Invoke]
public class GetOneConfigBytes: AInvokeHandler<ConfigComponent.GetOneConfigBytes, byte[]>
{
public override byte[] Handle(ConfigComponent.GetOneConfigBytes args)
{
byte[] configBytes = File.ReadAllBytes($"../Config/Excel/s/{args.ConfigName}.bytes");
return configBytes;
}
}
}

42
DotNet/Loader/Init.cs Normal file
View File

@@ -0,0 +1,42 @@
using System;
using System.Threading;
using CommandLine;
namespace ET
{
public class Init
{
public void Start()
{
try
{
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
Log.Error(e.ExceptionObject.ToString());
};
// 命令行参数
Parser.Default.ParseArguments<Options>(System.Environment.GetCommandLineArgs())
.WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
.WithParsed((o)=>World.Instance.AddSingleton(o));
World.Instance.AddSingleton<Logger>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
ETTask.ExceptionHandler += Log.Error;
World.Instance.AddSingleton<CodeLoader>();
}
catch (Exception e)
{
Log.Error(e);
}
}
public void Update()
{
FiberManager.Instance.Update();
}
public void LateUpdate()
{
FiberManager.Instance.LateUpdate();
}
}
}

View File

@@ -0,0 +1,13 @@
using System.IO;
namespace ET
{
[Invoke]
public class RecastFileReader: AInvokeHandler<NavmeshComponent.RecastFileLoader, byte[]>
{
public override byte[] Handle(NavmeshComponent.RecastFileLoader args)
{
return File.ReadAllBytes(Path.Combine("../Config/Recast", args.Name));
}
}
}

View File

@@ -0,0 +1,6 @@
namespace Unity.Mathematics.UnityEngine
{
public class PropertyAttribute
{
}
}