-
Notifications
You must be signed in to change notification settings - Fork 6
/
PFActor.lua
420 lines (339 loc) · 12.2 KB
/
PFActor.lua
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
local function print() end;
local function warn() end;
print('waiting for shared.require');
repeat task.wait(); until getrenv().shared.require;
local function SX_VM_CNONE() end;
local Debris = game:GetService('Debris');
local Players = game:GetService('Players');
local LocalPlayer = Players.LocalPlayer;
local commEvent = getgenv().syn.get_comm_channel(...);
local requireCache = rawget(getupvalue(getrenv().shared.require, 1), '_cache');
assert(requireCache);
print('waiting for game scan');
local network, effect, particle;
repeat
for _, v in next, getgc(true) do
if type(v) == 'table' then
if rawget(v, 'send') then
network = v;
elseif rawget(v, 'bullethit') then
effect = v;
elseif rawget(v, 'new') and rawget(v, 'step') and rawget(v, 'reset') then
particle = v;
end;
end;
end;
task.wait();
until network and effect and particle;
local flags = {};
local gunModMaid = {};
local function gameRequire(moduleName)
print('waiting for', moduleName);
repeat
task.wait()
until requireCache[moduleName] and requireCache[moduleName].module;
return requireCache[moduleName].module;
end;
-- Replication
local repInterface = gameRequire('ReplicationInterface');
-- Character
local characterInterface = gameRequire('CharacterInterface');
local characterEvents = gameRequire('CharacterEvents');
local characterObject = gameRequire('CharacterObject');
-- Weapons
local weaponControllerInterface = gameRequire('WeaponControllerInterface');
local weaponControllerEvents = gameRequire('WeaponControllerEvents');
-- Game UI
local menuScreenGui = gameRequire('MenuScreenGui');
local weaponController;
local function updateAllEntries()
SX_VM_CNONE();
debug.profilebegin('update all entries');
local batch = {};
for player, entry in next, getupvalue(repInterface.getEntry, 1) do
local thirdPersonObject = entry:getThirdPersonObject();
if (not thirdPersonObject) then continue end;
local currentHealth, maxHealth = entry:getHealth();
batch[tostring(player)] = {
isAlive = entry:isAlive(),
player = player,
currentHealth = currentHealth,
maxHealth = maxHealth,
head = entry:getThirdPersonObject():getBodyPart('head'),
torso = entry:getThirdPersonObject():getBodyPart('torso')
};
end;
commEvent:Fire(1, batch);
commEvent:Fire(8, menuScreenGui.isEnabled());
debug.profileend();
end;
local char;
local aimPart;
local function onCharacterAdded()
char = characterInterface:getCharacterObject();
end;
onCharacterAdded();
characterEvents.onSpawned:connect(onCharacterAdded);
-- Character Object Hooks
do
local oldSetBaseWalkspeed = characterObject.setBaseWalkSpeed;
function characterObject:setBaseWalkSpeed(...)
if (not char or self ~= char) then return oldSetBaseWalkspeed(self, ...) end;
local args = {...};
if(flags.walkspeed) then
args[2] = flags.walkspeedValue
end;
table.foreach(args, warn);
return oldSetBaseWalkspeed(self, unpack(args))
end;
end;
do -- Weapon Controller Hooks
local oldSpawn = weaponControllerInterface.spawn;
local function onWeaponControllerChanged()
weaponController = weaponControllerInterface:getController();
warn('[Weapon Controller] Got new controller', weaponController);
end;
function weaponControllerInterface.spawn(...)
local res = {oldSpawn(...)};
onWeaponControllerChanged();
return unpack(res);
end;
onWeaponControllerChanged();
end;
local physics = {};
do -- Physics (not made by me lol)
local v3 = Vector3.new;
local dot = v3().Dot;
local gravity = v3(0, 196.2, 0);
physics.solvebiquadratic = function(a, b, c)
local p = (b * b - 4 * a * c) ^ 0.5;
local r0 = (-b - p) / (2 * a);
return r0 ^ 0.5;
end;
physics.trajectory = function(o, t, v)
local vec = t - o;
local r = physics.solvebiquadratic(dot(gravity, gravity) / 4, dot(gravity, vec) - v * v, dot(vec, vec));
return (r and gravity * r / 2 + vec / r), r;
end;
end;
local weaponVars = {
NoRecoil = {
{'camkickmin', Vector3.zero};
{'camkickmax', Vector3.zero};
{'aimcamkickmin', Vector3.zero};
{'aimcamkickmax', Vector3.zero};
{'aimtranskickmin', Vector3.zero};
{'aimtranskickmax', Vector3.zero};
{'transkickmin', Vector3.zero};
{'transkickmax', Vector3.zero};
{'rotkickmin', Vector3.zero};
{'rotkickmax', Vector3.zero};
{'aimrotkickmin', Vector3.zero};
{'aimrotkickmax', Vector3.zero};
};
NoSway = {
{'swayamp', 0};
{'swayspeed', 0};
{'steadyspeed', 0};
{'breathspeed', 0};
};
NoSpread = {
{'hipfirespread', 0.00001};
{'hipfirestability', 0.00001};
{'hipfirespreadrecover', 0.00001};
};
FullAuto = {
{'firemodes', {true, 3, 1}}
};
NoFlash = {
{'hideflash', true};
{'hideminimap', true};
};
InstantEquip = {
{'equipspeed', 100};
};
InstantReload = function(req)
table.foreach(req, warn);
if (not req.animations) then return end;
for k,x in next, req.animations do
if (k:lower():find('reload') or k:lower():find('pullbolt') or k:lower():find('onfire')) and type(x) == 'table' then
print('passed');
x.timescale = 0
end
end
return req.animations;
end;
}
local function applyGunModifications(editType, isEnabled)
local currentGun;
local function onGunUpdate()
local gun = weaponController and weaponController:getActiveWeapon();
if (gun == currentGun) then return end;
currentGun = gun;
commEvent:Fire(5, {weaponType = gun:getWeaponType()});
if (not gun._oldWeaponData) then
gun._oldWeaponData = {};
end;
local weaponDatas = table.clone(gun:getActiveAimStats());
table.insert(weaponDatas, gun:getWeaponData());
for _, weaponData in next, weaponDatas do
local vars = weaponVars[editType];
if (not vars) then warn('[WeaponController] no vars for', editType); continue end;
if (typeof(vars) == 'function') then
if (not gun._oldWeaponData.animations) then
gun._oldWeaponData.animations = weaponData.animations;
end;
weaponData.animations = isEnabled and vars(weaponData) or gun._oldWeaponData.animations;
else
for _, modifyData in next, vars do
local varName, varValue = unpack(modifyData);
if (not gun._oldWeaponData[varName]) then
print('[WeaponController] We saved', varName, 'weapon data');
gun._oldWeaponData[varName] = weaponData[varName];
end;
weaponData[varName] = isEnabled and varValue or gun._oldWeaponData[varName];
print('[WeaponController] We modified', varName, 'weapon data');
end;
end;
end;
end;
if (gunModMaid[editType]) then
gunModMaid[editType]:Disconnect();
gunModMaid[editType] = nil;
end;
if (isEnabled) then
local con;
con = weaponControllerEvents.onControllerFlag:Connect(function(gun, flagName, t)
if (flagName ~= 'equipFlag') then return end;
print('UPDATE', editType, gun, flagName);
onGunUpdate();
end);
gunModMaid[editType] = con;
end;
onGunUpdate();
end;
commEvent:Connect(function(updateType, t, ...)
SX_VM_CNONE();
if (updateType == 1) then return end;
if (updateType == 2) then
flags = t;
elseif (updateType == 3) then
applyGunModifications(t, ...);
elseif (updateType == 4) then
aimPart = t;
elseif (updateType == 6) then
network:send(t, ...);
elseif (updateType == 7) then
if (not char) then return end;
char:setBaseWalkSpeed(t);
else
print(updateType, typeof(updateType), t, ...);
end;
end);
local oldIndex;
oldIndex = hookmetamethod(game, '__index', function(self, p)
SX_VM_CNONE();
if (checkparallel()) then return oldIndex(self, p); end;
if (p == 'CFrame') then
local currentGun = weaponController and weaponController:getActiveWeapon();
if (currentGun and (self == currentGun._barrelPart or oldIndex(self, 'Name') == 'SightMark')) then
if aimPart then
local _, TimeToHit = physics.trajectory(self.Position, aimPart.Position, currentGun:getWeaponStat('bulletspeed'));
return CFrame.new(self.Position, aimPart.Position + (Vector3.new(0, 98.1, 0) * (TimeToHit ^ 2)));
end;
end;
end;
return oldIndex(self, p);
end);
local function getClosestCharacterFromDist()
local closest;
local last = math.huge;
for _, v in next, Players:GetPlayers() do
local head = repInterface.getEntry(v):getThirdPersonObject():getBodyPart('head');
if v ~= LocalPlayer and head and v.Team ~= LocalPlayer.Team then
local mag = (LocalPlayer.Character.HumanoidRootPart.Position - head.Position).Magnitude;
if last > mag then
last = head;
closest = v;
end;
end;
end;
return closest;
end;
local function bulletTracer(Origin, Destination, LifeTime)
local beam = Instance.new('Part');
beam.Anchored = true;
beam.CanCollide = false;
beam.Material = flags.bulletTracersMaterial;
beam.Color = flags.bulletTracersColor;
beam.Size = Vector3.new(0.1, 0.1, (Destination - Origin).Magnitude);
beam.CFrame = CFrame.new(Origin, Destination) * CFrame.new(0, 0, -beam.Size.Z / 2);
beam.Transparency = flags.bulletTracersAlpha / 10;
beam.Parent = workspace;
Debris:AddItem(beam, LifeTime);
end;
local oldNetworkSend = network.send;
local oldParticleNew = particle.new;
local oldBulletHit = effect.bullethit;
network.send = function(self, ...)
SX_VM_CNONE();
local args = {...};
if args[1] == 'falldamage' and flags.noFallDamage then
return;
end;
if (flags.antiAim and args[1] == 'repupdate') then
args[3] = Vector2.new(-1.47, math.random(-50, 50));
end;
if (args[1] == 'newgrenade' and args[2] == 'FRAG' and flags.fragTeleport) then
local head = getClosestCharacterFromDist()
if (head) then
args[3].frames[#args[3].frames] = {
v0 = Vector3.zero,
glassbreaks = {},
t0 = 0,
offset = Vector3.zero,
rot0 = CFrame.identity,
a = Vector3.zero,
p0 = head.Position,
rotv = Vector3.zero
}
args[3].blowuptime = 0.001;
end;
end;
if (flags.bulletTracers and args[1] == 'newbullets') then
print('OK');
task.spawn(function()
local gun = weaponController and weaponController:getActiveWeapon();
if (not gun) then return end;
for i = 1, #args[2].bullets do
task.spawn(bulletTracer, gun._barrelPart.Position, (gun._barrelPart.Position + args[2].bullets[i][1]), flags.bulletTracersLifetime);
end;
end);
end;
return oldNetworkSend(self, unpack(args));
end;
function effect:bullethit(...)
local args = {...};
if (aimPart) then
args[2] = aimPart.Position;
end;
return oldBulletHit(self, unpack(args));
end;
setreadonly(particle, false);
particle.new = function(data, ...)
SX_VM_CNONE();
local currentGun = weaponController and weaponController:getActiveWeapon();
if aimPart and data.visualorigin == currentGun._barrelPart.Position then
data.position = aimPart.Position;
data.velocity = physics.trajectory(currentGun._barrelPart.Position, data.position, currentGun:getWeaponStat('bulletspeed'));
end;
return oldParticleNew(data, ...);
end;
setreadonly(particle, true);
task.spawn(function()
while task.wait() do
updateAllEntries();
end;
end);
print('Running on actor', ...);
commEvent:Fire('ready');