예제 #1
0
        void LoadFmtBlock(int size)
        {
            var format = mReader.ReadS16();

            if (format != 1)
            {
                mareep.WriteError("WAV: only LPCM is supported.");
            }

            mChannelCount = mReader.Read16();

            if (mChannelCount < 1 || mChannelCount > 2)
            {
                mareep.WriteError("WAV: only mono or stereo is supported.");
            }

            mSampleRate = mReader.ReadS32();
            mByteRate   = mReader.ReadS32();
            mBlockAlign = mReader.Read16();
            mBitDepth   = mReader.Read16();

            if (mBitDepth != 8 && mBitDepth != 16)
            {
                mareep.WriteError("WAV: only bit-depths of 8 and 16 are supported.");
            }
        }
예제 #2
0
        protected override void loadBlo1(aBinaryReader reader)
        {
            base.loadBlo1(reader);

            var finder = bloResourceFinder.getFinder();

            int numparams = reader.Read8();

            mFont = finder.find <bloResFont>(reader, "font");

            mTopColor    = new bloColor(reader.Read32());
            mBottomColor = new bloColor(reader.Read32());

            int binding = reader.Read8();

            mHBinding = (bloTextboxHBinding)((binding >> 2) & 3);
            mVBinding = (bloTextboxVBinding)((binding >> 0) & 3);

            mFontSpacing = reader.ReadS16();
            mFontLeading = reader.ReadS16();
            mFontWidth   = reader.Read16();
            mFontHeight  = reader.Read16();

            int strlen = reader.Read16();

            setString(reader.Read8s(strlen));

            numparams -= 10;

            if (numparams > 0)
            {
                if (reader.Read8() != 0)
                {
                    setConnectParent(true);
                }
                --numparams;
            }

            if (numparams > 0)
            {
                mFromColor = new bloColor(reader.Read32());
                --numparams;
            }
            else
            {
                mFromColor = new bloColor(bloColor.cZero);
            }

            if (numparams > 0)
            {
                mToColor = new bloColor(reader.Read32());
                --numparams;
            }
            else
            {
                mToColor = new bloColor(bloColor.cOne);
            }

            reader.Skip(4);
        }
예제 #3
0
        public static bloScreen loadBlo1(Stream stream)
        {
            aBinaryReader reader = new aBinaryReader(stream, Endianness.Big, Encoding.GetEncoding(1252));
            bloScreen     scrn   = new bloScreen();

            if (reader.Read32() != cSCRN)
            {
                return(null);
            }
            if (reader.Read32() != cBLO1)
            {
                return(null);
            }
            reader.Step(24);
            if (reader.Read32() != cINF1)
            {
                return(null);
            }
            long inf1size = reader.Read32();
            int  width    = reader.ReadS16();
            int  height   = reader.ReadS16();

            scrn.mRect.set(0, 0, width, height);
            scrn.mTintColor = new bloColor(reader.Read32());
            if (!loadBlo1(scrn, reader))
            {
                return(null);
            }
            return(scrn);
        }
예제 #4
0
        static void DecodeStreamPcm(aBinaryReader reader, aBinaryWriter writer, int sampleCount)
        {
            for (var i = 0; i < sampleCount; ++i)
            {
                writer.WriteS16(reader.ReadS16());
                writer.WriteS16(reader.ReadS16());

                if ((i % cMessageInterval) == 0 || i >= sampleCount)
                {
                    mareep.WriteMessage("\rSamples decoded: {0}/{1}", System.Math.Min((i + 1), sampleCount), sampleCount);
                }
            }
        }
예제 #5
0
        public override void load(Stream stream)
        {
            aBinaryReader reader = new aBinaryReader(stream, Endianness.Big);

            mFormat       = (gxTextureFormat)reader.Read8(); // 0000
            mTransparency = reader.Read8();                  // 0001
            mWidth        = reader.Read16();                 // 0002
            mHeight       = reader.Read16();                 // 0004
            mWrapS        = (gxWrapMode)reader.Read8();      // 0006
            mWrapT        = (gxWrapMode)reader.Read8();      // 0007
            reader.Step(1);                                  // 0008 (0001)
            mTlutFormat = (gxTlutFormat)reader.Read8();      // 0009
            int  tlutentrycount = reader.Read16();           // 000A
            long tlutoffset     = reader.Read32();           // 000C

            mMipMap     = (reader.Read8() != 0);             // 0010
            mEdgeLOD    = (reader.Read8() != 0);             // 0011
            mBiasClamp  = (reader.Read8() != 0);             // 0012
            mMaxAniso   = (gxAnisotropy)reader.Read8();      // 0013
            mMinFilter  = (gxTextureFilter)reader.Read8();   // 0014
            mMagFilter  = (gxTextureFilter)reader.Read8();   // 0015
            mMinLod     = reader.ReadS8();                   // 0016
            mMaxLod     = reader.ReadS8();                   // 0017
            mImageCount = reader.Read8();                    // 0018 (0001)
            mLodBias    = reader.ReadS16();                  // 001A
            long texoffset = reader.Read32();                // 001C

            loadImageData(reader, texoffset);
            if (tlutentrycount > 0)
            {
                loadPaletteData(reader, tlutentrycount, tlutoffset);
            }
        }
예제 #6
0
        protected override void loadCompact(aBinaryReader reader)
        {
            base.loadCompact(reader);

            var finder = bloResourceFinder.getFinder();

            mFont = finder.find <bloResFont>(reader, "font");

            mTopColor    = new bloColor(reader.Read32());
            mBottomColor = new bloColor(reader.Read32());

            int hbinding = reader.Read8();

            mHBinding = (bloTextboxHBinding)(hbinding & 127);
            mVBinding = (bloTextboxVBinding)reader.Read8();

            if ((hbinding & 0x80) != 0)
            {
                mFontSpacing = reader.ReadS16();
                mFontLeading = reader.ReadS16();
                mFontWidth   = reader.Read16();
                mFontHeight  = reader.Read16();
            }
            else if (mFont != null)
            {
                mFontSpacing = 0;
                mFontLeading = mFont.getLeading();
                mFontWidth   = mFont.getWidth();
                mFontHeight  = mFont.getHeight();
            }
            else
            {
                mFontSpacing = 0;
                mFontLeading = 0;
                mFontWidth   = 0;
                mFontHeight  = 0;
            }

            int strlen = reader.Read16();

            setString(reader.Read8s(strlen));

            mFromColor = new bloColor(bloColor.cZero);
            mToColor   = new bloColor(bloColor.cOne);

            reader.Skip(4);
        }
예제 #7
0
        protected virtual void loadCompact(aBinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            mVisible = (reader.Read8() != 0);
            reader.Step(1);

            mName = reader.Read32();

            int left   = reader.ReadS16();
            int top    = reader.ReadS16();
            int width  = reader.ReadS16();
            int height = reader.ReadS16();

            mRect.set(left, top, (left + width), (top + height));

            setBasePosition(bloAnchor.TopLeft);
            mAngle        = 0.0d;
            mAlpha        = 255;
            mInheritAlpha = true;
        }
예제 #8
0
파일: whap.cs 프로젝트: impiaaa/flaaffy
        protected override WaveBank DoTransform(WaveBank obj)
        {
            if (obj != null)
            {
                return(obj);
            }

            mReader.Keep();
            mReader.PushAnchor();

            if (mReader.Read32() != WSYS)
            {
                mareep.WriteError("WSYS: could not find header.");
            }

            var size = mReader.ReadS32();

            mReader.Step(8);             // unused
            var winfOffset = mReader.ReadS32();
            var wbctOffset = mReader.ReadS32();

            mareep.WriteMessage("WSYS: header found, size {0:F1} KB\n", ((double)size / 1024.0d));

            var waveBank = new WaveBank();

            waveBank.Name = mName;

            mReader.Goto(winfOffset);

            if (mReader.Read32() != WINF)
            {
                mareep.WriteError("WSYS: could not find WINF at 0x{0:X6}.", winfOffset);
            }

            var waveGroupCount = mReader.ReadS32();

            if (waveGroupCount < 0)
            {
                mareep.WriteError("WSYS: bad wave-group count '{0}' in WINF.", waveGroupCount);
            }

            mareep.WriteMessage("WSYS: WINF found, {0} wave group(s).\n", waveGroupCount);

            var waveGroupOffsets = mReader.ReadS32s(waveGroupCount);

            mReader.Goto(wbctOffset);

            if (mReader.Read32() != WBCT)
            {
                mareep.WriteError("WSYS: could not find WBCT at 0x{0:X6}.", wbctOffset);
            }

            mReader.Step(4);             // unused

            var sceneCount = mReader.ReadS32();

            if (sceneCount != waveGroupCount)
            {
                mareep.WriteError("WSYS: WINF count ({0}) does not match WBCT count ({1}).", waveGroupCount, sceneCount);
            }

            var sceneOffsets = mReader.ReadS32s(sceneCount);

            for (var i = 0; i < waveGroupCount; ++i)
            {
                mReader.Goto(waveGroupOffsets[i]);

                var archiveName   = mReader.ReadString <aCSTR>(112);
                var waveInfoCount = mReader.ReadS32();

                if (waveInfoCount < 0)
                {
                    mareep.WriteError("WSYS: bad wave count '{0}' in wave group #{1}.", waveInfoCount, i);
                }

                var waveInfoOffsets = mReader.ReadS32s(waveInfoCount);

                mReader.Goto(sceneOffsets[i]);

                if (mReader.Read32() != SCNE)
                {
                    mareep.WriteError("WSYS: could not find SCNE at 0x{0:X6}.", sceneOffsets[i]);
                }

                mReader.Step(8);                 // unused
                var cdfOffset = mReader.ReadS32();
                mReader.Goto(cdfOffset);

                if (mReader.Read32() != C_DF)
                {
                    mareep.WriteError("WSYS: could not find C-DF at 0x{0:X6}.", cdfOffset);
                }

                var waveidCount = mReader.ReadS32();

                if (waveidCount != waveInfoCount)
                {
                    mareep.WriteError("WSYS: C-DF count ({0}) does not match wave-info count ({1}).", waveidCount, waveInfoCount);
                }

                var waveidOffsets = mReader.ReadS32s(waveidCount);

                var waveGroup = new WaveGroup();
                waveGroup.ArchiveFileName = archiveName;

                for (var j = 0; j < waveInfoCount; ++j)
                {
                    var wave = new Wave();

                    mReader.Goto(waveidOffsets[j]);

                    var waveid = (mReader.ReadS32() & 0xFFFF);
                    wave.WaveId = waveid;

                    mReader.Goto(waveInfoOffsets[j]);
                    mReader.Step(1);                     // unknown

                    var format = (WaveFormat)mReader.Read8();

                    if (!format.IsDefined())
                    {
                        mareep.WriteError("WSYS: group #{0}: wave #{1}: bad format '{2}'.", i, j, (byte)format);
                    }
                    else
                    {
                        wave.Format = format;
                    }

                    var key = mReader.Read8();

                    if (key < 0 || key > 127)
                    {
                        mareep.WriteError("WSYS: group #{0}: wave #{1}: bad root key '{2}'.", i, j, key);
                    }
                    else
                    {
                        wave.RootKey = key;
                    }

                    mReader.Step(1);                     // alignment

                    var sampleRate = mReader.ReadF32();

                    if (sampleRate < 0.0f)
                    {
                        mareep.WriteError("WSYS: group #{0}: wave #{1}: bad sample rate '{2:F1}'.", i, j, sampleRate);
                    }
                    else
                    {
                        wave.SampleRate = sampleRate;
                    }

                    var waveStart = mReader.ReadS32();

                    if (waveStart < 0)
                    {
                        mareep.WriteError("WSYS: group #{0}: wave #{1}: bad wave start '{2}'.", i, j, waveStart);
                    }
                    else
                    {
                        wave.WaveStart = waveStart;
                    }

                    var waveSize = mReader.ReadS32();

                    if (waveSize < 0)
                    {
                        mareep.WriteError("WSYS: group #{0}: wave #{1}: bad wave size '{1}'.", i, j, waveSize);
                    }
                    else
                    {
                        wave.WaveSize = waveSize;
                    }

                    wave.Loop = (mReader.Read32() != 0);

                    var loopStart = mReader.ReadS32();

                    if (loopStart < 0)
                    {
                        mareep.WriteError("WSYS: group #{0}: wave #{1}: bad loop start '{2}'.", i, j, loopStart);
                    }
                    else
                    {
                        wave.LoopStart = loopStart;
                    }

                    var loopEnd = mReader.ReadS32();

                    if (loopEnd < 0)
                    {
                        mareep.WriteError("WSYS: group #{0}: wave #{1}: bad loop end '{2}'.", i, j, loopEnd);
                    }
                    else
                    {
                        wave.LoopEnd = loopEnd;
                    }

                    var sampleCount = mReader.ReadS32();
                    wave.SampleCount = mareep.CalculateSampleCount(format, waveSize);

                    if (loopStart > loopEnd)
                    {
                        mareep.WriteWarning("WSYS: group #{0}: wave #{1}: loop start '{2}' is greater than loop end '{3}'.\n", i, j, loopStart, loopEnd);
                    }

                    if (loopStart > wave.SampleCount)
                    {
                        mareep.WriteWarning("WSYS: group #{0}: wave #{1}: loop start '{2}' is greater than sample count '{3}'.\n", i, j, loopStart, wave.SampleCount);
                    }

                    if (loopEnd > wave.SampleCount)
                    {
                        mareep.WriteWarning("WSYS: group #{0}: wave #{1}: loop end '{2}' is greater than sample count '{3}'.\n", i, j, loopEnd, wave.SampleCount);
                    }

                    wave.HistoryLast   = mReader.ReadS16();
                    wave.HistoryPenult = mReader.ReadS16();

                    // rest of the fields are unknown or runtime

                    waveGroup.Add(wave);
                }

                waveBank.Add(waveGroup);
            }

            mReader.PopAnchor();
            mReader.Back();

            return(waveBank);
        }
