Sample mod project and modding bootstrap

This commit is contained in:
Alex
2025-01-10 23:42:41 +00:00
parent b62cf73086
commit ba78a15613
8 changed files with 109 additions and 6 deletions
+13 -5
View File
@@ -1,6 +1,6 @@
using Core.Annotations;
using System.Reflection;
using Core.Annotations;
using Core.Context;
using Core.Servers;
using Core.Utils;
namespace Server;
@@ -9,12 +9,13 @@ public static class Program
{
public static void Main(string[] args)
{
var assemblies = ModDllLoader.LoadAllMods();
HarmonyBootstrapper.LoadAllPatches(assemblies);
var builder = WebApplication.CreateBuilder(args);
RegisterSptComponents(builder.Services);
// TODO: deal with modding overriding services here!
RegisterModOverrideComponents(builder.Services, assemblies);
try
{
@@ -33,6 +34,13 @@ public static class Program
}
}
private static void RegisterModOverrideComponents(IServiceCollection builderServices, List<Assembly> assemblies)
{
// We get all the services from this assembly first, since mods will override them later
RegisterComponents(builderServices, assemblies.SelectMany(a => a.GetTypes())
.Where(type => Attribute.IsDefined(type, typeof(Injectable))));
}
private static void RegisterComponents(IServiceCollection builderServices, IEnumerable<Type> types)
{
var groupedTypes = types.Select(t =>