Exemple #1
0
        private void GenerateKey(string path)
        {
            uint seed = NexonArchiveFileDecoderStream.PythonHash(Encoding.ASCII.GetBytes(path));

            for (int i = 0; i < 16; i++)
            {
                seed        = seed * 1103515245u + 12345u;
                this.key[i] = (byte)(seed & 255u);
            }
        }
Exemple #2
0
        public long Extract(Stream outputStream)
        {
            if (outputStream == null)
            {
                throw new ArgumentNullException("outputStream");
            }
            if (!outputStream.CanWrite)
            {
                throw new ArgumentException("Cannot write to stream.", "outputStream");
            }
            if (this.extractedSize == 0L)
            {
                return(0L);
            }
            long result;

            lock (this.archive.Stream)
            {
                Stream readStream = new BoundedStream(this.archive.Stream, this.offset, this.storedSize);
                readStream.Position = 0L;
                switch (this.storedType)
                {
                case NexonArchiveFileEntryType.Raw:
                    break;

                case NexonArchiveFileEntryType.Encoded:
                    readStream = new NexonArchiveFileDecoderStream(readStream, this.path);
                    break;

                case NexonArchiveFileEntryType.EncodedAndCompressed:
                    readStream = new NexonArchiveFileDecompressStream(new NexonArchiveFileDecoderStream(readStream, this.path), this.extractedSize);
                    break;

                default:
                    throw new NotSupportedException("Unsupported file storage type: " + this.storedType + ".");
                }
                lock (outputStream)
                {
                    byte[] buffer      = new byte[8192];
                    long   totalLength = 0L;
                    int    length;
                    while ((length = readStream.Read(buffer, 0, 8192)) > 0)
                    {
                        outputStream.Write(buffer, 0, length);
                        totalLength += (long)length;
                    }
                    result = totalLength;
                }
            }
            return(result);
        }