Skip to main content

LuaObject

The Lua Object is a custom serialization format used by the game to store Lua objects. It is used in packets, blueprints and save files.

Structure

note

Parsing and building this structure requires the use of a BitStream. See BitStream for more information.

OffsetField NameField TypeNotes
0x00Magic TagConstant "LUA" (4c 55 41)This helps recognizing the start of the Lua object.
0x03Versionbe u32The version of the serialization format. This is currently 1.
0x07DataLuaSaveDataThe data that is serialized.

LuaSaveData

LuaSaveData Structure

OffsetField NameField TypeNotes
0x00Typeenum LuaSaveDataType : u8The type of data that is stored.
0x01ValueLuaSaveDataValueThe actual data that is stored. The type of this field depends on the Type field.

LuaSaveDataType enum

This enum is used to specify the type of data that is stored. This is an exhaustive list of all the types that can be serialized and deserialized.

TypeValue
Nil1
Boolean2
Number3
String4
Table5
Int326
Int167
Int88
Json9
Userdata100
Unknown_101101

LuaSaveDataValue

The LuaSaveDataValue field is used to store the actual data that is serialized. The type of this field depends on the Type field of the LuaSaveData structure.

Nil

The Nil type is used to represent a nil value in Lua. It does not have a value, as it is always nil. It is serialized as a byte array with a length of 0.

Field NameField TypeNotes
ValueConstant ""The nil value.

Boolean

The Boolean type is used to represent a boolean value in Lua. It is serialized as a single bit, where 0 is false and 1 is true.

Field NameField TypeNotes
ValueFlag (1 bit)The boolean value.
warning

The boolean type is serialized as a single bit, which means that the byte that contains the boolean value may contain other data as well. Any data after the boolean value is offset by 1 bit.

Number

The Number type is used to represent a number in Lua. It is serialized as a 32-bit floating point number in big-endian format. Note that precision may be lost when serializing and deserializing numbers. The game uses this type to represent floating point numbers, and integers that do not fit within the 32-bit signed integer range.

Field NameField TypeNotes
Valuebe floatThe number value.

String

The String type is used to represent a string in Lua. It is serialized as a length-prefixed, utf-8 encoded string. The length is a 32-bit unsigned integer in big-endian format, followed by the string data.

warning

The contents of the string must be aligned to a whole byte. If the length of the string data is not a multiple of 8 bits, padding is inserted between the length and the string data to align the string data to a whole byte.

Field NameField TypeNotes
Sizebe u32The amount of bytes required to store the utf-8 encoded string data.
PaddingPaddingPadding to align the string data to a whole byte.
Stringchar[Size]The string data, encoded in utf-8.

Table

The Table type is used to represent a table in Lua. It is serialized as a list of key-value pairs. The table can be either an array or a dictionary. The type of the table is determined by the Is Array field.

warning

The Is Array field is stored as a single bit. This means that the byte that contains the Is Array field may contain other data as well. Any data after the Is Array field is offset by 1 bit.

note

The Table type is a recursive structure, which means that tables can contain other tables.

Field NameField TypeNotes
Countbe u32The number of elements in the table.
Is ArrayFlag (1 bit)Whether the table is an array or a dictionary.

If Is Array is false (continued):

Field NameField TypeNotes
ElementsTableKeyValuePair[Count]The key-value pairs of the table.

If Is Array is true (continued):

Field NameField TypeNotes
Offsetbe u32The offset of the first element in the table.
ElementsLuaSaveData[Count]The elements of the table.

TableKeyValuePair

TableKeyValuePair Structure
Field NameField TypeNotes
KeyLuaSaveDataThe key of the pair.
ValueLuaSaveDataThe value of the pair.

Int32

The Int32 type is used to represent a 32-bit signed integer in Lua. It is serialized as a 32-bit signed integer in big-endian format. The game uses this type to represent integers that fit within the 32-bit signed integer range, but not within the 16-bit signed integer range.

Field NameField TypeNotes
Valuebe s32The integer value.

Int16

The Int16 type is used to represent a 16-bit signed integer in Lua. It is serialized as a 16-bit signed integer in big-endian format. The game uses this type to represent integers that fit within the 16-bit signed integer range, but not within the 8-bit signed integer range.

Field NameField TypeNotes
Valuebe s16The integer value.

Int8

The Int8 type is used to represent an 8-bit signed integer in Lua. It is serialized as an 8-bit signed integer.

