This repository has been archived by the owner on Nov 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainPlugin.cs
94 lines (82 loc) · 3.27 KB
/
MainPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using Terraria;
using TerrariaApi.Server;
using System.IO;
using TShockAPI;
namespace AntiCheats
{
[ApiVersion(2, 1)]
public class IgnoreTheMismatchedTiles : TerrariaPlugin
{
public override string Author => "Zoom L1 | Colag";
public override string Name => "Ignore the mismatched tiles";
public IgnoreTheMismatchedTiles(Main game) : base(game) {}
public override void Initialize()
{
GetDataHandlers.TileEdit += OnTileEdit;
GetDataHandlers.PlaceObject += OnPlaceObject;
ServerApi.Hooks.NetGetData.Register(this, OnGetData);
}
public static void OnTileEdit(object sender, GetDataHandlers.TileEditEventArgs args)
{
if (args.Action == GetDataHandlers.EditAction.PlaceTile || args.Action == GetDataHandlers.EditAction.ReplaceTile)
{
// The History plugin does not record 127 tiles.
// Cheaters use this to deliver tiles without leaving traces.
if (Main.tile[args.X, args.Y] != null && Main.tile[args.X, args.Y].type == 127)
{
args.Handled = true;
return;
}
if (args.Player.SelectedItem.placeStyle != args.Style)
{
TShock.Log.ConsoleError(string.Format("/ OnTileEdit / Player {0} ({1}) set a tile whose style({2}) is not true.", args.Player.Name, args.Player.IP, args.Style));
args.Player.SendErrorMessage("You cannot place this tile."); //I'm worried about real players. My plugin notifies players.
args.Handled = true;
return;
}
}
}
public static void OnPlaceObject(object sender, GetDataHandlers.PlaceObjectEventArgs args)
{
if (Main.tile[args.X, args.Y] != null && Main.tile[args.X, args.Y].type == 127)
{
args.Handled = true;
return;
}
if (args.Player.SelectedItem.placeStyle != args.Style)
{
TShock.Log.ConsoleError(string.Format("/ OnPlaceObject / Player {0} ({1}) placed an object whose style({2}) does not match the present.", args.Player.Name, args.Player.IP, args.Style));
args.Player.SendErrorMessage("You cannot place this object.");
args.Handled = true;
return;
}
}
public static void OnGetData(GetDataEventArgs e) // tShock do not use the block delivery style in GetDateNandlers HandlePlaceChest. Therefore, I have to get the style myself.
{
if (e.MsgID == (PacketTypes)34) // PacketTypes: PlaceChest = 34
{
TSPlayer player = TShock.Players[e.Msg.whoAmI];
using (var data = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{
data.ReadByte(); // Action. We do not take it, since it will not be needed in any way. Breaking the chest, we send 17 packet, in our case 34 packet only puts the chest.
int x = (int)data.ReadInt16();
int y = (int)data.ReadInt16();
short style = data.ReadInt16();
if (Main.tile[x, y] != null && Main.tile[x, y].type == 127)
{
e.Handled = true;
return;
}
if (player.SelectedItem.placeStyle != style)
{
TShock.Log.ConsoleError(string.Format("/ OnPlaceChest / Player {0} ({1}) placed an chest whose style({2}) does not match the present.", player.Name, player.IP, style));
player.SendErrorMessage("You cannot place this chest.");
e.Handled = true;
return;
}
}
}
}
}
}