Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. typedef void(__thiscall* tOverrideMouseInput)(PVOID, float *x, float *y);
  2. tOverrideMouseInput oOverrideMouseInput;
  3. void __stdcall hkOverrideMouseInput(float *_x, float *_y)
  4. {
  5. oOverrideMouseInput(pClientMode, _x, _y);
  6.  
  7. //If there is no mouse movement then we don't want to do anything (you can change that if you want)
  8. if (*(float*)_x == 0.0f || *(float*)_y == 0.0f)
  9. return;
  10.  
  11. IClientEntity *pLocalEntity = pEntityList->GetClientEntity(pEngine->GetLocalPlayer());
  12. if (!pLocalEntity)
  13. return;
  14.  
  15. if (!pLocalEntity->IsAlive())
  16. return;
  17.  
  18. CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)pEntityList->GetClientEntityFromHandle(pLocalEntity->GetActiveWeaponHandle());
  19. if (!pWeapon)
  20. return;
  21.  
  22. //Knife/Golden Knife - I don't want aim assistance with knifes
  23. int iWeaponClass = pWeapon->GetClientClass()->m_ClassID;
  24. if (iWeaponClass == 90 || iWeaponClass == 91)
  25. return;
  26.  
  27. //Grab our data...
  28. QAngle ViewAngles;
  29. pEngine->GetViewAngles(ViewAngles);
  30. ViewAngles += pLocalEntity->GetPunchAngles() * 2.0f;
  31. NormalizeAngles(ViewAngles);
  32. Vector vecPlayer = pLocalEntity->GetOrigin();
  33. Vector vecPlayerEyes = vecPlayer + pLocalEntity->GetEyePosition();
  34. int iBestTarget = -1;
  35.  
  36. //Get best target
  37. for (int i = 1; i < pEngine->GetMaxClients() + 1; i++)
  38. {
  39. //Pick best target here... it's your job, ez pz.
  40. iBestTarget = pEngine->GetLocalPlayer();
  41. break;
  42. }
  43.  
  44. if (iBestTarget != -1)
  45. {
  46. IClientEntity* pEntity = pEntityList->GetClientEntity(iBestTarget);
  47. if (!pEntity)
  48. return;
  49.  
  50. Vector vecHitbox = GetHitboxPosition(pEntity, 0); //Or use bones, w/e
  51. Vector vecDelta = vecHitbox - vecPlayerEye;
  52. QAngle qEntityAngles = CalcAngle(vecPlayerEye, vecHitbox);
  53. NormalizeAngles(qEntityAngles);
  54.  
  55. QAngle qDelta = ViewAngles - qEntityAngles;
  56. NormalizeAngles(qDelta);
  57.  
  58. //Angles to pixels, 0.022 == m_yaw == m_pitch
  59. //https://github.com/alliedmodders/hl2sdk/blob/csgo/game/client/in_mouse.cpp#L439
  60. qDelta.x /= 0.022f;
  61. qDelta.y /= 0.022f;
  62.  
  63. //Convert them to vectors, since I am lazy and vectors have stuff like Lenght :v Notice that we use yaw as X and -pitch as Y.
  64. Vector vMouse = Vector(*(float*)_x, *(float*)_y, 0.0f);
  65. Vector vDelta = Vector(qDelta.y, -qDelta.x, 0.0f);
  66.  
  67. //Scale down
  68. //I also added some "distance scaling", since it looked very strange and snappy without it.
  69. float fDistanceScaling = fNearsetFOV / 17.5f;
  70. fDistanceScaling += 0.385f;
  71. vDelta = vDelta.Normalized() * vMouse.Length() * fDistanceScaling;
  72.  
  73. //Average of two vectors
  74. float fRandom = RandomFloat(6.15f, 7.65f) * (1.0 - fDistanceScaling);
  75. vDelta *= fRandom;
  76. vMouse *= 10.0f - fRandom;
  77. vDelta += vMouse;
  78. vDelta /= 10.0f;
  79.  
  80. //Override original input with our values :v
  81. *(float*)_x = vDelta.x;
  82. *(float*)_y = vDelta.y;
  83. return;
  84. }
  85. }
  86.  
  87. //Hooking:
  88. //ClientMode pointer is your job, if you don't know how to do it check this out:
  89. //http://www.unknowncheats.me/forum/source-engine/159253-finding-pointer-clientmode-game.html
  90. pClientModeHook = new CVMTHookManager((PDWORD*)pClientMode);
  91. oOverrideMouseInput = (tOverrideMouseInput)pInputHook->dwHookMethod((DWORD)hkOverrideMouseInput, 23);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement