From 480dee53b566ccc7d8cb934da0603370197c5f3e Mon Sep 17 00:00:00 2001 From: Shank Date: Tue, 31 May 2011 00:54:20 -0600 Subject: [PATCH] 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. --- TShockAPI/TShock.cs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index e7fce4ec..90960cb0 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -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); + } } } \ No newline at end of file