Skip to content

Commit 874a3de

Browse files
committed
isolate mod component creation
1 parent 959db0f commit 874a3de

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Source/Hat.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ public void InitalizeAssemblies()
198198
{
199199
mod.InitializeAssembly();
200200
}
201+
foreach (var mod in Mods)
202+
{
203+
mod.InitializeComponents();
204+
}
201205
Logger.Log("HAT", "Assembly initialization completed!");
202206
}
203207

@@ -214,7 +218,7 @@ public void InitalizeComponents()
214218
{
215219
foreach(var mod in Mods)
216220
{
217-
mod.InitializeComponents();
221+
mod.InjectComponents();
218222
}
219223
Logger.Log("HAT", "Component initialization completed!");
220224
}

Source/Mod.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,21 @@ public void InitializeAssets()
9090
}
9191
}
9292

93-
// injects custom components of this mod into the game
93+
9494
public void InitializeComponents()
95+
{
96+
if (RawAssembly == null || Assembly == null) return;
97+
98+
foreach (Type type in Assembly.GetExportedTypes())
99+
{
100+
if (!typeof(IGameComponent).IsAssignableFrom(type) || !type.IsPublic) continue;
101+
var gameComponent = (IGameComponent)Activator.CreateInstance(type, new object[] { ModLoader.Game });
102+
Components.Add(gameComponent);
103+
}
104+
}
105+
106+
// injects custom components of this mod into the game
107+
public void InjectComponents()
95108
{
96109
// add game components
97110
foreach (var component in Components)
@@ -102,17 +115,11 @@ public void InitializeComponents()
102115
}
103116
}
104117

118+
// loads mod's assemblies
105119
public void InitializeAssembly()
106120
{
107121
if (RawAssembly == null) return;
108122
Assembly = Assembly.Load(RawAssembly);
109-
110-
foreach (Type type in Assembly.GetExportedTypes())
111-
{
112-
if (!typeof(IGameComponent).IsAssignableFrom(type) || !type.IsPublic) continue;
113-
var gameComponent = (IGameComponent)Activator.CreateInstance(type, new object[] { ModLoader.Game });
114-
Components.Add(gameComponent);
115-
}
116123
}
117124

118125
public void Dispose()

0 commit comments

Comments
 (0)