From b3edbb099b6479fd53a8e61db059e9587006dc46 Mon Sep 17 00:00:00 2001 From: GeffDev Date: Sat, 24 Feb 2024 13:07:26 +0800 Subject: [PATCH] implement file header removal arg --- src/extract.c | 8 ++++++++ src/extract.h | 2 ++ src/main.c | 8 +++++++- tools/decompress_gzip.sh | 27 +++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tools/decompress_gzip.sh diff --git a/src/extract.c b/src/extract.c index 2f7e89c..b2498a9 100644 --- a/src/extract.c +++ b/src/extract.c @@ -3,6 +3,8 @@ FILE *data_packs[DATA_FILE_NUM] = {0}; +bool remove_header = true; + i32 extractPacks() { const u8 *file_name_base = "Pack/Data"; @@ -137,6 +139,12 @@ i32 extractPacks() { strcat(full_file_path, path); FILE *unpacked_file = fopen(full_file_path, "wb+"); + // TODO: some files are under 48 bytes? which is the size of the file header? + if (remove_header && size > 0x30) { + offset += 0x30; + size -= 0x30; + } + fseek(data_packs[pack], offset, SEEK_SET); u8 *file_buffer = malloc(size); diff --git a/src/extract.h b/src/extract.h index 65cf38a..17585a5 100644 --- a/src/extract.h +++ b/src/extract.h @@ -16,6 +16,8 @@ typedef struct { // TODO: don't hardcode the number of data packs extern FILE *data_packs[DATA_FILE_NUM]; +extern bool remove_header; + i32 extractPacks(); #endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index 6571ad5..9fcd84f 100644 --- a/src/main.c +++ b/src/main.c @@ -2,9 +2,15 @@ #include "extract.h" -i32 main() { +i32 main(i32 argc, u8 *argv[]) { printLog("pennyunpacker\n"); + for (i32 i = 0; i < argc; i++) { + if (strcmp(argv[i], "--rmheader") == 0) { + remove_header = true; + } + } + extractPacks(); return 0; diff --git a/tools/decompress_gzip.sh b/tools/decompress_gzip.sh new file mode 100644 index 0000000..2a5b355 --- /dev/null +++ b/tools/decompress_gzip.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +function decompress_if_gzipped() { + local file="$1" + local mime_type=$(file -b --mime-type "$file") + + if [ "$mime_type" == "application/gzip" ]; then + zcat "$file" > "${file%.gz}.pvr" + echo "Decompressed $file to ${file%.gz}.pvr" + fi +} + +function recursively_check_and_decompress() { + local directory="$1" + local filelist=$(find "$directory" -type f) + + for file in $filelist; do + decompress_if_gzipped "$file" + done +} + +for dir in Data{001..121}; do + if [ -d "$dir" ]; then + echo "processing dir: $dir" + recursively_check_and_decompress "$dir" + fi +done