public FileInfo(Reader reader) { byte ss = reader.ReadByte(); char buf = ','; string DecryptedString = ""; for (int i = 0; i < ss; i++) { byte b = reader.ReadByte(); int bufInt = b; bufInt ^= 0xFF; buf = (char)bufInt; DecryptedString = DecryptedString + buf; } FileName = DecryptedString; Console.WriteLine(FileName); fileSize = reader.ReadUInt32(); byte[] tmp = reader.ReadBytes(fileSize); int[] outbuf = new int[fileSize]; for (int i = 0; i < (int)fileSize; i++) { outbuf[i] = tmp[i]; } decryptKeyZ = ((int)fileSize & 0x1fc) >> 2; decryptKeyIndex2 = (decryptKeyZ % 9) + 1; decryptKeyIndex1 = (decryptKeyZ % decryptKeyIndex2) + 1; decryptKeyIndexZ = 0; for (int i = 0; i < (int)fileSize; i++) { outbuf[i] ^= decryptKey2[decryptKeyIndex2++] ^ decryptKeyZ; if (decryptKeyIndexZ == 1) // swap nibbles { outbuf[i] = (outbuf[i] >> 4) | ((outbuf[i] & 0xf) << 4); } outbuf[i] ^= decryptKey1[decryptKeyIndex1++]; if ((decryptKeyIndex1 <= 19) || (decryptKeyIndex2 <= 11)) { if (decryptKeyIndex1 > 19) { decryptKeyIndex1 = 1; decryptKeyIndexZ ^= 1; } if (decryptKeyIndex2 > 11) { decryptKeyIndex2 = 1; decryptKeyIndexZ ^= 1; } } else { decryptKeyZ++; decryptKeyZ &= 0x7F; if (decryptKeyIndexZ != 0) { decryptKeyIndex1 = (decryptKeyZ % 12) + 6; decryptKeyIndex2 = (decryptKeyZ % 5) + 4; decryptKeyIndexZ = 0; } else { decryptKeyIndexZ = 1; decryptKeyIndex1 = (decryptKeyZ % 15) + 3; decryptKeyIndex2 = (decryptKeyZ % 7) + 1; } } } Filedata = new byte[outbuf.Length]; for (int i = 0; i < outbuf.Length; i++) { Filedata[i] = (byte)outbuf[i]; } }
void LoadVideoFrame(Reader reader) { Frames.Add(new VideoFrame(reader, Width, Height)); }
public GlobalVariable(Reader reader) { Name = reader.ReadString(); Console.WriteLine(Name); Value = reader.ReadInt32(); }
public void ReadGIFData(Reader reader) { int eighthHeight = Height >> 3; int quarterHeight = Height >> 2; int halfHeight = Height >> 1; int bitsWidth = 0; int width = 0; Entry[] codeTable = new Entry[0x10000]; ImageData = new byte[Width * Height + 1]; for (int i = 0; i < 0x10000; i++) { codeTable[i] = new Entry(); } // Get frame byte type, subtype, temp; type = reader.ReadByte(); while (type != 0) { bool tableFull, interlaced; int codeSize, initCodeSize; int clearCode, eoiCode, emptyCode; int codeToAddFrom, mark, str_len = 0, frm_off = 0; uint currentCode; switch (type) { // Extension case 0x21: subtype = reader.ReadByte(); switch (subtype) { // Graphics Control Extension case 0xF9: reader.ReadBytes(0x06); // temp = reader.ReadByte(); // Block Size [byte] (always 0x04) // temp = reader.ReadByte(); // Packed Field [byte] // // temp16 = reader.ReadUInt16(); // Delay Time [short] // // temp = reader.ReadByte(); // Transparent Color Index? [byte] // // temp = reader.ReadByte(); // Block Terminator [byte] // break; // Plain Text Extension case 0x01: // Comment Extension case 0xFE: // Application Extension case 0xFF: temp = reader.ReadByte(); // Block Size // Continue until we run out of blocks while (temp != 0) { // Read block reader.ReadBytes(temp); temp = reader.ReadByte(); // next block Size } break; default: Console.WriteLine("GIF LOAD FAILED"); return; } break; // Image descriptor case 0x2C: // temp16 = reader.ReadUInt16(); // Destination X // temp16 = reader.ReadUInt16(); // Destination Y // temp16 = reader.ReadUInt16(); // Destination Width // temp16 = reader.ReadUInt16(); // Destination Height reader.ReadBytes(8); temp = reader.ReadByte(); // Packed Field [byte] // If a local color table exists, if ((temp & 0x80) != 0) { int size = 2 << (temp & 0x07); // Load all colors for (int i = 0; i < size; i++) { byte r = reader.ReadByte(); byte g = reader.ReadByte(); byte b = reader.ReadByte(); FramePalette.Add(Color.FromArgb(r, g, b)); } } interlaced = (temp & 0x40) == 0x40; if (interlaced) { bitsWidth = 0; while (width != 0) { width >>= 1; bitsWidth++; } width = Width - 1; } codeSize = reader.ReadByte(); clearCode = 1 << codeSize; eoiCode = clearCode + 1; emptyCode = eoiCode + 1; codeSize++; initCodeSize = codeSize; // Init table for (int i = 0; i <= eoiCode; i++) { codeTable[i].Length = 1; codeTable[i].Prefix = 0xFFF; codeTable[i].Suffix = (byte)i; } blockLength = 0; bitCache = 0b00000000; bitCacheLength = 0; tableFull = false; currentCode = ReadCode(reader, codeSize); codeSize = initCodeSize; emptyCode = eoiCode + 1; tableFull = false; Entry entry = new Entry(); entry.Suffix = 0; while (blockLength != 0) { codeToAddFrom = -1; mark = 0; if (currentCode == clearCode) { codeSize = initCodeSize; emptyCode = eoiCode + 1; tableFull = false; } else if (!tableFull) { codeTable[emptyCode].Length = (ushort)(str_len + 1); codeTable[emptyCode].Prefix = (ushort)currentCode; codeTable[emptyCode].Suffix = entry.Suffix; emptyCode++; // Once we reach highest code, increase code size if ((emptyCode & (emptyCode - 1)) == 0) { mark = 1; } else { mark = 0; } if (emptyCode >= 0x1000) { mark = 0; tableFull = true; } } currentCode = ReadCode(reader, codeSize); if (currentCode == clearCode) { continue; } if (currentCode == eoiCode) { return; } if (mark == 1) { codeSize++; } entry = codeTable[currentCode]; str_len = entry.Length; while (true) { int p = frm_off + entry.Length - 1; if (interlaced) { int row = p >> bitsWidth; if (row < eighthHeight) { p = (p & width) + ((((row) << 3) + 0) << bitsWidth); } else if (row < quarterHeight) { p = (p & width) + ((((row - eighthHeight) << 3) + 4) << bitsWidth); } else if (row < halfHeight) { p = (p & width) + ((((row - quarterHeight) << 2) + 2) << bitsWidth); } else { p = (p & width) + ((((row - halfHeight) << 1) + 1) << bitsWidth); } } ImageData[p] = entry.Suffix; if (entry.Prefix != 0xFFF) { entry = codeTable[entry.Prefix]; } else { break; } } frm_off += str_len; if (currentCode < emptyCode - 1 && !tableFull) { codeTable[emptyCode - 1].Suffix = entry.Suffix; } } break; } type = reader.ReadByte(); if (type == 0x3B) { break; } } }
public GraphicsImage(Reader reader, bool dcGFX = false) { if (dcGFX) { reader.ReadByte(); } width = (ushort)(reader.ReadByte() << 8); width |= reader.ReadByte(); height = (ushort)(reader.ReadByte() << 8); height |= reader.ReadByte(); // Create image gfxImage = new Bitmap(width, height, PixelFormat.Format8bppIndexed); ColorPalette cp = gfxImage.Palette; // Read & Process palette for (int i = 0; i < 255; i++) { GFXpal[i].R = reader.ReadByte(); GFXpal[i].G = reader.ReadByte(); GFXpal[i].B = reader.ReadByte(); cp.Entries[i] = Color.FromArgb(255, GFXpal[i].R, GFXpal[i].G, GFXpal[i].B); } gfxImage.Palette = cp; //Read Image Data byte[] buf = new byte[3]; bool finished = false; int cnt = 0; int loop = 0; data = new byte[(width * height) + 1]; while (!finished) { buf[0] = reader.ReadByte(); if (buf[0] == 255) { buf[1] = reader.ReadByte(); if (buf[1] == 255) { finished = true; break; } else { buf[2] = reader.ReadByte(); loop = 0; // Repeat value needs to decreased by one to decode // the graphics from the Dreamcast demo if (dcGFX) { buf[2]--; } while (loop < buf[2] && !reader.IsEof) { data[cnt++] = buf[1]; loop++; } } } else { data[cnt++] = buf[0]; } } //Console.Write("file Length = " + reader.BaseStream.Length + " file pos = " + reader.Pos + " data remaining = " + (reader.BaseStream.Length - reader.Pos)); // Write data to image int pixel = 0; for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { BitmapData ImgData = gfxImage.LockBits(new Rectangle(new Point(w, h), new Size(1, 1)), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); byte b = System.Runtime.InteropServices.Marshal.ReadByte(ImgData.Scan0); System.Runtime.InteropServices.Marshal.WriteByte(ImgData.Scan0, (data[pixel])); gfxImage.UnlockBits(ImgData); pixel++; } } reader.Close(); }