Skip to content

Commit

Permalink
Cleanup, Documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagord committed Apr 3, 2023
1 parent ab5a85d commit c216428
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
29 changes: 19 additions & 10 deletions PulsarModLoader/MPModChecks/MPModCheckManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public static MPUserDataBlock DeserializeHashfullMPUserData(byte[] byteData)
}

/// <summary>
/// Converts a ModDataBlock array to a string list, Ussually for logging purposes.
/// Converts a ModDataBlock array to a string list, Usually for logging purposes. Starts with a new line
/// </summary>
/// <param name="ModDatas"></param>
/// <returns>Converts ModDataBLocks to a string list.</returns>
Expand Down Expand Up @@ -383,16 +383,20 @@ public bool ClientClickJoinRoom(RoomInfo room)
}
MPModDataBlock[] HostModList = HostModData.ModData;

//Debug Logging
string HostModListString = GetModListAsString(HostModList);
string LocalModListString = GetModListAsString(MyModList);
Logger.Info($"Joining room: {room.Name} ServerPMLVersion: {HostModData.PMLVersion}\n--Hostmodlist: {HostModListString}\n--Localmodlist: {LocalModListString}");

string missingMods = string.Empty;
//Variable Initiallization
string hostMPLimitedMods = string.Empty;
string localMPLimitedMods = string.Empty;
string outdatedMods = string.Empty;
int MyModListLength = MyModList.Length;
int LocalModListLength = MyModList.Length;
int HostModListLength = HostModList.Length;
for (int a = 0; a < MyModListLength; a++)

//Check all local mods and compare against host mods
for (int a = 0; a < LocalModListLength; a++)
{
bool found = false;
int b = 0;
Expand All @@ -404,25 +408,30 @@ public bool ClientClickJoinRoom(RoomInfo room)
break;
}
}

//Mod not found in host list, Check if mod mandates host installation via Host, All.
if (!found)
{ //didn't find mod in host list, checking if mod function mandates host installation
{
if (MyModList[a].MPRequirement == MPRequirement.Host || MyModList[a].MPRequirement == MPRequirement.All)
{
localMPLimitedMods += $"\n{MyModList[a].ModName}";
}
}
//Mod found in host list, check if mod versions match. -Should only reach this if mod was found in both lists. -Catches MPRequirements Host, All, or MatchVersion.
else
{ //found mod in host list, checking if mod versions match.
{
if (MyModList[a].MPRequirement != MPRequirement.None && MyModList[a].Version != HostModList[b].Version)
{
outdatedMods += $"\nLocal: {MyModList[a].ModName} {MyModList[a].Version} Host: {HostModList[b].ModName} {HostModList[b].Version}";
}
}
}

//Check all host mods and compare against local mods (Ensures the host doesn't have a mod requiring client installation)
for (int a = 0; a < HostModListLength; a++)
{
bool found = false;
for (int b = 0; b < MyModListLength; b++)
for (int b = 0; b < LocalModListLength; b++)
{
if (HostModList[a].HarmonyIdentifier == MyModList[b].HarmonyIdentifier)
{
Expand All @@ -434,14 +443,14 @@ public bool ClientClickJoinRoom(RoomInfo room)
{
if (HostModList[a].MPRequirement == MPRequirement.All)
{ //Host MP mod not found locally
missingMods += $"\n{HostModList[a].ModName}";
hostMPLimitedMods += $"\n{HostModList[a].ModName}";
}
}
}
string message = string.Empty;
if (missingMods != string.Empty)
if (hostMPLimitedMods != string.Empty)
{
message += $"\n<color=yellow>YOU ARE MISSING THE FOLLOWING REQUIRED MODS</color>{missingMods}";
message += $"\n<color=yellow>YOU ARE MISSING THE FOLLOWING REQUIRED MODS</color>{hostMPLimitedMods}";
}
if (localMPLimitedMods != string.Empty)
{
Expand Down
23 changes: 23 additions & 0 deletions PulsarModLoader/MPModChecks/MPModDataBlock.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
namespace PulsarModLoader.MPModChecks
{
/// <summary>
/// Holds data about Mods for MPModChecks
/// </summary>
public class MPModDataBlock
{
/// <summary>
/// Creates an MPModDataBlock (With Hash)
/// </summary>
/// <param name="HarmonyIdentifier"></param>
/// <param name="ModName"></param>
/// <param name="Version"></param>
/// <param name="MPRequirement"></param>
/// <param name="ModID"></param>
/// <param name="Hash"></param>
public MPModDataBlock(string HarmonyIdentifier, string ModName, string Version, MPRequirement MPRequirement, string ModID, byte[] Hash)
{
this.HarmonyIdentifier = HarmonyIdentifier;
Expand All @@ -12,6 +24,14 @@ public MPModDataBlock(string HarmonyIdentifier, string ModName, string Version,
this.ModID = ModID;
}

/// <summary>
/// Creates an MPModDataBlock (without Hash)
/// </summary>
/// <param name="HarmonyIdentifier"></param>
/// <param name="ModName"></param>
/// <param name="Version"></param>
/// <param name="MPRequirement"></param>
/// <param name="ModID"></param>
public MPModDataBlock(string HarmonyIdentifier, string ModName, string Version, MPRequirement MPRequirement, string ModID)
{
this.HarmonyIdentifier = HarmonyIdentifier;
Expand All @@ -22,11 +42,14 @@ public MPModDataBlock(string HarmonyIdentifier, string ModName, string Version,
this.ModID = ModID;
}

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public string HarmonyIdentifier { get; }
public string ModName { get; }
public string Version { get; }
public MPRequirement MPRequirement { get; }
public byte[] Hash { get; }
public string ModID { get; }

#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
}
6 changes: 6 additions & 0 deletions PulsarModLoader/PulsarMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public virtual string Name
}
}

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
[Obsolete]//Legacy support
public virtual int MPFunctionality
{
Expand All @@ -112,6 +113,10 @@ public virtual int MPFunctionality
return (int)MPRequirement.None;
}
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member


#pragma warning disable CS0612 // Type or member is obsolete
/// <summary>
/// Mod's multiplayer requirements. use MPModChecks.MPRequirement.<br/>
/// None: No requirement<br/>
Expand All @@ -133,6 +138,7 @@ public virtual int MPRequirements
}
}
}
#pragma warning restore CS0612 // Type or member is obsolete

/// <summary>
/// Up to the modder to implement
Expand Down

0 comments on commit c216428

Please sign in to comment.