public static Sound Read(Stream source) { BinaryReaderEx reader = new BinaryReaderEx(source); Sound result = new Sound(); int id = reader.ReadInt32(); if (id == 0x00394453) { int headerLength = reader.ReadInt32(); int sampleLength = reader.ReadInt32(); headerLength -= 12; if (headerLength > 0) reader.ReadBytes(headerLength); byte[] wavData = reader.ReadBytes(sampleLength); using (MemoryStream wavDataMem = new MemoryStream(wavData)) { using (WaveStream wavStream = new WaveFileReader(wavDataMem)) { byte[] rawWaveData = new byte[wavStream.Length]; wavStream.Read(rawWaveData, 0, (int)wavStream.Length); result.SetSound(rawWaveData, wavStream.WaveFormat); } } } return result; }
static public bool DetectBemani1(byte[] data) { if (data.Length < 0x68) return false; using (MemoryStream mem = new MemoryStream(data)) { BinaryReaderEx reader = new BinaryReaderEx(mem); mem.Position = mem.Length - 8; int endMarkerOffset = reader.ReadInt32(); int endMarkerData = reader.ReadInt32(); if (endMarkerData != 0x00000000 || endMarkerOffset != 0x7FFFFFFF) return false; } return true; }
public static BemaniSSP Read(Stream source) { BinaryReaderEx reader = new BinaryReaderEx(source); BemaniSSP result = new BemaniSSP(); reader.ReadBytes(16); // name of archive int length = reader.ReadInt32(); int count = (length - 18) / 4; for (int i = 0; i < count; i++) { int offset = reader.ReadInt32(); if (offset >= length && offset < reader.BaseStream.Length) { long currentOffset = reader.BaseStream.Position; reader.BaseStream.Position = offset; result.sounds.Add(BemaniSD9.Read(reader.BaseStream)); reader.BaseStream.Position = currentOffset; } } return result; }
public static BemaniSSQ Read(Stream source, int measureUnit) { BinaryReaderEx reader = new BinaryReaderEx(source); BemaniSSQ result = new BemaniSSQ(); Chunk tempoChunk = new Chunk(); List<Chunk> chartChunks = new List<Chunk>(); // parse all chunks in the file while (true) { int length = reader.ReadInt32(); if (length <= 0) break; Chunk chunk = Chunk.Read(source, length); switch (chunk.Type) { case 0x0001: // tempo info tempoChunk = chunk; break; case 0x0003: // chart chartChunks.Add(chunk); break; default: result.extraChunks.Add(chunk); break; } } // assemble tempo information result.TempoEntries.AddRange(DecodeTempoChunk(tempoChunk, measureUnit)); // convert charts foreach (Chunk chartChunk in chartChunks) { Chart chart = new Chart(); chart.Entries.AddRange(DecodeStepChunk(chartChunk, measureUnit)); chart.Tags["Panels"] = (chartChunk.Parameter & 0xF).ToString(); chart.Tags["Difficulty"] = ((chartChunk.Parameter & 0xFF00) >> 8).ToString(); result.charts.Add(chart); } return result; }
static public bool DetectBemani2DXArchive(byte[] data) { if (data.Length < 0x4C) return false; using (MemoryStream mem = new MemoryStream(data)) { BinaryReaderEx reader = new BinaryReaderEx(mem); mem.Position = 0x48; int offset = reader.ReadInt32(); if ((offset < 0) || ((offset + 4) > data.Length)) return false; mem.Position = offset; if (new string(reader.ReadChars(4)) != "2DX9") return false; return true; } }
private static Entry[] DecodeStepChunk(Chunk source, int measureUnit) { using (BinaryReaderEx reader = new BinaryReaderEx(new MemoryStream(source.Data))) { int count = reader.ReadInt32(); int[] metric = new int[count]; List<Entry> result = new List<Entry>(); for (int i = 0; i < count; i++) metric[i] = reader.ReadInt32(); byte[] step = reader.ReadBytes(count); byte[] freeze = reader.ReadBytes((int)reader.BaseStream.Length - (4 + (5 * count))); int freezeIndex = 0; int freezeCount = 0; while (freezeIndex < freeze.Length && freeze[freezeIndex] == 0) freezeIndex++; for (int i = 0; i < count; i++) { if (step[i] == 0) freezeCount++; } for (int i = 0; i < count; i++) { bool isShock = false; bool isFreeze = false; byte stepData = step[i]; int column = 0; if (stepData == 0) { isFreeze = true; stepData = freeze[freezeIndex]; freezeIndex++; freezeIndex++; // freeze type, ignored for now } else if ((stepData & 0xF) == 0xF) { isShock = true; } while (stepData > 0) { if ((stepData & 1) != 0) { Entry entry = new Entry(); entry.MetricMeasure = metric[i] / measureUnit; entry.MetricOffset = new Fraction(metric[i] % measureUnit, measureUnit); entry.Column = column; if (isFreeze) entry.Freeze = true; if (isShock) entry.Type = EntryType.Mine; else entry.Type = EntryType.Marker; result.Add(entry); } stepData >>= 1; column++; } } return result.ToArray(); } }
private static Entry[] DecodeTempoChunk(Chunk source, int measureUnit) { using (BinaryReaderEx reader = new BinaryReaderEx(new MemoryStream(source.Data))) { int count = reader.ReadInt32(); int[] metric = new int[count]; int[] linear = new int[count]; for (int i = 0; i < count; i++) metric[i] = reader.ReadInt32(); for (int i = 0; i < count; i++) linear[i] = reader.ReadInt32(); Entry[] result = new Entry[count - 1]; for (int i = 1; i < count; i++) { Entry entry = new Entry(); int metricDiff = metric[i] - metric[i - 1]; int linearDiff = linear[i] - linear[i - 1]; Fraction metricValue = new Fraction(metricDiff * 60, measureUnit / 4); Fraction linearValue = new Fraction(linearDiff, source.Parameter); Fraction bpmValue = metricValue / linearValue; entry.MetricMeasure = metric[i - 1] / measureUnit; entry.MetricOffset = new Fraction(metric[i - 1] % measureUnit, measureUnit); entry.LinearOffset = new Fraction(linear[i - 1], source.Parameter); entry.Type = EntryType.Tempo; entry.Value = bpmValue; result[i - 1] = entry; } return result; } }
public SHNFile(string path) { try { columns.Clear(); this.Path = path; if (System.IO.Path.GetFileNameWithoutExtension(path).ToLower().Contains("textdata")) isTextData = true; BinaryReaderEx r = new BinaryReaderEx(File.OpenRead(path)); if (path.EndsWith(".shn")) { this.CryptHeader = r.ReadBytes(0x20); data = r.ReadBytes(r.ReadInt32() - 0x24); } else data = r.ReadBytes((int)r.Length); r.Close(); if (Properties.Settings.Default.isNewCrypto == true) this.Decrypt(data, 0, data.Length, true); else this.Decrypt(data, 0, data.Length); r = new BinaryReaderEx(new MemoryStream(data)); this.Header = r.ReadUInt32(); //FileStream stream = new FileStream(System.IO.Path.GetDirectoryName(path) + "\\TestFile.dat", FileMode.Create); //stream.Write(data, 0, data.Length); //stream.Close(); //return; if (!((this.Header == 0xcdcdcdcd) | (this.Header == 0))) { //bleh, why check, unk.dat is useless, outspark uses other enc } //Parse columns this.RecordCount = r.ReadUInt32(); this.DefaultRecordLength = r.ReadUInt32(); this.ColumnCount = r.ReadUInt32(); this.ColumnNames = new string[this.ColumnCount]; this.ColumnTypes = new uint[this.ColumnCount]; this.ColumnLengths = new int[this.ColumnCount]; int num2 = 2; int unkCols = 0; for (uint i = 0; i < this.ColumnCount; i++) { string str = r.ReadString(0x30); // if (str.Length < 2) MessageBox.Show(str.Length.ToString()); uint num4 = r.ReadUInt32(); int num5 = r.ReadInt32(); SHNColumn col = new SHNColumn(); if (str.Length == 0) { str = "UnkCol" + unkCols.ToString(); unkCols++; } col.name = str; col.Type = num4; col.Lenght = num5; columns.Add(col); this.ColumnNames[i] = str; this.ColumnTypes[i] = num4; this.ColumnLengths[i] = num5; num2 += num5; } if (num2 != this.DefaultRecordLength) { throw new Exception("Wrong record lenght!"); } //generate columns this.GenerateColumns(table, columns); //add data into rows this.ReadRows(r, table); } catch (Exception e) { Stream X = new FileStream("unk.dat", FileMode.OpenOrCreate); BinaryWriter lol = new BinaryWriter(X); lol.Write(data, 0, data.Length); lol.Close(); throw new Exception("Unknown File Type -- dec to unk.dat Reason: " + e.Message); } }
private void ReadRows(BinaryReaderEx r, DataTable table) { object[] values = new object[columns.Count]; for (uint i = 0; i < this.RecordCount; i++) { uint RowLength = r.ReadUInt16(); for (int j = 0; j < columns.Count; j++) { switch (this.columns[j].Type) { case 1: values[j] = r.ReadByte(); break; case 2: values[j] = r.ReadUInt16(); break; case 3: values[j] = r.ReadUInt32(); break; case 5: values[j] = r.ReadSingle(); break; case 9: values[j] = r.ReadString(this.ColumnLengths[j]); break; case 11: values[j] = r.ReadUInt32(); break; case 12: values[j] = r.ReadByte(); break; case 13: values[j] = r.ReadInt16(); break; case 0x10: values[j] = r.ReadByte(); break; case 0x12: values[j] = r.ReadUInt32(); break; case 20: values[j] = r.ReadSByte(); break; case 0x15: values[j] = r.ReadInt16(); break; case 0x16: values[j] = r.ReadInt32(); break; case 0x18: values[j] = r.ReadString(this.ColumnLengths[j]); break; case 0x1a: //unk lenght values[j] = r.ReadString(); break; case 0x1b: values[j] = r.ReadUInt32(); break; } } table.Rows.Add(values); } }
public void LoadMe(string path) { BinaryReaderEx r = new BinaryReaderEx(File.OpenRead(path)); if (path.EndsWith(".shn")) { this.CryptHeader = r.ReadBytes(0x20); data = r.ReadBytes(r.ReadInt32() - 0x24); } else { data = r.ReadBytes((int)r.Length); } r.Close(); if (Properties.Settings.Default.isNewCrypto == true) this.Decrypt(data, 0, data.Length, true); else this.Decrypt(data, 0, data.Length); }