Updated GetData hook to support PvP and the tile whitelist.

Updated GetData to use BinaryReaders because they're 10x less confusing, 10x more versatile, and generally more awesome as a whole.
This commit is contained in:
Shank 2011-05-31 00:54:20 -06:00
parent d6b913a954
commit 480dee53b5

View file

@ -124,17 +124,22 @@ namespace TShockAPI
void GetData(GetDataEventArgs e)
{
if (Main.netMode != 2) { return; }
int n = 5;
byte[] buf = e.Msg.readBuffer;
if (e.MsgID == 17)
{
byte type = buf[n];
n++;
if (type == 0)
byte type;
int x = 0;
int y = 0;
using (var br = new BinaryReader(new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)))
{
type = br.ReadByte();
x = br.ReadInt32();
y = br.ReadInt32();
}
if (type == 0 && !TileOnWhitelist(Main.tile[x, y].type))
{
tileThreshold[e.Msg.whoAmI]++;
}
e.Handled = true;
return;
}
if (e.MsgID == 0x1e)
{
@ -776,5 +781,19 @@ namespace TShockAPI
}
}
public static bool TileOnWhitelist(byte tile)
{
int _tile = (int)tile;
TextReader tr2 = new StreamReader(saveDir + "tiles.txt");
tileWhitelist = tr2.ReadToEnd(); tr2.Close();
string hexValue = _tile.ToString("X");
if (hexValue == "0")
{
return false;
}
Console.WriteLine(hexValue);
return tileWhitelist.Contains(hexValue);
}
}
}