From 6a3f19325555ed9596baa3963859f54ef856f11e Mon Sep 17 00:00:00 2001 From: Gskartwii Date: Thu, 27 Jun 2019 14:26:14 +0300 Subject: [PATCH] [datamodel/parser] Implement PathWaypoint and SharedString types SharedString type uses placeholder MD5 until I figure out what the MD5s refer to --- datamodel/CustomTypes.go | 46 ++++++++++++++++++++--------- peer/BitstreamPropertyTypes.go | 25 ++++++++++++++++ peer/NetworkSchema.go | 6 ++++ peer/WriteBitstreamPropertyTypes.go | 23 +++++++++++++++ 4 files changed, 86 insertions(+), 14 deletions(-) diff --git a/datamodel/CustomTypes.go b/datamodel/CustomTypes.go index fc47a9e..62a0b71 100644 --- a/datamodel/CustomTypes.go +++ b/datamodel/CustomTypes.go @@ -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{ @@ -59,6 +60,7 @@ var CustomTypeNames = map[rbxfile.Type]string{ TypeReference: "Reference", TypeToken: "Token", TypeVector3int32: "Vector3int32", + TypePathWaypoint: "PathWaypoint", } type ValueColorSequenceKeypoint rbxfile.ValueColorSequenceKeypoint @@ -82,6 +84,10 @@ type ValueReference struct { Reference Reference Instance *Instance } +type ValuePathWaypoint struct { + Position rbxfile.ValueVector3 + Action uint32 +} type ValueToken struct { ID uint16 @@ -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 +} diff --git a/peer/BitstreamPropertyTypes.go b/peer/BitstreamPropertyTypes.go index ff65b01..5b35ad2 100644 --- a/peer/BitstreamPropertyTypes.go +++ b/peer/BitstreamPropertyTypes.go @@ -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() @@ -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 } diff --git a/peer/NetworkSchema.go b/peer/NetworkSchema.go index eeae6ee..8d2dc9e 100644 --- a/peer/NetworkSchema.go +++ b/peer/NetworkSchema.go @@ -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 @@ -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 diff --git a/peer/WriteBitstreamPropertyTypes.go b/peer/WriteBitstreamPropertyTypes.go index cf7c9c4..e71746f 100644 --- a/peer/WriteBitstreamPropertyTypes.go +++ b/peer/WriteBitstreamPropertyTypes.go @@ -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) { @@ -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))) } @@ -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) }