コード例 #1
0
ファイル: ObdCoder.cs プロジェクト: JoseEduardo/open-tibia
 private static byte[] EncodeV3(ThingData data)
 {
     throw new NotImplementedException();
 }
コード例 #2
0
ファイル: ObdCoder.cs プロジェクト: JoseEduardo/open-tibia
        private static byte[] EncodeV2(ThingData data)
        {
            using (BinaryWriter writer = new BinaryWriter(new MemoryStream()))
            {
                // write obd version
                writer.Write((ushort)ObdVersion.Version2);

                // write client version
                writer.Write((ushort)DatFormat.Format_1050);

                // write category
                writer.Write((byte)data.Category);

                // skipping the texture patterns position.
                int patternsPosition = (int)writer.BaseStream.Position;
                writer.Seek(4, SeekOrigin.Current);

                if (!WriteProperties(data.ThingType, writer))
                {
                    return null;
                }

                // write the texture patterns position.
                int position = (int)writer.BaseStream.Position;
                writer.Seek(patternsPosition, SeekOrigin.Begin);
                writer.Write((uint)writer.BaseStream.Position);
                writer.Seek(position, SeekOrigin.Begin);

                FrameGroup group = data.GetFrameGroup(FrameGroupType.Default);

                writer.Write(group.Width);
                writer.Write(group.Height);

                if (group.Width > 1 || group.Height > 1)
                {
                    writer.Write(group.ExactSize);
                }

                writer.Write(group.Layers);
                writer.Write(group.PatternX);
                writer.Write(group.PatternY);
                writer.Write(group.PatternZ);
                writer.Write(group.Frames);

                if (group.IsAnimation)
                {
                    writer.Write((byte)group.AnimationMode);
                    writer.Write(group.LoopCount);
                    writer.Write(group.StartFrame);

                    for (int i = 0; i < group.Frames; i++)
                    {
                        writer.Write((uint)group.FrameDurations[i].Minimum);
                        writer.Write((uint)group.FrameDurations[i].Maximum);
                    }
                }

                Sprite[] sprites = data.Sprites[FrameGroupType.Default];
                for (int i = 0; i < sprites.Length; i++)
                {
                    Sprite sprite = sprites[i];
                    byte[] pixels = sprite.GetARGBPixels();
                    writer.Write(sprite.ID);
                    writer.Write(pixels);
                }

                return LZMACoder.Compress(((MemoryStream)writer.BaseStream).ToArray());
            }
        }
コード例 #3
0
ファイル: ObdCoder.cs プロジェクト: JoseEduardo/open-tibia
        private static byte[] EncodeV1(ThingData data)
        {
            using (BinaryWriter writer = new BinaryWriter(new MemoryStream()))
            {
                // write client version
                writer.Write((ushort)DatFormat.Format_1010);

                // write category
                string category = string.Empty;
                switch (data.Category)
                {
                    case ThingCategory.Item:
                        category = "item";
                        break;

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

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

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

                writer.Write((ushort)category.Length);
                writer.Write(Encoding.UTF8.GetBytes(category));

                if (!ThingTypeSerializer.WriteProperties(data.ThingType, DatFormat.Format_1010, writer))
                {
                    return null;
                }

                FrameGroup group = data.GetFrameGroup(FrameGroupType.Default);

                writer.Write(group.Width);
                writer.Write(group.Height);

                if (group.Width > 1 || group.Height > 1)
                {
                    writer.Write(group.ExactSize);
                }

                writer.Write(group.Layers);
                writer.Write(group.PatternX);
                writer.Write(group.PatternY);
                writer.Write(group.PatternZ);
                writer.Write(group.Frames);

                Sprite[] sprites = data.Sprites[FrameGroupType.Default];
                for (int i = 0; i < sprites.Length; i++)
                {
                    Sprite sprite = sprites[i];
                    byte[] pixels = sprite.GetARGBPixels();
                    writer.Write((uint)sprite.ID);
                    writer.Write((uint)pixels.Length);
                    writer.Write(pixels);
                }

                return LZMACoder.Compress(((MemoryStream)writer.BaseStream).ToArray());
            }
        }
コード例 #4
0
ファイル: ObdCoder.cs プロジェクト: JoseEduardo/open-tibia
 public static bool Save(string path, ThingData data)
 {
     return Save(path, data, ObdVersion.Version2);
 }
コード例 #5
0
ファイル: ObdCoder.cs プロジェクト: JoseEduardo/open-tibia
        public static bool Save(string path, ThingData data, ObdVersion version)
        {
            if (data == null)
            {
                return false;
            }

            byte[] bytes = Encode(data, version);
            if (bytes == null)
            {
                return false;
            }

            using (BinaryWriter writer = new BinaryWriter(new FileStream(path, FileMode.Create)))
            {
                writer.Write(bytes);
                writer.Close();
            }

            return true;
        }
コード例 #6
0
ファイル: ObdCoder.cs プロジェクト: JoseEduardo/open-tibia
        public static byte[] Encode(ThingData data, ObdVersion obdVersion)
        {
            if (obdVersion == ObdVersion.Version3)
            {
                return EncodeV3(data);
            }
            else if (obdVersion == ObdVersion.Version2)
            {
                return EncodeV2(data);
            }
            else if (obdVersion == ObdVersion.Version1)
            {
                return EncodeV1(data);
            }

            return null;
        }