summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2007-07-10 16:24:40 +0000
committerpixel <pixel>2007-07-10 16:24:40 +0000
commit2b81447acc91685dbfb6419282a0f53b6ac3eaa0 (patch)
treea3977ef45afdcc9ac1d3a968af6a33819dcf3af9
parent126a396e4af6a3d9e92471cb8e82993853524e46 (diff)
Adding the true hash table support.
-rw-r--r--mpq-bios.c11
-rw-r--r--mpq-bios.h2
-rw-r--r--mpq-misc.c4
-rw-r--r--mpq-misc.h1
4 files changed, 13 insertions, 5 deletions
diff --git a/mpq-bios.c b/mpq-bios.c
index 8af3ef6..88da2ac 100644
--- a/mpq-bios.c
+++ b/mpq-bios.c
@@ -315,24 +315,27 @@ void mpqlib_printtables(struct mpq_archive_t * mpq_a) {
}
int mpqlib_find_hash_entry_by_name(struct mpq_archive_t * mpq_a, const char * name, uint32_t language, uint32_t platform) {
- uint32_t hA, hB;
+ uint32_t h, hA, hB;
+ h = mpqlib_hash_filename(name);
hA = mpqlib_hashA_filename(name);
hB = mpqlib_hashB_filename(name);
- return mpqlib_find_hash_entry_by_hash(mpq_a, hA, hB, language, platform);
+ return mpqlib_find_hash_entry_by_hash(mpq_a, h, hA, hB, language, platform);
}
-int mpqlib_find_hash_entry_by_hash(struct mpq_archive_t * mpq_a, uint32_t hA, uint32_t hB, uint32_t language, uint32_t platform) {
+int mpqlib_find_hash_entry_by_hash(struct mpq_archive_t * mpq_a, uint32_t h, uint32_t hA, uint32_t hB, uint32_t language, uint32_t platform) {
int i;
- for (i = 0; i < mpq_a->hash_table_entries; i++) {
+ for (i = h & (mpq_a->hash_table_entries - 1); i < mpq_a->hash_table_entries; i++) {
if ((mpq_a->hashs[i].file_path_hasha == hA) &&
(mpq_a->hashs[i].file_path_hashb == hB) &&
(mpq_a->hashs[i].language == language) &&
(mpq_a->hashs[i].platform == platform)) {
return mpq_a->hashs[i].file_block_index;
}
+ if (mpq_a->hashs[i].file_block_index == 0xffffffff)
+ break;
}
return -1;
diff --git a/mpq-bios.h b/mpq-bios.h
index 3ce553e..4e82973 100644
--- a/mpq-bios.h
+++ b/mpq-bios.h
@@ -34,7 +34,7 @@ struct mpq_archive_t * mpqlib_reopen_archive(int fd);
void mpqlib_printtables(struct mpq_archive_t *);
void mpqlib_close_archive(struct mpq_archive_t *);
int mpqlib_find_hash_entry_by_name(struct mpq_archive_t *, const char * name, uint32_t language, uint32_t platform);
-int mpqlib_find_hash_entry_by_hash(struct mpq_archive_t *, uint32_t hA, uint32_t hB, uint32_t language, uint32_t platform);
+int mpqlib_find_hash_entry_by_hash(struct mpq_archive_t *, uint32_t h, uint32_t hA, uint32_t hB, uint32_t language, uint32_t platform);
uint64_t mpqlib_ioctl(struct mpq_archive_t *, enum mpqlib_ioctl_t command, int entry);
#ifdef __cplusplus
diff --git a/mpq-misc.c b/mpq-misc.c
index 1e81659..9e1ff5d 100644
--- a/mpq-misc.c
+++ b/mpq-misc.c
@@ -1,6 +1,10 @@
#include "mpq-misc.h"
#include "MPQCryptography.h"
+uint32_t mpqlib_hash_filename(const char * str) {
+ return __mpqlib_hash_cstring(str, 0);
+}
+
uint32_t mpqlib_hashA_filename(const char * str) {
return __mpqlib_hash_cstring(str, 1);
}
diff --git a/mpq-misc.h b/mpq-misc.h
index 714d6de..0f38e66 100644
--- a/mpq-misc.h
+++ b/mpq-misc.h
@@ -7,6 +7,7 @@
extern "C" {
#endif
+uint32_t mpqlib_hash_filename(const char * str);
uint32_t mpqlib_hashA_filename(const char * str);
uint32_t mpqlib_hashB_filename(const char * str);