Пример #1
0
        public void Parse(InputMessage message)
        {
            byte worlds = message.GetU8();

            for (int i = 0; i < worlds; i++)
            {
                var world = new World();
                world.ID       = message.GetU8();
                world.Name     = message.GetString();
                world.HostName = message.GetString();
                world.Port     = message.GetU16();
                world.Preview  = message.GetBool();
                Worlds.Add(world);
            }

            byte characters = message.GetU8();

            for (int i = 0; i < characters; i++)
            {
                Character character = new Character();
                character.World = message.GetU8();
                character.Name  = message.GetString();
                Characters.Add(character);
            }

            AccountState     = message.GetU8();
            IsPremium        = message.GetBool();
            PremiumTimeStamp = message.GetU32();

            InfinitePremium = (IsPremium && PremiumTimeStamp == 0);
        }
Пример #2
0
        private void ParseAmbientLight(InputMessage message)
        {
            byte  intensity = message.GetU8();
            Color color     = Colors.ColorFrom8Bit(message.GetU8());

            m_WorldMapStorage.SetAmbientLight(color, intensity);
        }
Пример #3
0
        private void ParseBasicData(InputMessage message)
        {
            bool premium = message.GetBool();

            if (OpenTibiaUnity.GameManager.GetFeature(GameFeatures.GamePremiumExpiration))
            {
                uint premiumExpiration = message.GetU32();
            }

            byte vocation = message.GetU8();

            if (OpenTibiaUnity.GameManager.ClientVersion >= 1100)
            {
                bool hasReachedMain = message.GetBool();
            }

            List <byte> spells      = new List <byte>();
            ushort      spellsCount = message.GetU16();

            for (int i = 0; i < spellsCount; i++)
            {
                spells.Add(message.GetU8());
            }

            if (m_Player)
            {
                //m_Player.PremiumStatus = premium;
                //m_Player.PremiumExpiration = premiumExpiration;
                //m_Player.Vocation = vocation;
                //m_Player.ReachedMain = hasReachedMain;
            }
        }
Пример #4
0
        private void ParseCreatureMarks(InputMessage message)
        {
            uint creatureId = message.GetU32();
            bool permenant  = message.GetU8() != 1;
            byte mark       = message.GetU8();

            var creature = m_CreatureStorage.GetCreature(creatureId);

            if (!creature)
            {
                throw new System.Exception("ProtocolGame.ParseCreatureMarks: Unknown creature id: " + creatureId);
            }
            else
            {
                if (permenant)
                {
                    creature.Marks.SetMark(Appearances.Marks.MarkType_Permenant, mark);
                }
                else
                {
                    creature.Marks.SetMark(Appearances.Marks.MarkType_OneSecondTemp, mark);
                }

                m_CreatureStorage.InvalidateOpponents();
            }
        }
Пример #5
0
        private void ParseDeath(InputMessage message)
        {
            DeathType deathType = (DeathType)message.GetU8();

            int penalty = 100;

            if (deathType == DeathType.DeathTypeRegular)
            {
                penalty = message.GetU8();
            }

            // TODO death actions...
            //LocalPlayer.OnDeath(deathType, penalty);
        }
Пример #6
0
        private void ParseChannelEvent(InputMessage message)
        {
            int channelID = message.GetU16();

            Chat.Channel channel    = m_ChatStorage.GetChannel(channelID);
            string       playerName = message.GetString();
            int          eventType  = message.GetU8();

            switch (eventType)
            {
            case 0:
                channel.PlayerJoined(playerName);
                break;

            case 1:
                channel.PlayerLeft(playerName);
                break;

            case 2:
                channel.PlayerInvited(playerName);
                break;

            case 3:
                channel.PlayerExcluded(playerName);
                break;

            case 4:
                channel.PlayerPending(playerName);
                break;
            }
        }
Пример #7
0
        private void ParseChallange(InputMessage message)
        {
            uint timestamp = message.GetU32();
            byte challange = message.GetU8();

            SendLoginPacket(timestamp, challange);
        }
Пример #8
0
        private void ParseSetInventory(InputMessage message)
        {
            int slot = message.GetU8();
            var obj  = ReadObjectInstance(message);

            OpenTibiaUnity.ContainerStorage.BodyContainerView.SetObject((ClothSlots)slot, obj);
        }
