public static SEV_File Parse(string path, bool writeXml) { SEV_File file = Parse(File.ReadAllBytes(path)); if (writeXml) { YAXSerializer serializer = new YAXSerializer(typeof(SEV_File)); serializer.SerializeToFile(file, path + ".xml"); } return(file); }
public static SEV_File Parse(byte[] bytes) { if (BitConverter.ToUInt32(bytes, 0) != SEV_SIGNATURE) { throw new InvalidDataException("SEV signature not found!"); } SEV_File sev = new SEV_File(); int count = BitConverter.ToInt32(bytes, 8); //Find offsets to each section int sevEntryStart = 16; int charEventStart = sevEntryStart + (SEV_ENTRY_SIZE * count); int totalCharEvents = 0; int totalEvents = 0; for (int i = 0; i < count; i++) { totalCharEvents += BitConverter.ToInt32(bytes, sevEntryStart + (SEV_ENTRY_SIZE * i) + 12); } for (int i = 0; i < totalCharEvents; i++) { totalEvents += BitConverter.ToInt32(bytes, charEventStart + (SEV_CHARA_EVENT_SIZE * i) + 8); } int eventStart = charEventStart + (SEV_CHARA_EVENT_SIZE * totalCharEvents); int eventEntryStart = eventStart + (SEV_EVENT_SIZE * totalEvents); //Parse the data for (int i = 0; i < count; i++) { SEV_Entry sevEntry = new SEV_Entry(); sevEntry.CharaID = BitConverter.ToInt32(bytes, sevEntryStart + (SEV_ENTRY_SIZE * i) + 0); sevEntry.CostumeID = BitConverter.ToInt32(bytes, sevEntryStart + (SEV_ENTRY_SIZE * i) + 4); sevEntry.I_08 = BitConverter.ToUInt32(bytes, sevEntryStart + (SEV_ENTRY_SIZE * i) + 8); int charEventCount = BitConverter.ToInt32(bytes, sevEntryStart + (SEV_ENTRY_SIZE * i) + 12); for (int a = 0; a < charEventCount; a++) { SEV_CharEvent charEvent = new SEV_CharEvent(); charEvent.CharaID = BitConverter.ToInt32(bytes, charEventStart + 0); charEvent.CostumeID = BitConverter.ToInt32(bytes, charEventStart + 4); int eventCount = BitConverter.ToInt32(bytes, charEventStart + 8); for (int b = 0; b < eventCount; b++) { SEV_Event _event = new SEV_Event(); _event.Type = BitConverter.ToInt32(bytes, eventStart + 0); int eventEntryCount = BitConverter.ToInt32(bytes, eventStart + 4); for (int t = 0; t < eventEntryCount; t++) { SEV_EventEntry eventEntry = new SEV_EventEntry(); eventEntry.I_00 = BitConverter.ToInt32(bytes, eventEntryStart + 0); eventEntry.CueID = BitConverter.ToInt32(bytes, eventEntryStart + 4); eventEntry.FileID = BitConverter.ToInt32(bytes, eventEntryStart + 8); eventEntry.I_12 = BitConverter.ToInt32(bytes, eventEntryStart + 12); eventEntry.ResponseCueID = BitConverter.ToInt32(bytes, eventEntryStart + 16); eventEntry.ResponseFileID = BitConverter.ToInt32(bytes, eventEntryStart + 20); eventEntry.I_24 = BitConverter.ToInt32(bytes, eventEntryStart + 24); eventEntry.I_28 = BitConverter.ToInt32(bytes, eventEntryStart + 28); eventEntry.I_32 = BitConverter.ToInt32(bytes, eventEntryStart + 32); eventEntryStart += SEV_EVENT_ENTRY_SIZE; _event.EventEntries.Add(eventEntry); } eventStart += SEV_EVENT_SIZE; charEvent.Events.Add(_event); } charEventStart += SEV_CHARA_EVENT_SIZE; sevEntry.SubEntries.Add(charEvent); } sev.Entries.Add(sevEntry); } return(sev); }