예제 #9
0
        protected override void CalculateHistoryAdpcm2(int sample, out int last, out int penult)
        {
            last   = 0;
            penult = 0;

            var frame = (sample / 16);

            if (frame == 0)
            {
                return;
            }

            switch (mFormat)
            {
            case WaveFormat.Pcm8: {
                var adpcm2 = new byte[5];
                var pcm16 = new short[16];
                int _last = 0, _penult = 0;

                mReader.Goto(0);

                for (var i = 0; i < frame; ++i)
                {
                    for (var j = 0; j < 16; ++j)
                    {
                        pcm16[j] = 0;

                        if ((i * 16 + j) < mSampleCount)
                        {
                            Waveform.Pcm8toPcm16(mReader.ReadS8(), out pcm16[j]);
                        }
                    }

                    Waveform.Pcm16toAdpcm2(pcm16, adpcm2, ref _last, ref _penult);
                    Waveform.Adpcm2toPcm16(adpcm2, pcm16, ref last, ref penult);
                }

                break;
            }

            case WaveFormat.Pcm16: {
                var adpcm2 = new byte[5];
                var pcm16 = new short[16];
                int _last = 0, _penult = 0;

                mReader.Goto(0);

                for (var i = 0; i < frame; ++i)
                {
                    for (var j = 0; j < 16; ++j)
                    {
                        pcm16[j] = 0;

                        if ((i * 16 + j) < mSampleCount)
                        {
                            pcm16[j] = mReader.ReadS16();
                        }
                    }

                    Waveform.Pcm16toAdpcm2(pcm16, adpcm2, ref _last, ref _penult);
                    Waveform.Adpcm2toPcm16(adpcm2, pcm16, ref last, ref penult);
                }

                break;
            }

            case WaveFormat.Adpcm2: {
                var pcm16 = new short[16];

                mReader.Goto(0);

                for (var i = 0; i < frame; ++i)
                {
                    Waveform.Adpcm2toPcm16(mReader.Read8s(5), pcm16, ref last, ref penult);
                }

                break;
            }

            case WaveFormat.Adpcm4: {
                var adpcm2 = new byte[5];
                var pcm16 = new short[16];
                int last1 = 0, penult1 = 0;
                int last2 = 0, penult2 = 0;

                mReader.Goto(0);

                for (var i = 0; i < frame; ++i)
                {
                    Waveform.Adpcm4toPcm16(mReader.Read8s(9), pcm16, ref last1, ref penult1);
                    Waveform.Pcm16toAdpcm2(pcm16, adpcm2, ref last2, ref penult2);
                    Waveform.Adpcm2toPcm16(adpcm2, pcm16, ref last, ref penult);
                }

                break;
            }
            }
        }
예제 #10
0
        protected virtual void loadBlo1(aBinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            int numparams = reader.Read8();

            mVisible = (reader.Read8() != 0);
            reader.Step(2);

            mName = reader.Read32();

            int left   = reader.ReadS16();
            int top    = reader.ReadS16();
            int width  = reader.ReadS16();
            int height = reader.ReadS16();

            mRect.set(left, top, (left + width), (top + height));

            numparams -= 6;

            if (numparams > 0)
            {
                mAngle = reader.Read16();
                --numparams;
            }
            else
            {
                mAngle = 0.0d;
            }

            if (numparams > 0)
            {
                mAnchor = (bloAnchor)reader.Read8();
                --numparams;
            }
            else
            {
                mAnchor = bloAnchor.TopLeft;
            }

            if (numparams > 0)
            {
                mAlpha = reader.Read8();
                --numparams;
            }
            else
            {
                mAlpha = 255;
            }

            if (numparams > 0)
            {
                mInheritAlpha = (reader.Read8() != 0);
                --numparams;
            }
            else
            {
                mInheritAlpha = true;
            }

            reader.Skip(4);
        }
