@@ -328,7 +328,8 @@ int Hooks::dServerFireTerrorBullets(int playerId, const Vector &vecOrigin, const
328328 // Clients
329329 else if (mGame ->playersVRInfo [playerId].isUsingVR )
330330 {
331- vecNewAngles = mGame ->playersVRInfo [playerId].controllerAngles ;
331+ vecNewOrigin = mGame ->playersVRInfo [playerId].controllerPos ;
332+ vecNewAngles = mGame ->playersVRInfo [playerId].controllerAngle ;
332333 }
333334
334335 return hkServerFireTerrorBullets.fOriginal (playerId, vecNewOrigin, vecNewAngles, a4, a5, a6, a7);
@@ -368,11 +369,27 @@ int Hooks::dReadUsercmd(void *buf, CUserCmd *move, CUserCmd *from)
368369 hkReadUsercmd.fOriginal (buf, move, from);
369370
370371 int i = mGame ->currentUsercmdID ;
371- if (move->viewangles . z == - 1. 0 ) // Signal for VR CUserCmd
372+ if (move->tick_count < 0 ) // Signal for VR CUserCmd
372373 {
374+ move->tick_count *= -1 ;
375+
373376 mGame ->playersVRInfo [i].isUsingVR = true ;
374- mGame ->playersVRInfo [i].controllerAngles .x = (float )move->mousedx / 10 ;
375- mGame ->playersVRInfo [i].controllerAngles .y = (float )move->mousedy / 10 ;
377+ mGame ->playersVRInfo [i].controllerAngle .x = (float )move->mousedx / 10 ;
378+ mGame ->playersVRInfo [i].controllerAngle .y = (float )move->mousedy / 10 ;
379+ mGame ->playersVRInfo [i].controllerPos .x = move->viewangles .z ;
380+ mGame ->playersVRInfo [i].controllerPos .y = move->upmove ;
381+
382+ // Decode viewangles.x
383+ int decodedZInt = (move->viewangles .x / 10000 );
384+ float decodedAngle = abs ((float )(move->viewangles .x - (decodedZInt * 10000 )) / 10 );
385+ decodedAngle -= 360 ;
386+ float decodedZ = (float )decodedZInt / 10 ;
387+
388+ mGame ->playersVRInfo [i].controllerPos .z = decodedZ;
389+
390+ move->viewangles .x = decodedAngle;
391+ move->viewangles .z = 0 ;
392+ move->upmove = 0 ;
376393 }
377394 else
378395 {
@@ -395,16 +412,37 @@ int Hooks::dWriteUsercmd(void *buf, CUserCmd *to, CUserCmd *from)
395412 CVerifiedUserCmd *pVerified = &pVerifiedCommands[(to->command_number ) % 150 ];
396413
397414 // Signal to the server that this CUserCmd has VR info
398- to->viewangles . z = -1 ;
415+ to->tick_count * = -1 ;
399416
400417 QAngle controllerAngles = mVR ->GetRecommendedViewmodelAbsAngle ();
401418 to->mousedx = controllerAngles.x * 10 ; // Strip off 2nd decimal to save bits.
402419 to->mousedy = controllerAngles.y * 10 ;
403420
421+ Vector controllerPos = mVR ->GetRecommendedViewmodelAbsPos ();
422+ to->viewangles .z = controllerPos.x ;
423+ to->upmove = controllerPos.y ;
424+
425+ // Space in CUserCmd is tight, so encode viewangle.x and controllerPos.z together.
426+ // Encoding will overflow if controllerPos.z goes beyond +-21474.8
427+ float xAngle = to->viewangles .x ;
428+ int encodedAngle = (xAngle + 360 ) * 10 ;
429+ int encoding = (int )(controllerPos.z * 10 ) * 10000 ;
430+ encoding += encoding < 0 ? -encodedAngle : encodedAngle;
431+ to->viewangles .x = encoding;
432+
433+ hkWriteUsercmd.fOriginal (buf, to, from);
434+
435+ to->viewangles .x = xAngle;
436+ to->tick_count *= -1 ;
437+ to->viewangles .z = 0 ;
438+ to->upmove = 0 ;
439+
404440 // Must recalculate checksum for the edited CUserCmd or gunshots will sound
405441 // terrible in multiplayer.
406442 pVerified->m_cmd = *to;
407443 pVerified->m_crc = to->GetChecksum ();
444+ return 1 ;
445+
408446 }
409447 return hkWriteUsercmd.fOriginal (buf, to, from);
410448}
0 commit comments