fix addon patches

This commit is contained in:
_nebula 2022-12-14 11:47:01 +00:00
parent cda630ada6
commit 262d32c7f3
2 changed files with 22 additions and 0 deletions

View File

@ -17,8 +17,25 @@ public static class QSBPatchManager
public static Dictionary<QSBPatchTypes, Harmony> TypeToInstance = new();
private static bool _inited;
public static void Init()
{
if (_inited)
{
var count = _patchList.Count;
foreach (var type in typeof(QSBPatch).GetDerivedTypes())
{
if (!_patchList.Any(x => x.GetType() == type))
{
_patchList.Add((QSBPatch)Activator.CreateInstance(type));
}
}
DebugLog.DebugWrite($"Registered {_patchList.Count - count} addon patches.", MessageType.Success);
return;
}
foreach (var type in typeof(QSBPatch).GetDerivedTypes())
{
_patchList.Add((QSBPatch)Activator.CreateInstance(type));
@ -29,6 +46,7 @@ public static class QSBPatchManager
TypeToInstance.Add(type, new Harmony(type.ToString()));
}
_inited = true;
DebugLog.DebugWrite("Patch Manager ready.", MessageType.Success);
}

View File

@ -163,6 +163,9 @@ public class QSBCore : ModBehaviour
InitAssemblies();
// init again to get addon patches
QSBPatchManager.Init();
MenuApi = ModHelper.Interaction.TryGetModApi<IMenuAPI>(ModHelper.Manifest.Dependencies[0]);
DebugLog.DebugWrite("loading qsb_network_big bundle", MessageType.Info);
@ -215,6 +218,7 @@ public class QSBCore : ModBehaviour
var addons = GetDependants();
foreach (var addon in addons)
{
DebugLog.DebugWrite($"Registering addon {addon.ModHelper.Manifest.UniqueName}");
Addons.Add(addon.ModHelper.Manifest.UniqueName, addon);
}
}