/// <summary> /// The read. /// </summary> /// <param name="client"> /// </param> /// <param name="packet"> /// </param> public static void Read(Client client, byte[] packet) { // TODO: Fix this mess. ushort data_length = BitConverter.ToUInt16(new[] { packet[3], packet[2] }, 0); byte[] sender_ID = BitConverter.GetBytes(client.Character.characterId); Array.Reverse(sender_ID); MemoryStream m_stream = new MemoryStream(); m_stream.Write(packet, 0, 9); m_stream.Write(sender_ID, 0, 4); m_stream.Write(packet, 9, packet.Length - 9); m_stream.Capacity = (int)m_stream.Length; byte[] message = m_stream.GetBuffer(); byte[] new_length = BitConverter.GetBytes(message.Length - 4); message[2] = new_length[1]; message[3] = new_length[0]; m_stream.Close(); m_stream.Dispose(); foreach (Client m_client in client.Server.Clients) { if (!m_client.KnownClients.Contains(client.Character.characterId)) { byte[] pname = PlayerName.New(client, client.Character.characterId); m_client.Send(pname); m_client.KnownClients.Add(client.Character.characterId); } m_client.Send(message); } PacketReader reader = new PacketReader(ref packet); reader.ReadUInt16(); reader.ReadUInt16(); reader.ReadUInt16(); reader.ReadUInt16(); reader.ReadByte(); string text = reader.ReadString(); string channelName = ChatChannels.GetChannel(packet).Name; ChatLogger.WriteString(channelName, text, client.Character.characterName); }
private static void OnHuedEffect(PacketReader p, PacketHandlerEventArgs args) { byte type = p.ReadByte(); Serial src = p.ReadUInt32(); Serial dest = p.ReadUInt32(); ItemID itemID = p.ReadUInt16(); p.Seek(10, SeekOrigin.Current); byte speed = p.ReadByte(); byte count = p.ReadByte(); p.ReadUInt32(); uint hue = p.ReadUInt32(); uint mode = p.ReadUInt32(); Handle(huedEffect, args, type, src, dest, itemID, speed, count, hue, mode); }
private static void EquipmentUpdate( PacketReader p ) { Serial serial = p.ReadUInt32(); Item i = World.FindItem( serial ); if ( i == null ) { World.AddItem( i=new Item( serial ) ); Item.UpdateContainers(); } if ( World.Player != null && World.Player.Holding == i ) World.Player.Holding = null; ushort iid = p.ReadUInt16(); i.ItemID = (ushort)(iid + p.ReadSByte()); // signed, itemID offset i.Layer = p.ReadByte(); Serial ser = p.ReadUInt32();// cont must be set after hue (for counters) i.Hue = p.ReadUInt16(); i.Container = ser; }
private static void WorldItem( PacketReader p ) { Item item; uint serial = p.ReadUInt32(); item = World.FindItem( serial&0x7FFFFFFF ); if ( item == null ) { World.AddItem( item=new Item( serial&0x7FFFFFFF ) ); } item.Container = null; if ( World.Player.Holding == item ) World.Player.Holding = null; ushort itemID = p.ReadUInt16(); item.ItemID = (ushort)(itemID&0x7FFF); if ( (serial & 0x80000000) != 0 ) item.Amount = p.ReadUInt16(); else item.Amount = 0; if ( (itemID & 0x8000) != 0 ) item.ItemID = (ushort)(item.ItemID + p.ReadSByte()); ushort x = p.ReadUInt16(); ushort y = p.ReadUInt16(); if ( (x & 0x8000) != 0 ) item.Direction = p.ReadByte(); else item.Direction = 0; short z = p.ReadSByte(); item.Position = new Point3D( x&0x3FFF, y&0x3FFF, z ); if ( ( y & 0x8000 ) != 0 ) item.Hue = p.ReadUInt16(); else item.Hue = 0; byte flags = 0; if ( ( y & 0x4000 ) != 0 ) flags = p.ReadByte(); item.ProcessPacketFlags( flags ); Item.UpdateContainers(); }
private static void ClientGumpResponse( PacketReader p, PacketHandlerEventArgs args ) { if ( World.Player == null ) return; Serial ser = p.ReadUInt32(); uint tid = p.ReadUInt32(); int bid = p.ReadInt32(); World.Player.HasGump = false; int sc = p.ReadInt32(); if ( sc < 0 || sc > 2000 ) return; int[] switches = new int[sc]; for(int i=0;i<sc;i++) switches[i] = p.ReadInt32(); int ec = p.ReadInt32(); if ( ec < 0 || ec > 2000 ) return; GumpTextEntry[] entries = new GumpTextEntry[ec]; for(int i=0;i<ec;i++) { ushort id = p.ReadUInt16(); ushort len = p.ReadUInt16(); if ( len >= 240 ) return; string text = p.ReadUnicodeStringSafe( len ); entries[i] = new GumpTextEntry( id, text ); } if ( Macros.MacroManager.AcceptActions ) MacroManager.Action( new GumpResponseAction( bid, switches, entries ) ); }
private static void WorldItem( PacketReader p, PacketHandlerEventArgs args ) { Item item; uint serial = p.ReadUInt32(); item = World.FindItem( serial&0x7FFFFFFF ); bool isNew = false; if ( item == null ) { World.AddItem( item=new Item( serial&0x7FFFFFFF ) ); isNew = true; } else { item.CancelRemove(); } if ( !DragDropManager.EndHolding( serial ) ) return; item.Container = null; Counter.Uncount( item ); ushort itemID = p.ReadUInt16(); item.ItemID = (ushort)(itemID&0x7FFF); if ( (serial & 0x80000000) != 0 ) item.Amount = p.ReadUInt16(); else item.Amount = 1; if ( (itemID & 0x8000) != 0 ) item.ItemID = (ushort)(item.ItemID + p.ReadSByte()); ushort x = p.ReadUInt16(); ushort y = p.ReadUInt16(); if ( (x & 0x8000) != 0 ) item.Direction = p.ReadByte(); else item.Direction = 0; short z = p.ReadSByte(); item.Position = new Point3D( x&0x7FFF, y&0x3FFF, z ); if ( ( y & 0x8000 ) != 0 ) item.Hue = p.ReadUInt16(); else item.Hue = 0; byte flags = 0; if ( ( y & 0x4000 ) != 0 ) flags = p.ReadByte(); item.ProcessPacketFlags( flags ); if ( isNew && World.Player != null ) { if ( item.ItemID == 0x2006 )// corpse itemid = 0x2006 { if ( Config.GetBool( "ShowCorpseNames" ) ) ClientCommunication.SendToServer( new SingleClick( item ) ); if ( Config.GetBool( "AutoOpenCorpses" ) && Utility.InRange( item.Position, World.Player.Position, Config.GetInt( "CorpseRange" ) ) && World.Player != null && World.Player.Visible ) PlayerData.DoubleClick( item ) ; } else if ( item.IsMulti ) { ClientCommunication.PostAddMulti( item.ItemID, item.Position ); } else { ScavengerAgent s = ScavengerAgent.Instance; int dist = Utility.Distance( item.GetWorldPosition(), World.Player.Position ); if ( !World.Player.IsGhost && World.Player.Visible && dist <= 2 && s.Enabled && item.Movable ) s.Scavenge( item ); } } Item.UpdateContainers(); }
private static void Skills( PacketReader p, PacketHandlerEventArgs args ) { if ( World.Player == null || World.Player.Skills == null || Engine.MainWindow == null ) return; byte type = p.ReadByte(); switch ( type ) { case 0x02://list (with caps, 3.0.8 and up) { int i; while ( (i = p.ReadUInt16()) > 0 ) { if ( i>0 && i <= Skill.Count ) { Skill skill = World.Player.Skills[i-1]; if ( skill == null ) continue; skill.FixedValue = p.ReadUInt16(); skill.FixedBase = p.ReadUInt16(); skill.Lock = (LockType)p.ReadByte(); skill.FixedCap = p.ReadUInt16(); if ( !World.Player.SkillsSent ) skill.Delta = 0; ClientCommunication.PostSkillUpdate( i-1, skill.FixedBase ); } else { p.Seek( 7, SeekOrigin.Current ); } } World.Player.SkillsSent = true; Engine.MainWindow.RedrawSkills(); break; } case 0x00: // list (without caps, older clients) { int i; while ( (i = p.ReadUInt16()) > 0 ) { if ( i>0 && i <= Skill.Count ) { Skill skill = World.Player.Skills[i-1]; if ( skill == null ) continue; skill.FixedValue = p.ReadUInt16(); skill.FixedBase = p.ReadUInt16(); skill.Lock = (LockType)p.ReadByte(); skill.FixedCap = 100;//p.ReadUInt16(); if ( !World.Player.SkillsSent ) skill.Delta = 0; ClientCommunication.PostSkillUpdate( i-1, skill.FixedBase ); } else { p.Seek( 5, SeekOrigin.Current ); } } World.Player.SkillsSent = true; Engine.MainWindow.RedrawSkills(); break; } case 0xDF: //change (with cap, new clients) { int i = p.ReadUInt16(); if ( i >= 0 && i < Skill.Count ) { Skill skill = World.Player.Skills[i]; if ( skill == null ) break; ushort old = skill.FixedBase; skill.FixedValue = p.ReadUInt16(); skill.FixedBase = p.ReadUInt16(); skill.Lock = (LockType)p.ReadByte(); skill.FixedCap = p.ReadUInt16(); Engine.MainWindow.UpdateSkill( skill ); if ( Config.GetBool( "DisplaySkillChanges" ) && skill.FixedBase != old ) World.Player.SendMessage( MsgLevel.Force, LocString.SkillChanged, (SkillName)i, skill.Delta > 0 ? "+" : "", skill.Delta, skill.Value, skill.FixedBase - old > 0 ? "+" : "", ((double)( skill.FixedBase - old )) / 10.0 ); ClientCommunication.PostSkillUpdate( i, skill.FixedBase ); } break; } case 0xFF: //change (without cap, older clients) { int i = p.ReadUInt16(); if ( i >= 0 && i < Skill.Count ) { Skill skill = World.Player.Skills[i]; if ( skill == null ) break; ushort old = skill.FixedBase; skill.FixedValue = p.ReadUInt16(); skill.FixedBase = p.ReadUInt16(); skill.Lock = (LockType)p.ReadByte(); skill.FixedCap = 100; Engine.MainWindow.UpdateSkill( skill ); if ( Config.GetBool( "DisplaySkillChanges" ) && skill.FixedBase != old ) World.Player.SendMessage( MsgLevel.Force, LocString.SkillChanged, (SkillName)i, skill.Delta > 0 ? "+" : "", skill.Delta, skill.Value, ((double)( skill.FixedBase - old )) / 10.0, skill.FixedBase - old > 0 ? "+" : "" ); ClientCommunication.PostSkillUpdate( i, skill.FixedBase ); } break; } } }
private static void ServerList( PacketReader p, PacketHandlerEventArgs args ) { p.ReadByte(); //unknown ushort numServers = p.ReadUInt16(); for ( int i = 0; i < numServers; ++i ) { ushort num = p.ReadUInt16(); World.Servers[num] = p.ReadString( 32 ); p.ReadByte(); // full % p.ReadSByte(); // time zone p.ReadUInt32(); // ip } }
private static void SendMenu( PacketReader p, PacketHandlerEventArgs args ) { if ( World.Player == null ) return; World.Player.CurrentMenuS = p.ReadUInt32(); World.Player.CurrentMenuI = p.ReadUInt16(); World.Player.HasMenu = true; if ( MacroManager.AcceptActions && MacroManager.Action( new WaitForMenuAction( World.Player.CurrentMenuI ) ) ) args.Block = true; }
private static void PlayServer( PacketReader p, PacketHandlerEventArgs args ) { ushort index = p.ReadUInt16(); World.ShardName = World.Servers[index] as string; if ( World.ShardName == null ) World.ShardName = "[Unknown]"; }
private static void Features( PacketReader p, PacketHandlerEventArgs args ) { if ( World.Player != null ) World.Player.Features = p.ReadUInt16(); }
// Transfers raw incoming data into the security object. Call TransferIncoming to // obtain a list of ready to process packets. public void Recv(TransferBuffer raw_buffer) { List<TransferBuffer> incoming_buffers_tmp = new List<TransferBuffer>(); lock (m_class_lock) { int length = raw_buffer.Size - raw_buffer.Offset; int index = 0; while (length > 0) { int max_length = length; int calc_length = m_recv_buffer.Buffer.Length - m_recv_buffer.Size; if (max_length > calc_length) { max_length = calc_length; } length -= max_length; Buffer.BlockCopy(raw_buffer.Buffer, raw_buffer.Offset + index, m_recv_buffer.Buffer, m_recv_buffer.Size, max_length); m_recv_buffer.Size += max_length; index += max_length; // Loop while we have data to process while (m_recv_buffer.Size > 0) { // If we do not have a current packet object, try to allocate one. if (m_current_buffer == null) { // We need at least two bytes to allocate a packet. if (m_recv_buffer.Size < 2) { break; } // Calculate the packet size. int packet_size = m_recv_buffer.Buffer[1] << 8 | m_recv_buffer.Buffer[0]; // Check to see if this packet is encrypted. if ((packet_size & 0x8000) > 0) { // If so, calculate the total payload size. packet_size &= 0x7FFF; // Mask off the encryption. if (m_security_flags.blowfish == 1) { packet_size = 2 + m_blowfish.GetOutputLength(packet_size + 4); } else { packet_size += 6; } } else { // The packet is unencrypted. The final size is simply // header size + payload size. packet_size += 6; } // Allocate the final buffer the packet will be written to m_current_buffer = new TransferBuffer(packet_size, 0, packet_size); } // Calculate how many bytes are left to receive in the packet. int max_copy_count = m_current_buffer.Size - m_current_buffer.Offset; // If we need more bytes than we currently have, update the size. if (max_copy_count > m_recv_buffer.Size) { max_copy_count = m_recv_buffer.Size; } // Copy the buffer data to the packet buffer Buffer.BlockCopy(m_recv_buffer.Buffer, 0, m_current_buffer.Buffer, m_current_buffer.Offset, max_copy_count); // Update how many bytes we now have m_current_buffer.Offset += max_copy_count; m_recv_buffer.Size -= max_copy_count; // If there is data remaining in the buffer, copy it over the data // we just removed (sliding buffer). if (m_recv_buffer.Size > 0) { Buffer.BlockCopy(m_recv_buffer.Buffer, max_copy_count, m_recv_buffer.Buffer, 0, m_recv_buffer.Size); } // Check to see if the current packet is now complete. if (m_current_buffer.Size == m_current_buffer.Offset) { // If so, dispatch it to the manager class for processing by the system. m_current_buffer.Offset = 0; incoming_buffers_tmp.Add(m_current_buffer); // Set the current packet to null so we can process the next packet // in the stream. m_current_buffer = null; } else { // Otherwise, we are done with this loop, since we need more // data for the current packet. break; } } } if (incoming_buffers_tmp.Count > 0) { foreach (TransferBuffer buffer in incoming_buffers_tmp) { bool packet_encrypted = false; int packet_size = buffer.Buffer[1] << 8 | buffer.Buffer[0]; if ((packet_size & 0x8000) > 0) { if (m_security_flags.blowfish == 1) { packet_size &= 0x7FFF; packet_encrypted = true; } else { packet_size &= 0x7FFF; } } if (packet_encrypted) { byte[] decrypted = m_blowfish.Decode(buffer.Buffer, 2, buffer.Size - 2); byte[] new_buffer = new byte[6 + packet_size]; Buffer.BlockCopy(BitConverter.GetBytes((ushort)packet_size), 0, new_buffer, 0, 2); Buffer.BlockCopy(decrypted, 0, new_buffer, 2, 4 + packet_size); buffer.Buffer = null; buffer.Buffer = new_buffer; } PacketReader packet_data = new PacketReader(buffer.Buffer); packet_size = packet_data.ReadUInt16(); ushort packet_opcode = packet_data.ReadUInt16(); byte packet_security_count = packet_data.ReadByte(); byte packet_security_crc = packet_data.ReadByte(); // Client object whose bytes the server might need to verify if (m_client_security) { if (m_security_flags.security_bytes == 1) { byte expected_count = GenerateCountByte(true); if (packet_security_count != expected_count) { //throw (new Exception("[SecurityAPI::Recv] Count byte mismatch on {packet_opcode.ToString("X4")}.")); StaticLogger.Instance.Warn($"[SecurityAPI::Recv] Count byte mismatch on {packet_opcode.ToString("X4")}. (Expected: {expected_count}, Packet: {packet_security_count})"); } if (packet_encrypted || (m_security_flags.security_bytes == 1 && m_security_flags.blowfish == 0)) { if (packet_encrypted || m_enc_opcodes.Contains(packet_opcode)) { packet_size |= 0x8000; Buffer.BlockCopy(BitConverter.GetBytes((ushort)packet_size), 0, buffer.Buffer, 0, 2); } } buffer.Buffer[5] = 0; byte expected_crc = GenerateCheckByte(buffer.Buffer); if (packet_security_crc != expected_crc) { //throw (new Exception("[SecurityAPI::Recv] CRC byte mismatch.")); StaticLogger.Instance.Warn($"[SecurityAPI::Recv] CRC byte mismatch on {packet_opcode.ToString("X4")}. (Expected: {expected_crc}, Packet: {packet_security_crc})"); } buffer.Buffer[4] = 0; if (packet_encrypted || (m_security_flags.security_bytes == 1 && m_security_flags.blowfish == 0)) { if (packet_encrypted || m_enc_opcodes.Contains(packet_opcode)) { packet_size &= 0x7FFF; Buffer.BlockCopy(BitConverter.GetBytes((ushort)packet_size), 0, buffer.Buffer, 0, 2); } } } } if (packet_opcode == 0x5000 || packet_opcode == 0x9000) // New logic processing! { Handshake(packet_opcode, packet_data, packet_encrypted); // Pass the handshake packets to the user so they can at least see them. // They do not need to actually do anything with them. This was added to // help debugging and make output logs complete. Packet packet = new Packet(packet_opcode, packet_encrypted, false, buffer.Buffer, 6, packet_size); packet.Lock(); m_incoming_packets.Add(packet); } else { if (m_client_security) { // Make sure the client accepted the security system first if (!m_accepted_handshake) { throw (new Exception("[SecurityAPI::Recv] The client has not accepted the handshake.")); } } if (packet_opcode == 0x600D) // Auto process massive messages for the user { byte mode = packet_data.ReadByte(); if (mode == 1) { m_massive_count = packet_data.ReadUInt16(); ushort contained_packet_opcode = packet_data.ReadUInt16(); m_massive_packet = new Packet(contained_packet_opcode, packet_encrypted, true); } else { if (m_massive_packet == null) { throw (new Exception("[SecurityAPI::Recv] A malformed 0x600D packet was received.")); } m_massive_packet.WriteByteArray(packet_data.ReadBytes(packet_size - 1)); m_massive_count--; if (m_massive_count == 0) { m_massive_packet.Lock(); m_incoming_packets.Add(m_massive_packet); m_massive_packet = null; } } } else { Packet packet = new Packet(packet_opcode, packet_encrypted, false, buffer.Buffer, 6, packet_size); packet.Lock(); m_incoming_packets.Add(packet); } } } } } }
private static void LiftRequest(PacketReader p, PacketHandlerEventArgs args) { Serial serial = p.ReadUInt32(); if (items.ContainsKey(serial)) { lifting = p.ReadUInt16(); args.Block = true; WorldEx.SendToClient(new RemoveObject(serial)); } else args.Block = PacketHandler.ProcessViewers(liftRequest, p); }
internal static PSOObject FromPacketBin(byte[] v) { PacketReader reader = new PacketReader(v); PSOObject obj = new PSOObject(); reader.ReadStruct<PacketHeader>(); //Skip over header obj.Header = reader.ReadStruct<ObjectHeader>(); obj.Position = reader.ReadEntityPosition(); reader.ReadUInt16(); // Seek 2 obj.Name = reader.ReadFixedLengthAscii(0x34); obj.ThingFlag = reader.ReadUInt32(); uint thingCount = reader.ReadUInt32(); obj.Things = new PSOObjectThing[thingCount]; for (int i = 0; i < thingCount; i++) { obj.Things[i] = reader.ReadStruct<PSOObjectThing>(); } return obj; }
private static void ExtendedPacket( PacketReader p ) { ushort type = p.ReadUInt16(); switch ( type ) { case 0x04: // close gump { // int serial, int tid World.Player.HasGump = false; break; } case 0x08: // map change { if ( World.Player != null ) World.Player.Map = p.ReadByte(); break; } case 0x10: // object property list info { //args.Block = true; //ClientCommunication.SendToServer( new OPLInfoPacket( p.ReadUInt32(), p.ReadInt32() ) ); break; } case 0x18: // map patches { int count = p.ReadInt32() * 2; for(int i=0;i<count;i++) World.Player.MapPatches[i] = p.ReadInt32(); break; } case 0x19: // stat locks { if ( p.ReadByte() == 0x02 ) { Mobile m = World.FindMobile( p.ReadUInt32() ); if ( World.Player == m && m != null ) { p.ReadByte();// 0? byte locks = p.ReadByte(); World.Player.StrLock = (LockType)((locks>>4) & 3); World.Player.DexLock = (LockType)((locks>>2) & 3); World.Player.IntLock = (LockType)(locks & 3); } } break; } } }
private static void MovementRej( PacketReader p, PacketHandlerEventArgs args ) { if ( World.Player != null ) { byte seq = p.ReadByte(); int x = p.ReadUInt16(); int y = p.ReadUInt16(); Direction dir = (Direction)p.ReadByte(); sbyte z = p.ReadSByte(); if ( WalkAction.IsMacroWalk( seq ) ) args.Block = true; World.Player.MoveRej( seq, dir, new Point3D( x, y, z ) ); } }
private static void NewMobileStatus( PacketReader p, PacketHandlerEventArgs args ) { Mobile m = World.FindMobile( (Serial)p.ReadUInt32() ); if ( m == null ) return; UseNewStatus = true; // 00 01 p.ReadUInt16(); // 00 01 Poison // 00 02 Yellow Health Bar ushort id = p.ReadUInt16(); // 00 Off // 01 On // For Poison: Poison Level + 1 byte flag = p.ReadByte(); if ( id == 1 ) { bool wasPoisoned = m.Poisoned; m.Poisoned = ( flag != 0 ); if ( m == World.Player && wasPoisoned != m.Poisoned ) ClientCommunication.RequestTitlebarUpdate(); } }
private static void HitsUpdate( PacketReader p, PacketHandlerEventArgs args ) { Mobile m = World.FindMobile( p.ReadUInt32() ); if ( m != null ) { int oldPercent = (int)(m.Hits*100 / (m.HitsMax == 0 ? (ushort)1 : m.HitsMax)); m.HitsMax = p.ReadUInt16(); m.Hits = p.ReadUInt16(); if ( m == World.Player ) { ClientCommunication.RequestTitlebarUpdate(); ClientCommunication.PostHitsUpdate(); } if ( ClientCommunication.AllowBit( FeatureBit.OverheadHealth ) && Config.GetBool( "ShowHealth" ) ) { int percent = (int)(m.Hits*100 / (m.HitsMax == 0 ? (ushort)1 : m.HitsMax)); // Limit to people who are on screen and check the previous value so we dont get spammed. if ( oldPercent != percent && World.Player != null && Utility.Distance( World.Player.Position, m.Position ) <= 12 ) { try { m.OverheadMessageFrom( HealthHues[((percent+5)/10)%HealthHues.Length], Language.Format( LocString.sStatsA1, m.Name ), Config.GetString( "HealthFmt" ), percent ); } catch { } } } } }
private static void SAWorldItem(PacketReader p, PacketHandlerEventArgs args) { /* New World Item Packet PacketID: 0xF3 PacketLen: 24 Format: BYTE - 0xF3 packetId WORD - 0x01 BYTE - ArtDataID: 0x00 if the item uses art from TileData table, 0x02 if the item uses art from MultiData table) DWORD - item Serial WORD - item ID BYTE - item direction (same as old) WORD - amount WORD - amount WORD - X WORD - Y SBYTE - Z BYTE - item light WORD - item Hue BYTE - item flags (same as old packet) */ // Post-7.0.9.0 /* New World Item Packet PacketID: 0xF3 PacketLen: 26 Format: BYTE - 0xF3 packetId WORD - 0x01 BYTE - ArtDataID: 0x00 if the item uses art from TileData table, 0x02 if the item uses art from MultiData table) DWORD - item Serial WORD - item ID BYTE - item direction (same as old) WORD - amount WORD - amount WORD - X WORD - Y SBYTE - Z BYTE - item light WORD - item Hue BYTE - item flags (same as old packet) WORD ??? */ ushort _unk1 = p.ReadUInt16(); byte _artDataID = p.ReadByte(); Item item; uint serial = p.ReadUInt32(); item = World.FindItem(serial); bool isNew = false; if (item == null) { World.AddItem(item = new Item(serial)); isNew = true; } else { item.CancelRemove(); } if (!DragDropManager.EndHolding(serial)) return; item.Container = null; Counter.Uncount(item); ushort itemID = p.ReadUInt16(); item.ItemID = (ushort)( _artDataID == 0x02 ? itemID | 0x4000 : itemID ); item.Direction = p.ReadByte(); ushort _amount = p.ReadUInt16(); item.Amount = _amount = p.ReadUInt16(); ushort x = p.ReadUInt16(); ushort y = p.ReadUInt16(); short z = p.ReadSByte(); item.Position = new Point3D(x, y, z); byte _light = p.ReadByte(); item.Hue = p.ReadUInt16(); byte flags = p.ReadByte(); item.ProcessPacketFlags(flags); if (Engine.UsePostHSChanges) { p.ReadUInt16(); } if (isNew && World.Player != null) { if (item.ItemID == 0x2006)// corpse itemid = 0x2006 { if (Config.GetBool("ShowCorpseNames")) ClientCommunication.SendToServer(new SingleClick(item)); if (Config.GetBool("AutoOpenCorpses") && Utility.InRange(item.Position, World.Player.Position, Config.GetInt("CorpseRange")) && World.Player != null && World.Player.Visible) PlayerData.DoubleClick(item); } else if (item.IsMulti) { ClientCommunication.PostAddMulti(item.ItemID, item.Position); } else { ScavengerAgent s = ScavengerAgent.Instance; int dist = Utility.Distance(item.GetWorldPosition(), World.Player.Position); if (!World.Player.IsGhost && World.Player.Visible && dist <= 2 && s.Enabled && item.Movable) s.Scavenge(item); } } Item.UpdateContainers(); }
private static void HueResponse( PacketReader p, PacketHandlerEventArgs args ) { Serial serial = p.ReadUInt32(); ushort iid = p.ReadUInt16(); ushort hue = p .ReadUInt16(); if ( serial == Serial.MinusOne ) { if ( HueEntry.Callback != null ) HueEntry.Callback( hue ); args.Block = true; } }
private static void ServerChange( PacketReader p, PacketHandlerEventArgs args ) { if ( World.Player != null ) World.Player.Position = new Point3D( p.ReadUInt16(), p.ReadUInt16(), p.ReadInt16() ); }
private static void LiftRequest( PacketReader p, PacketHandlerEventArgs args ) { Serial serial = p.ReadUInt32(); ushort amount = p.ReadUInt16(); Item item = World.FindItem( serial ); ushort iid = 0; if ( item != null ) iid = item.ItemID.Value; if ( Config.GetBool( "QueueActions" ) ) { if ( item == null ) { World.AddItem( item = new Item( serial ) ); item.Amount = amount; } DragDropManager.Drag( item, amount, true ); //ClientCommunication.SendToClient( new RemoveObject( serial ) ); // remove the object from the client view args.Block = true; } if ( Macros.MacroManager.AcceptActions ) { MacroManager.Action( new LiftAction( serial, amount, iid ) ); //MacroManager.Action( new PauseAction( TimeSpan.FromMilliseconds( Config.GetInt( "ObjectDelay" ) ) ) ); } }
private static void SetSkillLock( PacketReader p, PacketHandlerEventArgs args ) { int i = p.ReadUInt16(); if ( i >= 0 && i < Skill.Count ) { Skill skill = World.Player.Skills[i]; skill.Lock = (LockType)p.ReadByte(); Engine.MainWindow.UpdateSkill( skill ); } }
private static void LoginConfirm( PacketReader p, PacketHandlerEventArgs args ) { World.Items.Clear(); World.Mobiles.Clear(); UseNewStatus = false; Serial serial = p.ReadUInt32(); PlayerData m = new PlayerData( serial ); m.Name = World.OrigPlayerName; Mobile test = World.FindMobile( serial ); if ( test != null ) test.Remove(); World.AddMobile( World.Player = m ); Config.LoadProfileFor( World.Player ); PlayerData.ExternalZ = false; p.ReadUInt32(); // always 0? m.Body = p.ReadUInt16(); m.Position = new Point3D( p.ReadUInt16(), p.ReadUInt16(), p.ReadInt16() ); m.Direction = (Direction)p.ReadByte(); m.Resync(); //ClientCommunication.SendToServer( new SkillsQuery( m ) ); //ClientCommunication.SendToServer( new StatusQuery( m ) ); ClientCommunication.RequestTitlebarUpdate(); ClientCommunication.PostLogin( (int)serial.Value ); Engine.MainWindow.UpdateTitle(); // update player name & shard name /* //the rest of the packet: (total length: 37) m_Stream.Write( (byte) 0 ); m_Stream.Write( (int) -1 ); m_Stream.Write( (short) 0 ); m_Stream.Write( (short) 0 ); m_Stream.Write( (short) (map==null?6144:map.Width) ); m_Stream.Write( (short) (map==null?4096:map.Height) ); Stream.Fill(); */ ClientCommunication.BeginCalibratePosition(); }
private static void StamUpdate( PacketReader p, PacketHandlerEventArgs args ) { Mobile m = World.FindMobile( p.ReadUInt32() ); if ( m != null ) { int oldPercent = (int)(m.Stam*100 / (m.StamMax == 0 ? (ushort)1 : m.StamMax)); m.StamMax = p.ReadUInt16(); m.Stam = p.ReadUInt16(); if ( m == World.Player ) { ClientCommunication.RequestTitlebarUpdate(); ClientCommunication.PostStamUpdate(); } if ( m != World.Player && ClientCommunication.AllowBit( FeatureBit.OverheadHealth ) && Config.GetBool( "ShowPartyStats" ) ) { int stamPercent = (int)(m.Stam*100 / (m.StamMax == 0 ? (ushort)1 : m.StamMax)); int manaPercent = (int)(m.Mana*100 / (m.ManaMax == 0 ? (ushort)1 : m.ManaMax)); // Limit to people who are on screen and check the previous value so we dont get spammed. if ( oldPercent != stamPercent && World.Player != null && Utility.Distance( World.Player.Position, m.Position ) <= 12 ) { try { m.OverheadMessageFrom( 0x63, Language.Format( LocString.sStatsA1, m.Name ), Config.GetString( "PartyStatFmt" ), manaPercent, stamPercent ); } catch { } } } } }
private static void MenuResponse( PacketReader pvSrc, PacketHandlerEventArgs args ) { if ( World.Player == null ) return; uint serial = pvSrc.ReadUInt32(); ushort menuID = pvSrc.ReadUInt16(); ushort index = pvSrc.ReadUInt16(); ushort itemID = pvSrc.ReadUInt16(); ushort hue = pvSrc.ReadUInt16(); World.Player.HasMenu = false; if ( MacroManager.AcceptActions ) MacroManager.Action( new MenuResponseAction( index, itemID, hue ) ); }
private static void ClientEncodedPacket( PacketReader p, PacketHandlerEventArgs args ) { Serial serial = p.ReadUInt32(); ushort packetID = p.ReadUInt16(); switch ( packetID ) { case 0x19: // set ability { int ability = 0; if ( p.ReadByte() == 0 ) ability = p.ReadInt32(); if ( ability >= 0 && ability < (int)AOSAbility.Invalid && Macros.MacroManager.AcceptActions ) MacroManager.Action( new SetAbilityAction( (AOSAbility)ability ) ); break; } } }
private static void MobileStatInfo( PacketReader pvSrc, PacketHandlerEventArgs args ) { Mobile m = World.FindMobile( pvSrc.ReadUInt32() ); if ( m == null ) return; PlayerData p = World.Player; m.HitsMax = pvSrc.ReadUInt16(); m.Hits = pvSrc.ReadUInt16(); m.ManaMax = pvSrc.ReadUInt16(); m.Mana = pvSrc.ReadUInt16(); m.StamMax = pvSrc.ReadUInt16(); m.Stam = pvSrc.ReadUInt16(); if ( m == World.Player ) { ClientCommunication.RequestTitlebarUpdate(); ClientCommunication.PostHitsUpdate(); ClientCommunication.PostStamUpdate(); ClientCommunication.PostManaUpdate(); } }
private static void ExtendedPacket( PacketReader p, PacketHandlerEventArgs args ) { ushort type = p.ReadUInt16(); switch ( type ) { case 0x04: // close gump { // int serial, int tid if ( World.Player != null ) World.Player.HasGump = false; break; } case 0x06: // party messages { OnPartyMessage( p, args ); break; } case 0x08: // map change { if ( World.Player != null ) World.Player.Map = p.ReadByte(); break; } case 0x14: // context menu { p.ReadInt16(); // 0x01 UOEntity ent = null; Serial ser = p.ReadUInt32(); if ( ser.IsMobile ) ent = World.FindMobile( ser ); else if ( ser.IsItem ) ent = World.FindItem( ser ); if ( ent != null ) { byte count = p.ReadByte(); try { ent.ContextMenu.Clear(); for(int i=0;i<count;i++) { ushort idx = p.ReadUInt16(); ushort num = p.ReadUInt16(); ushort flags = p.ReadUInt16(); ushort color = 0; if ( (flags&0x02) != 0 ) color = p.ReadUInt16(); ent.ContextMenu.Add( idx, num ); } } catch { } } break; } case 0x18: // map patches { if ( World.Player != null ) { int count = p.ReadInt32() * 2; try { World.Player.MapPatches = new int[count]; for(int i=0;i<count;i++) World.Player.MapPatches[i] = p.ReadInt32(); } catch { } } break; } case 0x19: // stat locks { if ( p.ReadByte() == 0x02 ) { Mobile m = World.FindMobile( p.ReadUInt32() ); if ( World.Player == m && m != null ) { p.ReadByte();// 0? byte locks = p.ReadByte(); World.Player.StrLock = (LockType)((locks>>4) & 3); World.Player.DexLock = (LockType)((locks>>2) & 3); World.Player.IntLock = (LockType)(locks & 3); } } break; } case 0x1D: // Custom House "General Info" { Item i = World.FindItem( p.ReadUInt32() ); if ( i != null ) i.HouseRevision = p.ReadInt32(); break; } } }
private static void MobileStatus( PacketReader p, PacketHandlerEventArgs args ) { Serial serial = p.ReadUInt32(); Mobile m = World.FindMobile( serial ); if ( m == null ) World.AddMobile( m = new Mobile( serial ) ); m.Name = p.ReadString( 30 ); m.Hits = p.ReadUInt16(); m.HitsMax = p.ReadUInt16(); p.ReadBoolean();//CanBeRenamed byte type = p.ReadByte(); if ( m == World.Player && type != 0x00 ) { PlayerData player = (PlayerData)m; player.Female = p.ReadBoolean(); int oStr = player.Str, oDex = player.Dex, oInt = player.Int; player.Str = p.ReadUInt16(); player.Dex = p.ReadUInt16(); player.Int = p.ReadUInt16(); if ( player.Str != oStr && oStr != 0 && Config.GetBool( "DisplaySkillChanges" ) ) World.Player.SendMessage( MsgLevel.Force, LocString.StrChanged, player.Str - oStr > 0 ? "+" : "", player.Str - oStr, player.Str ); if ( player.Dex != oDex && oDex != 0 && Config.GetBool( "DisplaySkillChanges" ) ) World.Player.SendMessage( MsgLevel.Force, LocString.DexChanged, player.Dex - oDex > 0 ? "+" : "", player.Dex - oDex, player.Dex ); if ( player.Int != oInt && oInt != 0 && Config.GetBool( "DisplaySkillChanges" ) ) World.Player.SendMessage( MsgLevel.Force, LocString.IntChanged, player.Int - oInt > 0 ? "+" : "", player.Int - oInt, player.Int ); player.Stam = p.ReadUInt16(); player.StamMax = p.ReadUInt16(); player.Mana = p.ReadUInt16(); player.ManaMax = p.ReadUInt16(); player.Gold = p.ReadUInt32(); player.AR = p.ReadUInt16(); // ar / physical resist player.Weight = p.ReadUInt16(); if ( type >= 0x03 ) { if ( type > 0x04 ) { player.MaxWeight = p.ReadUInt16(); p.ReadByte(); // race? } player.StatCap = p.ReadUInt16(); if ( type > 0x03 ) { player.Followers = p.ReadByte(); player.FollowersMax = p.ReadByte(); player.FireResistance = p.ReadInt16(); player.ColdResistance = p.ReadInt16(); player.PoisonResistance = p.ReadInt16(); player.EnergyResistance = p.ReadInt16(); player.Luck = p.ReadInt16(); player.DamageMin = p.ReadUInt16(); player.DamageMax = p.ReadUInt16(); player.Tithe = p.ReadInt32(); } } ClientCommunication.RequestTitlebarUpdate(); ClientCommunication.PostHitsUpdate(); ClientCommunication.PostStamUpdate(); ClientCommunication.PostManaUpdate(); Engine.MainWindow.UpdateTitle(); // update player name } }