rbxfile

package module
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 5 Imported by: 28

README

GoDoc

rbxfile

The rbxfile package handles the decoding, encoding, and manipulation of Roblox instance data structures.

This package can be used to manipulate Roblox instance trees outside of the Roblox client. Such data structures begin with a Root struct. A Root contains a list of child Instances, which in turn contain more child Instances, and so on, forming a tree of Instances. These Instances can be accessed and manipulated using an API similar to that of Roblox.

Each Instance also has a set of "properties". Each property has a specific value of a certain type. Every available type implements the Value interface, and is prefixed with "Value".

Root structures can be decoded from and encoded to various formats, including Roblox's native file formats. The two sub-packages rbxl and rbxlx provide formats for Roblox's binary and XML formats. Root structures can also be encoded and decoded with the json package.

Besides decoding from a format, root structures can also be created manually. The best way to do this is through the declare sub-package, which provides an easy way to generate root structures.

The implementation of the binary file format is based largely on the RobloxFileSpec document, a reverse-engineered specification by Gregory Comer.

Other projects that involve decoding and encoding Roblox files:

Documentation

Overview

The rbxfile package handles the decoding, encoding, and manipulation of Roblox instance data structures.

This package can be used to manipulate Roblox instance trees outside of the Roblox client. Such data structures begin with a Root struct. A Root contains a list of child Instances, which in turn contain more child Instances, and so on, forming a tree of Instances. These Instances can be accessed and manipulated using an API similar to that of Roblox.

Each Instance also has a set of "properties". Each property has a specific value of a certain type. Every available type implements the Value interface, and is prefixed with "Value".

Root structures can be decoded from and encoded to various formats, including Roblox's native file formats. The two sub-packages "rbxl" and "rbxlx" provide formats for Roblox's binary and XML formats. Root structures can also be encoded and decoded with the "json" package.

Besides decoding from a format, root structures can also be created manually. The best way to do this is through the "declare" sub-package, which provides an easy way to generate root structures.

Index

Constants

View Source
const (
	FontStyleNormal = 0
	FontStyleItalic = 1
)
View Source
const (
	FontWeightThin       = 100
	FontWeightExtraLight = 200
	FontWeightLight      = 300
	FontWeightRegular    = 400
	FontWeightMedium     = 500
	FontWeightSemiBold   = 600
	FontWeightBold       = 700
	FontWeightExtraBold  = 800
	FontWeightHeavy      = 900
)

Variables

This section is empty.

Functions

func GenerateReference

func GenerateReference() string

GenerateReference generates a unique string that can be used as a reference to an Instance.

func IsEmptyReference

func IsEmptyReference(ref string) bool

IsEmptyReference returns whether a reference string is considered "empty", and therefore does not have a referent.

Types

type FontStyle added in v0.6.4

type FontStyle uint8

func FontStyleFromString added in v0.6.4

func FontStyleFromString(s string) (fs FontStyle, ok bool)

func (FontStyle) String added in v0.6.4

func (f FontStyle) String() string

type FontWeight added in v0.6.4

type FontWeight uint16

func FontWeightFromString added in v0.6.4

func FontWeightFromString(s string) (fs FontWeight, ok bool)

func (FontWeight) String added in v0.6.4

func (f FontWeight) String() string

type Instance

type Instance struct {
	// ClassName indicates the instance's type.
	ClassName string

	// Reference is a unique string used to refer to the instance from
	// elsewhere in the tree.
	Reference string

	// IsService indicates whether the instance should be treated as a
	// service.
	IsService bool

	// Properties is a map of properties of the instance. It maps the name of
	// the property to its current value.
	Properties map[string]Value

	// Children contains instances that are the children of the current
	// instance. The user must take care not to introduce circular references.
	Children []*Instance
}

Instance represents a single Roblox instance.

func NewInstance

func NewInstance(className string) *Instance

NewInstance creates a new Instance of a given class, and an optional parent.

func (*Instance) Copy added in v0.2.0

