Пример #1
0
        public static AMK_Animation Read(byte[] bytes, int index, int offset, int nameOffset)
        {
            int dataCount  = BitConverter.ToInt32(bytes, offset + 4);
            int dataOffset = BitConverter.ToInt32(bytes, offset + 12);

            if (dataOffset == 0)
            {
                return(null);
            }

            AMK_Animation anim = new AMK_Animation();

            anim.ID        = index;
            anim.Keyframes = new List <AMK_Keyframe>();
            anim.Name      = StringEx.GetString(bytes, nameOffset, false, StringEx.EncodingType.ASCII, 32, true);
            anim.I_00      = BitConverter.ToInt32(bytes, offset + 0);
            anim.I_08      = BitConverter.ToInt32(bytes, offset + 8);

            for (int i = 0; i < dataCount; i++)
            {
                anim.Keyframes.Add(AMK_Keyframe.Read(bytes, dataOffset + (4 * i)));
            }

            return(anim);
        }
Пример #2
0
        public static AMK_File Read(byte[] bytes)
        {
            AMK_File amkFile = new AMK_File();

            //Header
            amkFile.I_06 = BitConverter.ToUInt16(bytes, 6);
            amkFile.I_08 = BitConverter.ToInt32(bytes, 8);
            amkFile.I_12 = BitConverter.ToInt32(bytes, 12);
            amkFile.I_16 = BitConverter.ToInt32(bytes, 16);

            int entryCount  = BitConverter.ToInt32(bytes, 20);
            int entryOffset = BitConverter.ToInt32(bytes, 24);
            int nameOffset  = BitConverter.ToInt32(bytes, 28);

            if (entryCount > 0)
            {
                amkFile.Animations = new List <AMK_Animation>();

                for (int i = 0; i < entryCount; i++)
                {
                    var anim = AMK_Animation.Read(bytes, i, entryOffset, nameOffset);

                    if (anim != null)
                    {
                        amkFile.Animations.Add(anim);
                    }

                    entryOffset += 16;
                    nameOffset  += 32;
                }
            }

            return(amkFile);
        }
Пример #3
0
        public byte[] Write()
        {
            List <byte> bytes = new List <byte>();

            int numEntries = NumEntries;

            //Header (32 bytes)
            bytes.AddRange(BitConverter.GetBytes(AMK_SIGNATURE));
            bytes.AddRange(BitConverter.GetBytes((ushort)32));
            bytes.AddRange(BitConverter.GetBytes(I_06));
            bytes.AddRange(BitConverter.GetBytes(I_08));
            bytes.AddRange(BitConverter.GetBytes(I_12));
            bytes.AddRange(BitConverter.GetBytes(I_16));
            bytes.AddRange(BitConverter.GetBytes(numEntries));
            bytes.AddRange(BitConverter.GetBytes(32)); //Entry offset
            bytes.AddRange(new byte[4]);               //Names offset

            List <int> entryOffsets = new List <int>();

            SortEntries();

            //Anim header
            for (int i = 0; i < numEntries; i++)
            {
                AMK_Animation anim = Animations.Find(a => a.ID == i);

                if (anim != null)
                {
                    //Anim exists
                    int keyframeCount = (anim.Keyframes != null) ? anim.Keyframes.Count : 0;

                    bytes.AddRange(BitConverter.GetBytes(anim.I_00));
                    bytes.AddRange(BitConverter.GetBytes(keyframeCount));
                    bytes.AddRange(BitConverter.GetBytes(anim.I_08));
                    entryOffsets.Add(bytes.Count);
                    bytes.AddRange(new byte[4]);
                }
                else
                {
                    //Anim is null, write dummy data
                    bytes.AddRange(new byte[16]);
                }
            }

            //Anim data
            int index = 0;

            for (int i = 0; i < numEntries; i++)
            {
                AMK_Animation anim = Animations.Find(a => a.ID == i);

                if (anim != null)
                {
                    bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), entryOffsets[index]);

                    int keyframeCount = (anim.Keyframes != null) ? anim.Keyframes.Count : 0;

                    for (int a = 0; a < keyframeCount; a++)
                    {
                        bytes.AddRange(anim.Keyframes[a].Write());
                    }

                    index++;
                }
            }

            //Names
            bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), 28);
            for (int i = 0; i < numEntries; i++)
            {
                AMK_Animation anim = Animations.Find(a => a.ID == i);

                if (anim != null)
                {
                    bytes.AddRange(Utils.GetStringBytes(anim.Name, 32));
                }
                else
                {
                    //Anim is null, write dummy data
                    bytes.AddRange(new byte[32]);
                }
            }

            return(bytes.ToArray());
        }