Пример #9
0
        private void ParseContainerUpdateItem(InputMessage message)
        {
            byte   containerId = message.GetU8();
            ushort slot        = message.GetU16();

            Appearances.ObjectInstance item = ReadObjectInstance(message);
        }
Пример #10
0
        private void ParsePlayerBlessings(InputMessage message)
        {
            ushort blessings = message.GetU16();

            message.GetU8(); // unknown

            //m_Player.Blessings = blessings;
        }
Пример #11
0
        private void ParseCreatureLight(InputMessage message)
        {
            uint creatureId = message.GetU32();

            byte intensity = message.GetU8();
            byte color     = message.GetU8();

            var creature = m_CreatureStorage.GetCreature(creatureId);

            if (!creature)
            {
                throw new System.Exception("ProtocolGame.ParseCreatureLight: Unknown creature id: " + creatureId);
            }
            else
            {
                creature.Brightness = intensity;
                creature.LightColor = Colors.ColorFrom8Bit(color);
            }
        }
Пример #12
0
        private void ParseGmActions(InputMessage message)
        {
            int numViolations = 20;

            List <byte> actions = new List <byte>();

            for (int i = 0; i < numViolations; i++)
            {
                actions.Add(message.GetU8());
            }
        }
Пример #13
0
 private void ParsePlayerStates(InputMessage message)
 {
     if (OpenTibiaUnity.GameManager.GetFeature(GameFeatures.GamePlayerStateU16))
     {
         m_Player.StateFlags = message.GetU16();
     }
     else
     {
         m_Player.StateFlags = message.GetU8();
     }
 }
Пример #14
0
        private void ParsePlayerInventory(InputMessage message)
        {
            //List<KeyValuePair<ushort, ushort>> items = new List<KeyValuePair<ushort, ushort>>();
            ushort size = message.GetU16();

            for (int i = 0; i < size; i++)
            {
                ushort id      = message.GetU16();
                byte   subType = message.GetU8();
                ushort count   = message.GetU16();
            }
        }
Пример #15
0
        private void ParseChannels(InputMessage message)
        {
            int count = message.GetU8();
            List <Chat.Channel> channels = new List <Chat.Channel>();

            for (int i = 0; i < count; i++)
            {
                int    id   = message.GetU16();
                string name = message.GetString();
                channels.Add(new Chat.Channel(id, name, MessageModes.None));
            }
        }
Пример #16
0
        private void ParseOpenContainer(InputMessage message)
        {
            byte containerId = message.GetU8();

            Appearances.ObjectInstance item = ReadObjectInstance(message);
            string name          = message.GetString();
            byte   capacity      = message.GetU8();
            bool   hasParent     = message.GetBool();
            bool   unlocked      = message.GetBool();
            bool   hasPages      = message.GetBool();
            ushort containerSize = message.GetU16();
            ushort firstIndex    = message.GetU16();

            int itemCount = message.GetU8();

            List <Appearances.ObjectInstance> items = new List <Appearances.ObjectInstance>(itemCount);

            for (int i = 0; i < itemCount; i++)
            {
                items.Add(ReadObjectInstance(message));
            }
        }
Пример #17
0
        private AppearanceInstance ReadCreatureOutfit(InputMessage message, AppearanceInstance instance = null)
        {
            int lookType = message.GetU16();

            if (lookType != 0)
            {
                int head   = message.GetU8();
                int body   = message.GetU8();
                int legs   = message.GetU8();
                int feet   = message.GetU8();
                int addons = message.GetU8();

                OutfitInstance outfitInstance = instance as OutfitInstance;
                if (!!outfitInstance)
                {
                    outfitInstance.UpdateProperties(head, body, legs, feet, addons);
                    return(instance);
                }

                return(m_AppearanceStorage.CreateOutfitInstance((uint)lookType, head, body, legs, feet, addons));
            }

            int lookTypeEx = message.GetU16();

            ObjectInstance objectInstance = instance as ObjectInstance;

            if (!!objectInstance && objectInstance.ID == (uint)lookTypeEx)
            {
                return(objectInstance);
            }

            if (lookTypeEx == 0)
            {
                return(m_AppearanceStorage.CreateOutfitInstance(OutfitInstance.InvisibleOutfitID, 0, 0, 0, 0, 0));
            }

            return(m_AppearanceStorage.CreateObjectInstance((uint)lookTypeEx, 0));
        }
