From ca90ebdfa8789654766c5d7969baa7afacd9ebd2 Mon Sep 17 00:00:00 2001 From: BanceDev Date: Mon, 16 Feb 2026 16:31:54 -0500 Subject: initial commit --- packet/command/playerinfo/playerinfo.go | 337 ++++++++++++++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100644 packet/command/playerinfo/playerinfo.go (limited to 'packet/command/playerinfo/playerinfo.go') diff --git a/packet/command/playerinfo/playerinfo.go b/packet/command/playerinfo/playerinfo.go new file mode 100644 index 0000000..962101b --- /dev/null +++ b/packet/command/playerinfo/playerinfo.go @@ -0,0 +1,337 @@ +package playerinfo + +import ( + "github.com/osm/quake/common/buffer" + "github.com/osm/quake/common/context" + "github.com/osm/quake/packet/command/deltausercommand" + "github.com/osm/quake/protocol" + "github.com/osm/quake/protocol/fte" + "github.com/osm/quake/protocol/mvd" +) + +const fteExtensions uint32 = fte.ExtensionHullSize | + fte.ExtensionTrans | + fte.ExtensionScale | + fte.ExtensionFatness + +type Command struct { + IsMVD bool + + Index byte + Default *CommandDefault + MVD *CommandMVD +} + +type CommandDefault struct { + CoordSize uint8 + MVDProtocolExtension uint32 + FTEProtocolExtension uint32 + + Bits uint16 + ExtraBits byte + Coord [3]float32 + Frame byte + Msec byte + DeltaUserCommand *deltausercommand.Command + Velocity [3]uint16 + ModelIndex byte + SkinNum byte + Effects byte + WeaponFrame byte +} + +type CommandMVD struct { + CoordSize uint8 + + Bits uint16 + Frame byte + Coord [3]float32 + Angle [3]float32 + ModelIndex byte + SkinNum byte + Effects byte + WeaponFrame byte +} + +func (cmd *Command) Bytes() []byte { + buf := buffer.New() + + buf.PutByte(protocol.SVCPlayerInfo) + buf.PutByte(cmd.Index) + + if cmd.IsMVD && cmd.MVD != nil { + buf.PutBytes(cmd.MVD.Bytes()) + } else if cmd.Default != nil { + buf.PutBytes(cmd.Default.Bytes()) + } + + return buf.Bytes() +} + +func (cmd *CommandDefault) Bytes() []byte { + buf := buffer.New() + + writeCoord := buf.PutCoord16 + if cmd.CoordSize == 4 || + cmd.MVDProtocolExtension&mvd.ExtensionFloatCoords != 0 || + cmd.FTEProtocolExtension&fteExtensions != 0 { + writeCoord = buf.PutCoord32 + } + + buf.PutUint16(cmd.Bits) + + if cmd.FTEProtocolExtension&fteExtensions != 0 && cmd.Bits&fte.UFarMore != 0 { + buf.PutByte(cmd.ExtraBits) + } + + for i := 0; i < 3; i++ { + writeCoord(cmd.Coord[i]) + } + + buf.PutByte(cmd.Frame) + + if cmd.Bits&protocol.PFMsec != 0 { + buf.PutByte(cmd.Msec) + } + + if cmd.Bits&protocol.PFCommand != 0 { + buf.PutBytes(cmd.DeltaUserCommand.Bytes()) + } + + for i := 0; i < 3; i++ { + if cmd.Bits&(protocol.PFVelocity1<