Ejemplo n.º 1
0
        public override bool ParseMessage(NetworkMessage msg, PacketDestination destination, NetworkMessage outMsg)
        {
            if (msg.GetByte() != (byte)IncomingPacketType.TileUpdate)
            {
                return(false);
            }

            Destination = destination;
            Type        = IncomingPacketType.TileUpdate;
            outMsg.AddByte((byte)Type);

            Objects.Location pos = msg.GetLocation();
            outMsg.AddLocation(pos);

            ushort thingId = msg.PeekUInt16();

            if (thingId == 0xFF01)
            {
                outMsg.AddUInt16(msg.GetUInt16());
            }
            else
            {
                ParseTileDescription(msg, pos, outMsg);
                outMsg.AddUInt16(msg.GetUInt16());
            }

            return(true);
        }
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddOutfit(Default);

            msg.AddByte((byte)OutfitList.Count);

            foreach (AvalibleOutfit i in OutfitList)
            {
                msg.AddUInt16(i.Id);
                msg.AddString(i.Name);
                msg.AddByte(i.Addons);
            }

            if (Client.VersionNumber >= 870)
            {
                msg.AddByte((byte)MountList.Count);

                foreach (MountDescription i in MountList)
                {
                    msg.AddUInt16(i.Id);
                    msg.AddString(i.Name);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Adds the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="creatureId">The creature identifier.</param>
 /// <param name="speedInfo">The speed information.</param>
 public static void Add(NetworkMessage message, uint creatureId, SpeedInfo speedInfo)
 {
     message.AddPacketType(GamePacketType.CreatureChangeSpeed);
     message.AddUInt32(creatureId);
     message.AddUInt16(speedInfo.WalkSpeed);
     message.AddUInt16(speedInfo.BonusSpeed);
 }
Ejemplo n.º 4
0
        /// <summary>
        ///     Adds the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="creatureSpawn">The creature spawn.</param>
        /// <param name="channelId">The channel identifier.</param>
        /// <param name="type">The type.</param>
        /// <param name="statementId">The statement identifier.</param>
        /// <param name="text">The text.</param>
        public static void Add(NetworkMessage message, ICreatureSpawn creatureSpawn, ushort channelId, SpeechType type, uint statementId, string text)
        {
            message.AddPacketType(GamePacketType.CreatureSpeech);
            message.AddUInt32(statementId);

            if (creatureSpawn == null)
            {
                message.AddUInt32(0x00);
            }
            else if (type == SpeechType.ChannelR2)
            {
                message.AddUInt32(0x00);
                type = SpeechType.Red;
            }
            else
            {
                message.AddString(creatureSpawn.Creature.Name);

                // Add level only for characters
                if (creatureSpawn is ICharacterSpawn characterSpawn)
                {
                    message.AddUInt16((ushort)characterSpawn.Level.Current);
                }
                else
                {
                    message.AddUInt16(0x00);
                }
            }

            message.AddSpeechType(type);
            message.AddUInt16(channelId);
            message.AddString(text);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Adds the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="channels">The channels.</param>
        public static void Add(NetworkMessage message, ICollection <IChannel> channels)
        {
            message.AddPacketType(GamePacketType.ChannelsList);
            message.AddByte((byte)channels.Count);

            foreach (IChannel channel in channels)
            {
                switch (channel)
                {
                case IPrivateChannel privateChannel:
                    // TODO: WARNING! Casting CharacterSpawn.Id to UInt16 is BAD design. FIX ASAP!
                    message.AddUInt16((ushort)privateChannel.Owner.Id);
                    break;

                case IGuildChannel guildChannel:
                    message.AddUInt16(guildChannel.Guild.Id);
                    break;

                case IPartyChannel partyChannel:
                    message.AddUInt16(partyChannel.Party.Id);
                    break;

                case IPublicChannel publicChannel:
                    message.AddChannelType(publicChannel.Type);
                    break;

                default:
                    message.AddUInt16(channel.Id);
                    break;
                }
                message.AddString(channel.Name);
            }
        }
        public static NetworkMessage Create(byte OS, ushort Version,
                                            byte[] Signatures, byte[] XteaKey, string AccountName, string Password, bool OpenTibia)
        {
            NetworkMessage msg = new NetworkMessage(149);

            msg.AddByte(0x95);
            msg.AddByte(0x00);
            msg.Position += 4;
            msg.AddByte(0x01);
            msg.AddUInt16(OS);
            msg.AddUInt16(Version);
            msg.AddBytes(Signatures);
            msg.AddByte(0x0);
            msg.AddBytes(XteaKey);
            msg.AddString(AccountName);
            msg.AddString(Password);
            if (OpenTibia)
            {
                msg.RsaOTEncrypt(23);
            }
            else
            {
                msg.RsaCipEncrypt(23);
            }
            msg.AddAdler32();
            return(msg);
        }
Ejemplo n.º 7
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt32(Unknown);
            msg.AddString(SenderName);
            msg.AddUInt16(SenderLevel);

            SpeechTypeInfo info = Enums.GetSpeechTypeInfo(Client.GetVersionNumber(), SpeechType);

            msg.AddByte(info.Value);

            switch (info.AdditionalSpeechData)
            {
            case AdditionalSpeechData.Location:
                msg.AddLocation(Position);
                break;

            case AdditionalSpeechData.ChannelId:
                msg.AddUInt16((ushort)ChannelId);
                break;

            case AdditionalSpeechData.Time:
                msg.AddUInt32(Time);
                break;

            default:
                break;
            }

            msg.AddString(Message);
        }
Ejemplo n.º 8
0
        public override bool ParseMessage(NetworkMessage msg, PacketDestination destination, NetworkMessage outMsg)
        {
            if (msg.GetByte() != (byte)IncomingPacketType.TileUpdate)
                return false;

            Destination = destination;
            Type = IncomingPacketType.TileUpdate;
            outMsg.AddByte((byte)Type);

            Objects.Location pos = msg.GetLocation();
            outMsg.AddLocation(pos);

            ushort thingId = msg.PeekUInt16();

            if (thingId == 0xFF01)
            {
                outMsg.AddUInt16(msg.GetUInt16());
            }
            else
            {
                ParseTileDescription(msg, pos, outMsg);
                outMsg.AddUInt16(msg.GetUInt16());
            }

            return true;
        }
Ejemplo n.º 9
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt16(Health);
            msg.AddUInt16(MaxHealth);
            msg.AddUInt32(Capacity);

            if (Client.VersionNumber >= 870)
            {
                msg.AddUInt64(Experience);
            }
            else
            {
                msg.AddUInt32((uint)Experience);
            }

            msg.AddUInt16(Level);

            msg.AddByte(LevelPercent);

            msg.AddUInt16(Mana);
            msg.AddUInt16(MaxMana);

            msg.AddByte(MagicLevel);
            msg.AddByte(MagicLevelPercent);
            msg.AddByte(Soul);

            msg.AddUInt16(Stamina);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Adds the creature.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="characterSpawn">The character spawn.</param>
        /// <param name="creatureSpawn">The creature spawn.</param>
        /// <param name="known">if set to <c>true</c> [known].</param>
        /// <param name="removeKnown">The remove known.</param>
        public static void AddCreature(NetworkMessage message, ICharacterSpawn characterSpawn, ICreatureSpawn creatureSpawn, bool known, uint removeKnown)
        {
            // TODO: This method MUST be called "Add" for consistency
            if (known)
            {
                // TODO: MAGIC NUMBER DETECTED!
                message.AddUInt16(0x62); // known
                message.AddUInt32(creatureSpawn.Id);
            }
            else
            {
                // TODO: MAGIC NUMBER DETECTED!
                message.AddUInt16(0x61); // unknown
                message.AddUInt32(removeKnown);
                message.AddUInt32(creatureSpawn.Id);
                message.AddCreatureType(creatureSpawn.Creature.CreatureType);
                message.AddString(creatureSpawn.Creature.Name);
            }

            message.AddPercent(creatureSpawn.Health.ToPercent());
            message.AddDirection(creatureSpawn.Direction);
            message.AddAppearance(creatureSpawn.Outfit, creatureSpawn.Mount);
            message.AddByte(creatureSpawn.LightInfo.Level);
            message.AddByte(creatureSpawn.LightInfo.Color);
            message.AddUInt16(creatureSpawn.Speed.WalkSpeed);
            message.AddSkullType(creatureSpawn.Skull.Type);
            message.AddPartyShield(characterSpawn.GetPartyShield(creatureSpawn as CharacterSpawn));

            if (!known)
            {
                message.AddWarIcon(creatureSpawn.WarIcon);
            }

            CreatureType creatureType = creatureSpawn.Creature.CreatureType;

            if (creatureType == CreatureType.Monster && creatureSpawn is ISummon summon)
            {
                creatureType = summon.Master == characterSpawn ? CreatureType.SummonOwn : CreatureType.SummonOthers;
            }

            message.AddCreatureType(creatureType);
            message.AddSpeechBubble(creatureSpawn.Creature.SpeechBubble);

            // TODO: Implement marked/unmarked??
            message.AddByte(0xFF);

            // TODO: Implement helpers
            //if (otherPlayer)
            //{
            //    msg.add<uint16_t>(otherPlayer->getHelpers());
            //}
            //else
            //{
            // TODO: MAGIC NUMBER DETECTED!
            message.AddUInt16(0x00);
            //}
            message.AddBoolean(creatureSpawn is ISolidBlock);
        }
Ejemplo n.º 11
0
 public override void ToNetworkMessage(NetworkMessage msg)
 {
     msg.AddByte((byte)Type);
     msg.AddLocation(FromLocation);
     msg.AddUInt16(FromSpriteId);
     msg.AddByte(FromStackPosition);
     msg.AddLocation(ToLocation);
     msg.AddUInt16(ToSpriteId);
     msg.AddByte(ToStackPosition);
 }
Ejemplo n.º 12
0
 public override void ToNetworkMessage(NetworkMessage msg)
 {
     msg.AddByte((byte)Type);
     msg.AddLocation(FromLocation);
     msg.AddUInt16(FromSpriteId);
     msg.AddByte(FromStackPosition);
     msg.AddLocation(ToLocation);
     msg.AddUInt16(ToSpriteId);
     msg.AddByte(ToStackPosition);
 }
Ejemplo n.º 13
0
        /// <summary>
        ///     Adds the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="characterSpawn">The character spawn.</param>
        public static void Add(NetworkMessage message, ICharacterSpawn characterSpawn)
        {
            message.AddPacketType(GamePacketType.SelfStats);
            message.AddUInt16((ushort)characterSpawn.Health.Current);
            message.AddUInt16((ushort)characterSpawn.Health.Maximum);
            message.AddUInt32(characterSpawn.FreeCapacity);
            message.AddUInt32(characterSpawn.Capacity);
            message.AddUInt64(characterSpawn.Level.Experience);
            message.AddUInt16((ushort)characterSpawn.Level.Current);
            message.AddPercent(characterSpawn.Level.ToPercent());

            // TODO: Experience bonus
            message.AddDouble(0, 3);

            message.AddUInt16((ushort)characterSpawn.Mana.Current);
            message.AddUInt16((ushort)characterSpawn.Mana.Maximum);

            message.AddByte(characterSpawn.MagicLevel.Base);
            message.AddByte(characterSpawn.MagicLevel.Current);
            message.AddPercent(characterSpawn.MagicLevel.ToPercent());

            message.AddByte(characterSpawn.Soul);
            message.AddUInt16(characterSpawn.Stamina);

            // TODO: Improve protocol to provide BonusSpeed in this packet
            message.AddUInt16(characterSpawn.Speed.WalkSpeed);

            // TODO: var condition = characterSpawn.getCondition(ConditionType.CONDITION_REGENERATION);
            message.AddUInt16(/*(ushort)(condition != null ? condition.getTicks() / 1000 : */ 0x00 /*)*/);

            message.AddUInt16((ushort)(characterSpawn.OfflineTraining.Elapsed.Ticks / 60 / 1000));
        }
Ejemplo n.º 14
0
 /// <summary>
 ///     Adds the private channel.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="privateChannel">The private channel.</param>
 private static void AddPrivateChannel(NetworkMessage message, IPrivateChannel privateChannel)
 {
     message.AddUInt16((ushort)privateChannel.Owner.Id);
     AddUsers(message, privateChannel);
     message.AddUInt16((ushort)privateChannel.Invitations.Count);
     foreach (ICharacterSpawn invitation in privateChannel.Invitations)
     {
         message.AddString(invitation.Character.Name);
     }
     message.AddUInt16(0x00);
 }
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt32(WindowId);
            msg.AddUInt16(ItemId);
            msg.AddUInt16(MaxLength);
            msg.AddString(Text);
            msg.AddString(Author);
            msg.AddString(Date);
        }
Ejemplo n.º 16
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt32(WindowId);
            msg.AddUInt16(ItemId);
            msg.AddUInt16(MaxLength);
            msg.AddString(Text);
            msg.AddString(Author);
            msg.AddString(Date);
        }
