예제 #1
0
        private Item internalGetItem(NetworkMessage incMsg, NetworkMessage outMsg, uint itemId)
        {
            if (itemId == 0xFFFFFFFF)
            {
                if (incMsg.CanRead(2))
                {
                    itemId = incMsg.GetUInt16();
                    outMsg.AddUInt16((ushort)itemId);
                }
                else
                    return null;
            }

            TibiaEzBot.Core.Entities.ObjectType it = Objects.GetInstance().GetItemType((ushort)itemId);

            if (it == null)
                return null;

            byte count = 0;
            if (it.IsStackable || it.IsSplash || it.IsFluidContainer || it.IsRune)
            {
                count = incMsg.GetByte();
                outMsg.AddByte(count);
            }

            return new Item((ushort)itemId, count, it);
        }
예제 #2
0
        private bool parseUpdateTile(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            Position tilePos = incMsg.GetPosition();
            outMsg.AddPosition(tilePos);

            ushort thingId = incMsg.PeekUInt16();

            if (thingId == 0xFF01)
            {
                outMsg.AddUInt16(incMsg.GetUInt16());

                Tile tile = Map.GetInstance().GetTile(tilePos);

                if (tile == null)
                    Logger.Log("Erro ao atualizar o tile. Posição: " + tilePos.ToString(), LogType.ERROR);

                tile.Clear();
            }
            else
            {
                if (!setTileDescription(incMsg, outMsg, tilePos))
                    Logger.Log("Erro ao atualizar o tile. Posição: " + tilePos.ToString(), LogType.ERROR);

                outMsg.AddUInt16(incMsg.GetUInt16());
            }

            return true;
        }
예제 #3
0
        private bool setFloorDescription(NetworkMessage incMsg, NetworkMessage outMsg, int x, int y, int z, int width, int height, int offset)
        {
            for (int nx = 0; nx < width; nx++)
            {
                for (int ny = 0; ny < height; ny++)
                {
                    if (skipTiles == 0)
                    {
                        ushort tileOpt = incMsg.PeekUInt16();
                        //Decide if we have to skip tiles
                        // or if it is a real tile
                        if (tileOpt >= 0xFF00)
                        {
                            ushort skip = incMsg.GetUInt16();
                            outMsg.AddUInt16(skip);
                            skipTiles = (ushort)(skip & 0xFF);
                        }
                        else
                        {
                            //real tile so read tile
                            Position pos = new Position((uint)(x + nx + offset), (uint)(y + ny + offset), (uint)z);
                            if (!setTileDescription(incMsg, outMsg, pos))
                            {
                                Logger.Log("Falha ao setar a descrição do tile. Posição: " + pos.ToString(), LogType.ERROR);
                                return false;
                            }

                            //read skip tiles info
                            ushort skip = incMsg.GetUInt16();
                            outMsg.AddUInt16(skip);
                            skipTiles = (ushort)(skip & 0xFF);
                        }
                    }
                    //skipping tiles...
                    else
                    {
                        skipTiles--;
                    }
                }
            }
            return true;
        }
예제 #4
0
 private bool parseOpenChannel(NetworkMessage incMsg, NetworkMessage outMsg)
 {
     ushort channelId = incMsg.GetUInt16();
     outMsg.AddUInt16(channelId);
     String name = incMsg.GetString();
     outMsg.AddString(name);
     //Notifications::openChannel(channelID, name);
     return true;
 }
