Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions Source/ModDefinition/CodeMod.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using Common;
using FezEngine.Tools;
using HatModLoader.Source.AssemblyResolving;
using HatModLoader.Source.FileProxies;
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions Source/ModDefinition/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public string VersionString
}

public string LibraryName { get; set; }

public string Entrypoint { get; set; }

public DependencyInfo[] Dependencies { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion Source/ModDefinition/ModContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Initialize(Game game)
{
_assemblyResolver = new ModInternalAssemblyResolver(this);
AssemblyResolverRegistry.Register(_assemblyResolver);
CodeMod?.Initialize(game);
CodeMod?.Initialize(game, Metadata.Entrypoint);
}
}

Expand Down