11package common
22
33import (
4- "encoding/binary"
5- "io"
6-
74 r3 "github.com/golang/geo/r3"
85
9- bit "github.com/markus-wa/demoinfocs-golang/bitread"
106 st "github.com/markus-wa/demoinfocs-golang/sendtables"
117)
128
@@ -25,26 +21,16 @@ type DemoHeader struct {
2521 SignonLength int
2622}
2723
28- // PlayerInfo contains general player information
29- type PlayerInfo struct {
30- Version int64
31- XUID int64
32- Name string
33- UserID int
34- GUID string
35- FriendsID int
36- FriendsName string
37- // Custom files stuff (CRC)
38- CustomFiles0 int
39- CustomFiles1 int
40- CustomFiles2 int
41- CustomFiles3 int
42- // Amount of downloaded files from the server
43- FilesDownloaded byte
44- // Bots
45- IsFakePlayer bool
46- // HLTV Proxy
47- IsHltv bool
24+ // FrameRate returns the frame rate of the demo (frames / demo-ticks per second).
25+ // Not necessarily the tick-rate the server ran on during the game.
26+ // VolvoPlx128TixKTnxBye
27+ func (h DemoHeader ) FrameRate () float32 {
28+ return float32 (h .PlaybackFrames ) / h .PlaybackTime
29+ }
30+
31+ // FrameTime returns the time a frame / demo-tick takes in seconds.
32+ func (h DemoHeader ) FrameTime () float32 {
33+ return h .PlaybackTime / float32 (h .PlaybackFrames )
4834}
4935
5036// Player contains mostly game-relevant player information.
@@ -77,6 +63,7 @@ type Player struct {
7763 IsDisconnected bool
7864 HasDefuseKit bool
7965 HasHelmet bool
66+ Connected bool
8067}
8168
8269// IsAlive returns true if the Hp of the player are > 0.
@@ -136,32 +123,6 @@ func NewSkinEquipment(eqName string, skinID string) Equipment {
136123 return Equipment {Weapon : wep , SkinID : skinID }
137124}
138125
139- // ParsePlayerInfo parses player information from a byte stream.
140- func ParsePlayerInfo (reader io.Reader ) * PlayerInfo {
141- br := bit .NewSmallBitReader (reader )
142- res := & PlayerInfo {
143- Version : int64 (binary .BigEndian .Uint64 (br .ReadBytes (8 ))),
144- XUID : int64 (binary .BigEndian .Uint64 (br .ReadBytes (8 ))),
145- Name : br .ReadCString (128 ),
146- UserID : int (int32 (binary .BigEndian .Uint32 (br .ReadBytes (4 )))),
147- GUID : br .ReadCString (33 ),
148- FriendsID : int (int32 (binary .BigEndian .Uint32 (br .ReadBytes (4 )))),
149- FriendsName : br .ReadCString (128 ),
150-
151- IsFakePlayer : br .ReadSingleByte ()& 0xff != 0 ,
152- IsHltv : br .ReadSingleByte ()& 0xff != 0 ,
153-
154- CustomFiles0 : int (br .ReadInt (32 )),
155- CustomFiles1 : int (br .ReadInt (32 )),
156- CustomFiles2 : int (br .ReadInt (32 )),
157- CustomFiles3 : int (br .ReadInt (32 )),
158-
159- FilesDownloaded : br .ReadSingleByte (),
160- }
161- br .Pool ()
162- return res
163- }
164-
165126// NewPlayer creates a *Player with an initialized equipment map.
166127func NewPlayer () * Player {
167128 return & Player {RawWeapons : make (map [int ]* Equipment )}
0 commit comments