Skip to content

Commit

Permalink
Merge pull request #5 from leo-ger/3-coin-removal-can-be-bypassed
Browse files Browse the repository at this point in the history
Fix coin removal exploit and add text hints
  • Loading branch information
leo-ger authored Jan 31, 2023
2 parents 051b699 + 184ec34 commit 3110fda
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace coin_pocket_escape
public class Config
{
[Description("Set the waiting time after the coin is flipped in ms")]
public int WaitingTime { get; set; } = 2500;
public int WaitingTime { get; set; } = 2000;
}
}
30 changes: 23 additions & 7 deletions Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Interactables.Interobjects;
using InventorySystem;
using MapGeneration;
using PluginAPI.Core;
Expand All @@ -18,7 +19,7 @@ public class Plugin

[PluginConfig] public Config Config;

public const string Version = "1.0.0";
public const string Version = "1.0.1";

[PluginPriority(LoadPriority.Highest)]
[PluginEntryPoint("Coin-Pocket-Escape", Version,
Expand All @@ -34,21 +35,24 @@ void LoadPlugin()
public async void OnPlayerCoinFlip(Player player, bool isTails)
{
var playerInPocket = (player.Zone == FacilityZone.Other);

Log.Info($"&rPlayer &6{player.Nickname}&r (&6{player.UserId}&r) flipped the coin. Flip result: " +
$"{(isTails ? "tails" : "heads")}. Player is {(playerInPocket ? "in" : "not in")} pocket.");

// If the player is not in the pocket, do nothing
if (!playerInPocket)
{
return;
}

player.ReceiveHint("The coin will decide your fate!", 2F);

// Wait to let the coin-flip animation play
await Task.Delay(TimeSpan.FromMilliseconds(Config.WaitingTime));

// If isTails and nuke not detonated, the player gets teleported to heavy zone and the coin gets removed
if (isTails && !AlphaWarheadController.Detonated)
// Only if the player still has a coin in his hand
if (isTails && !AlphaWarheadController.Detonated && player.CurrentItem.ItemTypeId == ItemType.Coin)
{
/*
Selecting a room in the HeavyZone to teleport the player.
Expand All @@ -61,14 +65,17 @@ Selecting a room in the HeavyZone to teleport the player.
}
Vector3 vector = HeavyZone.Rooms[i].Position;
vector.y += 1;

Log.Info($"&rPlayer gets teleported to Room &6{i}&r, Position: &6{vector.x}&r, &6{vector.y}&r, " +
$"&6{vector.z}&r.");
player.Position = vector;
player.ReceiveHint("You were lucky!", 2F);
player.ReferenceHub.inventory.ServerRemoveItem(player.CurrentItem.ItemSerial, null);
}

// If isTails and nuke detonated, the player gets teleported to surface zone and the coin gets removed
else if (isTails)
// Only if the player still has a coin in his hand.
else if (isTails && player.CurrentItem.ItemTypeId == ItemType.Coin)
{
int i = new Random().Next(SurfaceZone.Rooms.Count);
while (SurfaceZone.Rooms[i].Identifier.Name == RoomName.Unnamed)
Expand All @@ -77,17 +84,26 @@ Selecting a room in the HeavyZone to teleport the player.
}
Vector3 vector = SurfaceZone.Rooms[i].Position;
vector.y += 1;

Log.Info($"&rPlayer gets teleported to Room &6{i}&r, Position: &6{vector.x}&r, &6{vector.y}&r, " +
$"&6{vector.z}&r.");
player.Position = vector;
player.ReferenceHub.inventory.ServerRemoveItem(player.CurrentItem.ItemSerial, null);
}

// If the coin is heads, the coin just gets removed and the player stays in the pocket
else
// If the coin is heads, the coin just gets removed and the player stays in the pocket.
// Only if the player still has a coin in his hand.
else if (player.CurrentItem.ItemTypeId == ItemType.Coin)
{
player.ReceiveHint("Looks like you didn't have luck.", 1F);
player.ReferenceHub.inventory.ServerRemoveItem(player.CurrentItem.ItemSerial, null);
}

// If the player doesn't have a coin in his hand anymore, the event is cancelled.
else
{
player.ReceiveHint("Coin flip cancelled!", 1F);
}
}
}
}
1 change: 1 addition & 0 deletions coin-pocket-escape.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<RootNamespace>coin_pocket_escape</RootNamespace>
<AssemblyName>coin_pocket_escape</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down

0 comments on commit 3110fda

Please sign in to comment.