Skip to content

Commit

Permalink
Adding Anti-Grief Infinite Unit Block
Browse files Browse the repository at this point in the history
- Block players griefing by creating infinite units (changes game behavior to remove starting units (Crab, Horned Crab, or Wasp) when an Alien takeover is processed)
  • Loading branch information
data-bomb committed Dec 22, 2024
1 parent 0d2bce7 commit 7429b0c
Showing 1 changed file with 45 additions and 14 deletions.
59 changes: 45 additions & 14 deletions Si_AntiGrief/Si_AntiGrief.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.Linq;
using UnityEngine;

[assembly: MelonInfo(typeof(AntiGrief), "Anti-Grief", "1.3.8", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(AntiGrief), "Anti-Grief", "1.4.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

Expand Down Expand Up @@ -177,11 +177,6 @@ public void OnRequestEnterUnit(object? sender, OnRequestEnterUnitArgs args)
return;
}

if (!_BlockShrimpControllers.Value)
{
return;
}

Player player = args.Player;
Unit unit = args.Unit;

Expand All @@ -190,18 +185,29 @@ public void OnRequestEnterUnit(object? sender, OnRequestEnterUnitArgs args)
return;
}

// if the player isn't on the alien team, we can skip this check
if (player.Team.Index != (int)SiConstants.ETeam.Alien)
if (_BlockShrimpControllers.Value)
{
return;
// if the player isn't on the alien team, we can skip this check
if (player.Team.Index != (int)SiConstants.ETeam.Alien)
{
return;
}

// is it a shrimp?
if (unit.IsResourceHolder)
{
MelonLogger.Msg("Found " + player.PlayerName + " trying to use an Alien shrimp.");
HelperMethods.SendChatMessageToPlayer(player, HelperMethods.chatPrefix, " use of shrimp is not permitted on this server.");
args.Block = true;
return;
}
}

// is it a shrimp?
if (unit.IsResourceHolder)
// check if the unit the player is in right now needs to get deleted
if (ShouldDeletePriorUnit(player))
{
MelonLogger.Msg("Found " + player.PlayerName + " trying to use an Alien shrimp.");
HelperMethods.SendChatMessageToPlayer(player, HelperMethods.chatPrefix, " use of shrimp is not permitted on this server.");
args.Block = true;
MelonLogger.Msg("Player " + player.PlayerName + " found switching from spawn unit. Taking action to prevent inf creatures.");
DeletePriorUnit(player, player.ControlledUnit);
}
}
catch (Exception error)
Expand All @@ -210,6 +216,31 @@ public void OnRequestEnterUnit(object? sender, OnRequestEnterUnitArgs args)
}
}

public static void DeletePriorUnit(Player player, Unit unit)
{
for (int i = NetworkComponent.NetworkComponents.Count - 1; i >= 0; i--)
{
NetworkComponent networkComponent = NetworkComponent.NetworkComponents[i];
if (networkComponent != null && networkComponent.OwnerPlayer == player && networkComponent.IsValid && networkComponent == unit.NetworkComponent)
{
MelonLogger.Msg("Removing old unit (" + unit.name + ") from " + player.PlayerName + " before allowing transfer.");
UnityEngine.Object.Destroy(networkComponent.gameObject);
}
}
}

public static bool ShouldDeletePriorUnit(Player player)
{
Unit? currentUnit = player.ControlledUnit;
Team? playerTeam = player.Team;
if (currentUnit == null || playerTeam == null)
{
return false;
}

return GameMode.CurrentGameMode.GetCanDeletePlayerControlledUnit(player, currentUnit);
}

// hook DestroyAllUnitsForPlayer pre and override game code to prevent aliens from dying
public void OnRoleChanged(object? sender, OnRoleChangedArgs args)
{
Expand Down

0 comments on commit 7429b0c

Please sign in to comment.