common

package
v4.0.0-...-9ccc978 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package common contains common types, constants and functions used over different demoinfocs packages.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDataNotAvailable   = errors.New("some data is not (yet) available (reading the same data later during parsing may work)")
	ErrNotSupportedByDemo = errors.New("this data is not supported by the demo (this may be because the demos is too old)")
)
View Source
var EquipmentIndexMapping = map[uint64]EquipmentType{
	1:   EqDeagle,
	2:   EqDualBerettas,
	3:   EqFiveSeven,
	4:   EqGlock,
	7:   EqAK47,
	8:   EqAUG,
	9:   EqAWP,
	10:  EqFamas,
	11:  EqG3SG1,
	13:  EqGalil,
	14:  EqM249,
	16:  EqM4A4,
	17:  EqMac10,
	19:  EqP90,
	20:  EqZoneRepulsor,
	23:  EqMP5,
	24:  EqUMP,
	25:  EqXM1014,
	26:  EqBizon,
	27:  EqMag7,
	28:  EqNegev,
	29:  EqSawedOff,
	30:  EqTec9,
	31:  EqZeus,
	32:  EqP2000,
	33:  EqMP7,
	34:  EqMP9,
	35:  EqNova,
	36:  EqP250,
	37:  EqShield,
	38:  EqScar20,
	39:  EqSG556,
	40:  EqSSG08,
	41:  EqKnife,
	42:  EqKnife,
	43:  EqFlash,
	44:  EqHE,
	45:  EqSmoke,
	46:  EqMolotov,
	47:  EqDecoy,
	48:  EqIncendiary,
	49:  EqBomb,
	50:  EqKevlar,
	51:  EqHelmet,
	52:  EqHeavyAssaultSuit,
	54:  EqNightVision,
	55:  EqDefuseKit,
	56:  EqDefuseKit,
	57:  EqHealthShot,
	59:  EqKnife,
	60:  EqM4A1,
	61:  EqUSP,
	63:  EqCZ,
	64:  EqRevolver,
	68:  EqTacticalAwarenessGrenade,
	69:  EqFists,
	70:  EqBreachCharge,
	72:  EqTablet,
	74:  EqFists,
	75:  EqAxe,
	76:  EqHammer,
	78:  EqWrench,
	80:  EqKnife,
	81:  EqBomb,
	82:  EqDecoy,
	83:  EqHE,
	84:  EqSnowball,
	85:  EqBumpMine,
	500: EqKnife,
	503: EqKnife,
	505: EqKnife,
	506: EqKnife,
	507: EqKnife,
	508: EqKnife,
	509: EqKnife,
	512: EqKnife,
	514: EqKnife,
	515: EqKnife,
	516: EqKnife,
	517: EqKnife,
	518: EqKnife,
	519: EqKnife,
	520: EqKnife,
	521: EqKnife,
	522: EqKnife,
	523: EqKnife,
	525: EqKnife,
}

Indexes are available in the game file located at 'scripts/items/items_game.txt'.

Functions

func ConvertSteamID32To64

func ConvertSteamID32To64(steamID32 uint32) uint64

ConvertSteamID32To64 converts a Steam-ID in 32-bit format to a 64-bit variant. See https://developer.valvesoftware.com/wiki/SteamID

func ConvertSteamID64To32

func ConvertSteamID64To32(steamID64 uint64) uint32

ConvertSteamID64To32 converts a Steam-ID in 64-bit format to a 32-bit variant. See https://developer.valvesoftware.com/wiki/SteamID

func ConvertSteamIDTxtTo32

func ConvertSteamIDTxtTo32(steamID string) (uint32, error)

ConvertSteamIDTxtTo32 converts a Steam-ID in text format to a 32-bit variant. See https://developer.valvesoftware.com/wiki/SteamID

Types

type Bomb

type Bomb struct {
	// Intended for internal use only. Use Position() instead.
	// Contains the last location of the dropped or planted bomb.
	LastOnGroundPosition r3.Vector
	Carrier              *Player
}

Bomb tracks the bomb's position, and the player carrying it, if any.

func (*Bomb) Position

func (b *Bomb) Position() r3.Vector

Position returns the current position of the bomb. This is either the position of the player holding it or LastOnGroundPosition if it's dropped or planted.

type Color

type Color int

Color is the type for the various colors constants.

const (
	Grey Color = iota - 1
	Yellow
	Purple
	Green
	Blue
	Orange
)

Color constants give information about which color a player has.

func (Color) String

func (c Color) String() string

type DemoHeader

