Ejemplo n.º 1
0
        public static CML_File Parse(string path, bool writeXml)
        {
            CML_File file = Parse(File.ReadAllBytes(path));

            if (writeXml)
            {
                YAXSerializer serializer = new YAXSerializer(typeof(CML_File));
                serializer.SerializeToFile(file, path + ".xml");
            }

            return(file);
        }
Ejemplo n.º 2
0
        public static CML_File Parse(byte[] bytes)
        {
            CML_File cml        = new CML_File();
            int      numEntries = BitConverter.ToInt32(bytes, 0);
            int      offset     = 4;

            if (bytes.Length != 4 + (112 * numEntries))
            {
                throw new InvalidDataException($"Error on reading cml file: Invalid file size!");
            }

            for (int i = 0; i < numEntries; i++)
            {
                CML_Entry entry = new CML_Entry();

                entry.CharaId = BitConverter.ToUInt16(bytes, offset + 0);
                entry.Costume = BitConverter.ToUInt16(bytes, offset + 2);
                entry.I_04    = BitConverter.ToInt32(bytes, offset + 4);
                entry.F_08    = BitConverter.ToSingle(bytes, offset + 8);
                entry.F_12    = BitConverter.ToSingle(bytes, offset + 12);
                entry.F_16    = BitConverter.ToSingle(bytes, offset + 16);
                entry.F_20    = BitConverter.ToSingle(bytes, offset + 20);
                entry.F_24    = BitConverter.ToSingle(bytes, offset + 24);
                entry.F_28    = BitConverter.ToSingle(bytes, offset + 28);
                entry.F_32    = BitConverter.ToSingle(bytes, offset + 32);
                entry.F_36    = BitConverter.ToSingle(bytes, offset + 36);
                entry.F_40    = BitConverter.ToSingle(bytes, offset + 40);
                entry.F_44    = BitConverter.ToSingle(bytes, offset + 44);
                entry.F_48    = BitConverter.ToSingle(bytes, offset + 48);
                entry.F_52    = BitConverter.ToSingle(bytes, offset + 52);
                entry.F_56    = BitConverter.ToSingle(bytes, offset + 56);
                entry.F_60    = BitConverter.ToSingle(bytes, offset + 60);
                entry.F_64    = BitConverter.ToSingle(bytes, offset + 64);
                entry.F_68    = BitConverter.ToSingle(bytes, offset + 68);
                entry.F_72    = BitConverter.ToSingle(bytes, offset + 72);
                entry.F_76    = BitConverter.ToSingle(bytes, offset + 76);
                entry.F_80    = BitConverter.ToSingle(bytes, offset + 80);
                entry.F_84    = BitConverter.ToSingle(bytes, offset + 84);
                entry.F_88    = BitConverter.ToSingle(bytes, offset + 88);
                entry.F_92    = BitConverter.ToSingle(bytes, offset + 92);
                entry.F_96    = BitConverter.ToSingle(bytes, offset + 96);
                entry.F_100   = BitConverter.ToSingle(bytes, offset + 100);
                entry.F_104   = BitConverter.ToSingle(bytes, offset + 104);
                entry.F_108   = BitConverter.ToSingle(bytes, offset + 108);

                offset += 112;
                cml.Entries.Add(entry);
            }

            return(cml);
        }