Пример #18
0
        private ObjectInstance ReadObjectInstance(InputMessage message, int id = -1)
        {
            if (id == -1)
            {
                id = message.GetU16();
            }

            if (id == 0)
            {
                return(null);
            }
            else if (id <= AppearanceInstance.Creature)
            {
                throw new System.Exception("ProtocolGameUtility.ReadObjectInstance: Invalid type");
            }

            ObjectInstance instance = m_AppearanceStorage.CreateObjectInstance((uint)id, 0);

            if (!instance)
            {
                throw new System.Exception("ProtocolGameUtility.ReadObjectInstance: Invalid instance with id " + id);
            }

            instance.Marks.SetMark(Appearances.Marks.MarkType_Permenant, message.GetU8());

            if (instance.Type.IsStackable || instance.Type.IsLiquidContainer || instance.Type.IsSplash)
            {
                instance.Data = message.GetU8();
            }

            if (instance.Type.FrameGroups[(int)Proto.Appearances001.FrameGroupType.Idle].IsAnimation)
            {
                int phase = message.GetU8();
                instance.Phase = phase == 0 ? Appearances.AppearanceAnimator.PhaseAutomatic : phase;
            }

            return(instance);
        }
Пример #19
0
        private void ParseGraphicalEffect(InputMessage message)
        {
            var  position = message.GetPosition();
            byte effectId = message.GetU8();

            var effect = m_AppearanceStorage.CreateEffectInstance(effectId);

            if (!effect)
            {
                throw new System.Exception("Unknown effect id: " + effectId);
            }

            m_WorldMapStorage.AppendEffect(position, effect);
        }
Пример #20
0
        private void ParseMissleEffect(InputMessage message)
        {
            var  fromPosition = message.GetPosition();
            var  toPosition   = message.GetPosition();
            byte missleId     = message.GetU8();

            var missle = m_AppearanceStorage.CreateMissileInstance(missleId, fromPosition, toPosition);

            if (!missle)
            {
                throw new System.Exception("Unknown missle id: " + missleId);
            }

            m_WorldMapStorage.AppendEffect(fromPosition, missle);
        }
Пример #21
0
        private void ParseCreatureShield(InputMessage message)
        {
            uint creatureId = message.GetU32();
            byte partyFlag  = message.GetU8();

            var creature = m_CreatureStorage.GetCreature(creatureId);

            if (!creature)
            {
                throw new System.Exception("ProtocolGame.ParseCreatureShield: Unknown creature id: " + creatureId);
            }
            else
            {
                creature.SetPartyFlag((PartyFlags)partyFlag);
            }
        }
Пример #22
0
        private void ParseCreatureHealth(InputMessage message)
        {
            uint creatureId    = message.GetU32();
            byte healthPercent = message.GetU8();

            var creature = m_CreatureStorage.GetCreature(creatureId);

            if (!creature)
            {
                throw new System.Exception("ProtocolGame.ParseCreatureHealth: Unknown creature id: " + creatureId);
            }
            else
            {
                creature.SetSkill(SkillTypes.HealthPercent, healthPercent);
                m_CreatureStorage.InvalidateOpponents();
            }
        }
Пример #23
0
        private void ParseContainerRemoveItem(InputMessage message)
        {
            byte   containerId = message.GetU8();
            ushort slot        = message.GetU16();

            ushort itemId = message.GetU16();

            Appearances.ObjectInstance item;
            if (itemId != 0)
            {
                item = ReadObjectInstance(message);
            }
            else
            {
                item = null;
            }
        }
Пример #24
0
        private void ParsePlayerResource(InputMessage message)
        {
            byte  type    = message.GetU8();
            ulong balance = message.GetU64();

            switch (type)
            {
            case (int)ResourceTypes.BankGold:
                //m_Player.BankGold = balance;
                break;

            case (int)ResourceTypes.InventoryGold:
                //m_Player.InventoryGold = balance;
                break;

            case (int)ResourceTypes.PreyBonusRerolls:
                //PreyManager.getInstance().bonusRerollAmount = _loc3_;
                break;
            }
        }
Пример #25
0
        private void ParseCreatureType(InputMessage message)
        {
            uint creatureId = message.GetU32();
            byte type       = message.GetU8();
            uint master     = 0;

            if (type == (int)CreatureTypes.Summon)
            {
                master = message.GetU32();
            }

            var creature = m_CreatureStorage.GetCreature(creatureId);

            if (!creature)
            {
                throw new System.Exception("ProtocolGame.ParseCreatureType: Unknown creature id: " + creatureId);
            }
            else
            {
                creature.Type = (CreatureTypes)type;
                creature.SetSummonerID(master);
            }
        }
Пример #26
0
        private void ParsePlayerSkills(InputMessage message)
        {
            SkillTypes[] skills = new SkillTypes[] {
                SkillTypes.Fist,
                SkillTypes.Club,
                SkillTypes.Sword,
                SkillTypes.Axe,
                SkillTypes.Distance,
                SkillTypes.Shield,
                SkillTypes.Fishing
            };
            SkillTypes[] specialSkills = new SkillTypes[] {
                SkillTypes.CriticalHitChance,
                SkillTypes.CriticalHitDamage,
                SkillTypes.LifeLeechChance,
                SkillTypes.LifeLeechAmount,
                SkillTypes.ManaLeechChance,
                SkillTypes.ManaLeechAmount
            };

            foreach (var skill in skills)
            {
                int level      = message.GetU16();
                int baseLevel  = message.GetU16();
                int percentage = message.GetU8();

                m_Player.SetSkill(skill, level, baseLevel, percentage);
            }

            foreach (var skill in specialSkills)
            {
                int level     = message.GetU16();
                int baseLevel = message.GetU16();

                m_Player.SetSkill(skill, level, baseLevel);
            }
        }
Пример #27
0
        private void ParseTalk(InputMessage message)
        {
            uint   statementID  = message.GetU32();
            string speaker      = message.GetString();
            ushort speakerLevel = message.GetU16();

            MessageModes mode = (MessageModes)message.GetU8();

            Vector3Int?absolutePosition = null;

            Utility.UnionStrInt channelID = null;

            switch (mode)
            {
            case MessageModes.Say:
            case MessageModes.Whisper:
            case MessageModes.Yell:
                absolutePosition = message.GetPosition();
                channelID        = Chat.ChatStorage.LocalChannelID;
                break;

            case MessageModes.PrivateFrom:
                channelID = speaker;
                break;

            case MessageModes.Channel:
            case MessageModes.ChannelHighlight:
                channelID = message.GetU16();
                break;

            case MessageModes.Spell:
                absolutePosition = message.GetPosition();
                channelID        = Chat.ChatStorage.LocalChannelID;
                break;

            case MessageModes.NpcFromStartBlock:
                absolutePosition = message.GetPosition();
                break;

            case MessageModes.GamemasterBroadcast:
                break;

            case MessageModes.GamemasterChannel:
                channelID = message.GetU16();
                break;

            case MessageModes.GamemasterPrivateFrom:
                channelID = speaker;
                break;

            case MessageModes.BarkLow:
            case MessageModes.BarkLoud:
                absolutePosition = message.GetPosition();
                channelID        = -1;
                break;

            case MessageModes.Game:
                break;

            default:
                throw new System.Exception("ProtocolGame.ParseTalk: invalid message mode.");
            }

            string text = message.GetString();

            if (mode != MessageModes.NpcFromStartBlock && mode != MessageModes.NpcFrom)
            {
                try {
                    m_WorldMapStorage.AddOnscreenMessage(absolutePosition, (int)statementID, speaker, speakerLevel, mode, text);
                    m_ChatStorage.AddChannelMessage(channelID, (int)statementID, speaker, speakerLevel, mode, text);
                } catch (System.Exception e) {
                    throw new System.Exception("ProtocolGame.ParseTalk: Failed to add message: " + e.Message + "\n" + e.StackTrace);
                }
            }
            else if (mode == MessageModes.NpcFromStartBlock)
            {
                m_MessageStorage.StartMessageBlock(speaker, absolutePosition, text);
            }
            else if (mode == MessageModes.NpcFrom)
            {
                m_MessageStorage.AddTextToBlock(speaker, text);
            }
        }
Пример #28
0
 private void ParseCloseContainer(InputMessage message)
 {
     byte containerId = message.GetU8();
 }
