RPG format: Difference between revisions
(one more WIP tag I missed) |
No edit summary |
||
Line 1: | Line 1: | ||
darracnonoel | |||
==RPG file format (also known as data mismanagement 101)== | ==RPG file format (also known as data mismanagement 101)== | ||
Revision as of 22:40, 9 October 2007
darracnonoel
RPG file format (also known as data mismanagement 101)
The RPG file format is the format used by the OHRRPGCE to store games. This page is intended as a reference for people who want to write utilities to manipulate or convert RPG files, for those working with the source code, and for those who just wish to poke and prod their data. This file is also an interesting case study in bad data structuring, and should provide a wealth of cautionary examples of what not to do. It tracks my progress from "not having a clue how to manage data" to "knowing how to manage data but being unable to do it right because of backwards compatibility" and finally to "not caring one way or the other".
Lump Format
An RPG file is made of many files lumped together. These files are referred to as "lumps".
An RPG file starts with a null-terminated filename. The filename is a DOS short filename, not a Windows long filename. It should never include path information. If it does, the file has been tampered with (very old implementations of the RPG format did support directory paths, both relative and absolute. This would have made it possible for an RPG file to overwrite critical system files in other directories-- luckily, I found this flaw before anyone else did, so it was never exploited :)
Anyway. Null-terminated filename. 4 bytes of size information, then the data, repeat:
Data | Meaning |
---|---|
(characters) | Filename |
BYTE | always 0-- it terminates the filename |
LONG | size, in PDP-endian format, [high-byte, highest byte, lowest byte, low byte] |
Assumptions to make
Unless otherwise noted, numbers are stored in sane-right-thinking-normal-moral-christian-good-to-their-mothers byte ordering of
0,1 A,B low byte, high byte
Unless otherwise noted, 16 and 32-bit numbers are signed, as the goodly creators of QuickBasic decided that nobody would ever really need an unsigned value for anything. (the same people, if I recall correctly who decided that 640k of RAM would be all anyone ever needed)
Assumptions not to make
Even though lump names are usually UPPERCASE, dont assume they have to be. Lump names are case insensitive.
Even though lumps may appear to come in a specific predefined order in the RPG file, don't assume they will always come in that order. The lumping code puts ARCHINYM.LMP first to improve browsing speed, but that's not written in stone.
Lump naming rules
Lump names vary depending on the file name of the RPG file. It was moronic of me to design in that way, but I didn't know any better at the time, and I have to maintain backwards compatibility with my past screwups.
eg. If the filename of the RPG file is WANDER.RPG it will contain many lumps named WANDER.???
In an attempt to fix this silliness without breaking backwards compatibility, I added a new all-important lump. ARCHINYM.LMP
ARCHINYM.LMP Is a text file, which contains the Internal name used by all of the flexible-named lumps in the file. Then it has a CR/LF pair, and a string that tells the version number of CUSTOM.EXE that the file was created with (or the version of RPGFIX that first added the ARCHINYM.LMP)
So. Read the first line of ARCHINYM.LMP to get the correct prefix of most of the other lumps.
If ARCHINYM.LMP does not exist, you know you are dealing with an obsolete file, and you can assume that the variable-named lumps will use the RPG filename as a prefix.
Three other lumps have arbitrary fixed names. BROWSE.TXT and PLOTSCR.LST. and DEFPASS.BIN. Any new lumps I add in the future are likely to also have arbitrary names.
List of Lumps
WARNING: The documentation on any page in the "Unfinished Articles" category might be not just incomplete, but down-right WRONG. Any other page may still contain errors or be out-of-date.
ARCHINYM.LMP Internal game name BROWSE.TXT Long game title and description BINSIZE.BIN Binary record lengths for newer binary lumps PLOTSCR.LST Plotscript names and ID numbers DEFPASS.BIN Default passability for tilesets ATTACK.BIN More attack data, in additon to DT6 SONGDATA.BIN Song data, currently just the name of each SFXDATA.BIN Ditto, but for sound effects FIXBITS.BIN Bitsets that indicate whether format fixes have been applied LOOKUP##.BIN Script trigger table for trigger type ## PALETTES.BIN The 256-colour palettes lump GEN General misc data and record-counts .## .1 .2 .3 and so on, up to .99 are BAM songs. .T## / ##.T tilemap for map ## (See Map Format) .P## / ##.P passability (wallmap) for map ## .E## / ##.E enemy positions (foemap) for map ## .D## / ##.D door links for map ## .L## / ##.L NPC locations for map ## .N## / ##.N NPC definitions for map ## DOR Obsolete door locations. Feel free to delete it from your RPG DOX Real door locations DT0 Hero Data DT1 Enemy Data DT6 Attack Data EFS Enemy formation sets FOR Enemy formations FNT Font HSP Plotscripts HSX / HSZ Single Plotscript (Found lumped inside the HSP lump) ITM Item data MAP General Map data MAS Master palette MN Map names MXS Backdrops and backgrounds PAL 16-color palettes PT0 Hero pictures PT1 Small Enemy Graphics PT2 Medium Enemy Graphics PT3 Large Enemy Graphics PT4 Walkabout Graphics PT5 Weapon Graphics PT6 Attack Graphics DEFPAL#.BIN Default palettes SAY Text boxes SHO Shop definitions SNG Obsolete music name list STF Shop stuff STT Global Text Strings TAP Tile animation patterns TIL Maptile sets TMN Tag names VEH Vehicle definitions
Map Format Describes what lumps you need to load a map.