func (inst *Instance) Copy() *Instance

Copy returns a deep copy of the instance. Each property and all descendants are copied.

A copied reference within the tree is resolved so that it points to the corresponding copy of the original referent. Copied references that point to an instance which isn't being copied will still point to the same instance.

type PropRef

type PropRef struct {
	Instance  *Instance
	Property  string
	Reference string
}

PropRef specifies the property of an instance that is a reference, which is to be resolved into its referent at a later time.

type References

type References map[string]*Instance

References is a mapping of reference strings to Instances.

func (References) Get

func (refs References) Get(instance *Instance) (ref string)

Get gets a reference from an Instance, using References to check for duplicates. If the instance's reference already exists in References, then a new reference is generated and applied to the instance. The instance's reference is then added to References.

func (References) Resolve

func (refs References) Resolve(propRef PropRef) bool

Resolve resolves a PropRef and sets the value of the property using References. If the referent does not exist, and the reference is not empty, then false is returned. True is returned otherwise.

type Root

type Root struct {
	// Instances contains root instances contained in the tree.
	Instances []*Instance

	// Metadata contains metadata about the tree.
	Metadata map[string]string
}

Root represents the root of an instance tree. Root is not itself an instance, but a container for multiple root instances.

func NewRoot

func NewRoot() *Root

NewRoot returns a new initialized Root.

func (*Root) Copy

func (root *Root) Copy() *Root

Copy creates a copy of the root and its contents.

A copied reference within the tree is resolved so that it points to the corresponding copy of the original referent. Copied references that point to an instance which isn't being copied will still point to the same instance.

type Type

type Type byte

Type represents a Roblox type.

const (
	TypeInvalid Type = iota
	TypeString
	TypeBinaryString
	TypeProtectedString
	TypeContent
	TypeBool
	TypeInt
	TypeFloat
	TypeDouble
	TypeUDim
	TypeUDim2
	TypeRay
	TypeFaces
	TypeAxes
	TypeBrickColor
	TypeColor3
	TypeVector2
	TypeVector3
	TypeCFrame
	TypeToken
	TypeReference
	TypeVector3int16
	TypeVector2int16
	TypeNumberSequence
	TypeColorSequence
	TypeNumberRange
	TypeRect
	TypePhysicalProperties
	TypeColor3uint8
	TypeInt64
	TypeSharedString
	TypeOptional
	TypeUniqueId
	TypeFont
)

func TypeFromString

func TypeFromString(s string) Type

TypeFromString returns a Type from its string representation. TypeInvalid is returned if the string does not represent an existing Type.

func (Type) String

func (t Type) String() string

String returns a string representation of the type. If the type is not valid, then the returned value will be "Invalid".

type Value

type Value interface {
	// Type returns an identifier indicating the type.
	Type() Type

	// String returns a string representation of the current value.
	String() string

	// Copy returns a copy of the value, which can be safely modified.
	Copy() Value
}

Value holds a value of a particular Type.

func NewValue

func NewValue(typ Type) Value

NewValue returns new Value of the given Type. The initial value will not necessarily be the zero for the type. If the given type is invalid, then a nil value is returned.

type ValueAxes

type ValueAxes struct {
	X, Y, Z bool
}

func (ValueAxes) Copy

func (t ValueAxes) Copy() Value

func (ValueAxes) String

func (t ValueAxes) String() string

func (ValueAxes) Type

func (ValueAxes) Type() Type

type ValueBinaryString

type ValueBinaryString []byte

func (ValueBinaryString) Copy

func (t ValueBinaryString) Copy() Value

func (ValueBinaryString) String

func (t ValueBinaryString) String() string

func (ValueBinaryString) Type

func (ValueBinaryString) Type() Type

type ValueBool

type ValueBool bool

func (ValueBool) Copy

func (t ValueBool) Copy() Value

func (ValueBool) String

func (t ValueBool) String() string

func (ValueBool) Type

func (ValueBool) Type() Type

type ValueBrickColor

type ValueBrickColor uint32

