Implement place style checks, courtesy of @AgaSpace
This commit is contained in:
parent
07b70431f9
commit
85fbf593c9
2 changed files with 38 additions and 10 deletions
|
|
@ -303,6 +303,15 @@ namespace TShockAPI
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selectedItem.placeStyle != style)
|
||||||
|
{
|
||||||
|
TShock.Log.ConsoleError(string.Format("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
|
||||||
|
args.Player.Name, action, editData, style, selectedItem.placeStyle));
|
||||||
|
args.Player.SendTileSquare(tileX, tileY, 1);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == EditAction.KillTile && !Main.tileCut[tile.type] && !breakableTiles.Contains(tile.type))
|
if (action == EditAction.KillTile && !Main.tileCut[tile.type] && !breakableTiles.Contains(tile.type))
|
||||||
|
|
@ -354,9 +363,9 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
else if (CoilTileIds.Contains(editData))
|
else if (CoilTileIds.Contains(editData))
|
||||||
{
|
{
|
||||||
/// Handle placement if the user is placing rope that comes from a ropecoil,
|
// Handle placement if the user is placing rope that comes from a ropecoil,
|
||||||
/// but have not created the ropecoil projectile recently or the projectile was not at the correct coordinate, or the tile that the projectile places does not match the rope it is suposed to place
|
// but have not created the ropecoil projectile recently or the projectile was not at the correct coordinate, or the tile that the projectile places does not match the rope it is suposed to place
|
||||||
/// projectile should be the same X coordinate as all tile places (Note by @Olink)
|
// projectile should be the same X coordinate as all tile places (Note by @Olink)
|
||||||
if (ropeCoilPlacements.ContainsKey(selectedItem.netID) &&
|
if (ropeCoilPlacements.ContainsKey(selectedItem.netID) &&
|
||||||
!args.Player.RecentlyCreatedProjectiles.Any(p => GetDataHandlers.projectileCreatesTile.ContainsKey(p.Type) && GetDataHandlers.projectileCreatesTile[p.Type] == editData &&
|
!args.Player.RecentlyCreatedProjectiles.Any(p => GetDataHandlers.projectileCreatesTile.ContainsKey(p.Type) && GetDataHandlers.projectileCreatesTile[p.Type] == editData &&
|
||||||
!p.Killed && Math.Abs((int)(Main.projectile[p.Index].position.X / 16f) - tileX) <= Math.Abs(Main.projectile[p.Index].velocity.X)))
|
!p.Killed && Math.Abs((int)(Main.projectile[p.Index].position.X / 16f) - tileX) <= Math.Abs(Main.projectile[p.Index].velocity.X)))
|
||||||
|
|
@ -1106,6 +1115,7 @@ namespace TShockAPI
|
||||||
int tileX = args.TileX;
|
int tileX = args.TileX;
|
||||||
int tileY = args.TileY;
|
int tileY = args.TileY;
|
||||||
int flag = args.Flag;
|
int flag = args.Flag;
|
||||||
|
short style = args.Style;
|
||||||
|
|
||||||
if (!TShock.Utils.TilePlacementValid(tileX, tileY) || (args.Player.Dead && TShock.Config.Settings.PreventDeadModification))
|
if (!TShock.Utils.TilePlacementValid(tileX, tileY) || (args.Player.Dead && TShock.Config.Settings.PreventDeadModification))
|
||||||
{
|
{
|
||||||
|
|
@ -1122,6 +1132,14 @@ namespace TShockAPI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.Player.SelectedItem.placeStyle != style)
|
||||||
|
{
|
||||||
|
TShock.Log.ConsoleError(string.Format("Bouncer / OnPlaceChest / rejected from invalid place style from {0}", args.Player.Name));
|
||||||
|
args.Player.SendTileSquare(tileX, tileY, 3);
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (flag != 0 && flag != 4 // if no container or container2 placement
|
if (flag != 0 && flag != 4 // if no container or container2 placement
|
||||||
&& Main.tile[tileX, tileY].type != TileID.Containers
|
&& Main.tile[tileX, tileY].type != TileID.Containers
|
||||||
&& Main.tile[tileX, tileY].type != TileID.Dressers
|
&& Main.tile[tileX, tileY].type != TileID.Dressers
|
||||||
|
|
@ -1630,8 +1648,6 @@ namespace TShockAPI
|
||||||
short y = args.Y;
|
short y = args.Y;
|
||||||
short type = args.Type;
|
short type = args.Type;
|
||||||
short style = args.Style;
|
short style = args.Style;
|
||||||
byte alternate = args.Alternate;
|
|
||||||
bool direction = args.Direction;
|
|
||||||
|
|
||||||
if (type < 0 || type >= Main.maxTileSets)
|
if (type < 0 || type >= Main.maxTileSets)
|
||||||
{
|
{
|
||||||
|
|
@ -1654,6 +1670,13 @@ namespace TShockAPI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args.Player.SelectedItem.placeStyle != style)
|
||||||
|
{
|
||||||
|
TShock.Log.ConsoleError(string.Format("Bouncer / OnPlaceObject rejected object placement with invalid style from {0}", args.Player.Name));
|
||||||
|
args.Handled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//style 52 and 53 are used by ItemID.Fake_newchest1 and ItemID.Fake_newchest2
|
//style 52 and 53 are used by ItemID.Fake_newchest1 and ItemID.Fake_newchest2
|
||||||
//These two items cause localised lag and rendering issues
|
//These two items cause localised lag and rendering issues
|
||||||
if (type == TileID.FakeContainers && (style == 52 || style == 53))
|
if (type == TileID.FakeContainers && (style == 52 || style == 53))
|
||||||
|
|
|
||||||
|
|
@ -939,12 +939,16 @@ namespace TShockAPI
|
||||||
/// The Y coordinate
|
/// The Y coordinate
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int TileY { get; set; }
|
public int TileY { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Place style used
|
||||||
|
/// </summary>
|
||||||
|
public short Style { get; set; }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When a chest is added or removed from the world.
|
/// When a chest is added or removed from the world.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static HandlerList<PlaceChestEventArgs> PlaceChest = new HandlerList<PlaceChestEventArgs>();
|
public static HandlerList<PlaceChestEventArgs> PlaceChest = new HandlerList<PlaceChestEventArgs>();
|
||||||
private static bool OnPlaceChest(TSPlayer player, MemoryStream data, int flag, int tilex, int tiley)
|
private static bool OnPlaceChest(TSPlayer player, MemoryStream data, int flag, int tilex, int tiley, short style)
|
||||||
{
|
{
|
||||||
if (PlaceChest == null)
|
if (PlaceChest == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -956,6 +960,7 @@ namespace TShockAPI
|
||||||
Flag = flag,
|
Flag = flag,
|
||||||
TileX = tilex,
|
TileX = tilex,
|
||||||
TileY = tiley,
|
TileY = tiley,
|
||||||
|
Style = style
|
||||||
};
|
};
|
||||||
PlaceChest.Invoke(null, args);
|
PlaceChest.Invoke(null, args);
|
||||||
return args.Handled;
|
return args.Handled;
|
||||||
|
|
@ -2884,9 +2889,9 @@ namespace TShockAPI
|
||||||
int flag = args.Data.ReadByte();
|
int flag = args.Data.ReadByte();
|
||||||
int tileX = args.Data.ReadInt16();
|
int tileX = args.Data.ReadInt16();
|
||||||
int tileY = args.Data.ReadInt16();
|
int tileY = args.Data.ReadInt16();
|
||||||
args.Data.ReadInt16(); // Ignore style
|
short style = args.Data.ReadInt16();
|
||||||
|
|
||||||
if (OnPlaceChest(args.Player, args.Data, flag, tileX, tileY))
|
if (OnPlaceChest(args.Player, args.Data, flag, tileX, tileY, style))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue