From d6bbe8f2df43685bdc527e226ac5906c2b915e9d Mon Sep 17 00:00:00 2001 From: meep-eep Date: Tue, 15 Oct 2002 04:56:58 +0000 Subject: [PATCH] Improved version (almost there...) git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@122 8092fc87-c524-0410-9efc-e669fe64eaf9 --- tools/pkg/unpkg.c | 73 +++++++++++++++++++++++++++++------------------ tools/pkg/unpkg.h | 14 +++++---- 2 files changed, 55 insertions(+), 32 deletions(-) diff --git a/tools/pkg/unpkg.c b/tools/pkg/unpkg.c index d3d66d1ae..55177c7cd 100644 --- a/tools/pkg/unpkg.c +++ b/tools/pkg/unpkg.c @@ -110,7 +110,7 @@ readIndex(const uint8 *buf) { h.package_list[i].num_instances = GET_INSTANCE(temp); h.package_list[i].file_index = GET_PACKAGE(temp); fprintf(stderr, "0x%08x #%d, %d types, %d instances, " - "file index 0x%04x, ", bufptr - buf, i, + "file index 0x%04x, ", bufptr - buf, i + 1, h.package_list[i].num_types, h.package_list[i].num_instances, h.package_list[i].file_index); @@ -165,43 +165,62 @@ readIndex(const uint8 *buf) { if (filename == NULL) filename = ""; fprintf(stderr, "0x%08x Package #%d (%s):\n", - bufptr - buf, i, filename); + bufptr - buf, i + 1, filename); } else { // not packaged - fprintf(stderr, "0x%08x Package #%d:\n", bufptr - buf, i); + fprintf(stderr, "0x%08x Package #%d:\n", + bufptr - buf, i + 1); } + num_types = h.package_list[i].num_types; + h.package_list[i].type_list = + malloc(num_types * sizeof (packtype_desc)); for (j = 0; j < num_types; j++) { temp = MAKE_DWORD(bufptr[0], bufptr[1], bufptr[2], bufptr[3]); + h.package_list[i].type_list[j].type = GET_TYPE(temp); + h.package_list[i].type_list[j].first_instance = + GET_INSTANCE(temp); + h.package_list[i].type_list[j].num_instances = + GET_PACKAGE(temp); fprintf(stderr, "0x%08x Type #%d: type %d, " - "%d instances, rest: %d\n", + "%d instances starting with #%d\n", bufptr - buf, j, - GET_TYPE(temp), - GET_PACKAGE(temp), /* Yes, this is correct, the - package field contains the number of instances */ - GET_INSTANCE(temp)); + h.package_list[i].type_list[j].type, + h.package_list[i].type_list[j].num_instances, + h.package_list[i].type_list[j].first_instance); bufptr += 4; } - num_instances = h.package_list[i].num_instances; - for (j = 0; j < num_instances; j++) { - if (h.res_flags) { - // packaged - fprintf(stderr, "0x%08x Instance #%d: size %d " - "bytes\n", bufptr - buf, j, - 4 * MAKE_WORD(bufptr[0], bufptr[1])); - } else { - char *filename; - - filename = get_file_name(buf, &h, - MAKE_WORD(bufptr[0], bufptr[1])); - if (filename == NULL) - filename = ""; - fprintf(stderr, "0x%08x Instance #%d: %s\n", - bufptr - buf, j, filename); - } - bufptr += 2; - } + for (j = 0; j < num_types; j++) { + int k; + + num_instances = h.package_list[i].type_list[j].num_instances; + for (k = 0; k < num_instances; k++) { + if (h.res_flags) { + // packaged + fprintf(stderr, "0x%08x Instance #%d of " + "type %d: size %d bytes\n", bufptr - buf, + k + h.package_list[i].type_list[j]. + first_instance, + h.package_list[i].type_list[j].type, + 4 * MAKE_WORD(bufptr[0], bufptr[1])); + } else { + char *filename; + + filename = get_file_name(buf, &h, + MAKE_WORD(bufptr[0], bufptr[1])); + if (filename == NULL) + filename = ""; + fprintf(stderr, "0x%08x Instance #%d of " + "type %d: %s\n", bufptr - buf, + k + h.package_list[i].type_list[j]. + first_instance, + h.package_list[i].type_list[j].type, + filename); + } + bufptr += 2; + } // for k + } // for j } } } diff --git a/tools/pkg/unpkg.h b/tools/pkg/unpkg.h index 126522689..8ac7e594e 100644 --- a/tools/pkg/unpkg.h +++ b/tools/pkg/unpkg.h @@ -20,12 +20,15 @@ typedef unsigned int uint32; ((uint16)((res) >> (TYPE_BITS + INSTANCE_BITS)) & \ ((1 << PACKAGE_BITS) - 1)) -typedef struct -{ + +typedef struct { + uint8 type; + uint16 first_instance; // only low 13 bits used + uint16 num_instances; // only low 11 bits used +} packtype_desc; + +typedef struct { uint16 instance_count; -#if 0 - RES_VECTORS func_vectors; -#endif } type_desc; typedef struct { @@ -40,6 +43,7 @@ typedef struct { uint16 file_index; // only low 11 bits used uint8 flags; uint32 data_loc; // only low 24 bits used + packtype_desc *type_list; } package_desc; typedef struct {