public static DigitDataSet LoadFromFile(string labelPath, string dataPath) { // Ensure the files exist. if (!File.Exists(labelPath)) { throw new FileNotFoundException("The given label file path does not exist."); } if (!File.Exists(dataPath)) { throw new FileNotFoundException("The given data file path does not exist."); } // Open the files in binary readers. BeBinaryReader labelReader = new BeBinaryReader(File.OpenRead(labelPath)); BeBinaryReader dataReader = new BeBinaryReader(File.OpenRead(dataPath)); // Ensure the magic numbers are correct. int labelVersion = labelReader.ReadInt32(); int dataVersion = dataReader.ReadInt32(); if (labelVersion != labelMagicNumber) { throw new Exception($"Label file's version number was invalid. Expecting {labelMagicNumber}, got {labelVersion}."); } if (dataVersion != dataMagicNumber) { throw new Exception($"Data file's version number was invalid. Expecting {dataMagicNumber}, got {dataVersion}."); } // Create the data set from the readers, and return it. return(new DigitDataSet(labelReader, dataReader)); }
public int[] readWINF(BeBinaryReader binSteam, int Base) { var HEAD = binSteam.ReadInt32(); // Read the header (WINF) var LENGTH = binSteam.ReadInt32(); // Read the count of how many pointers we have return(Helpers.readInt32Array(binSteam, LENGTH)); // Read all of the pointers, and return. }
public Stats(BeBinaryReader br) { var pos = br.BaseStream.Position; Flag = br.ReadInt32(); Unknown = br.ReadInt32(); TP = br.ReadByte(); MaxTP = br.ReadByte(); Kick = br.ReadByte(); MaxKick = br.ReadByte(); Catch = br.ReadByte(); MaxCatch = br.ReadByte(); Body = br.ReadByte(); MaxBody = br.ReadByte(); Guard = br.ReadByte(); MaxGuard = br.ReadByte(); Control = br.ReadByte(); MaxControl = br.ReadByte(); Speed = br.ReadByte(); MaxSpeed = br.ReadByte(); Unk = br.ReadBytes(0xE); Kakusei = br.ReadInt32(); XP = br.ReadInt32(); MoveUnk = br.ReadInt16(); MoveKakusei2 = br.ReadInt16(); MoveKakusei2_2 = br.ReadInt16(); MoveKakusei2_3 = br.ReadInt16(); MoveKakusei3 = br.ReadInt16(); MoveKakusei3_2 = br.ReadInt16(); MoveKakusei3_3 = br.ReadInt16(); Unk2 = br.ReadInt16(); }
internal ResultResponse(ResponseFrame frame) : base(frame) { Kind = (ResultResponseKind)BeBinaryReader.ReadInt32(); switch (Kind) { case ResultResponseKind.Void: Output = new OutputVoid(TraceId); break; case ResultResponseKind.Rows: Output = new OutputRows(BeBinaryReader, frame.RawStream is BufferedProtoBuf, TraceId); break; case ResultResponseKind.SetKeyspace: Output = new OutputSetKeyspace(BeBinaryReader.ReadString()); break; case ResultResponseKind.Prepared: Output = new OutputPrepared(BeBinaryReader, frame.FrameHeader.Version == ResponseFrame.ProtocolV2ResponseVersionByte); break; case ResultResponseKind.SchemaChange: Output = new OutputSchemaChange(BeBinaryReader, TraceId); break; default: throw new DriverInternalError("Unknown ResultResponseKind Type"); } }
public OfpPacketOut(Stream stream, OfpHeader header = null) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); Header = header ?? new OfpHeader(stream); br.Parse(out BufferId); br.Parse(out InPort); br.Parse(out ActionsLen); int length = ActionsLen; while (length >= 8) { var action = OfpActionHeader.ParseAction(stream); Actions[action.Header.Type] = action; length -= action.Header.Len; } if (BufferId == uint.MaxValue) //-1 { length = Header.Length - (int)Size - ActionsLen; if (length > 0) { br.Parse(out Data, length); } } }
/* ** CHUNKS DO NOT HAVE __ANY__ OFFSET POINTERS, LOCATION IS COMPLETELY VARIABLE ** ** Chunks must be aligned multiple of 4 bytes of one another. ** JAIV2 IBNK Structure ** ??? ENVT - Envelope Table ** ??? OSCT - Oscillator Table ** ??? RAND - Random Effects Table ** ??? SENS - Sensor Effect Table ** ??? INST - Instrument Table ** ??? PMAP - Percussion Map ** ??? LIST - Instrument List */ public JIBank loadIBNK(BeBinaryReader binStream, int Base) { Console.WriteLine("Start load ibnk"); var RetIBNK = new JIBank(); Console.WriteLine(Base); iBase = Base; if (binStream.ReadInt32() != IBNK) { throw new InvalidDataException("Section doesn't have an IBNK header"); } Boundaries = binStream.ReadInt32() + 8; // total length of our section, the data of the section starts at +8, so we need to account for that, too. RetIBNK.id = binStream.ReadInt32(); // Forgot this. Ibank ID. Important. OscTableOffset = findChunk(binStream, OSCT); // Load oscillator table chunk EnvTableOffset = findChunk(binStream, ENVT); // Load envelope table chunk RanTableOffset = findChunk(binStream, RAND); // Load random effect table chunk SenTableOffset = findChunk(binStream, SENS); // Load sensor table chunk ListTableOffset = findChunk(binStream, LIST); // load the istrument list PmapTableOffset = findChunk(binStream, PMAP); // Percussion mapping lookup table binStream.BaseStream.Position = OscTableOffset + iBase; // Seek to the position of the oscillator table loadBankOscTable(binStream, Base); // Load oscillator table, also handles the ENVT!! binStream.BaseStream.Position = ListTableOffset + iBase; // Seek to the instrument list base var instruments = loadInstrumentList(binStream, Base); // Load it. RetIBNK.Instruments = instruments; return(RetIBNK); }
public OfpFlowMod(Stream stream, OfpHeader header = null) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); Header = header ?? new OfpHeader(stream); //var pos = stream.Position; Match = new OfpMatch(stream); //pos = stream.Position; br.Parse(out Cookie); br.Parse(out Command); br.Parse(out IdleTimeout); br.Parse(out HardTimeout); br.Parse(out Priority); br.Parse(out BufferId); br.Parse(out OutPort); //FIXED: br.Parse(out Flags); //pos = stream.Position; IOfpAction action = OfpActionHeader.ParseAction(stream); while (action != null) { Actions[action.Header.Type] = action; action = OfpActionHeader.ParseAction(stream); } }
/* * JAIV2 KeyRegion Structure * 0x00 byte baseKey * 0x01 byte[0x3] unused; * 0x04 int32 velocityRegionCount * VelocityRegion[velocityRegionCount] velocities; // NOTE THESE ARENT POINTERS, THESE ARE ACTUAL OBJECTS. */ public JInstrumentKey readKeyRegion(BeBinaryReader binStream, int Base) { JInstrumentKey newKey = new JInstrumentKey(); newKey.Velocities = new JInstrumentKeyVelocity[0x81]; // Create region array //------- //Console.WriteLine(binStream.BaseStream.Position); newKey.baseKey = binStream.ReadByte(); // Store base key binStream.BaseStream.Seek(3, SeekOrigin.Current);; // Skip 3 bytes var velRegCount = binStream.ReadInt32(); // Grab vel region count var velLow = 0; // Again, these are regions -- see LoadInstrument for this exact code ( a few lines above ) for (int i = 0; i < velRegCount; i++) { var breg = readKeyVelRegion(binStream, Base); // Read the vel region. for (int b = 0; b < breg.baseVel - velLow; b++) { // They're velocity regions, so we're going to have a toothy / gappy piano. So we need to span the missing gaps with the previous region config. // This means that if the last key was 4, and the next key was 8 -- whatever parameters 4 had will span keys 4 5 6 and 7. newKey.Velocities[b] = breg; newKey.Velocities[127] = breg; } velLow = breg.baseVel; } return(newKey); }
private void BatchLoop(string filename, int nlength) { var demotag = Path.Combine(Environment.CurrentDirectory, "demo.sound_looping"); using (var fs = new FileStream(demotag, FileMode.OpenOrCreate, FileAccess.ReadWrite)) using (var ds = new FileStream(filename + "_looping", FileMode.OpenOrCreate, FileAccess.ReadWrite)) using (var ms = new MemoryStream()) using (var bw = new BeBinaryWriter(ms)) using (var br = new BeBinaryReader(ms)) { fs.CopyTo(ms); ms.Position = 0; var tagpath = filename.Substring(tagsdir.Length + 1); tagpath = tagpath.Substring(0, tagpath.Length - 6); MessageBox.Show(tagpath); var namelength = tagpath.Length; Byte nan = 0; bw.BaseStream.Seek(220, SeekOrigin.Begin); bw.Write(namelength); bw.BaseStream.Seek(308, SeekOrigin.Begin); bw.Write(tagpath); bw.Write(nan); ms.Position = 0; fs.Position = 0; ms.CopyTo(ds); } }
public void BeBinaryWriter_WriteBoolTest() { using var mstr = CreateMemStream(); using var bw = new BeBinaryWriter(mstr); using var br = new BeBinaryReader(mstr); bw.Write(false); bw.Write(false); bw.Write(true); bw.Write(false); bw.Write(true); bw.Write(5); bw.Write(0); bw.Flush(); mstr.Position = 0; Assert.That(br.ReadBoolean(), Is.EqualTo(false)); Assert.That(br.ReadBoolean(), Is.EqualTo(false)); Assert.That(br.ReadBoolean(), Is.EqualTo(true)); Assert.That(br.ReadBoolean(), Is.EqualTo(false)); Assert.That(br.ReadBoolean(), Is.EqualTo(true)); Assert.That(br.ReadInt32(), Is.EqualTo(5)); Assert.That(br.ReadInt32(), Is.EqualTo(0)); }
private short currentBankID = 0; // also runtime -- just for tracking public JIBank loadIBNK(BeBinaryReader binStream, int Base) { var RetIBNK = new JIBank(); binStream.BaseStream.Position = Base; long anchor = 0; // Return / Seekback anchor //binStream.BaseStream.Seek(-4, SeekOrigin.Current); if (binStream.ReadInt32() != IBNK) // Check if first 4 bytes are IBNK { throw new InvalidDataException("Data is not an IBANK"); } var SectionSize = binStream.ReadUInt32(); // Read IBNK Size var IBankID = binStream.ReadInt32(); // Read the global IBankID currentBankID = (short)IBankID; var IBankFlags = binStream.ReadUInt32(); // Flags? binStream.BaseStream.Seek(0x10, SeekOrigin.Current); // Skip Padding anchor = binStream.BaseStream.Position; var Instruments = loadBank(binStream, Base); // Load the instruments RetIBNK.id = IBankID; // Store bankID RetIBNK.Instruments = Instruments; // Store instruments return(RetIBNK); }
internal ResultResponse(ResponseFrame frame) : base(frame) { Kind = (ResultResponseKind)BeBinaryReader.ReadInt32(); switch (Kind) { case ResultResponseKind.Void: Output = new OutputVoid(TraceId); break; case ResultResponseKind.Rows: Output = new OutputRows(frame.Header.Version, BeBinaryReader, true, TraceId); break; case ResultResponseKind.SetKeyspace: Output = new OutputSetKeyspace(BeBinaryReader.ReadString()); break; case ResultResponseKind.Prepared: Output = new OutputPrepared(BeBinaryReader, frame.Header.Version > 1); break; case ResultResponseKind.SchemaChange: Output = new OutputSchemaChange(BeBinaryReader, TraceId); break; default: throw new DriverInternalError("Unknown ResultResponseKind Type"); } }
/* * JAIV1 Oscillator Format * 0x00 - byte mode * 0x01 - byte[3] unknown * 0x04 - float rate * 0x08 - int32 attackVectorOffset * 0x0C - int32 releaseVectorOffset * 0x10 - float width * 0x14 - float vertex */ public JOscillator loadOscillator(BeBinaryReader binStream, int Base) { var Osc = new JOscillator(); // Create new oscillator var target = binStream.ReadByte(); // load target -- what is it affecting? binStream.BaseStream.Seek(3, SeekOrigin.Current); // read 3 bytes? Osc.rate = binStream.ReadSingle(); // Read the rate at which the oscillator progresses -- this will be relative to the number of ticks per beat. var attackSustainTableOffset = binStream.ReadInt32(); // Offset of AD table var releaseDecayTableOffset = binStream.ReadInt32(); // Offset of SR table Osc.Width = binStream.ReadSingle(); // We should load these next, this is the width, ergo the value of the oscillator at 32768. Osc.Vertex = binStream.ReadSingle(); // This is the vertex, the oscillator will always cross this point. // To determine the value of an oscillator, it's Vertex + Width*(value/32768) -- each vector should progress the value, depending on the mode. if (attackSustainTableOffset > 0) // first is AS table { binStream.BaseStream.Position = attackSustainTableOffset + Base; // Seek to the vector table Osc.envelopes[0] = readEnvelope(binStream, Base); // Load the table } if (releaseDecayTableOffset > 0) // Next is RD table { binStream.BaseStream.Position = releaseDecayTableOffset + Base; // Seek to the vector and load it Osc.envelopes[1] = readEnvelope(binStream, Base); // loadddd } Osc.target = (JOscillatorTarget)target; return(Osc); }
private long ReadJARCSizePointer(BeBinaryReader br) { var sectSize = br.ReadUInt32(); return(sectSize + 8); // This is basically taking the section size pointer and adding 8 to it, because the size is always 8 bytes deep. // Adding 8 to this makes it a pointer to the next section relative to the section base :v }
/* * JAIV2 Oscillator Structure * 0x00 - int32 0x4F736369 'Osci' * 0x04 - byte mode * 0x05 - byte[3] unknown * 0x08 - float rate * 0x0c - int32 attackVectorOffset (RELATIVE TO ENVT + 0x08) * 0x10 - int32 releaseVectorOffset (RELATIVE TO ENVT + 0x08) * 0x14 - float width * 0x18 - float vertex */ /* NOTE THAT THESE OSCILLATORS HAVE THE SAME FORMAT AS JAIV1, HOWEVER THE VECTORS ARE IN THE ENVT */ public JOscillator loadOscillator(BeBinaryReader binStream, int EnvTableBase) { var Osc = new JOscillator(); // Create new oscillator if (binStream.ReadInt32() != Osci) // Read first 4 bytes { throw new InvalidDataException("Oscillator format is invalid. " + binStream.BaseStream.Position); } var target = binStream.ReadByte(); // load target -- what is it affecting? binStream.BaseStream.Seek(3, SeekOrigin.Current); // read 3 bytes? Osc.rate = binStream.ReadSingle(); // Read the rate at which the oscillator progresses -- this will be relative to the number of ticks per beat. var attackSustainTableOffset = binStream.ReadInt32(); // Offset of AD table var releaseDecayTableOffset = binStream.ReadInt32(); // Offset of SR table Osc.Width = binStream.ReadSingle(); // We should load these next, this is the width, ergo the value of the oscillator at 32768. Osc.Vertex = binStream.ReadSingle(); // This is the vertex, the oscillator will always cross this point. // To determine the value of an oscillator, it's Vertex + Width*(value/32768) -- each vector should progress the value, depending on the mode. // We need to add + 8 to the offsets, because the pointers are the offset based on where the data starts, not the section if (attackSustainTableOffset > 0) // first is AS table { binStream.BaseStream.Position = attackSustainTableOffset + EnvTableBase + 8; // Seek to the vector table Osc.envelopes[0] = readEnvelope(binStream, EnvTableBase + 8); // Load the table } if (releaseDecayTableOffset > 0) // Next is RD table { binStream.BaseStream.Position = releaseDecayTableOffset + EnvTableBase + 8; // Seek to the vector and load it Osc.envelopes[1] = readEnvelope(binStream, EnvTableBase + 8); // loadddd } Osc.target = OscillatorTargetConversionLUT[target]; return(Osc); }
private void ParsePlayerFile(Stream input) { PlayerNames = Names.GetTextFile("Strikers2013Editor.Common.playerNames.txt"); using (var br = new BeBinaryReader(input)) { DataBackup = br.ReadBytes(0xFA4); br.BaseStream.Position = 0x10; var count = br.ReadInt32(); br.BaseStream.Position = 0xFA4; Players = new List <PlayerDef>(); for (var i = 1; i < count; i++) { if (br.BaseStream.Position > br.BaseStream.Length - 0x148) { break; } var player = new PlayerDef(br); Players.Add(player); if (i < PlayerNames.Length) { cmbPlayers.Items.Add(PlayerNames[i]); } else { cmbPlayers.Items.Add(player.Name); } } } }
public static BSTWaveInfo readStream(BeBinaryReader br, int fmt) { var newWI = new BSTWaveInfo(); newWI.format = fmt; switch (fmt & 0xF0) { case 0x40: break; case 0x50: // Console.WriteLine($"{br.BaseStream.Position:X}"); newWI.wSoundID = br.ReadInt16(); // Console.WriteLine(newWI.wSoundID); break; case 0x60: break; case 0x70: newWI.streamFormat = br.ReadByte(); newWI.unk1 = br.ReadByte(); newWI.flags = br.ReadUInt16(); var namePointer = br.ReadInt32(); br.BaseStream.Position = namePointer; newWI.streamFilePath = JBST.readTerminated(br, 0x00); break; } return(newWI); }
public OfpActionNwAddr(Stream stream) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); Header = new OfpActionHeader(stream); br.Parse(out NwAddr); }
public OfpVendorStats(Stream stream, int length) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); br.Parse(out Vendor, 4); br.Parse(out Content, length); }
public OfpPortStatsRequest(Stream stream, OfpHeader header = null) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); br.Parse(out PortNo); br.ReadBytes(6); }
public OfpQueuePropMinRate(Stream stream) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); PropHeader = new OfpQueuePropHeader(stream); br.Parse(out Rate); }
/* * JAIV1 BANK structure * 0x00 int32 0x42414E4B 'BANK'; * 0x04 int32[0xF0] InstrumentPointers * ---- NOTE: If the instrument pointer is 0, then the instrument for that index is NULL! */ public JInstrument[] loadBank(BeBinaryReader binStream, int Base) { if (binStream.ReadUInt32() != BANK) // Check if first 4 bytes are BANK { throw new InvalidDataException("Data is not a BANK"); } var InstrumentPoiners = new int[0xF0]; // Table of pointers for the instruments; var Instruments = new JInstrument[0xF0]; InstrumentPoiners = Helpers.readInt32Array(binStream, 0xF0); // Read instrument pointers. for (int i = 0; i < 0xF0; i++) { binStream.BaseStream.Position = InstrumentPoiners[i] + Base; // Seek to pointer position var type = binStream.ReadInt32(); // Read type binStream.BaseStream.Seek(-4, SeekOrigin.Current); // Seek back 4 bytes to undo header read. currentInstID = (short)i; switch (type) { case INST: Instruments[i] = loadInstrument(binStream, Base); // Load instrument break; case PER2: Instruments[i] = loadPercussionInstrument(binStream, Base); // Load percussion break; default: // no action, we don't know what it is and it won't misalign. break; } } return(Instruments); }
public OfpFlowStats(Stream stream) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); br.Parse(out Length); br.Parse(out TableId); br.ReadBytes(1); Match = new OfpMatch(stream); br.Parse(out DurationSec); br.Parse(out DurationNsec); br.Parse(out Priority); br.Parse(out IdleTimeout); br.Parse(out HardTimeout); br.ReadBytes(6); br.Parse(out Cookie); br.Parse(out PacketCount); br.Parse(out ByteCount); IOfpAction action = OfpActionHeader.ParseAction(stream); while (action != null) { Actions[action.Header.Type] = action; action = OfpActionHeader.ParseAction(stream); } }
public static int aaf_GetSectionSize(JAIInitSection sect, BeBinaryReader br) { switch (sect.type) { default: return(sect.size); } }
public OfpQueuePropHeader(Stream stream) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); br.Parse(out Property); br.Parse(out Len); br.ReadBytes(4); }
public OfpSwitchConfig(Stream stream, OfpHeader header = null) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); Header = header ?? new OfpHeader(stream); br.Parse(out Flags); br.Parse(out MissSendLen); }
internal ErrorResponse(ResponseFrame frame) : base(frame) { int errorCode = BeBinaryReader.ReadInt32(); string message = BeBinaryReader.ReadString(); Output = OutputError.CreateOutputError(errorCode, message, BeBinaryReader); }
public OfpPacketQueue(Stream stream) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); br.Parse(out QueueId); br.Parse(out Len); br.ReadBytes(2); //PAD }
public OfpQueueGetConfigRequest(Stream stream, OfpHeader header = null) { BeBinaryReader br = new BeBinaryReader(stream, Encoding.ASCII, true); Header = header ?? new OfpHeader(stream); br.Parse(out Port); br.ReadBytes(2); }
public int Flag; // & 0x2000 => key player public TeamPlayer(BeBinaryReader br) { Id = br.ReadInt32(); KitNumber = br.ReadInt32(); FormationIndex = br.ReadInt32(); ClubroomKit = br.ReadInt32(); Flag = br.ReadInt32(); }