func (ValueBrickColor) Copy

func (t ValueBrickColor) Copy() Value

func (ValueBrickColor) String

func (t ValueBrickColor) String() string

func (ValueBrickColor) Type

func (ValueBrickColor) Type() Type

type ValueCFrame

type ValueCFrame struct {
	Position ValueVector3
	Rotation [9]float32
}

func (ValueCFrame) Copy

func (t ValueCFrame) Copy() Value

func (ValueCFrame) String

func (t ValueCFrame) String() string

func (ValueCFrame) Type

func (ValueCFrame) Type() Type

type ValueColor3

type ValueColor3 struct {
	R, G, B float32
}

func (ValueColor3) Copy

func (t ValueColor3) Copy() Value

func (ValueColor3) String

func (t ValueColor3) String() string

func (ValueColor3) Type

func (ValueColor3) Type() Type

type ValueColor3uint8

type ValueColor3uint8 struct {
	R, G, B byte
}

func (ValueColor3uint8) Copy

func (t ValueColor3uint8) Copy() Value

func (ValueColor3uint8) String

func (t ValueColor3uint8) String() string

func (ValueColor3uint8) Type

func (ValueColor3uint8) Type() Type

type ValueColorSequence

type ValueColorSequence []ValueColorSequenceKeypoint

func (ValueColorSequence) Copy

func (t ValueColorSequence) Copy() Value

func (ValueColorSequence) String

func (t ValueColorSequence) String() string

func (ValueColorSequence) Type

func (ValueColorSequence) Type() Type

type ValueColorSequenceKeypoint

type ValueColorSequenceKeypoint struct {
	Time     float32
	Value    ValueColor3
	Envelope float32
}

func (ValueColorSequenceKeypoint) String

type ValueContent

type ValueContent []byte

func (ValueContent) Copy

func (t ValueContent) Copy() Value

func (ValueContent) String

func (t ValueContent) String() string

func (ValueContent) Type

func (ValueContent) Type() Type

type ValueDouble

type ValueDouble float64

func (ValueDouble) Copy

func (t ValueDouble) Copy() Value

func (ValueDouble) String

func (t ValueDouble) String() string

func (ValueDouble) Type

func (ValueDouble) Type() Type

type ValueFaces

type ValueFaces struct {
	Right, Top, Back, Left, Bottom, Front bool
}

func (ValueFaces) Copy

func (t ValueFaces) Copy() Value

func (ValueFaces) String

func (t ValueFaces) String() string

func (ValueFaces) Type

func (ValueFaces) Type() Type

type ValueFloat

type ValueFloat float32

func (ValueFloat) Copy

func (t ValueFloat) Copy() Value

func (ValueFloat) String

func (t ValueFloat) String() string

func (ValueFloat) Type

func (ValueFloat) Type() Type

type ValueFont added in v0.6.4

type ValueFont struct {
	Family       ValueContent
	Weight       FontWeight
	Style        FontStyle
	CachedFaceId ValueContent
}

func (ValueFont) Copy added in v0.6.4

func (t ValueFont) Copy() Value

func (ValueFont) String added in v0.6.4

func (v ValueFont) String() string

func (ValueFont) Type added in v0.6.4

func (ValueFont) Type() Type

type ValueInt

type ValueInt int32

func (ValueInt) Copy

func (t ValueInt) Copy() Value

func (ValueInt) String

func (t ValueInt) String() string

func (ValueInt) Type

func (ValueInt) Type() Type

type ValueInt64

type ValueInt64 int64

func (ValueInt64) Copy

func (t ValueInt64) Copy() Value

func (ValueInt64) String

func (t ValueInt64) String() string

func (ValueInt64) Type

func (ValueInt64) Type() Type

type ValueNumberRange

type ValueNumberRange struct {
	Min, Max float32
}

func (ValueNumberRange) Copy

func (t ValueNumberRange) Copy() Value

func (ValueNumberRange) String

func (t ValueNumberRange) String() string