type DemoHeader struct {
	Filestamp       string        // aka. File-type, must be HL2DEMO
	Protocol        int           // Should be 4
	NetworkProtocol int           // Not sure what this is for
	ServerName      string        // Server's 'hostname' config value
	ClientName      string        // Usually 'GOTV Demo'
	MapName         string        // E.g. de_cache, de_nuke, cs_office, etc.
	GameDirectory   string        // Usually 'csgo'
	PlaybackTime    time.Duration // Demo duration in seconds (= PlaybackTicks / Server's tickrate)
	PlaybackTicks   int           // Game duration in ticks (= PlaybackTime * Server's tickrate)
	PlaybackFrames  int           // Amount of 'frames' aka demo-ticks recorded (= PlaybackTime * Demo's recording rate)
	SignonLength    int           // Length of the Signon package in bytes
}

DemoHeader contains information from a demo's header.

func (*DemoHeader) FrameRate

func (h *DemoHeader) FrameRate() float64

FrameRate returns the frame rate of the demo (frames / demo-ticks per second). Not necessarily the tick-rate the server ran on during the game.

Returns 0 if PlaybackTime or PlaybackFrames are 0 (corrupt demo headers).

func (*DemoHeader) FrameTime

func (h *DemoHeader) FrameTime() time.Duration

FrameTime returns the time a frame / demo-tick takes in seconds.

Returns 0 if PlaybackTime or PlaybackFrames are 0 (corrupt demo headers).

type Equipment

type Equipment struct {
	Type   EquipmentType // The type of weapon which the equipment instantiates.
	Entity st.Entity     // The game entity instance
	Owner  *Player       // The player carrying the equipment, not necessarily the buyer.
	// E.g. 'models/weapons/w_rif_m4a1_s.mdl'.
	// Used internally to differentiate alternative weapons (M4A4 / M4A1-S etc.) for Source 1 demos.
	// It's always an empty string with Source 2 demos, you should use Type to know which weapon it is.
	OriginalString string
	// contains filtered or unexported fields
}

Equipment is a weapon / piece of equipment belonging to a player. This also includes the skin and some additional data.

func NewEquipment

func NewEquipment(wep EquipmentType) *Equipment

NewEquipment creates a new Equipment and sets the UniqueID.

Intended for internal use only.

func (*Equipment) AmmoInMagazine

func (e *Equipment) AmmoInMagazine() int

AmmoInMagazine returns the ammo left in the magazine. Returns 1 for grenades and equipments (Knife, C4...).

func (*Equipment) AmmoReserve

func (e *Equipment) AmmoReserve() int

AmmoReserve returns the ammo left available for reloading. Returns CWeaponCSBase.m_iPrimaryReserveAmmoCount for most weapons and 'Owner.AmmoLeft[AmmoType] - 1' for grenades. Use AmmoInMagazine() + AmmoReserve() to quickly get the amount of grenades a player owns.

func (*Equipment) AmmoType

func (e *Equipment) AmmoType() int

AmmoType returns the weapon's ammo type, mostly (only?) relevant for grenades. Works with Source 1 demos only, it's always 0 with Source 2 demos. It looks like the prop is not present with Source 2 and we don't need it anymore to retrieve the ammo reserve as there is a new dedicated prop "m_pReserveAmmo".

func (*Equipment) Class

func (e *Equipment) Class() EquipmentClass

Class returns the class of the equipment. E.g. pistol, smg, heavy etc.

func (*Equipment) RecoilIndex

func (e *Equipment) RecoilIndex() float32

RecoilIndex returns the weapon's recoil index

func (*Equipment) Silenced

func (e *Equipment) Silenced() bool

Silenced returns true if weapon is silenced.

func (*Equipment) String

func (e *Equipment) String() string

String returns a human readable name for the equipment. E.g. 'AK-47', 'UMP-45', 'Smoke Grenade' etc.

func (*Equipment) UniqueID

func (e *Equipment) UniqueID() int64

UniqueID returns a randomly generated unique id of the equipment element. The unique id is a random int generated internally by this library and can be used to differentiate equipment from each other. This is needed because demo-files reuse entity ids. Deprecated: Use UniqueID2 instead. Since UniqueID is randomly generated, duplicate IDs are possible. See the birthday problem for why repeatedly generating random 64 bit integers is likely to produce a collision.

func (*Equipment) UniqueID2

func (e *Equipment) UniqueID2() ulid.ULID

UniqueID2 returns a unique id of the equipment element that can be sorted efficiently. UniqueID2 is a value generated internally by this library and can be used to differentiate equipment from each other. This is needed because demo-files reuse entity ids. Unlike UniqueID, UniqueID2 is guaranteed to be unique.

func (*Equipment) ZoomLevel

func (e *Equipment) ZoomLevel() ZoomLevel

ZoomLevel returns how far the player has zoomed in on the weapon. Only weapons with scopes have a valid zoom level.

type EquipmentClass

type EquipmentClass int

EquipmentClass is the type for the various EqClassXYZ constants.

