Skip to content

Commit

Permalink
-Fixed usage of old enum in GUIMain
Browse files Browse the repository at this point in the history
-Changed sent datatype for RPCs
-Changed NetworkedPeersModLists dictionary and all ussages of it to store userdata.
-Changed multiple method data inputs and outputs.
-Added setting of modList value in CustomRoomProperties during lobby reaction.
  • Loading branch information
Nagord committed Sep 2, 2022
1 parent 2ebd25f commit 73c17e9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion PulsarModLoader/CustomGUI/GUIMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void WindowFunction(int WindowID)
Label($"Short Description: {mod.ShortDescription}");
if (mod.LongDescription != string.Empty)
Label($"Long Description: {mod.LongDescription}");
Label($"MPFunctionality: {((MPFunction)mod.MPFunctionality).ToString()}");
Label($"MPFunctionality: {((MPModChecks.MPFunction)mod.MPFunctionality).ToString()}");
}
EndScrollView();
}
Expand Down
24 changes: 13 additions & 11 deletions PulsarModLoader/MPModChecks/MPModCheckManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ private void UpdateLobbyModList() //Update Photon Lobby Listing with mod list

private MPModDataBlock[] MyModList = null;

private Dictionary<PhotonPlayer, MPModDataBlock[]> NetworkedPeersModLists = new Dictionary<PhotonPlayer, MPModDataBlock[]>();
private Dictionary<PhotonPlayer, MPUserDataBlock> NetworkedPeersModLists = new Dictionary<PhotonPlayer, MPUserDataBlock>();

private bool ServerHasMPMods = false;

public MPModDataBlock[] GetNetworkedPeerMods(PhotonPlayer Photonplayer)
public MPUserDataBlock GetNetworkedPeerMods(PhotonPlayer Photonplayer)
{
return NetworkedPeersModLists[Photonplayer];
}

public void AddNetworkedPeerMods(PhotonPlayer Photonplayer, MPModDataBlock[] modList)
public void AddNetworkedPeerMods(PhotonPlayer Photonplayer, MPUserDataBlock modList)
{
if (NetworkedPeersModLists.ContainsKey(Photonplayer))
{
Expand Down Expand Up @@ -109,7 +109,7 @@ private void UpdateMyModList()
Logger.Info("Finished Building MyModList, time elapsted: " + stopwatch.ElapsedMilliseconds.ToString());
}

private MemoryStream GetModListForLobbyListing()
public byte[] GetModListForLobbyListing()
{
MemoryStream dataStream = new MemoryStream();
using (BinaryWriter writer = new BinaryWriter(dataStream))
Expand All @@ -127,11 +127,12 @@ private MemoryStream GetModListForLobbyListing()
writer.Write(dataBlock.ModID); //string ModID
}
}
return dataStream;
return dataStream.ToArray();
}

public static MPUserDataBlock GetModListFromLobbyListingData(MemoryStream memoryStream)
public static MPUserDataBlock GetModListFromLobbyListingData(byte[] byteData)
{
MemoryStream memoryStream = new MemoryStream(byteData);
memoryStream.Position = 0;
MPUserDataBlock UserData = null;
using (BinaryReader reader = new BinaryReader(memoryStream))
Expand Down Expand Up @@ -161,7 +162,7 @@ public static MPUserDataBlock GetModListFromLobbyListingData(MemoryStream memory
return UserData;
}

private static string GetModListAsString(MPModDataBlock[] ModDatas)
public static string GetModListAsString(MPModDataBlock[] ModDatas)
{
string ModList = string.Empty;
foreach (MPModDataBlock DataBlock in ModDatas)
Expand All @@ -175,7 +176,7 @@ private static MPUserDataBlock GetHostModList(RoomInfo room)
{
if (room.CustomProperties.ContainsKey("modList"))
{
return GetModListFromLobbyListingData((MemoryStream)room.CustomProperties["modList"]);
return GetModListFromLobbyListingData((byte[])room.CustomProperties["modList"]);
}
return new MPUserDataBlock();
}
Expand Down Expand Up @@ -287,7 +288,7 @@ public void HostOnClientJoined(PhotonPlayer Player)
bool foundplayer = false;
if (NetworkedPeersModLists.ContainsKey(Player)) //checks if server has received mod list from client.
{
ClientMods = NetworkedPeersModLists[Player];
ClientMods = NetworkedPeersModLists[Player].ModData;
foundplayer = true;
}
Logger.Info("HostOnClientJoined checking for player mods, returned " + foundplayer.ToString());
Expand Down Expand Up @@ -398,6 +399,7 @@ public void HostOnClientJoined(PhotonPlayer Player)
string message = $"You have been disconnected for not having the mod loader installed";
ModMessageHelper.Instance.photonView.RPC("RecieveErrorMessage", Player, new object[] { message });
KickClient(Player);
return;
}
Utilities.Logger.Info("Didn't receive message or proper modlist, but the server doesn't have multiplayer explicit mods. Proceeding onwards");
}
Expand Down Expand Up @@ -446,10 +448,10 @@ static void Postfix(PhotonPlayer player, PhotonMessageInfo pmi)
{
if (player == PhotonNetwork.player)
{
Logger.Info("Sending 'RecieveConnectionMessage' RPC");
ModMessageHelper.Instance.photonView.RPC("ReceiveConnectionMessage", pmi.sender, new object[]
{
MPModCheckManager.Instance.MyModList,
Patches.GameVersion.PMLVersion
MPModCheckManager.Instance.GetModListForLobbyListing()
});
}
player.Verified = true;
Expand Down
7 changes: 4 additions & 3 deletions PulsarModLoader/ModMessage/ModMessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ public void RecieveErrorMessage(string message)
}

[PunRPC]
public void ReceiveConnectionMessage(MPModDataBlock[] modList, string PMLVersion, PhotonMessageInfo pmi) //Pong
public void ReceiveConnectionMessage(byte[] recievedData, PhotonMessageInfo pmi) //Pong
{
Logger.Info($"recieved modlist and connection info from user with the following info:\nPMLVersion: {PMLVersion}\nModlist:{MPModCheckManager.GetModListAsString(modList)}");
MPModCheckManager.Instance.AddNetworkedPeerMods(pmi.sender, modList);
MPUserDataBlock userDataBlock = MPModCheckManager.GetModListFromLobbyListingData(recievedData);
Logger.Info($"recieved modlist and connection info from user with the following info:\nPMLVersion: {userDataBlock.PMLVersion}\nModlist:{MPModCheckManager.GetModListAsString(userDataBlock.ModData)}");
MPModCheckManager.Instance.AddNetworkedPeerMods(pmi.sender, userDataBlock);
}
}
}
3 changes: 3 additions & 0 deletions PulsarModLoader/Patches/PhotonProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ private static void Prefix(RoomOptions roomOptions)
"playerList",
"modList",
});

//MPModCheck
roomOptions.CustomRoomProperties["modList"] = MPModChecks.MPModCheckManager.Instance.GetModListForLobbyListing();
}

public static void UpdatePlayerList()
Expand Down

0 comments on commit 73c17e9

Please sign in to comment.