Author Topic: ff9.img directories and files  (Read 31089 times)

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Re: ff9.img directories and files
« Reply #25 on: 2006-06-05 22:03:14 »
You know, you should really start nameing these directories. It will make things a little more standard and easier to read.

I mean it can't be any different than FF7's

INIT
ENEMY
WM
MINI


Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: ff9.img directories and files
« Reply #26 on: 2006-06-06 05:16:17 »
You know, you should really start nameing these directories. It will make things a little more standard and easier to read.

I mean it can't be any different than FF7's

INIT
ENEMY
WM
MINI
It's a thought save for the fact the directories are offsets from a table.. and the files are offsets from a table. So there are no names readily available.  Also the index value cannot be directly associated to a name unless one memorizes what the index value of a name is.  My memory is crap of late, so I know I would constantly have to use a little sheet irreguardless of the names.
When we finish hashing out the information contained in each directory I suppose it would be more functional to do it that way. As yet we are acertaining what files are where and such.  It would be nice if the scripting were the similar to FF7 and FF8's format.

Cyb

Tonberry

  • *
  • Posts: 38
    • View Profile
Re: ff9.img directories and files
« Reply #27 on: 2006-06-07 02:01:07 »
I agree with both of you. :)

Naming dirs and files can help people understand where things are located and such, but as Cyberman pointed out it is too early to do that. I'd suggest to simply create tables mapping the numbers to a short description so people interested can use them and don't get lost. But I'll keep on using numbers until things are a little more clear. (Anyway I wouldn't mind explaining something without the numbers if necessary.)

I think the table Zande provided for the directories is a good start. Now that I can read some of the encoded text, I'm doing a similar table for files in DIR00 in my free time (not much).


For those interested in reading the encoded text I found, I'll post this table:

Code: [Select]
    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
 +---------------------------------------------------
0|  0  1  2  3  4  5  6  7  8  9  +  -  =  *  % SPC
1|  A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P
2|  Q  R  S  T  U  V  W  X  Y  Z  (  !  ?  "  :  .
3|  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p
4|  q  r  s  t  u  v  w  x  y  z  )  ,  /  º  ~  &
5| 
6|              á                       Ã­
7|  ó           Ãº
8|
9|
A|
B|     Â¿
C|
D|
E|
F|                       \n

SPC=SPACE (0x20)
\n=New line

It's not complete, as I've added only the bytes I verified, but it should be enough to read some text; especially the dialog, some debug messages, and the text from the menus.

The row number is the most significant nibble in a byte and the column number is the less significant nibble. You'll have to convert that byte to the character inside the cell in those coordinates.

It's not too difficult to get the position for other characters as they can be found in some of the TIM images of fonts.
I already know how to get the image for each individual character from the font image, but I haven't looked too much into it so I'll leave that for when I have more time.

If anyone feels like completing the table I won't mind. :D

A note: there are probably similar tables for other fonts.


Besides that, I have a description of what I know is inside of F<00>013. It's interesting as I was able to recognize most elements from the first half of the file, but I think I won't be able to know what's inside the other half just by looking at it.

File F<00>013 seems to be the "load/save game" menu. Just to give some bad news to Cyberman ;D, I wasn't able to find a header nicelly describing the components, plus I think it's the same thing for all DIR00 files. My only hope is that those elements are pointed to from a script.

I won't give the offsets of my version, as they'll surelly be different for the English version; or any other language for that matter.

Code: [Select]
(4 bytes) File identifier? (=0x00000014)
(4 bytes) Unknown (=0x00003030)
(8 bytes) String "/DISCO" padded with 0x00. (Translation: "DISK")
(4 bytes) Unknown (0x00)
(2 bytes) Unknown (0x7e)
(2 bytes) Unknown (0xe0)
(4 bytes) Number of pointers to strings that follow. (=0x3a)
Pointer to string:
  (2 bytes) Number of bytes (relative to offset of first pointer) till the first char of the string.
  (2 bytes) Unknown. (Attributes of string?)
