FF7/Field

From Final Fantasy Inside
< FF7
Revision as of 22:37, 20 March 2005 by my_wiki>Synergy Blades (Field Overview)

Contents

Important Files

PSX Version PC Version
/FIELD/*.DAT /DATA/FIELD/FLEVEL.LGP
/FIELD/*.MIM /DATA/FIELD/CHAR.LGP
/FIELD/*.MIM /DATA/FIELD/CHAR.LGP
/FIELD/*.BSX  

Field Overview

The field module is the core of the game to which everything else is spawned. It is tied very closely with the kernel and contains many low-level calls to it. The field system also contains a self-contained bytecode language called commonly called "Field Script". The field module is responsible for the following:

  • The loading and parsing of the field files
  • The display of the 2D background ands related special effects
  • The display of 3D elements in the field such as the camera, perspective and and entities
  • The running of the Field Script to display events and to get user input
  • The on-demand loading of other modules when needed

The Field module loads modular "Field Files". In the PC version, the Field File is a single file with nine sections. In the PSX version, there are three files with the same name but with different extensions that do the same thing. The three files are MIM (Mutiple Image Maps, or the backgrounds), DAT (Field Script Data), and BSX (3D data).

 
Snapshot of the PSX's VRAM demonstrating the background field files in various stages of assembly.

The backgrounds are actually 16x16 blocks that are loaded into VRAM and then assembled into the video buffer every frame. The system allows for layers to obscure the 3D entities using a simple painter's algorithm.

In this particular field file, there are six cached sections of background data. Also notice the bright green patches that don't show up in in the video buffer. This was to show where a lower layer of 2D data was to be covered by a higher layer. The bright green is for debug purposes. During development, if any bright green showed up, it meant that your upper layer had a "hole" in it that a 3D entity could be seen through.

When the PSX version of FF7 is ran in higher resolutions via emulation with texture filtering on, often the lower layers will "bleed" outside the upper layer and make artifacts. This was also the reason why the field files were not re-rendered for the PC version of the game. It would of required "re-cutting" the layers again in the higher resolution.

Another last thing to note is in the middle of the bottom texture cache there are a sea of eyes. These blink at random times and reflect the random blinking of the characters in the game.


Field Format (PC)

General PC Field File Format

Field files are always found in FLEVEL.LGP. They are always LZS compressed.

The first two bytes of each (decompressed) field file are blank (zero). The next four bytes is an integer indicating how many sections are present in the file. Then a number of 4-byte integers follow, giving the starting offset for each section.

All field files should contain 9 sections; it's what FF7 expects.

PC Field File Header

Offset Size Description Section Data
0x00 2 bytes Blank Always 0x00
0x02 4 bytes Number of Sections Always 0x0009
0x06 4 bytes Pointer to Section 1 Field Script & Dialog
0x0A 4 bytes Pointer to Section 2 Camera Matrix
0x0E 4 bytes Pointer to Section 3 Unknown (Model Loader?)
0x12 4 bytes Pointer to Section 4 Palette
0x16 4 bytes Pointer to Section 5 Walkmesh
0x1A 4 bytes Pointer to Section 6 Unknown
0x1E 4 bytes Pointer to Section 7 Encounter
0x22 4 bytes Pointer to Section 8 Unknown
0x26 4 bytes Pointer to Section 9 Background
0x2A 4 bytes Where Pointer to Section 1 points to Length of Section 1
0x2E Varies Start of Section 1 data. Continues for the
number of bytes specified in Section Length
See links above

Each section generally starts with a four byte integer indicating the length of the section. You could just work this out by comparing offsets (how much space until the next section/end of file, etc) but FF7 stores the length at the start of the section anyway. After that the actual data follows. So the first bit of data for a section is actually 4 bytes after the point given in the section header (since the first four bytes are actually the length marker).

To examine each section, please navigate using the links in the table above.


Field Format (PSX)

PSX DAT Format

The PSX script is contained in the DAT file, it is compressed with LZS compression. After it's decompressed, here is the header format for that.

First, we have 28 unused bytes (in fact, they are used by the PSX, it's a list of 7 2-bytes values which refer to a place in the RAM). So each time you'll find a value which is an adress in the file, you'll have to add 28 to it in order to find the right position in the file (or else you can simply remove the first 28 bytes of the file).

Note: the first byte in the header is byte 0.

PSX MIM Format

PSX BCX Format

Event Scripting

Script commands

The event scripting language for FF7 has 246 commands that have a wide array of functions. For a complete listing of the commands, opcodes, arguments and descriptions, please refer to the opcodes section.

Movies

The 3D Overlay

Data Organization

"A" Field Animation Files for PC by Mirex

Each animation file holds one character animation ( run, walk or some other). Some characters have more animation files. Animation is set of frames, in each frame are stored bone rotations.

-- animation file contents --

Name Size in bytes
header 24
unknown 12
frames frames_count * frame

-- one frame, size is (bones * 12 + 24) --

unknown 24 bytes = 6 floats rotations bones * 12 bytes = bones * 3 floats

Name Size
unknown 24 = 6 floats
rotations bones * 12 bytes = bones * 3 floats

header structure, 24 bytes

struct {
    unsigned long x1;
    unsigned long frames_count;
    unsigned long bones_count;
    unsigned long x2, x3, x4;
} anim_head;

I understand only two values from the header, 'frames_count' which is number of animation frames and 'bones_count' which is suprisingly number of animated bones.

If you want to load all possible animations for the model (even animations of different models) then check if animation file has same number of bones as current model.

After header there is 12 bytes of data that are unknown to me. It could be some center of the coordinate system or anything.

Frame starts with 6 floats (unknown), followed by rotations for each bone. Rotations are stored as 3 floats (float is 4byte floating-point number).