private void numericGROUPcurrentGroup_ValueChanged(object sender, EventArgs e) { if (info.block[5].nEntries == 0) { return; } Info.GROUP group = (Info.GROUP)info.block[5].entries[(int)numericGROUPrecord.Value]; numericGROUPentry.Value = group.subgroup[(int)numericGROUPcurrentSubgroup.Value].nEntry; switch (group.subgroup[(int)numericGROUPcurrentSubgroup.Value].type) { case 0x0700: comboBoxGROUPtype.SelectedIndex = 0; break; case 0x0803: comboBoxGROUPtype.SelectedIndex = 1; break; case 0x0601: comboBoxGROUPtype.SelectedIndex = 2; break; case 0x0402: comboBoxGROUPtype.SelectedIndex = 3; break; } }
private void Add_Group() { Folder group = new Folder(); group = new Folder(); group.name = "GROUP"; group.id = 0x0F007; group.folders = new List <Folder>(); // Add files to GROUP folder for (int i = 0; i < sdat.info.block[5].nEntries; i++) { Info.GROUP entry = (Info.GROUP)sdat.info.block[5].entries[i]; Folder entryFld = new Folder(); entryFld.name = "Entry " + i.ToString(); entryFld.id = (uint)(0x0F008 + i); entryFld.files = new List <Sound>(); for (int n = 0; n < entry.nCount; n++) { switch (entry.subgroup[n].type) { case 0x700: // SSEQ if (sdat.files.root.folders[0].files.Count > entry.subgroup[n].nEntry) { entryFld.files.Add(sdat.files.root.folders[0].files[(int)entry.subgroup[n].nEntry]); } break; case 0x803: // SSAR if (sdat.files.root.folders[1].files.Count > entry.subgroup[n].nEntry) { entryFld.files.Add(sdat.files.root.folders[1].files[(int)entry.subgroup[n].nEntry]); } break; case 0x601: // SBNK if (sdat.files.root.folders[2].files.Count > entry.subgroup[n].nEntry) { entryFld.files.Add(sdat.files.root.folders[2].files[(int)entry.subgroup[n].nEntry]); } break; case 0x402: // SWAR if (sdat.files.root.folders[3].files.Count > entry.subgroup[n].nEntry) { entryFld.files.Add(sdat.files.root.folders[3].files[(int)entry.subgroup[n].nEntry]); } break; default: break; } } group.folders.Add(entryFld); } sdat.files.root.folders.Add(group); }
private void btnGROUPentryRemove_Click(object sender, EventArgs e) { Info.GROUP group = (Info.GROUP)info.block[5].entries[(int)numericGROUPrecord.Value]; Info.GROUP.Subgroup[] entries = new Info.GROUP.Subgroup[--group.nCount]; for (int i = 0, j = 0; i < group.subgroup.Length; i++) { if (i == numericGROUPcurrentSubgroup.Value) { continue; } entries[j++] = group.subgroup[i]; } group.subgroup = entries; info.block[5].entries[(int)numericGROUPrecord.Value] = group; ReadInfo(); }
private void btnGROUPentryAdd_Click(object sender, EventArgs e) { Info.GROUP group = (Info.GROUP)info.block[5].entries[(int)numericGROUPrecord.Value]; Info.GROUP.Subgroup[] entries = new Info.GROUP.Subgroup[++group.nCount]; if (group.subgroup is Info.GROUP.Subgroup[]) { Array.Copy(group.subgroup, 0, entries, 0, group.subgroup.Length); } entries[entries.Length - 1] = new Info.GROUP.Subgroup(); group.subgroup = entries; info.block[5].entries[(int)numericGROUPrecord.Value] = group; numericGROUPcurrentSubgroup.Maximum = group.nCount - 1; numericGROUPcurrentSubgroup.Value = numericGROUPcurrentSubgroup.Maximum; ReadInfo(); }
private void comboBoxGROUPtype_SelectedIndexChanged(object sender, EventArgs e) { Info.GROUP group = (Info.GROUP)info.block[5].entries[(int)numericGROUPrecord.Value]; switch (comboBoxGROUPtype.SelectedIndex) { case 0: group.subgroup[(int)numericGROUPcurrentSubgroup.Value].type = 0x0700; break; case 1: group.subgroup[(int)numericGROUPcurrentSubgroup.Value].type = 0x0803; break; case 2: group.subgroup[(int)numericGROUPcurrentSubgroup.Value].type = 0x0601; break; case 3: group.subgroup[(int)numericGROUPcurrentSubgroup.Value].type = 0x0402; break; } info.block[5].entries[(int)numericGROUPrecord.Value] = group; }
private void numericGROUPentry_ValueChanged(object sender, EventArgs e) { Info.GROUP group = (Info.GROUP)info.block[5].entries[(int)numericGROUPrecord.Value]; group.subgroup[(int)numericGROUPcurrentSubgroup.Value].nEntry = (uint)numericGROUPentry.Value; info.block[5].entries[(int)numericGROUPrecord.Value] = group; }
private void ReadRecord(int page) { switch (page) { case 0: if (info.block[0].nEntries == 0) { numericSSEQfileID.Enabled = false; numericSSEQunknown.Enabled = false; numericSSEQBnk.Enabled = false; numericSSEQVol.Enabled = false; numericSSEQcpr.Enabled = false; numericSSEQppr.Enabled = false; numericSSEQply.Enabled = false; return; } Info.SEQ seq = (Info.SEQ)info.block[0].entries[(int)numericSSEQrecord.Value]; numericSSEQfileID.Value = seq.fileID; numericSSEQunknown.Value = seq.unknown; numericSSEQBnk.Value = seq.bnk; numericSSEQVol.Value = seq.vol; numericSSEQcpr.Value = seq.cpr; numericSSEQppr.Value = seq.ppr; numericSSEQply.Value = seq.ply; break; case 1: if (info.block[1].nEntries == 0) { numericSSARfileID.Enabled = false; numericSSARunknown.Enabled = false; return; } Info.SEQARC ssar = (Info.SEQARC)info.block[1].entries[(int)numericSSARrecord.Value]; numericSSARfileID.Value = ssar.fileID; numericSSARunknown.Value = ssar.unknown; break; case 2: if (info.block[2].nEntries == 0) { numericSBNKfileID.Enabled = false; numericSBNKunknown.Enabled = false; numericSBNKwa1.Enabled = false; numericSBNKwa2.Enabled = false; numericSBNKwa3.Enabled = false; numericSBNKwa4.Enabled = false; return; } Info.BANK sbnk = (Info.BANK)info.block[2].entries[(int)numericSBNKrecord.Value]; numericSBNKfileID.Value = sbnk.fileID; numericSBNKunknown.Value = sbnk.unknown; numericSBNKwa1.Value = sbnk.wa[0]; numericSBNKwa2.Value = sbnk.wa[1]; numericSBNKwa3.Value = sbnk.wa[2]; numericSBNKwa4.Value = sbnk.wa[3]; break; case 3: if (info.block[3].nEntries == 0) { return; } Info.WAVEARC swar = (Info.WAVEARC)info.block[3].entries[(int)numericSWARrecord.Value]; numericSWARfileID.Value = swar.fileID; numericSWARunknown.Value = swar.unknown; break; case 4: if (info.block[4].nEntries == 0) { btnPLAYERremove.Enabled = false; numericPLAYERunknown.Enabled = false; numericPLAYERunknown2.Enabled = false; return; } btnPLAYERremove.Enabled = true; numericPLAYERunknown.Enabled = true; numericPLAYERunknown2.Enabled = true; Info.PLAYER player = (Info.PLAYER)info.block[4].entries[(int)numericPLAYERrecord.Value]; numericPLAYERunknown.Value = player.unknown; numericPLAYERunknown2.Value = player.unknown2; break; case 5: if (info.block[5].nEntries == 0) { btnGROUPremove.Enabled = false; btnGROUPsubgroupAdd.Enabled = false; btnGROUPsubgroupRemove.Enabled = false; labelGROUPsubgroupTotal.Text = "no group"; numericGROUPcurrentSubgroup.Enabled = false; comboBoxGROUPtype.Enabled = false; numericGROUPentry.Enabled = false; return; } btnGROUPremove.Enabled = true; btnGROUPsubgroupRemove.Enabled = true; btnGROUPsubgroupAdd.Enabled = true; numericGROUPcurrentSubgroup.Enabled = true; comboBoxGROUPtype.Enabled = true; numericGROUPentry.Enabled = true; Info.GROUP group = (Info.GROUP)info.block[5].entries[(int)numericGROUPrecord.Value]; if (group.nCount == 0) { btnGROUPsubgroupRemove.Enabled = false; comboBoxGROUPtype.Enabled = false; numericGROUPentry.Enabled = false; labelGROUPsubgroupTotal.Text = "of none"; numericGROUPcurrentSubgroup.Enabled = false; return; } labelGROUPsubgroupTotal.Text = "of " + (group.nCount - 1); numericGROUPcurrentSubgroup.Maximum = group.nCount - 1; numericGROUPcurrentSubgroup.Value = 0; numericGROUPcurrentGroup_ValueChanged(null, null); break; case 6: if (info.block[6].nEntries == 0) { btnPLAYER2remove.Enabled = false; numericPLAYER2count.Enabled = false; numericPLAYER2v1.Enabled = false; numericPLAYER2v2.Enabled = false; numericPLAYER2v3.Enabled = false; numericPLAYER2v4.Enabled = false; numericPLAYER2v5.Enabled = false; numericPLAYER2v6.Enabled = false; numericPLAYER2v7.Enabled = false; numericPLAYER2v8.Enabled = false; numericPLAYER2v9.Enabled = false; numericPLAYER2v10.Enabled = false; numericPLAYER2v11.Enabled = false; numericPLAYER2v12.Enabled = false; numericPLAYER2v13.Enabled = false; numericPLAYER2v14.Enabled = false; numericPLAYER2v15.Enabled = false; numericPLAYER2v16.Enabled = false; return; } btnPLAYER2remove.Enabled = true; numericPLAYER2count.Enabled = true; numericPLAYER2v1.Enabled = true; numericPLAYER2v2.Enabled = true; numericPLAYER2v3.Enabled = true; numericPLAYER2v4.Enabled = true; numericPLAYER2v5.Enabled = true; numericPLAYER2v6.Enabled = true; numericPLAYER2v7.Enabled = true; numericPLAYER2v8.Enabled = true; numericPLAYER2v9.Enabled = true; numericPLAYER2v10.Enabled = true; numericPLAYER2v11.Enabled = true; numericPLAYER2v12.Enabled = true; numericPLAYER2v13.Enabled = true; numericPLAYER2v14.Enabled = true; numericPLAYER2v15.Enabled = true; numericPLAYER2v16.Enabled = true; Info.PLAYER2 player2 = (Info.PLAYER2)info.block[6].entries[(int)numericPLAYER2record.Value]; numericPLAYER2count.Value = player2.nCount; numericPLAYER2v1.Value = player2.v[0]; numericPLAYER2v2.Value = player2.v[1]; numericPLAYER2v3.Value = player2.v[2]; numericPLAYER2v4.Value = player2.v[3]; numericPLAYER2v5.Value = player2.v[4]; numericPLAYER2v6.Value = player2.v[5]; numericPLAYER2v7.Value = player2.v[6]; numericPLAYER2v8.Value = player2.v[7]; numericPLAYER2v9.Value = player2.v[8]; numericPLAYER2v10.Value = player2.v[9]; numericPLAYER2v11.Value = player2.v[10]; numericPLAYER2v12.Value = player2.v[11]; numericPLAYER2v13.Value = player2.v[12]; numericPLAYER2v14.Value = player2.v[13]; numericPLAYER2v15.Value = player2.v[14]; numericPLAYER2v16.Value = player2.v[15]; break; case 7: if (info.block[7].nEntries == 0) { numericSTRMfileID.Enabled = false; numericSTRMunknown.Enabled = false; numericSTRMpri.Enabled = false; numericSTRMvol.Enabled = false; numericSTRMply.Enabled = false; return; } Info.STRM strm = (Info.STRM)info.block[7].entries[(int)numericSTRMrecord.Value]; numericSTRMfileID.Value = strm.fileID; numericSTRMunknown.Value = strm.unknown; numericSTRMpri.Value = strm.pri; numericSTRMvol.Value = strm.vol; numericSTRMply.Value = strm.ply; break; } }
private sSDAT Read_SDAT(sFile file) { sSDAT sdat = new sSDAT(); sdat.id = file.id; sdat.archivo = file.path; BinaryReader br = new BinaryReader(new FileStream(file.path, FileMode.Open)); string h = new String(br.ReadChars(4)); if (h == "SWAV") { sdat.files.root.id = 0x0F000; sdat.files.root.name = "SWAV"; sdat.files.root.files = new List<Sound>(); Sound swavFile = new Sound(); swavFile.id = 0x00; swavFile.name = file.name; swavFile.offset = 0x00; swavFile.size = file.size; swavFile.type = FormatSound.SWAV; swavFile.path = sdat.archivo; sdat.files.root.files.Add(swavFile); br.Close(); return sdat; } if (h == "STRM") // Quick fix { sdat.files.root.id = 0x0F000; sdat.files.root.name = "STRM"; sdat.files.root.files = new List<Sound>(); Sound swavFile = new Sound(); swavFile.id = 0x00; swavFile.name = file.name; swavFile.offset = 0x00; swavFile.size = file.size; swavFile.type = FormatSound.STRM; swavFile.path = sdat.archivo; sdat.files.root.files.Add(swavFile); br.Close(); return sdat; } br.BaseStream.Position = 0x00; #region Cabecera genérica sdat.generico.id = br.ReadChars(4); sdat.generico.endianess = br.ReadUInt16(); sdat.generico.constant = br.ReadUInt16(); sdat.generico.file_size = br.ReadUInt32(); sdat.generico.header_size = br.ReadUInt16(); sdat.generico.nSection = br.ReadUInt16(); #endregion #region Cabecera SDAT sdat.cabecera.symbOffset = br.ReadUInt32(); sdat.cabecera.symbSize = br.ReadUInt32(); sdat.cabecera.infoOffset = br.ReadUInt32(); sdat.cabecera.infoSize = br.ReadUInt32(); sdat.cabecera.fatOffset = br.ReadUInt32(); sdat.cabecera.fatSize = br.ReadUInt32(); sdat.cabecera.fileOffset = br.ReadUInt32(); sdat.cabecera.fileSize = br.ReadUInt32(); sdat.cabecera.reserved = br.ReadBytes(16); #endregion #region Bloque Symbol if (sdat.cabecera.symbSize == 0x00) // no hay sección Symbol goto Info; br.BaseStream.Position = sdat.cabecera.symbOffset; sdat.symbol.id = br.ReadChars(4); sdat.symbol.size = br.ReadUInt32(); sdat.symbol.offsetSeq = br.ReadUInt32(); sdat.symbol.offsetSeqArc = br.ReadUInt32(); sdat.symbol.offsetBank = br.ReadUInt32(); sdat.symbol.offsetWaveArch = br.ReadUInt32(); sdat.symbol.offsetPlayer = br.ReadUInt32(); sdat.symbol.offsetGroup = br.ReadUInt32(); sdat.symbol.offsetPlayer2 = br.ReadUInt32(); sdat.symbol.offsetStream = br.ReadUInt32(); sdat.symbol.reserved = br.ReadBytes(24); // Lectura de las entradas de cada record sdat.symbol.records = new Record[7]; uint[] offsets = new uint[7] { sdat.symbol.offsetSeq, sdat.symbol.offsetBank, sdat.symbol.offsetWaveArch, sdat.symbol.offsetPlayer, sdat.symbol.offsetGroup, sdat.symbol.offsetPlayer2, sdat.symbol.offsetStream }; #region Other Record for (int i = 0; i < offsets.Length; i++) { br.BaseStream.Position = 0x40 + offsets[i]; sdat.symbol.records[i] = new Record(); sdat.symbol.records[i].nEntries = br.ReadUInt32(); sdat.symbol.records[i].entriesOffset = new uint[sdat.symbol.records[i].nEntries]; sdat.symbol.records[i].entries = new string[sdat.symbol.records[i].nEntries]; for (int j = 0; j < sdat.symbol.records[i].nEntries; j++) sdat.symbol.records[i].entriesOffset[j] = br.ReadUInt32(); for (int k = 0; k < sdat.symbol.records[i].nEntries; k++) { if (sdat.symbol.records[i].entriesOffset[k] == 0x00) continue; br.BaseStream.Position = 0x40 + sdat.symbol.records[i].entriesOffset[k]; char c = '\0'; do { c = (char)br.ReadByte(); sdat.symbol.records[i].entries[k] += c; } while (c != 0x0); } } #endregion #region SEQARC Record br.BaseStream.Position = 0x40 + sdat.symbol.offsetSeqArc; sdat.symbol.record2 = new Record2(); sdat.symbol.record2.nEntries = br.ReadUInt32(); sdat.symbol.record2.group = new Group[sdat.symbol.record2.nEntries]; // Lee los offset de cada grupo for (int i = 0; i < sdat.symbol.record2.nEntries; i++) { sdat.symbol.record2.group[i].groupOffset = br.ReadUInt32(); sdat.symbol.record2.group[i].subRecOffset = br.ReadUInt32(); } // Lee los subgrupos de cada grupo for (int i = 0; i < sdat.symbol.record2.nEntries; i++) { char c = '\0'; if (sdat.symbol.record2.group[i].groupOffset == 0x00) // En caso de que no exista el nombre sdat.symbol.record2.group[i].groupName = "SEQARC_" + i.ToString(); else { // Lee el nombre del grupo br.BaseStream.Position = 0x40 + sdat.symbol.record2.group[i].groupOffset; c = '\0'; do { c = (char)br.ReadByte(); sdat.symbol.record2.group[i].groupName += c; } while (c != 0x0); } // Lee los offset de las entradas del subgrupo if (sdat.symbol.record2.group[i].subRecOffset == 0x00) // En caso de que no haya subgrupos { sdat.symbol.record2.group[i].subRecord = new Record(); continue; } br.BaseStream.Position = 0x40 + sdat.symbol.record2.group[i].subRecOffset; Record subRecord = new Record(); subRecord.nEntries = br.ReadUInt32(); subRecord.entriesOffset = new uint[subRecord.nEntries]; subRecord.entries = new string[subRecord.nEntries]; for (int j = 0; j < subRecord.nEntries; j++) subRecord.entriesOffset[j] = br.ReadUInt32(); // Lee las entradas del subgrupo for (int j = 0; j < subRecord.nEntries; j++) { if (subRecord.entriesOffset[j] == 0x00) continue; br.BaseStream.Position = 0x40 + subRecord.entriesOffset[j]; c = '\0'; do { c = (char)br.ReadByte(); subRecord.entries[j] += c; } while (c != 0x0); } sdat.symbol.record2.group[i].subRecord = subRecord; } #endregion #endregion #region Bloque Info Info: br.BaseStream.Position = sdat.cabecera.infoOffset; Info info = new Info(); // Header info.header.id = br.ReadChars(4); info.header.size = br.ReadUInt32(); info.header.offsetRecords = new uint[8]; for (int i = 0; i < 8; i++) info.header.offsetRecords[i] = br.ReadUInt32(); info.header.reserved = br.ReadBytes(24); // Blocks info.block = new Info.Block[8]; for (int i = 0; i < 8; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.header.offsetRecords[i]; info.block[i].nEntries = br.ReadUInt32(); info.block[i].offsetEntries = new uint[info.block[i].nEntries]; info.block[i].entries = new object[info.block[i].nEntries]; for (int j = 0; j < info.block[i].nEntries; j++) info.block[i].offsetEntries[j] = br.ReadUInt32(); } // Entries // SEQ for (int i = 0; i < info.block[0].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[0].offsetEntries[i]; Info.SEQ seq = new Info.SEQ(); seq.fileID = br.ReadUInt16(); seq.unknown = br.ReadUInt16(); seq.bnk = br.ReadUInt16(); seq.vol = br.ReadByte(); seq.cpr = br.ReadByte(); seq.ppr = br.ReadByte(); seq.ply = br.ReadByte(); seq.unknown2 = br.ReadBytes(2); info.block[0].entries[i] = seq; } // SEQARC for (int i = 0; i < info.block[1].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[1].offsetEntries[i]; Info.SEQARC seq = new Info.SEQARC(); seq.fileID = br.ReadUInt16(); seq.unknown = br.ReadUInt16(); info.block[1].entries[i] = seq; } // BANK for (int i = 0; i < info.block[2].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[2].offsetEntries[i]; Info.BANK bank = new Info.BANK(); bank.fileID = br.ReadUInt16(); bank.unknown = br.ReadUInt16(); bank.wa = new ushort[4]; for (int j = 0; j < 4; j++) bank.wa[j] = br.ReadUInt16(); info.block[2].entries[i] = bank; } // WAVEARC for (int i = 0; i < info.block[3].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[3].offsetEntries[i]; Info.WAVEARC wave = new Info.WAVEARC(); wave.fileID = br.ReadUInt16(); wave.unknown = br.ReadUInt16(); info.block[3].entries[i] = wave; } // PLAYER for (int i = 0; i < info.block[4].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[4].offsetEntries[i]; Info.PLAYER player = new Info.PLAYER(); player.unknown = br.ReadByte(); player.padding = br.ReadBytes(3); player.unknown2 = br.ReadUInt32(); info.block[4].entries[i] = player; } // GROUP for (int i = 0; i < info.block[5].nEntries; i++) { if (info.block[5].offsetEntries[i] == 0x00) { info.block[5].entries[i] = new Info.GROUP(); continue; } br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[5].offsetEntries[i]; Info.GROUP group = new Info.GROUP(); group.nCount = br.ReadUInt32(); group.subgroup = new Info.GROUP.Subgroup[group.nCount]; for (int j = 0; j < group.nCount; j++) { group.subgroup[j].type = br.ReadUInt32(); group.subgroup[j].nEntry = br.ReadUInt32(); } info.block[5].entries[i] = group; } // PLAYER2 for (int i = 0; i < info.block[6].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[6].offsetEntries[i]; Info.PLAYER2 player = new Info.PLAYER2(); player.nCount = br.ReadByte(); player.v = br.ReadBytes(16); player.reserved = br.ReadBytes(7); info.block[6].entries[i] = player; } // STRM for (int i = 0; i < info.block[7].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[7].offsetEntries[i]; Info.STRM strm = new Info.STRM(); strm.fileID = br.ReadUInt16(); strm.unknown = br.ReadUInt16(); strm.vol = br.ReadByte(); strm.pri = br.ReadByte(); strm.ply = br.ReadByte(); strm.reserved = br.ReadBytes(5); info.block[7].entries[i] = strm; } sdat.info = info; #endregion #region Bloque FAT br.BaseStream.Position = sdat.cabecera.fatOffset; FAT fat = new FAT(); // Header fat.header.id = br.ReadChars(4); fat.header.size = br.ReadUInt32(); fat.header.nRecords = br.ReadUInt32(); // Records fat.records = new FAT.Record[fat.header.nRecords]; for (int i = 0; i < fat.header.nRecords; i++) { fat.records[i].offset = br.ReadUInt32(); fat.records[i].size = br.ReadUInt32(); fat.records[i].reserved = br.ReadBytes(8); } sdat.fat = fat; #endregion #region Bloque File br.BaseStream.Position = sdat.cabecera.fileOffset; // Header sdat.files.header.id = br.ReadChars(4); sdat.files.header.size = br.ReadUInt32(); sdat.files.header.nSounds = br.ReadUInt32(); sdat.files.header.reserved = br.ReadUInt32(); #endregion br.Close(); try { System.Xml.Linq.XElement xml = System.Xml.Linq.XElement.Load(Application.StartupPath + Path.DirectorySeparatorChar + "Plugins" + Path.DirectorySeparatorChar + "SDATLang.xml"); xml = xml.Element(pluginHost.Get_Language()).Element("Messages"); Console.WriteLine(xml.Element("S00").Value); Console.WriteLine(xml.Element("S01").Value, sdat.files.header.nSounds.ToString()); } catch { throw new Exception("There was an error reading the XML file of language."); } FileSystem(ref sdat, file.path); Set_Data(ref sdat); return sdat; }
private sSDAT Read_SDAT(sFile file) { sSDAT sdat = new sSDAT(); sdat.id = file.id; sdat.archivo = file.path; BinaryReader br = new BinaryReader(new FileStream(file.path, FileMode.Open)); string h = new String(br.ReadChars(4)); if (h == "SWAV") { sdat.files.root.id = 0x0F000; sdat.files.root.name = "SWAV"; sdat.files.root.files = new List <Sound>(); Sound swavFile = new Sound(); swavFile.id = 0x00; swavFile.name = file.name; swavFile.offset = 0x00; swavFile.size = file.size; swavFile.type = FormatSound.SWAV; swavFile.path = sdat.archivo; sdat.files.root.files.Add(swavFile); br.Close(); return(sdat); } if (h == "STRM") // Quick fix { sdat.files.root.id = 0x0F000; sdat.files.root.name = "STRM"; sdat.files.root.files = new List <Sound>(); Sound swavFile = new Sound(); swavFile.id = 0x00; swavFile.name = file.name; swavFile.offset = 0x00; swavFile.size = file.size; swavFile.type = FormatSound.STRM; swavFile.path = sdat.archivo; sdat.files.root.files.Add(swavFile); br.Close(); return(sdat); } br.BaseStream.Position = 0x00; #region Cabecera genérica sdat.generico.id = br.ReadChars(4); sdat.generico.endianess = br.ReadUInt16(); sdat.generico.constant = br.ReadUInt16(); sdat.generico.file_size = br.ReadUInt32(); sdat.generico.header_size = br.ReadUInt16(); sdat.generico.nSection = br.ReadUInt16(); #endregion #region Cabecera SDAT sdat.cabecera.symbOffset = br.ReadUInt32(); sdat.cabecera.symbSize = br.ReadUInt32(); sdat.cabecera.infoOffset = br.ReadUInt32(); sdat.cabecera.infoSize = br.ReadUInt32(); sdat.cabecera.fatOffset = br.ReadUInt32(); sdat.cabecera.fatSize = br.ReadUInt32(); sdat.cabecera.fileOffset = br.ReadUInt32(); sdat.cabecera.fileSize = br.ReadUInt32(); sdat.cabecera.reserved = br.ReadBytes(16); #endregion #region Bloque Symbol if (sdat.cabecera.symbSize == 0x00) // no hay sección Symbol { goto Info; } br.BaseStream.Position = sdat.cabecera.symbOffset; sdat.symbol.id = br.ReadChars(4); sdat.symbol.size = br.ReadUInt32(); sdat.symbol.offsetSeq = br.ReadUInt32(); sdat.symbol.offsetSeqArc = br.ReadUInt32(); sdat.symbol.offsetBank = br.ReadUInt32(); sdat.symbol.offsetWaveArch = br.ReadUInt32(); sdat.symbol.offsetPlayer = br.ReadUInt32(); sdat.symbol.offsetGroup = br.ReadUInt32(); sdat.symbol.offsetPlayer2 = br.ReadUInt32(); sdat.symbol.offsetStream = br.ReadUInt32(); sdat.symbol.reserved = br.ReadBytes(24); // Lectura de las entradas de cada record sdat.symbol.records = new Record[7]; uint[] offsets = new uint[7] { sdat.symbol.offsetSeq, sdat.symbol.offsetBank, sdat.symbol.offsetWaveArch, sdat.symbol.offsetPlayer, sdat.symbol.offsetGroup, sdat.symbol.offsetPlayer2, sdat.symbol.offsetStream }; #region Other Record for (int i = 0; i < offsets.Length; i++) { br.BaseStream.Position = 0x40 + offsets[i]; sdat.symbol.records[i] = new Record(); sdat.symbol.records[i].nEntries = br.ReadUInt32(); sdat.symbol.records[i].entriesOffset = new uint[sdat.symbol.records[i].nEntries]; sdat.symbol.records[i].entries = new string[sdat.symbol.records[i].nEntries]; for (int j = 0; j < sdat.symbol.records[i].nEntries; j++) { sdat.symbol.records[i].entriesOffset[j] = br.ReadUInt32(); } for (int k = 0; k < sdat.symbol.records[i].nEntries; k++) { if (sdat.symbol.records[i].entriesOffset[k] == 0x00) { continue; } br.BaseStream.Position = 0x40 + sdat.symbol.records[i].entriesOffset[k]; char c = '\0'; do { c = (char)br.ReadByte(); sdat.symbol.records[i].entries[k] += c; } while (c != 0x0); } } #endregion #region SEQARC Record br.BaseStream.Position = 0x40 + sdat.symbol.offsetSeqArc; sdat.symbol.record2 = new Record2(); sdat.symbol.record2.nEntries = br.ReadUInt32(); sdat.symbol.record2.group = new Group[sdat.symbol.record2.nEntries]; // Lee los offset de cada grupo for (int i = 0; i < sdat.symbol.record2.nEntries; i++) { sdat.symbol.record2.group[i].groupOffset = br.ReadUInt32(); sdat.symbol.record2.group[i].subRecOffset = br.ReadUInt32(); } // Lee los subgrupos de cada grupo for (int i = 0; i < sdat.symbol.record2.nEntries; i++) { char c = '\0'; if (sdat.symbol.record2.group[i].groupOffset == 0x00) // En caso de que no exista el nombre { sdat.symbol.record2.group[i].groupName = "SEQARC_" + i.ToString(); } else { // Lee el nombre del grupo br.BaseStream.Position = 0x40 + sdat.symbol.record2.group[i].groupOffset; c = '\0'; do { c = (char)br.ReadByte(); sdat.symbol.record2.group[i].groupName += c; } while (c != 0x0); } // Lee los offset de las entradas del subgrupo if (sdat.symbol.record2.group[i].subRecOffset == 0x00) // En caso de que no haya subgrupos { sdat.symbol.record2.group[i].subRecord = new Record(); continue; } br.BaseStream.Position = 0x40 + sdat.symbol.record2.group[i].subRecOffset; Record subRecord = new Record(); subRecord.nEntries = br.ReadUInt32(); subRecord.entriesOffset = new uint[subRecord.nEntries]; subRecord.entries = new string[subRecord.nEntries]; for (int j = 0; j < subRecord.nEntries; j++) { subRecord.entriesOffset[j] = br.ReadUInt32(); } // Lee las entradas del subgrupo for (int j = 0; j < subRecord.nEntries; j++) { if (subRecord.entriesOffset[j] == 0x00) { continue; } br.BaseStream.Position = 0x40 + subRecord.entriesOffset[j]; c = '\0'; do { c = (char)br.ReadByte(); subRecord.entries[j] += c; } while (c != 0x0); } sdat.symbol.record2.group[i].subRecord = subRecord; } #endregion #endregion #region Bloque Info Info: br.BaseStream.Position = sdat.cabecera.infoOffset; Info info = new Info(); // Header info.header.id = br.ReadChars(4); info.header.size = br.ReadUInt32(); info.header.offsetRecords = new uint[8]; for (int i = 0; i < 8; i++) { info.header.offsetRecords[i] = br.ReadUInt32(); } info.header.reserved = br.ReadBytes(24); // Blocks info.block = new Info.Block[8]; for (int i = 0; i < 8; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.header.offsetRecords[i]; info.block[i].nEntries = br.ReadUInt32(); info.block[i].offsetEntries = new uint[info.block[i].nEntries]; info.block[i].entries = new object[info.block[i].nEntries]; for (int j = 0; j < info.block[i].nEntries; j++) { info.block[i].offsetEntries[j] = br.ReadUInt32(); } } // Entries // SEQ for (int i = 0; i < info.block[0].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[0].offsetEntries[i]; Info.SEQ seq = new Info.SEQ(); seq.fileID = br.ReadUInt16(); seq.unknown = br.ReadUInt16(); seq.bnk = br.ReadUInt16(); seq.vol = br.ReadByte(); seq.cpr = br.ReadByte(); seq.ppr = br.ReadByte(); seq.ply = br.ReadByte(); seq.unknown2 = br.ReadBytes(2); info.block[0].entries[i] = seq; } // SEQARC for (int i = 0; i < info.block[1].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[1].offsetEntries[i]; Info.SEQARC seq = new Info.SEQARC(); seq.fileID = br.ReadUInt16(); seq.unknown = br.ReadUInt16(); info.block[1].entries[i] = seq; } // BANK for (int i = 0; i < info.block[2].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[2].offsetEntries[i]; Info.BANK bank = new Info.BANK(); bank.fileID = br.ReadUInt16(); bank.unknown = br.ReadUInt16(); bank.wa = new ushort[4]; for (int j = 0; j < 4; j++) { bank.wa[j] = br.ReadUInt16(); } info.block[2].entries[i] = bank; } // WAVEARC for (int i = 0; i < info.block[3].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[3].offsetEntries[i]; Info.WAVEARC wave = new Info.WAVEARC(); wave.fileID = br.ReadUInt16(); wave.unknown = br.ReadUInt16(); info.block[3].entries[i] = wave; } // PLAYER for (int i = 0; i < info.block[4].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[4].offsetEntries[i]; Info.PLAYER player = new Info.PLAYER(); player.unknown = br.ReadByte(); player.padding = br.ReadBytes(3); player.unknown2 = br.ReadUInt32(); info.block[4].entries[i] = player; } // GROUP for (int i = 0; i < info.block[5].nEntries; i++) { if (info.block[5].offsetEntries[i] == 0x00) { info.block[5].entries[i] = new Info.GROUP(); continue; } br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[5].offsetEntries[i]; Info.GROUP group = new Info.GROUP(); group.nCount = br.ReadUInt32(); group.subgroup = new Info.GROUP.Subgroup[group.nCount]; for (int j = 0; j < group.nCount; j++) { group.subgroup[j].type = br.ReadUInt32(); group.subgroup[j].nEntry = br.ReadUInt32(); } info.block[5].entries[i] = group; } // PLAYER2 for (int i = 0; i < info.block[6].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[6].offsetEntries[i]; Info.PLAYER2 player = new Info.PLAYER2(); player.nCount = br.ReadByte(); player.v = br.ReadBytes(16); player.reserved = br.ReadBytes(7); info.block[6].entries[i] = player; } // STRM for (int i = 0; i < info.block[7].nEntries; i++) { br.BaseStream.Position = sdat.cabecera.infoOffset + info.block[7].offsetEntries[i]; Info.STRM strm = new Info.STRM(); strm.fileID = br.ReadUInt16(); strm.unknown = br.ReadUInt16(); strm.vol = br.ReadByte(); strm.pri = br.ReadByte(); strm.ply = br.ReadByte(); strm.reserved = br.ReadBytes(5); info.block[7].entries[i] = strm; } sdat.info = info; #endregion #region Bloque FAT br.BaseStream.Position = sdat.cabecera.fatOffset; FAT fat = new FAT(); // Header fat.header.id = br.ReadChars(4); fat.header.size = br.ReadUInt32(); fat.header.nRecords = br.ReadUInt32(); // Records fat.records = new FAT.Record[fat.header.nRecords]; for (int i = 0; i < fat.header.nRecords; i++) { fat.records[i].offset = br.ReadUInt32(); fat.records[i].size = br.ReadUInt32(); fat.records[i].reserved = br.ReadBytes(8); } sdat.fat = fat; #endregion #region Bloque File br.BaseStream.Position = sdat.cabecera.fileOffset; // Header sdat.files.header.id = br.ReadChars(4); sdat.files.header.size = br.ReadUInt32(); sdat.files.header.nSounds = br.ReadUInt32(); sdat.files.header.reserved = br.ReadUInt32(); #endregion br.Close(); try { System.Xml.Linq.XElement xml = System.Xml.Linq.XElement.Load(Application.StartupPath + Path.DirectorySeparatorChar + "Plugins" + Path.DirectorySeparatorChar + "SDATLang.xml"); xml = xml.Element(pluginHost.Get_Language()).Element("Messages"); Console.WriteLine(xml.Element("S00").Value); Console.WriteLine(xml.Element("S01").Value, sdat.files.header.nSounds.ToString()); } catch { throw new Exception("There was an error reading the XML file of language."); } FileSystem(ref sdat, file.path); Set_Data(ref sdat); return(sdat); }