Пример #1
0
        public static TTB_File Parse(string path, bool writeXml)
        {
            TTB_File file = Parse(File.ReadAllBytes(path));

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

            return(file);
        }
Пример #2
0
        public static TTB_File Parse(byte[] bytes)
        {
            if (BitConverter.ToUInt32(bytes, 0) != TTB_SIGNATURE)
            {
                throw new InvalidDataException("TTB signature not found!");
            }

            TTB_File ttb = new TTB_File();

            //Headers
            int stringSize = BitConverter.ToInt32(bytes, 12);
            int numEntries = BitConverter.ToInt32(bytes, stringSize + 16);
            int dataStart  = BitConverter.ToInt32(bytes, stringSize + 20) + stringSize + 16; //Relative

            //Data
            for (int i = 0; i < numEntries; i++)
            {
                TTB_Entry entry = new TTB_Entry();
                entry.CmsID = BitConverter.ToInt32(bytes, dataStart + (16 * i) + 12);

                int numEvents      = BitConverter.ToInt32(bytes, dataStart + (16 * i));
                int eventDataStart = BitConverter.ToInt32(bytes, dataStart + (16 * i) + 4) + stringSize + 16; //Relative to header 2 (after strings)
                int startIndex     = BitConverter.ToInt32(bytes, dataStart + (16 * i) + 8);
                eventDataStart += 116 * startIndex;

                for (int a = 0; a < numEvents; a++)
                {
                    TTB_Event _event = new TTB_Event();

                    _event.Index           = BitConverter.ToInt32(bytes, eventDataStart + 0).ToString();
                    _event.Cms_Id1         = BitConverter.ToInt32(bytes, eventDataStart + 4);
                    _event.Costume         = BitConverter.ToInt32(bytes, eventDataStart + 8);
                    _event.Transformation  = BitConverter.ToInt32(bytes, eventDataStart + 12);
                    _event.Cms_Id2         = BitConverter.ToInt32(bytes, eventDataStart + 16);
                    _event.Costume2        = BitConverter.ToInt32(bytes, eventDataStart + 20);
                    _event.Transformation2 = BitConverter.ToInt32(bytes, eventDataStart + 24);
                    _event.Cms_Id3         = BitConverter.ToInt32(bytes, eventDataStart + 28);
                    _event.Costume3        = BitConverter.ToInt32(bytes, eventDataStart + 32);
                    _event.Transformation3 = BitConverter.ToInt32(bytes, eventDataStart + 36);
                    _event.Cms_Id4         = BitConverter.ToInt32(bytes, eventDataStart + 40);
                    _event.Costume4        = BitConverter.ToInt32(bytes, eventDataStart + 44);
                    _event.Transformation4 = BitConverter.ToInt32(bytes, eventDataStart + 48);
                    _event.Cms_Id5         = BitConverter.ToInt32(bytes, eventDataStart + 52);
                    _event.Costume5        = BitConverter.ToInt32(bytes, eventDataStart + 56);
                    _event.Transformation5 = BitConverter.ToInt32(bytes, eventDataStart + 60);
                    _event.Type            = (EventType)BitConverter.ToInt32(bytes, eventDataStart + 64);
                    _event.I_68            = BitConverter.ToUInt32(bytes, eventDataStart + 68);
                    _event.I_72            = BitConverter.ToUInt32(bytes, eventDataStart + 72);

                    _event.Order1 = BitConverter.ToInt32(bytes, eventDataStart + 76);
                    _event.Order2 = BitConverter.ToInt32(bytes, eventDataStart + 84);
                    _event.Order3 = BitConverter.ToInt32(bytes, eventDataStart + 92);
                    _event.Order4 = BitConverter.ToInt32(bytes, eventDataStart + 100);
                    _event.Order5 = BitConverter.ToInt32(bytes, eventDataStart + 108);

                    //Names
                    int name1 = BitConverter.ToInt32(bytes, eventDataStart + 80);
                    int name2 = BitConverter.ToInt32(bytes, eventDataStart + 88);
                    int name3 = BitConverter.ToInt32(bytes, eventDataStart + 96);
                    int name4 = BitConverter.ToInt32(bytes, eventDataStart + 104);
                    int name5 = BitConverter.ToInt32(bytes, eventDataStart + 112);

                    if (name1 != -1 && name1 < stringSize)
                    {
                        _event.Voice1 = StringEx.GetString(bytes, name1 + 16, false);
                    }

                    if (name2 != -1 && name2 < stringSize)
                    {
                        _event.Voice2 = StringEx.GetString(bytes, name2 + 16, false);
                    }

                    if (name3 != -1 && name3 < stringSize)
                    {
                        _event.Voice3 = StringEx.GetString(bytes, name3 + 16, false);
                    }

                    if (name4 != -1 && name4 < stringSize)
                    {
                        _event.Voice4 = StringEx.GetString(bytes, name4 + 16, false);
                    }

                    if (name5 != -1 && name5 < stringSize)
                    {
                        _event.Voice5 = StringEx.GetString(bytes, name5 + 16, false);
                    }

                    entry.SubEntries.Add(_event);
                    eventDataStart += 116;
                }

                ttb.Entries.Add(entry);
            }

            return(ttb);
        }