common

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: MIT Imports: 8 Imported by: 30

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EquipmentElementNames added in v1.3.0

func EquipmentElementNames() map[EquipmentElement]string

EquipmentElementNames returns all human readable equipment names as map[EquipmentElement]string

func GamePhaseNames added in v1.3.0

func GamePhaseNames() map[GamePhase]string

GamePhaseNames returns all human readable game phase names as map[GamePhase]string

Types

type AdditionalPlayerInformation

type AdditionalPlayerInformation struct {
	Kills              int
	Deaths             int
	Assists            int
	Score              int
	MVPs               int
	Ping               int
	ClanTag            string
	TotalCashSpent     int
	CashSpentThisRound int
}

AdditionalPlayerInformation contains mostly scoreboard information.

type Bomb added in v1.0.0

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 added in v1.0.0

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 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 added in v0.4.0

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 added in v0.4.0

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).

func (DemoHeader) TickRate added in v1.0.0

func (h DemoHeader) TickRate() float64

TickRate returns the tick-rate the server ran on during the game. Deprecated: this function might return 0 in some cases (corrupt demo headers), use Parser.TickRate() instead. VolvoPlx128TixKTnxBye

func (DemoHeader) TickTime added in v1.0.0

func (h DemoHeader) TickTime() time.Duration

TickTime returns the time a single tick takes in seconds. Deprecated: this function might return 0 in some cases (corrupt demo headers), use Parser.TickTime() instead.

type Equipment

