示例#1
0
        private MpqHash GetHashEntry(string Filename)
        {
            uint index = HashString(Filename, 0);

            index &= mHeader.HashTableSize - 1;
            uint name1 = HashString(Filename, 0x100);
            uint name2 = HashString(Filename, 0x200);

            uint i = index;

            do
            {
                MpqHash hash = mHashes[i];
                if (hash.Name1 == name1 && hash.Name2 == name2)
                {
                    return(hash);
                }
                if (++i >= mHashes.Length)
                {
                    i = 0;
                }
            } while (i != index);

            return(MpqHash.InvalidHash());
        }
示例#2
0
		private void Init()
		{
			if (LocateMpqHeader() == false)
				throw new MpqParserException("Unable to find MPQ header");

			var br = new BinaryReader(mStream);

			mBlockSize = 0x200 << mHeader.BlockSize;

			// Load hash table
			mStream.Seek(mHeader.HashTablePos, SeekOrigin.Begin);
			byte[] hashdata = br.ReadBytes((int)(mHeader.HashTableSize * MpqHash.Size));
			DecryptTable(hashdata, "(hash table)");

			var br2 = new BinaryReader(new MemoryStream(hashdata));
			mHashes = new MpqHash[mHeader.HashTableSize];

			for (int i = 0; i < mHeader.HashTableSize; i++)
				mHashes[i] = new MpqHash(br2);

			// Load block table
			mStream.Seek(mHeader.BlockTablePos, SeekOrigin.Begin);
			byte[] blockdata = br.ReadBytes((int)(mHeader.BlockTableSize * MpqBlock.Size));
			DecryptTable(blockdata, "(block table)");

			br2 = new BinaryReader(new MemoryStream(blockdata));
			mBlocks = new MpqBlock[mHeader.BlockTableSize];

			for (int i = 0; i < mHeader.BlockTableSize; i++)
				mBlocks[i] = new MpqBlock(br2, (uint)mHeaderOffset);
		}
示例#3
0
        private MpqHash GetHashEntry(string Filename)
        {
            //uint index = HashString(Filename, 0);
            //index  &= mHeader.HashTableSize - 1;
            uint name1 = HashString(Filename, 0x100);
            uint name2 = HashString(Filename, 0x200);

            // 63   32 31    0
            // |     | |     |
            // [name2] [name1]

            MpqHash hash;

            if (dcHashes.TryGetValue((((UInt64)name2) << 32) | name1, out hash))
            {
                return(hash);
            }


            /*for (uint i = index; ; )
             * {
             *  MpqHash hash = mHashes[i];
             *  if (hash.Name1 == name1 && hash.Name2 == name2) return hash;
             *
             *  if (++i >= mHashes.Length) i = 0;
             *  if (i == index) break;
             * }*/

            return(MpqHash.InvalidHash());
        }
示例#4
0
        public static MpqHash InvalidHash()
        {
            MpqHash invalid = new MpqHash();

            invalid.Name1 = uint.MaxValue;
            invalid.Name2 = uint.MaxValue;
            return(invalid);
        }
示例#5
0
        private void Init()
        {
            if (LocateMpqHeader() == false)
            {
                Console.WriteLine("Unable to find MPQ header");
                mStream.Close();
                return;
            }

            BinaryReader br = new BinaryReader(mStream);

            mBlockSize = 0x200 << mHeader.BlockSize;

            // Load hash table
            mStream.Seek(mHeader.HashTablePos, SeekOrigin.Begin);
            byte[] hashdata = br.ReadBytes((int)(mHeader.HashTableSize * MpqHash.Size));
            DecryptTable(hashdata, "(hash table)");

            BinaryReader br2 = new BinaryReader(new MemoryStream(hashdata));

            //mHashes = new MpqHash[mHeader.HashTableSize];
            dcHashes = new Dictionary <UInt64, MpqHash>((int)mHeader.HashTableSize);

            for (int i = 0; i < mHeader.HashTableSize; i++)
            {
                //mHashes[i] = new MpqHash(br2);
                MpqHash mpqHash = new MpqHash(br2);

                // 63   32 31    0
                // |     | |     |
                // [name2] [name1]

                if (mpqHash.IsValid)
                {
                    dcHashes.Add((((UInt64)mpqHash.Name2) << 32) | mpqHash.Name1, mpqHash);
                }
            }

            // Load block table
            mStream.Seek(mHeader.BlockTablePos, SeekOrigin.Begin);
            byte[] blockdata = br.ReadBytes((int)(mHeader.BlockTableSize * MpqBlock.Size));
            DecryptTable(blockdata, "(block table)");

            br2     = new BinaryReader(new MemoryStream(blockdata));
            mBlocks = new MpqBlock[mHeader.BlockTableSize];

            for (int i = 0; i < mHeader.BlockTableSize; i++)
            {
                mBlocks[i] = new MpqBlock(br2, (uint)mHeaderOffset);
            }

            isValid = true;
        }
示例#6
0
        public uint GetFileSize(string Filename)
        {
            MpqHash hash = GetHashEntry(Filename);

            if (hash.IsValid)
            {
                MpqBlock block = mBlocks[hash.BlockIndex];
                return(block.FileSize);
            }

            return(0xFFFFFFFF);
        }
示例#7
0
        public MpqStream OpenFile(string Filename)
        {
            MpqHash hash = GetHashEntry(Filename);

            if (!hash.IsValid)
            {
                throw new FileNotFoundException("File not found: " + Filename);
            }

            MpqBlock block = mBlocks[hash.BlockIndex];

            return(new MpqStream(this, block));
        }