Ejemplo n.º 17
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddLocation(Location);
            msg.AddByte(Stack);
            msg.AddUInt16(ThingId);

            if (ThingId == 0x0061 || ThingId == 0x0062)
            {
                if (ThingId == 0x0062)
                {
                    msg.AddUInt32(Creature.Id);
                }
                else if (ThingId == 0x0061)
                {
                    msg.AddUInt32(Creature.RemoveId);
                    msg.AddUInt32(Creature.Id);
                    msg.AddString(Creature.Name);
                }

                msg.AddByte(Creature.Health);
                msg.AddByte(Creature.Direction);
                msg.AddOutfit(Creature.Outfit);

                msg.AddByte(Creature.LightLevel);
                msg.AddByte(Creature.LightColor);

                msg.AddUInt16(Creature.Speed);
                msg.AddByte((byte)Creature.Skull);
                msg.AddByte((byte)Creature.PartyShield);
                if (Client.VersionNumber >= 853)
                {
                    if (ThingId == 0x0061)
                    {
                        msg.AddByte((byte)Creature.WarIcon);
                    }
                    msg.AddByte(Convert.ToByte(Creature.IsBlocking));
                }
            }
            else if (ThingId == 0x0063)
            {
                msg.AddUInt32(Creature.Id);
                msg.AddByte(Creature.Direction);
            }
            else
            {
                if (Item.HasExtraByte)
                {
                    msg.AddByte(Item.Count);
                }
            }
        }
