internal CollisionMask(Reader reader) { byte flags = reader.ReadByte(); isCeiling = (flags >> 4) != 0; Behaviour = (byte)(flags & 0xF); FloorAngle = reader.ReadByte(); RWallAngle = reader.ReadByte(); LWallAngle = reader.ReadByte(); CeilingAngle = reader.ReadByte(); byte[] collision = reader.ReadBytes(8); int ActiveCollision = reader.ReadByte() << 8; ActiveCollision |= reader.ReadByte(); int i = 0; int i2 = 1; for (int c = 0; c < 8; c++) { Collision[i] = (byte)((collision[c] & 0xF0) >> 4); Collision[i2] = (byte)(collision[c] & 0x0F); i += 2; i2 += 2; } int b = 0; for (int ii = 0; ii < 16; ii++) { HasCollision[ii] = IsBitSet(ActiveCollision, b); b++; } }
public Animation(Reader reader, bool BitFlipped = false) { Unknown = reader.ReadBytes(5); if (BitFlipped) { for (int i = 0; i < 5; i++) { Unknown[i] ^= 255; } } int spriteSheetCount = 3; //always 3 for (int i = 0; i < spriteSheetCount; ++i) { int sLen = reader.ReadByte(); if (BitFlipped) { sLen ^= 255; } byte[] byteBuf = new byte[sLen]; byteBuf = reader.ReadBytes(sLen); if (BitFlipped) { for (int ii = 0; ii < sLen; ii++) { byteBuf[ii] ^= 255; } } string result = System.Text.Encoding.UTF8.GetString(byteBuf); SpriteSheets[i] = result; } byte EndTexFlag = reader.ReadByte(); //Seems to tell the RSDK's reader when to stop reading textures??? if (BitFlipped) { EndTexFlag ^= 255; } // Read number of animations var animationCount = reader.ReadByte(); if (BitFlipped) { animationCount ^= 255; } for (int i = 0; i < animationCount; ++i) { Animations.Add(new AnimationEntry(reader, BitFlipped)); } int collisionBoxCount = reader.ReadByte(); for (int i = 0; i < collisionBoxCount; ++i) { CollisionBoxes.Add(new sprHitbox(reader, BitFlipped)); } reader.Close(); }
public void ReadGIFData(Reader reader) { //I have no idea how to load GIF data CompressedImageData = new byte[Width * Height + 1]; byte bitSize = reader.ReadByte(); ExtendedCodeTable = bitSize == 8; bool notEnd = true; int c = 0; while (notEnd) { byte BlockSize = reader.ReadByte(); //byte clearCode = reader.ReadByte(); //just read the clearcode if (BlockSize == 0) { bool Next = false; while (!Next) { byte tmp = reader.ReadByte(); if (tmp == (byte)';') { Next = true; return; } // AKA ';' } } reader.ReadBytes(BlockSize); /*if (!ExtendedCodeTable) * { * * while ((c = reader.ReadByte()) != EndCode) * { * * if (c == ClearCode) * { * //do clearcode shit * * while ((c = reader.ReadByte()) == ClearCode) * { * //skip * } * * if (c == EndCode) * { * notEnd = false; * break; * } * * } * else * { * //Process data * } * } * } * else * { * Console.WriteLine("wtf no"); * break; * //gonna haveta do special stuff for 256 colour images * }*/ } }
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 void read(Reader reader) { fileName = reader.ReadString(); fileData = reader.ReadBytes((int)reader.ReadUInt32()); }