func (ValueNumberRange) Type

func (ValueNumberRange) Type() Type

type ValueNumberSequence

type ValueNumberSequence []ValueNumberSequenceKeypoint

func (ValueNumberSequence) Copy

func (t ValueNumberSequence) Copy() Value

func (ValueNumberSequence) String

func (t ValueNumberSequence) String() string

func (ValueNumberSequence) Type

func (ValueNumberSequence) Type() Type

type ValueNumberSequenceKeypoint

type ValueNumberSequenceKeypoint struct {
	Time, Value, Envelope float32
}

func (ValueNumberSequenceKeypoint) String

type ValueOptional added in v0.4.0

type ValueOptional struct {
	// contains filtered or unexported fields
}

func None added in v0.4.0

func None(t Type) ValueOptional

None returns a ValueOptional with type t and no value.

func Some added in v0.4.0

func Some(value Value) ValueOptional

Some returns a ValueOptional with the given value and value's type.

func (ValueOptional) Copy added in v0.4.0

func (t ValueOptional) Copy() Value

func (*ValueOptional) None added in v0.4.0

func (v *ValueOptional) None(t Type) ValueOptional

None sets the option to have type t with no value.

func (*ValueOptional) Some added in v0.4.0

func (v *ValueOptional) Some(value Value) ValueOptional

Some sets the option to have the given value and value's type.

func (ValueOptional) String added in v0.4.0

func (t ValueOptional) String() string

func (ValueOptional) Type added in v0.4.0

func (ValueOptional) Type() Type

func (ValueOptional) Value added in v0.4.0

func (v ValueOptional) Value() Value

Value returns the value of the option, or nil if the option has no value.

func (ValueOptional) ValueType added in v0.4.0

func (v ValueOptional) ValueType() Type

ValueType returns the the value type of the option.

type ValuePhysicalProperties

type ValuePhysicalProperties struct {
	CustomPhysics    bool
	Density          float32
	Friction         float32
	Elasticity       float32
	FrictionWeight   float32
	ElasticityWeight float32
}

func (ValuePhysicalProperties) Copy

func (t ValuePhysicalProperties) Copy() Value

func (ValuePhysicalProperties) String

func (t ValuePhysicalProperties) String() string

func (ValuePhysicalProperties) Type

type ValueProtectedString

type ValueProtectedString []byte

func (ValueProtectedString) Copy

func (t ValueProtectedString) Copy() Value

func (ValueProtectedString) String

func (t ValueProtectedString) String() string

func (ValueProtectedString) Type

func (ValueProtectedString) Type() Type

type ValueRay

type ValueRay struct {
	Origin, Direction ValueVector3
}

func (ValueRay) Copy

func (t ValueRay) Copy() Value

func (ValueRay) String

func (t ValueRay) String() string

func (ValueRay) Type

func (ValueRay) Type() Type

type ValueRect added in v0.3.0

type ValueRect struct {
	Min, Max ValueVector2
}

func (ValueRect) Copy added in v0.3.0

func (t ValueRect) Copy() Value

func (ValueRect) String added in v0.3.0

func (t ValueRect) String() string

func (ValueRect) Type added in v0.3.0

func (ValueRect) Type() Type

type ValueReference

type ValueReference struct {
	*Instance
}

func (ValueReference) Copy

func (t ValueReference) Copy() Value

func (ValueReference) String

func (t ValueReference) String() string

func (ValueReference) Type

func (ValueReference) Type() Type

type ValueSharedString

type ValueSharedString []byte

func (ValueSharedString) Copy

func (t ValueSharedString) Copy() Value

func (ValueSharedString) String

func (t ValueSharedString) String() string

func (ValueSharedString) Type

func (ValueSharedString) Type() Type

type ValueString

type ValueString []byte

func (ValueString) Copy

func (t ValueString) Copy() Value

func (ValueString) String

func (t ValueString) String() string

func (ValueString) Type

func (ValueString) Type() Type

type ValueToken

type ValueToken uint32

func (ValueToken) Copy