Ejemplo n.º 18
0
        public override void Add(NetworkMessage message)
        {
            message.AddByte(0x00); // Should always be 0 for this packet; means there was no error.
            message.AddUInt16((ushort)Houses.Count);

            foreach (var house in Houses)
            {
                message.AddUInt16((ushort)house.HouseId);
                message.AddUInt32((uint)house.PlayerId);
                message.AddString(house.OwnerString);
                message.AddUInt32((uint)house.Gold);
            }
        }
        public override byte[] ToByteArray()
        {
            NetworkMessage msg = NetworkMessage.CreateUnencrypted(Client, 13 + CreatureName.Length + Text.Length);

            msg.AddByte((byte)Type);

            msg.AddUInt32(CreatureId);
            msg.AddString(CreatureName);
            msg.AddUInt16((ushort)Location.X);
            msg.AddUInt16((ushort)Location.Y);
            msg.AddString(Text);

            return(msg.Data);
        }
Ejemplo n.º 20
0
        public override void Add(NetworkMessage message)
        {
            message.AddByte(0x00);

            message.AddByte(WorldType);
            message.AddByte(DailyResetHour);

            message.AddBytes(IpAddressBytes);
            message.AddUInt16(Port);

            message.AddUInt16(MaximumTotalPlayers);
            message.AddUInt16(PremiumMainlandBuffer);
            message.AddUInt16(MaximumRookgardians);
            message.AddUInt16(PremiumRookgardiansBuffer);
        }
