Ejemplo n.º 1
0
        public static ThingType Create(ushort id, ThingCategory category)
        {
            if (category == ThingCategory.Invalid)
            {
                throw new ArgumentException("Invalid category.");
            }

            ThingType thing = new ThingType(id, category);

            if (category == ThingCategory.Outfit)
            {
                for (int i = 0; i < 2; i++)
                {
                    FrameGroup group = FrameGroup.Create();
                    group.PatternX       = 4; // directions
                    group.Frames         = 3; // animations
                    group.IsAnimation    = true;
                    group.SpriteIDs      = new uint[group.GetTotalSprites()];
                    group.FrameDurations = new FrameDuration[group.Frames];

                    for (int f = 0; f < group.Frames; f++)
                    {
                        group.FrameDurations[f] = new FrameDuration(category);
                    }

                    thing.SetFrameGroup((FrameGroupType)i, group);
                }
            }
            else
            {
                FrameGroup group = FrameGroup.Create();

                if (category == ThingCategory.Missile)
                {
                    group.PatternX  = 3;
                    group.PatternY  = 3;
                    group.SpriteIDs = new uint[group.GetTotalSprites()];
                }

                thing.SetFrameGroup(FrameGroupType.Default, group);
            }

            return(thing);
        }
Ejemplo n.º 2
0
        public static bool ReadTexturePatterns(ThingType thing, ClientFeatures features, BinaryReader reader)
        {
            bool patternZEnabled       = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ;
            bool extendedEnabled       = (features & ClientFeatures.Extended) == ClientFeatures.Extended;
            bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations;
            bool frameGroupsEnabled    = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups;

            byte groupCount = 1;

            if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
            {
                groupCount = reader.ReadByte();
            }

            for (byte k = 0; k < groupCount; k++)
            {
                FrameGroupType groupType = FrameGroupType.Default;
                if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
                {
                    groupType = (FrameGroupType)reader.ReadByte();
                }

                FrameGroup group = new FrameGroup();

                group.Width  = reader.ReadByte();
                group.Height = reader.ReadByte();

                if (group.Width > 1 || group.Height > 1)
                {
                    group.ExactSize = reader.ReadByte();
                }
                else
                {
                    group.ExactSize = Sprite.DefaultSize;
                }

                group.Layers   = reader.ReadByte();
                group.PatternX = reader.ReadByte();
                group.PatternY = reader.ReadByte();
                group.PatternZ = patternZEnabled ? reader.ReadByte() : (byte)1;
                group.Frames   = reader.ReadByte();

                if (frameDurationsEnabled && group.Frames > 1)
                {
                    group.IsAnimation    = true;
                    group.AnimationMode  = (AnimationMode)reader.ReadByte();
                    group.LoopCount      = reader.ReadInt32();
                    group.StartFrame     = reader.ReadSByte();
                    group.FrameDurations = new FrameDuration[group.Frames];

                    for (int i = 0; i < group.Frames; i++)
                    {
                        uint minimum = reader.ReadUInt32();
                        uint maximum = reader.ReadUInt32();
                        group.FrameDurations[i] = new FrameDuration(minimum, maximum);
                    }
                }

                int totalSprites = group.GetTotalSprites();
                if (totalSprites > 4096)
                {
                    throw new Exception("A thing type has more than 4096 sprites.");
                }

                group.SpriteIDs = new uint[totalSprites];

                if (extendedEnabled)
                {
                    for (int i = 0; i < totalSprites; i++)
                    {
                        group.SpriteIDs[i] = reader.ReadUInt32();
                    }
                }
                else
                {
                    for (int i = 0; i < totalSprites; i++)
                    {
                        group.SpriteIDs[i] = reader.ReadUInt16();
                    }
                }

                thing.SetFrameGroup(groupType, group);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static ThingType Create(ushort id, ThingCategory category)
        {
            if (category == ThingCategory.Invalid)
            {
                throw new ArgumentException("Invalid category.");
            }

            ThingType thing = new ThingType(id, category);

            if (category == ThingCategory.Outfit)
            {
                for (int i = 0; i < 2; i++)
                {
                    FrameGroup group = FrameGroup.Create();
                    group.PatternX = 4; // directions
                    group.Frames = 3;   // animations
                    group.IsAnimation = true;
                    group.SpriteIDs = new uint[group.GetTotalSprites()];
                    group.FrameDurations = new FrameDuration[group.Frames];

                    for (int f = 0; f < group.Frames; f++)
                    {
                        group.FrameDurations[f] = new FrameDuration(category);
                    }

                    thing.SetFrameGroup((FrameGroupType)i, group);
                }
            }
            else
            {
                FrameGroup group = FrameGroup.Create();

                if (category == ThingCategory.Missile)
                {
                    group.PatternX = 3;
                    group.PatternY = 3;
                    group.SpriteIDs = new uint[group.GetTotalSprites()];
                }

                thing.SetFrameGroup(FrameGroupType.Default, group);
            }

            return thing;
        }
Ejemplo n.º 4
0
        public static bool ReadTexturePatterns(ThingType thing, ClientFeatures features, BinaryReader reader)
        {
            bool patternZEnabled = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ;
            bool extendedEnabled = (features & ClientFeatures.Extended) == ClientFeatures.Extended;
            bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations;
            bool frameGroupsEnabled = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups;

            byte groupCount = 1;
            if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
            {
                groupCount = reader.ReadByte();
            }

            for (byte k = 0; k < groupCount; k++)
            {
                FrameGroupType groupType = FrameGroupType.Default;
                if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit)
                {
                    groupType = (FrameGroupType)reader.ReadByte();
                }

                FrameGroup group = new FrameGroup();

                group.Width = reader.ReadByte();
                group.Height = reader.ReadByte();

                if (group.Width > 1 || group.Height > 1)
                {
                    group.ExactSize = reader.ReadByte();
                }
                else
                {
                    group.ExactSize = Sprite.DefaultSize;
                }

                group.Layers = reader.ReadByte();
                group.PatternX = reader.ReadByte();
                group.PatternY = reader.ReadByte();
                group.PatternZ = patternZEnabled ? reader.ReadByte() : (byte)1;
                group.Frames = reader.ReadByte();

                if (frameDurationsEnabled && group.Frames > 1)
                {
                    group.IsAnimation = true;
                    group.AnimationMode = (AnimationMode)reader.ReadByte();
                    group.LoopCount = reader.ReadInt32();
                    group.StartFrame = reader.ReadSByte();
                    group.FrameDurations = new FrameDuration[group.Frames];

                    for (int i = 0; i < group.Frames; i++)
                    {
                        uint minimum = reader.ReadUInt32();
                        uint maximum = reader.ReadUInt32();
                        group.FrameDurations[i] = new FrameDuration(minimum, maximum);
                    }
                }

                int totalSprites = group.GetTotalSprites();
                if (totalSprites > 4096)
                {
                    throw new Exception("A thing type has more than 4096 sprites.");
                }

                group.SpriteIDs = new uint[totalSprites];

                if (extendedEnabled)
                {
                    for (int i = 0; i < totalSprites; i++)
                    {
                        group.SpriteIDs[i] = reader.ReadUInt32();
                    }
                }
                else
                {
                    for (int i = 0; i < totalSprites; i++)
                    {
                        group.SpriteIDs[i] = reader.ReadUInt16();
                    }
                }

                thing.SetFrameGroup(groupType, group);
            }

            return true;
        }
Ejemplo n.º 5
0
        private static ThingData DecodeV1(BinaryReader reader)
        {
            reader.BaseStream.Position = 0;

            Console.WriteLine(reader.ReadUInt16());

            ushort nameLength = reader.ReadUInt16();
            byte[] buffer = reader.ReadBytes(nameLength);
            string categoryStr = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
            ThingCategory category = ThingCategory.Invalid;

            switch (categoryStr)
            {
                case "item":
                    category = ThingCategory.Item;
                    break;

                case "outfit":
                    category = ThingCategory.Outfit;
                    break;

                case "effect":
                    category = ThingCategory.Effect;
                    break;

                case "missile":
                    category = ThingCategory.Missile;
                    break;
            }

            ThingType thing = new ThingType(category);

            if (!ThingTypeSerializer.ReadProperties(thing, DatFormat.Format_1010, reader))
            {
                return null;
            }

            FrameGroup group = new FrameGroup();

            group.Width = reader.ReadByte();
            group.Height = reader.ReadByte();

            if (group.Width > 1 || group.Height > 1)
            {
                group.ExactSize = reader.ReadByte();
            }
            else
            {
                group.ExactSize = Sprite.DefaultSize;
            }

            group.Layers = reader.ReadByte();
            group.PatternX = reader.ReadByte();
            group.PatternY = reader.ReadByte();
            group.PatternZ = reader.ReadByte();
            group.Frames = reader.ReadByte();

            if (group.Frames > 1)
            {
                group.IsAnimation = true;
                group.AnimationMode = AnimationMode.Asynchronous;
                group.LoopCount = 0;
                group.StartFrame = 0;
                group.FrameDurations = new FrameDuration[group.Frames];

                for (byte i = 0; i < group.Frames; i++)
                {
                    group.FrameDurations[i] = new FrameDuration(category);
                }
            }

            int totalSprites = group.GetTotalSprites();
            if (totalSprites > 4096)
            {
                throw new Exception("The ThingData has more than 4096 sprites.");
            }

            group.SpriteIDs = new uint[totalSprites];
            SpriteGroup spriteGroup = new SpriteGroup();
            Sprite[] sprites = new Sprite[totalSprites];

            for (int i = 0; i < totalSprites; i++)
            {
                uint spriteID = reader.ReadUInt32();
                group.SpriteIDs[i] = spriteID;

                uint dataSize = reader.ReadUInt32();
                if (dataSize > Sprite.PixelsDataSize)
                {
                    throw new Exception("Invalid sprite data size.");
                }

                byte[] pixels = reader.ReadBytes((int)dataSize);

                Sprite sprite = new Sprite(spriteID, true);
                sprite.SetPixelsARGB(pixels);
                sprites[i] = sprite;
            }

            thing.SetFrameGroup(FrameGroupType.Default, group);
            spriteGroup.Add(FrameGroupType.Default, sprites);
            return new ThingData(thing, spriteGroup);
        }