Skip to content

Commit

Permalink
Joining player now has modlist sent to other clients.
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonFire47 committed Dec 9, 2023
1 parent 2b51f07 commit 5f96f10
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
15 changes: 6 additions & 9 deletions PulsarModLoader/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ class EnterNewGamePatch
{
static void Postfix()
{
//Clear NetworkedPeers on game enter
MPModCheckManager.Instance.NetworkedPeersModLists.Clear();

Events.Instance.EnterNewGameEvent?.Invoke();
Instance.EnterNewGameEvent?.Invoke();
}
}

Expand Down Expand Up @@ -158,21 +155,21 @@ static void Postfix(PLServer __instance)
}
}


/// <summary>
/// Used by ClientModlistRecievedEvent
/// </summary>
/// <param name="IncomingPlayer"></param>
public delegate void ClientModlistRecievedDelegate(PhotonPlayer IncomingPlayer);

/// <param name="DataSender"></param>
public delegate void ClientModlistRecievedDelegate(PhotonPlayer DataSender);

/// <summary>
/// Called after a client modlist has been recieved by the MPModCheckManager instance.
/// </summary>
public event ClientModlistRecievedDelegate ClientModlistRecievedEvent;

internal void CallClientModlistRecievedEvent(PhotonPlayer IncomingPlayer)
internal void CallClientModlistRecievedEvent(PhotonPlayer DataSender)
{
ClientModlistRecievedEvent?.Invoke(IncomingPlayer);
ClientModlistRecievedEvent?.Invoke(DataSender);
}


Expand Down
30 changes: 26 additions & 4 deletions PulsarModLoader/MPModChecks/MPModCheckManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public MPModCheckManager()
ModManager.Instance.OnModUnloaded += RefreshData;
ModManager.Instance.OnModSuccessfullyLoaded += RefreshData;
ModManager.Instance.OnAllModsLoaded += RefreshData;

Events.Instance.OnLeaveGameEvent += OnLeaveGame;
}

internal void OnLeaveGame()
{
SentModLists.Clear();
NetworkedPeersModLists.Clear();
}

/// <summary>
Expand All @@ -46,6 +54,11 @@ public void RefreshData()
HoldRefreshUntilAllModsLoaded = true;
UpdateMyModList();
UpdateLobbyModList();

foreach (PhotonPlayer photonPlayer in SentModLists)
{
Instance.SendModlistToClient(photonPlayer);
}
}

/// <summary>
Expand Down Expand Up @@ -88,10 +101,20 @@ private void RefreshData(PulsarMod mod = null)

private MPModDataBlock[] MyModList = null;

internal List<PhotonPlayer> SentModLists = new List<PhotonPlayer>();

internal Dictionary<PhotonPlayer, MPUserDataBlock> NetworkedPeersModLists = new Dictionary<PhotonPlayer, MPUserDataBlock>();

private int HighestLevelOfMPMods = 0;

internal void SendModlistToClient(PhotonPlayer photonPlayer)
{
ModMessageHelper.Instance.photonView.RPC("ClientRecieveModList", photonPlayer, new object[]
{
Instance.SerializeHashlessUserData()
});
}

/// <summary>
/// Gets full mod list of Networked Peer.
/// </summary>
Expand Down Expand Up @@ -678,6 +701,7 @@ class AttemptGetVerifiedSendPatch
{
Instance.SerializeHashfullUserData()
});
Instance.SentModLists.Add(PhotonNetwork.masterClient);
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
Expand All @@ -699,6 +723,7 @@ class RemovePlayerPatch
static void Postfix(PhotonPlayer photonPlayer)
{
Instance.RemoveNetworkedPeerMods(photonPlayer);
Instance.SentModLists.Remove(photonPlayer);
}
}

Expand All @@ -707,10 +732,7 @@ class AddPlayerPatch
{
static void Postfix(PhotonPlayer photonPlayer)
{
ModMessageHelper.Instance.photonView.RPC("ClientRecieveModList", photonPlayer, new object[]
{
Instance.SerializeHashlessUserData()
});
Instance.SendModlistToClient(photonPlayer);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions PulsarModLoader/ModMessage/ModMessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public void ServerRecieveModList(byte[] recievedData, PhotonMessageInfo pmi)
[PunRPC]
public void ClientRecieveModList(byte[] recievedData, PhotonMessageInfo pmi)
{
//Send local modlist to client other client
if (!pmi.sender.IsMasterClient && !MPModCheckManager.Instance.SentModLists.Contains(pmi.sender))
{
MPModCheckManager.Instance.SendModlistToClient(pmi.sender);
MPModCheckManager.Instance.SentModLists.Add(pmi.sender);
}
MPUserDataBlock userDataBlock = MPModCheckManager.DeserializeHashlessMPUserData(recievedData);
Logger.Info($"recieved modlist from user with the following info:\nPMLVersion: {userDataBlock.PMLVersion}\nModlist:{MPModCheckManager.GetModListAsString(userDataBlock.ModData)}");

Expand Down

0 comments on commit 5f96f10

Please sign in to comment.