Ejemplo n.º 21
0
        public override void Add(NetworkMessage message)
        {
            message.AddByte(PacketType);
            message.AddByte((byte)Characters.Count());

            foreach (ICharacterListItem character in Characters)
            {
                message.AddString(character.Name);
                message.AddString(character.World);
                message.AddBytes(character.Ip);
                message.AddUInt16(character.Port);
            }

            message.AddUInt16(PremiumDaysLeft);
        }
Ejemplo n.º 22
0
        public static void Send(Objects.Client client, Objects.Location fromLocation, ushort fromItemId, byte fromStackPostion, Objects.Location toLocation, ushort toItemId, byte toStackPosition)
        {
            NetworkMessage packet = new NetworkMessage();

            packet.Position = 0;
            packet.AddByte(0x83);
            packet.AddBytes(fromLocation.ToBytes());
            packet.AddUInt16(fromItemId);
            packet.AddByte(fromStackPostion);
            packet.AddBytes(toLocation.ToBytes());
            packet.AddUInt16(toItemId);
            packet.AddByte(toStackPosition);

            client.HookProxy.SendPacketToServer(packet.Data);
        }
Ejemplo n.º 23
0
        public override byte[] ToByteArray()
        {
            NetworkMessage msg = NetworkMessage.CreateUnencrypted(Client, 15);

            msg.AddByte((byte)Type);

            msg.AddUInt32(SkinId);
            msg.AddUInt16(PosX);
            msg.AddUInt16(PosY);
            msg.AddUInt16(Width);
            msg.AddUInt16(Height);
            msg.AddUInt16(GUIId);

            return(msg.Data);
        }
Ejemplo n.º 24
0
        public static void Add
        (
            NetworkMessage message,
            string senderName,
            ushort senderLevel,
            SpeechType speechType,
            string text,
            Location location,
            ChatChannel channelId,
            uint time
        )
        {
            message.AddByte((byte)ServerPacketType.CreatureSpeech);

            message.AddUInt32(0x00000000);
            message.AddString(senderName);
            message.AddUInt16(senderLevel);
            message.AddByte((byte)speechType);

            switch (speechType)
            {
            case SpeechType.Say:
            case SpeechType.Whisper:
            case SpeechType.Yell:
            case SpeechType.MonsterSay:
            case SpeechType.MonsterYell:
            case SpeechType.PrivateNPCToPlayer:
                message.AddLocation(location);
                break;

            case SpeechType.ChannelRed:
            case SpeechType.ChannelRedAnonymous:
            case SpeechType.ChannelOrange:
            case SpeechType.ChannelYellow:
            case SpeechType.ChannelWhite:
                message.AddUInt16((ushort)channelId);
                break;

            case SpeechType.RuleViolationReport:
                message.AddUInt32(time);
                break;

            default:
                break;
            }

            message.AddString(text);
        }
Ejemplo n.º 25
0
 public override void ToNetworkMessage(NetworkMessage msg)
 {
     msg.AddByte((byte)Type);
     msg.AddUInt32(YourId);
     msg.AddUInt16(0x0032); // Related to client-side drawing speed
     msg.AddByte(CanReportBug);
 }
Ejemplo n.º 26
0
 public override void ToNetworkMessage(NetworkMessage msg)
 {
     msg.AddByte((byte)Type);
     msg.AddUInt32(YourId);
     msg.AddUInt16(0x0032); // Related to client-side drawing speed
     msg.AddByte(CanReportBug);
 }
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt16(ChannelId);
            msg.AddString(Name);
        }
Ejemplo n.º 28
0
        public static void Add(NetworkMessage message, IEnumerable <CharacterListItem> characters, ushort premiumDaysLeft)
        {
            message.AddByte((byte)ServerPacketType.CharacterList);

            message.AddByte((byte)characters.Count());

            foreach (CharacterListItem character in characters)
            {
                message.AddString(character.Name);
                message.AddString(character.World);
                message.AddBytes(character.Ip);
                message.AddUInt16(character.Port);
            }

            message.AddUInt16(premiumDaysLeft);
        }
Ejemplo n.º 29
0
        public override void Add(NetworkMessage message)
        {
            message.AddByte(PacketType);
            message.AddUInt32(0);
            message.AddString(SenderName);
            message.AddByte((byte)SpeechType);

            switch (SpeechType)
            {
            case SpeechType.Say:
            case SpeechType.Whisper:
            case SpeechType.Yell:
            case SpeechType.MonsterSay:
                // case SpeechType.MonsterYell:
                message.AddLocation(Location);
                break;

            // case SpeechType.ChannelRed:
            // case SpeechType.ChannelRedAnonymous:
            // case SpeechType.ChannelOrange:
            case SpeechType.ChannelYellow:
                // case SpeechType.ChannelWhite:
                message.AddUInt16((ushort)ChannelId);
                break;

            case SpeechType.RuleViolationReport:
                message.AddUInt32(Time);
                break;

            default:
                break;
            }

            message.AddString(Text);
        }