func (t ValueToken) Copy() Value

func (ValueToken) String

func (t ValueToken) String() string

func (ValueToken) Type

func (ValueToken) Type() Type

type ValueUDim

type ValueUDim struct {
	Scale  float32
	Offset int32
}

func (ValueUDim) Copy

func (t ValueUDim) Copy() Value

func (ValueUDim) String

func (t ValueUDim) String() string

func (ValueUDim) Type

func (ValueUDim) Type() Type

type ValueUDim2

type ValueUDim2 struct {
	X, Y ValueUDim
}

func (ValueUDim2) Copy

func (t ValueUDim2) Copy() Value

func (ValueUDim2) String

func (t ValueUDim2) String() string

func (ValueUDim2) Type

func (ValueUDim2) Type() Type

type ValueUniqueId added in v0.5.0

type ValueUniqueId struct {
	// A pseudo-randomly generated value.
	Random int64
	// The number of seconds after 2021-01-01 00:00:00.
	Time uint32
	// A sequential value.
	Index uint32
}

ValueUniqueId represents the value of a unique identifier.

In Roblox's implementation, it would appear that there is a base value held in memory, which is updated by certain conditions, then copied to a new instance.

When a session starts, Random is initialized to a random value, apparently always positive. Time is initialized to the current time. Index seems to be initialized to 0x10000.

Index is incremented every time an instance is created. If Index rolls over back to 0, Random and Time are updated.

func (ValueUniqueId) Copy added in v0.5.0

func (t ValueUniqueId) Copy() Value

func (ValueUniqueId) String added in v0.5.0

func (v ValueUniqueId) String() string

func (ValueUniqueId) Type added in v0.5.0

func (ValueUniqueId) Type() Type

type ValueVector2

type ValueVector2 struct {
	X, Y float32
}

func (ValueVector2) Copy

func (t ValueVector2) Copy() Value

func (ValueVector2) String

func (t ValueVector2) String() string

func (ValueVector2) Type

func (ValueVector2) Type() Type

type ValueVector2int16

type ValueVector2int16 struct {
	X, Y int16
}

func (ValueVector2int16) Copy

func (t ValueVector2int16) Copy() Value

func (ValueVector2int16) String

func (t ValueVector2int16) String() string

func (ValueVector2int16) Type

func (ValueVector2int16) Type() Type

type ValueVector3

type ValueVector3 struct {
	X, Y, Z float32
}

func (ValueVector3) Copy

func (t ValueVector3) Copy() Value

func (ValueVector3) String

func (t ValueVector3) String() string

func (ValueVector3) Type

func (ValueVector3) Type() Type

type ValueVector3int16

type ValueVector3int16 struct {
	X, Y, Z int16
}

func (ValueVector3int16) Copy

func (t ValueVector3int16) Copy() Value

func (ValueVector3int16) String

func (t ValueVector3int16) String() string

func (ValueVector3int16) Type

func (ValueVector3int16) Type() Type

Directories

Path Synopsis
cmd
rbxfile-dcomp
The rbxfile-dcomp command rewrites a rbxl/rbxm file with decompressed chunks.
The rbxfile-dcomp command rewrites a rbxl/rbxm file with decompressed chunks.
rbxfile-dump
The rbxfile-dump command dumps the content of a rbxl/rbxm file.
The rbxfile-dump command dumps the content of a rbxl/rbxm file.
rbxfile-stat
The rbxfile-stat command displays stats for a roblox file.
The rbxfile-stat command displays stats for a roblox file.
The declare package is used to generate rbxfile structures in a declarative style.
The declare package is used to generate rbxfile structures in a declarative style.
The errors package provides additional error primitives.
The errors package provides additional error primitives.
The json package is used to encode and decode rbxfile objects to the JSON format.
The json package is used to encode and decode rbxfile objects to the JSON format.
Package rbxl implements a decoder and encoder for Roblox's binary file format.
Package rbxl implements a decoder and encoder for Roblox's binary file format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL