Documentation ¶
Overview ¶
Package sendtables contains code related to decoding sendtables. Mostly used internally but can be interesting for direct access to server-classes and entities.
Index ¶
- type Entity
- type EntityCreatedHandler
- type EntityHandler
- type EntityOp
- type Property
- type PropertyEntry
- type PropertyType
- type PropertyUpdateHandler
- type PropertyValue
- func (v PropertyValue) BoolVal() bool
- func (v PropertyValue) Float() float32
- func (v PropertyValue) Handle() uint64
- func (v PropertyValue) Int() int
- func (v PropertyValue) Int64() int64
- func (v PropertyValue) R3Vec() r3.Vector
- func (v PropertyValue) R3VecOrNil() *r3.Vector
- func (v PropertyValue) S2UInt32() uint32
- func (v PropertyValue) S2UInt64() uint64
- func (v PropertyValue) Str() string
- func (v PropertyValue) String() string
- type PropertyValueType
- type SendTableParser
- func (p *SendTableParser) OnDemoClassInfo(*msgs2.CDemoClassInfo) error
- func (p *SendTableParser) OnEntity(h EntityHandler)
- func (p *SendTableParser) OnPacketEntities(*msgs2.CSVCMsg_PacketEntities) error
- func (p *SendTableParser) OnServerInfo(*msgs2.CSVCMsg_ServerInfo) error
- func (p *SendTableParser) ParsePacket(b []byte) error
- func (p *SendTableParser) ReadEnterPVS(r *bit.BitReader, entityID int, existingEntities map[int]Entity, ...) Entity
- func (p *SendTableParser) ServerClasses() ServerClasses
- func (p *SendTableParser) SetInstanceBaseline(scID int, data []byte)
- type ServerClass
- type ServerClasses
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entity ¶
type Entity interface { // ServerClass returns the entity's server-class. ServerClass() ServerClass // ID returns the entity's ID. ID() int // SerialNum returns the entity's serial number. SerialNum() int // Properties returns all properties of the entity. Properties() (out []Property) // Property finds a property on the entity by name. // // Returns nil if the property wasn't found. Property(name string) Property // BindProperty combines Property() & Property.Bind() into one. // Essentially binds a property's value to a pointer. // See the docs of the two individual functions for more info. BindProperty(name string, variable any, valueType PropertyValueType) // PropertyValue finds a property on the entity by name and returns its value. // // Returns false as second value if the property was not found. PropertyValue(name string) (PropertyValue, bool) // PropertyValueMust finds a property on the entity by name and returns its value. // // Panics with nil pointer dereference error if the property was not found. PropertyValueMust(name string) PropertyValue // ApplyUpdate reads an update to an Enitiy's properties and // triggers registered PropertyUpdateHandlers if values changed. // // Intended for internal use only. ApplyUpdate(reader *bit.BitReader) // Position returns the entity's position in world coordinates. Position() r3.Vector // OnPositionUpdate registers a handler for the entity's position update. // The handler is called with the new position every time a position-relevant property is updated. // // See also Position() OnPositionUpdate(h func(pos r3.Vector)) // OnDestroy registers a function to be called on the entity's destruction. OnDestroy(delegate func()) // Destroy triggers all via OnDestroy() registered functions. // // Intended for internal use only. Destroy() // OnCreateFinished registers a function to be called once the entity is fully created - // i.e. once all property updates have been sent out. OnCreateFinished(delegate func()) }
Entity is an auto-generated interface for entity, intended to be used when mockability is needed. entity stores a entity in the game (e.g. players etc.) with its properties.
type EntityCreatedHandler ¶
type EntityCreatedHandler func(Entity)
EntityCreatedHandler is the interface for handlers that are interested in EntityCreatedEvents.
type EntityHandler ¶
EntityHandler is a function that receives Entity updates
type EntityOp ¶
type EntityOp int
EntityOp is a bitmask representing the type of operation performed on an Entity
const ( EntityOpNone EntityOp = 0x00 EntityOpCreated EntityOp = 0x01 EntityOpUpdated EntityOp = 0x02 EntityOpDeleted EntityOp = 0x04 EntityOpEntered EntityOp = 0x08 EntityOpLeft EntityOp = 0x10 EntityOpCreatedEntered EntityOp = EntityOpCreated | EntityOpEntered EntityOpUpdatedEntered EntityOp = EntityOpUpdated | EntityOpEntered EntityOpDeletedLeft EntityOp = EntityOpDeleted | EntityOpLeft )
type Property ¶
type Property interface { // Name returns the property's name. Name() string // Value returns the current value of the property. Value() PropertyValue // Type returns the data type of the property. Type() PropertyType // ArrayElementType returns the data type of array entries, if Property.Type() is PropTypeArray. ArrayElementType() PropertyType // OnUpdate registers a handler for updates of the property's value. // // The handler will be called with the current value upon registration. OnUpdate(handler PropertyUpdateHandler) /* Bind binds a property's value to a pointer. Example: var i int property.Bind(&i, ValTypeInt) This will bind the property's value to i so every time it's updated i is updated as well. The valueType indicates which field of the PropertyValue to use for the binding. */ Bind(variable any, valueType PropertyValueType) }
Property is an auto-generated interface for property, intended to be used when mockability is needed. property wraps a flattenedPropEntry and allows registering handlers that can be triggered on a update of the property.
type PropertyEntry ¶
type PropertyEntry struct { Name string IsArray bool Type PropertyType }
type PropertyType ¶
type PropertyType int
PropertyType identifies the data type of a property.
const ( PropTypeInt PropertyType = iota PropTypeFloat PropTypeVector PropTypeVectorXY PropTypeString PropTypeArray PropTypeDataTable PropTypeInt64 PropTypeAny )
type PropertyUpdateHandler ¶
type PropertyUpdateHandler func(PropertyValue)
PropertyUpdateHandler is the interface for handlers that are interested in property changes.
type PropertyValue ¶
type PropertyValue struct { VectorVal r3.Vector // Deprecated, use R3Vec() instead IntVal int // Deprecated, use Int() instead Int64Val int64 // Deprecated, use Int64() instead ArrayVal []PropertyValue // Deprecated. StringVal string // Deprecated, use Str() instead FloatVal float32 // Deprecated, use Float() instead Any any S2 bool }
PropertyValue stores parsed & decoded send-table values. For instance player health, location etc.
func (PropertyValue) BoolVal ¶
func (v PropertyValue) BoolVal() bool
BoolVal returns true if IntVal > 0.
func (PropertyValue) Float ¶
func (v PropertyValue) Float() float32
func (PropertyValue) Handle ¶
func (v PropertyValue) Handle() uint64
func (PropertyValue) Int ¶
func (v PropertyValue) Int() int
func (PropertyValue) Int64 ¶
func (v PropertyValue) Int64() int64
func (PropertyValue) R3Vec ¶
func (v PropertyValue) R3Vec() r3.Vector
func (PropertyValue) R3VecOrNil ¶
func (v PropertyValue) R3VecOrNil() *r3.Vector
func (PropertyValue) S2UInt32 ¶
func (v PropertyValue) S2UInt32() uint32
func (PropertyValue) S2UInt64 ¶
func (v PropertyValue) S2UInt64() uint64
func (PropertyValue) Str ¶
func (v PropertyValue) Str() string
func (PropertyValue) String ¶
func (v PropertyValue) String() string
type PropertyValueType ¶
type PropertyValueType int
PropertyValueType specifies the type of a PropertyValue
const ( ValTypeInt PropertyValueType = iota ValTypeFloat32 ValTypeFloat64 // Like ValTypeFloat32 but with additional cast to float64 ValTypeString ValTypeVector ValTypeArray ValTypeBoolInt // Int that is treated as bool (1 -> true, != 1 -> false) )
Possible types of property values. See Property.Bind()
type SendTableParser ¶
type SendTableParser struct {
// contains filtered or unexported fields
}
SendTableParser provides functions for parsing send-tables.
Intended for internal use only.
func NewSendTableParser ¶
func NewSendTableParser() *SendTableParser
NewSendTableParser returns a new SendTableParser.
Intended for internal use only.
func (*SendTableParser) OnDemoClassInfo ¶
func (p *SendTableParser) OnDemoClassInfo(*msgs2.CDemoClassInfo) error
func (*SendTableParser) OnEntity ¶
func (p *SendTableParser) OnEntity(h EntityHandler)
func (*SendTableParser) OnPacketEntities ¶
func (p *SendTableParser) OnPacketEntities(*msgs2.CSVCMsg_PacketEntities) error
func (*SendTableParser) OnServerInfo ¶
func (p *SendTableParser) OnServerInfo(*msgs2.CSVCMsg_ServerInfo) error
func (*SendTableParser) ParsePacket ¶
func (p *SendTableParser) ParsePacket(b []byte) error
ParsePacket parses a send-table packet.
Intended for internal use only.
func (*SendTableParser) ReadEnterPVS ¶
func (p *SendTableParser) ReadEnterPVS(r *bit.BitReader, entityID int, existingEntities map[int]Entity, recordingPlayerSlot int) Entity
ReadEnterPVS reads an entity entering the PVS (potentially visible system).
Intended for internal use only.
func (*SendTableParser) ServerClasses ¶
func (p *SendTableParser) ServerClasses() ServerClasses
ServerClasses returns the parsed server-classes.
Intended for internal use only.
func (*SendTableParser) SetInstanceBaseline ¶
func (p *SendTableParser) SetInstanceBaseline(scID int, data []byte)
SetInstanceBaseline sets the raw instance-baseline data for a serverclass by ID.
Intended for internal use only.
type ServerClass ¶
type ServerClass interface { // ID returns the server-class's ID. ID() int // Name returns the server-class's name. Name() string // DataTableID returns the data-table ID. DataTableID() int // DataTableName returns the data-table name. DataTableName() string // BaseClasses returns the base-classes of this server-class. BaseClasses() (res []ServerClass) // PropertyEntries returns the names of all property-entries on this server-class. PropertyEntries() []string // PropertyEntryDefinitions returns all property-entries on this server-class. PropertyEntryDefinitions() []PropertyEntry // OnEntityCreated registers a function to be called when a new entity is created from this serverClass. OnEntityCreated(handler EntityCreatedHandler) String() string }
ServerClass is an auto-generated interface for property, intended to be used when mockability is needed. serverClass stores meta information about Entity types (e.g. palyers, teams etc.).
type ServerClasses ¶
type ServerClasses interface { All() []ServerClass FindByName(name string) ServerClass }
ServerClasses is a searchable list of ServerClasses.