rbxattr

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 4 Imported by: 1

README

Go Reference

rbxattr

The rbxattr package implements the serialized format of Roblox's instance attributes.

Specification

The spec.md file is a specification describing the structure of the attributes binary format.

Usage

Example using ReadFrom:

package main

import (
	"bytes"
	"encoding/base64"
	"fmt"
	"strings"

	"github.com/robloxapi/rbxattr"
)

func main() {
	var data = `AgAAAAQAAABTaXplCgAAAD9kAAAAAAAAP2QAAAAIAAAAUG9zaXRpb24KAACAPs7///8AAIA+zv///w==`
	r := base64.NewDecoder(base64.StdEncoding, strings.NewReader(data))

	var model rbxattr.Model
	n, _ := model.ReadFrom(r)
	fmt.Printf("Read %d bytes\n", n)

	var dict = make(map[string]rbxattr.Value, len(model.Value))
	for _, entry := range model.Value {
		if _, ok := dict[entry.Key]; !ok {
			dict[entry.Key] = entry.Value
		}
	}

	fmt.Println("Size.X.Scale:", dict["Size"].(*rbxattr.ValueUDim2).X.Scale)
	fmt.Println("Size.X.Offset:", dict["Size"].(*rbxattr.ValueUDim2).X.Offset)
	fmt.Println("Size.Y.Scale:", dict["Size"].(*rbxattr.ValueUDim2).Y.Scale)
	fmt.Println("Size.Y.Offset:", dict["Size"].(*rbxattr.ValueUDim2).Y.Offset)
	fmt.Println("Position.X.Scale:", dict["Position"].(*rbxattr.ValueUDim2).X.Scale)
	fmt.Println("Position.X.Offset:", dict["Position"].(*rbxattr.ValueUDim2).X.Offset)
	fmt.Println("Position.Y.Scale:", dict["Position"].(*rbxattr.ValueUDim2).Y.Scale)
	fmt.Println("Position.Y.Offset:", dict["Position"].(*rbxattr.ValueUDim2).Y.Offset)
	// Output:
	// Read 58 bytes
	// Size.X.Scale: 0.5
	// Size.X.Offset: 100
	// Size.Y.Scale: 0.5
	// Size.Y.Offset: 100
	// Position.X.Scale: 0.25
	// Position.X.Offset: -50
	// Position.Y.Scale: 0.25
	// Position.Y.Offset: -50
}

Example using WriteTo:

package main

import (
	"bytes"
	"encoding/base64"
	"fmt"

	"github.com/robloxapi/rbxattr"
)

func main() {
	model := rbxattr.Model{
		Value: rbxattr.ValueDictionary{
			{Key: "Size", Value: &rbxattr.ValueUDim2{
				X: rbxattr.ValueUDim{Scale: 0.5, Offset: 100},
				Y: rbxattr.ValueUDim{Scale: 0.5, Offset: 100},
			}},
			{Key: "Position", Value: &rbxattr.ValueUDim2{
				X: rbxattr.ValueUDim{Scale: 0.25, Offset: -50},
				Y: rbxattr.ValueUDim{Scale: 0.25, Offset: -50},
			}},
		},
	}

	var w bytes.Buffer
	bw := base64.NewEncoder(base64.StdEncoding, &w)
	n, _ := model.WriteTo(bw)
	fmt.Printf("Wrote %d bytes\n", n)
	bw.Close()
	fmt.Println(w.String())

	// Output:
	// Wrote 58 bytes
	// AgAAAAQAAABTaXplCgAAAD9kAAAAAAAAP2QAAAAIAAAAUG9zaXRpb24KAACAPs7///8AAIA+zv///w==
}

Documentation

Overview

The rbxattr package implements the serialized format of Roblox's instance attributes.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Key   string
	Value Value
}

type Model

type Model struct {
	Value ValueDictionary
}

Model is a low-level model of Roblox's instance attribute format.

func (*Model) ReadFrom

func (f *Model) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom decodes bytes from r, setting Value on success.

Example
package main

import (
	"encoding/base64"
	"fmt"
	"strings"

	"github.com/robloxapi/rbxattr"
)

func main() {
	var data = `AgAAAAQAAABTaXplCgAAAD9kAAAAAAAAP2QAAAAIAAAAUG9zaXRpb24KAACAPs7///8AAIA+zv///w==`
	r := base64.NewDecoder(base64.StdEncoding, strings.NewReader(data))

	var model rbxattr.Model
	n, _ := model.ReadFrom(r)
	fmt.Printf("Read %d bytes\n", n)

	var dict = make(map[string]rbxattr.Value, len(model.Value))
	for _, entry := range model.Value {
		if _, ok := dict[entry.Key]; !ok {
			dict[entry.Key] = entry.Value
		}
	}

	fmt.Println("Size.X.Scale:", dict["Size"].(*rbxattr.ValueUDim2).X.Scale)
	fmt.Println("Size.X.Offset:", dict["Size"].(*rbxattr.ValueUDim2).X.Offset)
	fmt.Println("Size.Y.Scale:", dict["Size"].(*rbxattr.ValueUDim2).Y.Scale)
	fmt.Println("Size.Y.Offset:", dict["Size"].(*rbxattr.ValueUDim2).Y.Offset)
	fmt.Println("Position.X.Scale:", dict["Position"].(*rbxattr.ValueUDim2).X.Scale)
	fmt.Println("Position.X.Offset:", dict["Position"].(*rbxattr.ValueUDim2).X.Offset)
	fmt.Println("Position.Y.Scale:", dict["Position"].(*rbxattr.ValueUDim2).Y.Scale)
	fmt.Println("Position.Y.Offset:", dict["Position"].(*rbxattr.ValueUDim2).Y.Offset)
}
Output:

Read 58 bytes
Size.X.Scale: 0.5
Size.X.Offset: 100
Size.Y.Scale: 0.5
Size.Y.Offset: 100
Position.X.Scale: 0.25
Position.X.Offset: -50
Position.Y.Scale: 0.25
Position.Y.Offset: -50

func (*Model) WriteTo

func (f *Model) WriteTo(w io.Writer) (n int64, err error)

WriteTo encodes Value into bytes written to w.

Example
package main

import (
	"bytes"
	"encoding/base64"
	"fmt"

	"github.com/robloxapi/rbxattr"
)

func main() {
	model := rbxattr.Model{
		Value: rbxattr.ValueDictionary{
			{Key: "Size", Value: &rbxattr.ValueUDim2{
				X: rbxattr.ValueUDim{Scale: 0.5, Offset: 100},
				Y: rbxattr.ValueUDim{Scale: 0.5, Offset: 100},
			}},
			{Key: "Position", Value: &rbxattr.ValueUDim2{
				X: rbxattr.ValueUDim{Scale: 0.25, Offset: -50},
				Y: rbxattr.ValueUDim{Scale: 0.25, Offset: -50},
			}},
		},
	}

	var w bytes.Buffer
	bw := base64.NewEncoder(base64.StdEncoding, &w)
	n, _ := model.WriteTo(bw)
	fmt.Printf("Wrote %d bytes\n", n)
	bw.Close()
	fmt.Println(w.String())

}
Output:

Wrote 58 bytes
AgAAAAQAAABTaXplCgAAAD9kAAAAAAAAP2QAAAAIAAAAUG9zaXRpb24KAACAPs7///8AAIA+zv///w==

type Type

type Type byte

Type identifies an attribute type within an encoding.

const (
	TypeString Type = 0x02
	TypeBool   Type = 0x03

	TypeFloat  Type = 0x05
	TypeDouble Type = 0x06

	TypeUDim  Type = 0x09
	TypeUDim2 Type = 0x0A

	TypeBrickColor Type = 0x0E
	TypeColor3     Type = 0x0F
	TypeVector2    Type = 0x10
	TypeVector3    Type = 0x11

	TypeCFrame Type = 0x14

	TypeNumberSequence Type = 0x17

	TypeColorSequence Type = 0x19

	TypeNumberRange Type = 0x1B
	TypeRect        Type = 0x1C
)

type Value

type Value interface {
	Type() Type
	ReadFrom(r io.Reader) (n int64, err error)
	WriteTo(w io.Writer) (n int64, err error)
}

Value is an attribute value that can be decoded from and encoded to bytes, with an identifying type.

func NewValue

func NewValue(typ Type) Value

NewValue returns a new Value of the given Type, or nil if the Type does not correspond to a known Value.

type ValueBool

type ValueBool bool

func (*ValueBool) ReadFrom

func (v *ValueBool) ReadFrom(r io.Reader) (n int64, err error)

func (ValueBool) Type

func (ValueBool) Type() Type

func (ValueBool) WriteTo

func (v ValueBool) WriteTo(w io.Writer) (n int64, err error)

type ValueBrickColor

type ValueBrickColor uint32

func (*ValueBrickColor) ReadFrom

func (v *ValueBrickColor) ReadFrom(r io.Reader) (n int64, err error)

func (ValueBrickColor) Type

func (ValueBrickColor) Type() Type

func (ValueBrickColor) WriteTo

func (v ValueBrickColor) WriteTo(w io.Writer) (n int64, err error)

type ValueCFrame added in v0.2.0

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

func (*ValueCFrame) ReadFrom added in v0.2.0

func (v *ValueCFrame) ReadFrom(r io.Reader) (n int64, err error)

func (ValueCFrame) Type added in v0.2.0

func (ValueCFrame) Type() Type

func (ValueCFrame) WriteTo added in v0.2.0

func (v ValueCFrame) WriteTo(w io.Writer) (n int64, err error)

type ValueColor3

type ValueColor3 struct {
	R float32
	G float32
	B float32
}

func (*ValueColor3) ReadFrom

func (v *ValueColor3) ReadFrom(r io.Reader) (n int64, err error)

func (ValueColor3) Type

func (ValueColor3) Type() Type

func (ValueColor3) WriteTo

func (v ValueColor3) WriteTo(w io.Writer) (n int64, err error)

type ValueColorSequence

type ValueColorSequence []ValueColorSequenceKeypoint

func (*ValueColorSequence) ReadFrom

func (v *ValueColorSequence) ReadFrom(r io.Reader) (n int64, err error)

func (ValueColorSequence) Type

func (ValueColorSequence) Type() Type

func (ValueColorSequence) WriteTo

func (v ValueColorSequence) WriteTo(w io.Writer) (n int64, err error)

type ValueColorSequenceKeypoint

type ValueColorSequenceKeypoint struct {
	Envelope float32
	Time     float32
	Value    ValueColor3
}

func (*ValueColorSequenceKeypoint) ReadFrom

func (v *ValueColorSequenceKeypoint) ReadFrom(r io.Reader) (n int64, err error)

func (ValueColorSequenceKeypoint) WriteTo

func (v ValueColorSequenceKeypoint) WriteTo(w io.Writer) (n int64, err error)

type ValueDictionary

type ValueDictionary []Entry

func (*ValueDictionary) ReadFrom

func (v *ValueDictionary) ReadFrom(r io.Reader) (n int64, err error)

func (ValueDictionary) WriteTo

func (v ValueDictionary) WriteTo(w io.Writer) (n int64, err error)

type ValueDouble

type ValueDouble float64

func (*ValueDouble) ReadFrom

func (v *ValueDouble) ReadFrom(r io.Reader) (n int64, err error)

func (ValueDouble) Type

func (ValueDouble) Type() Type

func (ValueDouble) WriteTo

func (v ValueDouble) WriteTo(w io.Writer) (n int64, err error)

type ValueFloat

type ValueFloat float32

func (*ValueFloat) ReadFrom

func (v *ValueFloat) ReadFrom(r io.Reader) (n int64, err error)

func (ValueFloat) Type

