-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathclient.lua
775 lines (655 loc) · 16.9 KB
/
client.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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
local drawSprite = DrawSprite
local txd = {
'mphackinggame',
'mphackinggamebg',
'mphackinggamewin',
'mporderunlock',
'mporderunlock_decor',
'mphackinggamewin2'
}
local innerCircles = {
[1] = {
{x=0.244, y=0.321},
{x=0.244, y=0.419},
{x=0.244, y=0.516},
{x=0.244, y=0.614},
{x=0.244, y=0.712},
},
[2] = {
{x=0.304, y=0.321},
{x=0.304, y=0.419},
{x=0.304, y=0.516},
{x=0.304, y=0.614},
{x=0.304, y=0.712}
},
[3] = {
{x=0.363, y=0.321},
{x=0.363, y=0.417},
{x=0.363, y=0.516},
{x=0.363, y=0.615},
{x=0.363, y=0.711}
},
[4] = {
{x=0.423, y=0.321},
{x=0.423, y=0.418},
{x=0.423, y=0.516},
{x=0.423, y=0.614},
{x=0.423, y=0.711}
},
[5] = {
{x=0.483, y=0.321},
{x=0.483, y=0.418},
{x=0.483, y=0.515},
{x=0.483, y=0.614},
{x=0.483, y=0.712}
},
[6] = {
{x=0.543, y=0.321},
{x=0.543, y=0.419},
{x=0.543, y=0.515},
{x=0.543, y=0.614},
{x=0.543, y=0.712}
}
}
local scramblePos = {
{x=0.5, y=0.84},
{x=0.493, y=0.84},
{x=0.486, y=0.84},
{x=0.479, y=0.84},
{x=0.472, y=0.84},
{x=0.465, y=0.84},
{x=0.458, y=0.84},
{x=0.451, y=0.84},
{x=0.444, y=0.84},
{x=0.437, y=0.84},
{x=0.43, y=0.84},
{x=0.423, y=0.84},
{x=0.416, y=0.84},
{x=0.409, y=0.84},
{x=0.402, y=0.84},
{x=0.395, y=0.84},
{x=0.388, y=0.84},
{x=0.381, y=0.84},
{x=0.374, y=0.84},
{x=0.367, y=0.84},
{x=0.36, y=0.84},
{x=0.353, y=0.84},
{x=0.346, y=0.84},
{x=0.353, y=0.84},
{x=0.339, y=0.84},
{x=0.332, y=0.84},
{x=0.325, y=0.84},
{x=0.318, y=0.84},
{x=0.311, y=0.84},
{x=0.304, y=0.84},
{x=0.297, y=0.84},
{x=0.29, y=0.84},
{x=0.283, y=0.84}
}
local fakeKeyButtons = {
{x=0.726, y=0.62},
{x=0.669, y=0.343},
{x=0.726, y=0.343},
{x=0.782, y=0.343},
{x=0.669, y=0.435},
{x=0.726, y=0.435},
{x=0.782, y=0.435},
{x=0.669, y=0.527},
{x=0.726, y=0.527},
{x=0.782, y=0.527}
}
local resultCodePos = {
{x=0.666, y=0.766},
{x=0.706, y=0.767},
{x=0.746, y=0.767},
{x=0.786, y=0.767}
}
local lifePos = {
{x=0.553, y=0.153},
{x=0.587, y=0.153},
{x=0.62, y=0.153},
{x=0.653, y=0.153},
{x=0.686, y=0.153},
{x=0.719, y=0.153}
}
local showDialog = false
local dialogTexName = 'correct_0'
local toggleAnimOverlay = true
local isPlayerInputDisabled = false
local isGameActive = false
local gameWon = false
local availableLife = 0
local timer = 0 -- in seconds
local timeString = {}
local activeStage = 1
local activeColumn = 0
local activeRow = 0
local activeSelection = 0
local selectedDots = {
correctDots = {},
incorrectDots = {}
}
local fakepattern = {}
local passcodePattern
local passcodeResult
local callbackFn
function secondsToString(seconds)
local seconds = tonumber(seconds)
local hours = string.format("%02.f", math.floor(seconds/3600));
local mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
local secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
local time={}
mins:gsub(".",function(c) table.insert(time,c) end)
secs:gsub(".",function(c) table.insert(time,c) end)
return time
end
function shuffle(t)
local tbl = {}
for i = 1, #t do
Wait(0)
tbl[i] = t[i]
end
for i = #tbl, 2, -1 do
Wait(0)
math.randomseed(GetGameTimer()*GetFrameTime())
local j = math.random(i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
if table.concat(t) == table.concat(tbl) then
tbl = shuffle(t)
end
return tbl
end
function randNumExclusive(n, a, b)
local numbers = {}
for i = a, b do
Wait(0)
numbers[i] = i
end
for i = 1, #numbers - 1 do
Wait(0)
local j = math.random(i, #numbers)
numbers[i], numbers[j] = numbers[j], numbers[i]
end
numbers = shuffle(numbers)
return {table.unpack(numbers, 1, n)}
end
function generatePattern(n, a, b)
local numbers = {}
for i=1,5 do
numbers[i] = i
end
numbers = shuffle(numbers)
math.randomseed(GetGameTimer()*GetFrameTime()*GetRandomIntInRange(1000, 36415))
numbers[#numbers+1] = math.random(a, b)
numbers = shuffle(numbers)
return {table.unpack(numbers, 1, n)}
end
function generateFakePattern()
fakepattern = {}
for i=1,math.random(4,7) do
table.insert(fakepattern, generatePattern(6, 1, 5))
end
end
function showTimer()
if(not timeString[1] or not timeString[2] or not timeString[3] or not timeString[4]) then return end
drawSprite(
'mphackinggame',
'numbers_'..timeString[1],
0.258, 0.152, 0.025, 0.055, 0, 255, 255, 255, 255
)
drawSprite(
'mphackinggame',
'numbers_'..timeString[2],
0.283, 0.152, 0.025, 0.055, 0, 255, 255, 255, 255
)
drawSprite(
'mphackinggame',
'numbers_colon',
0.307, 0.154, 0.025, 0.055, 0, 255, 255, 255, 255
)
drawSprite(
'mphackinggame',
'numbers_'..timeString[3],
0.33, 0.153, 0.025, 0.055, 0, 255, 255, 255, 255
)
drawSprite(
'mphackinggame',
'numbers_'..timeString[4],
0.355, 0.153, 0.025, 0.055, 0, 255, 255, 255, 255
)
end
function blinkDialog(result)
local flash = 3000
local tex1
local tex2
if result == true then
tex1 = 'correct_1'
tex2 = 'correct_0'
else
tex1 = 'incorrect_1'
tex2 = 'incorrect_0'
end
CreateThread(function()
for i=1,4 do
flash = flash - 500
dialogTexName = tex1
Wait(500)
showDialog = true
flash = flash - 500
dialogTexName = tex2
Wait(500)
end
showDialog = false
end)
end
function startGame()
CreateThread(function()
for i=1,#txd do
Wait(0)
RequestStreamedTextureDict(txd[i], false)
end
for i=1,#txd do
Wait(0)
while not HasStreamedTextureDictLoaded(txd[i]) do
Wait(0)
end
end
-- Generate target
passcodePattern = generatePattern(6, 1, 5)
passcodeResult = randNumExclusive(4, 0, 9)
while passcodePattern == nil and passcodeResult == nil do
Wait(0)
end
SendNUIMessage({type = 'intro'})
Wait(3500)
-- Update timer string
CreateThread(function()
while timer > 0 and isGameActive do
timer = timer - 1
timeString = secondsToString(timer)
toggleAnimOverlay = not toggleAnimOverlay
Wait(1000)
end
if not gameWon and isGameActive then
isPlayerInputDisabled = true
gameWon = false
blinkDialog(false)
CreateThread(function()
Wait(3000)
callbackFn(2,'ran out of time')
SendNUIMessage({type = 'fail'})
isGameActive = false
end)
end
end)
-- Update scrable count
local count = 1
CreateThread(function()
waitTimer = (timer*1000)/#scramblePos
while count <= #scramblePos do
Wait(waitTimer)
count = count + 1
end
end)
local showFakePattern = false
local curFakePattern
CreateThread(function()
generateFakePattern()
local newthread = false
local draw = true
isPlayerInputDisabled = true
-- Show fake patterns
for index,itemTable in pairs(fakepattern) do
showFakePattern = true
curFakePattern = {}
for colnum,rownum in pairs(itemTable) do
table.insert(curFakePattern, innerCircles[colnum][rownum])
end
SendNUIMessage({type = 'audio', audioType = 'fake'})
Wait(800)
showFakePattern = false
Wait(200)
end
-- Show real pattern at the end
for i=1,2 do
showFakePattern = true
curFakePattern = {}
for colnum,rownum in pairs(passcodePattern) do
table.insert(curFakePattern, innerCircles[colnum][rownum])
end
SendNUIMessage({type = 'audio', audioType = 'real'})
Wait(300)
showFakePattern = false
Wait(200)
end
showFakePattern = false
activeColumn = 1
isPlayerInputDisabled = false
end)
while isGameActive do
Wait(0)
drawSprite(
'mphackinggamebg',
'bg',
0.50, 0.50, 1.0, 1.0, 0, 255, 255, 255, 255
)
-- Animation stuff
if toggleAnimOverlay then
drawSprite(
'mphackinggamewin',
'tech_1_3',
0.2, 0.40, 0.3, 0.5, 0, 255, 255, 255, 255
)
drawSprite(
'mphackinggamewin2',
'tech_2_2',
0.18, 0.80, 0.3, 0.3, 0, 255, 255, 255, 255
)
drawSprite(
'mphackinggamewin',
'tech_1_1',
0.8, 0.50, 0.3, 0.6, 0, 0, 140, 150, 255
)
else
drawSprite(
'mphackinggamewin',
'tech_1_1',
0.2, 0.40, 0.3, 0.5, 0, 255, 255, 255, 255
)
drawSprite(
'mphackinggamewin2',
'tech_2_0',
0.18, 0.80, 0.3, 0.3, 0, 255, 255, 255, 255
)
drawSprite(
'mphackinggamewin',
'tech_1_4',
0.8, 0.50, 0.3, 0.6, 0, 0, 140, 150, 255
)
end
-- Draw main overlay over background
drawSprite(
'mporderunlock',
'background_layout',
0.50, 0.50, 0.7, 0.85, 0, 255, 255, 255, 255
)
-- More animation stuff
if toggleAnimOverlay then
drawSprite('mporderunlock_decor',
'techaration_0',
0.50, 0.50, 0.7, 0.85, 0, 255, 255, 255, 255
)
else
drawSprite('mporderunlock_decor',
'techaration_1',
0.50, 0.50, 0.7, 0.85, 0, 255, 255, 255, 255
)
end
-- Life counter
for i=1, availableLife do
drawSprite(
'mphackinggame',
'life',
lifePos[i].x, lifePos[i].y, 0.035, 0.055, 0, 255, 255, 255, 255
)
end
showTimer()
-- Show fake patterns when toggled before every level start
if showFakePattern then
if curFakePattern ~= nil then
for i,k in pairs(curFakePattern) do
drawSprite(
'mporderunlock',
'correct_circles',
k.x, k.y, 0.06, 0.10, 0, 255, 255, 255, 255
)
end
end
end
-- Draw past columns
for i=1,activeColumn do
for j=1,#innerCircles[i] do
drawSprite(
'mporderunlock',
'inner_circles',
innerCircles[i][j].x, innerCircles[i][j].y, 0.07, 0.11, 0, 255, 255, 255, 255
)
end
end
-- Draw selected/active column
if activeColumn > 0 and activeRow > 0 then
drawSprite(
'mporderunlock',
'selector',
innerCircles[activeColumn][activeRow].x, innerCircles[activeColumn][activeRow].y, 0.07, 0.11, 0, 255, 255, 255, 255
)
end
-- Scramble reduction logic loop
for i=count,#scramblePos do
drawSprite(
'mphackinggame',
'scrambler_fill_segment',
scramblePos[i].x, scramblePos[i].y, 0.005, 0.07, 0, 255, 255, 255, 255
)
end
-- Render passcode for completed levels
if activeStage-1 > 0 then
local upperLimit = 1
if activeStage == 5 then
upperLimit = 4
else
upperLimit = activeStage-1
end
for i=1, upperLimit do
drawSprite(
'mporderunlock',
'keypad_feedback_'..passcodeResult[i],
resultCodePos[i].x, resultCodePos[i].y, 0.035, 0.06, 0, 255, 255, 255, 255
)
local keypadPos = fakeKeyButtons[(passcodeResult[i]+1)]
drawSprite(
'mporderunlock',
'keypad_'..passcodeResult[i],
keypadPos.x, keypadPos.y, 0.055, 0.09, 0, 255, 255, 255, 255
)
end
end
-- Render border box for code which needs to be cracked
if activeStage < 5 then
drawSprite(
'mporderunlock',
'keypad_feedback_box',
resultCodePos[activeStage].x, resultCodePos[activeStage].y, 0.045, 0.07, 0, 255, 255, 255, 255
)
end
-- Draw all correct selections
for i=1,#selectedDots['correctDots'] do
local rowNum = selectedDots['correctDots'][i].row
local colNum = selectedDots['correctDots'][i].col
local pos = innerCircles[colNum][rowNum]
drawSprite(
'mporderunlock',
'correct_circles',
pos.x, pos.y, 0.06, 0.10, 0, 255, 255, 255, 255
)
end
-- Draw all incorrect selections
for i=1,#selectedDots['incorrectDots'] do
local rowNum = selectedDots['incorrectDots'][i].row
local colNum = selectedDots['incorrectDots'][i].col
local pos = innerCircles[colNum][rowNum]
drawSprite(
'mporderunlock',
'incorrect_circles',
pos.x, pos.y, 0.02, 0.03, 0, 255, 255, 255, 255
)
end
-- Only show when its toggled by blinkDialog function
if showDialog then
drawSprite('mphackinggame', dialogTexName, 0.5, 0.5, 0.35, 0.15, 0.0, 255, 255, 255, 1.0)
end
if not isPlayerInputDisabled then -- Make sure player doesn't input when things are being processed
if IsControlJustPressed(0, 194) then -- Backspace
gameWon = false
timer = 0
elseif IsControlJustPressed(0, 172) then -- Arrow up
if activeRow > 1 then
SendNUIMessage({type = 'audio', audioType = 'keypress'})
activeRow = activeRow - 1
end
elseif IsControlJustPressed(0, 173) then -- Arrow down
if activeRow < 5 then
SendNUIMessage({type = 'audio', audioType = 'keypress'})
activeRow = activeRow + 1
end
elseif IsControlJustPressed(0, 191) then -- Enter
if activeColumn > 0 and activeColumn < 7 and activeRow ~= 0 then
if passcodePattern[activeColumn] == activeRow then -- If the selected position is correct then
local isCircleAlreadyPresent = false
-- Verify that it hasn't already been selected
for i=1, #selectedDots['correctDots'] do
if selectedDots['correctDots'][i].row == activeRow and selectedDots['correctDots'][i].col == activeColumn then
isCircleAlreadyPresent = true
break
end
end
if not isCircleAlreadyPresent then
SendNUIMessage({type = 'audio', audioType = 'correct'})
table.insert(selectedDots['correctDots'], {row=activeRow, col=activeColumn})
end
-- Logic for processing next stage
if activeColumn == 6 and activeStage < 4 then
blinkDialog(true)
showFakePattern = false
curFakePattern = {}
activeColumn = 0
activeRow = 0
if activeStage <=4 then
activeStage = activeStage + 1
CreateThread(function()
local newthread = false
local draw = true
isPlayerInputDisabled = true
selectedDots['correctDots'] = {}
selectedDots['incorrectDots'] = {}
generateFakePattern()
passcodePattern = generatePattern(6, 1, 5)
while passcodePattern == nil do
Wait(0)
end
while showDialog do
Wait(500)
end
for index,itemTable in pairs(fakepattern) do
showFakePattern = true
curFakePattern = {}
for colnum,rownum in pairs(itemTable) do
table.insert(curFakePattern, innerCircles[colnum][rownum])
end
SendNUIMessage({type = 'audio', audioType = 'fake'})
Wait(800)
showFakePattern = false
Wait(200)
end
for i=1,2 do
showFakePattern = true
curFakePattern = {}
for colnum,rownum in pairs(passcodePattern) do
table.insert(curFakePattern, innerCircles[colnum][rownum])
end
SendNUIMessage({type = 'audio', audioType = 'real'})
Wait(300)
showFakePattern = false
Wait(200)
end
showFakePattern = false
activeRow = 0
activeColumn = 1
isPlayerInputDisabled = false
end)
end
elseif activeColumn == 6 and activeStage == 4 then
activeStage = activeStage + 1
activeRow = 0
activeColumn = 0
isPlayerInputDisabled = true
gameWon = true
blinkDialog(true)
CreateThread(function()
Wait(3000)
callbackFn(1,'Hack successful')
SendNUIMessage({type = 'success'})
isGameActive = false
end)
end
if activeColumn < 6 then
activeColumn = activeColumn + 1
end
else
SendNUIMessage({type = 'audio', audioType = 'incorrect'})
local isCircleAlreadyPresent = false
for i=1, #selectedDots['incorrectDots'] do
if selectedDots['incorrectDots'][i].row == activeRow and selectedDots['incorrectDots'][i].col == activeColumn then
isCircleAlreadyPresent = true
break
end
end
if not isCircleAlreadyPresent then
table.insert(selectedDots['incorrectDots'], {row=activeRow, col=activeColumn})
end
if availableLife > 0 then
availableLife = availableLife - 1
end
if availableLife <= 0 then
availableLife = 0
isPlayerInputDisabled = true
gameWon = false
blinkDialog(false)
CreateThread(function()
Wait(3000)
callbackFn(0,'Lives ran out')
SendNUIMessage({type = 'fail'})
isGameActive = false
end)
end
end
end
end
end
end
end)
end
AddEventHandler("ultra-keypadhack", function(life, time, returnFn)
if life and time and returnFn then
callbackFn = returnFn
if life <= 0 or life > 6 then
callbackFn(-1,'Invalid lives passed')
return
end
if time < minTime or time > maxTime then
callbackFn(-1,'Invalid time passed')
return
end
timer = tonumber(time)
availableLife = tonumber(life)
timeString = {}
activeStage = 1
activeColumn = 0
activeRow = 0
activeSelection = 0
selectedDots['correctDots'] = {}
selectedDots['incorrectDots'] = {}
toggleAnimOverlay = true
isPlayerInputDisabled = false
gameWon = false
if not isGameActive then
isGameActive = true
startGame()
else
isGameActive = false
end
else
callbackFn(-1,'Invalid parameters passed')
end
end)