type Equipment struct {
	EntityID       int              // ID of the game entity
	Weapon         EquipmentElement // The type of weapon which the equipment instantiates.
	Owner          *Player          // The player carrying the equipment, not necessarily the buyer.
	AmmoType       int              // TODO: Remove this? doesn't seem applicable to CS:GO
	AmmoInMagazine int              // Amount of bullets in the weapon's magazine. Deprecated, use AmmoInMagazine2() instead.
	AmmoReserve    int              // Amount of reserve bullets
	OriginalString string           // E.g. 'models/weapons/w_rif_m4a1_s.mdl'. Used internally to differentiate alternative weapons (M4A4 / M4A1-S etc.).
	ZoomLevel      int              // How far the player has zoomed in on the weapon. 0=no zoom, 1=first level, 2=maximum zoom
	// 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 EquipmentElement) *Equipment

NewEquipment creates a new Equipment and sets the UniqueID.

Intended for internal use only.

func (Equipment) AmmoInMagazine2 added in v1.3.2

func (e Equipment) AmmoInMagazine2() int

AmmoInMagazine2 returns the ammo left in the magazine. Returns CWeaponCSBase.m_iClip1 for most weapons and 1 for grenades.

func (Equipment) AmmoReserve2 added in v1.3.2

func (e Equipment) AmmoReserve2() int

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

func (Equipment) Class

func (e Equipment) Class() EquipmentClass

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

func (Equipment) String added in v1.4.0

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 added in v0.5.4

func (e Equipment) UniqueID() int64

UniqueID returns the 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.

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: (EquipmentElement+99) / 100 = EquipmentClass

type EquipmentElement

type EquipmentElement int

EquipmentElement is the type for the various EqXYZ constants.

const (
	EqUnknown EquipmentElement = 0

	EqP2000        EquipmentElement = 1
	EqGlock        EquipmentElement = 2
	EqP250         EquipmentElement = 3
	EqDeagle       EquipmentElement = 4
	EqFiveSeven    EquipmentElement = 5
	EqDualBerettas EquipmentElement = 6
	EqDualBarettas EquipmentElement = 6 // Deprecated, use EqDualBerettas instead (spelling error)
	EqTec9         EquipmentElement = 7
	EqCZ           EquipmentElement = 8
	EqUSP          EquipmentElement = 9
	EqRevolver     EquipmentElement = 10

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

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

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

	EqZeus      EquipmentElement = 401
	EqKevlar    EquipmentElement = 402
	EqHelmet    EquipmentElement = 403
	EqBomb      EquipmentElement = 404
	EqKnife     EquipmentElement = 405
	EqDefuseKit EquipmentElement = 406
	EqWorld     EquipmentElement = 407

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

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

func EquipmentAlternative added in v1.3.2

func EquipmentAlternative(eq EquipmentElement) EquipmentElement

EquipmentAlternative returns the EquipmentElement 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) EquipmentElement

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

func (EquipmentElement) Class added in v0.5.1

func (e EquipmentElement) Class() EquipmentClass

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

func (EquipmentElement) String added in v0.5.2

func (e EquipmentElement) String() string

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

type Fire added in v1.0.0

type Fire struct {
	r3.Vector

	IsBurning bool
}

Fire is a component of an Inferno.

type GamePhase added in v1.0.0

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 added in v1.0.0

func (r GamePhase) String() string

type GrenadeProjectile added in v0.5.4

type GrenadeProjectile struct {
	EntityID int
	// Deprecated: Weapon exists for historical compatibility
	// and should not be used. To access the weapon corresponding to his GrenadeProjectile,
	// use the WeaponInstance.Weapon instead.
	Weapon         EquipmentElement
	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
	Position       r3.Vector
	Trajectory     []r3.Vector // List of all known locations 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 added in v0.5.4

func NewGrenadeProjectile() *GrenadeProjectile

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

Intended for internal use only.

func (GrenadeProjectile) UniqueID added in v0.5.4

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.

type Inferno added in v1.0.0

type Inferno struct {
	Entity   st.IEntity
	EntityID int // Same as Entity.ID(), use Entity.ID() instead
	Fires    []*Fire
	// 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 added in v1.0.0

func NewInferno(demoInfoProvider demoInfoProvider, entity st.IEntity) *Inferno

NewInferno creates a inferno and sets the Unique-ID.

Intended for internal use only.

func (Inferno) Active added in v1.0.0

func (inf Inferno) Active() Inferno

Active returns an Inferno containing only the active fires of the original. The returned Inferno will have the same Unique-ID as the original.

func (Inferno) ConvexHull2D added in v1.0.0

func (inf Inferno) 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 (Inferno) ConvexHull3D added in v1.0.0

func (inf Inferno) ConvexHull3D() quickhull.ConvexHull

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

func (Inferno) Owner deprecated added in v1.3.0

func (inf Inferno) Owner() *Player

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

Deprecated: Owner() exists for historical compatibility and should not be used. Use Thrower() instead.

func (Inferno) Thrower added in v1.7.0

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 added in v1.0.0

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 {
	SteamID                     int64     // int64 representation of the User's Steam ID
	Position                    r3.Vector // In-game coordinates. Like the one you get from cl_showpos 1
	LastAlivePosition           r3.Vector // The location where the player was last alive. Should be equal to Position if the player is still alive.
	Velocity                    r3.Vector // Movement velocity
	EntityID                    int       // The ID of the player-entity, see Entity field
	UserID                      int       // Mostly used in game-events to address this player
	Name                        string    // Steam / in-game user name
	Hp                          int
	Armor                       int
	Money                       int
	CurrentEquipmentValue       int
	FreezetimeEndEquipmentValue int
	RoundStartEquipmentValue    int
	ActiveWeaponID              int                          // Used internally to set the active weapon, see ActiveWeapon()
	RawWeapons                  map[int]*Equipment           // All weapons the player is currently carrying
	AmmoLeft                    [32]int                      // Ammo left for special weapons (e.g. grenades), index corresponds Equipment.AmmoType
	Entity                      st.IEntity                   // May be nil between player-death and re-spawn
	AdditionalPlayerInformation *AdditionalPlayerInformation // Mostly scoreboard information such as kills, deaths, etc.
	ViewDirectionX              float32                      // Yaw in degrees, 0 to 360
	ViewDirectionY              float32                      // Pitch in degrees, 270 to 90 (270=-90)
	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
	IsBot                       bool // True if this is a bot-entity. See also IsControllingBot and ControlledBot().
	IsConnected                 bool
	IsDucking                   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
	HasDefuseKit                bool
	HasHelmet                   bool
	// 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.

func (*Player) CashSpentThisRound added in v1.2.0

func (p *Player) CashSpentThisRound() int

CashSpentThisRound returns the amount of cash the player spent in the current round.

Deprecated, use Player.AdditionalPlayerInformation.CashSpentThisRound instead.

func (*Player) CashSpentTotal added in v1.2.0

func (p *Player) CashSpentTotal() int

CashSpentTotal returns the amount of cash the player spent during the whole game up to the current point.

Deprecated, use Player.AdditionalPlayerInformation.TotalCashSpent instead.

func (*Player) ControlledBot added in v1.7.0

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) FlashDurationTime added in v1.0.0

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 added in v1.1.0

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) HasSpotted added in v1.2.0

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

HasSpotted returns true if the player has spotted the other player.

func (*Player) IsAirborne added in v1.5.0

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 Hp of the player are > 0.

func (*Player) IsBlinded added in v1.0.0

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 added in v1.7.0

func (p *Player) IsControllingBot() bool

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

func (*Player) IsInBombZone added in v1.2.0

func (p *Player) IsInBombZone() bool

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

func (*Player) IsInBuyZone added in v1.2.0

func (p *Player) IsInBuyZone() bool

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

func (*Player) IsScoped added in v1.2.0

func (p *Player) IsScoped() bool

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

func (*Player) IsSpottedBy added in v1.2.0

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

IsSpottedBy returns true if the player has been spotted by the other player.

func (*Player) IsWalking added in v1.2.0

func (p *Player) IsWalking() bool

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

func (*Player) String added in v1.4.0

func (p *Player) String() string

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

func (*Player) Weapons

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

Weapons returns all weapons in the player's possession.

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 added in v1.0.0

type TeamState struct {

	// ID stays the same even after switching sides.
	ID int

	Score    int
	ClanName string

	// Flag, e.g. DE, FR, etc.
	//
	// Watch out, in some demos this is upper-case and in some lower-case.
	Flag string

	// 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 added in v1.0.0

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

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

func (TeamState) CashSpentThisRound added in v1.2.0

func (ts TeamState) CashSpentThisRound() (value int)

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

func (TeamState) CashSpentTotal added in v1.2.0

func (ts TeamState) CashSpentTotal() (value int)

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

func (TeamState) CurrentEquipmentValue added in v1.2.0

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

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

func (TeamState) FreezeTimeEndEquipmentValue added in v1.2.0

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) Members added in v1.2.0

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

Members returns the members of the team.

func (TeamState) RoundStartEquipmentValue added in v1.2.0

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) Team added in v1.0.0

func (ts TeamState) Team() Team

Team returns the team for which the TeamState contains data.

Jump to

Keyboard shortcuts

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