Example #1
0
        public static long HashWAR(string s)
        {
            uint ph = 0;
            uint sh = 0;

            MYP.HashWAR(s, 3735928559U, out ph, out sh);
            return(((long)ph << 32) + (long)sh);
        }
Example #2
0
        public byte[] ReadFile(string name)
        {
            long key = MYP.HashWAR(name);

            if (this.Enteries.ContainsKey(key))
            {
                return(this.ReadFile(this.Enteries[key]));
            }
            return((byte[])null);
        }
Example #3
0
        public Stream GetAssetStream(string assetName)
        {
            long hash = MYP.HashWAR(assetName);

            foreach (var myp in Archives.Values)
            {
                if (myp.Enteries.ContainsKey(hash))
                {
                    return(new MemoryStream(GetAsset(myp.Enteries[hash])));
                }
            }

            return(null);
        }
Example #4
0
        public bool HasAsset(string assetName)
        {
            long hash = MYP.HashWAR(assetName);

            foreach (var myp in Archives.Values)
            {
                if (myp.Enteries.ContainsKey(hash))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #5
0
        public void AddEntries(List <Tuple <string, byte[]> > files)
        {
            this._stream.Position = 24L;
            BinaryWriter binaryWriter = new BinaryWriter(this._stream);

            binaryWriter.Write((long)(uint)this.Enteries.Count + (long)files.Count);
            if (this.MFTTables.Count > 0)
            {
                this._stream.Position = this.MFTTables.Last <MYP.MFTHeader>().Offset + 4L;
                binaryWriter.Write((ulong)binaryWriter.BaseStream.Length);
            }
            binaryWriter.BaseStream.Position = binaryWriter.BaseStream.Length;
            int index1 = 0;
            List <MYP.MFTEntry> mftEntryList = new List <MYP.MFTEntry>();
            int  count = files.Count;
            long num1  = 0;

            while (count > 0)
            {
                binaryWriter.Write(1000U);
                if (files.Count - index1 > 1000)
                {
                    num1 = this._stream.Position;
                    binaryWriter.Write(0L);
                }
                else
                {
                    binaryWriter.Write(0L);
                }
                for (int index2 = 0; index2 < 1000; ++index2)
                {
                    if (index1 < files.Count)
                    {
                        --count;
                        MYP.MFTEntry mftEntry     = new MYP.MFTEntry();
                        MemoryStream memoryStream = new MemoryStream();
                        using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Compress, true))
                            deflateStream.Write(files[index1].Item2, 0, files[index1].Item2.Length);
                        mftEntry.Data    = new byte[memoryStream.Length + 2L];
                        mftEntry.Data[0] = (byte)120;
                        mftEntry.Data[1] = (byte)156;
                        Buffer.BlockCopy((Array)memoryStream.ToArray(), 0, (Array)mftEntry.Data, 2, (int)memoryStream.Length);
                        mftEntry.CompressedSize   = (uint)mftEntry.Data.Length;
                        mftEntry.Hash             = MYP.HashWAR(files[index1].Item1);
                        mftEntry.CRC32            = CRC32.ComputeChecksum(files[index1].Item2);
                        mftEntry.Compressed       = (byte)1;
                        mftEntry.UnCompressedSize = (uint)files[index1].Item2.Length;
                        mftEntry.MFTEntryOffset   = this._stream.Position;
                        binaryWriter.Write(0L);
                        binaryWriter.Write(mftEntry.HeaderSize);
                        binaryWriter.Write(mftEntry.CompressedSize);
                        binaryWriter.Write(mftEntry.UnCompressedSize);
                        binaryWriter.Write(mftEntry.Hash);
                        binaryWriter.Write(mftEntry.CRC32);
                        binaryWriter.Write(mftEntry.Compressed);
                        binaryWriter.Write((byte)0);
                        mftEntryList.Add(mftEntry);
                        ++index1;
                    }
                    else
                    {
                        binaryWriter.Write(0L);
                        binaryWriter.Write(0U);
                        binaryWriter.Write(0U);
                        binaryWriter.Write(0U);
                        binaryWriter.Write(0L);
                        binaryWriter.Write(0U);
                        binaryWriter.Write((byte)0);
                        binaryWriter.Write((byte)0);
                    }
                }
                int num2 = 0;
                foreach (MYP.MFTEntry mftEntry in mftEntryList)
                {
                    long position = this._stream.Position;
                    this._stream.Position = mftEntry.MFTEntryOffset;
                    binaryWriter.Write(position);
                    this._stream.Position = position;
                    byte[] data = mftEntry.Data;
                    this._stream.Write(data, 0, data.Length);
                    if ((int)mftEntry.Compressed == 1)
                    {
                        byte[]       buffer       = new byte[(int)mftEntry.UnCompressedSize];
                        MemoryStream memoryStream = new MemoryStream(data);
                        memoryStream.Position = (long)(mftEntry.HeaderSize + 2U);
                        using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Decompress, true))
                            deflateStream.Read(buffer, 0, buffer.Length);
                    }
                    ++num2;
                }
                if (index1 < files.Count)
                {
                    long position = this._stream.Position;
                    this._stream.Position = num1;
                    binaryWriter.Write(position);
                    this._stream.Position = position;
                }
                mftEntryList.Clear();
            }
        }
Example #6
0
 public void UpdateFile(string name, byte[] data)
 {
     this.UpdateFile(MYP.HashWAR(name), data);
 }