From 36fd1a3846fcb08abdf5dafcd6703586b51e369e Mon Sep 17 00:00:00 2001 From: pixel Date: Fri, 6 Jul 2007 16:22:15 +0000 Subject: Various progress. --- mpq-bios.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'mpq-bios.c') diff --git a/mpq-bios.c b/mpq-bios.c index bfc21df..98e852c 100644 --- a/mpq-bios.c +++ b/mpq-bios.c @@ -9,6 +9,8 @@ #include "MPQCryptography.h" #include "mpq-bios.h" #include "mpq-errors.h" +#include "mpq-misc.h" +#include "int-bios.h" #include "errors.h" #include "inttypes.h" @@ -54,6 +56,8 @@ typedef struct { uint32_t file_block_index; } hash_t; +/* Defined in int-bios.h + typedef struct { uint64_t block_offset; uint32_t block_size; @@ -61,6 +65,8 @@ typedef struct { uint32_t flags; } block_t; +*/ + struct mpq_internals_t { int fd; int closeit; @@ -89,7 +95,7 @@ mpq_archive_t * mpqlib_open_archive(const char * fname) { int fd; mpq_archive_t * r; - if ((fd = open(fname, O_RDONLY | O_BINARY)) == -1) { + if ((fd = open(fname, O_RDONLY | O_LARGEFILE | O_BINARY)) == -1) { __mpqlib_errno = MPQLIB_ERROR_OPEN; return NULL; } @@ -185,7 +191,7 @@ mpq_archive_t * mpqlib_reopen_archive(int fd) { no_mpq(); if (mpq_h.format_version == 1) { - if (read(fd, ((char *)(&mpq_h)) + STD_HEADER_SIZE, EXT_HEADER_SIZE) != EXT_HEADER_SIZE) + if (!read_data(mpq_a, ((char *)(&mpq_h)) + STD_HEADER_SIZE, EXT_HEADER_SIZE)) no_mpq(); } else { mpq_h.extended_block_table_offset = 0; @@ -290,3 +296,57 @@ mpq_archive_t * mpqlib_reopen_archive(int fd) { return mpq_a; } + +void mpqlib_printtables(mpq_archive_t * mpq_a) { + int i; + + printf("Hash table dump.\n"); + printf("HashA HashB language platform index\n"); + printf("-------- -------- -------- -------- -----\n"); + for (i = 0; i < mpq_a->mpq_i->hash_table_entries; i++) { + printf("%08X %08X %08X %08X %d\n", mpq_a->mpq_i->hashs[i].file_path_hasha, mpq_a->mpq_i->hashs[i].file_path_hashb, mpq_a->mpq_i->hashs[i].language, mpq_a->mpq_i->hashs[i].platform, mpq_a->mpq_i->hashs[i].file_block_index); + } + + printf("\n\nBlock table dump.\n"); + printf("Entry Block offset size filesize flags\n"); + printf("-------- ---------------- -------- -------- --------\n"); + for (i = 0; i < mpq_a->mpq_i->block_table_entries; i++) { + printf("%8d %016llX %8d %8d %08X\n", i, mpq_a->mpq_i->blocks[i].block_offset, mpq_a->mpq_i->blocks[i].block_size, mpq_a->mpq_i->blocks[i].file_size, mpq_a->mpq_i->blocks[i].flags); + } +} + +int mpqlib_find_hash_entry(mpq_archive_t * mpq_a, const char * name, uint32_t language, uint32_t platform) { + int i; + uint32_t hA, hB; + + hA = mpqlib_hashA_filename(name); + hB = mpqlib_hashB_filename(name); + + for (i = 0; i < mpq_a->mpq_i->hash_table_entries; i++) { + if ((mpq_a->mpq_i->hashs[i].file_path_hasha == hA) && + (mpq_a->mpq_i->hashs[i].file_path_hashb == hB) && + (mpq_a->mpq_i->hashs[i].language == language) && + (mpq_a->mpq_i->hashs[i].platform == platform)) { + return mpq_a->mpq_i->hashs[i].file_block_index; + } + } + + return -1; +} + +const block_t * __mpqlib_get_block_entry(mpq_archive_t * mpq_a, int entry) { + if ((entry >= mpq_a->mpq_i->block_table_entries) || (entry < 0)) + return NULL; + + return mpq_a->mpq_i->blocks + entry; +} + +int __mpqlib_seek(mpq_archive_t * mpq_a, off_t off) { + if (lseek64(mpq_a->mpq_i->fd, off, SEEK_SET) != off) + return 0; + return 1; +} + +int __mpqlib_read(mpq_archive_t * mpq_a, void * buffer, size_t size) { + return read_data(mpq_a, buffer, size); +} -- cgit v1.2.3