Skip to content

Commit

Permalink
Merge pull request #47 from data-bomb/beta
Browse files Browse the repository at this point in the history
Merge Game Fixes for v0.8.76+
  • Loading branch information
data-bomb authored Sep 4, 2024
2 parents 3706bb1 + d06dec1 commit ae41e7f
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 81 deletions.
15 changes: 13 additions & 2 deletions Si_AdminMod/CheatsLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public static void SendLimitedCheatsEvent(bool cheatsStatus)
Power modPowers = player.GetAdminPowers();
if (player.AdminLevel >= EAdminLevel.STANDARD || AdminMethods.PowerInPowers(Power.Cheat, modPowers))
{
if (SiAdminMod.Pref_Admin_DebugLogMessages.Value)
{
MelonLogger.Msg("Permitting cheats access to admin: " + player.PlayerName + " (server level: " + player.AdminLevel.ToString() + ") (mod powers: " + modPowers.ToString() + ")");
}

#if NET6_0
NetworkLayer.NetBitsSent += byteDataSize * 8U;
#else
Expand All @@ -118,8 +123,14 @@ public static void SendLimitedCheatsEvent(bool cheatsStatus)
bitsSent += byteDataSize * 8U;
netBitsSentField.SetValue(null, bitsSent);
#endif

SteamGameServerNetworking.SendP2PPacket(player.PlayerID, byteData, byteDataSize, EP2PSend.k_EP2PSendReliable, player.PlayerChannel);

#if NET6_0
NetworkLayer.SendServerPacket(player.PlayerID, gameByteStreamWriter.GetByteData(), byteDataSize, ENetworkPacketSend.Reliable, player.PlayerChannel);
#else
Type networkLayerType = typeof(NetworkLayer);
MethodInfo sendServerPacketMethod = networkLayerType.GetMethod("SendServerPacket", BindingFlags.NonPublic | BindingFlags.Static);
sendServerPacketMethod.Invoke(null, new object[] { player.PlayerID, gameByteStreamWriter.GetByteData(), byteDataSize, ENetworkPacketSend.Reliable, player.PlayerChannel });
#endif
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Si_AdminMod/Event_Netcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void Prefix(GameByteStreamReader __result, ref byte[] __0, int __1, uint
{
case (byte)ENetworkPacketType.ChatMessage:
{
CSteamID chatterSteamId = (CSteamID)tempReader.ReadUInt64();
NetworkID chatterSteamId = (NetworkID)tempReader.ReadUInt64();
int chatterChannel = (int)tempReader.ReadByte();
string chatText = tempReader.ReadString();
bool chatTeamOnly = tempReader.ReadBool();
Expand Down
24 changes: 18 additions & 6 deletions Si_AdminMod/Event_Roles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ You should have received a copy of the GNU General Public License
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Data;
using System.Globalization;

#if NET6_0
using Il2Cpp;
Expand All @@ -39,6 +40,9 @@ namespace SilicaAdminMod
{
public static class Event_Roles
{
#if !NET6_0
public static byte ERPC_RequestRole = HelperMethods.FindByteValueInEnum(typeof(MP_Strategy), "ERPCs", "REQUEST_ROLE");
#endif
public static event EventHandler<OnRequestCommanderArgs> OnRequestCommander = delegate { };
public static event EventHandler<OnRoleChangedArgs> OnRoleChanged = delegate { };

Expand All @@ -55,12 +59,16 @@ public static bool Prefix(MP_Strategy __instance, ref GameByteStreamReader __0,
}

// only look at RPC_RequestRole
if (__1 != (byte)GameModeExt.ERPCs.REQUEST_ROLE)
#if NET6_0
if (__1 != (byte)MP_Strategy.ERPCs.REQUEST_ROLE)
#else
if (__1 != ERPC_RequestRole)
#endif
{
return true;
}

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

if (requestingPlayer == null)
Expand Down Expand Up @@ -109,17 +117,17 @@ public static bool Prefix(MP_Strategy __instance, ref GameByteStreamReader __0,
{
MelonLogger.Msg("Allowing to join commander");
}
#if NET6_0
#if NET6_0
__instance.SetCommander(baseTeamSetup.Team, requestingPlayer);
__instance.RPC_SynchCommander(baseTeamSetup.Team);
#else
#else
Type strategyType = typeof(MP_Strategy);
MethodInfo setCommanderMethod = strategyType.GetMethod("SetCommander", BindingFlags.Instance | BindingFlags.NonPublic);
setCommanderMethod.Invoke(__instance, parameters: new object?[] { baseTeamSetup.Team, requestingPlayer });

MethodInfo synchCommanderMethod = strategyType.GetMethod("RPC_SynchCommander", BindingFlags.Instance | BindingFlags.NonPublic);
synchCommanderMethod.Invoke(__instance, new object[] { baseTeamSetup.Team });
#endif
#endif

FireOnRoleChangedEvent(requestingPlayer, GameModeExt.ETeamRole.COMMANDER);

Expand All @@ -139,7 +147,11 @@ public static GameByteStreamReader RestoreRPC_RequestRoleReader(Player requestin
GameByteStreamWriter gameByteStreamWriter = GameByteStreamWriter.GetGameByteStreamWriter(0U, "Si_AdminMod::RestoreRPC_RequestRoleReader", true);
gameByteStreamWriter.WriteByte((byte)ENetworkPacketType.GameModeRPC);
gameByteStreamWriter.WriteByte(0);
gameByteStreamWriter.WriteByte((byte)GameModeExt.ERPCs.REQUEST_ROLE);
#if NET6_0
gameByteStreamWriter.WriteByte((byte)MP_Strategy.ERPCs.REQUEST_ROLE);
#else
gameByteStreamWriter.WriteByte(ERPC_RequestRole);
#endif
gameByteStreamWriter.WriteUInt64((ulong)requestingPlayer.PlayerID);
gameByteStreamWriter.WriteByte((byte)requestingPlayer.PlayerChannel);
gameByteStreamWriter.WriteByte((byte)role);
Expand Down
55 changes: 41 additions & 14 deletions Si_AdminMod/HelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ private static void NetworkSendChat(Player recipient, Player sender, params stri
gameByteStreamWriter.WriteUInt64((ulong)sender.PlayerID);
gameByteStreamWriter.WriteByte((byte)sender.PlayerChannel);
gameByteStreamWriter.WriteString(String.Concat(messages));
gameByteStreamWriter.WriteBool(false);
gameByteStreamWriter.WriteBool(false); // teamOnly
gameByteStreamWriter.WriteBool(true); // isServerMessage

uint byteDataSize = (uint)gameByteStreamWriter.GetByteDataSize();
#if NET6_0
Expand All @@ -211,7 +212,14 @@ private static void NetworkSendChat(Player recipient, Player sender, params stri
bitsSent += byteDataSize * 8U;
netBitsSentField.SetValue(null, bitsSent);
#endif
SteamGameServerNetworking.SendP2PPacket(recipient.PlayerID, gameByteStreamWriter.GetByteData(), byteDataSize, EP2PSend.k_EP2PSendReliable, recipient.PlayerChannel);

#if NET6_0
NetworkLayer.SendServerPacket(recipient.PlayerID, gameByteStreamWriter.GetByteData(), byteDataSize, ENetworkPacketSend.Reliable, recipient.PlayerChannel);
#else
Type networkLayerType = typeof(NetworkLayer);
MethodInfo sendServerPacketMethod = networkLayerType.GetMethod("SendServerPacket", BindingFlags.NonPublic | BindingFlags.Static);
sendServerPacketMethod.Invoke(null, new object[] { recipient.PlayerID, gameByteStreamWriter.GetByteData(), byteDataSize, ENetworkPacketSend.Reliable, recipient.PlayerChannel });
#endif
}

private static void NetworkSendConsole(Player recipient, params string[] messages)
Expand All @@ -238,7 +246,14 @@ private static void NetworkSendConsole(Player recipient, params string[] message
bitsSent += byteDataSize * 8U;
netBitsSentField.SetValue(null, bitsSent);
#endif
SteamGameServerNetworking.SendP2PPacket(recipient.PlayerID, gameByteStreamWriter.GetByteData(), byteDataSize, EP2PSend.k_EP2PSendReliable, recipient.PlayerChannel);

#if NET6_0
NetworkLayer.SendServerPacket(recipient.PlayerID, gameByteStreamWriter.GetByteData(), byteDataSize, ENetworkPacketSend.Reliable, recipient.PlayerChannel);
#else
Type networkLayerType = typeof(NetworkLayer);
MethodInfo sendServerPacketMethod = networkLayerType.GetMethod("SendServerPacket", BindingFlags.NonPublic | BindingFlags.Static);
sendServerPacketMethod.Invoke(null, new object[] { recipient.PlayerID, gameByteStreamWriter.GetByteData(), byteDataSize, ENetworkPacketSend.Reliable, recipient.PlayerChannel });
#endif
}

public static Player FindBroadcastPlayer()
Expand Down Expand Up @@ -300,11 +315,11 @@ public static void PrintError(Exception exception, string? message = null)
int iTargetCount = 0;

// loop through all players
#if NET6_0
#if NET6_0
Il2CppSystem.Collections.Generic.List<Player> players = Player.Players;
#else
#else
List<Player> players = Player.Players;
#endif
#endif

int iPlayerCount = players.Count;

Expand Down Expand Up @@ -502,18 +517,13 @@ public static bool KickPlayer(Player playerToKick)
return false;
}

#if NET6_0
Il2CppSteamworks.CSteamID serverSteam = NetworkGameServer.GetServerID();
Il2CppSteamworks.CSteamID playerSteam = playerToKick.PlayerID;
#else
Steamworks.CSteamID serverSteam = NetworkGameServer.GetServerID();
Steamworks.CSteamID playerSteam = playerToKick.PlayerID;
#endif
NetworkID serverSteam = NetworkGameServer.GetServerID();
NetworkID playerSteam = playerToKick.PlayerID;

int playerChannel = playerToKick.PlayerChannel;

NetworkLayer.SendPlayerConnectResponse(ENetworkPlayerConnectType.Kicked, playerSteam, playerChannel, serverSteam);
Player.RemovePlayer(playerSteam, playerChannel);
Player.RemovePlayer(playerSteam);
NetworkLayer.SendPlayerConnect(ENetworkPlayerConnectType.Disconnected, playerSteam, playerChannel);

return true;
Expand Down Expand Up @@ -548,6 +558,23 @@ public static bool KickPlayer(Player playerToKick)
return spawnedObject;
}

#if !NET6_0
public static byte FindByteValueInEnum(Type parentType, string enumName, string byteName)
{
Type enumType = parentType.GetNestedType(enumName, BindingFlags.NonPublic);
var enumValues = enumType.GetEnumValues();
foreach (var enumValue in enumValues)
{
if (string.Compare(enumValue.ToString(), byteName) == 0)
{
return (byte)enumValue;
}
}

return byte.MaxValue;
}
#endif

public static bool IsTimerActive(float time)
{
if (time >= 0.0f)
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.936", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(SiAdminMod), "Admin Mod", "2.0.943", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]

// Color.Cyan
Expand Down
10 changes: 5 additions & 5 deletions Si_BasicBanlist/Si_BasicBans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You should have received a copy of the GNU General Public License
using System.Collections.Generic;
using System.Linq;

[assembly: MelonInfo(typeof(BasicBanlist), "Basic Banlist", "1.5.1", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(BasicBanlist), "Basic Banlist", "1.5.2", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand Down Expand Up @@ -332,15 +332,15 @@ public static bool UnbanPlayer(String target, Player? adminPlayer)
public static void BanPlayer(Player playerToBan, Player? adminPlayer)
{
// are we already banned?
if (IsPlayerBanned(playerToBan.PlayerID.m_SteamID))
if (IsPlayerBanned(playerToBan.PlayerID.SteamID.m_SteamID))
{
MelonLogger.Warning("Player name (" + playerToBan.PlayerName + ") SteamID (" + playerToBan.PlayerID.m_SteamID.ToString() + ") already on banlist.");
MelonLogger.Warning("Player name (" + playerToBan.PlayerName + ") SteamID (" + playerToBan.PlayerID.SteamID.m_SteamID.ToString() + ") already on banlist.");
return;
}

if (MasterBanList == null)
{
NetworkServerSettings.PlayerAddBan(playerToBan.PlayerID.m_SteamID, playerToBan.PlayerName, 0, adminPlayer == null ? "banned by SERVER CONSOLE" : "banned by " + adminPlayer.PlayerName);
NetworkServerSettings.PlayerAddBan(playerToBan.PlayerID.SteamID.m_SteamID, playerToBan.PlayerName, 0, adminPlayer == null ? "banned by SERVER CONSOLE" : "banned by " + adminPlayer.PlayerName);
}
else
{
Expand All @@ -349,7 +349,7 @@ public static void BanPlayer(Player playerToBan, Player? adminPlayer)
UpdateBanFile();
}

MelonLogger.Msg("Added player name (" + playerToBan.PlayerName + ") SteamID (" + playerToBan.PlayerID.m_SteamID.ToString() + ") to the banlist.");
MelonLogger.Msg("Added player name (" + playerToBan.PlayerName + ") SteamID (" + playerToBan.PlayerID.SteamID.m_SteamID.ToString() + ") to the banlist.");
NetworkGameServer.KickPlayer(playerToBan);
HelperMethods.AlertAdminActivity(adminPlayer, playerToBan, "banned");
}
Expand Down
Loading

0 comments on commit ae41e7f

Please sign in to comment.