Пример #1
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);
        }
Пример #2
0
        /*
        ** 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 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));
        }
Пример #4
0
        /*
         * 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);
        }
Пример #5
0
        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();
        }
Пример #6
0
        /*
         * 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);
        }
Пример #7
0
        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.
        }
Пример #8
0
        public int[] readWBCT(BeBinaryReader binSteam, int Base)
        {
            var HEAD   = binSteam.ReadInt32();                // Read the header
            var unk    = binSteam.ReadInt32();                // Read unknown 4 bytes
            var LENGTH = binSteam.ReadInt32();                // Read the count of how mamny pointers we have

            return(Helpers.readInt32Array(binSteam, LENGTH)); // Read all of the pointers, and return.
        }
Пример #9
0
        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();
        }
Пример #10
0
        private JAIInitSection load2PtSection(BeBinaryReader aafRead)
        {
            var NewSect = new JAIInitSection();
            var offset  = aafRead.ReadInt32();
            var size    = aafRead.ReadInt32();

            NewSect.start = offset;
            NewSect.size  = size;
            NewSect.flags = 0;
            return(NewSect);
        }
Пример #11
0
        /* JAIV2 Instrument Structure
         *    0x00 int32 = 0x496E7374 'Inst'
         *    0x04 int32 oscillatorCount
         *    0x08 int32[oscillatorCount] oscillatorIndicies
         *    ???? int32 0
         *    ???? int32 keyRegionCount
         *    ???? keyRegion[keyRegionCount]
         *    ???? float gain
         *    ???? float freqmultiplier
         *
         */
        public JInstrument loadInstrument(BeBinaryReader binStream, int Base)
        {
            var newInst = new JInstrument();

            newInst.IsPercussion = false; // Instrument isn't percussion
            // This is wrong, they come at the end of the instrument
            //newInst.Pitch = 1; // So these kinds of instruments don't initialize with a pitch value, which is strange.
            //newInst.Volume = 1; // I guess they figured that it was redundant since they're already doing it in 3 other places.
            if (binStream.ReadInt32() != Inst)
            {
                throw new InvalidDataException("Inst section started with unexpected data");
            }
            var osciCount = binStream.ReadInt32();                   // Read the count of the oscillators.

            newInst.oscillatorCount = (byte)osciCount;               // Hope no instrument never ever ever has > 255 oscillators lol.
            newInst.oscillators     = new JOscillator[osciCount];    // Initialize the instrument with the proper amount of oscillaotrs
            for (int i = 0; i < osciCount; i++)                      // Loop through and read each oscillator.
            {
                var osciIndex = binStream.ReadInt32();               // Each oscillator is stored as a 32 bit index.
                newInst.oscillators[i] = bankOscillators[osciIndex]; // We loaded the oscillators already, I hope.  So this will grab them by their index.
            }
            var notpadding = binStream.ReadInt32();                  // NOT PADDING. F**K. Probably effects.

            Helpers.readInt32Array(binStream, notpadding);
            var keyRegCount = binStream.ReadInt32();
            var keyLow      = 0;                              // For region spanning.

            JInstrumentKey[] keys = new JInstrumentKey[0x81]; // Always go for one more.
            for (int i = 0; i < keyRegCount; i++)             // Loop through all pointers.
            {
                var bkey = readKeyRegion(binStream, Base);    // Read the key region
                //Console.WriteLine("KREG BASE KEY {0}", bkey.baseKey);
                for (int b = 0; b < bkey.baseKey - keyLow; b++)
                {
                    //  They're key 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.
                    keys[b + keyLow] = bkey; // span the keys
                    keys[127]        = bkey;
                }
                keyLow = bkey.baseKey; // Store our last key
            }
            newInst.Keys = keys;

            newInst.Volume = binStream.ReadSingle(); // ^^
            newInst.Pitch  = binStream.ReadSingle(); // Pitch and volume come last???
            // WE HAVE READ EVERY BYTE IN THE INST, WOOO
            return(newInst);
        }