示例#8
0
        private MpqHash GetHashEntry(string Filename)
        {
            uint index = HashString(Filename, 0);

            index &= mHeader.HashTableSize - 1;
            uint name1 = HashString(Filename, 0x100);
            uint name2 = HashString(Filename, 0x200);

            for (uint i = index; i < mHashes.Length; ++i)
            {
                MpqHash hash = mHashes[i];
                if (hash.Name1 == name1 && hash.Name2 == name2)
                {
                    return(hash);
                }
            }

            return(MpqHash.InvalidHash());
        }
示例#9
0
        private void Init()
        {
            if (LocateMpqHeader() == false)
            {
                throw new MpqParserException("Unable to find MPQ header");
            }

            BinaryReader br = new BinaryReader(mStream);

            mBlockSize = 0x200 << mHeader.BlockSize;

            // Load hash table
            mStream.Seek(mHeader.HashTablePos, SeekOrigin.Begin);
            byte[] hashdata = br.ReadBytes((int)(mHeader.HashTableSize * MpqHash.Size));
            DecryptTable(hashdata, "(hash table)");

            BinaryReader br2 = new BinaryReader(new MemoryStream(hashdata));

            mHashes = new MpqHash[mHeader.HashTableSize];

            for (int i = 0; i < mHeader.HashTableSize; i++)
            {
                mHashes[i] = new MpqHash(br2);
            }

            // Load block table
            mStream.Seek(mHeader.BlockTablePos, SeekOrigin.Begin);
            byte[] blockdata  = br.ReadBytes((int)(mHeader.BlockTableSize * MpqBlock.Size));
            int    blockcount = (int)(blockdata.Length / MpqBlock.Size); // This is not always mHeader.BlockTableSize

            DecryptTable(blockdata, "(block table)");

            br2     = new BinaryReader(new MemoryStream(blockdata));
            mBlocks = new MpqBlock[mHeader.BlockTableSize];

            for (int i = 0; i < blockcount; i++)
            {
                mBlocks[i] = new MpqBlock(br2, (uint)mHeaderOffset);
            }
        }
示例#10
0
        private MpqHash GetHashEntry(string Filename)
        {
            uint index = HashString(Filename, 0);

            index &= mHeader.HashTableSize - 1;
            uint name1 = HashString(Filename, 0x100);
            uint name2 = HashString(Filename, 0x200);

            for (uint i = index; i < mHashes.Length; ++i)
            {
                MpqHash hash = mHashes[i];
                if (hash.Name1 == name1 && hash.Name2 == name2)
                {
                    return(hash);
                }
            }

            MpqHash nullhash = new MpqHash();

            nullhash.BlockIndex = uint.MaxValue;
            return(nullhash);
        }
示例#11
0
 public static MpqHash InvalidHash()
 {
     MpqHash invalid = new MpqHash();
     invalid.Name1 = uint.MaxValue;
     invalid.Name2 = uint.MaxValue;
     return invalid;
 }
示例#12
0
        public bool FileExists(string Filename)
        {
            MpqHash hash = GetHashEntry(Filename);

            return(hash.IsValid);
        }
示例#13
0
        public bool FileExists(string Filename)
        {
            MpqHash hash = GetHashEntry(Filename);

            return(hash.BlockIndex != uint.MaxValue);
        }
示例#14
0
		private MpqHash GetHashEntry(string Filename)
		{
			uint index = HashString(Filename, 0);
			index  &= mHeader.HashTableSize - 1;
			uint name1 = HashString(Filename, 0x100);
			uint name2 = HashString(Filename, 0x200);
			
			for(uint i = index; i < mHashes.Length; ++i)
			{
				MpqHash hash = mHashes[i];
				if (hash.Name1 == name1 && hash.Name2 == name2) return hash;
			}

			MpqHash nullhash = new MpqHash();
			nullhash.BlockIndex = uint.MaxValue;
			return nullhash;
		}
示例#15
0
		private void Init()
		{
            if (LocateMpqHeader() == false)
            {
                Console.WriteLine("Unable to find MPQ header");
                mStream.Close();
                return;
            }

			BinaryReader br = new BinaryReader(mStream);

			mBlockSize = 0x200 << mHeader.BlockSize;

			// Load hash table
			mStream.Seek(mHeader.HashTablePos, SeekOrigin.Begin);
			byte[] hashdata = br.ReadBytes((int)(mHeader.HashTableSize * MpqHash.Size));
			DecryptTable(hashdata, "(hash table)");

			BinaryReader br2 = new BinaryReader(new MemoryStream(hashdata));
			//mHashes = new MpqHash[mHeader.HashTableSize];
            dcHashes = new Dictionary<UInt64, MpqHash>((int)mHeader.HashTableSize);
            
            for (int i = 0; i < mHeader.HashTableSize; i++)
            {
                //mHashes[i] = new MpqHash(br2);
                MpqHash mpqHash = new MpqHash(br2);

                // 63   32 31    0
                // |     | |     |
                // [name2] [name1]

                if (mpqHash.IsValid)                                    
                    dcHashes.Add((((UInt64)mpqHash.Name2) << 32) | mpqHash.Name1, mpqHash);                
            }

			// Load block table
			mStream.Seek(mHeader.BlockTablePos, SeekOrigin.Begin);
			byte[] blockdata = br.ReadBytes((int)(mHeader.BlockTableSize * MpqBlock.Size));
			DecryptTable(blockdata, "(block table)");

			br2 = new BinaryReader(new MemoryStream(blockdata));
			mBlocks = new MpqBlock[mHeader.BlockTableSize];

			for (int i = 0; i < mHeader.BlockTableSize; i++)
				mBlocks[i] = new MpqBlock(br2, (uint)mHeaderOffset);

            isValid = true;
		}