Beispiel #1
0
        public static EMA_Animation Read(byte[] rawBytes, List <byte> bytes, int offset, int index, EMA_File emaFile)
        {
            EMA_Animation animation = new EMA_Animation();

            animation.Index    = index;
            animation.I_00     = BitConverter.ToUInt16(rawBytes, offset + 0);
            animation.I_08     = (EmaType)BitConverter.ToUInt16(rawBytes, offset + 8);
            animation.I_10     = (ValueType)BitConverter.ToUInt16(rawBytes, offset + 10);
            animation.Commands = new ObservableCollection <EMA_Command>();

            int commandCount = BitConverter.ToUInt16(rawBytes, offset + 2);
            int valueCount   = BitConverter.ToInt32(rawBytes, offset + 4);
            int valueOffset  = BitConverter.ToInt32(rawBytes, offset + 16) + offset;
            int nameOffset   = (BitConverter.ToInt32(rawBytes, offset + 12) != 0) ? BitConverter.ToInt32(rawBytes, offset + 12) + offset : 0;

            //Name
            if (nameOffset > 0)
            {
                animation.Name = Utils.GetString(bytes, nameOffset + 11);
            }

            //Values
            float[] values = new float[valueCount];

            for (int i = 0; i < valueCount; i++)
            {
                if (animation.I_10 == ValueType.Float16)
                {
                    values[i] = Half.ToHalf(rawBytes, valueOffset + (i * 2));
                }
                else if (animation.I_10 == ValueType.Float32 || animation.I_10 == ValueType.Float32_2)
                {
                    values[i] = BitConverter.ToSingle(rawBytes, valueOffset + (i * 4));
                }
                else
                {
                    throw new InvalidDataException(String.Format("EMA_Animation: Unknown float type ({0}).", animation.I_10));
                }

                //Console.WriteLine(string.Format("{1}: {0}", values[i], i));
            }
            //Console.ReadLine();

            //Commands
            for (int i = 0; i < commandCount; i++)
            {
                int commandOffset = BitConverter.ToInt32(rawBytes, offset + 20 + (i * 4));

                if (commandOffset != 0)
                {
                    animation.Commands.Add(EMA_Command.Read(rawBytes, commandOffset + offset, values, emaFile, animation.I_08));
                }
            }

            return(animation);
        }
Beispiel #2
0
        public static EMA_File Load(byte[] rawBytes)
        {
            List <byte> bytes = rawBytes.ToList();

            EMA_File emaFile = new EMA_File();

            //Header
            emaFile.Version = BitConverter.ToInt32(rawBytes, 8);
            emaFile.I_18    = BitConverter.ToUInt16(rawBytes, 18);
            emaFile.I_20    = BitConverter.ToInt32(rawBytes, 20);
            emaFile.I_24    = BitConverter.ToInt32(rawBytes, 24);
            emaFile.I_28    = BitConverter.ToInt32(rawBytes, 28);

            int    skeletonOffset  = BitConverter.ToInt32(rawBytes, 12);
            ushort animationCount  = BitConverter.ToUInt16(rawBytes, 16);
            int    animationsStart = 32;

            //Parse skeleton
            if (skeletonOffset > 0)
            {
                emaFile.skeleton = Skeleton.Parse(rawBytes, bytes, skeletonOffset);
            }

            //Parse animations
            emaFile.Animations = new ObservableCollection <EMA_Animation>();

            for (int i = 0; i < animationCount; i++)
            {
                int animOffset = BitConverter.ToInt32(rawBytes, animationsStart + (i * 4));

                if (animOffset != 0)
                {
                    emaFile.Animations.Add(EMA_Animation.Read(rawBytes, bytes, BitConverter.ToInt32(rawBytes, animationsStart + (i * 4)), i, emaFile));
                }
            }

            return(emaFile);
        }