Skip to content

Commit

Permalink
Fix for Server Error when Clients Switch Teams
Browse files Browse the repository at this point in the history
- Removes server error spam "Wrong data type read - UInt64, should be Byte" when players try and switch teams
  • Loading branch information
data-bomb committed May 5, 2024
1 parent 56fe067 commit 061cc2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Si_AdminMod/Event_Roles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static class Event_Roles
[HarmonyPatch(typeof(MP_Strategy), nameof(MP_Strategy.ProcessNetRPC))]
static class ApplyPatch_MPStrategy_RequestRole
{
public static bool Prefix(MP_Strategy __instance, GameByteStreamReader __0, byte __1)
public static bool Prefix(MP_Strategy __instance, ref GameByteStreamReader __0, byte __1)
{
try
{
Expand All @@ -61,18 +61,18 @@ public static bool Prefix(MP_Strategy __instance, GameByteStreamReader __0, byte
}

Player requestingPlayer = Player.FindPlayer((CSteamID)__0.ReadUInt64(), (int)__0.ReadByte());
MP_Strategy.ETeamRole eRole = (MP_Strategy.ETeamRole)__0.ReadByte();

if (requestingPlayer == null)
{
MelonLogger.Warning("Cannot find player in role request.");
return false;
}

MP_Strategy.ETeamRole eRole = (MP_Strategy.ETeamRole)__0.ReadByte();

// would the game code treat it as an infantry/no role request?
if (eRole != MP_Strategy.ETeamRole.COMMANDER || __instance.GetCommanderForTeam(requestingPlayer.Team))
{
RestoreRPC_RequestRoleReader(requestingPlayer, eRole);
__0 = RestoreRPC_RequestRoleReader(requestingPlayer, eRole);
FireOnRoleChangedEvent(requestingPlayer, eRole);
return true;
}
Expand Down Expand Up @@ -127,10 +127,17 @@ public static bool Prefix(MP_Strategy __instance, GameByteStreamReader __0, byte
public static GameByteStreamReader RestoreRPC_RequestRoleReader(Player requestingPlayer, MP_Strategy.ETeamRole role)
{
GameByteStreamWriter gameByteStreamWriter = GameByteStreamWriter.GetGameByteStreamWriter(true);
gameByteStreamWriter.WriteByte(20);
gameByteStreamWriter.WriteByte(0);
gameByteStreamWriter.WriteByte((byte)MP_Strategy.ERPCs.REQUEST_ROLE);
gameByteStreamWriter.WriteUInt64((ulong)requestingPlayer.PlayerID);
gameByteStreamWriter.WriteByte((byte)requestingPlayer.PlayerChannel);
gameByteStreamWriter.WriteByte((byte)role);
return GameByteStreamReader.GetGameByteStreamReader(gameByteStreamWriter.GetByteData(), gameByteStreamWriter.GetByteDataSize(), true);
GameByteStreamReader gameByteStreamReader = GameByteStreamReader.GetGameByteStreamReader(gameByteStreamWriter.GetByteData(), gameByteStreamWriter.GetByteDataSize(), true);
gameByteStreamReader.ReadByte();
gameByteStreamReader.ReadByte();
gameByteStreamReader.ReadByte();
return gameByteStreamReader;
}

public static void FireOnRoleChangedEvent(Player player, MP_Strategy.ETeamRole role)
Expand Down
2 changes: 1 addition & 1 deletion Si_AdminMod/ModAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You should have received a copy of the GNU General Public License
using SilicaAdminMod;
using System.Drawing;

[assembly: MelonInfo(typeof(SiAdminMod), "Admin Mod", "2.0.761", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(SiAdminMod), "Admin Mod", "2.0.768", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]

// Color.Cyan
Expand Down

0 comments on commit 061cc2c

Please sign in to comment.