Author Topic: Extracting Data from the PSX version of FF7  (Read 6528 times)

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Extracting Data from the PSX version of FF7
« on: 2004-06-18 02:51:04 »
Ok, to help unify the PC and PSX ports of FF7, there a little tutorial to help start data mining the PSX version. Let us start with the extraction of a texture.

Now I'm going to use the PC executable as a map, as I don't know exactly how the data is mapped in the PSX version. I'm also running Linux, so I have a few slick tools to help me.

Let us extract a texture, because that's the easiest. I have arbitrarily decided to extract from the PSX disk the blue bubble from the "aqua" enemy attack.

First I need to know where the texture is located. I start with the PC executable (There is a very good reason for this, I know we can just go into /magic/aqua.bin on the PSX CD-ROM but I want to show how you how the PC and the PSX formats link togeather.)

The first thing I do I look up the aqua attack in ff7.exe I have a command in Linux called "strings" that gets me pointed in the right direction.

Code: [Select]

>$ strings ff7.exe | less


This dumps all the readable text into a scrollable interface. I want to look for the aqua attack so I press the forward slash and put in "aqua" as my search string.

Code: [Select]

/aqua


The search will return with the following

Code: [Select]

...
goblinp1.spt
GOBLIN_2.TIM
goblinp2.spt
blue/goblinp
AQUA.TIM
AQUA.SPT
blue/aqua
MAGIKAL.TIM
MAGIKAL.SPT
blue/magikal
trainn_1.rsd
...


You can see the "blue/aqua" line. That's telling me that the aqua command is referenced in the /blue directory. I know that the "blue" dir is folded into the "magic" dir. Now I know what to look for in "magic/aqua.bin" on the PSX CD-ROM.

No you will notice that the actual files that make up aqua.bin are listed *BEFORE* the directory. This is not telling the order the data is in though, it's a refrence of what is in there.

Now, we are going  want to extract aqua.tim, which is the texture for the command. We do that by opening auqa.bin on the PSX disk and finding the TIM header.

ABOUT TIM HEADERS

A Texture In Memory (TIM)  is raw PSX video memory image with a few headers. The PSX did not have the ability to directly access it's VRAM and pushes everything through the GPU. TIMs are an easy way to upload a texture into VRAM with little hassle. The header format is as follows.

Here is a  4 bpp TIM header
  [1-4]   - 10 00 00 00: ID Tag for TIM Format
  [5-8]   - 08 00 00 00: ID Tag for 4BPP
 
Here is a  8 bpp TIM header
  [1-4]   - 10 00 00 00: ID Tag for TIM Format
  [5-8]   - 09 00 00 00: ID Tag for 8BPP

Here is a  16 bpp TIM header
  [1-4]   - 10 00 00 00: ID Tag for TIM Format
  [5-8]   - 02 00 00 00: ID Tag for 16BPP

Here is a  24 bpp TIM header
  [1-4]   - 10 00 00 00: ID Tag for TIM Format
  [5-8]   - 03 00 00 00: ID Tag for 24BPP


So now what we do is search for the TIM and extract it out of the bin file.

I'll so a search with the hex command first.

Code: [Select]

>$ hex aqua.bin | less


now I need to search for the TIM header sequence

Code: [Select]

/10 00 00 00


I wind up with this.

Code: [Select]

0720  10 00 00 00 09 00 00 00  0c 02 00 00 00 03 ff 00  ........ ........
0730  00 01 01 00 ff ff de ff  bc ff 9a ff 78 ff 56 ff  ........ ....x.V.


AHA! One 8 bpp texture at an offset of 0720

Now here's the sad thing that will probably be a let-down for everyone.

I don't know how to extract it properly...

I usally strip out all the data before the 10 00 00 00 header and use a TIM ripper to extract the file. I than can use the imagemagik to view it as it can read TIM files natively.
.
.
.
.
.
Wait for it....
.
.
.
.
.
Wait for it....
.
.
.
.
.



TAAAADAAAAA!~

Here are some exercises for the reader.

