demo

package
v1.0.236 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

mvd2text is for parsing MVD2 demos in their text format

Index

Constants

View Source
const (
	MVDMagic         = 843339341 // {'M','V','D','2'}
	MaxMessageLength = 32768     // 0x8000
	MaxPacketLength  = 1400      // default Q2 UDP packet len
	MaxStats         = 32        // playerstate stats uint32 bitmask
	MaxQpath         = 64        // max len for file path
	MaxStringChars   = 1024      // biggest string to deal with
	MaxConfigStrings = 2080      // CS_MAX
	MaxClients       = 256       // hard limit
	MaxEdicts        = 1024      // hard limit
	ProtocolVersion  = 37        // major q2 protocol version
	ProtocolMinimum  = 2009      // minor proto version required
	ProtocolCurrent  = 2010      // minor proto version
	MVD2CMDBits      = 5
	MVD2CMDMask      = ((1 << MVD2CMDBits) - 1)
)
View Source
const (
	MVDSvcBad = iota
	MVDSvcNop
	MVDSvcDisconnect
	MVDSvcReconnect
	MVDSvcServerData
	MVDSvcConfigString
	MVDSvcFrame
	MVDSvcFrameNoDelta
	MVDSvcUnicast
	MVDSvcUnicastR
	MVDSvcMulticastAll
	MVDSvcMulticastPHS
	MVDSvcMulticastPVS
	MVDSvcMulticastAllR
	MVDSvcMulticastPHSR
	MVDSvcMulticastPVSR
	MVDSvcSound
	MVDSvcPrint
	MVDSvcStuffText
	MVDSvcMax
)
View Source
const (
	SvcBad = iota
	SvcMuzzleFlash
	SvcMuzzleFlash2
	SvcTemporaryEntity
	SvcLayout
	SvcInventory
	SvcNoOperation
	SvcDisconnect
	SvcReconnect
	SvcSound
	SvcPrint
	SvcStuffText
	SvcServerData
	SvcConfigString
	SvcSpawnBaseline
	SvcCenterprint
	SvcDownload
	SvcPlayerInfo
	SvcPacketEntities
	SvcDeltaPacketEntities
	SvcFrame
	SvcMax
)
View Source
const (
	FlagNoMessages = 1 << 0
	FlagReverved1  = 1 << 1
	FlagReverved2  = 1 << 2
)

Stream flags (3 bits)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseFrame added in v1.0.87

type BaseFrame struct {
	PortalBits int
	Players    []Player
	Entities   []Entity
}

type Block added in v1.0.87

type Block struct {
	Frame BaseFrame
}

type ConfigString added in v1.0.87

type ConfigString struct {
	Index  int
	String string
}

type DM2Parser added in v1.0.233

type DM2Parser struct {
	// contains filtered or unexported fields
}

func NewDM2Demo added in v1.0.233

func NewDM2Demo(filename string) (*DM2Parser, error)

Read the entire binary demo file into memory

func (*DM2Parser) ApplyPacket added in v1.0.233

func (d *DM2Parser) ApplyPacket(packet *pb.Packet) error

ApplyPacket will add all the messages from the packet to the current demo.

func (*DM2Parser) GetTextProto added in v1.0.233

func (demo *DM2Parser) GetTextProto() *pb.DM2Demo

func (*DM2Parser) Marshal added in v1.0.233

func (demo *DM2Parser) Marshal() ([]byte, error)

Convert the textproto demo back into a quake 2 playable binary demo. The returned byte slice just needs to be written to a file as is.

func (*DM2Parser) NextPacket added in v1.0.233

func (demo *DM2Parser) NextPacket() (message.Buffer, int, error)

Demos are organized by "lumps" of data that are essentially packets. Even though all the data is already known, each lump represents a server packet's worth of game data. Each packet is prefixed with a 32 bit integer of the size of the packet and then a bunch of individual messages.

The default packet size for protocol 34 is 1390 bytes. Demos created by modern clients using protocols 35/36 will still write demos for protocol 34 to maximize compatability. Although it is possible to force these clients to record in their native protocol version.

func (*DM2Parser) RegisterCallback added in v1.0.233

func (p *DM2Parser) RegisterCallback(event int, dofunc func(any))

RegisterCallback allows for a custom function to be called at specific points while a demo is being parsed.

`event` is an index corresponding to what you want your callback to be associated with. These match up with the SVC* server messages.

`dofunc` is the function definition to be called at that event. The argument is set to `any` to accept any type, but this arg should be the parsed server message proto. Inside the dofunc, the arg will need to be casted to the appropriate type. Something like:

printMsg := argname.(*pb.Print)

func (*DM2Parser) Unmarshal added in v1.0.233

func (p *DM2Parser) Unmarshal() error

Load the binary demo into protobuf

func (*DM2Parser) UnregisterCallback added in v1.0.233

func (p *DM2Parser) UnregisterCallback(msgtype int)

Dynamically remove a particular callback

func (*DM2Parser) WriteTextProto added in v1.0.233

func (demo *DM2Parser) WriteTextProto(filename string) error

Turn a parsed demo structure back into a binary file

type DemoFile added in v1.0.87

type DemoFile struct {
	Blocks []Block
}

func ParseMVD2TextDemo added in v1.0.87

func ParseMVD2TextDemo(demofile string) (DemoFile, error)

type Entity added in v1.0.87

type Entity struct {
	Number      int
	ModelIndex  int
	ModelIndex2 int
	Frame       int
	Skin        int
	Solid       int
	OriginX     int
	OriginY     int
	OriginZ     int
	RenderFX    int // hex
	Sound       int
	Effects     int // hex
	AngleX      int
	AngleY      int
	AngleZ      int
}

type MVD2File added in v1.0.87

type MVD2File struct {
	Filename string
	Handle   *os.File
	Position int // needed?
	Msg      *message.Buffer
}

func OpenMVD2File added in v1.0.87

func OpenMVD2File(f string) (*MVD2File, error)

Open the demo file and return an demo struct. Checks if the first 4 bytes match the MVDMagic value.

func (*MVD2File) Close added in v1.0.87

func (d *MVD2File) Close()

If the demo file is open (has a valid handle), close it

func (*MVD2File) ParseConfigString added in v1.0.87

func (d *MVD2File) ParseConfigString()

func (*MVD2File) ParseLump added in v1.0.87

func (d *MVD2File) ParseLump(buf message.Buffer)

func (*MVD2File) ParseMulticast added in v1.0.87

func (d *MVD2File) ParseMulticast(cmd byte, bits uint32) (*pb.Multicast, error)

func (*MVD2File) ParseServerData added in v1.0.87

func (d *MVD2File) ParseServerData(bits byte)

type MVDGameState added in v1.0.87

type MVDGameState struct {
	// node?
	Flags         uint32
	VersionMajor  uint32
	VersionMinor  uint16
	ServerCount   uint32
	ClientNumber  uint16
	GameDir       string
	ConfigStrings []*pb.ConfigString
}

type Player added in v1.0.87

type Player struct {
	Number       int
	OriginXY     [2]int
	OriginZ      int
	ViewOffset   [3]int
	ViewAnglesXY [2]int
	KickAngles   [3]int
	WeaponIndex  int
	WeaponFrame  int
	FOV          int
	Stats        []Stat
}

type ServerData added in v1.0.87

type ServerData struct {
	MajorVersion string
	MinorVersion string
	ServerCount  int
	GameDir      string
	ClientNum    int
	NoMessages   bool
	BaseStrings  []ConfigString
}

type Stat added in v1.0.87

type Stat struct {
	Index int
	Value int
}

Jump to

Keyboard shortcuts

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