Ray Tracing Based Triggerbot
Hello!
Recently I have seen some ray tracing functions and I wanted to implement it to update my triggerbot. I have used Merccys ray tracing functions:
tiioN's hitboxes for head:
Code:
Hitbox[ 11 ].Setup( BONE_HEAD, Vector( -2.7713f, -2.8783f, -3.103f ), Vector( 6.955f, 3.5203f, 3.0067f ) );
The triggerbot compiles nicely with no errors but it does not shoot when I aim for an entity head.
If anyone could point out what is the problem here or have some pointers :) plez post
ray.h:
Code:
#ifndef RAY_H
#define RAY_H
typedef struct Vector3d_
{
float x, y, z;
}Vector3d;
class Ray {
public:
Vector3d origin, direction, directionInverse;
Ray(Vector3d _origin, Vector3d _direction);
bool Trace(Vector3d leftBottom, Vector3d rightTop, float &distance);
};
#endif
Ray.cpp:
Code:
#include "Ray.h"
#include <algorithm>
Ray::Ray(Vector3d _origin, Vector3d _direction) {
origin = _origin;
direction = _direction;
directionInverse.x = 1.0f / direction.x;
directionInverse.y = 1.0f / direction.y;
directionInverse.z = 1.0f / direction.z;
}
bool Ray::Trace(Vector3d leftBottom, Vector3d rightTop, float &distance) {
// If line is parallel and outsite the box it is not possible to intersect
if (direction.x == 0.0f && (origin.x < std::min(leftBottom.x, rightTop.x) || origin.x > std::max(leftBottom.x, rightTop.x)))
return false;
if (direction.y == 0.0f && (origin.y < std::min(leftBottom.y, rightTop.y) || origin.y > std::max(leftBottom.y, rightTop.y)))
return false;
if (direction.z == 0.0f && (origin.z < std::min(leftBottom.z, rightTop.z) || origin.z > std::max(leftBottom.z, rightTop.z)))
return false;
float t1 = (leftBottom.x - origin.x) * directionInverse.x;
float t2 = (rightTop.x - origin.x) * directionInverse.x;
float t3 = (leftBottom.y - origin.y) * directionInverse.y;
float t4 = (rightTop.y - origin.y) * directionInverse.y;
float t5 = (leftBottom.z - origin.z) * directionInverse.z;
float t6 = (rightTop.z - origin.z) * directionInverse.z;
float tmin = std::max(std::max(std::min(t1, t2), std::min(t3, t4)), std::min(t5, t6));
float tmax = std::min(std::min(std::max(t1, t2), std::max(t3, t4)), std::max(t5, t6));
if (tmax < 0) {
distance = tmax;
return false;
}
if (tmin > tmax) {
distance = tmax;
return false;
}
distance = tmin;
return true;
}
main:
Code:
int main()
{
DWORD pId;
HWND hwnd = FindWindow(NULL, "Counter-Strike: Global Offensive");
GetWindowThreadProcessId(hwnd, &pId);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, NULL, pId);
DWORD clientDll = getDll("client.dll", pId);
DWORD engineDll = getDll("engine.dll", pId);
while (true) {
Vector3d viewAngle = Player.getViewAngle(hProc, engineDll);
Vector3d eyePos = Player.getEyePos(hProc, clientDll);
float distance;
Vector3d viewDirection = AngleToDirection(viewAngle);
Ray viewRay(eyePos, viewDirection);
for (int i = 0; i < 64; ++i)
{
Vector3d bottomHitboxHead = Entity.getBonePosition(clientDll, hProc, i);
bottomHitboxHead.x += -2.771300f;
bottomHitboxHead.y += -2.878300f;
bottomHitboxHead.z += -3.103000f;
Vector3d topHitboxHead = Entity.getBonePosition(clientDll, hProc, i);
topHitboxHead.x += 6.955000f;
topHitboxHead.y += 4.020300f;
topHitboxHead.z += 5.006700f;
if (viewRay.Trace(bottomHitboxHead, topHitboxHead, distance) && (GetAsyncKeyState(0x02) & (1 << 15)));
{
Mem.Write<int>(hProc, (clientDll + DwAttack), shoot);
Sleep(5);
Mem.Write<int>(hProc, (clientDll + DwAttack), dontShoot);
Sleep(10);
}
}
Sleep(1);
}
return 0;
}