Documentation ¶
Overview ¶
Package common contains common types, constants and functions used over different demoinfocs packages.
Index ¶
- func ConvertSteamID32To64(steamID32 uint32) uint64
- func ConvertSteamID64To32(steamID64 uint64) uint32
- func ConvertSteamIDTxtTo32(steamID string) (uint32, error)
- type Bomb
- type DemoHeader
- type Equipment
- type EquipmentClass
- type EquipmentType
- type Fire
- type Fires
- type GamePhase
- type GrenadeProjectile
- type Inferno
- type Player
- func (p *Player) ActiveWeapon() *Equipment
- func (p *Player) Armor() int
- func (p *Player) Assists() int
- func (p *Player) ClanTag() string
- func (p *Player) ControlledBot() *Player
- func (p *Player) Deaths() int
- func (p *Player) EquipmentValueCurrent() int
- func (p *Player) EquipmentValueFreezeTimeEnd() int
- func (p *Player) EquipmentValueRoundStart() int
- func (p *Player) FlashDurationTime() time.Duration
- func (p *Player) FlashDurationTimeRemaining() time.Duration
- func (p *Player) HasDefuseKit() bool
- func (p *Player) HasHelmet() bool
- func (p *Player) HasSpotted(other *Player) bool
- func (p *Player) Health() int
- func (p *Player) IsAirborne() bool
- func (p *Player) IsAlive() bool
- func (p *Player) IsBlinded() bool
- func (p *Player) IsControllingBot() bool
- func (p *Player) IsDucking() bool
- func (p *Player) IsInBombZone() bool
- func (p *Player) IsInBuyZone() bool
- func (p *Player) IsScoped() bool
- func (p *Player) IsSpottedBy(other *Player) bool
- func (p *Player) IsWalking() bool
- func (p *Player) Kills() int
- func (p *Player) MVPs() int
- func (p *Player) Money() int
- func (p *Player) MoneySpentThisRound() int
- func (p *Player) MoneySpentTotal() int
- func (p *Player) Ping() int
- func (p *Player) Position() r3.Vector
- func (p *Player) ResourceEntity() st.Entity
- func (p *Player) Score() int
- func (p *Player) SteamID32() uint32
- func (p *Player) String() string
- func (p *Player) Velocity() r3.Vector
- func (p *Player) ViewDirectionX() float32
- func (p *Player) ViewDirectionY() float32
- func (p *Player) Weapons() []*Equipment
- type Team
- type TeamState
- func (ts *TeamState) ClanName() string
- func (ts *TeamState) CurrentEquipmentValue() (value int)
- func (ts *TeamState) Flag() string
- func (ts *TeamState) FreezeTimeEndEquipmentValue() (value int)
- func (ts *TeamState) ID() int
- func (ts *TeamState) Members() []*Player
- func (ts *TeamState) MoneySpentThisRound() (value int)
- func (ts *TeamState) MoneySpentTotal() (value int)
- func (ts *TeamState) RoundStartEquipmentValue() (value int)
- func (ts *TeamState) Score() int
- func (ts *TeamState) Team() Team
- type ZoomLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertSteamID32To64 ¶
ConvertSteamID32To64 converts a Steam-ID in 32-bit format to a 64-bit variant. See https://developer.valvesoftware.com/wiki/SteamID
func ConvertSteamID64To32 ¶
ConvertSteamID64To32 converts a Steam-ID in 64-bit format to a 32-bit variant. See https://developer.valvesoftware.com/wiki/SteamID
func ConvertSteamIDTxtTo32 ¶
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.
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. OriginalString string // E.g. 'models/weapons/w_rif_m4a1_s.mdl'. Used internally to differentiate alternative weapons (M4A4 / M4A1-S etc.). // 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 ¶
AmmoInMagazine returns the ammo left in the magazine. Returns CWeaponCSBase.m_iClip1 for most weapons and 1 for grenades.
func (*Equipment) AmmoReserve ¶
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 ¶
AmmoType returns the weapon's ammo type, mostly (only?) relevant for grenades.
func (*Equipment) Class ¶
func (e *Equipment) Class() EquipmentClass
Class returns the class of the equipment. E.g. pistol, smg, heavy etc.
func (*Equipment) String ¶
String returns a human readable name for the equipment. E.g. 'AK-47', 'UMP-45', 'Smoke Grenade' etc.
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 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 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) ConvexHull2D ¶
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.
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.
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 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 ¶
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.
type Inferno ¶
Inferno is a list of Fires with helper functions. Also contains already extinguished fires.
See also: Inferno.Active() and Fire.IsBurning
func NewInferno ¶
NewInferno creates a inferno and sets the Unique-ID.
Intended for internal use only.
func (*Inferno) Fires ¶
Fires returns all fires (past + present). Some are currently active and some have extinguished (see Fire.IsBurning).
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/DavyVan/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 ¶
ActiveWeapon returns the currently active / equipped weapon of the player.
func (*Player) Assists ¶
Assists returns the amount of assists the player has as shown on the scoreboard.
func (*Player) ControlledBot ¶
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) Deaths ¶
Deaths returns the amount of deaths the player has as shown on the scoreboard.
func (*Player) EquipmentValueCurrent ¶
EquipmentValueCurrent returns the current value of equipment in the player's inventory.
func (*Player) EquipmentValueFreezeTimeEnd ¶
EquipmentValueFreezeTimeEnd returns the value of equipment in the player's inventory at the end of the freeze time.
func (*Player) EquipmentValueRoundStart ¶
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) FlashDurationTime ¶
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 ¶
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) HasDefuseKit ¶
HasDefuseKit returns true if the player currently has a defuse kit in his inventory.
func (*Player) HasSpotted ¶
HasSpotted returns true if the player has spotted the other player.
func (*Player) IsAirborne ¶
IsAirborne returns true if the player is jumping or falling.
func (*Player) IsBlinded ¶
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 ¶
IsControllingBot returns true if the player is currently controlling a bot. See also ControlledBot().
func (*Player) IsInBombZone ¶
IsInBombZone returns whether the player is currently in the bomb zone or not.
func (*Player) IsInBuyZone ¶
IsInBuyZone returns whether the player is currently in the buy zone or not.
func (*Player) IsSpottedBy ¶
IsSpottedBy returns true if the player has been spotted by the other player.
func (*Player) IsWalking ¶
IsWalking returns whether the player is currently walking (sneaking) in or not.
func (*Player) MVPs ¶
MVPs returns the amount of Most-Valuable-Player awards the player has as shown on the scoreboard.
func (*Player) MoneySpentThisRound ¶
MoneySpentThisRound returns the amount of money the player has spent in the current round.
func (*Player) MoneySpentTotal ¶
MoneySpentTotal returns the total amount of money the player has spent in the current match.
func (*Player) Position ¶
Position returns the in-game coordinates. Like the ones you get from cl_showpos 1.
func (*Player) ResourceEntity ¶
ResourceEntity returns the player's CCSPlayerResource entity.
func (*Player) SteamID32 ¶
SteamID32 converts SteamID64 to the 32-bit SteamID variant and returns the result. See https://developer.valvesoftware.com/wiki/SteamID
func (*Player) ViewDirectionX ¶
ViewDirectionX returns the Yaw value in degrees, 0 to 360.
func (*Player) ViewDirectionY ¶
ViewDirectionY returns the Pitch value in degrees, 270 to 90 (270=-90).
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 ¶
NewTeamState creates a new TeamState with the given Team and members callback function.
func (*TeamState) CurrentEquipmentValue ¶
CurrentEquipmentValue returns the cumulative value of all equipment currently owned by the members of the team.
func (*TeamState) Flag ¶
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 ¶
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) MoneySpentThisRound ¶
MoneySpentThisRound returns the total amount of cash spent by the whole team in the current round.
func (*TeamState) MoneySpentTotal ¶
MoneySpentThisRound returns the total amount of cash spent by the whole team during the whole game up to the current point.
func (*TeamState) RoundStartEquipmentValue ¶
RoundStartEquipmentValue returns the cumulative value of all equipment owned by the members of the team at the start of the current round.