This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
main.cpp
121 lines (95 loc) · 3.6 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "memory.h"
#include "vector.h"
#include <thread>
namespace offset
{
// client
constexpr ::std::ptrdiff_t dwLocalPlayer = 0xDB25DC;
constexpr ::std::ptrdiff_t dwEntityList = 0x4DCDE7C;
// engine
constexpr ::std::ptrdiff_t dwClientState = 0x58CFC4;
constexpr ::std::ptrdiff_t dwClientState_ViewAngles = 0x4D90;
constexpr ::std::ptrdiff_t dwClientState_GetLocalPlayer = 0x180;
// entity
constexpr ::std::ptrdiff_t m_dwBoneMatrix = 0x26A8;
constexpr ::std::ptrdiff_t m_bDormant = 0xED;
constexpr ::std::ptrdiff_t m_iTeamNum = 0xF4;
constexpr ::std::ptrdiff_t m_lifeState = 0x25F;
constexpr ::std::ptrdiff_t m_vecOrigin = 0x138;
constexpr ::std::ptrdiff_t m_vecViewOffset = 0x108;
constexpr ::std::ptrdiff_t m_aimPunchAngle = 0x303C;
constexpr ::std::ptrdiff_t m_bSpottedByMask = 0x980;
}
Vector3 CalculateAngle(
const Vector3& localPosition,
const Vector3& enemyPosition,
const Vector3& viewAngles) noexcept
{
return ((enemyPosition - localPosition).ToAngle() - viewAngles);
}
int main()
{
// initialize memory class
const auto memory = Memory{ "csgo.exe" };
// module addresses
const auto client = memory.GetModuleAddress("client.dll");
const auto engine = memory.GetModuleAddress("engine.dll");
// infinite hack loop
while (true)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
// aimbot key
if (!GetAsyncKeyState(VK_RBUTTON))
continue;
// get local player
const auto localPlayer = memory.Read<std::uintptr_t>(client + offset::dwLocalPlayer);
const auto localTeam = memory.Read<std::int32_t>(localPlayer + offset::m_iTeamNum);
// eye position = origin + viewOffset
const auto localEyePosition = memory.Read<Vector3>(localPlayer + offset::m_vecOrigin) +
memory.Read<Vector3>(localPlayer + offset::m_vecViewOffset);
const auto clientState = memory.Read<std::uintptr_t>(engine + offset::dwClientState);
const auto localPlayerId =
memory.Read<std::int32_t>(clientState + offset::dwClientState_GetLocalPlayer);
const auto viewAngles = memory.Read<Vector3>(clientState + offset::dwClientState_ViewAngles);
const auto aimPunch = memory.Read<Vector3>(localPlayer + offset::m_aimPunchAngle) * 2;
// aimbot fov
auto bestFov = 5.f;
auto bestAngle = Vector3{ };
for (auto i = 1; i <= 32; ++i)
{
const auto player = memory.Read<std::uintptr_t>(client + offset::dwEntityList + i * 0x10);
if (memory.Read<std::int32_t>(player + offset::m_iTeamNum) == localTeam)
continue;
if (memory.Read<bool>(player + offset::m_bDormant))
continue;
if (memory.Read<std::int32_t>(player + offset::m_lifeState))
continue;
if (memory.Read<std::int32_t>(player + offset::m_bSpottedByMask) & (1 << localPlayerId))
{
const auto boneMatrix = memory.Read<std::uintptr_t>(player + offset::m_dwBoneMatrix);
// pos of player head in 3d space
// 8 is the head bone index :)
const auto playerHeadPosition = Vector3{
memory.Read<float>(boneMatrix + 0x30 * 8 + 0x0C),
memory.Read<float>(boneMatrix + 0x30 * 8 + 0x1C),
memory.Read<float>(boneMatrix + 0x30 * 8 + 0x2C)
};
const auto angle = CalculateAngle(
localEyePosition,
playerHeadPosition,
viewAngles + aimPunch
);
const auto fov = std::hypot(angle.x, angle.y);
if (fov < bestFov)
{
bestFov = fov;
bestAngle = angle;
}
}
}
// if we have a best angle, do aimbot
if (!bestAngle.IsZero())
memory.Write<Vector3>(clientState + offset::dwClientState_ViewAngles, viewAngles + bestAngle / 3.f); // smoothing
}
return 0;
}