Skip to content

Commit

Permalink
implement file header removal arg
Browse files Browse the repository at this point in the history
  • Loading branch information
GeffDev committed Feb 24, 2024
1 parent 44b2619 commit b3edbb0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

FILE *data_packs[DATA_FILE_NUM] = {0};

bool remove_header = true;

i32 extractPacks() {
const u8 *file_name_base = "Pack/Data";

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions tools/decompress_gzip.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b3edbb0

Please sign in to comment.