예제 #5
0
        private bool parseTileTransformThing(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            Position tilePos = incMsg.GetPosition();
            outMsg.AddPosition(tilePos);

            byte stackPos = incMsg.GetByte();
            outMsg.AddByte(stackPos);

            ushort thingId = incMsg.GetUInt16();
            outMsg.AddUInt16(thingId);

            if (thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063)
            {
                //creature turn
                uint creatureID = incMsg.GetUInt32();
                outMsg.AddUInt32(creatureID);

                byte direction = incMsg.GetByte();
                outMsg.AddByte(direction);

                Creature creature = Creatures.GetInstance().GetCreature(creatureID);

                if (creature == null)
                {
                    Logger.Log("Falha ao transformar o objeto. Creatura retornou nula.", LogType.ERROR);
                    return false;
                }

                if (direction > 3)
                {
                    Logger.Log("Falha ao transformar o objeto. Direção maior que 3.", LogType.ERROR);
                    return false;
                }

                creature.SetTurnDirection((Direction)direction);
            }
            else
            {
                //get tile
                Tile tile = Map.GetInstance().GetTile(tilePos);

                if (tile == null)
                {
                    Logger.Log("Falha ao transformar o objeto. Tile retornou nulo.", LogType.ERROR);
                    return false;
                }

                //removes the old item
                Thing thing = tile.GetThingByStackPosition(stackPos);

                if (thing == null)
                {
                    Logger.Log("Falha ao transformar o objeto. Objeto retornou nulo.", LogType.ERROR);
                    return false;
                }

                if (!tile.RemoveThing(thing))
                {
                    Logger.Log("Falha ao transformar o objeto. Falha ao remover o item.", LogType.ERROR);
                    return false;
                }

                //adds a new item
                Item item = internalGetItem(incMsg, outMsg, thingId);

                if (!tile.InsertThing(item, (int)stackPos))
                {
                    Logger.Log("Falha ao transformar o objeto. Não foi possivel inserir o item.", LogType.ERROR);
                    return false;
                }
            }

            return true;
        }
예제 #6
0
 private bool parseClosePrivateChannel(NetworkMessage incMsg, NetworkMessage outMsg)
 {
     ushort channelId = incMsg.GetUInt16();
     outMsg.AddUInt16(channelId);
     return true;
 }
예제 #7
0
        private bool parseCreatureSpeak(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            uint unknown = incMsg.GetUInt32();
            outMsg.AddUInt32(unknown);
            String senderName = incMsg.GetString();
            outMsg.AddString(senderName);
            ushort senderLevel = incMsg.GetUInt16();
            outMsg.AddUInt16(senderLevel);
            SpeechType type = (SpeechType)incMsg.GetByte();
            outMsg.AddByte((byte)type);

            switch (type)
            {
                case SpeechType.Say:
                case SpeechType.Whisper:
                case SpeechType.Yell:
                case SpeechType.MonsterSay:
                case SpeechType.MonsterYell:
                case SpeechType.PrivateNPCToPlayer:
                    Position position = incMsg.GetPosition();
                    outMsg.AddPosition(position);
                    break;
                case SpeechType.ChannelRed:
                case SpeechType.ChannelRedAnonymous:
                case SpeechType.ChannelOrange:
                case SpeechType.ChannelYellow:
                case SpeechType.ChannelWhite:
                    ChatChannel channelId = (ChatChannel)incMsg.GetUInt16();
                    outMsg.AddUInt16((ushort)channelId);
                    break;
                case SpeechType.RuleViolationReport:
                    uint time = incMsg.GetUInt32();
                    outMsg.AddUInt32(time);
                    break;
                case SpeechType.Private:
                    break;
                default:
                    Logger.Log("Tipo de mensagem desconhecido.", LogType.ERROR);
                    break;
            }

            String message = incMsg.GetString();
            outMsg.AddString(message);

            return true;
        }
예제 #8
0
        private bool parsePlayerStats(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            ushort health = incMsg.GetUInt16();
            outMsg.AddUInt16(health);

            ushort healthMax = incMsg.GetUInt16();
            outMsg.AddUInt16(healthMax);

            uint capacity = incMsg.GetUInt32();
            outMsg.AddUInt32(capacity);

            uint experience = incMsg.GetUInt32();
            outMsg.AddUInt32(experience);

            ushort level = incMsg.GetUInt16();
            outMsg.AddUInt16(level);

            byte levelPercent = incMsg.GetByte();
            outMsg.AddByte(levelPercent);

            ushort mana = incMsg.GetUInt16();
            outMsg.AddUInt16(mana);

            ushort maxMana = incMsg.GetUInt16();
            outMsg.AddUInt16(maxMana);

            byte magicLevel = incMsg.GetByte();
            outMsg.AddByte(magicLevel);

            byte magicLevelPercent = incMsg.GetByte();
            outMsg.AddByte(magicLevelPercent);

            byte soul = incMsg.GetByte();
            outMsg.AddByte(soul);

            ushort stamina = incMsg.GetUInt16();
            outMsg.AddUInt16(stamina);

            //some validations
            // NOTE (nfries88): sometimes, upon death, your mana will be greater than your maximum mana (due to level loss)
            if (health > healthMax || levelPercent > 100 || magicLevelPercent > 100)
            {
                Logger.Log("Player stats - values", LogType.ERROR);
                return false;
            }

            GlobalVariables.SetPlayerStatus(PlayerStatus.Health, health);
            GlobalVariables.SetPlayerStatus(PlayerStatus.HealthMax, healthMax);
            GlobalVariables.SetPlayerStatus(PlayerStatus.Capacity, capacity);
            GlobalVariables.SetPlayerStatus(PlayerStatus.Experience, experience);
            GlobalVariables.SetPlayerSkill(Skills.Level, SkillAttribute.Level, level);
            GlobalVariables.SetPlayerSkill(Skills.Level, SkillAttribute.Percent, levelPercent);
            GlobalVariables.SetPlayerStatus(PlayerStatus.Mana, mana);
            GlobalVariables.SetPlayerStatus(PlayerStatus.ManaMax, maxMana);
            GlobalVariables.SetPlayerSkill(Skills.Magic, SkillAttribute.Level, magicLevel);
            GlobalVariables.SetPlayerSkill(Skills.Magic, SkillAttribute.Percent, magicLevelPercent);
            GlobalVariables.SetPlayerStatus(PlayerStatus.Soul, soul);
            GlobalVariables.SetPlayerStatus(PlayerStatus.Stamina, stamina);

            return true;
        }
