context: #region References
  using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.IO;
  using System.Net;
  using System.Security.Cryptography;
  using System.Text;
  using System.Threading;
  
  using Server.Accounting;
  using Server.ContextMenus;
  using Server.Diagnostics;
  using Server.Gumps;
  using Server.HuePickers;
  using Server.Items;
  using Server.Menus;
  using Server.Menus.ItemLists;
  using Server.Menus.Questions;
  using Server.Mobiles;
  using Server.Prompts;
  using Server.Targeting;
  #endregion
  
  namespace Server.Network
  {
  	public enum PMMessage : byte
  	{
  		CharNoExist = 1,
  		CharExists = 2,
  		CharInWorld = 5,
  		LoginSyncError = 6,
  		IdleWarning = 7
  	}
  
  	public enum LRReason : byte
  	{
  		CannotLift = 0,
  		OutOfRange = 1,
  		OutOfSight = 2,
  		TryToSteal = 3,
  		AreHolding = 4,
  		Inspecific = 5
  	}
  
  	/*public enum CMEFlags
  	{
  	None = 0x00,
  	Locked = 0x01,
  	Arrow = 0x02,
  	x0004 = 0x04,
  	Color = 0x20,
  	x0040 = 0x40,
  	x0080 = 0x80
  	}*/
  
  	public sealed class DamagePacketOld : Packet
  	{
  		public DamagePacketOld(Mobile m, int amount)
  			: base(0xBF)
  		{
  			EnsureCapacity(11);
  
  			m_Stream.Write((short)0x22);
  			m_Stream.Write((byte)1);
  			m_Stream.Write(m.Serial);
  
  			if (amount > 255)
  			{
  				amount = 255;
  			}
  			else if (amount < 0)
  			{
  				amount = 0;
  			}
  
  			m_Stream.Write((byte)amount);
  		}
  	}
  
  	public sealed class DamagePacket : Packet
  	{
  		public DamagePacket(IDamageable damageable, int amount)
  			: base(0x0B, 7)
  		{
              m_Stream.Write(damageable.Serial);
  
  			if (amount > 0xFFFF)
  			{
  				amount = 0xFFFF;
  			}
  			else if (amount < 0)
  			{
  				amount = 0;
  			}
  
  			m_Stream.Write((ushort)amount);
  		}
  
  		/*public DamagePacket( Mobile m, int amount ) : base( 0xBF )
  		{
  		EnsureCapacity( 11 );
  
  		m_Stream.Write( (short) 0x22 );
  		m_Stream.Write( (byte) 1 );
  		m_Stream.Write( (int) m.Serial );
  
  		if ( amount > 255 )
  		amount = 255;
  		else if ( amount < 0 )
  		amount = 0;
  
  		m_Stream.Write( (byte)amount );
  		}*/
  	}
  
  	public sealed class CancelArrow : Packet
  	{
  		public CancelArrow()
  			: base(0xBA, 6)
  		{
  			m_Stream.Write((byte)0);
  			m_Stream.Write((short)-1);
  			m_Stream.Write((short)-1);
  		}
  	}
  
  	public sealed class SetArrow : Packet
  	{
  		public SetArrow(int x, int y)
  			: base(0xBA, 6)
  		{
  			m_Stream.Write((byte)1);
  			m_Stream.Write((short)x);
  			m_Stream.Write((short)y);
  		}
  	}
  
  	public sealed class CancelArrowHS : Packet
  	{
  		public CancelArrowHS(int x, int y, Serial s)
  			: base(0xBA, 10)
  		{
  			m_Stream.Write((byte)0);
  			m_Stream.Write((short)x);
  			m_Stream.Write((short)y);
  			m_Stream.Write(s);
  		}
  	}
  
  	public sealed class SetArrowHS : Packet
  	{
  		public SetArrowHS(int x, int y, Serial s)
  			: base(0xBA, 10)
  		{
  			m_Stream.Write((byte)1);
  			m_Stream.Write((short)x);
  			m_Stream.Write((short)y);
  			m_Stream.Write(s);
  		}
  	}
  
  	public sealed class DisplaySecureTrade : Packet
  	{
  		public DisplaySecureTrade(Mobile them, Container first, Container second, string name)
  			: base(0x6F)
  		{
  			if (name == null)
  			{
  				name = "";
  			}
  
  			EnsureCapacity(18 + name.Length);
  
  			m_Stream.Write((byte)0); // Display
  			m_Stream.Write(them.Serial);
  			m_Stream.Write(first.Serial);
  			m_Stream.Write(second.Serial);
  			m_Stream.Write(true);
  
  			m_Stream.WriteAsciiFixed(name, 30);
  		}
  	}
  
  	public sealed class CloseSecureTrade : Packet
  	{
  		public CloseSecureTrade(Container cont)
  			: base(0x6F)
  		{
  			EnsureCapacity(8);
  
  			m_Stream.Write((byte)1); // Close
  			m_Stream.Write(cont.Serial);
  		}
  	}
  
  	public enum TradeFlag : byte
  	{
  		Display = 0x0,
  		Close = 0x1,
  		Update = 0x2,
  		UpdateGold = 0x3,
  		UpdateLedger = 0x4
  	}
  
  	public sealed class UpdateSecureTrade : Packet
  	{
  		public UpdateSecureTrade(Container cont, bool first, bool second)
  			: this(cont, TradeFlag.Update, first ? 1 : 0, second ? 1 : 0)
  		{ }
  
  		public UpdateSecureTrade(Container cont, TradeFlag flag, int first, int second)
  			: base(0x6F)
  		{
  			EnsureCapacity(17);
  
  			m_Stream.Write((byte)flag);
  			m_Stream.Write(cont.Serial);
  			m_Stream.Write(first);
  			m_Stream.Write(second);
  		}
  	}
  
  	public sealed class SecureTradeEquip : Packet
  	{
  		public SecureTradeEquip(Item item, Mobile m)
  			: base(0x25, 20)
  		{
  			m_Stream.Write(item.Serial);
  			m_Stream.Write((short)item.ItemID);
  			m_Stream.Write((byte)0);
  			m_Stream.Write((short)item.Amount);
  			m_Stream.Write((short)item.X);
  			m_Stream.Write((short)item.Y);
  			m_Stream.Write(m.Serial);
  			m_Stream.Write((short)item.Hue);
  		}
  	}
  
  	public sealed class SecureTradeEquip6017 : Packet
  	{
  		public SecureTradeEquip6017(Item item, Mobile m)
  			: base(0x25, 21)
  		{
  			m_Stream.Write(item.Serial);
  			m_Stream.Write((short)item.ItemID);
  			m_Stream.Write((byte)0);
  			m_Stream.Write((short)item.Amount);
  			m_Stream.Write((short)item.X);
  			m_Stream.Write((short)item.Y);
  			m_Stream.Write((byte)0); // Grid Location?
  			m_Stream.Write(m.Serial);
  			m_Stream.Write((short)item.Hue);
  		}
  	}
  
  	public sealed class MapPatches : Packet
  	{
  		public MapPatches()
  			: base(0xBF)
  		{
  			EnsureCapacity(9 + (3 * 8));
  
  			m_Stream.Write((short)0x0018);
  
  			m_Stream.Write(4);
  
  			m_Stream.Write(Map.Felucca.Tiles.Patch.StaticBlocks);
  			m_Stream.Write(Map.Felucca.Tiles.Patch.LandBlocks);
  
  			m_Stream.Write(Map.Trammel.Tiles.Patch.StaticBlocks);
  			m_Stream.Write(Map.Trammel.Tiles.Patch.LandBlocks);
  
  			m_Stream.Write(Map.Ilshenar.Tiles.Patch.StaticBlocks);
  			m_Stream.Write(Map.Ilshenar.Tiles.Patch.LandBlocks);
  
  			m_Stream.Write(Map.Malas.Tiles.Patch.StaticBlocks);
  			m_Stream.Write(Map.Malas.Tiles.Patch.LandBlocks);
  
  			//TODO: Should this include newer facets?
  		}
  	}
  
  	public sealed class ObjectHelpResponse : Packet
  	{
  		public ObjectHelpResponse(IEntity e, string text)
  			: base(0xB7)
  		{
  			EnsureCapacity(9 + (text.Length * 2));
  
  			m_Stream.Write(e.Serial);
  			m_Stream.WriteBigUniNull(text);
  		}
  	}
  
  	public sealed class VendorBuyContent : Packet
  	{
  		public VendorBuyContent(List<BuyItemState> list)
  			: base(0x3c)
  		{
  			EnsureCapacity(list.Count * 19 + 5);
  
  			m_Stream.Write((short)list.Count);
  
  			//The client sorts these by their X/Y value.
  			//OSI sends these in wierd order.  X/Y highest to lowest and serial loest to highest
  			//These are already sorted by serial (done by the vendor class) but we have to send them by x/y
  			//(the x74 packet is sent in 'correct' order.)
  			for (int i = list.Count - 1; i >= 0; --i)
  			{
  				BuyItemState bis = list[i];
  
  				m_Stream.Write(bis.MySerial);
  				m_Stream.Write((ushort)bis.ItemID);
  				m_Stream.Write((byte)0); //itemid offset
  				m_Stream.Write((ushort)bis.Amount);
  				m_Stream.Write((short)(i + 1)); //x
  				m_Stream.Write((short)1); //y
  				m_Stream.Write(bis.ContainerSerial);
  				m_Stream.Write((ushort)bis.Hue);
  			}
  		}
  	}
  
  	public sealed class VendorBuyContent6017 : Packet
  	{
  		public VendorBuyContent6017(List<BuyItemState> list)
  			: base(0x3c)
  		{
  			EnsureCapacity(list.Count * 20 + 5);
  
  			m_Stream.Write((short)list.Count);
  
  			//The client sorts these by their X/Y value.
  			//OSI sends these in wierd order.  X/Y highest to lowest and serial loest to highest
  			//These are already sorted by serial (done by the vendor class) but we have to send them by x/y
  			//(the x74 packet is sent in 'correct' order.)
  			for (int i = list.Count - 1; i >= 0; --i)
  			{
  				BuyItemState bis = list[i];
  
  				m_Stream.Write(bis.MySerial);
  				m_Stream.Write((ushort)bis.ItemID);
  				m_Stream.Write((byte)0); //itemid offset
  				m_Stream.Write((ushort)bis.Amount);
  				m_Stream.Write((short)(i + 1)); //x
  				m_Stream.Write((short)1); //y
  				m_Stream.Write((byte)0); // Grid Location?
  				m_Stream.Write(bis.ContainerSerial);
  				m_Stream.Write((ushort)bis.Hue);
  			}
  		}
  	}
  
  	public sealed class DisplayBuyList : Packet
  	{
  		public DisplayBuyList(Mobile vendor)
  			: base(0x24, 7)
  		{
  			m_Stream.Write(vendor.Serial);
  			m_Stream.Write((short)0x30); // buy window id?
  		}
  	}
  
  	public sealed class DisplayBuyListHS : Packet
  	{
  		public DisplayBuyListHS(Mobile vendor)
  			: base(0x24, 9)
  		{
  			m_Stream.Write(vendor.Serial);
  			m_Stream.Write((short)0x30); // buy window id?
  			m_Stream.Write((short)0x00);
  		}
  	}
  
  	public sealed class VendorBuyList : Packet
  	{
  		public VendorBuyList(Mobile vendor, List<BuyItemState> list)
  			: base(0x74)
  		{
  			EnsureCapacity(256);
  
  			Container BuyPack = vendor.FindItemOnLayer(Layer.ShopBuy) as Container;
  			m_Stream.Write((BuyPack == null ? Serial.MinusOne : BuyPack.Serial));
  
  			m_Stream.Write((byte)list.Count);
  
  			for (int i = 0; i < list.Count; ++i)
  			{
  				BuyItemState bis = list[i];
  
  				m_Stream.Write(bis.Price);
  
  				string desc = bis.Description;
  
  				if (desc == null)
  				{
  					desc = "";
  				}
  
  				m_Stream.Write((byte)(desc.Length + 1));
  				m_Stream.WriteAsciiNull(desc);
  			}
  		}
  	}
  
  	public sealed class VendorSellList : Packet
  	{
  		public VendorSellList(Mobile shopkeeper, ICollection<SellItemState> sis)
  			: base(0x9E)
  		{
  			EnsureCapacity(256);
  
  			m_Stream.Write(shopkeeper.Serial);
  
  			m_Stream.Write((ushort)sis.Count);
  
  			foreach (SellItemState state in sis)
  			{
  				m_Stream.Write(state.Item.Serial);
  				m_Stream.Write((ushort)state.Item.ItemID);
  				m_Stream.Write((ushort)state.Item.Hue);
  				m_Stream.Write((ushort)state.Item.Amount);
  				m_Stream.Write((ushort)state.Price);
  
  				string name = state.Item.Name;
  
  				if (name == null || (name = name.Trim()).Length <= 0)
  				{
  					name = state.Name;
  				}
  
  				if (name == null)
  				{
  					name = "";
  				}
  
  				m_Stream.Write((ushort)(name.Length));
  				m_Stream.WriteAsciiFixed(name, (ushort)(name.Length));
  			}
  		}
  	}
  
  	public sealed class EndVendorSell : Packet
  	{
  		public EndVendorSell(Mobile Vendor)
  			: base(0x3B, 8)
  		{
  			m_Stream.Write((ushort)8); //length
  			m_Stream.Write(Vendor.Serial);
  			m_Stream.Write((byte)0);
  		}
  	}
  
  	public sealed class EndVendorBuy : Packet
  	{
  		public EndVendorBuy(Mobile Vendor)
  			: base(0x3B, 8)
  		{
  			m_Stream.Write((ushort)8); //length
  			m_Stream.Write(Vendor.Serial);
  			m_Stream.Write((byte)0);
  		}
  	}
  
  	public sealed class DeathAnimation : Packet
  	{
  		public DeathAnimation(Mobile killed, Item corpse)
  			: base(0xAF, 13)
  		{
  			m_Stream.Write(killed.Serial);
  			m_Stream.Write((corpse == null ? Serial.Zero : corpse.Serial));
  			m_Stream.Write(0);
  		}
  	}
  
  	public sealed class StatLockInfo : Packet
  	{
  		public StatLockInfo(Mobile m)
  			: base(0xBF)
  		{
  			EnsureCapacity(12);
  
  			m_Stream.Write((short)0x19);
  
              if (m.NetState.IsEnhancedClient)
              {
                  m_Stream.Write((byte)5);
              }
              else
              {
                  m_Stream.Write((byte)2);
              }
  			
  			m_Stream.Write(m.Serial);
  			m_Stream.Write((byte)0);
  
  			int lockBits = 0;
  
  			lockBits |= (int)m.StrLock << 4;
  			lockBits |= (int)m.DexLock << 2;
  			lockBits |= (int)m.IntLock;
  
  			m_Stream.Write((byte)lockBits);
          }
      }
  
  	public class EquipInfoAttribute
  	{
  		private readonly int m_Number;
  		private readonly int m_Charges;
  
  		public int Number { get { return m_Number; } }
  
  		public int Charges { get { return m_Charges; } }
  
  		public EquipInfoAttribute(int number)
  			: this(number, -1)
  		{ }
  
  		public EquipInfoAttribute(int number, int charges)
  		{
  			m_Number = number;
  			m_Charges = charges;
  		}
  	}
  
  	public class EquipmentInfo
  	{
  		private readonly int m_Number;
  		private readonly Mobile m_Crafter;
  		private readonly bool m_Unidentified;
  		private readonly EquipInfoAttribute[] m_Attributes;
  
  		public int Number { get { return m_Number; } }
  
  		public Mobile Crafter { get { return m_Crafter; } }
  
  		public bool Unidentified { get { return m_Unidentified; } }
  
  		public EquipInfoAttribute[] Attributes { get { return m_Attributes; } }
  
  		public EquipmentInfo(int number, Mobile crafter, bool unidentified, EquipInfoAttribute[] attributes)
  		{
  			m_Number = number;
  			m_Crafter = crafter;
  			m_Unidentified = unidentified;
  			m_Attributes = attributes;
  		}
  	}
  
  	public sealed class DisplayEquipmentInfo : Packet
  	{
  		public DisplayEquipmentInfo(Item item, EquipmentInfo info)
  			: base(0xBF)
  		{
  			var attrs = info.Attributes;
  
  			EnsureCapacity(
  				17 + (info.Crafter == null ? 0 : 6 + info.Crafter.TitleName == null ? 0 : info.Crafter.TitleName.Length) +
  				(info.Unidentified ? 4 : 0) + (attrs.Length * 6));
  
  			m_Stream.Write((short)0x10);
  			m_Stream.Write(item.Serial);
  
  			m_Stream.Write(info.Number);
  
  			if (info.Crafter != null)
  			{
  				string name = info.Crafter.TitleName;
  
  				m_Stream.Write(-3);
  
  				if (name == null)
  				{
  					m_Stream.Write((ushort)0);
  				}
  				else
  				{
  					int length = name.Length;
  					m_Stream.Write((ushort)length);
  					m_Stream.WriteAsciiFixed(name, length);
  				}
  			}
  
  			if (info.Unidentified)
  			{
  				m_Stream.Write(-4);
  			}
  
  			for (int i = 0; i < attrs.Length; ++i)
  			{
  				m_Stream.Write(attrs[i].Number);
  				m_Stream.Write((short)attrs[i].Charges);
  			}
  
  			m_Stream.Write(-1);
  		}
  	}
  
  	public sealed class ChangeUpdateRange : Packet
  	{
  		private static readonly ChangeUpdateRange[] m_Cache = new ChangeUpdateRange[0x100];
  
  		public static ChangeUpdateRange Instantiate(int range)
  		{
  			byte idx = (byte)range;
  			ChangeUpdateRange p = m_Cache[idx];
  
  			if (p == null)
  			{
  				m_Cache[idx] = p = new ChangeUpdateRange(range);
  				p.SetStatic();
  			}
  
  			return p;
  		}
  
  		public ChangeUpdateRange(int range)
  			: base(0xC8, 2)
  		{
  			m_Stream.Write((byte)range);
  		}
  	}
  
  	public sealed class ChangeCombatant : Packet
  	{
  		public ChangeCombatant(IEntity combatant)
  			: base(0xAA, 5)
  		{
  			m_Stream.Write(combatant != null ? combatant.Serial : Serial.Zero);
  		}
  	}
  
  	public sealed class DisplayHuePicker : Packet
  	{
  		public DisplayHuePicker(HuePicker huePicker)
  			: base(0x95, 9)
  		{
  			m_Stream.Write(huePicker.Serial);
  			m_Stream.Write((short)0);
  			m_Stream.Write((short)huePicker.ItemID);
  		}
  	}
  
  	public sealed class TripTimeResponse : Packet
  	{
  		public TripTimeResponse(int unk)
  			: base(0xC9, 6)
  		{
  			m_Stream.Write((byte)unk);
  			m_Stream.Write(Environment.TickCount);
  		}
  	}
  
  	public sealed class UTripTimeResponse : Packet
  	{
  		public UTripTimeResponse(int unk)
  			: base(0xCA, 6)
  		{
  			m_Stream.Write((byte)unk);
  			m_Stream.Write(Environment.TickCount);
  		}
  	}
  
  	public sealed class UnicodePrompt : Packet
  	{
  		public UnicodePrompt(Prompt prompt, Mobile to)
  			: base(0xC2)
  		{
  			EnsureCapacity(21);
  
              Serial senderSerial = prompt.Sender != null ? prompt.Sender.Serial : to.Serial;
  
              m_Stream.Write((int)senderSerial);
              m_Stream.Write((int)prompt.TypeId); //0x2C
              m_Stream.Write((int)0); // type
              m_Stream.Write((int)0); // language
              m_Stream.Write((short)0); // text
          }
  	}
  
  	public sealed class ChangeCharacter : Packet
  	{
  		public ChangeCharacter(IAccount a)
  			: base(0x81)
  		{
  			EnsureCapacity(305);
  
  			int count = 0;
  
  			for (int i = 0; i < a.Length; ++i)
  			{
  				if (a[i] != null)
  				{
  					++count;
  				}
  			}
  
  			m_Stream.Write((byte)count);
  			m_Stream.Write((byte)0);
  
  			for (int i = 0; i < a.Length; ++i)
  			{
  				if (a[i] != null)
  				{
  					string name = a[i].Name;
  
  					if (name == null)
  					{
  						name = "-null-";
  					}
  					else if ((name = name.Trim()).Length == 0)
  					{
  						name = "-empty-";
  					}
  
  					m_Stream.WriteAsciiFixed(name, 30);
  					m_Stream.Fill(30); // password
  				}
  				else
  				{
  					m_Stream.Fill(60);
  				}
  			}
  		}
  	}
  
  	public sealed class DeathStatus : Packet
  	{
  		public static readonly Packet Dead = SetStatic(new DeathStatus(true));
  		public static readonly Packet Alive = SetStatic(new DeathStatus(false));
  
  		public static Packet Instantiate(bool dead)
  		{
  			return (dead ? Dead : Alive);
  		}
  
  		public DeathStatus(bool dead)
  			: base(0x2C, 2)
  		{
  			m_Stream.Write((byte)(dead ? 0 : 2));
  		}
  	}
  
      public enum SpeedControlType : byte
      {
          Disable,
          MountSpeed,
          WalkSpeed,
          WalkSpeedFast,
          TeleportSpeed
      }
  
  	public sealed class SpeedControl : Packet
  	{
          public static readonly Packet TeleportSpeed = SetStatic(new SpeedControl(SpeedControlType.TeleportSpeed));
          public static readonly Packet WalkSpeedFast = SetStatic(new SpeedControl(SpeedControlType.WalkSpeedFast));
          public static readonly Packet WalkSpeed = SetStatic(new SpeedControl(SpeedControlType.WalkSpeed));
          public static readonly Packet MountSpeed = SetStatic(new SpeedControl(SpeedControlType.MountSpeed));
          public static readonly Packet Disable = SetStatic(new SpeedControl(SpeedControlType.Disable));
  
  		public SpeedControl(SpeedControlType type)
  			: base(0xBF)
  		{
  			EnsureCapacity(3);
  
  			m_Stream.Write((short)0x26);
              m_Stream.Write((byte)type);
  		}
  	}
  
  	public sealed class InvalidMapEnable : Packet
  	{
  		public InvalidMapEnable()
  			: base(0xC6, 1)
  		{ }
  	}
  
  	public sealed class BondedStatus : Packet
  	{
  		public BondedStatus(int val1, Serial serial, int val2)
  			: base(0xBF)
  		{
  			EnsureCapacity(11);
  
  			m_Stream.Write((short)0x19);
  			m_Stream.Write((byte)val1);
  			m_Stream.Write(serial);
  			m_Stream.Write((byte)val2);
  		}
  	}
  
  	public sealed class ToggleSpecialAbility : Packet
  	{
  		public ToggleSpecialAbility(int abilityID, bool active)
  			: base(0xBF)
  		{
  			EnsureCapacity(7);
  
  			m_Stream.Write((short)0x25);
  
  			m_Stream.Write((short)abilityID);
  			m_Stream.Write(active);
  		}
  	}
  
  	public sealed class DisplayItemListMenu : Packet
  	{
  		public DisplayItemListMenu(ItemListMenu menu)
  			: base(0x7C)
  		{
  			EnsureCapacity(256);
  
  			m_Stream.Write(((IMenu)menu).Serial);
  			m_Stream.Write((short)0);
  
  			string question = menu.Question;
  
  			if (question == null)
  			{
  				m_Stream.Write((byte)0);
  			}
  			else
  			{
  				int questionLength = question.Length;
  				m_Stream.Write((byte)questionLength);
  				m_Stream.WriteAsciiFixed(question, questionLength);
  			}
  
  			var entries = menu.Entries;
  
  			int entriesLength = (byte)entries.Length;
  
  			m_Stream.Write((byte)entriesLength);
  
  			for (int i = 0; i < entriesLength; ++i)
  			{
  				ItemListEntry e = entries[i];
  
  				m_Stream.Write((ushort)e.ItemID);
  				m_Stream.Write((short)e.Hue);
  
  				string name = e.Name;
  
  				if (name == null)
  				{
  					m_Stream.Write((byte)0);
  				}
  				else
  				{
  					int nameLength = name.Length;
  					m_Stream.Write((byte)nameLength);
  					m_Stream.WriteAsciiFixed(name, nameLength);
  				}
  			}
  		}
  	}
  
  	public sealed class DisplayQuestionMenu : Packet
  	{
  		public DisplayQuestionMenu(QuestionMenu menu)
  			: base(0x7C)
  		{
  			EnsureCapacity(256);
  
  			m_Stream.Write(((IMenu)menu).Serial);
  			m_Stream.Write((short)0);
  
  			string question = menu.Question;
  
  			if (question == null)
  			{
  				m_Stream.Write((byte)0);
  			}
  			else
  			{
  				int questionLength = question.Length;
  				m_Stream.Write((byte)questionLength);
  				m_Stream.WriteAsciiFixed(question, questionLength);
  			}
  
  			var answers = menu.Answers;
  
  			int answersLength = (byte)answers.Length;
  
  			m_Stream.Write((byte)answersLength);
  
  			for (int i = 0; i < answersLength; ++i)
  			{
  				m_Stream.Write(0);
  
  				string answer = answers[i];
  
  				if (answer == null)
  				{
  					m_Stream.Write((byte)0);
  				}
  				else
  				{
  					int answerLength = answer.Length;
  					m_Stream.Write((byte)answerLength);
  					m_Stream.WriteAsciiFixed(answer, answerLength);
  				}
  			}
  		}
  	}
  
  	public sealed class GlobalLightLevel : Packet
  	{
  		private static readonly GlobalLightLevel[] m_Cache = new GlobalLightLevel[0x100];
  
  		public static GlobalLightLevel Instantiate(int level)
  		{
  			byte lvl = (byte)level;
  			GlobalLightLevel p = m_Cache[lvl];
  
  			if (p == null)
  			{
  				m_Cache[lvl] = p = new GlobalLightLevel(level);
  				p.SetStatic();
  			}
  
  			return p;
  		}
  
  		public GlobalLightLevel(int level)
  			: base(0x4F, 2)
  		{
  			m_Stream.Write((byte)level);
  		}
  	}
  
  	public sealed class PersonalLightLevel : Packet
  	{
  		public PersonalLightLevel(Mobile m)
  			: this(m, m.LightLevel)
  		{ }
  
  		public PersonalLightLevel(Mobile m, int level)
  			: base(0x4E, 6)
  		{
  			m_Stream.Write(m.Serial);
  			m_Stream.Write((byte)level);
  		}
  	}
  
  	public sealed class PersonalLightLevelZero : Packet
  	{
  		public PersonalLightLevelZero(Mobile m)
  			: base(0x4E, 6)
  		{
  			m_Stream.Write(m.Serial);
  			m_Stream.Write((byte)0);
  		}
  	}
  
  	public enum CMEFlags
  	{
  		None = 0x00,
  		Disabled = 0x01,
  		Arrow = 0x02,
  		Highlighted = 0x04,
  		Colored = 0x20
  	}
  
  	public sealed class DisplayContextMenu : Packet
  	{
  		public DisplayContextMenu(ContextMenu menu)
  			: base(0xBF)
  		{
  			var entries = menu.Entries;
  
  			int length = (byte)entries.Length;
  
  			EnsureCapacity(12 + (length * 8));
  
  			m_Stream.Write((short)0x14);
  			m_Stream.Write((short)0x02);
  
  			IEntity target = menu.Target as IEntity;
  
  			m_Stream.Write((target == null ? Serial.MinusOne : target.Serial));
  
  			m_Stream.Write((byte)length);
  
  			Point3D p;
  
  			if (target is Mobile)
  			{
  				p = target.Location;
  			}
  			else if (target is Item)
  			{
  				p = ((Item)target).GetWorldLocation();
  			}
  			else
  			{
  				p = Point3D.Zero;
  			}
  
  			for (int i = 0; i < length; ++i)
  			{
  				ContextMenuEntry e = entries[i];
  
  				m_Stream.Write(e.Number);
  				m_Stream.Write((short)i);
  
  				int range = e.Range;
  
  				if (range == -1)
  				{
  					range = 18;
  				}
  
  				CMEFlags flags = (e.Enabled && menu.From.InRange(p, range)) ? CMEFlags.None : CMEFlags.Disabled;
  
  				flags |= e.Flags;
  
  				m_Stream.Write((short)flags);
  			}
  		}
  	}
  
  	public sealed class DisplayContextMenuOld : Packet
  	{
          public DisplayContextMenuOld(ContextMenu menu)
              : base(0xBF)
              {
              var entries = menu.Entries;
  
              int length = (byte)entries.Length;
  
              EnsureCapacity(12 + (length * 8));
  
              m_Stream.Write((short)0x14);
  			m_Stream.Write((short)0x02); 
  
              IEntity target = menu.Target as IEntity;
  
  			m_Stream.Write((target == null ? Serial.MinusOne : target.Serial));
  
  			m_Stream.Write((byte)length);
  
  			Point3D p;
  
  			if (target is Mobile)
  			{
  				p = target.Location;
  			}
  			else if (target is Item)
  			{
  				p = ((Item)target).GetWorldLocation();
  			}
  			else
  			{
  				p = Point3D.Zero;
  			}
  
  			for (int i = 0; i < length; ++i)
  			{
  				ContextMenuEntry e = entries[i];
  
                  if (e.Number <= 65535)
                  {
                      m_Stream.Write((uint)(e.Number + 3000000));
                  }
                  else
                  {
                      m_Stream.Write((uint)e.Number);
                  }
  
                  m_Stream.Write((short)i);
  
                  int range = e.Range;
  
  				if (range == -1)
  				{
  					range = 18;
  				}
  
  				CMEFlags flags = (e.Enabled && menu.From.InRange(p, range)) ? CMEFlags.None : CMEFlags.Disabled;
  
  				int color = e.Color & 0xFFFF;
  
  				if (color != 0xFFFF)
  				{
  					flags |= CMEFlags.Colored;
  				}
  
  				flags |= e.Flags;
  
  				m_Stream.Write((short)flags);
  
  				if ((flags & CMEFlags.Colored) != 0)
  				{
  					m_Stream.Write((short)color);
  				}
  			}
  		}
  	}
  
  	public sealed class DisplayProfile : Packet
  	{
  		public DisplayProfile(bool realSerial, Mobile m, string header, string body, string footer)
  			: base(0xB8)
  		{
  			if (header == null)
  			{
  				header = "";
  			}
  
  			if (body == null)
  			{
  				body = "";
  			}
  
  			if (footer == null)
  			{
  				footer = "";
  			}
  
  			EnsureCapacity(12 + header.Length + (footer.Length * 2) + (body.Length * 2));
  
  			m_Stream.Write((realSerial ? m.Serial : Serial.Zero));
  			m_Stream.WriteAsciiNull(header);
  			m_Stream.WriteBigUniNull(footer);
  			m_Stream.WriteBigUniNull(body);
  		}
  	}
  
  	public sealed class CloseGump : Packet
  	{
  		public CloseGump(int typeID, int buttonID)
  			: base(0xBF)
  		{
  			EnsureCapacity(13);
  
  			m_Stream.Write((short)0x04);
  			m_Stream.Write(typeID);
  			m_Stream.Write(buttonID);
  		}
  	}
  
  	public sealed class EquipUpdate : Packet
  	{
  		public EquipUpdate(Item item)
  			: base(0x2E, 15)
  		{
  			Serial parentSerial;
  
  			if (item.Parent is Mobile)
  			{
  				parentSerial = ((Mobile)item.Parent).Serial;
  			}
  			else
  			{
  				Console.WriteLine("Warning: EquipUpdate on item with !(parent is Mobile)");
  				parentSerial = Serial.Zero;
  			}
  
  			int hue = item.Hue;
  
  			if (item.Parent is Mobile)
  			{
  				Mobile mob = (Mobile)item.Parent;
  
  				if (mob.SolidHueOverride >= 0)
  				{
  					hue = mob.SolidHueOverride;
  				}
  			}
  
  			m_Stream.Write(item.Serial);
  			m_Stream.Write((short)item.ItemID);
  			m_Stream.Write((byte)0);
  			m_Stream.Write((byte)item.Layer);
  			m_Stream.Write(parentSerial);
  			m_Stream.Write((short)hue);
  		}
  	}
  
  	public sealed class WorldItem : Packet
  	{
  		public WorldItem(Item item)
  			: base(0x1A)
  		{
  			EnsureCapacity(20);
  
  			// 14 base length
  			// +2 - Amount
  			// +2 - Hue
  			// +1 - Flags
  
  			uint serial = (uint)item.Serial.Value;
  			int itemID = item.ItemID & 0x3FFF;
  			int amount = item.Amount;
  			Point3D loc = item.Location;
  			int x = loc.m_X;
  			int y = loc.m_Y;
  			int hue = item.Hue;
  			int flags = item.GetPacketFlags();
  			int light = (int)item.Light;
  
  			if (amount != 0)
  			{
  				serial |= 0x80000000;
  			}
  			else
  			{
  				serial &= 0x7FFFFFFF;
  			}
  
  			m_Stream.Write(serial);
  
  			if (item is BaseMulti)
  			{
  				m_Stream.Write((short)(itemID | 0x4000));
  			}
  			else
  			{
  				m_Stream.Write((short)itemID);
  			}
  
  			if (amount != 0)
  			{
  				m_Stream.Write((short)amount);
  			}
  
  			x &= 0x7FFF;
  
  			if (light != 0)
  			{
  				x |= 0x8000;
  			}
  
  			m_Stream.Write((short)x);
  
  			y &= 0x3FFF;
  
  			if (hue != 0)
  			{
  				y |= 0x8000;
  			}
  
  			if (flags != 0)
  			{
  				y |= 0x4000;
  			}
  
  			m_Stream.Write((short)y);
  
  			if (light != 0)
  			{
  				m_Stream.Write((byte)light);
  			}
  
  			m_Stream.Write((sbyte)loc.m_Z);
  
  			if (hue != 0)
  			{
  				m_Stream.Write((ushort)hue);
  			}
  
  			if (flags != 0)
  			{
  				m_Stream.Write((byte)flags);
  			}
  		}
  	}
  
  	public sealed class WorldItemSA : Packet
  	{
  		public WorldItemSA(Item item)
  			: base(0xF3, 24)
  		{
  			m_Stream.Write((short)0x1);
  
  			int itemID = item.ItemID;
  
  			if (item is BaseMulti)
  			{
  				m_Stream.Write((byte)0x02);
  
  				m_Stream.Write(item.Serial);
  
  				itemID &= 0x3FFF;
  
  				m_Stream.Write((short)itemID);
  
  				m_Stream.Write((byte)0);
  			}
  			else
  			{
  				m_Stream.Write((byte)0x00);
  
  				m_Stream.Write(item.Serial);
  
  				itemID &= 0x7FFF;
  
  				m_Stream.Write((short)itemID);
  
  				m_Stream.Write((byte)0);
  			}
  
  			int amount = item.Amount;
  			m_Stream.Write((short)amount);
  			m_Stream.Write((short)amount);
  
  			Point3D loc = item.Location;
  			int x = loc.m_X & 0x7FFF;
  			int y = loc.m_Y & 0x3FFF;
  			m_Stream.Write((short)x);
  			m_Stream.Write((short)y);
  			m_Stream.Write((sbyte)loc.m_Z);
  
  			m_Stream.Write((byte)item.Light);
  			m_Stream.Write((short)item.Hue);
  			m_Stream.Write((byte)item.GetPacketFlags());
  		}
  	}
  
      public sealed class WorldItemHS : Packet
      {
          public WorldItemHS(Item item)
              : base(0xF3, 26)
          {
              m_Stream.Write((short)0x1);
  
              int itemID = item.ItemID;
  
              if (item is BaseMulti)
              {
                  m_Stream.Write((byte)0x02);
                  m_Stream.Write(item.Serial);
  
                  itemID &= 0x3FFF;
  
                  m_Stream.Write((ushort)itemID);
  
                  m_Stream.Write((byte)0);
              }
              else
              {
                  if (item is IDamageable)
                  {
                      m_Stream.Write((byte)0x03);
                  }
                  else
                  {
                      m_Stream.Write((byte)0x00);
                  }
  
                  m_Stream.Write(item.Serial);
  
                  itemID &= 0xFFFF;
  
                  m_Stream.Write((ushort)itemID);
  
                  m_Stream.Write((byte)0);
              }
  
              int amount = item.Amount;
              m_Stream.Write((short)amount);
              m_Stream.Write((short)amount);
  
              Point3D loc = item.Location;
              int x = loc.m_X & 0x7FFF;
              int y = loc.m_Y & 0x3FFF;
              m_Stream.Write((short)x);
              m_Stream.Write((short)y);
              m_Stream.Write((sbyte)loc.m_Z);
  
              m_Stream.Write((byte)item.Light);
              m_Stream.Write((short)item.Hue);
              m_Stream.Write((byte)item.GetPacketFlags());
  
              m_Stream.Write((short)0x00); // ??
          }
  
          public WorldItemHS(Item item, PacketWriter stream)
              : base(0xF3, 26, stream)
          {
              stream.Write((short)0x1);
  
              int itemID = item.ItemID;
  
              if (item is BaseMulti)
              {
                  m_Stream.Write((byte)0x02);
                  stream.Write((int)item.Serial);
                  itemID &= 0x3FFF;
                  stream.Write((ushort)itemID);
                  stream.Write((byte)0);
              }
              else
              {
                  if (item is IDamageable)
                  {
                      m_Stream.Write((byte)0x03);
                  }
                  else
                  {
                      m_Stream.Write((byte)0x00);
                  }
  
                  stream.Write((int)item.Serial);
                  itemID &= 0xFFFF;
                  stream.Write((ushort)itemID);
                  stream.Write((byte)0);
              }
  
              int amount = item.Amount;
              stream.Write((short)amount);
              stream.Write((short)amount);
  
              Point3D loc = item.Location;
              int x = loc.m_X & 0x7FFF;
              int y = loc.m_Y & 0x3FFF;
              stream.Write((short)x);
              stream.Write((short)y);
              stream.Write((sbyte)loc.m_Z);
  
              stream.Write((byte)item.Light);
              stream.Write((short)item.Hue);
              stream.Write((byte)item.GetPacketFlags());
  
              stream.Write((short)0x00); // ??
          }
  
          public WorldItemHS(Mobile mob, PacketWriter stream)
              : base(0xF3, 26, stream)
          {
              stream.Write((short)0x1);
  
              stream.Write((byte)0x01);
              stream.Write((int)mob.Serial);
              stream.Write((ushort)mob.BodyValue);
              stream.Write((byte)0);
  
              int amount = 1;
              stream.Write((short)amount);
              stream.Write((short)amount);
  
              Point3D loc = mob.Location;
              int x = loc.m_X & 0x7FFF;
              int y = loc.m_Y & 0x3FFF;
              stream.Write((short)x);
              stream.Write((short)y);
              stream.Write((sbyte)loc.m_Z);
  
              stream.Write((byte)mob.LightLevel);
              stream.Write((short)mob.Hue);
              stream.Write((byte)mob.GetPacketFlags());
  
              stream.Write((short)0x00); // ??
          }
      }
  
      public sealed class LiftRej : Packet
  	{
  		public LiftRej(LRReason reason)
  			: base(0x27, 2)
  		{
  			m_Stream.Write((byte)reason);
  		}
  	}
  
  	public sealed class LogoutAck : Packet
  	{
  		public LogoutAck()
  			: base(0xD1, 2)
  		{
  			m_Stream.Write((byte)0x01);
  		}
  	}
  
  	public sealed class Weather : Packet
  	{
  		public Weather(int v1, int v2, int v3)
  			: base(0x65, 4)
  		{
  			m_Stream.Write((byte)v1);
  			m_Stream.Write((byte)v2);
  			m_Stream.Write((byte)v3);
  		}
  	}
  
  	public sealed class UnkD3 : Packet
  	{
  		public UnkD3(Mobile beholder, Mobile beheld)
  			: base(0xD3)
  		{
  			EnsureCapacity(256);
  
  			//int
  			//short
  			//short
  			//short
  			//byte
  			//byte
  			//short
  			//byte
  			//byte
  			//short
  			//short
  			//short
  			//while ( int != 0 )
  			//{
  			//short
  			//byte
  			//short
  			//}
  
  			m_Stream.Write(beheld.Serial);
  			m_Stream.Write((short)beheld.Body);
  			m_Stream.Write((short)beheld.X);
  			m_Stream.Write((short)beheld.Y);
  			m_Stream.Write((sbyte)beheld.Z);
  			m_Stream.Write((byte)beheld.Direction);
  			m_Stream.Write((ushort)beheld.Hue);
  			m_Stream.Write((byte)beheld.GetPacketFlags());
  			m_Stream.Write((byte)Notoriety.Compute(beholder, beheld));
  
  			m_Stream.Write((short)0);
  			m_Stream.Write((short)0);
  			m_Stream.Write((short)0);
  
  			m_Stream.Write(0);
  		}
  	}
  
  	public sealed class GQRequest : Packet
  	{
  		public GQRequest()
  			: base(0xC3)
  		{
  			EnsureCapacity(256);
  
  			m_Stream.Write(1);
  			m_Stream.Write(2); // ID
  			m_Stream.Write(3); // Customer ? (this)
  			m_Stream.Write(4); // Customer this (?)
  			m_Stream.Write(0);
  			m_Stream.Write((short)0);
  			m_Stream.Write((short)6);
  			m_Stream.Write((byte)'r');
  			m_Stream.Write((byte)'e');
  			m_Stream.Write((byte)'g');
  			m_Stream.Write((byte)'i');
  			m_Stream.Write((byte)'o');
  			m_Stream.Write((byte)'n');
  			m_Stream.Write(7); // Call time in seconds
  			m_Stream.Write((short)2); // Map (0=fel,1=tram,2=ilsh)
  			m_Stream.Write(8); // X
  			m_Stream.Write(9); // Y
  			m_Stream.Write(10); // Z
  			m_Stream.Write(11); // Volume
  			m_Stream.Write(12); // Rank
  			m_Stream.Write(-1);
  			m_Stream.Write(1); // type
  		}
  	}
  
  	/// <summary>
  	///     Causes the client to walk in a given direction. It does not send a movement request.
  	/// </summary>
  	public sealed class PlayerMove : Packet
  	{
  		public PlayerMove(Direction d)
  			: base(0x97, 2)
  		{
  			m_Stream.Write((byte)d);
  			// @4C63B0
  		}
  	}
  
  	/// <summary>
  	///     Displays a message "There are currently [count] available calls in the global queue.".
  	/// </summary>
  	public sealed class GQCount : Packet
  	{
  		public GQCount(int unk, int count)
  			: base(0xCB, 7)
  		{
  			m_Stream.Write((short)unk);
  			m_Stream.Write(count);
  		}
  	}
  
  	/// <summary>
  	///     Asks the client for it's version
  	/// </summary>
  	public sealed class ClientVersionReq : Packet
  	{
  		public ClientVersionReq()
  			: base(0xBD)
  		{
  			EnsureCapacity(3);
  		}
  	}
  
  	/// <summary>
  	///     Asks the client for it's "assist version". (Perhaps for UOAssist?)
  	/// </summary>
  	public sealed class AssistVersionReq : Packet
  	{
  		public AssistVersionReq(int unk)
  			: base(0xBE)
  		{
  			EnsureCapacity(7);
  
  			m_Stream.Write(unk);
  		}
  	}
  
  	public enum EffectType
  	{
  		Moving = 0x00,
  		Lightning = 0x01,
  		FixedXYZ = 0x02,
  		FixedFrom = 0x03
  	}
  
  	public class ParticleEffect : Packet
  	{
  		public ParticleEffect(
  			EffectType type,
  			Serial from,
  			Serial to,
  			int itemID,
  			Point3D fromPoint,
  			Point3D toPoint,
  			int speed,
  			int duration,
  			bool fixedDirection,
  			bool explode,
  			int hue,
  			int renderMode,
  			int effect,
  			int explodeEffect,
  			int explodeSound,
  			Serial serial,
  			int layer,
  			int unknown)
  			: base(0xC7, 49)
  		{
  			m_Stream.Write((byte)type);
  			m_Stream.Write(@from);
  			m_Stream.Write(to);
  			m_Stream.Write((short)itemID);
  			m_Stream.Write((short)fromPoint.m_X);
  			m_Stream.Write((short)fromPoint.m_Y);
  			m_Stream.Write((sbyte)fromPoint.m_Z);
  			m_Stream.Write((short)toPoint.m_X);
  			m_Stream.Write((short)toPoint.m_Y);
  			m_Stream.Write((sbyte)toPoint.m_Z);
  			m_Stream.Write((byte)speed);
  			m_Stream.Write((byte)duration);
  			m_Stream.Write((byte)0);
  			m_Stream.Write((byte)0);
  			m_Stream.Write(fixedDirection);
  			m_Stream.Write(explode);
  			m_Stream.Write(hue);
  			m_Stream.Write(renderMode);
  			m_Stream.Write((short)effect);
  			m_Stream.Write((short)explodeEffect);
  			m_Stream.Write((short)explodeSound);
  			m_Stream.Write(serial);
  			m_Stream.Write((byte)layer);
  			m_Stream.Write((short)unknown);
  		}
  
  		public ParticleEffect(
  			EffectType type,
  			Serial from,
  			Serial to,
  			int itemID,
  			IPoint3D fromPoint,
  			IPoint3D toPoint,
  			int speed,
  			int duration,
  			bool fixedDirection,
  			bool explode,
  			int hue,
  			int renderMode,
  			int effect,
  			int explodeEffect,
  			int explodeSound,
  			Serial serial,
  			int layer,
  			int unknown)
  			: base(0xC7, 49)
  		{
  			m_Stream.Write((byte)type);
  			m_Stream.Write(@from);
  			m_Stream.Write(to);
  			m_Stream.Write((short)itemID);
  			m_Stream.Write((short)fromPoint.X);
  			m_Stream.Write((short)fromPoint.Y);
  			m_Stream.Write((sbyte)fromPoint.Z);
  			m_Stream.Write((short)toPoint.X);
  			m_Stream.Write((short)toPoint.Y);
  			m_Stream.Write((sbyte)toPoint.Z);
  			m_Stream.Write((byte)speed);
  			m_Stream.Write((byte)duration);
  			m_Stream.Write((byte)0);
  			m_Stream.Write((byte)0);
  			m_Stream.Write(fixedDirection);
  			m_Stream.Write(explode);
  			m_Stream.Write(hue);
  			m_Stream.Write(renderMode);
  			m_Stream.Write((short)effect);
  			m_Stream.Write((short)explodeEffect);
  			m_Stream.Write((short)explodeSound);
  			m_Stream.Write(serial);
  			m_Stream.Write((byte)layer);
  			m_Stream.Write((short)unknown);
  		}
  	}
  
      public class GraphicalEffect : Packet
      {
          public GraphicalEffect(EffectType type, Serial from, Serial to, int itemID, Point3D fromPoint, Point3D toPoint, int speed, int duration, bool fixedDirection, bool explode)
              : this(type, from, to, itemID, fromPoint, toPoint, speed, duration, fixedDirection, explode ? 1 : 0)
          {
          }
  
          public GraphicalEffect(EffectType type, Serial from, Serial to, int itemID, Point3D fromPoint, Point3D toPoint, int speed, int duration, bool fixedDirection, int explode)
              : base(0x70, 28)
          {
              m_Stream.Write((byte)type);
              m_Stream.Write((int)from);
              m_Stream.Write((int)to);
              m_Stream.Write((short)itemID);
              m_Stream.Write((short)fromPoint.X);
              m_Stream.Write((short)fromPoint.Y);
              m_Stream.Write((sbyte)fromPoint.Z);
              m_Stream.Write((short)toPoint.X);
              m_Stream.Write((short)toPoint.Y);
              m_Stream.Write((sbyte)toPoint.Z);
              m_Stream.Write((byte)speed);
              m_Stream.Write((byte)duration);
              m_Stream.Write((byte)0);
              m_Stream.Write((byte)0);
              m_Stream.Write((bool)fixedDirection);
              m_Stream.Write((byte)explode);
          }
      }
  
      public class HuedEffect : Packet
  	{
  		public HuedEffect(
  			EffectType type,
  			Serial from,
  			Serial to,
  			int itemID,
  			Point3D fromPoint,
  			Point3D toPoint,
  			int speed,
  			int duration,
  			bool fixedDirection,
  			bool explode,
  			int hue,
  			int renderMode)
  			: base(0xC0, 36)
  		{
  			m_Stream.Write((byte)type);
  			m_Stream.Write(@from);
  			m_Stream.Write(to);
  			m_Stream.Write((short)itemID);
  			m_Stream.Write((short)fromPoint.m_X);
  			m_Stream.Write((short)fromPoint.m_Y);
  			m_Stream.Write((sbyte)fromPoint.m_Z);
  			m_Stream.Write((short)toPoint.m_X);
  			m_Stream.Write((short)toPoint.m_Y);
  			m_Stream.Write((sbyte)toPoint.m_Z);
  			m_Stream.Write((byte)speed);
  			m_Stream.Write((byte)duration);
  			m_Stream.Write((byte)0);
  			m_Stream.Write((byte)0);
  			m_Stream.Write(fixedDirection);
  			m_Stream.Write(explode);
  			m_Stream.Write(hue);
  			m_Stream.Write(renderMode);
  		}
  
  		public HuedEffect(
  			EffectType type,
  			Serial from,
  			Serial to,
  			int itemID,
  			IPoint3D fromPoint,
  			IPoint3D toPoint,
  			int speed,
  			int duration,
  			bool fixedDirection,
  			bool explode,
  			int hue,
  			int renderMode)
  			: base(0xC0, 36)
  		{
  			m_Stream.Write((byte)type);
  			m_Stream.Write(@from);
  			m_Stream.Write(to);
  			m_Stream.Write((short)itemID);
  			m_Stream.Write((short)fromPoint.X);
  			m_Stream.Write((short)fromPoint.Y);
  			m_Stream.Write((sbyte)fromPoint.Z);
  			m_Stream.Write((short)toPoint.X);
  			m_Stream.Write((short)toPoint.Y);
  			m_Stream.Write((sbyte)toPoint.Z);
  			m_Stream.Write((byte)speed);
  			m_Stream.Write((byte)duration);
  			m_Stream.Write((byte)0);
  			m_Stream.Write((byte)0);
  			m_Stream.Write(fixedDirection);
  			m_Stream.Write(explode);
  			m_Stream.Write(hue);
  			m_Stream.Write(renderMode);
  		}
  	}
  
  	public sealed class TargetParticleEffect : ParticleEffect
  	{
  		public TargetParticleEffect(
  			IEntity e, int itemID, int speed, int duration, int hue, int renderMode, int effect, int layer, int unknown)
  			: base(
  				EffectType.FixedFrom,
  				e.Serial,
  				Serial.Zero,
  				itemID,
  				e.Location,
  				e.Location,
  				speed,
  				duration,
  				true,
  				false,
  				hue,
  				renderMode,
  				effect,
  				1,
  				0,
  				e.Serial,
  				layer,
  				unknown)
  		{ }
  	}
  
  	public sealed class TargetEffect : HuedEffect
  	{
  		public TargetEffect(IEntity e, int itemID, int speed, int duration, int hue, int renderMode)
  			: base(
  				EffectType.FixedFrom,
  				e.Serial,
  				Serial.Zero,
  				itemID,
  				e.Location,
  				e.Location,
  				speed,
  				duration,
  				true,
  				false,
  				hue,
  				renderMode)
  		{ }
  	}
  
  	public sealed class LocationParticleEffect : ParticleEffect
  	{
  		public LocationParticleEffect(
  			IEntity e, int itemID, int speed, int duration, int hue, int renderMode, int effect, int unknown)
  			: base(
  				EffectType.FixedXYZ,
  				e.Serial,
  				Serial.Zero,
  				itemID,
  				e.Location,
  				e.Location,
  				speed,
  				duration,
  				true,
  				false,
  				hue,
  				renderMode,
  				effect,
  				1,
  				0,
  				e.Serial,
  				255,
  				unknown)
  		{ }
  	}
  
  	public sealed class LocationEffect : HuedEffect
  	{
  		public LocationEffect(IPoint3D p, int itemID, int speed, int duration, int hue, int renderMode)
  			: base(EffectType.FixedXYZ, Serial.Zero, Serial.Zero, itemID, p, p, speed, duration, true, false, hue, renderMode)
  		{ }
  	}
  
  	public sealed class MovingParticleEffect : ParticleEffect
  	{
  		public MovingParticleEffect(
  			IEntity from,
  			IEntity to,
  			int itemID,
  			int speed,
  			int duration,
  			bool fixedDirection,
  			bool explodes,
  			int hue,
  			int renderMode,
  			int effect,
  			int explodeEffect,
  			int explodeSound,
  			EffectLayer layer,
  			int unknown)
  			: base(
  				EffectType.Moving,
  				from.Serial,
  				to.Serial,
  				itemID,
  				from.Location,
  				to.Location,
  				speed,
  				duration,
  				fixedDirection,
  				explodes,
  				hue,
  				renderMode,
  				effect,
  				explodeEffect,
  				explodeSound,
  				Serial.Zero,
  				(int)layer,
  				unknown)
  		{ }
  	}
  
  	public sealed class MovingEffect : HuedEffect
  	{
  		public MovingEffect(
  			IEntity from,
  			IEntity to,
  			int itemID,
  			int speed,
  			int duration,
  			bool fixedDirection,
  			bool explodes,
  			int hue,
  			int renderMode)
  			: base(
  				EffectType.Moving,
  				from.Serial,
  				to.Serial,
  				itemID,
  				from.Location,
  				to.Location,
  				speed,
  				duration,
  				fixedDirection,
  				explodes,
  				hue,
  				renderMode)
  		{ }
  	}
  
  	public enum ScreenEffectType
  	{
  		FadeOut = 0x00,
  		FadeIn = 0x01,
  		LightFlash = 0x02,
  		FadeInOut = 0x03,
  		DarkFlash = 0x04
  	}
  
  	public class ScreenEffect : Packet
  	{
  		public ScreenEffect(ScreenEffectType type)
  			: base(0x70, 28)
  		{
  			m_Stream.Write((byte)0x04);
  			m_Stream.Fill(8);
  			m_Stream.Write((short)type);
  			m_Stream.Fill(16);
  		}
  	}
  
  	public sealed class ScreenFadeOut : ScreenEffect
  	{
  		public static readonly Packet Instance = SetStatic(new ScreenFadeOut());
  
  		public ScreenFadeOut()
  			: base(ScreenEffectType.FadeOut)
  		{ }
  	}
  
  	public sealed class ScreenFadeIn : ScreenEffect
  	{
  		public static readonly Packet Instance = SetStatic(new ScreenFadeIn());
  
  		public ScreenFadeIn()
  			: base(ScreenEffectType.FadeIn)
  		{ }
  	}
  
  	public sealed class ScreenFadeInOut : ScreenEffect
  	{
  		public static readonly Packet Instance = SetStatic(new ScreenFadeInOut());
  
  		public ScreenFadeInOut()
  			: base(ScreenEffectType.FadeInOut)
  		{ }
  	}
  
  	public sealed class ScreenLightFlash : ScreenEffect
  	{
  		public static readonly Packet Instance = SetStatic(new ScreenLightFlash());
  
  		public ScreenLightFlash()
  			: base(ScreenEffectType.LightFlash)
  		{ }
  	}
  
  	public sealed class ScreenDarkFlash : ScreenEffect
  	{
  		public static readonly Packet Instance = SetStatic(new ScreenDarkFlash());
  
  		public ScreenDarkFlash()
  			: base(ScreenEffectType.DarkFlash)
  		{ }
  	}
  
  	public enum DeleteResultType
  	{
  		PasswordInvalid,
  		CharNotExist,
  		CharBeingPlayed,
  		CharTooYoung,
  		CharQueued,
  		BadRequest
  	}
  
  	public sealed class DeleteResult : Packet
  	{
  		public DeleteResult(DeleteResultType res)
  			: base(0x85, 2)
  		{
  			m_Stream.Write((byte)res);
  		}
  	}
  
  	/*public sealed class MovingEffect : Packet
  {
  public MovingEffect( IEntity from, IEntity to, int itemID, int speed, int duration, bool fixedDirection, bool turn, int hue, int renderMode ) : base( 0xC0, 36 )
  {
  m_Stream.Write( (byte) 0x00 );
  m_Stream.Write( (int) from.Serial );
  m_Stream.Write( (int) to.Serial );
  m_Stream.Write( (short) itemID );
  m_Stream.Write( (short) from.Location.m_X );
  m_Stream.Write( (short) from.Location.m_Y );
  m_Stream.Write( (sbyte) from.Location.m_Z );
  m_Stream.Write( (short) to.Location.m_X );
  m_Stream.Write( (short) to.Location.m_Y );
  m_Stream.Write( (sbyte) to.Location.m_Z );
  m_Stream.Write( (byte) speed );
  m_Stream.Write( (byte) duration );
  m_Stream.Write( (byte) 0 );
  m_Stream.Write( (byte) 0 );
  m_Stream.Write( (bool) fixedDirection );
  m_Stream.Write( (bool) turn );
  m_Stream.Write( (int) hue );
  m_Stream.Write( (int) renderMode );
  }
  }*/
  
  	/*public sealed class LocationEffect : Packet
  {
  public LocationEffect( IPoint3D p, int itemID, int duration, int hue, int renderMode ) : base( 0xC0, 36 )
  {
  m_Stream.Write( (byte) 0x02 );
  m_Stream.Write( (int) Serial.Zero );
  m_Stream.Write( (int) Serial.Zero );
  m_Stream.Write( (short) itemID );
  m_Stream.Write( (short) p.X );
  m_Stream.Write( (short) p.Y );
  m_Stream.Write( (sbyte) p.Z );
  m_Stream.Write( (short) p.X );
  m_Stream.Write( (short) p.Y );
  m_Stream.Write( (sbyte) p.Z );
  m_Stream.Write( (byte) 10 );
  m_Stream.Write( (byte) duration );
  m_Stream.Write( (byte) 0 );
  m_Stream.Write( (byte) 0 );
  m_Stream.Write( (byte) 1 );
  m_Stream.Write( (byte) 0 );
  m_Stream.Write( (int) hue );
  m_Stream.Write( (int) renderMode );
  }
  }*/
  
  	public sealed class BoltEffect : Packet
  	{
  		public BoltEffect(IEntity target, int hue)
  			: base(0xC0, 36)
  		{
  			m_Stream.Write((byte)0x01); // type
  			m_Stream.Write(target.Serial);
  			m_Stream.Write(Serial.Zero);
  			m_Stream.Write((short)0); // itemID
  			m_Stream.Write((short)target.X);
  			m_Stream.Write((short)target.Y);
  			m_Stream.Write((sbyte)target.Z);
  			m_Stream.Write((short)target.X);
  			m_Stream.Write((short)target.Y);
  			m_Stream.Write((sbyte)target.Z);
  			m_Stream.Write((byte)0); // speed
  			m_Stream.Write((byte)0); // duration
  			m_Stream.Write((short)0); // unk
  			m_Stream.Write(false); // fixed direction
  			m_Stream.Write(false); // explode
  			m_Stream.Write(hue);
  			m_Stream.Write(0); // render mode
  		}
  	}
  
      public sealed class BoltEffectNew : Packet
      {
          public BoltEffectNew(IEntity target)
              : base(0x70, 28)
          {
              m_Stream.Write((byte)0x01); // type
              m_Stream.Write(target.Serial);
              m_Stream.Write(Serial.Zero);
              m_Stream.Write((short)0); // itemID
              m_Stream.Write((short)target.X);
              m_Stream.Write((short)target.Y);
              m_Stream.Write((sbyte)target.Z);
              m_Stream.Write((short)target.X);
              m_Stream.Write((short)target.Y);
              m_Stream.Write((sbyte)target.Z);
              m_Stream.Write((byte)0); // speed
              m_Stream.Write((byte)0); // duration
              m_Stream.Write((short)0); // unk
              m_Stream.Write(false); // fixed direction
              m_Stream.Write(false); // explode
          }
      }
  
  	public sealed class DisplaySpellbook : Packet
  	{
  		public DisplaySpellbook(Item book)
  			: base(0x24, 7)
  		{
  			m_Stream.Write(book.Serial);
  			m_Stream.Write((short)-1);
  		}
  	}
  
  	public sealed class DisplaySpellbookHS : Packet
  	{
  		public DisplaySpellbookHS(Item book)
  			: base(0x24, 9)
  		{
  			m_Stream.Write(book.Serial);
  			m_Stream.Write((short)-1);
  			m_Stream.Write((short)0x7D);
  		}
  	}
  
  	public sealed class NewSpellbookContent : Packet
  	{
  		public NewSpellbookContent(Item item, int graphic, int offset, ulong content)
  			: base(0xBF)
  		{
  			EnsureCapacity(23);
  
  			m_Stream.Write((short)0x1B);
  			m_Stream.Write((short)0x01);
  
  			m_Stream.Write(item.Serial);
  			m_Stream.Write((short)graphic);
  			m_Stream.Write((short)offset);
  
  			for (int i = 0; i < 8; ++i)
  			{
  				m_Stream.Write((byte)(content >> (i * 8)));
  			}
  		}
  	}
  
  	public sealed class SpellbookContent : Packet
  	{
  		public SpellbookContent(int count, int offset, ulong content, Item item)
  			: base(0x3C)
  		{
  			EnsureCapacity(5 + (count * 19));
  
  			int written = 0;
  
  			m_Stream.Write((ushort)0);
  
  			ulong mask = 1;
  
  			for (int i = 0; i < 64; ++i, mask <<= 1)
  			{
  				if ((content & mask) != 0)
  				{
  					m_Stream.Write((0x7FFFFFFF - i));
  					m_Stream.Write((ushort)0);
  					m_Stream.Write((byte)0);
  					m_Stream.Write((ushort)(i + offset));
  					m_Stream.Write((short)0);
  					m_Stream.Write((short)0);
  					m_Stream.Write(item.Serial);
  					m_Stream.Write((short)0);
  
  					++written;
  				}
  			}
  
  			m_Stream.Seek(3, SeekOrigin.Begin);
  			m_Stream.Write((ushort)written);
  		}
  	}
  
  	public sealed class SpellbookContent6017 : Packet
  	{
  		public SpellbookContent6017(int count, int offset, ulong content, Item item)
  			: base(0x3C)
  		{
  			EnsureCapacity(5 + (count * 20));
  
  			int written = 0;
  
  			m_Stream.Write((ushort)0);
  
  			ulong mask = 1;
  
  			for (int i = 0; i < 64; ++i, mask <<= 1)
  			{
  				if ((content & mask) != 0)
  				{
  					m_Stream.Write((0x7FFFFFFF - i));
  					m_Stream.Write((ushort)0);
  					m_Stream.Write((byte)0);
  					m_Stream.Write((ushort)(i + offset));
  					m_Stream.Write((short)0);
  					m_Stream.Write((short)0);
  					m_Stream.Write((byte)0); // Grid Location?
  					m_Stream.Write(item.Serial);
  					m_Stream.Write((short)0);
  
  					++written;
  				}
  			}
  
  			m_Stream.Seek(3, SeekOrigin.Begin);
  			m_Stream.Write((ushort)written);
  		}
  	}
  
  	public sealed class ContainerDisplay : Packet
  	{
  		public ContainerDisplay(Container c)
  			: base(0x24, 7)
  		{
  			m_Stream.Write(c.Serial);
  			m_Stream.Write((short)c.GumpID);
  		}
  	}
  
  	public sealed class ContainerDisplayHS : Packet
  	{
  		public ContainerDisplayHS(Container c)
  			: base(0x24, 9)
  		{
  			m_Stream.Write(c.Serial);
  			m_Stream.Write((short)c.GumpID);
              m_Stream.Write((short)0x7D);
          }
  	}
  
  	public sealed class ContainerContentUpdate : Packet
  	{
  		public ContainerContentUpdate(Item item)
  			: base(0x25, 20)
  		{
  			Serial parentSerial;
  
  			if (item.Parent is Item)
  			{
  				parentSerial = ((Item)item.Parent).Serial;
  			}
  			else
  			{
  				Console.WriteLine("Warning: ContainerContentUpdate on item with !(parent is Item)");
  				parentSerial = Serial.Zero;
  			}
  
  			m_Stream.Write(item.Serial);
  			m_Stream.Write((ushort)item.ItemID);
  			m_Stream.Write((byte)0); // signed, itemID offset
  			m_Stream.Write((ushort)item.Amount);
  			m_Stream.Write((short)item.X);
  			m_Stream.Write((short)item.Y);
              m_Stream.Write((byte)item.GridLocation);
              m_Stream.Write(parentSerial);
  			m_Stream.Write((ushort)(item.QuestItem ? item.QuestItemHue : item.Hue));
  		}
  	}
  
  	public sealed class ContainerContentUpdate6017 : Packet
  	{
  		public ContainerContentUpdate6017(Item item)
  			: base(0x25, 21)
  		{
  			Serial parentSerial;
  
  			if (item.Parent is Item)
  			{
  				parentSerial = ((Item)item.Parent).Serial;
  			}
  			else
  			{
  				Console.WriteLine("Warning: ContainerContentUpdate on item with !(parent is Item)");
  				parentSerial = Serial.Zero;
  			}
  
  			m_Stream.Write(item.Serial);
  			m_Stream.Write((ushort)item.ItemID);
  			m_Stream.Write((byte)0); // signed, itemID offset
  			m_Stream.Write((ushort)item.Amount);
  			m_Stream.Write((short)item.X);
  			m_Stream.Write((short)item.Y);
              m_Stream.Write((byte)item.GridLocation);
              m_Stream.Write(parentSerial);
  			m_Stream.Write((ushort)(item.QuestItem ? item.QuestItemHue : item.Hue));
  		}
  	}
  
  	public sealed class ContainerContent : Packet
  	{
  		public ContainerContent(Mobile beholder, Item beheld)
  			: base(0x3C)
  		{
  			var items = beheld.Items;
  			int count = items.Count;
  
  			EnsureCapacity(5 + (count * 19));
  
  			long pos = m_Stream.Position;
  
  			int written = 0;
  
  			m_Stream.Write((ushort)0);
  
  			for (int i = 0; i < count; ++i)
  			{
  				Item child = items[i];
  
  				if (!child.Deleted && beholder.CanSee(child))
  				{
  
gt:                     if (child.GridLocation == 0xFF)