const (
	EqClassUnknown   EquipmentClass = 0
	EqClassPistols   EquipmentClass = 1
	EqClassSMG       EquipmentClass = 2
	EqClassHeavy     EquipmentClass = 3
	EqClassRifle     EquipmentClass = 4
	EqClassEquipment EquipmentClass = 5
	EqClassGrenade   EquipmentClass = 6
)

EquipmentClass constants give information about the type of an equipment (SMG, Rifle, Grenade etc.).

Note: (EquipmentType+99) / 100 = EquipmentClass

type EquipmentType

type EquipmentType int

EquipmentType is the type for the various EqXYZ constants.

const (
	EqUnknown EquipmentType = 0

	EqP2000        EquipmentType = 1
	EqGlock        EquipmentType = 2
	EqP250         EquipmentType = 3
	EqDeagle       EquipmentType = 4
	EqFiveSeven    EquipmentType = 5
	EqDualBerettas EquipmentType = 6
	EqTec9         EquipmentType = 7
	EqCZ           EquipmentType = 8
	EqUSP          EquipmentType = 9
	EqRevolver     EquipmentType = 10

	EqMP7   EquipmentType = 101
	EqMP9   EquipmentType = 102
	EqBizon EquipmentType = 103
	EqMac10 EquipmentType = 104
	EqUMP   EquipmentType = 105
	EqP90   EquipmentType = 106
	EqMP5   EquipmentType = 107

	EqSawedOff EquipmentType = 201
	EqNova     EquipmentType = 202
	EqMag7     EquipmentType = 203 // You should consider using EqSwag7 instead
	EqSwag7    EquipmentType = 203
	EqXM1014   EquipmentType = 204
	EqM249     EquipmentType = 205
	EqNegev    EquipmentType = 206

	EqGalil  EquipmentType = 301
	EqFamas  EquipmentType = 302
	EqAK47   EquipmentType = 303
	EqM4A4   EquipmentType = 304
	EqM4A1   EquipmentType = 305
	EqScout  EquipmentType = 306
	EqSSG08  EquipmentType = 306
	EqSG556  EquipmentType = 307
	EqSG553  EquipmentType = 307
	EqAUG    EquipmentType = 308
	EqAWP    EquipmentType = 309
	EqScar20 EquipmentType = 310
	EqG3SG1  EquipmentType = 311

	EqZeus                     EquipmentType = 401
	EqKevlar                   EquipmentType = 402
	EqHelmet                   EquipmentType = 403
	EqBomb                     EquipmentType = 404
	EqKnife                    EquipmentType = 405
	EqDefuseKit                EquipmentType = 406
	EqWorld                    EquipmentType = 407
	EqZoneRepulsor             EquipmentType = 408
	EqShield                   EquipmentType = 409
	EqHeavyAssaultSuit         EquipmentType = 410
	EqNightVision              EquipmentType = 411
	EqHealthShot               EquipmentType = 412
	EqTacticalAwarenessGrenade EquipmentType = 413
	EqFists                    EquipmentType = 414
	EqBreachCharge             EquipmentType = 415
	EqTablet                   EquipmentType = 416
	EqAxe                      EquipmentType = 417
	EqHammer                   EquipmentType = 418
	EqWrench                   EquipmentType = 419
	EqSnowball                 EquipmentType = 420
	EqBumpMine                 EquipmentType = 421

	EqDecoy      EquipmentType = 501
	EqMolotov    EquipmentType = 502
	EqIncendiary EquipmentType = 503
	EqFlash      EquipmentType = 504
	EqSmoke      EquipmentType = 505
	EqHE         EquipmentType = 506
)

EquipmentType constants give information about what weapon a player has equipped.

func EquipmentAlternative

func EquipmentAlternative(eq EquipmentType) EquipmentType

EquipmentAlternative returns the EquipmentType of the alternatively equippable weapon. E.g. returns EquipmentAlternative(EqP2000) returns EqUSP. Only works one way (default-to-alternative) as the Five-Seven and Tec-9 both map to the CZ-75.

func MapEquipment

func MapEquipment(eqName string) EquipmentType

MapEquipment creates an EquipmentType from the name of the weapon / equipment. Returns EqUnknown if no mapping can be found.

func (EquipmentType) Class

func (e EquipmentType) Class() EquipmentClass

Class returns the class of the equipment. E.g. pistol, smg, heavy etc.

func (EquipmentType) String

func (e EquipmentType) String() string

String returns a human readable name for the equipment. E.g. 'AK-47', 'UMP-45', 'Smoke Grenade' etc.

type Fire

type Fire struct {
	r3.Vector

	IsBurning bool
}

Fire is a component of an Inferno.

type Fires

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

Fires is a collection of fires that provides utility functions for things like calculation of 2D & 3D convex hulls. See also Inferno.

func (Fires) Active

func (f Fires) Active() Fires