예제 #9
0
        private bool parseQuestList(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            ushort nQuests = incMsg.GetUInt16();
            outMsg.AddUInt16(nQuests);

            for (uint i = 0; i < nQuests; ++i)
            {
                ushort questId = incMsg.GetUInt16();
                outMsg.AddUInt16(questId);

                String questsName = incMsg.GetString();
                outMsg.AddString(questsName);

                byte questState = incMsg.GetByte();
                outMsg.AddByte(questState);
            }
            return true;
        }
예제 #10
0
        private bool parsePlayerCash(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            uint cash = incMsg.GetUInt32();
            outMsg.AddUInt32(cash);

            byte size = incMsg.GetByte();
            outMsg.AddByte(size);

            for (uint i = 0; i < size; ++i)
            {
                ushort itemId = incMsg.GetUInt16();
                outMsg.AddUInt16(itemId);

                byte runeCharges = incMsg.GetByte();
                outMsg.AddByte(runeCharges);
            }

            GlobalVariables.SetPlayerCash(cash);
            return true;
        }
예제 #11
0
 private bool parsePlayerIcons(NetworkMessage incMsg, NetworkMessage outMsg)
 {
     ushort icons = incMsg.GetUInt16();
     outMsg.AddUInt16(icons);
     GlobalVariables.SetPlayerIcons(icons);
     return true;
 }
예제 #12
0
        private bool parseOutfitWindow(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            Outfit outfit = incMsg.GetOutfit();
            outMsg.AddOutfit(outfit);
            byte nOutfits = incMsg.GetByte();

            if (nOutfits == 0 || nOutfits > 25)
            {
                Logger.Log("Outfit window - n = 0 || n > 25", LogType.ERROR);
                return false;
            }

            for (uint i = 0; i < nOutfits; ++i)
            {

                ushort outfitID = incMsg.GetUInt16();
                outMsg.AddUInt16(outfitID);

                if (Objects.GetInstance().GetOutfitType(outfitID) == null)
                {
                    Logger.Log("Outfit window  - outfit list error", LogType.ERROR);
                    return false;
                }

                String name = incMsg.GetString();
                outMsg.AddString(name);

                byte addons = incMsg.GetByte();
                outMsg.AddByte(addons);

            }

            return true;
        }
예제 #13
0
        // 8.2+
        private bool parseOpenShopWindow(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            byte size = incMsg.GetByte();
            outMsg.AddByte(size);

            for (uint i = 0; i < size; ++i)
            {
                ushort itemId = incMsg.GetUInt16();
                outMsg.AddUInt16(itemId);

                byte runeCharges = incMsg.GetByte();
                outMsg.AddByte(runeCharges);

                String name = incMsg.GetString();
                outMsg.AddString(name);

                uint weight = incMsg.GetUInt32();
                outMsg.AddUInt32(weight);

                uint buyPrice = incMsg.GetUInt32();
                outMsg.AddUInt32(buyPrice);

                uint sellPrice = incMsg.GetUInt32();
                outMsg.AddUInt32(sellPrice);
            }

            return true;
        }