Ejemplo n.º 30
0
 /// <summary>
 ///     Adds the specified message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="channelId">The channel identifier.</param>
 /// <param name="channelName">Name of the channel.</param>
 /// <param name="channelEventType">Type of the channel event.</param>
 public static void Add(NetworkMessage message, ushort channelId, string channelName, ChannelEventType channelEventType)
 {
     message.AddPacketType(GamePacketType.ChannelEvent);
     message.AddUInt16(channelId);
     message.AddString(channelName);
     message.AddChannelEventType(channelEventType);
 }
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt16(ChannelId);
            msg.AddString(Name);
        }
Ejemplo n.º 32
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddLocation(Location);
            msg.AddUInt16(SpriteId);
            msg.AddByte(StackPosition);
        }
Ejemplo n.º 33
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt16(ItemId);
            msg.AddByte(Count);
            msg.AddByte(Amount);
        }
Ejemplo n.º 34
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddLocation(Location);
            msg.AddUInt16(SpriteId);
            msg.AddByte(StackPosition);
        }
Ejemplo n.º 35
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt16(ItemId);
            msg.AddByte(Count);
            msg.AddByte(Amount);
        }
Ejemplo n.º 36
0
 /// <summary>
 ///     Adds the spells.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="spells">The spells.</param>
 private static void AddSpells(NetworkMessage message, ICollection <ISpell> spells)
 {
     message.AddUInt16((ushort)spells.Count);
     foreach (ISpell spell in spells)
     {
         message.AddByte(spell.Id);
     }
 }
Ejemplo n.º 37
0
 /// <summary>
 ///     Adds the quests.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="quests">The quests.</param>
 private static void AddQuests(NetworkMessage message, ICollection <IQuestInfo> quests)
 {
     message.AddUInt16((ushort)quests.Count);
     foreach (IQuestInfo quest in quests)
     {
         message.AddQuest(quest);
     }
 }
Ejemplo n.º 38
0
        protected bool ParseFloorDescription(NetworkMessage msg, int x, int y, int z, int width, int height, int offset, NetworkMessage outMsg)
        {
            ushort skipTiles;

            for (int nx = 0; nx < width; nx++)
            {
                for (int ny = 0; ny < height; ny++)
                {
                    if (m_skipTiles == 0)
                    {
                        ushort tileOpt = msg.PeekUInt16();
                        //Decide if we have to skip tiles
                        // or if it is a real tile
                        if (tileOpt >= 0xFF00)
                        {
                            skipTiles = msg.GetUInt16();
                            outMsg.AddUInt16(skipTiles);

                            m_skipTiles = (short)(skipTiles & 0xFF);
                        }
                        else
                        {
                            //real tile so read tile
                            Objects.Location pos = new Pokemon.Objects.Location(x + nx + offset, y + ny + offset, z);

                            if (!ParseTileDescription(msg, pos, outMsg))
                            {
                                return(false);
                            }
                            //read skip tiles info
                            skipTiles = msg.GetUInt16();
                            outMsg.AddUInt16(skipTiles);

                            m_skipTiles = (short)(skipTiles & 0xFF);
                        }
                    }
                    //skipping tiles...
                    else
                    {
                        m_skipTiles--;
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 39
0
        public static NetworkMessage Create(byte OS, ushort Version,
            byte[] Signatures, byte[] XteaKey, string AccountName, string Password,bool OpenTibia)
        {
            NetworkMessage msg = new NetworkMessage(149);
            msg.AddByte(0x95);
            msg.AddByte(0x00);
            msg.Position += 4;
            msg.AddByte(0x01);
            msg.AddUInt16(OS);
            msg.AddUInt16(Version);
            msg.AddBytes(Signatures);
            msg.AddByte(0x0);
            msg.AddBytes(XteaKey);
            msg.AddString(AccountName);
            msg.AddString(Password);
            msg.RsaOTEncrypt(23);

            return msg;
        }
Ejemplo n.º 40
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt16(ItemId);
            msg.AddByte(Count);
            msg.AddByte(Amount);
            msg.AddByte(Unknown);
            msg.AddByte(Convert.ToByte(WithBackpack));
        }
Ejemplo n.º 41
0
        public static NetworkMessage Create(byte OS, ushort Version,
         byte[] XteaKey, string AccountName,string CharacterName, string Password, bool OpenTibia)
        {
            NetworkMessage msg = new NetworkMessage(139);
            msg.AddByte(0x89);
            msg.AddByte(0x00);
            msg.Position += 4;
            msg.AddByte(0x0A);
            msg.AddUInt16(OS);
            msg.AddUInt16(Version);
            msg.AddByte(0x0);
            msg.AddBytes(XteaKey);
            msg.AddByte(0x0);
            msg.AddString(AccountName);
            msg.AddString(CharacterName);
            msg.AddString(Password);
            msg.RsaOTEncrypt(11);

            return msg;
        }
Ejemplo n.º 42
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);
            msg.AddByte((byte)Channels.Count);

            foreach (Objects.Channel c in Channels)
            {
                msg.AddUInt16((ushort)c.Id);
                msg.AddString(c.Name);
            }
        }
Ejemplo n.º 43
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);
            msg.AddUInt16((ushort)ChannelId);
            msg.AddString(ChannelName);

            if (Client.VersionNumber >= 872)
            {
                msg.AddUInt16(NumberOfParticipants);
                for (ushort p = 0; p < NumberOfParticipants; p++)
                {
                    msg.AddString(Participants[p]);
                }
                msg.AddUInt16(NumberOfInvitees);
                for (ushort i = 0; i < NumberOfInvitees; i++)
                {
                    msg.AddString(Invitees[i]);
                }
            }
        }