Field NameField TypeNotes
Values8The integer value.

Json

The Json type has not been documented yet.

Userdata

The Userdata type is used to represent a userdata object in Lua. It is serialized as a LuaUserdata object.

Unknown_101

The Unknown_101 type has not been documented yet.

LuaUserdata

The LuaUserdata type is used to represent a userdata object in Lua. It is serialized as a type ID followed by the data of the userdata object. The type ID is used to determine the type of the userdata object, and the data is specific to the type of the userdata object.

Field NameField TypeNotes
Type IDenum UserdataTypeId : be u32The type ID of the userdata object.
DatadynamicThe data of the userdata object. The type of this field depends on the Type ID field.

UserdataTypeId enum

This enum is used to specify the type of the userdata object. This is an exhaustive list of all the types that can be serialized and deserialized.

TypeValueNotes
Uuid10001 Serializable.
Vec310003 Serializable.
Quat10004 Serializable.
Color10005 Serializable.
RaycastResult10006 Cannot be serialized at all.
LoadCellHandle10007 Unknown.
Effect10008 Cannot be serialized at all.
Shape10021 Serializable.
Body10022 Serializable.
Interactable10023 Serializable.
Container10024 Serializable.
Harvestable10025 Serializable.
Network10026 Cannot be serialized at all.
World10027 Serializable.
Unit10028:large_orange_square: Cannot be deserialized on the client, but can be serialized for sm.event.sendTo* and storing in sm.storage.
Storage10029 Cannot be serialized at all.
Player10030 Serializable.
Character10031 Serializable.
Joint10032 Serializable.
AiState10033 Cannot be serialized at all.
AreaTrigger10035 Cannot be serialized at all.
Portal10036:large_orange_square: Cannot be deserialized on the client, but can be serialized for sm.event.sendTo* and storing in sm.storage.
PathNode10037:large_orange_square: Cannot be deserialized on the client, but can be serialized for sm.event.sendTo* and storing in sm.storage.
Lift10038 Serializable.
ScriptableObject10039 Serializable.
BuilderGuide10040 Cannot be serialized at all.
CullSphereGroup10041 Cannot be serialized at all.
VoxelTerrain10042 Unknown.
Widget20001 Unknown.
Tool20002 Serializable.
GuiInterface20006 Cannot be serialized at all.
BlueprintVisualization20007 Cannot be serialized at all.

Uuid

Field NameField TypeNotes
Uuidle u128The UUID value.

Vec3

Field NameField TypeNotes
Xbe floatThe X component of the vector.
Ybe floatThe Y component of the vector.
Zbe floatThe Z component of the vector.

Quat

Field NameField TypeNotes
Xbe floatThe X component of the quaternion.
Ybe floatThe Y component of the quaternion.
Zbe floatThe Z component of the quaternion.
Wbe floatThe W component of the quaternion.

Color

Field NameField TypeNotes
Rbe floatThe red component of the color.
Gbe floatThe green component of the color.
Bbe floatThe blue component of the color.
Abe floatThe alpha component of the color.

Shape

Field NameField TypeNotes
Shape IDbe u32The ID of the shape.

Body

Field NameField TypeNotes
Body IDbe u32The ID of the body.

Interactable

Field NameField TypeNotes
Interactable IDbe u32The ID of the interactable.

Container

Field NameField TypeNotes
Container IDbe u32The ID of the container.

Harvestable

Field NameField TypeNotes
Harvestable IDbe u32The ID of the harvestable.

World

Field NameField TypeNotes
World IDbe u32The ID of the world.

Unit

Field NameField TypeNotes
Unit IDbe u32The ID of the unit.

Player

Field NameField TypeNotes
Player IDbe u32The ID of the player.

Character

Field NameField TypeNotes
Character IDbe u32The ID of the character.

Joint

Field NameField TypeNotes
Joint IDbe u32The ID of the joint.

Portal

Field NameField TypeNotes
Portal IDbe u32The ID of the portal.

PathNode

Field NameField TypeNotes
PathNode IDbe u32The ID of the path node.

Lift

Field NameField TypeNotes
Lift IDbe u32The ID of the lift.

ScriptableObject

Field NameField TypeNotes
Scriptable Object IDbe u32The ID of the scriptable object.

Tool

Field NameField TypeNotes
Tool IDbe u32The ID of the tool.