Active returns all currently active fires (only Fire.IsBurning == true).

func (Fires) ConvexHull2D

func (f Fires) ConvexHull2D() []r2.Point

ConvexHull2D returns clockwise sorted corner points making up the 2D convex hull of all the fires in the inferno. Useful for drawing on 2D maps.

func (Fires) ConvexHull3D

func (f Fires) ConvexHull3D() quickhull.ConvexHull

ConvexHull3D returns the 3D convex hull of all the fires in the inferno.

func (Fires) List

func (f Fires) List() []Fire

List returns fires a list of the raw Fire entities. This can be useful if you need to do custom calculations on the fires.

type GamePhase

type GamePhase int

GamePhase represents a phase in CS:GO

const (
	// GamePhaseInit is the default value of the game phase
	GamePhaseInit GamePhase = 0 // enum name: Init

	// GamePhasePregame
	GamePhasePregame GamePhase = 1 // enum name: Pregame

	// GamePhaseStartGamePhase is set whenever a new game phase is started.
	// A game phase can be the normal match, i.e. first to 16 rounds, or an overtime match,
	// i.e. first to 4 rounds. It is set for _all_ overtimes played, i.e. for a match
	// with 3 overtimes,  GamePhaseStartGamePhase is set 1 time for the normal
	// match and 1 time for each overtime played, for a total of 4 times.
	GamePhaseStartGamePhase GamePhase = 2 // enum name: StartGame

	// GamePhaseTeamSideSwitch is set whenever a team side switch happened,
	// i.e. both during normal game and overtime play.
	GamePhaseTeamSideSwitch GamePhase = 3 // enum name: PreRound

	// GamePhaseGameHalfEnded is set whenever a game phase has ended.
	// A game phase can be the normal match, i.e. first to 16 rounds, or an overtime match,
	// i.e. first to 4 rounds. It is set once for all overtimes played, i.e. for a match
	// with 3 overtimes,  GamePhaseGameHalfEnded is set 1 time for the normal
	// match and 1 time for each overtime played, for a total of 4 times.
	GamePhaseGameHalfEnded GamePhase = 4 // enum name: TeamWin

	// GamePhaseGameEnded is set when the full game has ended.
	// This existence of this event is not reliable: it has been observed that a demo ends
	// before this event is set
	GamePhaseGameEnded GamePhase = 5 // enum name: Restart

	// GamePhaseStaleMate has not been observed so far
	GamePhaseStaleMate GamePhase = 6 // enum name: StaleMate

	// GamePhaseGameOver has not been observed so far
	GamePhaseGameOver GamePhase = 7 // enum name: GameOver
)

The following game rules have been found at https://github.com/pmrowla/hl2sdk-csgo/blob/master/game/shared/teamplayroundbased_gamerules.h#L37. It seems that the naming used in the source engine is _not_ what is used in-game. The original names of the enum fields are added as comments to each field.

func (GamePhase) String

func (r GamePhase) String() string

type GrenadeProjectile

type GrenadeProjectile struct {
	Entity         st.Entity
	WeaponInstance *Equipment
	Thrower        *Player // Always seems to be the same as Owner, even if the grenade was picked up
	Owner          *Player // Always seems to be the same as Thrower, even if the grenade was picked up

	// Deprecated: use Trajectory2 instead
	Trajectory []r3.Vector // List of all known locations of the grenade up to the current point

	Trajectory2 []TrajectoryEntry // List of all known locations and the point in time of the grenade up to the current point
	// contains filtered or unexported fields
}

GrenadeProjectile is a grenade thrown intentionally by a player. It is used to track grenade projectile positions between the time at which they are thrown and until they detonate.

func NewGrenadeProjectile

func NewGrenadeProjectile() *GrenadeProjectile

NewGrenadeProjectile creates a grenade projectile and sets the Unique-ID.

Intended for internal use only.

func (*GrenadeProjectile) Position

func (g *GrenadeProjectile) Position() r3.Vector

Position returns the current position of the grenade projectile in world coordinates.

func (*GrenadeProjectile) UniqueID

func (g *GrenadeProjectile) UniqueID() int64

UniqueID returns the unique id of the grenade. The unique id is a random int generated internally by this library and can be used to differentiate grenades from each other. This is needed because demo-files reuse entity ids.

func (*GrenadeProjectile) Velocity

func (g *GrenadeProjectile) Velocity() r3.Vector

Velocity returns the projectile's velocity.

type Hostage

type Hostage struct {
	Entity st.Entity
	// contains filtered or unexported fields
}

Hostage represents a hostage.

func NewHostage

func NewHostage(demoInfoProvider demoInfoProvider, entity st.Entity) *Hostage

NewHostage creates a hostage.

func (*Hostage) Health

func (hostage *Hostage) Health() int

Health returns the hostage's health points. ! On Valve MM matches hostages are invulnerable, it will always return 100 unless "mp_hostages_takedamage" is set to 1

func (*Hostage) Leader

func (hostage *Hostage) Leader() *Player

Leader returns the possible player leading the hostage. Returns nil if the hostage is not following a player.

func (*Hostage) Position

func (hostage *Hostage) Position() r3.Vector

Position returns the current position of the hostage.

func (*Hostage) State

func (hostage *Hostage) State() HostageState

State returns the current hostage's state. e.g. being untied, picked up, rescued etc. See HostageState for all possible values.

type HostageState

type HostageState byte

HostageState is the type for the various HostageStateXYZ constants.

const (
	HostageStateIdle            HostageState = 0
	HostageStateBeingUntied     HostageState = 1
	HostageStateGettingPickedUp HostageState = 2
	HostageStateBeingCarried    HostageState = 3
	HostageStateFollowingPlayer HostageState = 4
	HostageStateGettingDropped  HostageState = 5
	HostageStateRescued         HostageState = 6
	HostageStateDead            HostageState = 7
)

HostageState constants give information about hostages state. e.g. being untied, picked up, rescued etc.

type Inferno

type Inferno struct {
	Entity st.Entity
	// contains filtered or unexported fields
}

Inferno is a list of Fires with helper functions. Also contains already extinguished fires.

See also: Inferno.Active() and Fire.IsBurning

func NewInferno

func NewInferno(demoInfoProvider demoInfoProvider, entity st.Entity, thrower *Player) *Inferno

NewInferno creates a inferno and sets the Unique-ID.

Intended for internal use only.

func (*Inferno) Fires

func (inf *Inferno) Fires() Fires

Fires returns all fires (past + present). Some are currently active and some have extinguished (see Fire.IsBurning).

func (*Inferno) Thrower

func (inf *Inferno) Thrower() *Player

Thrower returns the player who threw the fire grenade. Could be nil if the player disconnected after throwing it.

func (*Inferno) UniqueID

func (inf *Inferno) UniqueID() int64

UniqueID returns the unique id of the inferno. The unique id is a random int generated internally by this library and can be used to differentiate infernos from each other. This is needed because demo-files reuse entity ids.

type Player

type Player struct {
	SteamID64         uint64             // 64-bit representation of the user's Steam ID. See https://developer.valvesoftware.com/wiki/SteamID
	LastAlivePosition r3.Vector          // The location where the player was last alive. Should be equal to Position if the player is still alive.
	UserID            int                // Mostly used in game-events to address this player
	Name              string             // Steam / in-game user name
	Inventory         map[int]*Equipment // All weapons / equipment the player is currently carrying. See also Weapons().
	AmmoLeft          [32]int            // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType
	EntityID          int                // Usually the same as Entity.ID() but may be different between player death and re-spawn.
	Entity            st.Entity          // May be nil between player-death and re-spawn
	FlashDuration     float32            // Blindness duration from the flashbang currently affecting the player (seconds)
	FlashTick         int                // In-game tick at which the player was last flashed
	TeamState         *TeamState         // When keeping the reference make sure you notice when the player changes teams
	Team              Team               // Team identifier for the player (e.g. TeamTerrorists or TeamCounterTerrorists).
	IsBot             bool               // True if this is a bot-entity. See also IsControllingBot and ControlledBot().
	IsConnected       bool
	IsDefusing        bool
	IsPlanting        bool
	IsReloading       bool
	IsUnknown         bool // Used to identify unknown/broken players. see https://github.com/markus-wa/demoinfocs-golang/issues/162
	// contains filtered or unexported fields
}

Player contains mostly game-relevant player information.

func NewPlayer

func NewPlayer(demoInfoProvider demoInfoProvider) *Player

NewPlayer creates a *Player with an initialized equipment map.

Intended for internal use only.

func (*Player) ActiveWeapon

func (p *Player) ActiveWeapon() *Equipment

ActiveWeapon returns the currently active / equipped weapon of the player. ! Can be nil

func (*Player) Armor

func (p *Player) Armor() int

Armor returns the player's armor points, normally 0-100.

func (*Player) Assists

func (p *Player) Assists() int

Assists returns the amount of assists the player has as shown on the scoreboard.

func (*Player) ClanTag

func (p *Player) ClanTag() string

ClanTag returns the player's individual clan tag (Steam Groups etc.).

func (*Player) Color

func (p *Player) Color() Color

Color returns the players color as shown on the minimap. It will return Grey (-1) if the resource entity does not exist when the function is called or when the demo does not support player colors. Deprecated: Use ColorOrErr() instead.

func (*Player) ColorOrErr

func (p *Player) ColorOrErr() (Color, error)

ColorOrErr returns the players color as shown on the minimap. Returns ErrDataNotAvailable if the resource entity does not exist (it may exist later during parsing). Returns ErrNotSupportedByDemo if the demo does not support player colors (e.g. very old demos).

func (*Player) CompetitiveWins

func (p *Player) CompetitiveWins() int

CompetitiveWins returns the amount of competitive wins the player has for the current RankType.

func (*Player) ControlledBot

func (p *Player) ControlledBot() *Player

ControlledBot returns the player instance of the bot that the player is controlling, if any. Returns nil if the player is not controlling a bot.

func (*Player) CrosshairCode

func (p *Player) CrosshairCode() string

CrosshairCode returns the player's crosshair code or an empty string if there isn't one.

func (*Player) Deaths

func (p *Player) Deaths() int

Deaths returns the amount of deaths the player has as shown on the scoreboard.

func (*Player) EquipmentValueCurrent

func (p *Player) EquipmentValueCurrent() int

EquipmentValueCurrent returns the current value of equipment in the player's inventory.

func (*Player) EquipmentValueFreezeTimeEnd

func (p *Player) EquipmentValueFreezeTimeEnd() int

EquipmentValueFreezeTimeEnd returns the value of equipment in the player's inventory at the end of the freeze time.

func (*Player) EquipmentValueRoundStart

func (p *Player) EquipmentValueRoundStart() int

EquipmentValueRoundStart returns the value of equipment in the player's inventory at the time of the round start. This is before the player has bought any new items in the freeze time. See also Player.EquipmentValueFreezetimeEnd().

func (*Player) Flags

func (p *Player) Flags() PlayerFlags

Flags returns flags currently set on m_fFlags.

func (*Player) FlashDurationTime

func (p *Player) FlashDurationTime() time.Duration

FlashDurationTime returns the duration of the blinding effect as time.Duration instead of float32 in seconds. Will return 0 if IsBlinded() returns false.

func (*Player) FlashDurationTimeRemaining

func (p *Player) FlashDurationTimeRemaining() time.Duration

FlashDurationTimeRemaining returns the remaining duration of the blinding effect (or 0 if the player is not currently blinded). It takes into consideration FlashDuration, FlashTick, DemoHeader.TickRate() and GameState.IngameTick().

func (*Player) GetFlashDuration

func (p *Player) GetFlashDuration() float32

func (*Player) GetTeam

func (p *Player) GetTeam() Team

func (*Player) HasDefuseKit

func (p *Player) HasDefuseKit() bool

HasDefuseKit returns true if the player currently has a defuse kit in his inventory.

func (*Player) HasHelmet

func (p *Player) HasHelmet() bool

HasHelmet returns true if the player is currently wearing head armor.

func (*Player) HasSpotted

func (p *Player) HasSpotted(other *Player) bool

HasSpotted returns true if the player has spotted the other player. This is NOT "Line of Sight" / FOV - look up "CSGO TraceRay" for that. May not behave as expected with multiple spotters.

func (*Player) Health

func (p *Player) Health() int

Health returns the player's health points, normally 0-100.

func (*Player) IsAirborne

func (p *Player) IsAirborne() bool

IsAirborne returns true if the player is jumping or falling.

func (*Player) IsAlive

func (p *Player) IsAlive() bool

IsAlive returns true if the player is alive.

func (*Player) IsBlinded

func (p *Player) IsBlinded() bool

IsBlinded returns true if the player is currently flashed. This is more accurate than 'FlashDuration != 0' as it also takes into account FlashTick, DemoHeader.TickRate() and GameState.IngameTick().

func (*Player) IsControllingBot

func (p *Player) IsControllingBot() bool

IsControllingBot returns true if the player is currently controlling a bot. See also ControlledBot().

func (*Player) IsDucking

func (p *Player) IsDucking() bool

IsDucking returns true if the player is currently fully crouching. See also: Flags().Ducking() & Flags().DuckingKeyPressed()

func (*Player) IsDuckingInProgress

func (p *Player) IsDuckingInProgress() bool

IsDuckingInProgress returns true if the player is currently in the progress of going from standing to crouched. See also: Flags().Ducking() & Flags().DuckingKeyPressed()

func (*Player) IsGrabbingHostage

func (p *Player) IsGrabbingHostage() bool

IsGrabbingHostage returns true if the player is currently grabbing a hostage.

func (*Player) IsInBombZone

func (p *Player) IsInBombZone() bool

IsInBombZone returns whether the player is currently in the bomb zone or not.

func (*Player) IsInBuyZone

func (p *Player) IsInBuyZone() bool

IsInBuyZone returns whether the player is currently in the buy zone or not.

func (*Player) IsScoped

func (p *Player) IsScoped() bool

IsScoped returns whether the player is currently scoped in or not.

func (*Player) IsSpottedBy

func (p *Player) IsSpottedBy(other *Player) bool