Ejemplo n.º 44
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);
            msg.AddUInt32(Cash);

            msg.AddByte((byte)ItemList.Count);

            foreach (ShopInfo i in ItemList)
            {
                msg.AddUInt16(i.ItemId);
                msg.AddByte(i.SubType);
            }
        }
Ejemplo n.º 45
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);
            msg.AddOutfit(Default);
            msg.AddByte((byte)OutfitList.Count);

            foreach (AvalibleOutfit i in OutfitList)
            {
                msg.AddUInt16(i.Id);
                msg.AddString(i.Name);
                msg.AddByte(i.Addons);
            }
        }
Ejemplo n.º 46
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddByte((byte)ShopList.Count);

            foreach (ShopInfo i in ShopList)
            {
                msg.AddUInt16(i.ItemId);
                msg.AddByte(i.SubType);
                msg.AddString(i.ItemName);
                msg.AddUInt32(i.Weight);
                msg.AddUInt32(i.BuyPrice);
                msg.AddUInt32(i.SellPrice);
            }
        }
Ejemplo n.º 47
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddByte(Id);
            msg.AddUInt16(ItemId);
            msg.AddString(Name);
            msg.AddByte(Capacity);
            msg.AddByte(HasParent);
            msg.AddByte((byte)Items.Count);


            foreach (Objects.Item i in Items)
            {
                msg.AddItem(i);
            }
        }
Ejemplo n.º 48
0
        protected bool ParseFloorDescription(NetworkMessage msg, int x, int y, int z, int width, int height, int offset, NetworkMessage outMsg)
        {
            ushort skipTiles;

            for (int nx = 0; nx < width; nx++)
            {
                for (int ny = 0; ny < height; ny++)
                {
                    if (m_skipTiles == 0)
                    {
                        ushort tileOpt = msg.PeekUInt16();
                        //Decide if we have to skip tiles
                        // or if it is a real tile
                        if (tileOpt >= 0xFF00)
                        {
                            skipTiles = msg.GetUInt16();
                            outMsg.AddUInt16(skipTiles);

                            m_skipTiles = (short)(skipTiles & 0xFF);
                        }
                        else
                        {
                            //real tile so read tile
                            Objects.Location pos = new Pokemon.Objects.Location(x + nx + offset, y + ny + offset, z);

                            if (!ParseTileDescription(msg, pos, outMsg))
                            {
                                return false;
                            }
                            //read skip tiles info
                            skipTiles = msg.GetUInt16();
                            outMsg.AddUInt16(skipTiles);

                            m_skipTiles = (short)(skipTiles & 0xFF);
                        }
                    }
                    //skipping tiles...
                    else
                    {
                        m_skipTiles--;
                    }
                }
            }
            return true;
        }
Ejemplo n.º 49
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddLocation(Position);
            msg.AddByte(StackPosition);
            msg.AddUInt16(ThingId);

            if (ThingId == 0x0061 || ThingId == 0x0062 || ThingId == 0x0063)
            {
                msg.AddUInt32(CreatureId);
                msg.AddByte(CreatureDirection);
            }
            else
            {
                if (Item.HasExtraByte)
                    msg.AddByte(Item.Count);
            }
        }
Ejemplo n.º 50
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            SpeechTypeInfo info = Enums.GetSpeechTypeInfo(Client.GetVersionNumber(), SpeechType);

            msg.AddByte(info.Value);

            if (SpeechType == SpeechType.Private)
            {
                msg.AddString(Receiver);
            }
            else if (info.AdditionalSpeechData == AdditionalSpeechData.ChannelId)
            {
                msg.AddUInt16((ushort)ChannelId);
            }

            msg.AddString(Message);
        }
Ejemplo n.º 51
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt16(Health);
            msg.AddUInt16(MaxHealth);
            msg.AddUInt32(PokemonsCount);

            msg.AddUInt32((uint)Experience);

            msg.AddUInt16(Level);

            msg.AddByte(LevelPercent);

            msg.AddUInt16(Pokemons);
            msg.AddUInt16(PokemonsMax);

            msg.AddByte(MagicLevel);
            msg.AddByte(MagicLevelPercent);
            msg.AddByte(Soul);

            msg.AddUInt16(Stamina);
        }
Ejemplo n.º 52
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddOutfit(Default);

            msg.AddByte((byte)OutfitList.Count);

            foreach (AvalibleOutfit i in OutfitList)
            {
                msg.AddUInt16(i.Id);
                msg.AddString(i.Name);
                msg.AddByte(i.Addons);
            }

            if (Client.VersionNumber >= 870)
            {
                msg.AddByte((byte)MountList.Count);

                foreach (MountDescription i in MountList)
                {
                    msg.AddUInt16(i.Id);
                    msg.AddString(i.Name);
                }
            }
        }
