void WriteSdta() { mWriter.WriteString("LIST"); mWriter.WriteS32(CalculateSmplSize() + 12); mWriter.WriteString("sdta"); mWriter.WriteString("smpl"); mWriter.WriteS32(CalculateSmplSize()); foreach (var waveGroup in mWaveBank) { var archiveFileName = Path.Combine(mInputDirectory, waveGroup.ArchiveFileName); using (var instream = mareep.OpenFile(archiveFileName)) { var reader = new aBinaryReader(instream, Endianness.Big); mareep.WriteSeparator('-'); mareep.WriteMessage("{0} ({1} wave(s))\n", waveGroup.ArchiveFileName, waveGroup.Count); foreach (var wave in waveGroup) { reader.Goto(wave.WaveStart); var data = reader.Read8s(wave.WaveSize); var mixer = new RawWaveMixer(new MemoryStream(data), wave.Format); mixer.Write(WaveFormat.Pcm16, mWriter); for (var i = 0; i < 92; i++) { mWriter.WriteS8(0); } } } } }
public T find <T>(aBinaryReader reader, string directory) where T : bloResource, new() { bloResourceType type; return(find <T>(reader, directory, out type)); }
public Lump(aBinaryReader reader) : this() { Start = reader.ReadS32(); Length = reader.ReadS32(); Name = reader.ReadString<aCSTR>(8); }
protected override void loadCompact(aBinaryReader reader) { base.loadCompact(reader); var finder = bloResourceFinder.getFinder(); mTextureCount = 1; mTextures[0] = finder.find <bloTexture>(reader, "timg"); mPalette = finder.find <bloPalette>(reader, "tlut"); mBinding = (bloBinding)reader.Read8(); int bits = reader.Read8(); mMirror = (bloMirror)((bits >> 0) & 3); mRotate90 = ((bits & 4) != 0); mWrapS = (bloWrapMode)((bits >> 3) & 3); mWrapT = mWrapS; reader.Skip(4); for (int i = 0; i < 4; ++i) { mColors[i] = new bloColor(bloColor.cWhite); } setBlendKonstColor(); setBlendKonstAlpha(); }
public static object loadImageData(aBinaryReader reader, int width, int height, gxTextureFormat format) { switch (format) { case gxTextureFormat.I4: return(loadI4(reader, width, height)); case gxTextureFormat.I8: return(loadI8(reader, width, height)); case gxTextureFormat.IA4: return(loadIA4(reader, width, height)); case gxTextureFormat.IA8: return(loadIA8(reader, width, height)); case gxTextureFormat.RGB565: return(loadRGB565(reader, width, height)); case gxTextureFormat.RGB5A3: return(loadRGB5A3(reader, width, height)); case gxTextureFormat.RGBA8: return(loadRGBA8(reader, width, height)); case gxTextureFormat.CI4: return(loadCI4(reader, width, height)); case gxTextureFormat.CI8: return(loadCI8(reader, width, height)); case gxTextureFormat.CI14X2: return(loadCI14X2(reader, width, height)); case gxTextureFormat.CMPR: return(loadCMPR(reader, width, height)); default: { throw new NotImplementedException(String.Format("Encountered an unimplemented texture format {0}.", format)); } } }
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); }
static short[] loadCI4(aBinaryReader reader, int width, int height) { var data = new short[width * height]; const int cBlockWidth = 8, cBlockHeight = 8; for (var y = 0; y < height; y += cBlockHeight) { for (var x = 0; x < width; x += cBlockWidth) { for (var by = 0; by < cBlockHeight; ++by) { for (var bx = 0; bx < cBlockWidth; bx += 2) { var ci4 = reader.Read8(); var index = (width * (y + by) + (x + bx)); if ((by + y) >= height) { continue; } if ((bx + x) < width) { data[index] = (short)((ci4 >> 4) & 0xF); } if ((bx + x + 1) < width) { data[index + 1] = (short)((ci4 >> 0) & 0xF); } } } } } return(data); }
static aRGBA[] loadI4(aBinaryReader reader, int width, int height) { var data = new aRGBA[width * height]; const int cBlockWidth = 8, cBlockHeight = 8; for (var y = 0; y < height; y += cBlockHeight) { for (var x = 0; x < width; x += cBlockWidth) { for (var by = 0; by < cBlockHeight; ++by) { for (var bx = 0; bx < cBlockWidth; bx += 2) { var i4 = reader.Read8(); var index = (width * (y + by) + (x + bx)); if ((by + y) >= height) { continue; } if ((bx + x) < width) { data[index] = new aRGBA(sNybbleToByte[(i4 >> 4) & 0xF]); } if ((bx + x + 1) < width) { data[index + 1] = new aRGBA(sNybbleToByte[i4 & 0xF]); } } } } } return(data); }
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); }
public Lump(aBinaryReader reader) : this() { Start = reader.ReadS32(); Length = reader.ReadS32(); Name = reader.ReadString <aCSTR>(8); }
static short[] loadCI14X2(aBinaryReader reader, int width, int height) { var data = new short[width * height]; const int cBlockWidth = 4, cBlockHeight = 4; for (var y = 0; y < height; y += cBlockHeight) { for (var x = 0; x < width; x += cBlockWidth) { for (var by = 0; by < cBlockHeight; ++by) { for (var bx = 0; bx < cBlockWidth; ++bx) { var ci14x2 = reader.Read16(); if ((bx + x) >= width || (by + y) >= height) { continue; } data[width * (y + by) + (x + bx)] = (short)(ci14x2 & 0x3FFF); } } } } return(data); }
void countBlock(aBinaryReader reader) { reader.Goto(0x20u); for (var i = 0u; i < mFontHeader.blockCount; ++i) { var blockStart = reader.Position; var typeID = reader.Read32(); var size = reader.Read32(); switch (typeID) { case cINF1: break; case cWID1: ++mWidthCount; break; case cMAP1: ++mMapCount; break; case cGLY1: ++mGlyphCount; break; default: { Debug.Fail("Unknown data block."); break; } } reader.Goto(blockStart + size); } }
static void DecodeStreamAdpcm(aBinaryReader reader, aBinaryWriter writer, int sampleCount) { var left = new short[16]; int left_last = 0, left_penult = 0; var right = new short[16]; int right_last = 0, right_penult = 0; for (var i = 0; i < sampleCount; i += 16) { Waveform.Adpcm4toPcm16(reader.Read8s(9), left, ref left_last, ref left_penult); Waveform.Adpcm4toPcm16(reader.Read8s(9), right, ref right_last, ref right_penult); for (var j = 0; j < 16 && (i + j) < sampleCount; ++j) { writer.WriteS16(left[j]); writer.WriteS16(right[j]); } if ((i % cMessageInterval) == 0 || (i + 16) >= sampleCount) { mareep.WriteMessage("\rSamples encoded: {0}/{1}", System.Math.Min((i + 16), sampleCount), sampleCount); } } }
public FontBlock(aBinaryReader reader) { typeID = reader.Read32(); version = reader.Read32(); size = reader.Read32(); blockCount = reader.Read32(); }
static aRGBA[] loadCMPR(aBinaryReader reader, int width, int height) { var data = new aRGBA[width * height]; const int cTileWidth = 8, cTileHeight = 8; const int cBlockWidth = 4, cBlockHeight = 4; for (var y = 0; y < height; y += cTileHeight) // tile { for (var x = 0; x < width; x += cTileWidth) { for (var by = 0; by < cTileHeight; by += cBlockHeight) // block { for (var bx = 0; bx < cTileWidth; bx += cBlockWidth) { var colors = aRGBA.FromST3C1(reader.Read64()); for (var ty = 0; ty < cBlockHeight && y + by + ty < height; ty++) // texel { for (var tx = 0; tx < cBlockWidth && x + bx + tx < width; tx++) { data[width * (y + by + ty) + (x + bx + tx)] = colors[(ty * cBlockWidth) + tx]; } } } } } } return(data); }
static aRGBA[] loadIA4(aBinaryReader reader, int width, int height) { var data = new aRGBA[width * height]; const int cBlockWidth = 8, cBlockHeight = 4; for (var y = 0; y < height; y += cBlockHeight) { for (var x = 0; x < width; x += cBlockWidth) { for (var by = 0; by < cBlockHeight; ++by) { for (var bx = 0; bx < cBlockWidth; ++bx) { var ia4 = reader.Read8(); if ((bx + x) >= width || (by + y) >= height) { continue; } data[width * (y + by) + (x + bx)] = new aRGBA(sNybbleToByte[ia4 & 0xF], sNybbleToByte[(ia4 >> 4) & 0xF]); } } } } return(data); }
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); } }
static aRGBA[] loadIA8(aBinaryReader reader, int width, int height) { var data = new aRGBA[width * height]; const int cBlockWidth = 4, cBlockHeight = 4; for (var y = 0; y < height; y += cBlockHeight) { for (var x = 0; x < width; x += cBlockWidth) { for (var by = 0; by < cBlockHeight; ++by) { for (var bx = 0; bx < cBlockWidth; ++bx) { var intensity = reader.Read8(); var alpha = reader.Read8(); if ((bx + x) >= width || (by + y) >= height) { continue; } data[width * (y + by) + (x + bx)] = new aRGBA(intensity, alpha); } } } } return(data); }
static aRGBA[] loadRGB5A3(aBinaryReader reader, int width, int height) { var data = new aRGBA[width * height]; const int cBlockWidth = 4, cBlockHeight = 4; for (var y = 0; y < height; y += cBlockHeight) { for (var x = 0; x < width; x += cBlockWidth) { for (var by = 0; by < cBlockHeight; ++by) { for (var bx = 0; bx < cBlockWidth; ++bx) { var color = reader.Read16(); if ((bx + x) >= width || (by + y) >= height) { continue; } data[(width * (y + by)) + (x + bx)] = ( (color & 0x8000) != 0 ? aRGBA.FromRGB5(color) : aRGBA.FromRGB4A3(color) ); } } } } return(data); }
public bloPalette(gxTlutFormat format, int transparency, int entrycount, aBinaryReader reader) { mFormat = format; mTransparency = transparency; mEntryCount = entrycount; mData = new aRGBA[mEntryCount]; loadPaletteData(reader); }
void loadPaletteDataRGB565(aBinaryReader reader) { for (int i = 0; i < mEntryCount; ++i) { var rgb565 = reader.Read16(); mData[i] = aRGBA.FromRGB565(rgb565); } }
void loadPaletteDataIA8(aBinaryReader reader) { for (int i = 0; i < mEntryCount; ++i) { var i8 = reader.Read8(); var a8 = reader.Read8(); mData[i] = new aRGBA(i8, a8); } }
public InfoBlock(aBinaryReader reader) { fontType = (bloFontType)reader.Read16(); ascent = reader.Read16(); descent = reader.Read16(); width = reader.Read16(); leading = reader.Read16(); invalChar = reader.Read16(); }
public Symbol(aBinaryReader reader) { mType = (SymbolType)reader.Read32(); mStringOffset = reader.Read32(); mData = reader.Read32(); // skip the last two fields reader.Read32(); reader.Read32(); }
public override string Read(aBinaryReader reader) { var value = base.Read(reader); #if DEBUG aError.Check<Exception>(reader.ReadChar() == '\0', "BZSTR is not null-terminated."); #else reader.Step(1); #endif return value; }
public override void load(Stream stream) { var reader = new aBinaryReader(stream, Endianness.Big); reader.PushAnchor(); mFormat = (gxTlutFormat)reader.Read8(); mTransparency = reader.Read8(); mEntryCount = reader.Read16(); reader.Goto(0x20); loadPaletteData(reader); }
public static bloScreen loadCompact(Stream stream) { aBinaryReader reader = new aBinaryReader(stream, Endianness.Big, Encoding.GetEncoding(1252)); bloScreen scrn = new bloScreen(); if (!loadCompact(scrn, reader)) { return(null); } return(scrn); }
void loadPaletteDataRGB5A3(aBinaryReader reader) { for (int i = 0; i < mEntryCount; ++i) { var rgb5a3 = reader.Read16(); mData[i] = ( (rgb5a3 & 0x8000) != 0 ? aRGBA.FromRGB5(rgb5a3) : aRGBA.FromRGB4A3(rgb5a3) ); } }
protected override WaveBank DoTransform(WaveBank obj) { if (obj == null) { return(null); } if (!Directory.Exists(mWaveDirectory)) { mareep.WriteMessage("Creating directory '{0}'...\n", mWaveDirectory); Directory.CreateDirectory(mWaveDirectory); } mareep.WriteMessage("Transferring waves...\n"); var extension = (mExtractWav ? "wav" : "raw"); foreach (var waveGroup in obj) { var archiveFileName = Path.Combine(mBankDirectory, waveGroup.ArchiveFileName); var archiveNoExtension = Path.GetFileNameWithoutExtension(waveGroup.ArchiveFileName); using (var input = mareep.OpenFile(archiveFileName)) { var reader = new aBinaryReader(input, Endianness.Big); mareep.WriteSeparator('-'); mareep.WriteMessage("{0} ({1} wave(s))\n", waveGroup.ArchiveFileName, waveGroup.Count); foreach (var wave in waveGroup) { wave.FileName = String.Format("{0}_{1:D5}.{2}.{3}", archiveNoExtension, wave.WaveId, wave.Format.ToLowerString(), extension); string waveFileName = Path.Combine(mWaveDirectory, wave.FileName); using (var output = mareep.CreateFile(waveFileName)) { reader.Goto(wave.WaveStart); var data = reader.Read8s(wave.WaveSize); if (mExtractWav) { ExtractWav(wave, data, output); } else { ExtractRaw(wave, data, output); } } mareep.WriteMessage(" #{0:X4} {1} {2} {3}Hz {4} samples\n", wave.WaveId, mareep.ConvertKey(wave.RootKey), wave.Format.ToLowerString(), (int)wave.SampleRate, wave.SampleCount); } } } return(obj); }
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); } } }
public T find <T>(aBinaryReader reader, string directory, out bloResourceType type) where T : bloResource, new() { type = (bloResourceType)reader.Read8(); int length = reader.Read8(); string name = reader.ReadString(length); T resource = find <T>(type, name, directory); if (resource == null && type != bloResourceType.None) { Console.WriteLine(">>> FAILED: could not find {0} resource '{1}'", type, name); } return(resource); }
void setBlock(aBinaryReader reader) { int widthBlocks = 0; int glyphBlocks = 0; int mapBlocks = 0; reader.Goto(0x20u); for (uint i = 0; i < mFontHeader.blockCount; ++i) { var blockStart = reader.Position; var typeID = reader.Read32(); var size = reader.Read32(); switch (typeID) { case cINF1: { mInfoBlock = new InfoBlock(reader); mDecoderMethod = sAboutEncoding[(int)mInfoBlock.fontType]; break; } case cWID1: { mWidthBlocks[widthBlocks++] = new WidthBlock(reader); break; } case cGLY1: { mGlyphBlocks[glyphBlocks++] = new GlyphBlock(reader); break; } case cMAP1: { mMapBlocks[mapBlocks] = new MapBlock(reader); int firstChar = mMapBlocks[mapBlocks].firstChar; if (mFirstChar > firstChar) { mFirstChar = firstChar; } ++mapBlocks; break; } default: { Debug.Fail("Unknown data block."); break; } } reader.Goto(blockStart + size); } }
public override string Read(aBinaryReader reader) { var sb = new StringBuilder(256); char c; while ((c = reader.ReadChar()) != '\x00') { sb.Append(c); } return sb.ToString(); }
static void Main(string[] arguments) { Message("doomwadcorrupter v{0} arookas", new Version(0, 1, 12)); Separator(); if (arguments == null || arguments.Length < 2) { Message("Usage: doomwadcorrupter <input.wad> <output.wad> [options]"); Message(); Message("Options:"); Message(" -start <value>"); Message(" -end <value>"); Message(" -inc <value>"); Message(" -mode <type> [<value>]"); Message(" -skip <filter> [<filter> [...]]"); Message(" -only <filter> [<filter> [...]]"); Message(" -zdoom"); Message(); Message("For more detailed instructions, refer to the official repo page."); Pause(); Exit(false); } var inputWAD = arguments[0]; var outputWAD = arguments[1]; cmd = new aCommandLine(arguments.Skip(2).ToArray()); options = new CorrupterOptions(cmd); DisplayOptions(inputWAD, outputWAD); int lumpCount; var lumpsCorrupted = 0; var lumpsSkipped = 0; var bytesCorrupted = 0; rnd = new Random((uint)options.CorruptSeed); var timeTaken = Stopwatch.StartNew(); using (var instream = OpenWAD(inputWAD)) { var reader = new aBinaryReader(instream, Endianness.Little, Encoding.ASCII); // header var wadType = reader.ReadString(4); if (wadType != "IWAD" && wadType != "PWAD") { Error("Input file is not a DOOM WAD."); } lumpCount = reader.ReadS32(); var directoryOffset = reader.ReadS32(); // directory reader.Goto(directoryOffset); var lumps = aCollection.Initialize(lumpCount, () => new Lump(reader)); using (var outstream = CreateWAD(outputWAD)) { var writer = new aBinaryWriter(outstream, Endianness.Little, Encoding.ASCII); // header writer.WriteString(wadType); writer.WriteS32(lumpCount); writer.WriteS32(directoryOffset); // data var corruptBuff = new byte[options.Increment]; var startBuff = new byte[options.Start]; var ns = LumpNamespace.Global; foreach (var lump in lumps) { reader.Goto(lump.Start); writer.Goto(lump.Start); CheckNamespaceMarker(lump, ref ns); if (options.Filter.IsCorruptable(lump.Name, ns) && !(options.ZDOOM && IsZDOOMLump(lump.Name))) { ++lumpsCorrupted; var i = options.Start; var end = options.End ?? lump.Length; if (i > 0) { var count = (int)System.Math.Min(lump.Length, i); reader.Read(startBuff, count); writer.Write8s(startBuff, count); } while (i < lump.Length && i < end) { Status("Corrupting '{0}'... (0x{1:X8} / 0x{2:X8})", lump.Name, i, lump.Length); var count = (int)System.Math.Min(lump.Length - i, options.Increment); reader.Read(corruptBuff, count); CorruptByte(ref corruptBuff[0], options.CorruptMode, options.CorruptValue); writer.Write8s(corruptBuff, count); ++bytesCorrupted; i += count; } } else { ++lumpsSkipped; writer.Write8s(reader.Read8s(lump.Length)); } } // directory writer.Goto(directoryOffset); foreach (var lump in lumps) { Status("Writing lump directory for '{0}'...", lump.Name); lump.ToStream(writer); } } } timeTaken.Stop(); Status("Finished corrupting."); Message(); Separator(); Message(" Files : {0}", lumpCount); Message(" Files corrupted : {0}", lumpsCorrupted); Message(" Files skipped : {0}", lumpsSkipped); Message("Bytes mercilessly sacrificed : {0}", bytesCorrupted); Message(" Time taken : {0}", timeTaken.Elapsed.ToString("g")); Message(" Finished at : {0}", DateTime.Now.ToString("HH:mm:ss tt")); Pause(); }
public abstract string Read(aBinaryReader reader);
public override string Read(aBinaryReader reader) { var length = reader.Read8(); var value = reader.ReadString(length); return value; }
public override string Read(aBinaryReader reader) { var value = reader.ReadString(mMultiple); var length = value.IndexOf('\x00'); if (length > 0) { return value.Substring(0, length); } return value; }