Skip to content

Commit

Permalink
[datamodel/parser] Implement PathWaypoint and SharedString types
Browse files Browse the repository at this point in the history
SharedString type uses placeholder MD5 until I figure out what the MD5s refer to
  • Loading branch information
Gskartwii committed Jun 27, 2019
1 parent a22a5e9 commit 6a3f193
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 14 deletions.
46 changes: 32 additions & 14 deletions datamodel/CustomTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@ func (ref Reference) String() string {
}

const (
TypeNumberSequenceKeypoint rbxfile.Type = rbxfile.TypeInt64 + 1 + iota
TypeColorSequenceKeypoint = rbxfile.TypeInt64 + 1 + iota
TypeNumberSequence = rbxfile.TypeInt64 + 1 + iota
TypeColorSequence = rbxfile.TypeInt64 + 1 + iota
TypeSystemAddress = rbxfile.TypeInt64 + 1 + iota
TypeMap = rbxfile.TypeInt64 + 1 + iota
TypeDictionary = rbxfile.TypeInt64 + 1 + iota
TypeArray = rbxfile.TypeInt64 + 1 + iota
TypeTuple = rbxfile.TypeInt64 + 1 + iota
TypeRegion3 = rbxfile.TypeInt64 + 1 + iota
TypeRegion3int16 = rbxfile.TypeInt64 + 1 + iota
TypeReference = rbxfile.TypeInt64 + 1 + iota
TypeToken = rbxfile.TypeInt64 + 1 + iota
TypeNumberSequenceKeypoint rbxfile.Type = rbxfile.TypeSharedString + 1 + iota
TypeColorSequenceKeypoint = rbxfile.TypeSharedString + 1 + iota
TypeNumberSequence = rbxfile.TypeSharedString + 1 + iota
TypeColorSequence = rbxfile.TypeSharedString + 1 + iota
TypeSystemAddress = rbxfile.TypeSharedString + 1 + iota
TypeMap = rbxfile.TypeSharedString + 1 + iota
TypeDictionary = rbxfile.TypeSharedString + 1 + iota
TypeArray = rbxfile.TypeSharedString + 1 + iota
TypeTuple = rbxfile.TypeSharedString + 1 + iota
TypeRegion3 = rbxfile.TypeSharedString + 1 + iota
TypeRegion3int16 = rbxfile.TypeSharedString + 1 + iota
TypeReference = rbxfile.TypeSharedString + 1 + iota
TypeToken = rbxfile.TypeSharedString + 1 + iota
// used for terrain
TypeVector3int32 = rbxfile.TypeInt64 + 1 + iota
TypeVector3int32 = rbxfile.TypeSharedString + 1 + iota
TypePathWaypoint = rbxfile.TypeSharedString + 1 + iota
)

var CustomTypeNames = map[rbxfile.Type]string{
Expand All @@ -59,6 +60,7 @@ var CustomTypeNames = map[rbxfile.Type]string{
TypeReference: "Reference",
TypeToken: "Token",
TypeVector3int32: "Vector3int32",
TypePathWaypoint: "PathWaypoint",
}

type ValueColorSequenceKeypoint rbxfile.ValueColorSequenceKeypoint
Expand All @@ -82,6 +84,10 @@ type ValueReference struct {
Reference Reference
Instance *Instance
}
type ValuePathWaypoint struct {
Position rbxfile.ValueVector3
Action uint32
}

type ValueToken struct {
ID uint16
Expand Down Expand Up @@ -302,3 +308,15 @@ func (x ValueVector3int32) Copy() rbxfile.Value {
func (x ValueVector3int32) String() string {
return fmt.Sprintf("%d, %d, %d", x.X, x.Y, x.Z)
}

func (x ValuePathWaypoint) Type() rbxfile.Type {
return TypePathWaypoint
}

func (x ValuePathWaypoint) String() string {
return fmt.Sprintf("%s, action %d", x.Position, x.Action)
}

func (x ValuePathWaypoint) Copy() rbxfile.Value {
return x
}
25 changes: 25 additions & 0 deletions peer/BitstreamPropertyTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,27 @@ func (b *extendedReader) readInt64() (rbxfile.ValueInt64, error) {
return rbxfile.ValueInt64(val), err
}

func (b *extendedReader) readPathWaypoint() (datamodel.ValuePathWaypoint, error) {
var val datamodel.ValuePathWaypoint
var err error
val.Position, err = b.readVector3Simple()
if err != nil {
return val, err
}

val.Action, err = b.readUint32BE()
return val, err
}

func (b *extendedReader) readSharedString() (rbxfile.ValueSharedString, error) {
md5, err := b.readASCII(0x10)
if err != nil {
return rbxfile.ValueSharedString{}, err
}
println("FIXME: read sharedstring (ignored) md5=", md5)
return rbxfile.ValueSharedString{}, nil
}

func (b *extendedReader) readPhysicsVelocity() (rbxfile.ValueVector3, error) {
var val rbxfile.ValueVector3
flags, err := b.readUint8()
Expand Down Expand Up @@ -1232,6 +1253,10 @@ func (b *extendedReader) readSerializedValueGeneric(reader PacketReader, valueTy
result, err = b.readRegion3int16()
case PropertyTypeInt64:
result, err = b.readInt64()
case PropertyTypePathWaypoint:
result, err = b.readPathWaypoint()
case PropertyTypeSharedString:
result, err = b.readSharedString()
}
return result, err
}
6 changes: 6 additions & 0 deletions peer/NetworkSchema.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ const (
PropertyTypeRegion3int16 = iota
// PropertyTypeInt64 is the type for 64-bit signed integer values
PropertyTypeInt64 = iota
// PropertyTypePathWaypoint is the type for path waypoints
PropertyTypePathWaypoint = iota
// PropertyTypeSharedString is the type for shared strings
PropertyTypeSharedString = iota
)

// TypeNames is a list of names for value types
Expand Down Expand Up @@ -143,6 +147,8 @@ var TypeNames = map[uint8]string{
PropertyTypeRect2D: "Rect2D",
PropertyTypePhysicalProperties: "PhysicalProperties",
PropertyTypeInt64: "sint64",
PropertyTypePathWaypoint: "PathWaypoint",
PropertyTypeSharedString: "SharedString",
}

// NetworkArgumentSchema describes the schema of one event argument
Expand Down
23 changes: 23 additions & 0 deletions peer/WriteBitstreamPropertyTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ var typeToNetworkConvTable = map[rbxfile.Type]uint8{
datamodel.TypeArray: PropertyTypeArray,
datamodel.TypeTuple: PropertyTypeTuple,
rbxfile.TypeInt64: PropertyTypeInt64,
datamodel.TypePathWaypoint: PropertyTypePathWaypoint,
rbxfile.TypeSharedString: PropertyTypeSharedString,
}

func typeToNetwork(val rbxfile.Value) (uint8, bool) {
Expand Down Expand Up @@ -433,6 +435,10 @@ func (b *extendedWriter) writeSerializedValueGeneric(val rbxfile.Value, valueTyp
err = b.writeVarsint64(int64(val.(rbxfile.ValueInt64)))
case PropertyTypeStringNoCache:
err = b.writePStringNoCache(val.(rbxfile.ValueString))
case PropertyTypePathWaypoint:
err = b.writePathWaypoint(val.(datamodel.ValuePathWaypoint))
case PropertyTypeSharedString:
err = b.writeSharedString(val.(rbxfile.ValueSharedString))
default:
return errors.New("Unsupported property type: " + strconv.Itoa(int(valueType)))
}
Expand Down Expand Up @@ -632,6 +638,23 @@ func (b *extendedWriter) writePhysicalProperties(val rbxfile.ValuePhysicalProper
return err
}

func (b *extendedWriter) writePathWaypoint(val datamodel.ValuePathWaypoint) error {
err := b.writeVector3Simple(val.Position)
if err != nil {
return err
}
return b.writeUint32BE(val.Action)
}

func (b *extendedWriter) writeSharedString(val rbxfile.ValueSharedString) error {
err := b.writeASCII("0123456789abcdef")
if err != nil {
return err
}
println("FIXME: wrote sharedstring (placeholder)")
return nil
}

func (b *extendedWriter) writeCoordsMode0(val rbxfile.ValueVector3) error {
return b.writeVector3Simple(val)
}
Expand Down

0 comments on commit 6a3f193

Please sign in to comment.