Ejemplo n.º 53
0
 public override void ToNetworkMessage(NetworkMessage msg)
 {
     msg.AddByte((byte)Type);
     msg.AddUInt32(CreatureId);
     msg.AddUInt16(Speed);
 }
Ejemplo n.º 54
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddLocation(Location);
            msg.AddByte(Stack);
            msg.AddUInt16(ThingId);

            if (ThingId == 0x0061 || ThingId == 0x0062)
            {
                if (ThingId == 0x0062)
                    msg.AddUInt32(Creature.Id);
                else if (ThingId == 0x0061)
                {
                    msg.AddUInt32(Creature.RemoveId);
                    msg.AddUInt32(Creature.Id);
                    msg.AddString(Creature.Name);
                }

                msg.AddByte(Creature.Health);
                msg.AddByte(Creature.Direction);
                msg.AddOutfit(Creature.Outfit);

                msg.AddByte(Creature.LightLevel);
                msg.AddByte(Creature.LightColor);

                msg.AddUInt16(Creature.Speed);
                msg.AddByte((byte)Creature.Skull);
                msg.AddByte((byte)Creature.PartyShield);
                if (Client.VersionNumber >= 853)
                {
                    if (ThingId == 0x0061)
                        msg.AddByte((byte)Creature.WarIcon);
                    msg.AddByte(Convert.ToByte(Creature.IsBlocking));
                }
            }
            else if (ThingId == 0x0063)
            {
                msg.AddUInt32(Creature.Id);
                msg.AddByte(Creature.Direction);
            }
            else
            {
                if (Item.HasExtraByte)
                    msg.AddByte(Item.Count);
            }
        }
Ejemplo n.º 55
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            msg.AddByte((byte)Type);

            msg.AddUInt32(Unknown);
            msg.AddString(SenderName);
            msg.AddUInt16(SenderLevel);

            SpeechTypeInfo info = Enums.GetSpeechTypeInfo(Client.VersionNumber, SpeechType);

            msg.AddByte(info.Value);

            switch (info.AdditionalSpeechData)
            {
                case AdditionalSpeechData.Location:
                    msg.AddLocation(Position);
                    break;
                case AdditionalSpeechData.ChannelId:
                    msg.AddUInt16((ushort)ChannelId);
                    break;
                case AdditionalSpeechData.Time:
                    msg.AddUInt32(Time);
                    break;
                default:
                    break;
            }

            msg.AddString(Message);
        }
Ejemplo n.º 56
0
 public override void ToNetworkMessage(NetworkMessage msg)
 {
     msg.AddByte((byte)Type);
     msg.AddUInt16(Flag);
 }
Ejemplo n.º 57
0
        protected bool ParseThing(NetworkMessage msg, Location pos, Tile tile, int n, NetworkMessage outMsg)
        {
            //get thing type
            ushort thingId = msg.GetUInt16();
            outMsg.AddUInt16(thingId);

            PacketCreature c;

            if (thingId == 0x0061 || thingId == 0x0062)
            {

                c = new PacketCreature(Client);
                c.Location = pos;

                //creatures
                if (thingId == 0x0062) //creature is known
                {
                    c.Type = PacketCreatureType.Known;
                    c.Id = msg.GetUInt32();
                    outMsg.AddUInt32(c.Id); //creatureid
                }
                else if (thingId == 0x0061)
                { //creature is not known
                    //perhaps we have to remove a known creature
                    c.RemoveId = msg.GetUInt32();
                    outMsg.AddUInt32(c.RemoveId);

                    //add a new creature
                    c.Type = PacketCreatureType.Unknown;
                    c.Id = msg.GetUInt32();
                    outMsg.AddUInt32(c.Id);

                    c.Name = msg.GetString();
                    outMsg.AddString(c.Name);
                }

                //read creature properties
                c.Health = msg.GetByte();
                outMsg.AddByte(c.Health);

                c.Direction = msg.GetByte();
                outMsg.AddByte(c.Direction);

                c.Outfit = msg.GetOutfit();
                outMsg.AddOutfit(c.Outfit);

                c.LightLevel = msg.GetByte();
                outMsg.AddByte(c.LightLevel);

                c.LightColor = msg.GetByte();
                outMsg.AddByte(c.LightColor);

                c.Speed = msg.GetUInt16();
                outMsg.AddUInt16(c.Speed);

                c.Skull = (Constants.Skull)msg.GetByte();
                outMsg.AddByte((byte)c.Skull);

                c.PartyShield = (Constants.PartyShield)msg.GetByte();
                outMsg.AddByte((byte)c.PartyShield);

                creatures.Add(c);

                return true;
            }
            else if (thingId == 0x0063)
            {
                //creature turn
                c = new PacketCreature(Client);
                c.Location = pos;
                c.Type = PacketCreatureType.Turn;
                c.Id = msg.GetUInt32();
                outMsg.AddUInt32(c.Id);

                c.Direction = msg.GetByte();
                outMsg.AddByte(c.Direction);

                creatures.Add(c);

                return true;
            }
            else
            {
                //item
                UInt16 itemId;
                if (thingId == UInt16.MaxValue)
                {
                    itemId = msg.GetUInt16();
                    outMsg.AddUInt16(itemId);
                }
                else
                    itemId = thingId;

                Item item = new Item(Client, itemId, 0, "", ItemLocation.FromLocation(pos, (byte)n));

                if (item.HasExtraByte)
                {
                    item.Count = msg.GetByte();
                    outMsg.AddByte(item.Count);
                }

                if (n == 0)
                    tile.Ground = item;
                else
                    tile.Items.Add(item);

                return true;
            }
        }