Пример #12
0
        /*
         * 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);
        }
Пример #13
0
        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");
            }
        }
Пример #14
0
        public Team(BeBinaryReader br)
        {
            br.BaseStream.Position += 2;
            Kit       = br.ReadInt16();
            Formation = br.ReadInt32();
            Manager   = br.ReadInt32();
            Coach     = br.ReadInt32();
            Emblem    = 0; //Placeholder
            Players   = new TeamPlayer[16];
            Name      = "";

            for (var i = 0; i < 16; i++)
            {
                Players[i] = new TeamPlayer(br);
            }
        }
Пример #15
0
        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));
        }
Пример #16
0
        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);
        }
Пример #17
0
        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");
            }
        }
Пример #18
0
        /*
         *  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);
        }
Пример #19
0
        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);
                    }
                }
            }
        }
Пример #20
0
        /* JAIV1 OSCT Structure
         *  0x00 int32 0x4F534354 'OSCT'
         *  0x04 int32 SectionLength (+8 for entire section)
         *  0x08 int32 OscillatorCouint
         */

        private void loadBankOscTable(BeBinaryReader binStream, int Base)
        {
            if (binStream.ReadInt32() != OSCT)                                                                                            // Check if it has the oscillator table header
            {
                throw new InvalidDataException("Oscillator table section started with unexpected data " + binStream.BaseStream.Position); // Throw if it doesn't
            }
            binStream.ReadInt32();                                                                                                        // This is the section length, its mainly used for seeking the file so we won't touch it.
            var count = binStream.ReadInt32();                                                                                            // Read the count

            bankOscillators = new JOscillator[count];                                                                                     // Initialize the bank oscillators with the number of oscillators int he table
            for (int i = 0; i < count; i++)                                                                                               // Loop through each onne
            {
                var returnPos = binStream.BaseStream.Position;                                                                            // Save our position, the oscillator load function destroys our position.
                bankOscillators[i]            = loadOscillator(binStream, EnvTableOffset + iBase);                                        // Ask the oscillator to load
                binStream.BaseStream.Position = returnPos + 0x1c;                                                                         // Oscillatrs are 0x1c in length, so advance to the next osc.
            }
        }
Пример #21
0
        public static JBSC readStream(BeBinaryReader br, JBST jbst)
        {
            br.ReadInt32(); // skip head lol
            var newBSC = new JBSC();

            newBSC.size   = br.ReadInt32();
            newBSC.groups = new JBSCGroup[jbst.sections[0].groups.Length];
            var sectionPointers = Helpers.readInt32Array(br, jbst.sections[0].groups.Length);

            for (int i = 0; i < newBSC.groups.Length; i++)
            {
                br.BaseStream.Position = sectionPointers[i];
                Console.WriteLine(sectionPointers[i]);
                newBSC.groups[i] = JBSCGroup.readStream(br);
            }
            return(newBSC);
        }
Пример #22
0
        internal ErrorResponse(ResponseFrame frame)
            : base(frame)
        {
            int    errorCode = BeBinaryReader.ReadInt32();
            string message   = BeBinaryReader.ReadString();

            Output = OutputError.CreateOutputError(errorCode, message, BeBinaryReader);
        }
Пример #23
0
        private JWave loadWave(BeBinaryReader binStream, int Base)
        {
            var newWave = new JWave();

            binStream.ReadByte();                                                           // First byte unknown?
            newWave.format = binStream.ReadByte();                                          // Read wave format, usually 5
            newWave.key    = binStream.ReadByte();                                          // Read the base tuning key
            //Console.WriteLine(newWave.key);
            binStream.ReadByte();                                                           // fourth byte unknown?
            newWave.sampleRate  = binStream.ReadSingle();                                   // Read the samplerate
            newWave.wsys_start  = binStream.ReadInt32();                                    // Read the offset in the AW
            newWave.wsys_size   = binStream.ReadInt32();                                    // Read the length in the AW
            newWave.loop        = binStream.ReadUInt32() == UInt32.MaxValue ? true : false; // Check if it loops?
            newWave.loop_start  = binStream.ReadInt32();                                    // Even if looping is disabled, it should still read loops
            newWave.loop_end    = binStream.ReadInt32();                                    // Sample index of loop end
            newWave.sampleCount = binStream.ReadInt32();                                    // Sample count
            return(newWave);
        }
