public Bitmap GetImage() { var initstream = GetReadStream(); var reader = new EndiannessAwareBinaryReader(initstream, Encoding.Default, true, Endianness); try { var savpos = reader.BaseStream.Position; if (reader.ReadInt32(ByteOrder.LittleEndian) == 0x73676573) { Endianness = ByteOrder.BigEndian; reader.BaseStream.Seek(-4, SeekOrigin.Current); reader.Close(); reader.Dispose(); reader = new EndiannessAwareBinaryReader( SEGSCompression.DecompressStream(initstream, Endianness), Endianness); } else { reader.BaseStream.Seek(12, SeekOrigin.Current); if (reader.BaseStream.Position != reader.BaseStream.Length) { if (reader.ReadInt32(ByteOrder.LittleEndian) == 0x73676573) { Endianness = ByteOrder.BigEndian; reader.BaseStream.Seek(-4, SeekOrigin.Current); reader.Close(); reader.Dispose(); reader = new EndiannessAwareBinaryReader( SEGSCompression.DecompressStream(initstream, Endianness), Endianness); } else { reader.BaseStream.Seek(-20, SeekOrigin.Current); } } else { reader.BaseStream.Position = savpos; } } if (!endiannessChecked) { CheckEndianness(reader.ReadBytes(4)); reader.ChangeEndianness(Endianness); reader.BaseStream.Seek(-4, SeekOrigin.Current); } using (var memStream = new MemoryStream()) { reader.BaseStream.CopyTo(memStream); var ddsImage = new DDSImage(memStream.ToArray(), Endianness); if (ddsImage.BitmapImage == null) { return(null); } return(ddsImage.BitmapImage); } } catch { return(null); } finally { reader.Close(); reader.Dispose(); initstream.Close(); initstream.Dispose(); } }
public VirtualFileSystemInfo[] GetFiles(bool recheck = false) { if (!Initialized) { Initialize(); InitGetHeader(); } try { if (FileCount <= 0) { return(new VirtualFileSystemInfo[0]); } if (Files != null && !recheck) { return(Files); } using (var reader = new EndiannessAwareBinaryReader(GetReadStream(), Endianness)) { ReadHeaderInfo(reader); var virtualFiles = new VirtualFileSystemInfo[FileCount]; for (var i = 0; i < FileCount; i++) { var fileName = Encoding.ASCII .GetString(reader.ReadBytes(FileNameLength, ByteOrder.LittleEndian)) .Replace("\0", string.Empty); var fileIndex = reader.ReadUInt32(); var fileOffset = reader.ReadUInt32(); var fileLength = reader.ReadUInt32(); var seeklength = (FileNameLength + 12) % 16; reader.BaseStream.Seek(seeklength == 0 ? seeklength : 16 - seeklength, SeekOrigin.Current); if (reader.ReadByte() == 0x0 && seeklength == 0) { reader.BaseStream.Seek(16, SeekOrigin.Current); } reader.BaseStream.Seek(-1, SeekOrigin.Current); var ext = Path.GetExtension(fileName); switch (ext) { case ".pac": case ".paccs": case ".pacgz": case ".fontpac": virtualFiles[i] = new PACFileInfo( FullName + ':' + fileName, fileLength, fileOffset + HeaderSize, this); break; case ".hip": virtualFiles[i] = new HIPFileInfo( FullName + ':' + fileName, fileLength, fileOffset + HeaderSize, this); break; case ".hpl": virtualFiles[i] = new HPLFileInfo( FullName + ':' + fileName, fileLength, fileOffset + HeaderSize, this); break; case ".dds": virtualFiles[i] = new DDSFileInfo( FullName + ':' + fileName, fileLength, fileOffset + HeaderSize, this); break; default: virtualFiles[i] = new VirtualFileSystemInfo( FullName + ':' + fileName, fileLength, fileOffset + HeaderSize, this); break; } } reader.Close(); Files = virtualFiles; return(Files); } } catch { Files = new VirtualFileSystemInfo[0]; return(Files); } }