@@ -156,8 +156,6 @@ int Hooks::initSourceHooks()
156156 hkRotateObject.createHook ((LPVOID)(m_Game->m_Offsets ->RotateObject .address ), &dRotateObject);
157157 hkEyeAngles.createHook ((LPVOID)(m_Game->m_Offsets ->EyeAngles .address ), &dEyeAngles);
158158
159- hkMatrixBuildPerspectiveX.createHook ((LPVOID)(m_Game->m_Offsets ->MatrixBuildPerspectiveX .address ), &dMatrixBuildPerspectiveX);
160-
161159 // Portal Gun VFX
162160 hkGetDefaultFOV.createHook ((LPVOID)(m_Game->m_Offsets ->GetDefaultFOV .address ), &dGetDefaultFOV);
163161 hkGetFOV.createHook ((LPVOID)(m_Game->m_Offsets ->GetFOV .address ), &dGetFOV);
@@ -192,25 +190,10 @@ void __fastcall Hooks::dPrecache(void* ecx, void* edx) {
192190}
193191
194192void __fastcall Hooks::dClientThink (void * ecx, void * edx) {
195- // std::cout << "dSetDrawOnlyForSplitScreenUser: " << nSlot << "\n";
196-
197- /* int playerIndex = m_Game->m_EngineClient->GetLocalPlayer();
198- C_BasePlayer* localPlayer = (C_BasePlayer*)m_Game->GetClientEntity(playerIndex);
199-
200- if (localPlayer) {
201- uintptr_t* m_PointLaser = *(uintptr_t**)((uintptr_t)localPlayer + 0x23C0);
202-
203- if (!m_PointLaser) {
204- std::cout << "Creating Point Laser Beam Sight Thingy" << "\n";
205- m_Game->m_Hooks->CreatePingPointer(localPlayer, m_VR->m_AimPos);
206- }
207- }*/
208-
209193 hkClientThink.fOriginal (ecx);
210194}
211195
212196void __fastcall Hooks::dSetDrawOnlyForSplitScreenUser (void * ecx, void * edx, int nSlot) {
213- // std::cout << "dSetDrawOnlyForSplitScreenUser: " << nSlot << "\n";
214197 hkSetDrawOnlyForSplitScreenUser.fOriginal (ecx, -1 );
215198}
216199
@@ -272,6 +255,8 @@ void __fastcall Hooks::dRenderView(void *ecx, void *edx, CViewSetup &setup, CVie
272255 QAngle inGameAngle (hmdAngle.x , hmdAngle.y , hmdAngle.z );
273256 m_Game->m_EngineClient ->SetViewAngles (inGameAngle);
274257
258+ float aspect = setup.m_flAspectRatio ;
259+
275260 setup.x = 0 ;
276261 setup.y = 0 ;
277262 setup.width = m_VR->m_RenderWidth ;
@@ -337,6 +322,13 @@ void __fastcall Hooks::dRenderView(void *ecx, void *edx, CViewSetup &setup, CVie
337322 rndrContext->SetRenderTarget(NULL);
338323 rndrContext->Release();*/
339324
325+ if (m_VR->m_RenderWindow ) {
326+ setup.m_flAspectRatio = aspect;
327+
328+ // setup.width, setup.height
329+ hkRenderView.fOriginal (ecx, setup, hudViewSetup, nClearFlags, whatToDraw);
330+ }
331+
340332
341333 m_VR->m_RenderedNewFrame = true ;
342334}
@@ -435,180 +427,55 @@ void __fastcall Hooks::dCalcViewModelView(void *ecx, void *edx, const Vector &ey
435427
436428float __fastcall Hooks::dProcessUsercmds (void *ecx, void *edx, edict_t *player, void *buf, int numcmds, int totalcmds, int dropped_packets, bool ignore, bool paused)
437429{
438- // Function pointer for CBaseEntity::entindex
439- typedef int (__thiscall *tEntindex)(void *thisptr);
440- static tEntindex oEntindex = (tEntindex)(m_Game->m_Offsets ->CBaseEntity_entindex .address );
441-
442- IServerUnknown * pUnknown = player->m_pUnk ;
443- Server_BaseEntity *pPlayer = (Server_BaseEntity*)pUnknown->GetBaseEntity ();
430+ Server_BaseEntity *pPlayer = (Server_BaseEntity*)player->m_pUnk ->GetBaseEntity ();
444431
445- // std::cout << "dProcessUsercmds:" << pPlayer << "\n";
446-
447- /* Vector test = {0, 0, 0};
448- (*(void(__thiscall**)(int, Vector*))(*(DWORD*)pPlayer + 1156))((int)pPlayer, &test);
449-
450- std::cout << "dProcessUsercmds:" << test.x << ", " << test.y << ", " << test.z << "\n";*/
451-
452- int index = oEntindex (pPlayer);
432+ int index = EntityIndex (pPlayer);
453433 m_Game->m_CurrentUsercmdID = index;
454434
455- float result = hkProcessUsercmds.fOriginal (ecx, player, buf, numcmds, totalcmds, dropped_packets, ignore, paused);
456-
457- // check if swinging melee wep
458- /* if (m_Game->m_PlayersVRInfo[index].isUsingVR && m_Game->m_PlayersVRInfo[index].isMeleeing)
459- {
460- typedef Server_WeaponCSBase *(__thiscall *tGetActiveWep)(void *thisptr);
461- static tGetActiveWep oGetActiveWep = (tGetActiveWep)(m_Game->m_Offsets->GetActiveWeapon.address);
462- Server_WeaponCSBase *curWep = oGetActiveWep(pPlayer);
463-
464- if (curWep)
465- {
466- int wepID = curWep->GetWeaponID();
467- if (wepID == 19) // melee weapon
468- {
469- if (m_Game->m_PlayersVRInfo[index].isNewSwing)
470- {
471- m_Game->m_PlayersVRInfo[index].isNewSwing = false;
472- curWep->entitiesHitThisSwing = 0;
473- }
474-
475- typedef void *(__thiscall *tGetMeleeWepInfo)(void *thisptr);
476- static tGetMeleeWepInfo oGetMeleeWepInfo = (tGetMeleeWepInfo)(m_Game->m_Offsets->GetMeleeWeaponInfo.address);
477- void *meleeWepInfo = oGetMeleeWepInfo(curWep);
478-
479- Vector initialForward, initialRight, initialUp;
480- QAngle::AngleVectors(m_Game->m_PlayersVRInfo[index].prevControllerAngle, &initialForward, &initialRight, &initialUp);
481- Vector initialMeleeDirection = VectorRotate(initialForward, initialRight, 50.0);
482- VectorNormalize(initialMeleeDirection);
483-
484- Vector finalForward, finalRight, finalUp;
485- QAngle::AngleVectors(m_Game->m_PlayersVRInfo[index].controllerAngle, &finalForward, &finalRight, &finalUp);
486- Vector finalMeleeDirection = VectorRotate(finalForward, finalRight, 50.0);
487- VectorNormalize(finalMeleeDirection);
488-
489- Vector pivot;
490- CrossProduct(initialMeleeDirection, finalMeleeDirection, pivot);
491- VectorNormalize(pivot);
492-
493- float swingAngle = acos(DotProduct(initialMeleeDirection, finalMeleeDirection)) * 180 / 3.14159265;
494-
495- m_Game->m_Hooks->hkGetPrimaryAttackActivity.fOriginal(curWep, meleeWepInfo); // Needed to call TestMeleeSwingCollision
496-
497- m_Game->m_PerformingMelee = true;
498-
499- Vector traceDirection = initialMeleeDirection;
500- int numTraces = 10;
501- float traceAngle = swingAngle / numTraces;
502- for (int i = 0; i < numTraces; ++i)
503- {
504- traceDirection = VectorRotate(traceDirection, pivot, traceAngle);
505- m_Game->m_Hooks->hkTestMeleeSwingCollisionServer.fOriginal(curWep, traceDirection);
506- }
507-
508- m_Game->m_PerformingMelee = false;
509- }
510- }
511- }
512- else
513- {
514- m_Game->m_PlayersVRInfo[index].isNewSwing = true;
515- }*/
516-
517- m_Game->m_PlayersVRInfo [index].prevControllerAngle = m_Game->m_PlayersVRInfo [index].controllerAngle ;
518-
519- return result;
520- }
521-
522- void __fastcall Hooks::dWriteUsercmdDeltaToBuffer (void *ecx, void *edx, int a1, void *buf, int from, int to, bool isnewcommand)
523- {
524- return hkWriteUsercmdDeltaToBuffer.fOriginal (ecx, a1, buf, from, to, isnewcommand);
435+ return hkProcessUsercmds.fOriginal (ecx, player, buf, numcmds, totalcmds, dropped_packets, ignore, paused);
525436}
526437
527438int Hooks::dWriteUsercmd (bf_write *buf, CUserCmd *to, CUserCmd *from)
528439{
440+ auto result = hkWriteUsercmd.fOriginal (buf, to, from);
441+
442+ // Let's write our stuff into the buffer
529443 if (m_VR->m_IsVREnabled )
530444 {
531- CInput *m_Input = **(CInput ***)(m_Game->m_Offsets ->g_pppInput .address );
532- CVerifiedUserCmd *pVerifiedCommands = *(CVerifiedUserCmd **)((uintptr_t )m_Input + 0xF0 );
533- CVerifiedUserCmd *pVerified = &pVerifiedCommands[(to->command_number ) % 150 ];
534-
535- // Signal to the server that this CUserCmd has VR info
536- to->tick_count *= -1 ;
537-
538- int originalCommandNum = to->command_number ;
539-
445+ Vector controllerPos = m_VR->GetRightControllerAbsPos ();
540446 QAngle controllerAngles = m_VR->GetRightControllerAbsAngle ();
541- to->mousedx = controllerAngles.x * 10 ; // Strip off 2nd decimal to save bits.
542- to->mousedy = controllerAngles.y * 10 ;
543- int rollEncoding = (((int )controllerAngles.z + 180 ) / 2 * 10000000 );
544- to->command_number += rollEncoding;
545447
546- Vector controllerPos = m_VR->GetRightControllerAbsPos ();
547- to->viewangles .z = controllerPos.x ;
548- to->upmove = controllerPos.y ;
549-
550- // Space in CUserCmd is tight, so encode viewangle.x and controllerPos.z together.
551- // Encoding will overflow if controllerPos.z goes beyond +-21474.8
552- float xAngle = to->viewangles .x ;
553- int encodedAngle = (xAngle + 360 ) * 10 ;
554- int encoding = (int )(controllerPos.z * 10 ) * 10000 ;
555- encoding += encoding < 0 ? -encodedAngle : encodedAngle;
556- to->viewangles .x = encoding;
557-
558- hkWriteUsercmd.fOriginal (buf, to, from);
559-
560- to->viewangles .x = xAngle;
561- to->tick_count *= -1 ;
562- to->viewangles .z = 0 ;
563- to->upmove = 0 ;
564- to->command_number = originalCommandNum;
565-
566- // Must recalculate checksum for the edited CUserCmd or gunshots will sound
567- // terrible in multiplayer.
568- /* pVerified->m_cmd = *to;
569- pVerified->m_crc = to->GetChecksum();*/
570- return 1 ;
448+ buf->WriteChar (-2 );
449+ buf->WriteBitVec3Coord (controllerPos);
450+ buf->WriteBitAngles (controllerAngles);
571451 }
572- return hkWriteUsercmd.fOriginal (buf, to, from);
452+
453+ return result;
573454}
574455
575456int Hooks::dReadUsercmd (bf_read *buf, CUserCmd* move, CUserCmd* from)
576457{
577- hkReadUsercmd.fOriginal (buf, move, from);
458+ auto result = hkReadUsercmd.fOriginal (buf, move, from);
578459
579460 int i = m_Game->m_CurrentUsercmdID ;
580- if (move->tick_count < 0 ) // Signal for VR CUserCmd
461+ auto vrPlayer = m_Game->m_PlayersVRInfo [i];
462+
463+ auto pos = buf->Tell ();
464+ int res = buf->ReadChar ();
465+
466+ // This means we got a VR player on the other side
467+ if (res == -2 )
581468 {
582- move->tick_count *= -1 ;
583-
584- m_Game->m_PlayersVRInfo [i].isUsingVR = true ;
585- m_Game->m_PlayersVRInfo [i].controllerAngle .x = (float )move->mousedx / 10 ;
586- m_Game->m_PlayersVRInfo [i].controllerAngle .y = (float )move->mousedy / 10 ;
587- m_Game->m_PlayersVRInfo [i].controllerPos .x = move->viewangles .z ;
588- m_Game->m_PlayersVRInfo [i].controllerPos .y = move->upmove ;
589-
590- // Decode controllerAngle.z
591- int rollEncoding = move->command_number / 10000000 ;
592- move->command_number -= rollEncoding * 10000000 ;
593- m_Game->m_PlayersVRInfo [i].controllerAngle .z = (rollEncoding * 2 ) - 180 ;
594-
595- // Decode viewangles.x
596- int decodedZInt = (move->viewangles .x / 10000 );
597- float decodedAngle = abs ((float )(move->viewangles .x - (decodedZInt * 10000 )) / 10 );
598- decodedAngle -= 360 ;
599- float decodedZ = (float )decodedZInt / 10 ;
600-
601- m_Game->m_PlayersVRInfo [i].controllerPos .z = decodedZ;
602-
603- move->viewangles .x = decodedAngle;
604- move->viewangles .z = 0 ;
605- move->upmove = 0 ;
469+ vrPlayer.isUsingVR = true ;
470+ buf->ReadBitVec3Coord (vrPlayer.controllerPos );
471+ buf->ReadBitAngles (vrPlayer.controllerAngle );
606472 }
607- else
608- {
609- m_Game-> m_PlayersVRInfo [i]. isUsingVR = false ;
473+ else {
474+ vrPlayer. isUsingVR = false ;
475+ buf-> Seek (pos) ;
610476 }
611- return 1 ;
477+
478+ return result;
612479}
613480
614481
@@ -620,34 +487,12 @@ void Hooks::dAdjustEngineViewport(int &x, int &y, int &width, int &height)
620487 hkAdjustEngineViewport.fOriginal (x, y, width, height);
621488}
622489
623- void Hooks::dViewport (void *ecx, void *edx, int x, int y, int width, int height)
624- {
625- // std::cout << "dViewport - X: " << x << ", Y: " << y << ", W: " << width << ", H: " << height << "\n";
626-
627-
628- /* if (m_VR->m_IsVREnabled && m_Game->m_EngineClient->IsInGame() && !m_Game->m_VguiSurface->IsCursorVisible())
629- {
630- int windowWidth, windowHeight;
631- m_Game->m_MaterialSystem->GetRenderContext()->GetWindowSize(windowWidth, windowHeight);
632-
633- if (width == windowWidth && height == windowHeight) {
634- return hkViewport.fOriginal(ecx, x, y, m_VR->m_RenderWidth, m_VR->m_RenderHeight);
635- }
636- }*/
637-
638-
639- // hkViewport.fOriginal(ecx, x, y, m_VR->m_RenderWidth, m_VR->m_RenderHeight);
640- hkViewport.fOriginal (ecx, x, y, width, height);
641- }
642-
643490void Hooks::dGetViewport (void *ecx, void *edx, int &x, int &y, int &width, int &height)
644491{
645492 hkGetViewport.fOriginal (ecx, x, y, width, height);
646493
647494 width = m_VR->m_RenderWidth ;
648495 height = m_VR->m_RenderHeight ;
649-
650- // std::cout << "dGetViewport - X: " << x << ", Y: " << y << ", W: " << width << ", H: " << height << "\n";
651496}
652497
653498int Hooks::dGetPrimaryAttackActivity (void *ecx, void *edx, void *meleeInfo)
@@ -835,9 +680,7 @@ bool __fastcall Hooks::dTraceFirePortal(void* ecx, void* edx, const Vector& vTra
835680 }
836681 }
837682
838- bool bTraceSucceeded = hkTraceFirePortal.fOriginal (ecx, vNewTraceStart, vNewDirection, bPortal2, iPlacedBy, tr);
839-
840- return bTraceSucceeded;
683+ return hkTraceFirePortal.fOriginal (ecx, vNewTraceStart, vNewDirection, bPortal2, iPlacedBy, tr);
841684}
842685
843686void __fastcall Hooks::dPlayerPortalled (void * ecx, void * edx, void * a2, __int64 a3)
@@ -1058,15 +901,8 @@ QAngle& __fastcall Hooks::dEyeAngles(void* ecx, void* edx) {
1058901 return vrPlayer.controllerAngle ;
1059902 }
1060903 }
1061- else {
1062- return hkEyeAngles.fOriginal (ecx);
1063- }
1064- }
1065-
1066- void Hooks::dMatrixBuildPerspectiveX (void *& dst, double flFovX, double flAspect, double flZNear, double flZFar) {
1067- std::cout << " dMatrixBuildPerspectiveX - flFovX: " << flFovX << " , flAspect: " << flAspect << " , flZNear: " << flZNear << " , flZFar: " << flZFar << " \n " ;
1068904
1069- hkMatrixBuildPerspectiveX .fOriginal (dst, flFovX, flAspect, flZNear, flZFar );
905+ return hkEyeAngles .fOriginal (ecx );
1070906}
1071907
1072908int __fastcall Hooks::dGetDefaultFOV (void * ecx, void * edx) {
0 commit comments