Skip to content

Commit 338f547

Browse files
committed
Utilize BitReader.Skip()
1 parent 8d8646e commit 338f547

File tree

5 files changed

+75
-79
lines changed

5 files changed

+75
-79
lines changed

demopacket.go

Lines changed: 50 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import (
55
"sync"
66

77
proto "github.com/gogo/protobuf/proto"
8-
r3 "github.com/golang/geo/r3"
98

10-
bit "github.com/markus-wa/demoinfocs-golang/bitread"
119
msg "github.com/markus-wa/demoinfocs-golang/msg"
1210
)
1311

@@ -20,9 +18,9 @@ var byteSlicePool sync.Pool = sync.Pool{
2018

2119
func (p *Parser) parsePacket() {
2220
// Booooring
23-
parseCommandInfo(p.bitReader)
24-
p.bitReader.ReadInt(32) // SeqNrIn
25-
p.bitReader.ReadInt(32) // SeqNrOut
21+
// 152 bytes CommandInfo, 4 bytes SeqNrIn, 4 bytes SeqNrOut
22+
// See at the bottom what the CommandInfo would contain if you are interested.
23+
p.bitReader.Skip((152 + 4 + 4) << 3)
2624

2725
// Here we go
2826
p.bitReader.BeginChunk(p.bitReader.ReadSignedInt(32) << 3)
@@ -92,69 +90,50 @@ func (p *Parser) parsePacket() {
9290
p.bitReader.EndChunk()
9391
}
9492

95-
// TODO: Find out what all this is good for and why we didn't use the removed functions on seVector, split & commandInfo
96-
type commandInfo struct {
97-
splits [2]split
98-
}
99-
100-
type split struct {
101-
flags int
102-
103-
viewOrigin seVector
104-
viewAngles r3.Vector
105-
localViewAngles r3.Vector
106-
107-
viewOrigin2 seVector
108-
viewAngles2 r3.Vector
109-
localViewAngles2 r3.Vector
110-
}
111-
type seVector struct {
112-
r3.Vector
113-
}
114-
115-
type boundingBoxInformation struct {
116-
index int
117-
min r3.Vector
118-
max r3.Vector
119-
}
120-
121-
func (bbi boundingBoxInformation) contains(point r3.Vector) bool {
122-
return point.X >= bbi.min.X && point.X <= bbi.max.X &&
123-
point.Y >= bbi.min.Y && point.Y <= bbi.max.Y &&
124-
point.Z >= bbi.min.Z && point.Z <= bbi.max.Z
125-
}
126-
127-
type bombsiteInfo struct {
128-
index int
129-
center r3.Vector
130-
}
131-
132-
func parseCommandInfo(r *bit.BitReader) commandInfo {
133-
return commandInfo{splits: [2]split{parseSplit(r), parseSplit(r)}}
134-
}
135-
136-
func parseSplit(r *bit.BitReader) split {
137-
return split{
138-
flags: r.ReadSignedInt(32),
139-
140-
viewOrigin: parseSEVector(r),
141-
viewAngles: parseVector(r),
142-
localViewAngles: parseVector(r),
143-
144-
viewOrigin2: parseSEVector(r),
145-
viewAngles2: parseVector(r),
146-
localViewAngles2: parseVector(r),
147-
}
148-
}
149-
150-
func parseSEVector(r *bit.BitReader) seVector {
151-
return seVector{parseVector(r)}
152-
}
153-
154-
func parseVector(r *bit.BitReader) r3.Vector {
155-
return r3.Vector{
156-
X: float64(r.ReadFloat()),
157-
Y: float64(r.ReadFloat()),
158-
Z: float64(r.ReadFloat()),
159-
}
160-
}
93+
/*
94+
Format of 'CommandInfos' - I honestly have no clue what they are good for.
95+
If you find a use for this please let me know!
96+
97+
Here is all i know:
98+
99+
CommandInfo [152 bytes]
100+
- [2]Split
101+
102+
Split [76 bytes]
103+
- flags [4 bytes]
104+
- viewOrigin [12 bytes]
105+
- viewAngles [12 bytes]
106+
- localViewAngles [12 bytes]
107+
- viewOrigin2 [12 bytes]
108+
- viewAngles2 [12 bytes]
109+
- localViewAngles2 [12 bytes]
110+
111+
Origin [12 bytes]
112+
- X [4 bytes]
113+
- Y [4 bytes]
114+
- Z [4 bytes]
115+
116+
Angle [12 bytes]
117+
- X [4 bytes]
118+
- Y [4 bytes]
119+
- Z [4 bytes]
120+
121+
They are parsed in the following order:
122+
split1.flags
123+
split1.viewOrigin.x
124+
split1.viewOrigin.y
125+
split1.viewOrigin.z
126+
split1.viewAngles.x
127+
split1.viewAngles.y
128+
split1.viewAngles.z
129+
split1.localViewAngles.x
130+
split1.localViewAngles.y
131+
split1.localViewAngles.z
132+
split1.viewOrigin2...
133+
split1.viewAngles2...
134+
split1.localViewAngles2...
135+
split2.flags
136+
...
137+
138+
Or just check this file's history for an example on how to parse them
139+
*/

packet_handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (p *Parser) handlePacketEntities(pe *msg.CSVCMsg_PacketEntities) {
5858

5959
func (p *Parser) readEnterPVS(reader *bit.BitReader, entityID int) *st.Entity {
6060
scID := int(reader.ReadInt(p.stParser.ClassBits()))
61-
reader.ReadInt(10) // Serial Number
61+
reader.Skip(10) // Serial Number
6262

6363
newEntity := st.NewEntity(entityID, p.stParser.ServerClasses()[scID])
6464
newEntity.ServerClass.FireEntityCreatedEvent(newEntity)

parser.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"sync"
88

9+
r3 "github.com/golang/geo/r3"
910
dp "github.com/markus-wa/godispatch"
1011

1112
bit "github.com/markus-wa/demoinfocs-golang/bitread"
@@ -53,6 +54,23 @@ type Parser struct {
5354
errLock sync.Mutex
5455
}
5556

57+
type bombsiteInfo struct {
58+
index int
59+
center r3.Vector
60+
}
61+
62+
type boundingBoxInformation struct {
63+
index int
64+
min r3.Vector
65+
max r3.Vector
66+
}
67+
68+
func (bbi boundingBoxInformation) contains(point r3.Vector) bool {
69+
return point.X >= bbi.min.X && point.X <= bbi.max.X &&
70+
point.Y >= bbi.min.Y && point.Y <= bbi.max.Y &&
71+
point.Z >= bbi.min.Z && point.Z <= bbi.max.Z
72+
}
73+
5674
// Map returns the map name. E.g. de_dust2 or de_inferno.
5775
// Deprecated, use Header().MapName instead.
5876
func (p *Parser) Map() string {

parsing.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (p *Parser) parseFrame() bool {
152152
p.msgQueue <- ingameTickNumber(p.bitReader.ReadSignedInt(32))
153153

154154
// Skip 'player slot'
155-
p.bitReader.ReadSingleByte()
155+
p.bitReader.Skip(8)
156156

157157
switch cmd {
158158
case dcSynctick:
@@ -163,8 +163,7 @@ func (p *Parser) parseFrame() bool {
163163

164164
case dcConsoleCommand:
165165
// Skip
166-
p.bitReader.BeginChunk(p.bitReader.ReadSignedInt(32) << 3)
167-
p.bitReader.EndChunk()
166+
p.bitReader.Skip(p.bitReader.ReadSignedInt(32) << 3)
168167

169168
case dcDataTables:
170169
p.msgDispatcher.SyncQueues(p.msgQueue)
@@ -183,9 +182,8 @@ func (p *Parser) parseFrame() bool {
183182

184183
case dcUserCommand:
185184
// Skip
186-
p.bitReader.ReadInt(32)
187-
p.bitReader.BeginChunk(p.bitReader.ReadSignedInt(32) << 3)
188-
p.bitReader.EndChunk()
185+
p.bitReader.Skip(32)
186+
p.bitReader.Skip(p.bitReader.ReadSignedInt(32) << 3)
189187

190188
case dcSignon:
191189
fallthrough

stringtables.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ func (p *Parser) parseSingleStringTable(name string) {
5151
}
5252
}
5353
}
54+
5455
// Client side stuff, dgaf
5556
if p.bitReader.ReadBit() {
5657
strings2 := p.bitReader.ReadSignedInt(16)
5758
for i := 0; i < strings2; i++ {
5859
p.bitReader.ReadString()
5960
if p.bitReader.ReadBit() {
60-
p.bitReader.ReadBytes(p.bitReader.ReadSignedInt(16))
61+
p.bitReader.Skip(p.bitReader.ReadSignedInt(16))
6162
}
6263
}
6364
}

0 commit comments

Comments
 (0)