We know this bin has a TIM and a SPR file. Where is the SPR file? What's in it? What's in the leftover data? Is there leftover data? Where is the script? Where is the file table in the PSX version?

Well, that's it for now. Lemme know what you guys thought of this.

-halkun

Kislinskiy

  • Guest
Extracting Data from the PSX version of FF7
« Reply #1 on: 2004-06-18 07:38:47 »
If you need to know how to extract other textures that are compressed like the effect textures in ENEMY6/SEFFECT.LZS here is the original algorithm source code:

http://sprite.phys.ncku.edu.tw/NCKUtech/DCM/pub/DCM_CODE_ASM/lzss.c


You have to do a few slight modifications:

1. initialize text_buf with 0 instead of ' ' (space).

2. Begin decoding at LZS file offset 0x04 because LSZ files have stored the size of the decoded file as a UInt32 at offset 0x00 (do not forget to write the decoded file size in encoded LZS files before encoding the actual data).

Anakin

  • *
  • Posts: 42
    • View Profile
Extracting Data from the PSX version of FF7
« Reply #2 on: 2004-06-18 20:21:18 »
Hi, sorry if I'm boring you...
I compiled the lzss.c through Cygwin gcc (without changeing anything from the source code)
and with the executable that resulted I decompressed the ENEMY331.LZS (89KB) which produced a file 121KB
is this file actualy the unzipped format?
I mean I view the contents of this file with  Hex Workshop and I see ...code, are these the actual unzipped raw data?

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Extracting Data from the PSX version of FF7
« Reply #3 on: 2004-06-18 20:35:00 »
yea, it's an uncompressed bin archive

Anakin

  • *
  • Posts: 42
    • View Profile
Extracting Data from the PSX version of FF7
« Reply #4 on: 2004-06-18 22:33:28 »
thanks!
...now I have to browse the file with a TIM and a SPR reader
I guess...

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Extracting Data from the PSX version of FF7
« Reply #5 on: 2004-06-18 22:47:24 »
I'm going to be picking apart the sorce code for imagemagik to figure out the TIM format. I don't know what format a SPR is in. I hope that in taking apart an easy magic, the header will be a little more readable

Cyberman

  • *
  • Posts: 1572
    • View Profile
Extracting Data from the PSX version of FF7
« Reply #6 on: 2004-06-19 01:05:23 »
Quote from: halkun
I'm going to be picking apart the sorce code for imagemagik to figure out the TIM format. I don't know what format a SPR is in. I hope that in taking apart an easy magic, the header will be a little more readable


Places undecoded (or that haven't been understood and posted about).  Between Sectrion 0 (the actual model) and the Tim file no clue what those sections do yet, I believe they are battle animations and bone deformation information. Section 1  is most intriuging as it is always at least 412 bytes in size and only increases with the more sections in the file.  It has a regular pattern of numbers however I haven't made sense of them yet. Maybe now that I finally resolved Section 0 completely it will make more sense.

Cyb

Darkdevil

  • *
  • Posts: 728
    • View Profile
    • Http://darkdevil177.5u.com
Extracting Data from the PSX version of FF7
« Reply #7 on: 2004-06-19 08:49:30 »
Quote from: Cyberman
Section 1  is most intriuging as it is always at least 412 bytes in size and only increases with the more sections in the file.  It has a regular pattern of numbers however I haven't made sense of them yet.
Cyb



Could that possibly be the bone data then?  As not all of the skeletons have the same amount of bones....EG Naniki's bone formation and bone count will be different to Sephiroths....Just a thought..

Cyberman

  • *
  • Posts: 1572
    • View Profile
Extracting Data from the PSX version of FF7
« Reply #8 on: 2004-06-21 21:31:19 »
Quote from: Darkdevil

Could that possibly be the bone data then?  As not all of the skeletons have the same amount of bones....EG Naniki's bone formation and bone count will be different to Sephiroths....Just a thought..


No I was thinking more like it's the 'directory' or information about the information past section 1.  I think it indicates what files do what but I have yet to make true heads or tails of it. :)

Cyb