Пример #29
0
        private void ParseTextMessage(InputMessage message)
        {
            MessageModes mode = (MessageModes)message.GetU8();

            try {
                switch (mode)
                {
                case MessageModes.ChannelManagment:
                    int    channelID = message.GetU16();
                    string text      = message.GetString();
                    // TODO name filter
                    //var regex = new System.Text.RegularExpressions.Regex(@"^(.+?) invites you to |^You have been excluded from the channel ([^']+)'s Channel\.$");
                    //var match = regex.Match(text);
                    //string speaker = match != null && match.Success ? match.Value : null;

                    m_WorldMapStorage.AddOnscreenMessage(null, -1, null, 0, mode, text);
                    m_ChatStorage.AddChannelMessage(channelID, -1, null, 0, mode, text);
                    break;

                case MessageModes.Guild:
                case MessageModes.PartyManagement:
                case MessageModes.Party:
                    channelID = message.GetU16();
                    text      = message.GetString();
                    m_WorldMapStorage.AddOnscreenMessage(null, -1, null, 0, mode, text);
                    m_ChatStorage.AddChannelMessage(channelID, -1, null, 0, mode, text);
                    break;

                case MessageModes.Login:
                case MessageModes.Admin:
                case MessageModes.Game:
                case MessageModes.GameHighlight:
                case MessageModes.Failure:
                case MessageModes.Look:
                case MessageModes.Status:
                case MessageModes.Loot:
                case MessageModes.TradeNpc:
                case MessageModes.HotkeyUse:
                    channelID = -1;
                    text      = message.GetString();
                    m_WorldMapStorage.AddOnscreenMessage(null, -1, null, 0, mode, text);
                    m_ChatStorage.AddChannelMessage(channelID, -1, null, 0, mode, text);
                    break;

                case MessageModes.Market:
                    text = message.GetString();
                    // TODO: market
                    break;

                case MessageModes.Report:
                    // TODO
                    //ReportWidget.s_ReportTimestampReset();
                    text = message.GetString();
                    m_WorldMapStorage.AddOnscreenMessage(null, -1, null, 0, mode, text);
                    m_ChatStorage.AddChannelMessage(-1, -1, null, 0, mode, text);
                    break;

                case MessageModes.DamageDealed:
                case MessageModes.DamageReceived:
                case MessageModes.DamageOthers:
                    Vector3Int position = message.GetPosition();
                    uint       value    = message.GetU32();
                    uint       color    = message.GetU8();
                    if (value > 0)
                    {
                        m_WorldMapStorage.AddOnscreenMessage(position, -1, null, 0, mode, (int)value, color);
                    }

                    value = message.GetU32();
                    color = message.GetU8();
                    if (value > 0)
                    {
                        m_WorldMapStorage.AddOnscreenMessage(position, -1, null, 0, mode, (int)value, color);
                    }

                    text = message.GetString();
                    m_ChatStorage.AddChannelMessage(-1, -1, null, 0, mode, text);
                    break;

                case MessageModes.Heal:
                case MessageModes.Mana:
                case MessageModes.Exp:
                case MessageModes.HealOthers:
                case MessageModes.ExpOthers:
                    position = message.GetPosition();
                    value    = message.GetU32();
                    color    = message.GetU8();
                    m_WorldMapStorage.AddOnscreenMessage(position, -1, null, 0, mode, (int)value, color);

                    text = message.GetString();
                    m_ChatStorage.AddChannelMessage(-1, -1, null, 0, mode, text);
                    break;

                default:
                    throw new System.Exception("Invalid message mode " + mode + ".");
                }
            } catch (System.Exception e) {
                throw new System.Exception("Connection.readSMESSAGE: Failed to add message of type " + mode + ": " + e.Message + "\n" + e.StackTrace);
            }
        }
