Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- FF7 .bin packer/unpacker
- Developed by Xeeynamo
- The extracted files are GZip deflate files. To recompress them with a format
- that the game accepts, compress them back to .gz format, remove the header (it
- usually finish with the name of the file with NULL terminating character) and
- replace it with the original header used from the game: 1F8B 0800 0000 0000 0003
- I tried this on ./INIT/WINDOW.BIN, but I'm sure that it works also for
- KERNEL.BIN, SCENE.BIN etc.
- */
- #include <stdio.h>
- #define MODE_REPACK
- size_t CalcFileSize(FILE* f)
- {
- size_t prevPos = ftell(f);
- size_t fileSize;
- fseek(f, 0, SEEK_END);
- fileSize = ftell(f);
- fseek(f, prevPos, SEEK_SET);
- return fileSize;
- }
- int FileToMemory(const char* filename, void** memory, size_t* size)
- {
- FILE* f = fopen(filename, "r+b");
- if (f == NULL) return 0;
- *memory = malloc( *size = CalcFileSize(f) );
- fread(*memory, *size, 1, f);
- fclose(f);
- return 1;
- }
- int main()
- {
- typedef struct
- {
- unsigned short compressedSize;
- unsigned short uncompressedSize;
- unsigned short fileType;
- } Header;
- int i;
- char tmpStr[0x100];
- Header* header[256];
- FILE* fOut;
- size_t fileSize;
- FILE* fGz;
- size_t fileGzSize;
- void* data;
- void* datagz;
- if (FileToMemory("WINDOW.BIN", &data, &fileSize) == 0)
- return -1;
- #ifdef MODE_REPACK
- fOut = fopen("WINDOW.BIN", "w+b");
- #endif // MODE_REPACK
- // Parse data
- header[0] = (Header*)data;
- for(i = 0; header[i]->compressedSize != 0; i++)
- {
- header[i + 1] = (char*)header[i] +
- header[i]->compressedSize + sizeof(Header);
- sprintf(tmpStr, "WINDOW_%i.BIN.GZ", i);
- #ifdef MODE_REPACK
- if (FileToMemory(tmpStr, &datagz, &fileGzSize))
- {
- header[i]->compressedSize = fileGzSize;
- fwrite(header[i], sizeof(Header), 1, fOut);
- fwrite(datagz, fileGzSize, 1, fOut);
- free(datagz);
- }
- #else
- fGz = fopen(tmpStr, "w+b");
- fwrite(((char*)header[i]) + sizeof(Header),
- header[i]->compressedSize, 1, fGz);
- fclose(fGz);
- #endif // MODE_REPACK
- }
- #ifdef MODE_REPACK
- short empty = 0;
- fwrite(&empty, 2, 1, fOut);
- fclose(fOut);
- #endif // MODE_REPACK
- free(data);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement