Skip to content

Commit

Permalink
feat: log a warning if a mod accesses a manager too early
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Sep 25, 2023
1 parent 873fe86 commit 818a343
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 18 deletions.
12 changes: 12 additions & 0 deletions JotunnLib/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,17 @@ private void InitializePatches()
tuple.Item1.Invoke(null, null);
}
}

internal static void LogManagerInit(string manager)
{
Jotunn.Logger.LogInfo($"Initializing {manager}");

if (!Instance)
{
string message = $"{manager} was accessed before Jotunn Awake, this can cause unexpected behaviour. " +
"Please make sure to add `[BepInDependency(Jotunn.Main.ModGuid)]` next to your BaseUnityPlugin";
Jotunn.Logger.LogWarning(BepInExUtils.GetSourceModMetadata(), message);
}
}
}
}
2 changes: 1 addition & 1 deletion JotunnLib/Managers/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static CommandManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing CommandManager");
Main.LogManagerInit("CommandManager");
AddConsoleCommand(new ClearCommand());

Main.Harmony.PatchAll(typeof(Patches));
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/CreatureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static CreatureManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing CreatureManager");
Main.LogManagerInit("CreatureManager");

SpawnListContainer = new GameObject("Creatures");
SpawnListContainer.transform.parent = Main.RootObject.transform;
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/GUIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static void TextInput_IsVisible(ref bool __result)
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing GUIManager");
Main.LogManagerInit("GUIManager");

// Cache headless state
Headless = SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null;
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static InputManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing InputManager");
Main.LogManagerInit("InputManager");

// Dont init on a dedicated server
if (!GUIManager.IsHeadless())
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/ItemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static ItemManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing ItemManager");
Main.LogManagerInit("ItemManager");
Main.Harmony.PatchAll(typeof(Patches));
}

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/KeyHintManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static KeyHintManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing KeyHintManager");
Main.LogManagerInit("KeyHintManager");

// Dont init on a headless server
if (!GUIManager.IsHeadless())
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/KitbashManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static KitbashManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing KitbashManager");
Main.LogManagerInit("KitbashManager");
ItemManager.OnKitbashItemsAvailable += ApplyKitbashes;
}

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/LocalizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static LocalizationManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing LocalizationManager");
Main.LogManagerInit("LocalizationManager");

Main.Harmony.PatchAll(typeof(Patches));

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/MinimapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static MinimapManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing MinimapManager");
Main.LogManagerInit("MinimapManager");

// Dont init on a headless server
if (GUIManager.IsHeadless())
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/MockSystem/MockManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private MockManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing MockManager");
Main.LogManagerInit("MockManager");

MockPrefabContainer = new GameObject("MockPrefabs");
MockPrefabContainer.transform.parent = Main.RootObject.transform;
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static NetworkManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing NetworkManager");
Main.LogManagerInit("NetworkManager");
Main.Harmony.PatchAll(typeof(Patches));
}

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/PieceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static class PieceCategorySettings
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing PieceManager");
Main.LogManagerInit("PieceManager");
Main.Harmony.PatchAll(typeof(Patches));
}

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/PrefabManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static PrefabManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing PrefabManager");
Main.LogManagerInit("PrefabManager");

PrefabContainer = new GameObject("Prefabs");
PrefabContainer.transform.parent = Main.RootObject.transform;
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/RenderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static RenderManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing RenderManager");
Main.LogManagerInit("RenderManager");

if (GUIManager.IsHeadless())
{
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/SkillManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static SkillManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing SkillManager");
Main.LogManagerInit("SkillManager");
Main.Harmony.PatchAll(typeof(Patches));
}

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/SynchronizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private SynchronizationManager() { }
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing SynchronizationManager");
Main.LogManagerInit("SynchronizationManager");

// Register RPCs and the admin watchdog
ConfigRPC = NetworkManager.Instance.AddRPC(
Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/UndoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static UndoManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing UndoManager");
Main.LogManagerInit("UndoManager");
Main.Harmony.PatchAll(typeof(Patches));
}

Expand Down
2 changes: 1 addition & 1 deletion JotunnLib/Managers/ZoneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static ZoneManager()
/// </summary>
void IManager.Init()
{
Logger.LogInfo("Initializing ZoneManager");
Main.LogManagerInit("ZoneManager");

LocationContainer = new GameObject("Locations");
LocationContainer.transform.parent = Main.RootObject.transform;
Expand Down

0 comments on commit 818a343

Please sign in to comment.