예제 #14
0
        private bool parseOpenContainer(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            byte cid = incMsg.GetByte();
            outMsg.AddByte(cid);
            ushort itemId = incMsg.GetUInt16();
            outMsg.AddUInt16(itemId);
            String name = incMsg.GetString();
            outMsg.AddString(name);
            byte capacity = incMsg.GetByte();
            outMsg.AddByte(capacity);
            byte hasParent = incMsg.GetByte();
            outMsg.AddByte(hasParent);
            byte size = incMsg.GetByte();
            outMsg.AddByte(size);

            if (size > capacity)
            {
                Logger.Log("Open container - size > cap", LogType.ERROR);
                return false;
            }

            // NOTE (nfries88)
            // The server sends a message to open a container when it is moved client-side
            // In the event of it already being opened, don't remake it
            // but allow updates.
            Container container = Containers.GetInstance().CreateContainer(cid);
            if (container == null)
            {
                Logger.Log("Open container - !container", LogType.ERROR);
                return true;
            }

            container.SetName(name);
            container.SetItemId(itemId);
            container.SetCapacity(capacity);
            container.SetHasParent(hasParent == 1);

            for (uint i = 0; i < size; ++i)
            {
                Item item = internalGetItem(incMsg, outMsg, 0xFFFFFFFF);
                if (item == null)
                {
                    Logger.Log("Container Open - !item", LogType.ERROR);
                    return false;
                }
                // When the server sends a message to open a container that's already opened
                if (container.GetItem(i) != null)
                {
                    if (!container.UpdateItem(i, item))
                    {
                        Logger.Log("Container Open - updateItem", LogType.ERROR);
                        return false;
                    }
                }
                else if (!container.AddItemInitial(item))
                {
                    Logger.Log("Container Open - addItem", LogType.ERROR);
                    return false;
                }
            }

            return true;
        }
예제 #15
0
        private Thing internalGetThing(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            //get thing type
            ushort thingId = incMsg.GetUInt16();
            outMsg.AddUInt16(thingId);

            if (thingId == 0x0061 || thingId == 0x0062)
            {
                //creatures
                Creature creature = null;

                if (thingId == 0x0062)
                { //creature is known
                    uint creatureID = incMsg.GetUInt32();
                    outMsg.AddUInt32(creatureID);
                    creature = Creatures.GetInstance().GetCreature(creatureID);
                }
                else if (thingId == 0x0061)
                {
                    //creature is not known
                    //perhaps we have to remove a known creature
                    uint removeID = incMsg.GetUInt32();
                    outMsg.AddUInt32(removeID);
                    Creatures.GetInstance().RemoveCreature(removeID);

                    //add a new creature
                    uint creatureID = incMsg.GetUInt32();
                    outMsg.AddUInt32(creatureID);
                    creature = Creatures.GetInstance().AddCreature(creatureID);

                    if (creature == null)
                        return null;

                    creature.SetName(incMsg.GetString());
                    outMsg.AddString(creature.GetName());
                }

                if (creature == null)
                    return null;

                //read creature properties
                creature.SetHealth(incMsg.GetByte());
                outMsg.AddByte(creature.GetHealth());
                if (creature.GetHealth() > 100)
                    return null;

                byte direction = incMsg.GetByte();
                outMsg.AddByte(direction);
                if (direction > 3)
                    return null;

                creature.SetTurnDirection((Direction)direction);

                creature.SetOutfit(incMsg.GetOutfit());
                outMsg.AddOutfit(creature.GetOutfit());

                //check if we can read 6 bytes
                if (!incMsg.CanRead(6))
                    return null;

                creature.SetLightLevel(incMsg.GetByte());
                outMsg.AddByte(creature.GetLightLevel());

                creature.SetLightColor(incMsg.GetByte());
                outMsg.AddByte(creature.GetLightColor());

                creature.SetSpeed(incMsg.GetUInt16());
                outMsg.AddUInt16(creature.GetSpeed());

                creature.SetSkull(incMsg.GetByte());
                outMsg.AddByte(creature.GetSkull());

                creature.SetShield(incMsg.GetByte());
                outMsg.AddByte(creature.GetShield());

                if (thingId == 0x0061)
                {
                    // emblem is sent only in packet type 0x61
                    creature.SetEmblem(incMsg.GetByte());
                    outMsg.AddByte(creature.GetEmblem());
                }

                byte impassable = incMsg.GetByte();
                creature.SetImpassable(impassable == 0x01);
                outMsg.AddByte(impassable);

                return creature;
            }
            else if (thingId == 0x0063)
            {
                //creature turn
                uint creatureID = incMsg.GetUInt32();
                outMsg.AddUInt32(creatureID);

                Creature creature = Creatures.GetInstance().GetCreature(creatureID);

                if (creature == null)
                    return null;

                //check if we can read 1 byte
                byte direction = incMsg.GetByte();
                outMsg.AddByte(direction);

                if (direction > 3)
                    return null;

                creature.SetTurnDirection((Direction)direction);

                return creature;
            }
            else
            {
                //item
                return internalGetItem(incMsg, outMsg, thingId);
            }
        }
