Data Structures

This page describes the internal data structures that are used by Essentials as defined by RPG Maker XP or RGSS. This information can be useful when this raw data is needed for scanning, aggregating, or otherwise. Each section will contain the filename of the data file the data is stored in if applicable, followed by the class name(s) and all its attributes and properties.

Loading these data files is trivial. RGSS and mkxp provide the load\_data method, which reads and serializes the referenced file, or pulls it from the encrypted archive if it exists. For loading files, load\_data(filename) is equivalent to:

```
File.open(filename, 'rb') { |f| Marshal.load(f) }

```

For this deserialization (Marshal.load) to work though, the classes that it is to deserialize must be defined. That is to say, you cannot load Map data if the RPG::Map class (and all dependent types further in its data structure) are not defined.

Furthermore, only **serializable** data structures can be written-to and read-from files. An object is said to be serializable if it can be converted to a string, and back to the original class again without loss of data (at least for properly implemented \_load and \_dump methods). You cannot call Marshal.load or Marshal.dump on non-serializable objects.

## RPG

### Map

Map data notably does not store the name of the map. This can be found in the corresponding MapInfo.

#### Event

RPG::Event attributes, part of RPG::Map
 @name
 @x
 @y
 @pages

### Event Command

RPG::EventCommand attributes, part of RPG::Event::Page
 @indent
 @parameters

### Moveroute

RPG::MoveRoute attributes, part of RPG::Event
 @skippable
 @list

### Move Command

RPG::MoveCommand attributes, part of RPG::MoveRoute
 @parameters

### Audio File

RPG::AudioFile attributes
 @volume
 @pitch

### Common Event

RPG::CommonEvent, stored as an array of objects in CommonEvents.rxdata
 @name
 @switch\_id
 @list

### Map Info

RPG::MapInfo, stored as a hash<map\_id, map\_info> in MapInfos.rxdata
 @parent\_id
 @order
 @expanded
 @scroll\_x
 @scroll\_y

There are several more classes defined by RPG Maker XP in the RPG module, such as those for Animation and System, but finding the data structures for these files is left as an exercise for the reader.

## Other Data Structures

### Scripts

RPG Maker XP stores script files in a rather different way than the RPG classes we've seen above. It stores scripts in the **Scripts.rxdata** file as an array of scripts. Each element of this array corresponds with a script, and the format of such a script element is the following:

```
[magic\_number, script\_name, code]

```
Where **magic\_number** is an arbitrary integer (this appears to be unused by RPG Maker XP itself, and its value does not affect the way the program behaves), **script\_name** is a string representing the name of the script, and **code** is the compressed script itself.
Conversion of the compressed script to a decompressed, readable version is trivial, and shown below is also how to compress it back again.

```
decompressed\_code = Zlib::Inflate.inflate(code)
# And to compress it again:
compressed\_code = Zlib::Deflate.deflate(decompressed\_code)
compressed\_code == code #=> true

```
Please note that decompressed\_code must be a UTF-8 string. You may run into errors when attempting to run a poorly encoded/decoded script.
In short, serializing the content of **Scripts.rxdata** will yield a structure that looks something like this:

```
[
 [mn1, name1, code1],
 [mn2, name2, code2],
 [mn3, name3, code3],
 ...
]

```
The format for **PluginScripts.rxdata** is identical to that of **Scripts.rxdata** (which means you could rename PluginScripts to Scripts if you wanted to inspect its contents within RPG Maker XP's script editor).

### Table

The Table class in RGSS is simply one big array of predetermined size (expressed in 3 dimensions) to simulate a 3D array, but supposedly (or at the time) with better performance. It has **size**, **xsize**, **ysize**, and **zsize** attributes for finding the respective sizes, and its elements can be accessed via **table[x, y, z]**. More documentation on the Table class can be found in RGSS's Reference Manual.

As a sidenote for those interested in the serialization process of the Table class, when a Table is deserialized into a string, it is deserialized as **[zsize, xsize, ysize, zsize, size, \*data].pack("LLLLLS\*")**. Similarly, when serializing, it performs **xsize, ysize, zsize, size, data = string.unpack("LLLLLS\*")[1..-1]** internally, or something that closely resembles it. This bigger array (with its length equal to size+5) is only used internally for serialization, and thus does not affect the indices x, y, or z of the Table itself.

### Color & Tone

RGSS's Color and Tone objects represent color and tone respectively, and they both contain the **red**, **green**, and **blue** components. Furthermore, Color also contains an **alpha** value, whereas Tone contains a **gray** value.

As a sidenote for those interested in the serialization process of the Color and Tone classes, they are deserialized as **[red, green, blue, alpha\_or\_gray].pack("E4")** and serialized as **red, green, blue, alpha\_or\_grey = string.unpack("E4")** or something that closely resembles it.