Пример #24
0
        /* This class originally had something more clever going on, Zelda Four Swords threw a giant f*****g wrench in my code. */
        /* I'd not recommend using it, as it might be removed in the future if the codebase for it doesn't grow. */
        public static JAIInitType checkVersion(ref byte[] data)
        {
            var JStream = new MemoryStream(data);
            var JReader = new BeBinaryReader(JStream);
            var hdr     = JReader.ReadUInt32();

            if (hdr == 1094803260) // AA_< LITERAL , opening of BAA archive or BAA Format
            {
                JReader.Close();
                JStream.Close();
                return(JAIInitType.BAA); // return BAA type
            }
            else
            { /* PIKMIN BX ARCHIVE */
              /* CHECKING FOR BX
               * This is not 100% accurate, but the likelyhood of something like this actually getting confused with AAF is slim to none.
               * Considering there's only one game that uses BX.
               */

                JStream.Position = 0;               // reset pos;
                var BXWSOffs = JReader.ReadInt32(); // should point to location in file.
                if (BXWSOffs < JStream.Length)      // check if is within BX
                {
                    JStream.Position = BXWSOffs;
                    var WSO = JReader.ReadInt32();
                    if (WSO < JStream.Length) // fall out, not valid
                    {
                        var WSYS = JReader.ReadInt32();
                        if (WSYS == 0x57535953) // 0x57535953 is literal WSYS
                        {
                            JReader.Close();    // flush / close streams
                            JStream.Close();    // flush and close streams
                            return(JAIInitType.BX);
                        }
                    }
                }
            }
            // * The init type is otherwise AAF.
            {
                JReader.Close();
                JStream.Close();
                return(JAIInitType.AAF); // JAIInitSection v1 doesn't have an identifying header.
            }
        }
Пример #25
0
        public static BSTGroup readStream(BeBinaryReader br)
        {
            var newSect = new BSTGroup();
            var count   = br.ReadInt32();

            br.ReadInt32(); // Alignment (skip 4 bytes, always 0);
            newSect.waves = new BSTWaveInfo[count];
            for (int i = 0; i < count; i++)
            {
                var anch = br.BaseStream.Position + 4; // Return to the section in front of the current one
                var type = br.ReadByte();              // Describes type
                var addr = Helpers.ReadUInt24BE(br);
                br.BaseStream.Position = addr;
                newSect.waves[i]       = BSTWaveInfo.readStream(br, type);

                br.BaseStream.Position = anch;
            }
            return(newSect);
        }
Пример #26
0
        private JC_DFEntry[] loadC_DF(BeBinaryReader binStream, int Base)
        {
            binStream.ReadInt32();                                  // should be C-DF.
            var count = binStream.ReadInt32();                      // Read the count
            //Console.WriteLine("{0:X}" , binStream.BaseStream.Position); // DEBUG DEEEEBUG
            var Offsets = Helpers.readInt32Array(binStream, count); // Read all offsets, (count int32's)
            var idmap   = new JC_DFEntry[count];                    // New array to store all the waveid's in

            for (int i = 0; i < count; i++)
            {
                binStream.BaseStream.Position = Offsets[i] + Base; // Seek to each c_DF entry
                idmap[i] = new JC_DFEntry
                {
                    mOffset = (int)binStream.BaseStream.Position,
                    awid    = binStream.ReadInt16(), // read AW ID -- A better name for this might be "SystemID"
                    waveid  = binStream.ReadInt16()  // Read Wave ID
                };
            }
            return(idmap);
        }
Пример #27
0
        public static int[] readInt32Array(BeBinaryReader binStream, int count)
        {
            var b = new int[count];

            for (int i = 0; i < count; i++)
            {
                b[i] = binStream.ReadInt32();
            }

            return(b);
        }
Пример #28
0
        public static BSTNSection readStream(BeBinaryReader br)
        {
            var newSect = new BSTNSection();

            newSect.count = br.ReadInt32();
            var nameOffset = br.ReadInt32();

            newSect.groups = new BSTNGroup[newSect.count];
            var groupPointers = Helpers.readInt32Array(br, newSect.count);

            br.BaseStream.Position = nameOffset;
            newSect.name           = JBST.readTerminated(br, 0x00);
            //Console.WriteLine(newSect.name);
            for (int i = 0; i < groupPointers.Length; i++)
            {
                br.BaseStream.Position = groupPointers[i];
                newSect.groups[i]      = BSTNGroup.readStream(br);
            }
            return(newSect);
        }