예제 #16
0
        private bool parseQuestPartList(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            ushort questId = incMsg.GetUInt16();
            outMsg.AddUInt16(questId);

            byte nMission = incMsg.GetByte();
            outMsg.AddByte(nMission);

            for (uint i = 0; i < nMission; ++i)
            {
                String questsName = incMsg.GetString();
                outMsg.AddString(questsName);

                String questsDesc = incMsg.GetString();
                outMsg.AddString(questsDesc);

            }
            return true;
        }
예제 #17
0
        private bool parseChannelList(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            byte count = incMsg.GetByte();
            outMsg.AddByte(count);

            for (uint i = 0; i < count; ++i)
            {
                ushort channelId = incMsg.GetUInt16();
                outMsg.AddUInt16(channelId);
                String name = incMsg.GetString();
                outMsg.AddString(name);
            }

            return true;
        }
예제 #18
0
 private bool parseRuleViolationB1(NetworkMessage incMsg, NetworkMessage outMsg)
 {
     //TODO
     outMsg.AddUInt16(incMsg.GetUInt16());
     return true;
 }
예제 #19
0
 private bool parseCreatePrivateChannel(NetworkMessage incMsg, NetworkMessage outMsg)
 {
     ushort channelId = incMsg.GetUInt16();
     outMsg.AddUInt16(channelId);
     String name = incMsg.GetString();
     outMsg.AddString(name);
     return true;
 }
예제 #20
0
        private bool parseSelfApper(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            Creatures.GetInstance().Clear();
            Inventory.GetInstance().Clear();
            Containers.GetInstance().Clear();
            Map.GetInstance().Clear();
            GlobalVariables.Clear();

            GlobalVariables.SetPlayerId(incMsg.GetUInt32());
            outMsg.AddUInt32(GlobalVariables.GetPlayerId());

            outMsg.AddUInt16(incMsg.GetUInt16());

            GlobalVariables.SetCanReportBugs(Convert.ToBoolean(incMsg.GetByte()));
            outMsg.AddByte(Convert.ToByte(GlobalVariables.GetCanReportBugs()));

            GlobalVariables.SetConnected(true);

            new Action(getPlayerMemoryAddress).BeginInvoke(null, null);

            Logger.Log("Entrou no jogo.");
            return true;
        }
예제 #21
0
        private bool parseCreatureSpeed(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            uint creatureId = incMsg.GetUInt32();
            outMsg.AddUInt32(creatureId);

            ushort speed = incMsg.GetUInt16();
            outMsg.AddUInt16(speed);

            Creature creature = Creatures.GetInstance().GetCreature(creatureId);
            if (creature != null)
            {
                creature.SetSpeed(speed);
            }
            return true;
        }
예제 #22
0
        private bool parseItemTextWindow(NetworkMessage incMsg, NetworkMessage outMsg)
        {
            /*MSG_READ_U32(windowID);
            MSG_READ_U16(itemID);
            MSG_READ_U16(maxlen);
            MSG_READ_STRING(text);
            MSG_READ_STRING(writter);
            MSG_READ_STRING(date);*/

            outMsg.AddUInt32(incMsg.GetUInt32());
            outMsg.AddUInt16(incMsg.GetUInt16());
            outMsg.AddUInt16(incMsg.GetUInt16());
            outMsg.AddString(incMsg.GetString());
            outMsg.AddString(incMsg.GetString());
            outMsg.AddString(incMsg.GetString());

            return true;
        }