diff --git a/.vs/gust_gmpk.vcxproj.user b/.vs/gust_gmpk.vcxproj.user
index ab13ac9..e1d8846 100644
--- a/.vs/gust_gmpk.vcxproj.user
+++ b/.vs/gust_gmpk.vcxproj.user
@@ -3,7 +3,7 @@
$(SolutionDir)
WindowsLocalDebugger
- H_KYO_A.gmpk
+ BOCHI_00
$(SolutionDir)
diff --git a/gust_gmpk.c b/gust_gmpk.c
index a881b6d..0d85f76 100644
--- a/gust_gmpk.c
+++ b/gust_gmpk.c
@@ -36,7 +36,6 @@
#define NID1_LE_MAGIC 0x4E494431 // '1DIN'
#define NID1_BE_MAGIC 0x3144494E // 'NID1'
#define EXPECTED_VERSION 0x00312E31
-#define ENTRY_FLAG_HAS_G1X 0x00000001
#define MIN_HEADER_SIZE 0x100
#define MAX_HEADER_SIZE 0x10000
#define MAX_NAMES_COUNT 0x100
@@ -260,22 +259,25 @@ JSON_Value* read_sdp(uint8_t* buf, uint32_t size)
return NULL;
}
model_entry* me = (model_entry*)&buf[hdr->entry_offset];
- if (hdr->entry_count > 1 && (me->component[hdr->entry_record_size / 2 - 1].has_component != 1 ||
- me->component[hdr->entry_record_size / 2 - 1].file_index != hdr->entry_count - 1)) {
- fprintf(stderr, "ERROR: Unexpected EntryMap submodel count\n");
- fprintf(stderr, "Please report this error to %s.\n", REPORT_URL);
- json_value_free(json_sdp);
- return NULL;
- }
- for (uint32_t i = 1; i < hdr->entry_count; i++) {
- me = (model_entry*)&buf[hdr->entry_offset + (i * hdr->entry_record_size * sizeof_32(uint32_t))];
- if (me->component[hdr->entry_record_size / 2 - 1].has_component != 1 ||
- me->component[hdr->entry_record_size / 2 - 1].file_index != 0xffffffff) {
- fprintf(stderr, "ERROR: More than one level of EntryMap submodels\n");
+ if (me->component[0].has_component != 0) {
+ // Only check submodels if we actually have a model
+ if (hdr->entry_count > 1 && (me->component[hdr->entry_record_size / 2 - 1].has_component != 1 ||
+ me->component[hdr->entry_record_size / 2 - 1].file_index != hdr->entry_count - 1)) {
+ fprintf(stderr, "ERROR: Unexpected EntryMap submodel count\n");
fprintf(stderr, "Please report this error to %s.\n", REPORT_URL);
json_value_free(json_sdp);
return NULL;
}
+ for (uint32_t i = 1; i < hdr->entry_count; i++) {
+ me = (model_entry*)&buf[hdr->entry_offset + (i * hdr->entry_record_size * sizeof_32(uint32_t))];
+ if (me->component[hdr->entry_record_size / 2 - 1].has_component != 1 ||
+ me->component[hdr->entry_record_size / 2 - 1].file_index != 0xffffffff) {
+ fprintf(stderr, "ERROR: More than one level of EntryMap submodels\n");
+ fprintf(stderr, "Please report this error to %s.\n", REPORT_URL);
+ json_value_free(json_sdp);
+ return NULL;
+ }
+ }
}
}
@@ -610,7 +612,7 @@ int main_utf8(int argc, char** argv)
printf("OFFSET SIZE NAME\n");
uint32_t extracted_files = 0, num_extensions_to_check = entrymap_sdp->entry_record_size / 2;
- if (entrymap_sdp->entry_count > 1)
+ if (entrymap_sdp->entry_count > 1 && fp[0] == 1)
num_extensions_to_check -= 1;
if (num_extensions_to_check > array_size(extension)) {
fprintf(stderr, "ERROR: This archive includes unsupported G1X data\n");
@@ -620,7 +622,7 @@ int main_utf8(int argc, char** argv)
for (uint32_t i = 0; i < entrymap_sdp->entry_count; i++, fp = &fp[entrymap_sdp->entry_record_size]) {
const char* name = json_object_get_string(json_array_get_object(json_names, i), "name");
for (uint32_t j = 0; j < num_extensions_to_check; j++) {
- if (fp[2 * j] & ENTRY_FLAG_HAS_G1X) {
+ if (fp[2 * j] == 1) {
uint32_t index = fp[2 * j + 1];
snprintf(path, sizeof(path), "%s%s%c%s%s", dir,
_basename(argv[argc - 1]), PATH_SEP, name, extension[j]);
@@ -652,16 +654,14 @@ int main_utf8(int argc, char** argv)
}
}
}
- if (extracted_files != files_count) {
- fprintf(stderr, "ERROR: Some files were not extracted\n");
- goto out;
- }
-
if (!list_only) {
snprintf(path, sizeof(path), "%s%cgmpk.json", argv[argc - 1], PATH_SEP);
json_serialize_to_file_pretty(json, path);
}
-
+ if (extracted_files != files_count) {
+ fprintf(stderr, "ERROR: Some files were not extracted\n");
+ goto out;
+ }
r = 0;
} else {
// Create a GMPK
@@ -751,7 +751,7 @@ int main_utf8(int argc, char** argv)
me->component[j].file_index = files_count++;
}
}
- if (names_count > 1) {
+ if (entry_data[0] == 1 && names_count > 1) {
me->component[entry_data_size - 1].has_component = 1;
me->component[entry_data_size - 1].file_index = (i == 0) ? names_count - 1 : 0xffffffff;
}
diff --git a/test_g1t.cmd b/test_g1t.cmd
index cd6c0b3..59196fb 100644
--- a/test_g1t.cmd
+++ b/test_g1t.cmd
@@ -6,6 +6,7 @@
@echo off
setlocal EnableDelayedExpansion
set EXT=g1t
+set TST=.test
call build.cmd %EXT%
if %ERRORLEVEL% neq 0 goto err
@@ -38,11 +39,11 @@ for %%a in (%list%) do (
for %%a in (%list%) do (
echo | set /p PrintName=* %%a.%EXT%...
if exist %%a.%EXT% (
- gust_%EXT%.exe -y %%a.%EXT% >NUL 2>&1
+ gust_%EXT%.exe -y %%a.%EXT% >%TST% 2>&1
if !ERRORLEVEL! neq 0 goto err
- gust_%EXT%.exe -y %%a >NUL 2>&1
+ gust_%EXT%.exe -y %%a >%TST% 2>&1
if !ERRORLEVEL! neq 0 goto err
- fc /b %%a.%EXT% %%a.%EXT%.bak >NUL 2>&1
+ fc /b %%a.%EXT% %%a.%EXT%.bak >%TST% 2>&1
if !ERRORLEVEL! neq 0 goto err
echo [PASS]
) else (
@@ -55,8 +56,13 @@ goto out
:err
echo [FAIL]
+echo.
+echo ----------------------- FAILURE DATA -----------------------
+type %TST%
+echo ------------------------------------------------------------
:out
for %%a in (%list%) do (
if exist %%a.%EXT%.bak move /y %%a.%EXT%.bak %%a.%EXT% >NUL 2>&1
)
+del /q %TST% >NUL 2>&1
diff --git a/test_gmpk.cmd b/test_gmpk.cmd
index ec33411..6d523e4 100644
--- a/test_gmpk.cmd
+++ b/test_gmpk.cmd
@@ -6,10 +6,12 @@
@echo off
setlocal EnableDelayedExpansion
set EXT=gmpk
+set TST=.test
call build.cmd %EXT%
if %ERRORLEVEL% neq 0 goto err
set list=^
+ BOCHI_00^
G_HAK_A^
G_KAG_D^
H_KYO_A^
@@ -26,11 +28,11 @@ for %%a in (%list%) do (
for %%a in (%list%) do (
echo | set /p PrintName=* %%a.%EXT%...
if exist %%a.%EXT% (
- gust_%EXT%.exe -y %%a.%EXT% >NUL 2>&1
+ gust_%EXT%.exe -y %%a.%EXT% >%TST% 2>&1
if !ERRORLEVEL! neq 0 goto err
- gust_%EXT%.exe -y %%a >NUL 2>&1
+ gust_%EXT%.exe -y %%a >%TST% 2>&1
if !ERRORLEVEL! neq 0 goto err
- fc.exe /b %%a.%EXT% %%a.%EXT%.bak >NUL 2>&1
+ fc.exe /b %%a.%EXT% %%a.%EXT%.bak >%TST% 2>&1
if !ERRORLEVEL! neq 0 goto err
echo [PASS]
) else (
@@ -43,8 +45,13 @@ goto out
:err
echo [FAIL]
+echo.
+echo ----------------------- FAILURE DATA -----------------------
+type %TST%
+echo ------------------------------------------------------------
:out
for %%a in (%list%) do (
if exist %%a.%EXT%.bak move /y %%a.%EXT%.bak %%a.%EXT% >NUL 2>&1
)
+del /q %TST% >NUL 2>&1