Beispiel #1
0
 public void ExtractFile(NisPackFile file, string path)
 {
     using (MemoryStream stream = file.GetStream(rawData))
     {
         stream.Seek(0, SeekOrigin.Begin);
         using (EndianBinaryReader reader = new EndianBinaryReader(stream))
         {
             File.WriteAllBytes(path, reader.ReadBytes((int)reader.BaseStream.Length));
         }
     }
 }
Beispiel #2
0
        public NisPack(string filePath)
            : base(filePath)
        {
            using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                stream.Seek(0x0C, SeekOrigin.Begin);
                byte[] numFilesRaw = new byte[4];
                stream.Read(numFilesRaw, 0, numFilesRaw.Length);
                stream.Seek(0, SeekOrigin.Begin);

                /* Crappy endianness detection GO! */
                Endian endian = Endian.BigEndian;
                if (numFilesRaw[0] != 0 && numFilesRaw[3] == 0)
                {
                    endian = Endian.LittleEndian;
                }

                using (EndianBinaryReader reader = new EndianBinaryReader(stream, endian))
                {
                    //OutOfMemoryException on 32bit, on files > 256MB?
                    rawData = new MemoryStream(reader.ReadBytes((int)reader.BaseStream.Length), 0, (int)reader.BaseStream.Length, false, true);

                    reader.BaseStream.Seek(0, SeekOrigin.Begin);

                    Magic       = Encoding.ASCII.GetString(reader.ReadBytes(0x08));
                    Unknown0x08 = reader.ReadUInt32();
                    NumFiles    = reader.ReadUInt32();

                    Files = new NisPackFile[NumFiles];
                    for (int i = 0; i < Files.Length; i++)
                    {
                        Files[i] = new NisPackFile(this, reader);
                    }

                    Files = Files.OrderBy(x => x.Filename).ToArray();
                }
            }
        }