Engine:Entity Files

From Noita Wiki
Jump to navigation Jump to search

The entity files are used to store data about entities in the world and the components attached to them (see: [1](ECS)). These files can be found at save00/world/entities_NUM.bin. The number associated with a given chunk is given by (2000y+x) where x, y are the chunks x and y (floor of coordinates divided by 512). Note that as this mapping is not unique there may be multiple real chunks mapping to a single entity file

Format:

Using standard C type sizes (32 bit integer, 32 bit float, etc. )

Header:

Like most of Noita's binary files, this format is [2](FastLZ) compressed.

The first 4 bytes are a little endian integer representing the compressed file size, and the next 4 bytes are a little endian integer representing the decompressed file size.

The remaining data is FastLZ compressed, you can use the size values to call the decompressor with appropriately sized input and output buffers. All values in the decompressed file are big endian.

Once you have the decompressed data, the next 4 bytes are a value representing whether or not the hash is present (unknown purpose, format version maybe? - can be skipped while parsing). A value of 00 00 00 02 represents a present hash, and a value of 00 02 00 20 represents an absent hash.

A length encoded string is used here to mean a string with a 4 byte big endian integer with value N followed by an N ascii character ascii string (not null terminated).

The next entry is a length encoded string representing the hash of the schema used. The length is always 0x20 but is specified.

It is necessary to pass the schema xml file for later use (note this is nxml not xml and does not comply with the xml specification, either use an nxml parser or some simple string replacement of the invalid <> usage inside of strings with &lt; &gt; will work).

The next 4 bytes are an integer representing the number of entities without parents.

The next section of data is all the entities contained within the chunk and their children.

Entities:

An entity starts with a length encoded string representing the name of the entity. There is a null at the end of this string though this may be another field (possibly kill flag?).

Next is a length encoded string representing the file path of the entity.

Next is a length encoded string representing a csv of the tags of the entity.

The entities transform is represented next.

Next is a float (big endian, as are all data types in the compressed section) representing the x coordinate of the entity, note this is an absolute coordinate not relative to the chunk it belongs to.

Next is a float representing the y coordinate of the entity.

Next is a float representing the x scale of the entity.

Next is a float representing the y scale of the entity.

Next is a float representing the rotation of the entity (in radians).

Next is a integer representing the number of components on the entity.

Next are the Components of the entity, see components section.

Next is a 4 byte integer representing the number of children of the entity.

Components:

TODO!

Children:

TODO!