Skip to content

Commit

Permalink
Added event for mod checks finished. Appears functional.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagord committed Nov 11, 2023
1 parent 38c3d18 commit 2bbef4e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
62 changes: 58 additions & 4 deletions PulsarModLoader/MPModChecks/MPModCheckManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using PulsarModLoader.Patches;
using Steamworks;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand All @@ -25,20 +24,53 @@ public class MPModCheckManager
public MPModCheckManager()
{
Instance = this;
RefreshData();
ModManager.Instance.OnModUnloaded += RefreshData;
ModManager.Instance.OnModSuccessfullyLoaded += RefreshData;
ModManager.Instance.OnAllModsLoaded += RefreshData;
}

/// <summary>
/// Delays Refreshing of MPModList until all mods have been loaded.
/// </summary>
public void HoldMPModListRefresh()
{
HoldRefreshUntilAllModsLoaded = true;
}

private bool HoldRefreshUntilAllModsLoaded = false;

/// <summary>
/// Updates modlists
/// </summary>
/// <param name="mod"></param>
public void RefreshData(PulsarMod mod = null)
public void RefreshData()
{
HoldRefreshUntilAllModsLoaded = true;
UpdateMyModList();
UpdateLobbyModList();
}

/// <summary>
/// Calls normal RefreshData
/// </summary>
/// <param name="name"></param>
/// <param name="mod"></param>
private void RefreshData(string name, PulsarMod mod)
{
if (HoldRefreshUntilAllModsLoaded)
{
RefreshData();
}
}

/// <summary>
/// Calls normal RefreshData
/// </summary>
/// <param name="mod"></param>
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)
Expand All @@ -57,6 +89,27 @@ private void UpdateLobbyModList() //Update Photon Lobby Listing with mod list

private MPModDataBlock[] MyModList = null;

/// <summary>
/// Called after all mod checks finished HostSide
/// </summary>
public delegate void ModChecksFinishedHost(PhotonPlayer JoiningPhotonPlayer);

/// <summary>
/// Called after all mod checks finished HostSide
/// </summary>
public event ModChecksFinishedHost OnModChecksFinishedHost;

/*
/// <summary>
/// Called after all mod checks finished ClientSide
/// </summary>
//public delegate void ModChecksFinishedClient();
/// <summary>
/// Called after all mod checks finished ClientSide
/// </summary>
//public event ModChecksFinishedClient OnModChecksFinishedClient;*/

/// <summary>
/// List of clients that have requested mod lists of other clients.
/// </summary>
Expand Down Expand Up @@ -600,6 +653,7 @@ public bool HostOnClientJoined(PhotonPlayer Player)
}
else
{
OnModChecksFinishedHost?.Invoke(Player);
Logger.Info("Modcheck passed, proceding onwards");
}
}
Expand Down
5 changes: 5 additions & 0 deletions PulsarModLoader/ModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.IO.Compression;
using PulsarModLoader.MPModChecks;

namespace PulsarModLoader
{
Expand Down Expand Up @@ -199,6 +200,10 @@ public IEnumerable<PulsarMod> GetAllMods()
/// <param name="modsDir"></param>
public void LoadModsDirectory(string modsDir)
{
//Delays MPModListRefresh
MPModCheckManager.Instance.HoldMPModListRefresh();


OnModSuccessfullyLoaded += Events.EventHelper.RegisterEventHandlers;
Logger.Info($"Attempting to load mods from {modsDir}");

Expand Down
6 changes: 3 additions & 3 deletions PulsarModLoader/Patches/PLGlobalStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 2bbef4e

Please sign in to comment.