@@ -82,9 +82,19 @@ func (p *parser) bindBomb() {
8282 bomb .LastOnGroundPosition = pos
8383 })
8484
85- bombEntity .Property ("m_hOwner" ).OnUpdate (func (val st.PropertyValue ) {
86- bomb .Carrier = p .gameState .Participants ().FindByHandle (val .IntVal )
87- })
85+ if p .isSource2 () {
86+ bombEntity .Property ("m_hOwnerEntity" ).OnUpdate (func (val st.PropertyValue ) {
87+ bomb .Carrier = p .gameState .Participants ().FindByHandle64 (val .Handle ())
88+ })
89+ } else {
90+ bombEntity .Property ("m_hOwner" ).OnUpdate (func (val st.PropertyValue ) {
91+ if val .IntVal < 0 {
92+ panic ("bomb owner < 0" )
93+ }
94+
95+ bomb .Carrier = p .gameState .Participants ().FindByHandle (val .IntVal )
96+ })
97+ }
8898
8999 bombEntity .Property ("m_bStartedArming" ).OnUpdate (func (val st.PropertyValue ) {
90100 if val .IntVal != 0 {
@@ -107,7 +117,6 @@ func (p *parser) bindBomb() {
107117}
108118
109119func (p * parser ) bindTeamStates () {
110- fmt .Println (p .stParser .ServerClasses ().FindByName ("CCSTeam" ))
111120 p .stParser .ServerClasses ().FindByName ("CCSTeam" ).OnEntityCreated (func (entity st.Entity ) {
112121 teamVal := entity .PropertyValueMust ("m_szTeamname" )
113122 team := teamVal .StringVal
@@ -170,20 +179,30 @@ func (p *parser) bindBombSites() {
170179 t := new (boundingBoxInformation )
171180 p .triggers [baseTrigger .ID ()] = t
172181
173- baseTrigger .BindProperty ("m_Collision.m_vecMins" , & t .min , st .ValTypeVector )
174- baseTrigger .BindProperty ("m_Collision.m_vecMaxs" , & t .max , st .ValTypeVector )
182+ if p .isSource2 () {
183+ baseTrigger .BindProperty ("m_vecMins" , & t .min , st .ValTypeVector )
184+ baseTrigger .BindProperty ("m_vecMaxs" , & t .max , st .ValTypeVector )
185+ } else {
186+ baseTrigger .BindProperty ("m_Collision.m_vecMins" , & t .min , st .ValTypeVector )
187+ baseTrigger .BindProperty ("m_Collision.m_vecMaxs" , & t .max , st .ValTypeVector )
188+ }
175189 })
176190}
177191
178192func (p * parser ) bindPlayers () {
179- fmt .Println (p .stParser .ServerClasses ().FindByName ("CCSPlayerPawn" ))
180- p .stParser .ServerClasses ().FindByName ("CCSPlayerPawn" ).OnEntityCreated (func (player st.Entity ) {
181- p .bindNewPlayer (player )
182- })
193+ if p .isSource2 () {
194+ p .stParser .ServerClasses ().FindByName ("CCSPlayerPawn" ).OnEntityCreated (func (player st.Entity ) {
195+ p .bindNewPlayer (player )
196+ })
197+ } else {
198+ p .stParser .ServerClasses ().FindByName ("CCSPlayerResource" ).OnEntityCreated (func (entity st.Entity ) {
199+ p .gameState .playerResourceEntity = entity
200+ })
183201
184- p .stParser .ServerClasses ().FindByName ("CCSPlayerResource" ).OnEntityCreated (func (entity st.Entity ) {
185- p .gameState .playerResourceEntity = entity
186- })
202+ p .stParser .ServerClasses ().FindByName ("CCSPlayer" ).OnEntityCreated (func (player st.Entity ) {
203+ p .bindNewPlayer (player )
204+ })
205+ }
187206}
188207
189208func (p * parser ) getOrCreatePlayer (entityID int , rp * common.PlayerInfo ) (isNew bool , player * common.Player ) {
@@ -263,18 +282,32 @@ func (p *parser) bindNewPlayer(playerEntity st.Entity) {
263282 pl .FlashDuration = val .FloatVal
264283 })
265284
266- p .bindPlayerWeapons (playerEntity , pl )
285+ if ! p .isSource2 () {
286+ p .bindPlayerWeapons (playerEntity , pl ) // FIXME: make weapons work for S2
267287
268- // Active weapon
269- playerEntity .Property ("m_hActiveWeapon" ).OnUpdate (func (val st.PropertyValue ) {
270- pl .IsReloading = false
271- })
288+ for i := 0 ; i < 32 ; i ++ {
289+ i2 := i // Copy so it stays the same
290+ playerEntity .BindProperty ("m_iAmmo." + fmt .Sprintf ("%03d" , i2 ), & pl .AmmoLeft [i2 ], st .ValTypeInt )
291+ }
292+ }
272293
273- for i := 0 ; i < 32 ; i ++ {
274- i2 := i // Copy so it stays the same
275- playerEntity .BindProperty ("m_iAmmo." + fmt .Sprintf ("%03d" , i2 ), & pl .AmmoLeft [i2 ], st .ValTypeInt )
294+ var (
295+ activeWep st.Property
296+ spottedByPrefix string
297+ )
298+
299+ if p .isSource2 () {
300+ activeWep = playerEntity .Property ("m_pWeaponServices.m_hActiveWeapon" )
301+ spottedByPrefix = "m_bSpottedByMask.000"
302+ } else {
303+ activeWep = playerEntity .Property ("m_hActiveWeapon" )
304+ spottedByPrefix = "m_bSpottedByMask.00"
276305 }
277306
307+ activeWep .OnUpdate (func (val st.PropertyValue ) {
308+ pl .IsReloading = false
309+ })
310+
278311 playerEntity .Property ("m_bIsDefusing" ).OnUpdate (func (val st.PropertyValue ) {
279312 if p .gameState .currentDefuser == pl && pl .IsDefusing && val .IntVal == 0 {
280313 p .eventDispatcher .Dispatch (events.BombDefuseAborted {Player : pl })
@@ -284,14 +317,14 @@ func (p *parser) bindNewPlayer(playerEntity st.Entity) {
284317 pl .IsDefusing = val .IntVal != 0
285318 })
286319
287- spottedByMaskProp := playerEntity .Property ("m_bSpottedByMask.000 " )
320+ spottedByMaskProp := playerEntity .Property (spottedByPrefix + "0 " )
288321 if spottedByMaskProp != nil {
289322 spottersChanged := func (val st.PropertyValue ) {
290323 p .eventDispatcher .Dispatch (events.PlayerSpottersChanged {Spotted : pl })
291324 }
292325
293326 spottedByMaskProp .OnUpdate (spottersChanged )
294- playerEntity .Property ("m_bSpottedByMask.001 " ).OnUpdate (spottersChanged )
327+ playerEntity .Property (spottedByPrefix + "1 " ).OnUpdate (spottersChanged )
295328 }
296329
297330 if isNew {
@@ -415,7 +448,7 @@ func (p *parser) bindGrenadeProjectiles(entity st.Entity) {
415448 })
416449
417450 entity .Property ("m_hOwnerEntity" ).OnUpdate (func (val st.PropertyValue ) {
418- proj .Owner = p .gameState .Participants ().FindByHandle (val .IntVal )
451+ proj .Owner = p .gameState .Participants ().FindByHandle64 (val .Handle () )
419452 })
420453
421454 entity .OnPositionUpdate (func (newPos r3.Vector ) {
@@ -550,12 +583,16 @@ func (p *parser) infernoExpired(inf *common.Inferno) {
550583
551584//nolint:funlen
552585func (p * parser ) bindGameRules () {
553- grPrefix := func (s string ) string {
554- return fmt .Sprintf ("%s.%s" , gameRulesPrefix , s )
555- }
556-
557586 gameRules := p .ServerClasses ().FindByName ("CCSGameRulesProxy" )
558587 gameRules .OnEntityCreated (func (entity st.Entity ) {
588+ grPrefix := func (s string ) string {
589+ if p .isSource2 () {
590+ return fmt .Sprintf ("%s.%s" , gameRulesPrefixS2 , s )
591+ }
592+
593+ return fmt .Sprintf ("%s.%s" , gameRulesPrefix , s )
594+ }
595+
559596 p .gameState .rules .entity = entity
560597
561598 entity .Property (grPrefix ("m_gamePhase" )).OnUpdate (func (val st.PropertyValue ) {
0 commit comments