@@ -141,15 +141,40 @@ func (e *Entity) ApplyBaseline(baseline map[int]PropValue) {
141
141
}
142
142
}
143
143
144
- const maxCoordInt = 16384
144
+ const (
145
+ maxCoordInt = 16384
146
+
147
+ propCellBits = "m_cellbits"
148
+ propCellX = "m_cellX"
149
+ propCellY = "m_cellY"
150
+ propCellZ = "m_cellZ"
151
+ propVecOrigin = "m_vecOrigin"
152
+ propVecOriginPlayerXY = "cslocaldata.m_vecOrigin"
153
+ propVecOriginPlayerZ = "cslocaldata.m_vecOrigin[2]"
154
+
155
+ serverClassPlayer = "CCSPlayer"
156
+ )
145
157
146
158
// Position returns the entity's position in world coordinates.
147
159
func (e * Entity ) Position () r3.Vector {
148
- cellWidth := 1 << uint (e .FindProperty ("m_cellbits" ).value .IntVal )
149
- cellX := e .FindProperty ("m_cellX" ).value .IntVal
150
- cellY := e .FindProperty ("m_cellY" ).value .IntVal
151
- cellZ := e .FindProperty ("m_cellZ" ).value .IntVal
152
- offset := e .FindProperty ("m_vecOrigin" ).value .VectorVal
160
+ // Player positions are calculated differently
161
+ if e .isPlayer () {
162
+ return e .positionPlayer ()
163
+ }
164
+
165
+ return e .positionDefault ()
166
+ }
167
+
168
+ func (e * Entity ) isPlayer () bool {
169
+ return e .ServerClass .Name == serverClassPlayer
170
+ }
171
+
172
+ func (e * Entity ) positionDefault () r3.Vector {
173
+ cellWidth := 1 << uint (e .FindProperty (propCellBits ).value .IntVal )
174
+ cellX := e .FindProperty (propCellX ).value .IntVal
175
+ cellY := e .FindProperty (propCellY ).value .IntVal
176
+ cellZ := e .FindProperty (propCellZ ).value .IntVal
177
+ offset := e .FindProperty (propVecOrigin ).value .VectorVal
153
178
154
179
return r3.Vector {
155
180
X : coordFromCell (cellX , cellWidth , offset .X ),
@@ -158,6 +183,16 @@ func (e *Entity) Position() r3.Vector {
158
183
}
159
184
}
160
185
186
+ func (e * Entity ) positionPlayer () r3.Vector {
187
+ xy := e .FindProperty (propVecOriginPlayerXY ).value .VectorVal
188
+ z := float64 (e .FindProperty (propVecOriginPlayerZ ).value .FloatVal )
189
+ return r3.Vector {
190
+ X : xy .X ,
191
+ Y : xy .Y ,
192
+ Z : z ,
193
+ }
194
+ }
195
+
161
196
// Returns a coordinate from a cell + offset
162
197
func coordFromCell (cell , cellWidth int , offset float64 ) float64 {
163
198
return float64 (cell * cellWidth - maxCoordInt ) + offset
0 commit comments