forked from TomGrobbe/vMenu
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Noclip.cs
343 lines (305 loc) · 15.8 KB
/
Noclip.cs
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;
namespace vMenuClient
{
public class NoClip : BaseScript
{
private static bool NoclipActive { get; set; } = false;
private static int MovingSpeed { get; set; } = 0;
private static int Scale { get; set; } = -1;
private static bool FollowCamMode { get; set; } = true;
private static bool FlyCamMode { get; set; } = true;
private List<string> speeds = new List<string>()
{
"Very Slow | 1/8",
"Slow | 2/8",
"Normal | 3/8",
"Fast | 4/8",
"Very Fast | 5/8",
"Extremely Fast | 6/8",
"Extremely Fast v2.0 | 7/8",
"Max Speed | 8/8"
};
public NoClip()
{
Tick += NoClipHandler;
}
internal static void SetNoclipActive(bool active)
{
NoclipActive = active;
}
internal static bool IsNoclipActive()
{
return NoclipActive;
}
static string HashString(string command)
{
uint hash = 0;
string str = command.ToLower();
for (int i = 0; i < str.Length; i++)
{
uint letter = (uint)str[i];
hash = hash + letter;
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
if (hash < 0)
{
hash = (uint)((int)hash);
}
hash ^= (hash >> 11);
hash += (hash << 15);
if (hash < 0)
{
hash = (uint)((int)hash);
}
return hash.ToString("X");
}
private async Task NoClipHandler()
{
if (NoclipActive)
{
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
//TriggerEvent("mosh_notify:notify", "SUCCESS", "<span class=\"text-white\">You are now in NoClip! Press F2 to turn off NoClip.</span>", "success", "success", 5000);
}
Scale = RequestScaleformMovie("INSTRUCTIONAL_BUTTONS");
while (!HasScaleformMovieLoaded(Scale))
{
await Delay(0);
}
DrawScaleformMovieFullscreen(Scale, 255, 255, 255, 0, 0);
}
while (NoclipActive)
{
if (!IsHudHidden())
{
BeginScaleformMovieMethod(Scale, "CLEAR_ALL");
EndScaleformMovieMethod();
BeginScaleformMovieMethod(Scale, "SET_DATA_SLOT");
ScaleformMovieMethodAddParamInt(0);
PushScaleformMovieMethodParameterString("~INPUT_SPRINT~");
PushScaleformMovieMethodParameterString($"Change Speed ({speeds[MovingSpeed]})");
EndScaleformMovieMethod();
BeginScaleformMovieMethod(Scale, "SET_DATA_SLOT");
ScaleformMovieMethodAddParamInt(1);
PushScaleformMovieMethodParameterString("~INPUT_MOVE_LR~");
PushScaleformMovieMethodParameterString($"Turn Left/Right");
EndScaleformMovieMethod();
BeginScaleformMovieMethod(Scale, "SET_DATA_SLOT");
ScaleformMovieMethodAddParamInt(2);
PushScaleformMovieMethodParameterString("~INPUT_MOVE_UD~");
PushScaleformMovieMethodParameterString($"Move");
EndScaleformMovieMethod();
BeginScaleformMovieMethod(Scale, "SET_DATA_SLOT");
ScaleformMovieMethodAddParamInt(3);
PushScaleformMovieMethodParameterString("~INPUT_MULTIPLAYER_INFO~");
PushScaleformMovieMethodParameterString($"Down");
EndScaleformMovieMethod();
BeginScaleformMovieMethod(Scale, "SET_DATA_SLOT");
ScaleformMovieMethodAddParamInt(4);
PushScaleformMovieMethodParameterString("~INPUT_COVER~");
PushScaleformMovieMethodParameterString($"Up");
EndScaleformMovieMethod();
BeginScaleformMovieMethod(Scale, "SET_DATA_SLOT");
ScaleformMovieMethodAddParamInt(5);
PushScaleformMovieMethodParameterString("~INPUT_VEH_HEADLIGHT~");
PushScaleformMovieMethodParameterString($"Cam Mode");
EndScaleformMovieMethod();
BeginScaleformMovieMethod(Scale, "SET_DATA_SLOT");
ScaleformMovieMethodAddParamInt(6);
PushScaleformMovieMethodParameterString($"~INPUT_{HashString($"{vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_individual_server_id)}vMenu:NoClip")}~");
PushScaleformMovieMethodParameterString($"Toggle NoClip");
EndScaleformMovieMethod();
BeginScaleformMovieMethod(Scale, "DRAW_INSTRUCTIONAL_BUTTONS");
ScaleformMovieMethodAddParamInt(0);
EndScaleformMovieMethod();
DrawScaleformMovieFullscreen(Scale, 255, 255, 255, 255, 0);
}
var noclipEntity = Game.PlayerPed.IsInVehicle() ? Game.PlayerPed.CurrentVehicle.Handle : Game.PlayerPed.Handle;
FreezeEntityPosition(noclipEntity, true);
SetEntityInvincible(noclipEntity, true);
Vector3 newPos;
Game.DisableControlThisFrame(0, Control.AccurateAim);
Game.DisableControlThisFrame(0, Control.Attack);
Game.DisableControlThisFrame(0, Control.Attack2);
Game.DisableControlThisFrame(0, Control.Aim);
Game.DisableControlThisFrame(0, Control.Cover);
Game.DisableControlThisFrame(0, Control.Detonate);
Game.DisableControlThisFrame(0, Control.MeleeAttack1);
Game.DisableControlThisFrame(0, Control.MeleeAttack2);
Game.DisableControlThisFrame(0, Control.MeleeAttackAlternate);
Game.DisableControlThisFrame(0, Control.MeleeAttackLight);
Game.DisableControlThisFrame(0, Control.MeleeAttackHeavy);
Game.DisableControlThisFrame(0, Control.MeleeBlock);
Game.DisableControlThisFrame(0, Control.MoveUpOnly);
Game.DisableControlThisFrame(0, Control.MoveUp);
Game.DisableControlThisFrame(0, Control.MoveUpDown);
Game.DisableControlThisFrame(0, Control.MoveDown);
Game.DisableControlThisFrame(0, Control.MoveDownOnly);
Game.DisableControlThisFrame(0, Control.MoveLeft);
Game.DisableControlThisFrame(0, Control.MoveLeftOnly);
Game.DisableControlThisFrame(0, Control.MoveLeftRight);
Game.DisableControlThisFrame(0, Control.MoveRight);
Game.DisableControlThisFrame(0, Control.MoveRightOnly);
Game.DisableControlThisFrame(0, Control.MultiplayerInfo);
Game.DisableControlThisFrame(0, Control.NextWeapon);
Game.DisableControlThisFrame(0, Control.PrevWeapon);
Game.DisableControlThisFrame(0, Control.SelectNextWeapon);
Game.DisableControlThisFrame(0, Control.SelectPrevWeapon);
Game.DisableControlThisFrame(0, Control.SelectWeapon);
Game.DisableControlThisFrame(0, Control.SelectWeaponAutoRifle);
Game.DisableControlThisFrame(0, Control.SelectWeaponHandgun);
Game.DisableControlThisFrame(0, Control.SelectWeaponHeavy);
Game.DisableControlThisFrame(0, Control.SelectWeaponMelee);
Game.DisableControlThisFrame(0, Control.SelectWeaponSmg);
Game.DisableControlThisFrame(0, Control.SelectWeaponSniper);
Game.DisableControlThisFrame(0, Control.SelectWeaponSpecial);
Game.DisableControlThisFrame(0, Control.SelectWeaponUnarmed);
Game.DisableControlThisFrame(0, Control.ThrowGrenade);
Game.DisableControlThisFrame(0, Control.VehicleAim);
Game.DisableControlThisFrame(0, Control.VehicleAttack);
Game.DisableControlThisFrame(0, Control.VehicleAttack2);
Game.DisableControlThisFrame(0, Control.VehicleFlyAttack);
Game.DisableControlThisFrame(0, Control.VehicleFlyAttack2);
Game.DisableControlThisFrame(0, Control.VehicleFlyAttackCamera);
Game.DisableControlThisFrame(0, Control.VehicleFlySelectNextWeapon);
Game.DisableControlThisFrame(0, Control.VehicleFlySelectPrevWeapon);
Game.DisableControlThisFrame(0, Control.VehicleGunDown);
Game.DisableControlThisFrame(0, Control.VehicleGunLeft);
Game.DisableControlThisFrame(0, Control.VehicleGunLeftRight);
Game.DisableControlThisFrame(0, Control.VehicleGunRight);
Game.DisableControlThisFrame(0, Control.VehicleGunUp);
Game.DisableControlThisFrame(0, Control.VehicleGunUpDown);
Game.DisableControlThisFrame(0, Control.VehicleHeadlight);
Game.DisableControlThisFrame(0, Control.VehicleSelectNextWeapon);
Game.DisableControlThisFrame(0, Control.VehicleSelectPrevWeapon);
Game.DisableControlThisFrame(0, Control.VehiclePassengerAim);
Game.DisableControlThisFrame(0, Control.VehiclePassengerAttack);
Game.DisableControlThisFrame(0, Control.WeaponSpecial);
Game.DisableControlThisFrame(0, Control.WeaponWheelLeftRight);
Game.DisableControlThisFrame(0, Control.WeaponWheelNext);
Game.DisableControlThisFrame(0, Control.WeaponWheelPrev);
Game.DisableControlThisFrame(0, Control.WeaponWheelUpDown);
if (Game.PlayerPed.IsInVehicle())
Game.DisableControlThisFrame(0, Control.VehicleRadioWheel);
var xoff = 0.0f;
var yoff = 0.0f;
var zoff = 0.0f;
if (Game.CurrentInputMode == InputMode.MouseAndKeyboard && UpdateOnscreenKeyboard() != 0 && !Game.IsPaused)
{
if (Game.IsControlJustPressed(0, Control.Sprint))
{
MovingSpeed++;
if (MovingSpeed == speeds.Count)
{
MovingSpeed = 0;
}
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
//TriggerEvent("mosh_notify:notify", "SUCCESS", $"<span class=\"text-white\">Your NoClip speed is: {speeds[MovingSpeed]}.</span>", "success", "success", 3000);
}
}
if (Game.IsDisabledControlPressed(0, Control.MoveUpOnly))
{
yoff = 0.5f;
}
if (Game.IsDisabledControlPressed(0, Control.MoveDownOnly))
{
yoff = -0.5f;
}
if (Game.IsDisabledControlPressed(0, Control.MoveLeftOnly))
{
if (FlyCamMode && FollowCamMode)
{
xoff = -0.5f;
}
else if (!FollowCamMode)
{
SetEntityHeading(Game.PlayerPed.Handle, GetEntityHeading(Game.PlayerPed.Handle) + 3f);
}
}
if (Game.IsDisabledControlPressed(0, Control.MoveRightOnly))
{
if (FlyCamMode && FollowCamMode)
{
xoff = 0.5f;
}
else if (!FollowCamMode)
{
SetEntityHeading(Game.PlayerPed.Handle, GetEntityHeading(Game.PlayerPed.Handle) - 3f);
}
}
if (Game.IsDisabledControlPressed(0, Control.Cover))
{
zoff = 0.21f;
}
if (Game.IsDisabledControlPressed(0, Control.MultiplayerInfo))
{
zoff = -0.21f;
}
if (Game.IsDisabledControlJustPressed(0, Control.VehicleHeadlight))
{
if (FlyCamMode)
{
FlyCamMode = false;
}
else if (FollowCamMode)
{
FollowCamMode = false;
}
else
{
FollowCamMode = true;
FlyCamMode = true;
}
}
}
float moveSpeed = MovingSpeed;
if (MovingSpeed > speeds.Count / 2)
{
moveSpeed *= 1.8f;
}
moveSpeed = moveSpeed / (1f / GetFrameTime()) * 60;
float num = (FlyCamMode ? MathUtil.DegreesToRadians(GetGameplayCamRelativePitch()) : 0f);
float rotxy = (float)Math.Cos((double)num);
float rotz = (float)Math.Sin((double)num);
xoff *= rotxy;
yoff *= rotxy;
zoff += rotz * yoff;
newPos = GetOffsetFromEntityInWorldCoords(noclipEntity, xoff * (moveSpeed + 0.3f), yoff * (moveSpeed + 0.3f), zoff * (moveSpeed + 0.3f));
var heading = GetEntityHeading(noclipEntity);
SetEntityVelocity(noclipEntity, 0f, 0f, 0f);
SetEntityRotation(noclipEntity, 0f, 0f, 0f, 0, false);
SetEntityHeading(noclipEntity, FollowCamMode ? GetGameplayCamRelativeHeading() : heading);
SetEntityCollision(noclipEntity, false, false);
SetEntityCoordsNoOffset(noclipEntity, newPos.X, newPos.Y, newPos.Z, true, true, true);
SetEntityVisible(noclipEntity, false, false);
SetLocalPlayerVisibleLocally(true);
SetEntityAlpha(noclipEntity, (int)(255 * 0.2), 0);
SetEveryoneIgnorePlayer(Game.PlayerPed.Handle, true);
SetPoliceIgnorePlayer(Game.PlayerPed.Handle, true);
// After the next game tick, reset the entity properties.
await Delay(0);
FreezeEntityPosition(noclipEntity, false);
SetEntityInvincible(noclipEntity, false);
SetEntityCollision(noclipEntity, true, true);
// If the player is not set as invisible by PlayerOptions or if the noclip entity is not the player ped, reset the visibility
if (MainMenu.PlayerOptionsMenu == null || (!MainMenu.PlayerOptionsMenu.PlayerInvisible || (MainMenu.PlayerOptionsMenu.PlayerInvisible && noclipEntity == Game.PlayerPed.Handle)))
{
SetEntityVisible(noclipEntity, true, false);
SetLocalPlayerVisibleLocally(true);
}
// Always reset the alpha.
ResetEntityAlpha(noclipEntity);
SetEveryoneIgnorePlayer(Game.PlayerPed.Handle, false);
SetPoliceIgnorePlayer(Game.PlayerPed.Handle, false);
}
await Task.FromResult(0);
}
}
}