This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Noclip.cpp
93 lines (73 loc) · 2.55 KB
/
Noclip.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
#include "pch.h"
#include "Noclip.h"
#include "alt-log.h"
const double PI = 3.141592653589793238463;
Noclip::Noclip()
{
enabled = false;
speed = 1.0;
}
Vector3f GetCamDirection()
{
uint32_t localPed = Native::Invoke<uint32_t, uint32_t>(N::GET_PLAYER_PED, 0);
float pedHeading = Native::Invoke<float, uint32_t>(N::GET_ENTITY_HEADING, localPed);
float camHeading = Native::Invoke<float>(N::GET_GAMEPLAY_CAM_RELATIVE_HEADING);
float camPitch = Native::Invoke<float>(N::GET_GAMEPLAY_CAM_RELATIVE_PITCH);
float heading = (camHeading + pedHeading);
float x = -sin(heading * PI / 180.f);
float y = cos(heading * PI / 180.f);
float z = sin(camPitch * PI / 180.f);
float length = sqrt(x * x + y * y + z * z);
if (length != 0)
{
x /= length;
y /= length;
z /= length;
}
return { x, y, z };
}
void Noclip::Tick()
{
if (!enabled)
{
return;
}
uint32_t localPed = Native::Invoke<uint32_t, uint32_t>(N::GET_PLAYER_PED, 0);
Vector3f curPosition = Native::Invoke<Vector3f, uint32_t, bool>(N::GET_ENTITY_COORDS, localPed, false);
Vector3f camDirection = GetCamDirection();
Native::Invoke<void, uint32_t, float, float, float>(N::SET_ENTITY_VELOCITY, localPed, 0.f, 0.f, 0.f);
if (Native::Invoke<bool, uint32_t, uint32_t>(N::IS_CONTROL_PRESSED, 0, String::Hash("input_move_up_only")))
{
curPosition.x += speed * camDirection.x * (highSpeed ? 3 : 1);
curPosition.y += speed * camDirection.y * (highSpeed ? 3 : 1);
curPosition.z += speed * camDirection.z * (highSpeed ? 3 : 1);
}
if (Native::Invoke<bool, uint32_t, uint32_t>(N::IS_CONTROL_PRESSED, 0, String::Hash("input_move_down_only")))
{
curPosition.x -= speed * camDirection.x * (highSpeed ? 3 : 1);
curPosition.y -= speed * camDirection.y * (highSpeed ? 3 : 1);
curPosition.z -= speed * camDirection.z * (highSpeed ? 3 : 1);
}
Native::Invoke<void, uint32_t, float, float, float, bool, bool, bool, bool>(N::SET_ENTITY_COORDS_NO_OFFSET, localPed, curPosition.x, curPosition.y, curPosition.z, false, false, false, false);
}
void Noclip::Toggle()
{
auto flag = !enabled;
uint32_t localPed = Native::Invoke<uint32_t, uint32_t>(N::GET_PLAYER_PED, 0);
if (!flag)
{
Native::Invoke<void, uint32_t, int>(N::SET_ENTITY_ALPHA, localPed, 255);
Native::Invoke<void, uint32_t, bool>(N::SET_ENTITY_VISIBLE, localPed, true);
}
else
{
Native::Invoke<void, uint32_t, int>(N::SET_ENTITY_ALPHA, localPed, 0);
Native::Invoke<void, uint32_t, bool>(N::SET_ENTITY_VISIBLE, localPed, false);
}
Log::Info("Noclip::Toggle ", enabled);
enabled = flag;
}
void Noclip::SetHighSpeed(bool enable)
{
highSpeed = enable;
}