Author Topic: [FF7 PSX] What should be removed after recompressing the BATTLE.X file?  (Read 847 times)

Raziel80

  • *
  • Posts: 119
    • View Profile
When I use gzip to recompress (BATTLE.X) file after editing, it turns out 7 bytes larger than the original file and that's after I reinsert the 8 byte header. What bytes need to be removed after recompressing the BATTLE.X file? (FF7 PSX PAL English SCES-00867)
SymphoniC said that this is because: "compression utilities by default add a time stamp when compressing"
Quote
I guess most compression utilities by default add in the filename and a time stamp when compressing and stuff like that.

It looks like something has been added to the beginning of the file.

original BATTLE.X looks like this: (first 0x28 bytes for comparison)
Code: [Select]
Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

00000000   C0 38 05 00 D8 41 07 00  1F 8B 08 00 00 00 00 00   А8  ШA   ‹     
00000010   00 00 C4 BD 0D 7C 5C 55  99 3F FE CC 9D 9B 64 92     ДЅ |\U™?юМќ›d’
00000020   A6 ED 4D 3A 2D 53 A8 74                            ¦нM:-SЁt

after recompressing and reinserting the 8 byte header BATTLE.X looks like this
Code: [Select]
Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

00000000   C0 38 05 00 D8 41 07 00  1F 8B 08 08 9B 11 A9 60   А8  ШA   ‹  › ©`
00000010   00 03 42 41 54 54 4C 45  00 C4 BD 0D 7C 5C 55 99     BATTLE ДЅ |\U™
00000020   3F FE CC 9D 9B 64 92 A6                            ?юМќ›d’¦

So, I deleted in the edited BATTLE.X 7 bytes: 03 42 41 54 54 4C 45 at offset 0x11. (this means the word BATTLE, the gzip tool may have added the filename)
Then I changed 1F 8B 08 08 9B 11 A9 60 from offset 0x08 to 1F 8B 08 00 00 00 00 00. (don’t know, because there’s something wrong with that)
Did I do everything right?

Additional question. What tools are exist for working with BIN, BIN-GZIP, LZS archives, to decompress/recompress?
« Last Edit: 2021-05-24 03:24:29 by Raziel80 »

MysticLord

  • *
  • Posts: 79
    • View Profile
https://github.com/cebix/ff7tools
^Tools for working with FF7 archives, though you'll need to understand how to use the command prompt and how to install the dependencies (Python 2.7 and a couple other things).

Raziel80

  • *
  • Posts: 119
    • View Profile
https://github.com/cebix/ff7tools
^Tools for working with FF7 archives, though you'll need to understand how to use the command prompt and how to install the dependencies (Python 2.7 and a couple other things).
I installed Python 2.7.16, launched Command Prompt (launched cmd.exe on win xp 32 bit) and went to the folder where BATTLE.X is located along the path F: \ games \ FF7 \ zQhimm-FF7 \ ff7tools-master \ ff7.
What to do next? Need step by step instructions.
Do I need to do the following steps as in the post below?
Quote
The X format is a simple gzip file containing overlay code and with an 8 byte header. The first 4 bytes are used for decompression size, the last 4 indicate the decompression size+bss segment (which is an area used for zero-initialized values, so it's just a bunch of zeroes). Cut those 8 bytes, rename .x to .gz and decompress. When recompressing add again those 8 bytes using identical values and it will work.
« Last Edit: 2021-05-25 22:44:50 by Raziel80 »

MysticLord

  • *
  • Posts: 79
    • View Profile
I assume so. Make sure you back up your files.

Ask NFITC1 if you run into problems.

Raziel80

  • *
  • Posts: 119
    • View Profile
Answers to my questions.
To decompress files with https://github.com/cebix/ff7tools need to enter command in the command prompt: python unbingz KERNEL.BIN.
But these tools work with KERNEL.BIN file, they don't work with BATTLE.gz file. I do not see a tool or command that can recompress the KERNEL.BIN back.

ff7_gzip tools can decompress/recompress BATTLE.gz file. Command to decompress BATTLE.gz: gunzip BATTLE.gz. Command to recompress BATTLE file: gzip BATTLE or gzip -n BATTLE.
The -n switch stops gzip inserting the file's name and compression timestamp into the archive.

vayneruel

  • *
  • Posts: 160
    • View Profile
Have you renamed BATTLE.X to BATTLE.gz, Raziel?

Raziel80

  • *
  • Posts: 119
    • View Profile
Have you renamed BATTLE.X to BATTLE.gz, Raziel?
Yes, I did what I wanted with ff7_gzip (FF7Dec + gzip) tools.
Information for modifying FF7 PSX files: http://forums.qhimm.com/index.php?topic=15074.0 ,
http://forums.qhimm.com/index.php?topic=12174.msg168727#msg168727
« Last Edit: 2021-05-30 03:04:07 by Raziel80 »

MysticLord

  • *
  • Posts: 79
    • View Profile
It might be useful for someone to upload the decompressed version of the file, so you can compress it and see how it corresponds to the file you're working with.

Bosola

  • Fire hazard!
  • *
  • Posts: 1748
    • View Profile
    • My YouTube Channel
It's been a long time since I worked on the BATTLE.X file. However, I did find the following README I wrote to myself, in a file from 2014. It was for running an assembler patch for long range enemy attacks:

Quote
Here's the procedure:

- unpack the BATTLE.X by removing the initial eight header bytes (copy them somewhere)
- decompress the file as a gzip archive
- run the ASM file (enemy_long_range_attacks_asm.txt) through ARMIPS
- recompress with gzip (using the Cygwin version of gzip with the flags -9 -n will work best)
- re-add the initial header bytes
- reinsert your BATTLE.X file using whatever means you like

Raziel80

  • *
  • Posts: 119
    • View Profile
Here's the procedure:

- unpack the BATTLE.X by removing the initial eight header bytes (copy them somewhere)
- decompress the file as a gzip archive
- run the ASM file (enemy_long_range_attacks_asm.txt) through ARMIPS
- recompress with gzip (using the Cygwin version of gzip with the flags -9 -n will work best)
- re-add the initial header bytes
- reinsert your BATTLE.X file using whatever means you like
Where can I download this Cygwin version of gzip?

MysticLord

  • *
  • Posts: 79
    • View Profile
It's a chore, unfortunately.

You have to install Cygwin, and at some point in the installation there will be an option to install a bunch of programs with it. Select gzip there.

https://www.cygwin.com/install.html

If you want to update it and install more programs, run the installer again.

Cygwin is a bunch of linux apps ported to windows, complete with it's own terminal to run them from.

Raziel80

  • *
  • Posts: 119
    • View Profile
Thanks for the tips.