예제 #11
0
        void DoReplaceSeq()
        {
            if (mAafInPath == null)
            {
                mareep.WriteError("CHARGE: missing -init-data-file parameter");
            }

            if (mArcInPath == null)
            {
                mareep.WriteError("CHARGE: missing -seq-data-file parameter");
            }

            byte[] arc_data = ReadFileData(mArcInPath);

            if (mInput == null)
            {
                mareep.WriteError("CHARGE: missing -input parameter");
            }

            byte[] seq_data = ReadFileData(mInput);

            if (mTarget == null)
            {
                mareep.WriteError("CHARGE: missing -target parameter");
            }

            byte[] barc_data = null;

            using (Stream input = mareep.OpenFile(mAafInPath)) {
                mareep.WriteMessage("Scanning AAF header...\n");
                aBinaryReader reader = new aBinaryReader(input, Endianness.Big);
                int           offset, size;

                if (!ReadAafHeader(reader, 4, 0, out offset, out size))
                {
                    mareep.WriteError("CHARGE: failed to find sequence info block");
                }

                reader.Goto(offset);

                if (reader.ReadS32() != 0x42415243)                   // 'BARC'
                {
                    mareep.WriteError("CHARGE: could not find 'BARC' header");
                }

                reader.Goto(offset + 12);
                int count = reader.ReadS32();
                barc_data = new byte[32 + 32 * count];
                reader.Goto(offset + 32);
                int index, old_offset, old_size;

                mareep.WriteMessage("Found sequence info data (0x{0:X6}, 0x{1:X6}), {2} sequence(s)\n", offset, size, count);
                mareep.WriteMessage("Scanning sequence list...\n");

                if (!ReadBarcHeader(reader, mTarget, count, out index, out old_offset, out old_size))
                {
                    mareep.WriteError("CHARGE: could not find sequence {0}", mTarget);
                }

                mareep.WriteMessage("Found sequence {0} (0x{1:X6}, 0x{2:X6})\n", index, offset, size);

                int new_offset, new_size = ((seq_data.Length + 31) & ~31);
                int difference = (new_size - old_size);
                reader.Goto(offset + 16);

                using (Stream arc_stream = mareep.CreateFile(mArcOutPath))
                    using (MemoryStream barc_stream = new MemoryStream(barc_data, true)) {
                        mareep.WriteMessage("Writing new sequence data...\n");
                        aBinaryWriter arc_writer  = new aBinaryWriter(arc_stream);
                        aBinaryWriter barc_writer = new aBinaryWriter(barc_stream, Endianness.Big);
                        barc_writer.WriteS32(0x42415243);                 // 'BARC'
                        barc_writer.WriteS32(0x2D2D2D2D);                 // '----'
                        barc_writer.WriteS32(0);
                        barc_writer.WriteS32(count);
                        barc_writer.Write8s(reader.Read8s(16));

                        for (int i = 0; i < count; ++i)
                        {
                            barc_writer.Write8s(reader.Read8s(14));
                            barc_writer.WriteS16(reader.ReadS16());
                            barc_writer.WriteS32(reader.ReadS32());
                            barc_writer.WriteS32(reader.ReadS32());
                            offset     = reader.ReadS32();
                            size       = reader.ReadS32();
                            new_offset = offset;

                            if (offset > old_offset)
                            {
                                new_offset += difference;
                            }

                            arc_writer.Goto(new_offset);

                            if (i == index)
                            {
                                arc_writer.Write8s(seq_data);
                                arc_writer.WritePadding(32, 0);
                                size = new_size;
                            }
                            else
                            {
                                arc_writer.Write8s(arc_data, offset, size);
                            }

                            barc_writer.WriteS32(new_offset);
                            barc_writer.WriteS32(size);
                        }
                    }

                reader.Goto(0);

                using (Stream output = mareep.CreateFile(mAafOutPath)) {
                    mareep.WriteMessage("Writing new AAF file...\n");
                    aBinaryWriter writer = new aBinaryWriter(output, Endianness.Big);

                    if (!WriteAafHeader(reader, writer, 4, 0, barc_data))
                    {
                        mareep.WriteError("CHARGE: failed to write aaf file");
                    }
                }
            }
        }