Example #1
0
        public ClientState(PacketStream InStream)
        {
            this.InStream = InStream;
            FileStream datFile = new FileStream("./Tibia.dat", FileMode.Open);
            FileStream sprFile = new FileStream("./Tibia.spr", FileMode.Open);

            GameData = new TibiaGameData(datFile, sprFile);
            Protocol = new TibiaGameProtocol(GameData);
            Viewport = new ClientViewport(GameData, Protocol);
        }
Example #2
0
        public ClientViewport(TibiaGameData GameData, TibiaGameProtocol Protocol)
        {
            this.GameData    = GameData;
            this.Protocol    = Protocol;
            DefaultChannel   = new ClientChannel(0, "Default");
            this.Channels[0] = DefaultChannel;

            for (int i = 0; i < 12; ++i)
            {
                Inventory.Add(null);
            }

            Protocol.PlayerLogin.Add(OnPlayerLogin);
            Protocol.UpdateSkills.Add(OnUpdateSkills);
            Protocol.UpdateStats.Add(OnUpdateStats);
            Protocol.PlayerIcons.Add(OnPlayerIcons);

            Protocol.MapDescription.Add(OnMapDescription);
            Protocol.MoveNorth.Add(OnMapDescription);
            Protocol.MoveWest.Add(OnMapDescription);
            Protocol.MoveSouth.Add(OnMapDescription);
            Protocol.MoveEast.Add(OnMapDescription);
            Protocol.FloorUp.Add(OnMapDescription);
            Protocol.FloorDown.Add(OnMapDescription);

            Protocol.AddThing.Add(OnAddThing);
            Protocol.RemoveThing.Add(OnRemoveThing);
            Protocol.RefreshTile.Add(OnRefreshTile);
            Protocol.TransformThing.Add(OnTransformThing);

            Protocol.CreatureMove.Add(OnCreatureMove);
            Protocol.CreatureTurn.Add(OnCreatureTurn);
            Protocol.CreatureSpeed.Add(OnCreatureSpeed);
            Protocol.CreatureShield.Add(OnCreatureShield);
            Protocol.CreatureSkull.Add(OnCreatureSkull);
            Protocol.CreatureHealth.Add(OnCreatureHealth);
            Protocol.CreatureTurn.Add(OnCreatureLight);

            Protocol.CreatureSpeak.Add(OnCreatureSpeak);
            Protocol.OpenChannel.Add(OnOpenChannel);
            Protocol.OpenPrivateChat.Add(OnOpenPrivateChat);
            Protocol.TextMessage.Add(OnTextMessage);

            Protocol.VIPState.Add(OnVIPState);
            Protocol.VIPLogin.Add(OnVIPLogin);
            Protocol.VIPLogout.Add(OnVIPLogout);

            Protocol.UpdateInventory.Add(OnUpdateInventory);
            Protocol.ClearInventory.Add(OnClearInventory);
            Protocol.OpenContainer.Add(OnOpenContainer);
            Protocol.CloseContainer.Add(OnCloseContainer);
            Protocol.ContainerAddItem.Add(OnContainerAddItem);
            Protocol.ContainerRemoveItem.Add(OnContainerRemoveItem);
            Protocol.ContainerTransformItem.Add(OnContainerTransformItem);
        }
Example #3
0
        /// <summary>
        /// Loads all mapped handlers from the file.
        /// </summary>
        /// <param name="File"></param>
        public TibiaGamePacketParserFactory(Stream File, TibiaGameData data)
        {
            GameData = data;
            try
            {
                System.Xml.XmlDocument XMLData = new System.Xml.XmlDocument();
                XMLData.Load(File);

                System.Xml.XmlNodeList Versions = XMLData.GetElementsByTagName("TibiaVersion");
                foreach (System.Xml.XmlNode versionNode in Versions)
                {
                    int version = int.Parse(versionNode.Attributes["id"].InnerText);
                    if (version != GameData.Version)
                    {
                        continue;
                    }

                    foreach (System.Xml.XmlNode packetNode in versionNode.ChildNodes)
                    {
                        if (packetNode.LocalName == "Packet")
                        {
                            PacketParser ph = new PacketParser();
                            string       n  = packetNode.Attributes["type"].InnerText;
                            if (!int.TryParse(packetNode.Attributes["type"].InnerText.Substring(2),
                                              System.Globalization.NumberStyles.HexNumber,
                                              System.Globalization.CultureInfo.InvariantCulture,
                                              out ph.type))
                            {
                                continue;
                            }

                            ph.name   = packetNode.Attributes["parser"].InnerText;
                            ph.parser = GetPacketParser(ph.name);
                            AllHandlers.Add(ph);
                        }
                    }
                }
            }
            catch (System.Xml.XmlException xmlException)
            {
                Log.Error("XML error when parsing internal version table: " + xmlException.Message);
            }
            catch (System.ArgumentException argException)
            {
                Log.Error("Conversion error when parsing internal version table: " + argException.Message);
            }
        }
Example #4
0
 public GameRenderer(TibiaGameData GameData)
 {
     this.Device   = UIContext.Graphics.GraphicsDevice;
     this.GameData = GameData;
 }
Example #5
0
 public MagicEffect(TibiaGameData GameData, int ID)
 {
     this.ID       = ID;
     Sprite        = GameData.GetEffectSprite(ID);
     this.Duration = Sprite.AnimationLength / 10.0;
 }
Example #6
0
 public GameImage(TibiaGameData GameData, int ID)
 {
     this.GameData = GameData;
     this.ID       = ID;
 }
Example #7
0
        public DistanceEffect(TibiaGameData GameData, int ID, MapPosition From, MapPosition To)
        {
            this.ID = ID;
            Sprite  = GameData.GetDistanceEffectSprite(ID);

            int dx = To.X - From.X;
            int dy = To.Y - From.Y;

            /*
             * 0 = NW
             * 1 = N
             * 2 = NE
             * 3 = W
             * 4 = C
             * 5 = E
             * 6 = SW
             * 7 = S
             * 8 = SE
             * */

            double tan = 10;

            if (dx != 0)
            {
                tan = (float)dy / (float)dx;
            }

            if (Math.Abs(tan) < 0.4142f)
            {
                if (dx > 0)
                {
                    Frame = 5;            // EAST
                }
                else
                {
                    Frame = 3;// WEST
                }
            }
            else if (Math.Abs(tan) < 2.4142f)
            {
                if (tan > 0)
                {
                    if (dy > 0)
                    {
                        Frame = 8;// SOUTH EAST
                    }
                    else
                    {
                        Frame = 0;// NORTH WEST;
                    }
                }
                else
                { //tan < 0
                    if (dx > 0)
                    {
                        Frame = 2;// NORTH EAST;
                    }
                    else
                    {
                        Frame = 6;// SOUTH WEST
                    }
                }
            }
            else
            {
                if (dy > 0)
                {
                    Frame = 7;// SOUTH
                }
                else
                {
                    Frame = 1;// NORTH
                }
            }

            Duration = Math.Sqrt(dx * dx + dy * dy) / 10;
            Offset   = new Vector2(
                (From.X - Math.Max(From.X, To.X)) * 32,
                (From.Y - Math.Max(From.Y, To.Y)) * 32
                );
            Speed = new Vector2(Math.Sign(dx) * 160, Math.Sign(dy) * 160);
            //Speed -= Offset;
        }
Example #8
0
        /// <summary>
        /// Create a Protocol given a Game Data object (which contains the version.
        /// </summary>
        /// <param name="data"></param>
        public TibiaGameProtocol(TibiaGameData data)
        {
            Stream f = Assembly.GetExecutingAssembly().GetManifestResourceStream("Tibia.Windows.Client.TibiaProtocolMap.xml");

            Factory = new TibiaGamePacketParserFactory(f, data);

            AddPacketHandler("ErrorMessage", ErrorMessage);
            AddPacketHandler("MOTD", MOTD);
            AddPacketHandler("Ping", Ping);

            AddPacketHandler("CanReport", CanReport);
            AddPacketHandler("Death", Death);

            AddPacketHandler("UpdateInventory", UpdateInventory);
            AddPacketHandler("ClearInventory", ClearInventory);
            AddPacketHandler("OpenContainer", OpenContainer);
            AddPacketHandler("CloseContainer", CloseContainer);
            AddPacketHandler("ContainerAddItem", ContainerAddItem);
            AddPacketHandler("ContainerTransformItem", ContainerTransformItem);
            AddPacketHandler("ContainerRemoveItem", ContainerRemoveItem);

            AddPacketHandler("PlayerLogin", PlayerLogin);
            AddPacketHandler("UpdateStats", UpdateStats);
            AddPacketHandler("UpdateSkills", UpdateSkills);
            AddPacketHandler("PlayerIcons", PlayerIcons);
            AddPacketHandler("CancelAttack", CancelAttack);
            AddPacketHandler("CancelWalk", CancelWalk);

            AddPacketHandler("CreatureMove", CreatureMove);
            AddPacketHandler("CreatureHealth", CreatureHealth);
            AddPacketHandler("CreatureLight", CreatureLight);
            AddPacketHandler("CreatureRefresh", CreatureRefresh);
            AddPacketHandler("CreatureSpeed", CreatureSpeed);
            AddPacketHandler("CreatureSkull", CreatureSkull);
            AddPacketHandler("CreatureShield", CreatureShield);

            AddPacketHandler("CreatureSpeak", CreatureSpeak);
            AddPacketHandler("ChannelList", ChannelList);
            AddPacketHandler("OpenChannel", OpenChannel);
            AddPacketHandler("OpenPrivateChat", OpenPrivateChat);
            AddPacketHandler("TextMessage", TextMessage);

            AddPacketHandler("VIPState", VIPState);
            AddPacketHandler("VIPLogin", VIPLogin);
            AddPacketHandler("VIPLogout", VIPLogout);

            AddPacketHandler("WorldLight", WorldLight);
            AddPacketHandler("Effect", Effect);
            AddPacketHandler("AnimatedText", AnimatedText);
            AddPacketHandler("ShootEffect", ShootEffect);
            AddPacketHandler("SquareEffect", SquareEffect);

            AddPacketHandler("MoveNorth", MoveNorth);
            AddPacketHandler("MoveSouth", MoveSouth);
            AddPacketHandler("MoveEast", MoveEast);
            AddPacketHandler("MoveWest", MoveWest);
            AddPacketHandler("FloorUp", FloorUp);
            AddPacketHandler("FloorDown", FloorDown);

            AddPacketHandler("MapDescription", MapDescription);
            AddPacketHandler("RefreshTile", RefreshTile);
            AddPacketHandler("AddThing", AddThing);
            AddPacketHandler("TransformThing", TransformThing);
            AddPacketHandler("RemoveThing", RemoveThing);

            AddPacketHandler("RuleViolationChannel", RuleViolationChannel);
            AddPacketHandler("RuleViolationRemove", RuleViolationRemove);
            AddPacketHandler("RuleViolationCancel", RuleViolationCancel);
            AddPacketHandler("RuleViolationLock", RuleViolationLock);
        }