public BCON(IFFChunk BaseChunk) : base(BaseChunk) { FileReader Reader = new FileReader(new MemoryStream(m_Data), false); byte NumConstants = Reader.ReadByte(); Reader.ReadByte(); //Unknown. for (int i = 0; i < NumConstants; i++) Constants.Add(Reader.ReadInt16()); }
public PALT(IFFChunk BaseChunk) : base(BaseChunk) { FileReader Reader = new FileReader(new MemoryStream(m_Data), false); Reader.ReadUInt32(); //Version m_Colors = new Color[Reader.ReadUInt32()]; Reader.ReadBytes(8); //Reserved for (int i = 0; i < m_Colors.Length; i++) m_Colors[i] = new Color(new Vector3(Reader.ReadByte(), Reader.ReadByte(), Reader.ReadByte())); Reader.Close(); m_Data = null; }
public Anim(Stream Data) { m_Reader = new FileReader(Data, true); m_Reader.ReadUInt32(); //Version ASCIIEncoding Enc = new ASCIIEncoding(); Name = Enc.GetString(m_Reader.ReadBytes(m_Reader.ReadUShort())); Duration = m_Reader.ReadFloat(); Distance = m_Reader.ReadFloat(); IsMoving = (m_Reader.ReadByte() != 0) ? true : false; TranslationsCount = m_Reader.ReadUInt32(); Translations = new float[TranslationsCount, 3]; for(int i = 0; i < TranslationsCount; i++) { Translations[i, 0] = m_Reader.ReadFloat(); Translations[i, 1] = m_Reader.ReadFloat(); Translations[i, 2] = m_Reader.ReadFloat(); } RotationsCount = m_Reader.ReadUInt32(); Rotations = new float[RotationsCount, 4]; for (int i = 0; i < RotationsCount; i++) { Rotations[i, 0] = m_Reader.ReadFloat(); Rotations[i, 1] = m_Reader.ReadFloat(); Rotations[i, 2] = m_Reader.ReadFloat(); Rotations[i, 3] = m_Reader.ReadFloat(); } MotionCount = m_Reader.ReadUInt32(); for(int i = 0; i < MotionCount; i++) Motions.Add(new Motion(m_Reader)); m_Reader.Close(); }
public CST(IFFChunk BaseChunk) : base(BaseChunk) { FileReader Reader = new FileReader(new MemoryStream(m_Data), false); Version = Reader.ReadInt16(); ushort NumStrings = 0; if ((Reader.StreamLength - Reader.Position) > 2) { switch (Version) { case 0: NumStrings = Reader.ReadUShort(); for (int i = 0; i < NumStrings; i++) { TranslatedString Str = new TranslatedString(); Str.LangCode = LanguageCodes.unused; Str.TranslatedStr = Reader.ReadPascalString(); if (Strings.ContainsKey(Str.LangCode)) Strings[Str.LangCode].Add(Str); else { List<TranslatedString> LanguageSet = new List<TranslatedString>(); LanguageSet.Add(Str); Strings.Add(Str.LangCode, LanguageSet); } } break; case -1: NumStrings = Reader.ReadUShort(); for (int i = 0; i < NumStrings; i++) { TranslatedString Str = new TranslatedString(); Str.LangCode = LanguageCodes.unused; Str.TranslatedStr = Reader.ReadCString(); if (Strings.ContainsKey(Str.LangCode)) Strings[Str.LangCode].Add(Str); else { List<TranslatedString> LanguageSet = new List<TranslatedString>(); LanguageSet.Add(Str); Strings.Add(Str.LangCode, LanguageSet); } } break; case -2: NumStrings = Reader.ReadUShort(); for (int i = 0; i < NumStrings; i++) { TranslatedString Str = new TranslatedString(); Str.LangCode = LanguageCodes.unused; Str.TranslatedStr = Reader.ReadCString(); Reader.ReadCString(); //Comment if (Strings.ContainsKey(Str.LangCode)) Strings[Str.LangCode].Add(Str); else { List<TranslatedString> LanguageSet = new List<TranslatedString>(); LanguageSet.Add(Str); Strings.Add(Str.LangCode, LanguageSet); } } break; case -3: NumStrings = Reader.ReadUShort(); for (int i = 0; i < NumStrings; i++) { TranslatedString Str = new TranslatedString(); Str.LangCode = (LanguageCodes)Reader.ReadByte(); Str.TranslatedStr = Reader.ReadCString(); Reader.ReadCString(); //Comment if (Strings.ContainsKey(Str.LangCode)) Strings[Str.LangCode].Add(Str); else { List<TranslatedString> LanguageSet = new List<TranslatedString>(); LanguageSet.Add(Str); Strings.Add(Str.LangCode, LanguageSet); } } break; case -4: byte LanguageSets = Reader.ReadByte(); for (int i = 0; i < LanguageSets; i++) { NumStrings = Reader.ReadUShort(); for (int j = 0; j < NumStrings; j++) { TranslatedString Str = new TranslatedString(); Str.LangCode = (LanguageCodes)(Reader.ReadByte() + 1); Str.TranslatedStr = Reader.ReadString(); Reader.ReadString(); //Comment if (Strings.ContainsKey(Str.LangCode)) Strings[Str.LangCode].Add(Str); else { List<TranslatedString> LanguageSet = new List<TranslatedString>(); LanguageSet.Add(Str); Strings.Add(Str.LangCode, LanguageSet); } } } break; } } Reader.Close(); m_Data = null; }
public SPR2Frame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SpriteVersion) { if(SpriteVersion == 1001) { Reader.ReadUInt32(); //Version Reader.ReadUInt32(); //Size } Width = Reader.ReadUShort(); Height = Reader.ReadUShort(); Texture = new Texture2D(Device, Width, Height); ZBuffer = new byte[Width * Height]; uint Flags = Reader.ReadUInt32(); Reader.ReadUShort(); //Palette. TransparentColor = Palette[Reader.ReadUShort()]; HasZBuffer = (Flags & 0x02) == 0x02; HasAlphaChannel = (Flags & 0x04) == 0x04; XLocation = Reader.ReadUShort(); YLocation = Reader.ReadUShort(); bool EndMarker = false; while(!EndMarker) { ushort Marker = Reader.ReadUShort(); var Command = Marker >> 13; var Count = Marker & 0x1FFF; switch(Command) { //Fill this row with pixel data that directly follows; the count byte of the row command denotes //the size in bytes of the row's command/count bytes together with the supplied pixel data. In //the pixel data, each pixel command consists of a 3-bit/13-bit command/count header followed by a //block of pixel data padded to a multiple of 2 bytes. If the row is not filled completely, the //remainder is transparent. The pixel commands are: case 0x00: for(int i = 0; i < Count; i++) { ushort PxMarker = Reader.ReadUShort(); var PxCommand = PxMarker >> 13; var PxCount = PxMarker & 0x1FFF; Color[] Colors; switch(PxCommand) { //Set the next pixel count pixels in the z-buffer and color channels to the values defined //by the pixel data provided directly after this command. Every group of 2 bytes in the pixel //data provides a luminosity (z-buffer) or color index (color) value to be copied to the row //for the z-buffer channel and color channel, respectively, in that order, using the full //opacity value of 255 for each pixel that is not the transparent color. case 0x01: Colors = new Color[PxCount]; for(int j = 0; j < PxCount; j++) { byte Luminosity = Reader.ReadByte(); byte ColorIndex = Reader.ReadByte(); Colors[j] = Palette[ColorIndex]; ZBuffer[j] = Luminosity; } Texture.SetData<Color>(Colors, 0, Colors.Length); break; //Set the next pixel count pixels in the z-buffer, color, and alpha channels to the values //defined by the pixel data provided directly after this command. Every group of 3 bytes in //the pixel data, minus the padding byte at the very end (if it exists), provides a luminosity //(z-buffer and alpha) or color index (color) value to be copied to the row for the z-buffer, //color, and alpha channels, respectively, in that order. The alpha channel data is grayscale //in the range 0-31, and the z buffer is in range 0-255. case 0x02: Colors = new Color[PxCount]; for (int j = 0; j < PxCount; j++) { byte Luminosity = Reader.ReadByte(); byte ColorIndex = Reader.ReadByte(); byte Alpha = (byte)(Reader.ReadByte() * 8.2258064516129032258064516129032); Colors[j] = Palette[ColorIndex]; Colors[j].A = Alpha; ZBuffer[j] = Luminosity; } Texture.SetData<Color>(Colors, 0, Colors.Length); break; //Leave the next pixel count pixels in the color channel filled with the transparent color, //in the z-buffer channel filled with 255, and in the alpha channel filled with 0. This pixel //command has no pixel data. case 0x03: Colors = new Color[PxCount]; for (int j = 0; j < PxCount; j++) { Colors[j] = Color.Transparent; Colors[j].A = 0; ZBuffer[j] = 255; } Texture.SetData<Color>(Colors, 0, Colors.Length); break; //Set the next pixel count pixels in the color channel to the palette color indices defined by //the pixel data provided directly after this command.Every byte in the pixel data, minus the //padding byte at the very end(if it exists), provides a color index value to be copied to the //row for the color channel using the full opacity value of 255 and the closest z-buffer value //of 0 if the pixel is not the transparent color, or otherwise the no opacity value of 0 and the //farthest z-buffer value of 255. case 0x06: Colors = new Color[PxCount]; for (int j = 0; j < PxCount; j++) { byte ColorIndex = Reader.ReadByte(); Colors[j] = Palette[ColorIndex]; Colors[j].A = (Palette[ColorIndex] != Color.Transparent) ? (byte)255 : (byte)0; ZBuffer[j] = (Palette[ColorIndex] != Color.Transparent) ? (byte)0 : (byte)255; } Texture.SetData<Color>(Colors, 0, Colors.Length); break; } } break; //Leave the next count rows in the color channel filled with the transparent color, //in the z-buffer channel filled with 255, and in the alpha channel filled with 0. case 0x04: for (int j = 0; j < Count; j++) { Color[] Colors = new Color[Width]; for (int k = 0; k < Width; k++) { Colors[k] = Color.Transparent; Colors[k].A = 0; ZBuffer[k] = 255; } Texture.SetData<Color>(Colors, 0, Colors.Length); } break; case 0x05: EndMarker = true; break; } } }
public DGRPImg(FileReader Reader, uint Version) { if (Version == 20000 || Version == 20001) { SpriteCount = Reader.ReadUShort(); DirectionFlags = Reader.ReadByte(); ZoomLevel = Reader.ReadByte(); for (int i = 0; i < SpriteCount; i++) Info.Add(new SpriteInfo(Reader, Version)); } else { DirectionFlags = Reader.ReadUInt32(); ZoomLevel = Reader.ReadUInt32(); SpriteCount = Reader.ReadUInt32(); for (int i = 0; i < SpriteCount; i++) Info.Add(new SpriteInfo(Reader, Version)); } }
public SPRFrame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SPRVersion) { if (Version == 1001) { Version = Reader.ReadUInt32(); Size = Reader.ReadUInt32(); } Reader.ReadUInt32(); //Reserved Height = Reader.ReadUShort(); Width = Reader.ReadUShort(); Texture = new Texture2D(Device, Width, Height); for(ushort i = 0; i < Height; i++) { byte Cmd = Reader.ReadByte(); byte Count = Reader.ReadByte(); switch(Cmd) { case 0x04: for(byte j = 0; j < Count; j++) { byte PxCmd = Reader.ReadByte(); byte PxCount = Reader.ReadByte(); Color[] Pixels; switch(PxCmd) { case 0x01: //Leave the next pixel count pixels as transparent. This pixel command has no pixel data. Pixels = new Color[Count]; for (int k = 0; k < Count; k++) Pixels[k] = Color.Transparent; Texture.SetData<Color>(Pixels, 0, Count); break; case 0x02: //Fill the next pixel count pixels with a single palette color. //The pixel data is two bytes: the first byte denotes the palette color //index, and the second byte is padding (which is always equal to the //first byte but is ignored). Pixels = new Color[Count]; byte ColorIndex = Reader.ReadByte(); for (int k = 0; k < Count; k++) Pixels[k] = Palette[ColorIndex]; Texture.SetData<Color>(Pixels, 0, Count); break; case 0x03: //Set the next pixel count pixels to the palette color indices defined by //the pixel data provided directly after this command. Each byte in the pixel data, //minus the padding byte at the very end (if it exists), is a color index value to //be copied to the row. Pixels = new Color[Count]; for (int k = 0; k < Count; k++) Pixels[k] = Palette[Reader.ReadByte()]; Texture.SetData<Color>(Pixels, 0, Count); break; case 0x09: //Leave the next count rows as transparent. for (int k = 0; k < Count; k++) { Pixels = new Color[Width]; for (int l = 0; l < Width; l++) Pixels[l] = Color.Transparent; Texture.SetData<Color>(Pixels, 0, Width); } break; } } break; } } }