Ejemplo n.º 58
0
        public override void ToNetworkMessage(NetworkMessage msg)
        {
            Tile playerTile = Client.Map.GetTileWithPlayer();
            msg.AddByte((byte)Type);
            msg.AddLocation(playerTile.Location);

            //GetMapDescription(playerLocation.X - 8, playerLocation.Y - 6, playerLocation.Z, 18, 14, msg);

            int startz, endz, zstep;

            if (playerTile.Location.Z > 7)
            {
                startz = playerTile.Location.Z - 2;
                endz = Math.Min(15, playerTile.Location.Z + 2);
                zstep = 1;
            }
            else
            {
                startz = 7;
                endz = 0;
                zstep = -1;
            }

            uint mapStart = Client.Memory.ReadUInt32(Addresses.Map.MapPointer);

            for (int z = startz; z != endz + zstep; z += zstep)
            {
                for (int x = 0; x < 18; x++)
                {
                    for (int y = 0; y < 14; y++)
                    {
                        Location memLoc = new Location(x, y, z);
                        uint num = memLoc.ToTileNumber();
                        Tile pCurrent = new Tile(Client, mapStart + (Addresses.Map.StepTile * num), num);

                        foreach (TileObject o in pCurrent.Objects)
                        {
                            if (o.Id == 0x0063)
                            {
                                // Add a creature
                                Creature c = Client.BattleList.GetCreatures().FirstOrDefault(cr => cr.Id == o.Data);

                                if (c == null)
                                    throw new Exception("Creature does not exist.");

                                // Add as unknown
                                msg.AddUInt16((ushort)o.Id);

                                // No need to remove a creature
                                msg.AddUInt32(0);

                                // Add the creature id
                                msg.AddUInt32((uint)c.Id);

                                msg.AddString(c.Name);

                                msg.AddByte((byte)c.HPBar);

                                msg.AddByte((byte)c.Direction);

                                msg.AddOutfit(c.Outfit);

                                msg.AddByte((byte)c.Light);

                                msg.AddByte((byte)c.LightColor);

                                msg.AddUInt16((ushort)c.WalkSpeed);

                                msg.AddByte((byte)c.Skull);

                                msg.AddByte((byte)c.PartyShield);
                            }
                            else
                            {
                                Item item = new Item(Client, (uint)o.Id);

                                msg.AddUInt16((ushort)item.Id);

                                if (item.HasExtraByte)
                                    msg.AddByte(item.Count);
                            }
                        }

                        msg.AddByte(0x00);
                        msg.AddByte(0xFF);
                    }
                }
            }

        }
Ejemplo n.º 59
0
        protected void GetTileDescription(Tile tile, NetworkMessage msg)
        {
            if (tile != null)
            {
                List<TileObject> objects = tile.Objects;
                objects.Insert(0, new TileObject(tile.Ground.Id, tile.Ground.Count, 0));

                foreach (TileObject o in objects)
                {
                    if (o.Id <= 0)
                    {
                        return;
                    }
                    else if (o.Id == 0x0061 || o.Id == 0x0062 || o.Id == 0x0063)
                    {
                        // Add a creature
                        Creature c = Client.BattleList.GetCreatures().FirstOrDefault(cr => cr.Id == o.Data);

                        if (c == null)
                            throw new Exception("Creature does not exist.");

                        // Add as unknown
                        msg.AddUInt16((ushort)o.Id);

                        // No need to remove a creature
                        msg.AddUInt32(0);

                        // Add the creature id
                        msg.AddUInt32((uint)c.Id);

                        msg.AddString(c.Name);

                        msg.AddByte((byte)c.HPBar);

                        msg.AddByte((byte)c.Direction);

                        msg.AddOutfit(c.Outfit);

                        msg.AddByte((byte)c.Light);

                        msg.AddByte((byte)c.LightColor);

                        msg.AddUInt16((ushort)c.WalkSpeed);

                        msg.AddByte((byte)c.Skull);

                        msg.AddByte((byte)c.PartyShield);
                    }
                    else if (o.Id <= 9999)
                    {
                        // Add an item
                        Item item = new Item(Client, (uint)o.Id, (byte)o.Data, "",
                            ItemLocation.FromLocation(tile.Location, (byte)o.StackOrder));

                        msg.AddUInt16((ushort)o.Id);

                        try
                        {
                            if (item.HasExtraByte)
                            {
                                msg.AddByte(item.Count);
                            }
                        }
                        catch { }
                    }
                }
            }
        }
Ejemplo n.º 60
0
 public override void ToNetworkMessage(NetworkMessage msg)
 {
     msg.AddByte((byte)Type);
     msg.AddUInt16((ushort)ChannelId);
 }