1 #define _CRT_SECURE_NO_DEPRECATE
2 #define _CRT_SECURE_NO_WARNINGS
7 #include "libmpq/mpq.h"
16 typedef unsigned int uint32
;
23 MPQArchive(const char* filename
);
26 uint32
HashString(const char* Input
, uint32 Offset
) {
27 uint32 seed1
= 0x7fed7fed;
28 uint32 seed2
= 0xeeeeeeee;
30 for (uint32 i
= 0; i
< strlen(Input
); i
++) {
31 uint32 val
= toupper(Input
[i
]);
32 seed1
= mpq_a
.buf
[Offset
+ val
] ^ (seed1
+ seed2
);
33 seed2
= val
+ seed1
+ seed2
+ (seed2
<< 5) + 3;
38 mpq_hash
GetHashEntry(const char* Filename
) {
39 uint32 index
= HashString(Filename
, 0);
40 index
&= mpq_a
.header
->hashtablesize
- 1;
41 uint32 name1
= HashString(Filename
, 0x100);
42 uint32 name2
= HashString(Filename
, 0x200);
44 for(uint32 i
= index
; i
< mpq_a
.header
->hashtablesize
; ++i
) {
45 mpq_hash hash
= mpq_a
.hashtable
[i
];
46 if (hash
.name1
== name1
&& hash
.name2
== name2
) return hash
;
50 nullhash
.blockindex
= 0xFFFFFFFF;
54 void GetFileListTo(vector
<string
>& filelist
) {
55 mpq_hash hash
= GetHashEntry("(listfile)");
56 uint32 blockindex
= hash
.blockindex
;
58 if ((blockindex
== 0xFFFFFFFF) || (blockindex
== 0))
61 uint32 size
= libmpq_file_info(&mpq_a
, LIBMPQ_FILE_UNCOMPRESSED_SIZE
, blockindex
);
62 char *buffer
= new char[size
];
64 libmpq_file_getdata(&mpq_a
, hash
, blockindex
, (unsigned char*)buffer
);
69 token
= strtok( buffer
, seps
);
71 while ((token
!= NULL
) && (counter
< size
)) {
72 //cout << token << endl;
73 token
[strlen(token
) - 1] = 0;
75 filelist
.push_back(s
);
76 counter
+= strlen(token
) + 2;
77 token
= strtok(NULL
, seps
);
83 typedef std::deque
<MPQArchive
*> ArchiveSet
;
93 MPQFile(const MPQFile
&f
) {}
94 void operator=(const MPQFile
&f
) {}
97 MPQFile(const char* filename
); // filenames are not case sensitive
98 ~MPQFile() { close(); }
99 size_t read(void* dest
, size_t bytes
);
100 size_t getSize() { return size
; }
101 size_t getPos() { return pointer
; }
102 char* getBuffer() { return buffer
; }
103 char* getPointer() { return buffer
+ pointer
; }
104 bool isEof() { return eof
; }
105 void seek(int offset
);
106 void seekRelative(int offset
);
110 inline void flipcc(char *fcc
)