Пример #30
0
        private Creatures.Creature ReadCreatureInstance(InputMessage message, int type          = -1,
                                                        UnityEngine.Vector3Int?absolutePosition = null)
        {
            if (type == -1)
            {
                type = message.GetU16();
            }

            if (type != AppearanceInstance.Creature && type != AppearanceInstance.OutdatedCreature && type != AppearanceInstance.UnknownCreature)
            {
                throw new System.Exception("ProtocolGame.ReadCreatureInstance: Invalid creature type");
            }

            var gameManager = OpenTibiaUnity.GameManager;

            Creatures.Creature creature;
            switch (type)
            {
            case AppearanceInstance.UnknownCreature:
            case AppearanceInstance.OutdatedCreature:
                if (type == AppearanceInstance.UnknownCreature)
                {
                    uint removeID = message.GetU32();
                    uint newID    = message.GetU32();
                    int  creatureType;

                    if (gameManager.ClientVersion >= 910)
                    {
                        creatureType = message.GetU8();
                    }
                    else
                    {
                        if (newID >= Constants.PlayerStartID && newID < Constants.PlayerEndID)
                        {
                            creatureType = (int)CreatureTypes.Player;
                        }
                        else if (newID >= Constants.MonsterStartID && newID < Constants.MonsterEndID)
                        {
                            creatureType = (int)CreatureTypes.Monster;
                        }
                        else
                        {
                            creatureType = (int)CreatureTypes.NPC;
                        }
                    }

                    if (newID == m_Player.ID)
                    {
                        creature = m_Player;
                    }
                    else
                    {
                        creature = new Creatures.Creature(newID);
                    }

                    creature = m_CreatureStorage.ReplaceCreature(creature, removeID);
                    if (!creature)
                    {
                        throw new System.Exception("ProtocolGame.ReadCreatureInstance: Failed to append creature.");
                    }

                    creature.Type = (CreatureTypes)creatureType;

                    creature.Name = message.GetString();
                }
                else
                {
                    creature = m_CreatureStorage.GetCreature(message.GetU32());
                    if (!creature)
                    {
                        throw new System.Exception("ProtocolGame.ReadCreatureInstance: Outdated creature not found.");
                    }
                }

                creature.SetSkill(SkillTypes.HealthPercent, message.GetU8());
                creature.Direction   = (Directions)message.GetU8();
                creature.Outfit      = ReadCreatureOutfit(message, creature.Outfit);
                creature.MountOutfit = ReadMountOutfit(message, creature.MountOutfit);
                creature.Brightness  = message.GetU8();
                creature.LightColor  = Colors.ColorFrom8Bit(message.GetU8());
                creature.SetSkill(SkillTypes.Speed, message.GetU16());
                creature.SetPKFlag((PKFlags)message.GetU8());
                creature.SetPartyFlag((PartyFlags)message.GetU8());

                if (gameManager.GetFeature(GameFeatures.GameCreatureEmblems) && type == AppearanceInstance.UnknownCreature)
                {
                    creature.SetGuildFlag((GuildFlags)message.GetU8());
                }

                if (gameManager.GetFeature(GameFeatures.GameThingMarks))
                {
                    creature.Type = (CreatureTypes)message.GetU8();
                }

                // TODO, idk what version this respects to //
                //if (creature.IsSummon) {
                //    creature.SetSummonerID(message.GetU32());
                //} else {
                //    creature.SetSummonerID(0);
                //}

                if (gameManager.GetFeature(GameFeatures.GameCreatureIcons))
                {
                    creature.SetSpeechCategory((SpeechCategories)message.GetU8());
                }

                if (gameManager.GetFeature(GameFeatures.GameThingMarks))
                {
                    creature.Marks.SetMark(Appearances.Marks.MarkType_Permenant, message.GetU8());

                    // TODO insspection state
                    //message.GetU8(); // inspection state

                    creature.NumberOfPvPHelpers = message.GetU16();
                }

                if (gameManager.ClientVersion >= 854)
                {
                    creature.Unpassable = message.GetU8() != 0;
                }
                break;

            case AppearanceInstance.Creature:
                creature = m_CreatureStorage.GetCreature(message.GetU32());
                if (!creature)
                {
                    throw new System.Exception("ProtocolGame.ReadCreatureInstance: Known creature not found.");
                }

                creature.Direction = (Directions)message.GetU8();

                if (gameManager.ClientVersion >= 953)
                {
                    creature.Unpassable = message.GetU8() != 0;
                }
                break;

            default:
                throw new System.Exception("ProtocolGame.ReadCreatureInstance: unknown creature identity type.");
            }

            if (absolutePosition.HasValue)
            {
                creature.Position = absolutePosition.Value;
            }

            m_CreatureStorage.MarkOpponentVisible(creature, true);
            m_CreatureStorage.InvalidateOpponents();
            return(creature);
        }