diff --git a/PulsarModLoader/MPModChecks/MPModCheckManager.cs b/PulsarModLoader/MPModChecks/MPModCheckManager.cs index fd74e1c..35ece2d 100644 --- a/PulsarModLoader/MPModChecks/MPModCheckManager.cs +++ b/PulsarModLoader/MPModChecks/MPModCheckManager.cs @@ -2,7 +2,6 @@ using PulsarModLoader.Patches; using Steamworks; using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -25,20 +24,53 @@ public class MPModCheckManager public MPModCheckManager() { Instance = this; - RefreshData(); ModManager.Instance.OnModUnloaded += RefreshData; + ModManager.Instance.OnModSuccessfullyLoaded += RefreshData; + ModManager.Instance.OnAllModsLoaded += RefreshData; } + /// + /// Delays Refreshing of MPModList until all mods have been loaded. + /// + public void HoldMPModListRefresh() + { + HoldRefreshUntilAllModsLoaded = true; + } + + private bool HoldRefreshUntilAllModsLoaded = false; + /// /// Updates modlists /// - /// - public void RefreshData(PulsarMod mod = null) + public void RefreshData() { + HoldRefreshUntilAllModsLoaded = true; UpdateMyModList(); UpdateLobbyModList(); } + /// + /// Calls normal RefreshData + /// + /// + /// + private void RefreshData(string name, PulsarMod mod) + { + if (HoldRefreshUntilAllModsLoaded) + { + RefreshData(); + } + } + + /// + /// Calls normal RefreshData + /// + /// + private void RefreshData(PulsarMod mod = null) + { + RefreshData(); + } + private void UpdateLobbyModList() //Update Photon Lobby Listing with mod list { if (PhotonNetwork.isMasterClient && PhotonNetwork.inRoom && PLNetworkManager.Instance != null) @@ -57,6 +89,27 @@ private void UpdateLobbyModList() //Update Photon Lobby Listing with mod list private MPModDataBlock[] MyModList = null; + /// + /// Called after all mod checks finished HostSide + /// + public delegate void ModChecksFinishedHost(PhotonPlayer JoiningPhotonPlayer); + + /// + /// Called after all mod checks finished HostSide + /// + public event ModChecksFinishedHost OnModChecksFinishedHost; + + /* + /// + /// Called after all mod checks finished ClientSide + /// + //public delegate void ModChecksFinishedClient(); + + /// + /// Called after all mod checks finished ClientSide + /// + //public event ModChecksFinishedClient OnModChecksFinishedClient;*/ + /// /// List of clients that have requested mod lists of other clients. /// @@ -600,6 +653,7 @@ public bool HostOnClientJoined(PhotonPlayer Player) } else { + OnModChecksFinishedHost?.Invoke(Player); Logger.Info("Modcheck passed, proceding onwards"); } } diff --git a/PulsarModLoader/ModManager.cs b/PulsarModLoader/ModManager.cs index adee0e6..be9ab9c 100644 --- a/PulsarModLoader/ModManager.cs +++ b/PulsarModLoader/ModManager.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.IO.Compression; +using PulsarModLoader.MPModChecks; namespace PulsarModLoader { @@ -199,6 +200,10 @@ public IEnumerable GetAllMods() /// public void LoadModsDirectory(string modsDir) { + //Delays MPModListRefresh + MPModCheckManager.Instance.HoldMPModListRefresh(); + + OnModSuccessfullyLoaded += Events.EventHelper.RegisterEventHandlers; Logger.Info($"Attempting to load mods from {modsDir}"); diff --git a/PulsarModLoader/Patches/PLGlobalStart.cs b/PulsarModLoader/Patches/PLGlobalStart.cs index 7f38e11..ad24860 100644 --- a/PulsarModLoader/Patches/PLGlobalStart.cs +++ b/PulsarModLoader/Patches/PLGlobalStart.cs @@ -22,13 +22,13 @@ static void Prefix() //KeybindManager Init() _ = PulsarModLoader.Keybinds.KeybindManager.Instance; + //MP Mod Checks + new MPModChecks.MPModCheckManager(); + //ModLoading string modsDir = Path.Combine(Directory.GetCurrentDirectory(), "Mods"); ModManager.Instance.LoadModsDirectory(modsDir); - //MP Mod Checks - new MPModChecks.MPModCheckManager(); - modsLoaded = true; } }