Пример #29
0
        /*
         *  JAIV2 LIST STRUCTURE
         *  0x00 - int32 0x4C495354 'LIST';
         *  0x04 - int32 length
         *  0x08 - int32 count
         *  0x0c - int32[count] instrumentPointers (RELATIVE TO IBANK 0x00)
         */

        public JInstrument[] loadInstrumentList(BeBinaryReader binStream, int Base)
        {
            JInstrument[] instruments = new JInstrument[0xF0];                                                                     // JSystem doesn't have more than 0xF0 instruments in each bank
            if (binStream.ReadInt32() != LIST)                                                                                     // Verify we're loading the right section
            {
                throw new InvalidDataException("LIST data section started with unexpected data " + binStream.BaseStream.Position); // Throw if it's not the right data
            }
            binStream.ReadInt32();                                                                                                 // Section Length // Section lenght doesn't matter, but we have to read it to keep alignment.
            var count = binStream.ReadInt32();                                                                                     // Count of entries in the section (Including nulls.)
            // why are these F***S relative whenever literally nothing else in the file is ? //
            var pointers = Helpers.readInt32Array(binStream, count);                                                               // This will be an in32[] of pointers

            for (int i = 0; i < count; i++)
            {
                if (pointers[i] < 1)                                  // Instrument is empty.
                {
                    continue;                                         // Instrument is empty. Skip this iteration
                }
                binStream.BaseStream.Position = Base + pointers[i];   // F**K THIS. Err I mean. Seek to the position of the instrument index + the base of the bank.
                var IID = binStream.ReadInt32();                      // read the identity at the base of each section
                binStream.BaseStream.Seek(-4, SeekOrigin.Current);    // Seek back identity (We read 4 bytes for the ID)

                switch (IID)                                          // Switch ID
                {
                case Inst:                                            // It's a regular instrument
                    instruments[i] = loadInstrument(binStream, Base); // Ask it to load (We're already just behind the Inst)
                    break;

                case Perc:     // Percussion Instrument
                    instruments[i] = loadPercussionInstrument(binStream, Base);
                    break;

                default:

                    Console.WriteLine("unknown inst index {0:X}", binStream.BaseStream.Position);
                    break;
                }
            }

            return(instruments);
        }
Пример #30
0
        public JWaveSystem loadWSYS(BeBinaryReader binStream, int Base)
        {
            var newWSYS = new JWaveSystem();

            binStream.BaseStream.Position = Base;
            newWSYS.mOffset = (int)binStream.BaseStream.Position;

            if (binStream.ReadInt32() != WSYS) // Check if first 4 bytes are WSYS
            {
                throw new InvalidDataException("Data is not an WSYS");
            }

            var wsysSize = binStream.ReadInt32(); // Read the size of the WSYS
            var wsysID   = binStream.ReadInt32(); // Read WSYS ID
            var unk1     = binStream.ReadInt32(); // Unused?
            var waveINF  = binStream.ReadInt32(); // Offset to WINF
            var waveBCT  = binStream.ReadInt32(); // Offset to WBCT

            /* Should probably squish this into a different function. And I did. */

            binStream.BaseStream.Position = waveINF + Base; // Seek to  WINF relative to base.
            var winfoPointers = readWINF(binStream, Base);  // Read the waveGroup pointers

            binStream.BaseStream.Position = waveBCT + Base; // Seek to the WBCT
            var wbctPointers = readWBCT(binStream, Base);   // load the pointers for the wbct (Wave ID's)



            JWaveGroup[] WSYSGroups = new JWaveGroup[winfoPointers.Length]; // The count of waveInfo's determines the amount of groups -- there is one WINF entry per group
            JWaveScene[] WSYSScenes = new JWaveScene[wbctPointers.Length];

            for (int i = 0; i < WSYSGroups.Length; i++)
            {
                binStream.BaseStream.Position = Base + winfoPointers[i]; // Seek to the wavegroup base.
                WSYSGroups[i] = readWaveGroup(binStream, Base);          // load the WaveGroup
            }
            for (int i = 0; i < WSYSGroups.Length; i++)
            {
                var currentWG = WSYSGroups[i];                          // After they've been loaded, we need to load their wave ID's
                binStream.BaseStream.Position = Base + wbctPointers[i]; // this is achieve by the WBCT, which points to a SCNE
                WSYSScenes[i] = new JWaveScene()
                {
                    mOffset = (int)binStream.BaseStream.Position
                };

                var scenes = loadScene(binStream, Base);              // Load the SCNE object
                {
                    binStream.BaseStream.Position = scenes[0] + Base; // The SCNE contains pointers to C-DF, C-EX, and C-ST -- we only know that C-DF works.

                    var IDMap = loadC_DF(binStream, Base);            // load the C_DF, which gives us  an array of C_DF entries, containing awID and WaveID.
                    WSYSScenes[i].CDFData = IDMap;
                }
            }
            newWSYS.id     = wsysID;     // We loaded the ID from above, store it
            newWSYS.Scenes = WSYSScenes;
            newWSYS.Groups = WSYSGroups; // We need to store the groups too, so let's do that.
            return(newWSYS);
        }