/
afkmoney_v2.ahk
1977 lines (1780 loc) · 53.3 KB
/
afkmoney_v2.ahk
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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Requires AutoHotkey v2.0
#SingleInstance force
;Version 0.5
; 10/28/2023: gradually learning to use FindText(); the GUI is still a bit confusing to me
; TODO: replace all ImageSearch with FindText()'s version
; Eventually maybe: store several resolutions of FindText
; A setup wizard would be nice, that leads the user through the screenshotting process.
; A single key to screenshot each relevant screen, followed by later snipping, makes sense to me.
; AFKMoney_v2 moved to github on 8/14/2023:
; https://github.com/tallpeak/AHK/tree/main/GTA/AFKMoney
; Also linked from QOMPH.com/gta ; ignore the ZIP of the v1 version
; IMPORTANT SETUP INSTRUCTIONS!
; If you want to use F8 to start looping the
; AFKMoney & RP mission, you will need to make screenshots
; of some appropriate portion of the screen used to identify
; the corresponding screen area
; representing where in the process the game currently is.
;
; These files must be placed in the "img" subdirectory.
;
; My resolution is 1280x720, so my screen clippings are named as follows:
; AFKMoney&RPv2_1280x720.png -- the name of the mission to be bookmarked from social club; can be found in the upper-left corner of the screen after pressing z, while in the AFK survival mission
; Play_1280x720.png -- Play button to start mission
; SETTINGS_1280x720.png -- SETTINGS header of first screen after Play/Replay button
; INVITE_1280x720.png -- "INVITE" header of the second screen after Play/Replay button
; Replay_1280x720.png -- Large Replay button on voting screen after mission over
; Not needed: ConfirmSettings_1280x720.png -- "Confirm Settings"
;
; And yes, I know this process could use some
; better error detection and documentation... maybe tomorrow.
InstallKeybdHook
InstallMouseHook ; causes WheelDown and WheelUp to remain "physically" pressed-down, according to GetKeyState
; but installing the mouse hook causes A_TimeIdlePhysical to revert to 0 when mouse is moving
hideMouseWheelUpDownPhysical := false ; hide this apparent bug (whether in AHK, Windows, bluetooth mouse driver, or game); it seems to go away after resetting bluetooth.
KeyHistory(100)
Persistent
#Include "AppVol.AHK"
#Include "dialer.AHK" ; stolen from https://github.com/2called-chaos/gtav-online-ahk
#Include "*i RyzenAdj.AHK" ; for controlling milliwatts on my AMD 5625U CPU
global gWaitTimer := 0
; Important configuration variables
AttemptLaunch := true ; Run steam game
Debug_KeyState := true
KeyState_Update_Interval := 500
global Mouse_Blocked := false
launch_dir := A_ScriptDir
SetWorkingDir(A_ScriptDir) ; Ensures a consistent starting directory.
imgDir := A_ScriptDir . "/img"
if (! FileExist(imgDir)) {
DirCreate(imgDir)
; also need to do some setup to screenshot the relevant clippings
}
GTAtitle := "GTA5"
SetNumLockState("Off") ; set a consistent state for Numlock
SetCapsLockState("Off") ; it always annoys me when I accidentally hit capslock
SendMode("Event") ; default, and only working method
myTimeIdlePhysical() {
return Min(A_TimeIdleKeyboard, A_TimeIdleMouse)
}
; AFKmoney by Aaron W. West, aaron@qomph.com
; converted to AHK2 7/13-7/21/2023
; uploaded to https://qomph.com/gta
; Started 3/7/2021
; Original script by reddit u/lucasgabriel7, "Updated 6/27/20" per
; https://www.reddit.com/r/gtaglitches/comments/gx8kol/improved_ahk_script_for_afk_money_rp_glitch_pc/
; For use with "AFK Money & RP v2" job
; Bookmark the job from Social Club;
; and make sure it is your first job in the list of bookmarked Survival jobs.
; 4/24: Quick volume control: Ctrl Up and Down
; 4/29: Interrupt the user after 25 minutes, until Replay pressed, regardless of whether busy
; (added MinMissionSeconds & elapsedMission)
; 5/?? aggressive window switching after 25 minutes, to avoid missing Replay
; 5/16 replaced A_TimeIdlePhysical with A_TimeIdlePhysical but didn't like aggressive window switching; changing back
; 7/26 - 7/20 update broke ImageSearch -- fixed, I think
; 8/2 SetVolume was creating multiple timers, now -2000
; 8/4 wait for Ctrl to be released for get vehicle
; 10/3/2021 stop searching for Play button; this seems to no longer work
; The biggest remaining issue with this script:
; Originally I was trying to make the computer usable during automation
; (return keyboard focus to the "original" window)
; I did not fully succeed, but it's usable during Netflix or Youtube,
; and sometimes light work if you don't mind the aggressive window switching at about 25 minutes into mission.
; ImageSearch can only work when the window is active, unfortunately;
; binary code could be included to fix this issue, but I like this script to be pure AutoHotKey and no binaries.
; Rewrite needed, using SetTimer instead of a loop. Would be much cleaner.
#SingleInstance force
; #WinActivateForce ; This does not seem to have any effect; a different workaround may be needed for occasionally failing WinActivate
; REMOVED: #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; disable #Warn for normal use because it can bring up modal dialogs (halt script with error)
#Warn All ;,OutputDebug ; Enable warnings to assist with detecting common errors
; SendMode must be left at the default (Event); GTA does not seem to respond to "Input":
; SendMode,Event
; DetectHiddenWindows, On
; CONSTANTS
; A "kick" is a periodic activity to prevent idle; currently {z}
GTAwindow := "ahk_exe GTA5.exe" ; or "ahk_class grcWindow"
;Sky Fall Fast AFK Test = 8
WhichJob := 1 ; (only upload this as #0, first job) move down how many times in the bookmarked Survivals?
helptext:=" F8 Start,F9 Resume,F10 Exit,F12 Freemode "
UserIdleThreshold := 122 * 1000 ; (milliseconds) At least 10 to 60 seconds, to avoid interrupting the user
; Tweak this for your system, based on highest elapsed value seen during wave 20:
; start interrupting the user when close to end of mission
; If set too high, the Replay button may be missed:
MinMissionSeconds := 1500-10 ; Last measured 1506 (25 minutes)
MaxMissionSeconds := 1500+90 ; Stop aggressively switching windows after this time
MinKickSeconds := 3 * 60 ; when user is idle
MaxKickSeconds := 10 * 60 ; Normally, 2 to 14 minutes, to avoid idle kick at 15 min
EmergencyKickSeconds := 9*60 ; A few minutes before 15 minute idle kick
RaiseStealth := false ; if you'd like more stealth, set to true
; global KEY_SEND_DELAY := 190 ; Increase this if it moves between menus very fast.
; global KEY_PRESS_DELAY := 20 ; If it doesn't press, increase it too.
Enable_SPAM := false ; seems to just annoy people when advertised in freemode
MenuDelay := 1600
warning := ""
lastKick := A_TickCount
idleSec := 0
VolumeIncrement := 5
Volume := 50 ; I like starting volume to be lower than other apps (for the first SetVolume)
ProcessId := 0
gotoFreemode := ""
setdefaultkeydelay()
gtaWX := 0
gtaWY := 0
gtaWW := 0
gtaWH := 0
if ! WinExist(GTAwindow) {
if AttemptLaunch {
Run("steam://rungameid/271590") ; RunWait sometimes gets stuck
}
; If the user alt-tabs away while the launcher is loading, this can take a long time
gtawindowfound := 0
Loop 3 {
ToolTip("Looking for GTA5, waiting 60 seconds, loop #" . A_Index . " of 3")
gtawindowfound := WinWaitActive(GTAwindow,,60) ; Set GTA in focus at start (but user can change focus)
if gtawindowfound {
break
}
WinActivate(GTAwindow)
}
ToolTip("")
if gtawindowfound && WinExist(GTAwindow) {
ToolTip("GTA5 window found, reloading script in 4 seconds...")
Sleep(4000)
ToolTip()
Reload
ToolTip("Reload failed")
Sleep(2000)
ExitApp(1)
} else {
ToolTip("can't find GTA5.exe; exiting in 10 seconds. Reload the script after loading GTA")
Sleep(10000)
ExitApp(1)
}
}
;WinGetPos(>aWX, >aWY, >aWW, >aWH)
WinGetClientPostries := 0
Loop {
TryWinActivate(GTAwindow)
WinGetClientPos(>aWX, >aWY, >aWW, >aWH, GTAwindow)
Sleep(100)
if WinGetClientPostries > 100 {
throw("can't get client window position/size, bombing out")
}
WinGetClientPostries += 1
} until gtaWW > 0 && gtaWH > 0
full_command_line := DllCall("GetCommandLine", "str")
WinSetAlwaysOnTop(false) ; bug I hit once after alt-enter to go fullscreen; it was stuck on top after returning to windowed
; ImageResolution := "_1280x720" ; screen resolution at which the image was clipped
; bug in 2.0.7? ImageResolution == _0x0 gtaWX: -32000 gtaWY: -32000 gtaWH: 0 gtaWW: 0
ImageResolution := "_" . gtaWW . "x" . gtaWH ; current screen resolution; look for images recorded at same
XToolTip := 200
YToolTip := gtaWH-20
; Old method of messaging the user was ToolTip, but I like WinSetTitle better
; although title bar usage requires windowed with borders
;ToolTip, Instructions for use`: %helptext%, XToolTip, YToolTip, 1
WinSetTitle(GTAtitle "`: " helptext, GTAwindow)
startMission := 0
GetAllKeyState() {
ListLines false
freq := 0
CounterBefore := 0
CounterAfter := 0
;Critical "On" ;; testing to see if the timing would be more stable
;~ DllCall("QueryPerformanceFrequency", "Int64*", &freq)
;~ DllCall("QueryPerformanceCounter", "Int64*", &CounterBefore)
;~ kss := ""
kp := "" ; physical key states
kl := "" ; logical key states
kb := "" ; both
Loop 255 {
vk := Format("vk{:X}", A_Index)
n := GetKeyName(vk)
p := GetKeyState(vk, "P")
l := GetKeyState(vk)
;; display vk only if not [0-9A-Z]
if A_Index >= 48 && A_Index <= 57 || A_Index >= 65 && A_Index <= 90 {
ks := n . " "
} else {
ks := n . "(" . vk . ") "
}
if p && l && p == l {
kb .= ks
} else if l && !p {
kl .= ks
} else if p && !l && (((A_Index & 0x9E) != 0x9E) && !hideMouseWheelUpDownPhysical) {
; got tired of seeing MouseWheelUp and MouseWheelDown
kp .= ks
}
}
kss := ""
if StrLen(kb) {
kss .= " keyState:" . kb
}
if StrLen(kp) {
kss .= "Phys:" . kp
}
if StrLen(kl) {
kss .= " Logi:" . kl
}
;~ if StrLen(kss)>0 {
;~ DllCall("QueryPerformanceCounter", "Int64*", &CounterAfter)
;~ kss .= "" . Format("{:d} µs", (CounterAfter - CounterBefore) * 1000000 / freq)
;~ }
;Critical "Off"
ListLines true
return kss
}
; Reload clears logical keystate, so this may not be very useful,
; or only useful when "physical" keystate is stuck down
*^!NumLock::ClearAllKeyState()
ClearAllKeyState() {
WinSetTitle("Clearing key state", GTAwindow)
Loop 255 {
vk := Format("vk{:X}", A_Index)
p := GetKeyState(vk, "P")
l := GetKeyState(vk)
if p || l {
Send("{" . vk . " up}")
}
}
UpdateTitleBar_KeyState()
}
global current_keystate := ""
global last_keystate := ""
updateTitleBar() {
global last_keystate, lastKick
if last_keystate == "suspended" {
return
}
if WinActive(GTAwindow) {
; if idle 5 minutes and more than 5 minutes since last anti-idle event:
if A_TimeIdle > 300000 && lastKick < A_TickCount - 300000 {
Send("{blind}z")
lastKick := A_TickCount
}
}
if last_keystate != current_keystate {
title := GTAtitle . "`: " . current_keystate
WinSetTitle(title, GTAwindow)
last_keystate := current_keystate
}
}
UpdateTitleBar_KeyState() {
global current_keystate := GetAllKeyState()
updateTitleBar()
}
UpdateTimer() {
if Debug_KeyState {
SetTimer(UpdateTitleBar_KeyState, KeyState_Update_Interval, 0)
} else {
SetTimer(UpdateTitleBar_KeyState, 0, 0)
}
}
UpdateTimer()
^!u:: {
global
Debug_KeyState := !Debug_KeyState
WinSetTitle("Debug_KeyState=" Debug_KeyState , GTAwindow )
UpdateTimer()
}
;Return ;; used to end running the script here
;Hotkey, F8, Start_AFK_Farming
;Hotkey, F9, Resume_AFK_Farming
;Hotkey, F10, Shutdown_AFK_Farming
;;;;;;;;;;;;;;;;;;;;;;;
;; pressDuration must be longer than 1 frame
;; so if vsync = half (30fps), then it must be at least 34ms
setdefaultkeydelay(){
SetKeyDelay(30, 90) ;delay,pressDuration ; WAS 190,20
}
^!+s::
StealthCircles(*)
{
KeyWait("Ctrl", "T2")
KeyWait("Alt", "T2")
KeyWait("Shift", "T2")
KeyWait("s", "T1")
global RaiseStealth:=!RaiseStealth
if (RaiseStealth)
{
Send("{LCtrl}")
Send("{d down}")
}
else
{
Send("{LCtrl}")
Send("{d up}")
}
}
; ^!F4::
; Process, Close, GTA5.exe
; return
*^!F6::
{
ClearAllKeyState()
reloadscript()
}
^!F7::
;Sleep, 10*60000 ; 10 minutes, enough time for a resupply to come in
{
Loop 300
{
remaining := 600 - A_Index * 2
WinSetTitle(remaining " seconds until start of automation", GTAwindow)
Sleep(2000)
}
Start_AFK_Farming()
}
^!F8::
{
Start_AFK_Farming()
}
^!F9::
{
Resume_AFK_Farming()
}
^!F10::
{
Shutdown_AFK_Farming()
}
^!F11::
{
KeyWait("Ctrl", "T2")
KeyWait("Alt", "T2")
KeyWait("F11", "T1")
Goto(SPAM)
}
^!F12::
{
toggleReturnToFreemode()
}
; Avoid messing with application-specific hotkeys:
#HotIf WinActive(GTAwindow) ; //replaces #IfWinActive from AHK v1
; Try this ?
; HotIfWinActive(GTAwindow)
; Pressing F8 hogs the thread so that F8 doesn't work again,
; until SetTimer and Return releases the thread
F8::Start_AFK_Farming()
Start_AFK_Farming()
{
;Start_AFK_Farming:
SetCapsLockState("AlwaysOff") ; prevent Social Club from popping up during automation
global gotoFreemode := ""
setdefaultkeydelay()
job_status := 0
TryWinActivate(GTAwindow) ; GTA need to be on focus.
Sleep(10)
ErrorLevel := WinWaitActive(GTAwindow, , 1) , ErrorLevel := ErrorLevel = 0 ? 1 : 0
Sleep(10)
KeyWait("Ctrl", "T1")
KeyWait("Shift", "T2")
KeyWait("F8", "T3") ; wait for F8 to be released
Sleep(MenuDelay)
Send("{esc down}") ; Pause menu
Sleep(MenuDelay)
Send("{esc up}") ; Pause menu
Sleep( MenuDelay * 5 ) ; this is hard to get right?
Send("{d}") ; ONLINE tab
Sleep(MenuDelay)
Send("{enter}") ; ONLINE dropdown
Sleep(MenuDelay)
Send("{enter}") ; Jobs
Sleep(MenuDelay)
Send("{s}") ; Play Job
Sleep(MenuDelay)
Send("{enter}") ; select Play Job
Sleep(MenuDelay)
Send("{s}") ; Bookmarked
Sleep(MenuDelay)
Send("{enter}") ; select Bookmarked
Sleep( MenuDelay * 4 ) ; it can take a long time for this menu to come up
Send("{w 5}") ; Survivals
Sleep(100)
Send("{enter}") ; Select Survivals
Sleep(400)
Loop WhichJob ; which survival
{
Send("{s}")
Sleep(66)
}
Send("{enter}")
Loop 5
{
Sleep(MenuDelay)
Send("{enter}")
}
;Gosub, SPAM
; Sleep, ( MenuDelay * 3.2 )
global startMission := A_TickCount
; Goto, Resume_AFK_Farming
SetTimer(Resume_AFK_Farming,-100)
}
F9::Resume_AFK_Farming()
Resume_AFK_Farming()
; It's impossible to compute startMission, so I just make a guess
; Unless it's possible to read Wave ## (but if I could do that, I'd scan for Wave 20)
{
global startMission := A_TickCount - 5 * 60000 ; Just a guess
SetTimer(Resume_AFK_Farming2,-100)
Return ; Free the thread so that F8/F9 keys can be pressed again
}
Resume_AFK_Farming2()
{
global gotoFreemode := ""
setdefaultkeydelay()
SPAM()
Loop
{
original := 0
elapsedMission := Round((A_TickCount - startMission) / 1000)
; try to avoid interrupting the user when busy
; Do not change below to A_TimeIdlePhysical; it starts aggressive windows switching and interrupting the game
; I think it's because keydown is a single event, so driving/flying straight is idle activity, after the threashold
; Ideally, I would like to be able to customize the meaning of TimeIdle(Physical) to my needs
; Or create a keyboard+mouse hook for every event to create my own idle variable
if (A_TimeIdlePhysical < UserIdleThreshold
&& (elapsedMission < MinMissionSeconds || elapsedMission >= MaxMissionSeconds ))
{
if (! WinActive(GTAwindow) && WinExist(GTAwindow)) {
;ToolTip, %warning% User busy`:idle`=%idleSec%s, 750, 1, 1
kss := GetAllKeyState()
WinSetTitle(GTAtitle "`:" kss " " warning " User busy`:idle`=" idleSec "s idle=" A_TimeIdle " phys=" A_TimeIdlePhysical " " gotoFreemode " elapseM=" elapsedMission " V" Volume, GTAwindow)
}
}
else
{
if (A_TimeIdlePhysical < UserIdleThreshold && (! WinActive("ahk_axe GTA5.exe")) && (! gotoFreemode))
{
; warn the user that they are being interrupted
Loop 1 {
SoundBeep(6666, 10)
;Sleep(10)
}
}
original := -1
tries := 0
while original == -1 && tries < 5 {
tries += 1
try {
original := WinGetID("A")
break
} catch Error as e {
OutputDebug("Error" || e)
}
OutputDebug("original wingetid=" || original || ",tries=" || tries)
}
;~ if original == -1 {
;~ ToolTip("cant get original window; returning")
;~ sleep(3333)
;~ ToolTip("")
;~ return
;~ }
TryWinActivate(GTAwindow)
Sleep(200)
ErrorLevel := WinWaitActive(GTAwindow, , 2)
ErrorLevel := ErrorLevel = 0 ? 1 : 0
}
;ImageSearch is pointless if GTA not active window (it will fail)
If WinActive(GTAwindow)
{
; the time has come! to switch to FindText() ...
;~ ; Possibly reduce search area to lower CPU usage
;~ ; And/or change image search frequency depending on elapsed time in mission
;~ ImageSearch(&xSettings, &ySettings, 1, 1, A_ScreenWidth, A_ScreenHeight, "*30 " launch_dir "\img\SETTINGS" ImageResolution ".png")
;~ ImageSearch(&xInvite, &yInvite, 1, 1, A_ScreenWidth, A_ScreenHeight, "*30 " launch_dir "\img\INVITE" ImageResolution ".png")
;~ ; Replay=534,694; *50 because it has to be higher than 30, because Replay is on a changing background, I think
;~ ImageSearch(&xReplay, &yReplay, 1, 1, A_ScreenWidth, A_ScreenHeight, "*80 " launch_dir "\img\Replay" ImageResolution ".png")
xSettings:=ySettings:=xInvite:=yInvite:=xReplay:=yReplay:=""
Text:="|<SETTINGS>*133$60.Vk001BxsT3ArzDbAxkCNSrzTbARbawTrzTbBRjqT3kDTbBBjz3krzTbBZi3lyrzTbBpjnwSrzTbBljmwArzTbBtbWQVk7TbBts31U"
Text.="|<INVITE>*131$38.NtT+0U6CHqwtxXaxjSTMNiPrbqKNixs5abPjSTNVovrbqQQSxtxb7bjSTNttvrU8"
Text.="|<Replay>*123$55.zUzzzyTzzy0DzzyDzzz3rzzz7zzznvzzz/zzzntzzz5zzztwzzzZzzzswsybasjSwssi9msXCQktqAmsnCS1snCMstbC3wn7AwtbD9y3b4wwn6iSTXaSQna7DjXaCQNXLnnWW6AMXPxw10MlV0zzztzzzzszzzwzzzzkzzzyzzzzmTzzyTzzzmTzzzDzzzvDzzzjzzztDy"
tStart := FindText().QPC()
if (ok:=FindText(&X, &Y, 1, 1, A_ScreenWidth, A_ScreenHeight, 0, 0, Text)) {
switch(ok[1].id) {
case "SETTINGS" : xSettings := ok[1].1, ySettings := ok[1].2
case "INVITE" : xInvite := ok[1].1, yInvite := ok[1].2
case "Replay" : xReplay := ok[1].1, yReplay := ok[1].2
}
}
tEnd := FindText().QPC()
tElapsed := tEnd - tStart
;~ positions last found for Replay: if (ok:=FindText(&X, &Y, 693-150000, 579-150000, 693+150000, 579+150000, 0, 0, Text))
; Some debugging information; status and image locations if found
global idleSec:=Round((A_TickCount - lastKick)/1000)
;ToolTip, %warning% SETTINGS`=%xSettings%`,%ySettings% INVITE=%xInvite%`,%yInvite% Replay=%xReplay%`,%yReplay% idle`=%idleSec%s %helptext%, XToolTip, YToolTip, 1
WinSetTitle(GTAtitle "`:" gotoFreemode " " warning " SETTINGS`=" xSettings "," ySettings " INVITE=" xInvite "," yInvite " Replay=" xReplay "," yReplay " idle`=" idleSec "s idle=" A_TimeIdle " phys=" A_TimeIdlePhysical " elapM=" elapsedMission " " helptext " V" Volume " " gtaWW "x" gtaWH ", t=" Round(tElapsed) "ms", GTAwindow)
if (xSettings != "")
{
Sleep(MenuDelay)
TryWinActivate(GTAwindow) ; GTA need to be on focus.
Send("{w}")
Send("{enter}")
if original > 0 {
TryWinActivate("ahk_id " original)
}
Sleep(( MenuDelay * 2 ))
Continue
}
else if (xInvite != "") ; && xPlay != ""
{
; TODO: change from search for Invite to search for PLAY
Sleep(MenuDelay * 6) ; this seems necessary; play button doesnt appear immediately
; Experiment with leaving the mission open? (can make more with more players)
; No: they will often vote me into a real survival!
TryWinActivate(GTAwindow) ; GTA need to be on focus.
CloseMission := True
if (CloseMission) {
Send("{d}") ; Matchmaking: closed
Sleep(222)
}
Send("{w}")
Sleep(222)
Send("{w}")
Sleep(222)
if (CloseMission) {
Send("{d}") ; client invites: disabled
Sleep(222)
}
Send("{s}") ; Play
Sleep(222)
Send("{enter}") ; launch
Sleep(2000)
Send("{enter 3}") ; are you sure you want to launch this on your own?
; a few of minutes of waiting for possible player joining
Loop 50 ; because of "player joining" at times
{
Sleep(MenuDelay * 5)
if WinActive(GTAwindow)
{
if (A_TimeIdlePhysical > 10000) ; dont interrupt typing in chat, etc
{
Send("{enter}") ; launch
}
; for more accurate mission timing,
; find the AFKMoney&RPv2 image and set the mission start time
Sleep(100)
TryWinActivate(GTAwindow) ; GTA need to be on focus.
Send("{z}")
Sleep(200)
;~ ImageSearch(&xMission, &yMission, 1, 1, A_ScreenWidth, A_ScreenHeight, "*30 " launch_dir "\img\AFKMoney&RPv2" ImageResolution ".png")
;~ if (xMission)
;~ {
;~ ;ToolTip, AFKMoney`&RPv2_800x600=(%xMission%`,%yMission%), xMission, yMission, 2
;~ ; (x,y)=(14,29)
;~ ;SetTimer, deleteToolTip2, -30000
;~ break ; so that we can set startMission
;~ }
t1:=A_TickCount, Text:=X:=Y:=""
Text:="|<>*177$115.zsBzzyzzzzzzbz7lzztttytySTzzzzzfzQnjzvQRzNzDDzzzzzozjfvzvqizdzjb3UsPrszrpxxrur0kzpfCrPqrwzvqQyvvRjtTupjPg3Pxfw30zPnUrxrxerhqzhylyxbzprjPytynPqvStzQzSrztrrpzSzNinRqQzaTjPzwtw"
if (ok:=FindText(&X:="wait", &Y:=3, 1, 1, 247+150, 113+150, 0, 0, Text))
{
; FindText().Click(X, Y, "L")
break ; so that we can set startMission
}
; consider killing GTA5,
; Quitting the mission,
; or other drastic measures if we fail to find the mission we are looking for
}
SetCapsLockState("Off") ; instead of AlwaysOff; this is to prevent Social Club from popping up during automation
if A_LoopField == 50 {
; failed to find mission, need to exit after the end of this
global gotoFreemode := "Freemode"
}
}
global startMission := A_TickCount ; - 5 * 24 ; compensate for loop above
TryWinActivate("ahk_id " original)
Sleep(( MenuDelay * 10 ))
if WinActive(GTAwindow)
{
doSPAM() ; clue any joiners into the fact that I am likely AFK!
Send("t{Esc}")
}
Continue
}
else if (xReplay != "")
{
; Job is done, time to find a new one! (Press replay!)
Send("{w}zz")
if (gotoFreemode)
{
Send("{d}zz{d}") ; Freemode is two to the right from Replay
Sleep(MenuDelay)
SoundBeep(444, 20)
}
Sleep(MenuDelay)
Send("{enter}") ; vote for replay or freemode
Sleep(60000) ; wait a minute! To prevent possible re-vote
startMission := A_TickCount ; so that we stop bothering the user with window switching as soon as possible!
TryWinActivate("ahk_id " original)
if gotoFreemode && A_TimeIdlePhysical > 3600000 {
; user is very idle (over an hour) yet we are returning to freemode; not good!
; spending a long time in freemode while AFK can lead to raids, for example
; so just suspend the game until the user gets back
WinSetTitle("Idle>1hr while going Freemode; suspending game in 180 sec; ESC to abort",GTAwindow)
kw := KeyWait("{ESC}","DT180")
if !kw && A_TimeIdlePhysical > 3600000 {
; copy-paste coding (sorry!)
Thread("NoTimers")
Suspend(true) ; prevent hotkeys (Send to the window would cause a deadlock)
global last_keystate := "suspended"
Critical "On"
PID_or_Name := GTAwindow
WinSetTitle("Suspending game...",PID_or_Name)
Sleep(200)
PID := (InStr(PID_or_Name, ".")) ? ProcExist(PID_or_Name) : PID_or_Name
h:=DllCall("OpenProcess", "uInt", 0x1F0FFF, "Int", 0, "Int", pid)
If !h
Return -1
DllCall("ntdll.dll\NtSuspendProcess", "Int", h)
mb := MsgBox("Resume game? (exit script if no)",,4)
if mb == "Yes" {
DllCall("ntdll.dll\NtResumeProcess", "Int", h)
DllCall("CloseHandle", "Int", h)
} else {
ExitApp()
}
Critical "Off"
global last_keystate := ""
Suspend(false)
Thread("NoTimers",false)
}
}
job_status := 0
Sleep(( MenuDelay * 3 ))
Continue
}
}
; else { ; Prevent AFK idle kick
if (A_TimeIdlePhysical > UserIdleThreshold
&& A_TickCount > ( lastKick + MinKickSeconds*1000)
|| A_TickCount > ( lastKick + MaxKickSeconds*1000) )
{
;WinGet, original, , ahk_exe GTA5.exe
TryWinActivate(GTAwindow)
ErrorLevel := WinWaitActive(GTAwindow, , 1) , ErrorLevel := ErrorLevel = 0 ? 1 : 0
if !WinActive(GTAwindow)
{
; This code comes from a time when I thought WinActivate was failing. It could probably be deleted
if WinExist(GTAwindow)
{
; WinMinimize, A
; Send {Alt Down}{Tab}{Alt Up}
; Sleep,50
TryWinActivate(GTAwindow)
ErrorLevel := WinWaitActive(GTAwindow, , 1) , ErrorLevel := ErrorLevel = 0 ? 1 : 0 ; might be hanging?
}
Else ; If GTA5 crashed, we might as well quit? Consider restarting GTA5?
{
ToolTip("`"GTA5 gone; crashed? Exiting...`"")
Sleep(5000)
ToolTip()
ExitApp(1)
}
}
If WinActive(GTAwindow)
{
if (A_TimeIdlePhysical > 4*60*1000) ; when *very* AFK, but hopefully not about to get kicked (ESC can interfere with some things)
{
Send("{t}") ; talk, but don't say anything
Sleep(600) ;I think this is needed when social club overlay is up?
Send("{Esc}") ; this should escape from Social Club overlay if up, else escape from Talk
Sleep(600)
}
Send("{z}")
if (RaiseStealth)
{
if (A_TickCount < startMission + 15 * 60000)
{
StealthCircles()
}
else
{
Send("{d up}")
}
}
; Sleep, MenuDelay * 10
global lastKick := A_TickCount
global warning := ""
ToolTip(, , , 2)
}
Else
{
warning := " WinActivate Failed!"
ToolTip(warning, 20, 100, 2)
if (A_TickCount > ( lastKick + EmergencyKickSeconds*1000))
{
; EMERGENCY! Warn user that idle kick timeout may be coming quickly
Loop 10
{
TryWinActivate(GTAwindow)
ErrorLevel := WinWaitActive(GTAwindow, , 1) , ErrorLevel := ErrorLevel = 0 ? 1 : 0
If WinActive(GTAwindow)
{
Send("{blind}{z}")
; Sleep, MenuDelay * 10
lastKick := A_TickCount
warning := ""
ToolTip(, , , 2)
Continue
}
else
{
If (!WinExist(GTAwindow))
{
;ToolTip, "GTA5.exe does not exist; crashed? Exiting..."
;sleep,3000
;ExitApp, 1 ; no need to keep running? User will just have to restart.
Continue
}
SoundBeep(666, 10)
Sleep(10)
}
}
}
}
TryWinActivate("ahk_id " original)
}
TryWinActivate("ahk_id " original)
Sleep(( MenuDelay * 2))
}
}
; first time pressed; disable Replay image search and window activation
; second time pressed = exit AHK
F10::Shutdown_AFK_Farming()
Shutdown_AFK_Farming()
{
if (startMission > 0) {
global startMission := -24*3600*1000 ; a large negative number equal to one day
Return
}
Shutdown_AFK_Farming1:
;ToolTip, Shutting down AFK_Farming..., XToolTip, YToolTip, 1
WinSetTitle(GTAtitle "`: Shutting down AFKmoney...", GTAwindow)
Sleep(MenuDelay * 2) ; Just so the user can read the message
;ToolTip, , , , 1
WinSetTitle("Grand Theft Auto V", GTAwindow)
ExitApp() ; stop the macro
}
F6::reloadscript()
reloadscript()
{
Reload()
Sleep(1000) ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
msgResult := MsgBox("The script could not be reloaded. Would you like to open it for editing?", "", 4)
if (msgResult = "Yes") {
Edit()
}
}
^!+r::Reload() ; Ctrl+Alt+R
; A little bit of self-promotion; hopefully not too much
SPAM()
{
IF (Enable_SPAM)
{
doSPAM()
}
}
F11::doSPAM()
doSPAM()
{
if (WinActive(GTAwindow) )
{
SetKeyDelay(3, 1)
Send("t{Esc}")
Sleep(100)
Send("t")
Sleep(100)
Send("Free AFK money macro: QOMPH.COM/GTA")
setdefaultkeydelay()
Sleep(MenuDelay * 2) ; a brief chance to press ESC to reduce spamming
Send("{Enter}")
}
}
pasteToChat(msg)
{
KeyWait("Ctrl", "T2")
KeyWait("Alt", "T2")
KeyWait("v", "T2")
SetKeyDelay(0, 10)
;Send("t{Esc}")
;SendMode("Input")
Loop Parse msg, "`r`n", "`r`n" {
if StrLen(A_LoopField) > 0 {
m := StrReplace(A_LoopField,"`t"," ")
Sleep(200)
Send("t")
Sleep(100)
Send("{Raw}" . m)
;SendInput("Input:{Raw}" . m)
;SendPlay("Play:{Raw}" . m)
;SendEvent("Event:{Raw}" . m)
;SendText("Text:{Raw}" . m)
Send("{enter}")
}
}
;SendMode("Event")
}
/*
^+F11::{
msg := ( "Public service announcement, to help PC users with griefing modders"
"|To escape from a session, get pssuspend from Microsoft.com and run this command:"
"|pssuspend gta5 && timeout -T 10 && pssuspend -r gta5"
"|See https://learn.microsoft.com/en-us/sysinternals/downloads/pssuspend{enter}" )
pasteToChat(msg)
setdefaultkeydelay()
}
*/
F12::toggleReturnToFreemode()
toggleReturnToFreemode()
{
global gotoFreemode
ErrorLevel := !KeyWait("Ctrl", "T2")
ErrorLevel := !KeyWait("Alt", "T2")
ErrorLevel := !KeyWait("F12", "T1")
if (gotoFreemode) {
global gotoFreemode := ""
} else global gotoFreemode := "Freemode"
Return
}
; get oppressor mk2 from mechanic using dialNumber (last vehicle in arcade)
^o::getOppressor2_DialMechanic()
getOppressor2_DialMechanic() {
dialMechanic_getCar(-8,-1)
}
; -1 means last garage or last car
; 0 should be first garage or first car
; +1 is second garage or second car
dialMechanic_getCar(garage,car) {
CallMechanic("")
Sleep(5600)
Send("{" (garage >= 0 ? "down " : "up ") abs(garage) "}")
Send("{enter}")
Sleep(100)
Send("{" (car >= 0 ? "down " : "up ") abs(car) "}")
; Send("{enter}")
setdefaultkeydelay()
}
; old call mors insurance; only works in freemode
; so use dialNumber instead
;~ ^m::
;~ {
;~ SetCapsLockState("AlwaysOff")
;~ ErrorLevel := !KeyWait("Alt", "T2")
;~ SetKeyDelay(10, 200) ;delay,pressDuration
;~ Send("{up}")
;~ Sleep(666)
;~ Send("{right}{up}{enter}")
;~ Sleep(666)
;~ Send("{up 16}{enter}")
;~ setdefaultkeydelay()
;~ }
; it was working fine in freemode but not missions;
; hence the switch to using the dialer
;~ ; get oppressor mk2 from mechanic (last vehicle in arcade)
;~ ^o::
;~ {
;~ SetCapsLockState("AlwaysOff")
;~ ErrorLevel := !KeyWait("Alt", "T2")
;~ SetKeyDelay(15, 200) ;delay,pressDuration
;~ Send("{up}")
;~ Sleep(666)
;~ Send("{right}{up}{enter}")
;~ Sleep(777)
;~ ;Send("{up 18}{enter}") ; sometimes 17
;~ Send("{left 4}{down 2}{enter}")
;~ Sleep(5250) ; or up 9 instead of {down 5(assoc) or 6(ceo)}
;~ Send("{up 8}{enter}{up}") ; {enter}
;~ setdefaultkeydelay()
;~ }
; Oppressor Mk2 get ??? seems to be return to garage
;~ ErrorLevel := !KeyWait("Alt", "T2")
;~ SetKeyDelay(25, 15) ;delay,pressDuration
;~ Send("{m}")
;~ Sleep(55) ; or up 9 instead of {down 5(assoc) or 6(ceo)}
;~ Send("{down 5}{enter}{down 3}{enter}{down 2}{enter}")
;~ setdefaultkeydelay()
; Oppressor Mk2 get from terrorbyte
^+o::
{
KeyWait("Shift", "T2")
KeyWait("Control", "T2")
SetKeyDelay(10, 70) ;delay,pressDuration
Send("{m}")
Sleep(55)
Send("{down 6}{enter}{down 3}{enter}{down 2}{enter}")
Send("z{enter}z{esc 3}") ; one extra enter, some delay
setdefaultkeydelay()
}
;;helicopter fly forward 120 seconds
^+NumpadUp::flyHeli()
^+Numpad8::flyHeli()
flyHeli()
{