Example #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());
        }
Example #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);
		}
Example #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());
        }
Example #4
0
        public static MpqHash InvalidHash()
        {
            MpqHash invalid = new MpqHash();

            invalid.Name1 = uint.MaxValue;
            invalid.Name2 = uint.MaxValue;
            return(invalid);
        }
Example #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;
        }
Example #6
0
        public uint GetFileSize(string Filename)
        {
            MpqHash hash = GetHashEntry(Filename);

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

            return(0xFFFFFFFF);
        }
Example #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));
        }
Example #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());
        }
Example #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);
            }
        }
Example #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);
        }
Example #11
0
 public static MpqHash InvalidHash()
 {
     MpqHash invalid = new MpqHash();
     invalid.Name1 = uint.MaxValue;
     invalid.Name2 = uint.MaxValue;
     return invalid;
 }
Example #12
0
        public bool FileExists(string Filename)
        {
            MpqHash hash = GetHashEntry(Filename);

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

            return(hash.BlockIndex != uint.MaxValue);
        }
Example #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;
		}
Example #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;
		}