func (ValueFloat) Type() Type

func (ValueFloat) WriteTo

func (v ValueFloat) WriteTo(w io.Writer) (n int64, err error)

type ValueNumberRange

type ValueNumberRange struct {
	Min float32
	Max float32
}

func (*ValueNumberRange) ReadFrom

func (v *ValueNumberRange) ReadFrom(r io.Reader) (n int64, err error)

func (ValueNumberRange) Type

func (ValueNumberRange) Type() Type

func (ValueNumberRange) WriteTo

func (v ValueNumberRange) WriteTo(w io.Writer) (n int64, err error)

type ValueNumberSequence

type ValueNumberSequence []ValueNumberSequenceKeypoint

func (*ValueNumberSequence) ReadFrom

func (v *ValueNumberSequence) ReadFrom(r io.Reader) (n int64, err error)

func (ValueNumberSequence) Type

func (ValueNumberSequence) Type() Type

func (ValueNumberSequence) WriteTo

func (v ValueNumberSequence) WriteTo(w io.Writer) (n int64, err error)

type ValueNumberSequenceKeypoint

type ValueNumberSequenceKeypoint struct {
	Envelope float32
	Time     float32
	Value    float32
}

func (*ValueNumberSequenceKeypoint) ReadFrom

func (v *ValueNumberSequenceKeypoint) ReadFrom(r io.Reader) (n int64, err error)

func (ValueNumberSequenceKeypoint) WriteTo

func (v ValueNumberSequenceKeypoint) WriteTo(w io.Writer) (n int64, err error)

type ValueRect

type ValueRect struct {
	Min ValueVector2
	Max ValueVector2
}

func (*ValueRect) ReadFrom

func (v *ValueRect) ReadFrom(r io.Reader) (n int64, err error)

func (ValueRect) Type

func (ValueRect) Type() Type

func (ValueRect) WriteTo

func (v ValueRect) WriteTo(w io.Writer) (n int64, err error)

type ValueString

type ValueString string

func (*ValueString) ReadFrom

func (v *ValueString) ReadFrom(r io.Reader) (n int64, err error)

func (ValueString) Type

func (ValueString) Type() Type

func (ValueString) WriteTo

func (v ValueString) WriteTo(w io.Writer) (n int64, err error)

type ValueUDim

type ValueUDim struct {
	Scale  float32
	Offset int32
}

func (*ValueUDim) ReadFrom

func (v *ValueUDim) ReadFrom(r io.Reader) (n int64, err error)

func (ValueUDim) Type

func (ValueUDim) Type() Type

func (ValueUDim) WriteTo

func (v ValueUDim) WriteTo(w io.Writer) (n int64, err error)

type ValueUDim2

type ValueUDim2 struct {
	X ValueUDim
	Y ValueUDim
}

func (*ValueUDim2) ReadFrom

func (v *ValueUDim2) ReadFrom(r io.Reader) (n int64, err error)

func (ValueUDim2) Type

func (ValueUDim2) Type() Type

func (ValueUDim2) WriteTo

func (v ValueUDim2) WriteTo(w io.Writer) (n int64, err error)

type ValueVector2

type ValueVector2 struct {
	X float32
	Y float32
}

func (*ValueVector2) ReadFrom

func (v *ValueVector2) ReadFrom(r io.Reader) (n int64, err error)

func (ValueVector2) Type

func (ValueVector2) Type() Type

func (ValueVector2) WriteTo

func (v ValueVector2) WriteTo(w io.Writer) (n int64, err error)

type ValueVector3

type ValueVector3 struct {
	X float32
	Y float32
	Z float32
}

func (*ValueVector3) ReadFrom

func (v *ValueVector3) ReadFrom(r io.Reader) (n int64, err error)

func (ValueVector3) Type

func (ValueVector3) Type() Type

func (ValueVector3) WriteTo

func (v ValueVector3) WriteTo(w io.Writer) (n int64, err error)

Jump to

Keyboard shortcuts

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