Skip to content

Commit

Permalink
Fixed game crashing when running vanilla game (without jk+) due to as…
Browse files Browse the repository at this point in the history
…suming main menu is initialized directly after startup
  • Loading branch information
Skippeh committed Mar 20, 2022
1 parent 096afe1 commit 0b995ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions JKMP.Core/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@ public static void OnPostGameInitialize()
{
PostGameInitialized?.Invoke(DefaultEventSender, EventArgs.Empty);
}

public static event EventHandler? GameTitleScreenLoaded;

public static void OnGameTitleScreenLoaded()
{
GameTitleScreenLoaded?.Invoke(DefaultEventSender, EventArgs.Empty);
}
}
}
5 changes: 5 additions & 0 deletions JKMP.Core/JKCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ internal JKCore()
Events.PostGameInitialized += OnPostGameInitialized;
Events.PreGameUpdate += OnPreGameUpdate;
Events.PostGameUpdate += OnPostGameUpdate;
Events.GameTitleScreenLoaded += OnGameTitleScreenLoaded;
}

internal void SaveConfig()
Expand All @@ -82,6 +83,10 @@ private void OnPostGameInitialized(object sender, EventArgs e)
JsonSerializerSettings = PluginManager.CreateDefaultJsonSerializerSettings()
};
Config = configs.LoadConfig<JkmpConfig>("Config");
}

private void OnGameTitleScreenLoaded(object sender, EventArgs e)
{
startupInformation = new();
}

Expand Down
9 changes: 9 additions & 0 deletions JKMP.Core/Patches/GameTitleScreenPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ private static void DrawLogo()
TextHelper.DrawString(JKContentManager.Font.MenuFont, logoText, drawPosition, Color.Gold, Vector2.Zero);
}
}

[HarmonyPatch(typeof(GameTitleScreen), "OnNewRun")]
internal static class GameTitleScreenOnNewRunPatch
{
private static void Postfix()
{
Events.OnGameTitleScreenLoaded();
}
}
}

0 comments on commit 0b995ff

Please sign in to comment.