From aa05ee4b5ed30380d4404b5d22afd28ef0b11163 Mon Sep 17 00:00:00 2001 From: zerocker Date: Fri, 20 Feb 2026 14:30:42 +0900 Subject: [PATCH] feat: add support for entrypoint component class --- Source/ModDefinition/CodeMod.cs | 24 ++++++++++++++++++++++-- Source/ModDefinition/Metadata.cs | 2 ++ Source/ModDefinition/ModContainer.cs | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Source/ModDefinition/CodeMod.cs b/Source/ModDefinition/CodeMod.cs index c571d57..e1f6aa7 100644 --- a/Source/ModDefinition/CodeMod.cs +++ b/Source/ModDefinition/CodeMod.cs @@ -1,4 +1,5 @@ using System.Reflection; +using Common; using FezEngine.Tools; using HatModLoader.Source.AssemblyResolving; using HatModLoader.Source.FileProxies; @@ -19,7 +20,7 @@ private CodeMod(byte[] rawAssembly) RawAssembly = rawAssembly; } - public void Initialize(Game game) + public void Initialize(Game game, string entrypoint) { if (RawAssembly == null || RawAssembly.Length < 1) { @@ -33,8 +34,27 @@ public void Initialize(Game game) Assembly = Assembly.Load(RawAssembly); Components = []; + + Type[] types; + if (!string.IsNullOrEmpty(entrypoint)) + { + if (!Assembly.GetTypes().Any(t => t.FullName?.Equals(entrypoint) ?? false)) + { + throw new ArgumentException($"The entrypoint name is not a fully qualified name: {entrypoint}"); + } + + // Entrypoint class may load other components (services) via Game.Components (Game.Services) + Logger.Log("HAT", LogSeverity.Information, $"Starting at entrypoint {entrypoint}."); + types = [Assembly.GetType(entrypoint)]; + } + else + { + // Use backward compatible method + Logger.Log("HAT", LogSeverity.Warning, "No entrypoint was specified. Loading all public components..."); + types = Assembly.GetExportedTypes(); + } - foreach (var type in Assembly.GetExportedTypes()) + foreach (var type in types) { if (typeof(GameComponent).IsAssignableFrom(type) && type.IsPublic && !type.IsAbstract) { diff --git a/Source/ModDefinition/Metadata.cs b/Source/ModDefinition/Metadata.cs index 01e8c78..86b278f 100644 --- a/Source/ModDefinition/Metadata.cs +++ b/Source/ModDefinition/Metadata.cs @@ -31,6 +31,8 @@ public string VersionString } public string LibraryName { get; set; } + + public string Entrypoint { get; set; } public DependencyInfo[] Dependencies { get; set; } diff --git a/Source/ModDefinition/ModContainer.cs b/Source/ModDefinition/ModContainer.cs index b4ca05f..9bccc25 100644 --- a/Source/ModDefinition/ModContainer.cs +++ b/Source/ModDefinition/ModContainer.cs @@ -30,7 +30,7 @@ public void Initialize(Game game) { _assemblyResolver = new ModInternalAssemblyResolver(this); AssemblyResolverRegistry.Register(_assemblyResolver); - CodeMod?.Initialize(game); + CodeMod?.Initialize(game, Metadata.Entrypoint); } }