... (Repeat for every pointer.)
Encoded string. (Variable length.)
... (Repeat for every string.)
(256 bytes)  CLUT for Zidane. (entries=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of Zidane's face. (width=32, height=46, size=1472 bytes)
(256 bytes)  CLUT for Vivi. (entries=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of Vivi's face. (width=32, height=46, size=1472 bytes)
(256 bytes)  CLUT for Garnet. (entries=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of Garnet's face. (width=32, height=46, size=1472 bytes)
(256 bytes)  CLUT for ***. (entries=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of ***'s face. (width=32, height=46, size=1472 bytes)
(256 bytes)  CLUT for Steiner. (entries=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of Steiner's face. (width=32, height=46, size=1472 bytes)
(256 bytes)  CLUT for Quina. (entires=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of Quina's face. (width=32, height=46, size=1472 bytes)
(256 bytes)  CLUT for Eiko. (entries=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of Eiko's face. (width=32, height=46, size=1472 bytes)
(256 bytes)  CLUT for Freya. (entries=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of Freya's face. (width=32, heigth=46, size=1472 bytes)
(256 bytes)  CLUT for Amarant. (entires=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of Amarant's face. (width=32, height=46, size=1472 bytes)
(256 bytes)  CLUT for Marcus. (entires=128, 16bpp, size=256 bytes)
(1472 bytes) Picture of Marcus' face. (entries=128, 16bpp, size=1472 bytes)
(512 bytes)  CLUT for "passing pages of a book". (entries=256, 16bpp, size=512 bytes)
(5808 bytes) Picture of "passign pages of a book". (width=176, height=33, size=5808 bytes)
... (Rest is unknown at the moment and is barelly half the file.)

The *** above means I don't remember the name of the protagonist, but if I'm not wrong it's Dagger. I really don't remember if Garnet changed names and the picture of her face changed in the menus as well.

The "passing pages of a book" is, as I mentioned before, the animation of the book that appears when the game is opening a memory card.

After that image I don't know what's in there. That may be a good place to look for some script or compiled code but I don't know machine code nor assembly for the psx and neither do I know ff7 nor ff8 scripting language. So, if anyone could look a little bit into it, please... :)

It's quite homogeneous and if it was a 8086 architecture I'd go for code, but I might as well be completelly wrong.

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: ff9.img directories and files
« Reply #28 on: 2006-06-07 19:01:30 »
It's not bad news that's good news. I suspected DIR00 of being odd.  I believe this to be splash screens and menu things for the game now. (MENU? :D)
In summary things are potentially better because of this.
Hmmm I believe there is a font that looks similiar to your matrix coding for text.. I'll have to nose around for it.

The game has a script somewhere, but where is the question, finding the script data is likely going to be troublesome I suspect.

It may be in DIR02 but not with the text... only time will tell.

Erstwhile I am looking at cooling my hard disk and trying to get the data off of it (or at least Hoping too).

Cyb

Tonberry

  • *
  • Posts: 38
    • View Profile
Re: ff9.img directories and files
« Reply #29 on: 2006-06-07 23:14:38 »
Quote
It's not bad news that's good news. I suspected DIR00 of being odd.  I believe this to be splash screens and menu things for the game now. (MENU?)

I was just kidding about the bad news, but I'd prefer headers in the files. I agree with the MENU designation but there can be some exception to it.

Quote
It may be in DIR02 but not with the text... only time will tell.

All the files in DIR02 have this structure:

Code: [Select]
(4 bytes) DB structure with one sub-element. (Always DB 01 00 00)
(3 bytes) Pointer to first (and only) sub-element in DB struct. (Always 0x04)
(1 byte)  Type of sub-element. (Always 0x06. Text array?)
First sub-element:
  (4 bytes) Unknown. (Always 06 01 00 00)
  (4 bytes) Unknown. It's incremented by 1 or more units with each file.
  (4 bytes) Unknown. (Always 08 00 00 00)
  (4 bytes) Pointer to first byte after last string. (Pointer to slack space.)
  (4 bytes) Number of string pointers.
  Pointer to first string:
    (2 bytes) Number of bytes (relative to offset of first pointer) till the first char of the string.
    (2 bytes) Unknown. (Attributes of string?)
  ... (Repeat for every pointer.)
  First encoded string. (Variable length, ends in 0xFF.)
  ... (Repeat for every string.)
(0x00 padded to complete last sector.)

As you can see they are quite simple. Every file is "text oriented" (meaning they define arrays of strings and not much more.) As I said before, the only relation to a script can be defined in the attributes or by some special character inside the strings, but there aren't many examples where that's possible; and there is no chance to find a complex script there.


---------------------------------------------

Mmmmmm.... Just a correction, as I messed up a bit with the description of F<00>013 (save/load menu). I said I couldn't recognize the second half of the file and thought it could be code, but from a comment by halkun I realized I was missing something. I opened a memory card image and found the first 256 unknown bytes into it. (So much for code.  :oops:)
« Last Edit: 2006-06-09 02:49:13 by Tonberry »

Tonberry

  • *
  • Posts: 38
    • View Profile
Re: ff9.img directories and files
« Reply #30 on: 2006-06-11 07:25:03 »
I think I found assembler code in F<00>013 (load/save game menu), and I mean "valid" assembler code; but it would be great if someone with experience on the psx could tell me if I'm making any mistakes.

I made some quick routines to disassemble the portions of F<00>013 that I couldn't classify and I found something like this at the very begining:

Code: [Select]
* ADDIU  $sp, $sp, 65504
  ...
  JR     $ra
  ADDIU  $sp, $sp, 32
* ADDIU  $sp, $sp, 65496
  ...
  JR     $ra
  ADDIU  $sp, $sp, 40
* ADDIU  $sp, $sp, 65512
  ...
  JR     $ra
  ADDIU  $sp, $sp, 24
* ADDIU  $sp, $sp, 65488
  ...
  JR     $ra
  ADDIU  $sp, $sp, 48
* ADDIU  $sp, $sp, 65464
  ...
  JR     $ra
  ADDIU  $sp, $sp, 72
* ADDIU  $sp, $sp, 65472
  ...
  JR     $ra
  ADDIU  $sp, $sp, 64
* ADDIU  $sp, $sp, 65448
...

etc.

Now, if I'm not mistaken, those should be typical entry/exit points for functions, as the instructions marked with an asterisk reserve certain amount of memory on the stack and the one after the "JR $ra" frees the same amount of memory.

I tried with other files from DIR00 and got similar results.

scmark15

  • *
  • Posts: 9
    • View Profile
Re: ff9.img directories and files
« Reply #31 on: 2008-01-18 19:04:35 »
I was bored and decided to play with Tile Molester, I found the Change Disc Images & Game over screen...
*Note: I used Zidane_2's ff9_extractor and db_extract programs to tear apart my ff9.img...

Quote
I redownload img and db extractors to:
http://zidane_games.webhost.ru/FF9_TOOLS.rar

And upload new version of the "battle scene viewer":
http://zidane_games.webhost.ru/New_viewer.rar

In new version i fix old bug with textures ))

Archive contain old and new versions and 2 files for example.

Code: [Select]
Dir 01 file 2 (Standard 16bpp TIM File):
Game Over Screen
Height: 224px
Width: 320px

Code: [Select]
Dir 01 files 7-10:
Change Disc 1-4
...after a little cut and paste...
Height: 224px
Width: 320px
...One thing I noticed is that the right half is missing 19 (8x8pixel) tiles from the bottom right of all of them...


*Edit .... Searched through the original ff9.img file (too big to open with tile molester) using my hex editor and
cut out about 1400 bytes and pasted it at the end of the 7th file in the 01 directory saved it as a new file and
tried to view it again and the missing tiles are there now. I have no idea why it got cut off, maybe a problem with
Zande_2's ff9_extractor, I don't know C++ so I can't tell ^_^ (my original ripped 7th file is 143, 360 bytes).



Best viewed settings for change disc images...
Codec: 16bpp ABGR (1555) *Corrected*
Mode: 2-Dimensional
Zoom: 100%
Width: 20 (8x8 pixel) tiles
Height: ?????? (don't feel like counting)

The image will be cut in half with the right half of the image below the left half.

I know a little hex but I really gotta learn Visual C++ so I write my own custom TIM/file viewers.
Any recommendations on books/commented source (I like the cut, delete, paste method of learning also) that would help, I'd greatly appreciate it!

Thanks,
scmark15
« Last Edit: 2008-01-21 13:34:49 by scmark15 »

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: ff9.img directories and files
« Reply #32 on: 2008-01-20 14:19:33 »
I'm afraid not much source code exists for TIM file reading.
I have header information for the file type however.
I believe the TIM images on FF9's change disk screens are 320x224.
Since most of the TIM images that are directly readable are 16bit (this includes background images). They are very easy to decode, save the back ground images although 16 bit TIM's include palettes. I suspect they did this to make things easier programming wise.

Code: [Select]
#define  _PSX_STRUCT_H_
//typedef  long           INT32;
//typedef  unsigned long  UINT32;
typedef  short int      INT16;
typedef  unsigned short UINT16;
typedef  char           INT8;
typedef  unsigned char  UINT8;

typedef struct
{
   UINT32   Magic;
   UINT32   Type;
} base_tim_hdr;

typedef struct
{
   UINT32   WCount;
   UINT16   IMGX, IMGY; // origin of image
   UINT16   Pitch;   // in 16 bit words per horizontal line
   UINT16   Height;  // number of lines;
} base_tim_img;

typedef  struct
{
   base_tim_hdr   INFO;
   UINT32   Bytes;
   UINT16   PALX, PALY;
   UINT16   ZZ01;
   UINT16   CLUT_CNT;
} tim_4bpp;

typedef  struct
{
   base_tim_hdr   INFO;
   UINT32   Bytes;
   UINT16   PALX, PALY;
   UINT16   ZZ01;
   UINT16   CLUT_CNT;
} tim_8bpp;

typedef  struct
{
   base_tim_hdr   INFO;
   base_tim_img   IMAGEDAT;
}  tim_16bpp;

typedef  struct
{
   base_tim_hdr   INFO;
   base_tim_img   IMAGEDAT;
}  tim_24bpp;

#define  TIM_4BPP    8
#define  TIM_8BPP    9
#define  TIM_16BPP   2
#define  TIM_24BPP   3
#define  TIM_MAGIC   0x10

// Pallette/Color Look Up Tables for TIM files
typedef  UINT16 CLUT_4bpp[16];
typedef  UINT16 CLUT_8bpp[256];
The code I have simply will not work for whatever you are using it for (It is VCL specific).
The best method is to convert the BGR16 (note it IS 16 bit data not 15 bit don't forget this EVER as that could really mess things up if you do).
The data in all tim's other than 24bpp is 16 bit WORD sized ALWAYS and more importantly it is NOT BGR15 data EVER. I repeat it WILL be a big mistake if you assume that.  Why? Bit 16 is the ALPHA bit or mask bit.  IF it is set be VERY wary of the data that's associated with it.  It can indicate any of 4 modes of transparency and this IS used in FF9 background data. FF9's background data is 16 bit TIM information, however they use a custom method to decode the data in the TIM (IE it's internally not 16bit data :D). 
My suggestion is start with the data you have the header information I've included should be enough to get you started and look at the wiki for further details on TIM images.

scmark15

  • *
  • Posts: 9
    • View Profile
Re: ff9.img directories and files
« Reply #33 on: 2008-01-21 13:31:50 »
Thanks Cyb!

I was just messing around with Tile Molester and found them accidently, they weren't found
with any TIM viewer/scanner (Yuri 0.99e, Tim Viewer, PSXMC, etc...) that I had.

I realized that they were actually 16bpp after when I viewed them the second time after reading
qhimms wiki on TIM files with the extra 1400 (approx) bytes pasted at the end (to see if the
missing tiles would appear). I just found them by accident with the 15bpp BGR (555) codec setting
first, they display the same (or there is an un-noticable difference). In Tile Molester they are not
colored correctly  at 16bpp BGRA (5551) or any other display codec but at 16bpp ABGR (1555)....
I'm not including the 15bpp (555) setting ^_^.

Just thought that others may wish to view them ^_^.

---------------------------------------------------------------------------------------------------------------------------------------

I have Visual Studio (6 & 2008 .Net) as well as Borlands C++ & Delphi (My old mans a
programer/systems analyst). I have very little programming experience (I know HTML, PHP and a
little hex) but want to learn C++, I've played with MS Visual C# .Net and Visual Basic as well as
Borlands Delphi but have no idea where to start with C++, like should I start with Borland C++ or
MS Visual C++, what is the difference. Any recommendations on language and/or books for
beginners would be greatly appreciated.

!!Thanks again!!,
scmark15

---------------------------------------------------------------------------------------------------------------------------------------
PS Cyb,

Thanks for the code! I'll save it for later.

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: ff9.img directories and files
« Reply #34 on: 2008-01-21 21:39:04 »
A few Things VCL (BC++) makes things very easy. However MS created C# to countermand this concept (IE that coding for there SDK is a pain in the arse).  It's now 6 of this half dozen of the other.  It may or may not be easier.  the important thing is to use what you have examples of that you can make work.  BCB was what worked for me.  (It really is Rapid Application Development) If your father (petrarch), can help you with it that's even better. 

I used VCL because I have little patients to build wheels over and over again (VC++). C# is a bit easier ... a bit. It does have a large learning curve. Also it is not C++.  My opinion on it aside, it is what it is.  Don't be worried I guess I'm getting old and inflexible :D

Anyhow try one thing and stick with it, don't use Visual Basic.. too many limitations, it's for business oriented applications not something that would require some pretty precarious methods of getting at data.  C++ or C# is a better bet.

Cyb

scmark15

  • *
  • Posts: 9
    • View Profile
Re: ff9.img directories and files
« Reply #35 on: 2008-01-22 14:44:31 »
Thanks Cyb! I picked up some books that my father recommended, he also recommended some webpages that show examples and source. Unfortunently though he's grown accustomed to working with Microsoft Products (the company he works for has deals with microsoft, one of the CEO works for MS also) but he told me to start with Borland C++ and then give Visual C++ a try a little later down the road, and he also recommended a while back to learn C# (that's why I dabbled with it).

Anyways...Time to crack open some books

Thanks again Cyb!
Scmark15


Zidane_2

  • *
  • Posts: 28
    • View Profile
Re: ff9.img directories and files
« Reply #36 on: 2008-02-10 15:20:44 »
Some info:

Dir 0:
File "1" - Field Module
File "2" - Battle Module
File "3" - WORLDMAP Module
File "4" - TetraMaster module
File "5" - ???? module.
File "6" - ???? module.
File "9" - ???? module.
File "14" - ???? module.
« Last Edit: 2008-02-12 08:21:00 by Zidane_2 »