IsSpottedBy returns true if the player has been spotted by the other player. This is NOT "Line of Sight" / FOV - look up "CSGO TraceRay" for that. May not behave as expected with multiple spotters.

func (*Player) IsStanding

func (p *Player) IsStanding() bool

IsStanding returns true if the player is currently fully standing upright. See also: Flags().Ducking() & Flags().DuckingKeyPressed()

func (*Player) IsUnDuckingInProgress

func (p *Player) IsUnDuckingInProgress() bool

IsUnDuckingInProgress returns true if the player is currently in the progress of going from crouched to standing. See also: Flags().Ducking() & Flags().DuckingKeyPressed()

func (*Player) IsWalking

func (p *Player) IsWalking() bool

IsWalking returns whether the player is currently walking (sneaking) in or not.

func (*Player) Kills

func (p *Player) Kills() int

Kills returns the amount of kills the player has as shown on the scoreboard.

func (*Player) LastPlaceName

func (p *Player) LastPlaceName() string

LastPlaceName returns the string value of the player's position.

func (*Player) MVPs

func (p *Player) MVPs() int

MVPs returns the amount of Most-Valuable-Player awards the player has as shown on the scoreboard.

func (*Player) Money

func (p *Player) Money() int

Money returns the amount of money in the player's bank.

func (*Player) MoneySpentThisRound

func (p *Player) MoneySpentThisRound() int

MoneySpentThisRound returns the amount of money the player has spent in the current round.

func (*Player) MoneySpentTotal

func (p *Player) MoneySpentTotal() int

MoneySpentTotal returns the total amount of money the player has spent in the current match.

func (*Player) Ping

func (p *Player) Ping() int

Ping returns the players latency to the game server.

func (*Player) PlayerPawnEntity

func (p *Player) PlayerPawnEntity() st.Entity

func (*Player) Position

func (p *Player) Position() r3.Vector

Position returns the in-game coordinates. Note: the Z value is not on the player's eye height but instead at his feet. See also PositionEyes().

func (*Player) PositionEyes

func (p *Player) PositionEyes() r3.Vector

PositionEyes returns the player's position with the Z value at eye height. This is what you get from cl_showpos 1. See also Position().

func (*Player) Rank

func (p *Player) Rank() int

Rank returns the current rank of the player for the current RankType. CS:GO demos -> from 0 to 18 (0 = unranked/unknown, 18 = Global Elite) CS2 demos -> Number representation of the player's rank.

func (*Player) RankType

func (p *Player) RankType() int

RankType returns the current rank type that the player is playing for. CS:GO values: -1 -> Information not present, the demo is too old 0 -> None/not available 6 -> Classic Competitive 7 -> Wingman 2v2 10 -> Danger zone

CS2 values: -1 -> Not available, demo probably not coming from a Valve server 0 -> None? 7 -> Wingman 2v2 11 -> Premier mode 12 -> Classic Competitive

func (*Player) Score

func (p *Player) Score() int

Score returns the players score as shown on the scoreboard.

func (*Player) SteamID32

func (p *Player) SteamID32() uint32

SteamID32 converts SteamID64 to the 32-bit SteamID variant and returns the result. See https://developer.valvesoftware.com/wiki/SteamID

func (*Player) String

func (p *Player) String() string

String returns the player's name. Implements fmt.Stringer.

func (*Player) TotalDamage

func (p *Player) TotalDamage() int

TotalDamage returns the total health damage done by the player.

func (*Player) UtilityDamage

func (p *Player) UtilityDamage() int

UtilityDamage returns the total damage done by the player with grenades.

func (*Player) Velocity

func (p *Player) Velocity() r3.Vector

Velocity returns the player's velocity.

func (*Player) ViewDirectionX

func (p *Player) ViewDirectionX() float32

ViewDirectionX returns the Yaw value in degrees, 0 to 360.

func (*Player) ViewDirectionY

func (p *Player) ViewDirectionY() float32

ViewDirectionY returns the Pitch value in degrees, 270 to 90 (270=-90).

func (*Player) Weapons

func (p *Player) Weapons() []*Equipment

Weapons returns all weapons in the player's possession. Contains all entries from Player.Inventory but as a slice instead of a map.

type PlayerFlags

type PlayerFlags uint32

PlayerFlags wraps m_fFlags and provides accessors for the various known flags a player may have set.

func (PlayerFlags) Ducking

func (pf PlayerFlags) Ducking() bool

Ducking returns true if the player is/was fully crouched.

Fully ducked: Ducking() && DuckingKeyPressed()
Previously fully ducked, unducking in progress: Ducking() && !DuckingKeyPressed()
Fully unducked: !Ducking() && !DuckingKeyPressed()
Previously fully unducked, ducking in progress: !Ducking() && DuckingKeyPressed()

See m_fFlags FL_DUCKING https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188

func (PlayerFlags) DuckingKeyPressed

func (pf PlayerFlags) DuckingKeyPressed() bool

DuckingKeyPressed returns true if the player is holding the crouch key pressed.

Fully ducked: Ducking() && DuckingKeyPressed()
Previously fully ducked, unducking in progress: Ducking() && !DuckingKeyPressed()
Fully unducked: !Ducking() && !DuckingKeyPressed()
Previously fully unducked, ducking in progress: !Ducking() && DuckingKeyPressed()

See m_fFlags FL_ANIMDUCKING https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188

func (PlayerFlags) Get

func (pf PlayerFlags) Get(f PlayerFlags) bool

func (PlayerFlags) OnGround

func (pf PlayerFlags) OnGround() bool

OnGround returns true if the player is touching the ground. See m_fFlags FL_ONGROUND https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188

type PlayerInfo

type PlayerInfo struct {
	Version     int64  // Not available with CS2 demos
	XUID        uint64 // SteamID64
	Name        string
	UserID      int    // Not available with CS2 demos
	GUID        string // Not available with CS2 demos
	FriendsID   int    // Not available with CS2 demos
	FriendsName string // Not available with CS2 demos
	// Custom files stuff (CRC). Not available with CS2 demos
	CustomFiles0 int
	CustomFiles1 int
	CustomFiles2 int
	CustomFiles3 int
	// Amount of downloaded files from the server
	FilesDownloaded byte // Not available with CS2 demos
	// Bots
	IsFakePlayer bool
	// HLTV Proxy
	IsHltv bool
}

PlayerInfo contains information about a player such as their name and SteamID. Primarily intended for internal use.

type Team

type Team byte

Team is the type for the various TeamXYZ constants.

const (
	TeamUnassigned        Team = 0
	TeamSpectators        Team = 1
	TeamTerrorists        Team = 2
	TeamCounterTerrorists Team = 3
)

Team constants give information about which team a player is on.

type TeamState

type TeamState struct {
	Entity st.Entity

	// Terrorist TeamState for CTs, CT TeamState for Terrorists
	Opponent *TeamState
	// contains filtered or unexported fields
}

TeamState contains a team's ID, score, clan name & country flag.

func NewTeamState

func NewTeamState(team Team, membersCallback func(Team) []*Player, demoInfoProvider demoInfoProvider) TeamState

NewTeamState creates a new TeamState with the given Team and members callback function.

func (*TeamState) ClanName

func (ts *TeamState) ClanName() string

ClanName returns the team name (e.g. Fnatic).

func (*TeamState) CurrentEquipmentValue

func (ts *TeamState) CurrentEquipmentValue() (value int)

CurrentEquipmentValue returns the cumulative value of all equipment currently owned by the members of the team.

func (*TeamState) Flag

func (ts *TeamState) Flag() string

Flag returns the flag code (e.g. DE, FR, etc.).

Watch out, in some demos this is upper-case and in some lower-case.

func (*TeamState) FreezeTimeEndEquipmentValue

func (ts *TeamState) FreezeTimeEndEquipmentValue() (value int)

FreezeTimeEndEquipmentValue returns the cumulative value of all equipment owned by the members of the team at the end of the freeze-time of the current round.

func (*TeamState) ID

func (ts *TeamState) ID() int

ID returns the team ID, this stays the same even after switching sides.

func (*TeamState) Members

func (ts *TeamState) Members() []*Player

Members returns the players that are members of the team.

func (*TeamState) MoneySpentThisRound

func (ts *TeamState) MoneySpentThisRound() (value int)

MoneySpentThisRound returns the total amount of cash spent by the whole team in the current round.

func (*TeamState) MoneySpentTotal

func (ts *TeamState) MoneySpentTotal() (value int)

MoneySpentTotal returns the total amount of cash spent by the whole team during the whole game up to the current point.

func (*TeamState) RoundStartEquipmentValue

func (ts *TeamState) RoundStartEquipmentValue() (value int)

RoundStartEquipmentValue returns the cumulative value of all equipment owned by the members of the team at the start of the current round.

func (*TeamState) Score

func (ts *TeamState) Score() int

Score returns the current score of the team (usually 0-16 without overtime).

func (*TeamState) Team

func (ts *TeamState) Team() Team

Team returns the team for which the TeamState contains data.

type TrajectoryEntry

type TrajectoryEntry struct {
	Position r3.Vector
	FrameID  int
	Time     time.Duration
}

TrajectoryEntry represents the location of a grenade's trajectory at a specific point in time.

type ZoomLevel

type ZoomLevel int

ZoomLevel contains how far a player is zoomed in.

const (
	ZoomNone ZoomLevel = 0
	ZoomHalf ZoomLevel = 1
	ZoomFull ZoomLevel = 2
)

All currently known zoom levels.

Jump to

Keyboard shortcuts

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