-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathminescript.ahk
487 lines (419 loc) · 13.3 KB
/
minescript.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
; AHK settings
#NoEnv
SetBatchLines -1
SetTitleMatchMode 2
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
FileInstall, ./assets/welcome.png, %A_Temp%/minescript_welcome.png
FileInstall, ./assets/logo.ico, %A_Temp%/minescript_logo.ico
; These don't seem to be doing anything, the compiler won't listen to them :-(
;@Ahk2Exe-SetMainIcon ./assets/logo.ico
;@Ahk2Exe-ExeName Minescript.exe
; Global variables
windowTitle := "Minescript v0.8"
DEBUG := False
targetwinclass := "GLFW30" ; This is the Class of a Java program used to check we have a Minecraft program
targettitle := ""
ModeText := ""
id := 0
ProgState := 0
; 0: Start - Program called for first time and setting default state. Hotkeys set, menu
; configured and default welcome GUI
; 1: Selected - User has selected the target window to send key/mouse activity too
; will use option Menu to slect mode. Note that JumpFlying is only
; avalible while in this state!
; 2: FishingMode - Enter Fishing Mode
; 3: ConcreteMode - Enter Concrete Mode
; 4: MobGrindMode - Enter Mob Grinder Mode
; 5: KillingMode - Enter Killing Mode
; 6: GeneratorMode - Enter Stone/Cobblestone Generator Mode
; Hotkeys
Hotkey !^f, Fishing ; Pressing ctrl + alt + f will start fishing
Hotkey !^e, JumpFly ; Pressing ctrl + alt + e will dubble hit space and fire a rockct in main hand
Hotkey !^c, Concrete ; Pressing ctrl + alt + c will start concrete farming
Hotkey !^m, MobGrind ; Pressing ctrl + alt + m will start mob grinding
Hotkey !^k, MobKill ; Pressing ctrl + alt + k will start mob killing
Hotkey !^g, Generator ; Pressing ctrl + alt + g will start generator mode
Hotkey !^s, Stop ; Pressing ctrl + alt + s will stop it
Hotkey !^w, SelectWindow ; Allows user to select window to control by hovering mouse over it and pressing ctrl + alt + w
; Menu Setup
Menu, Tray, icon, %A_Temp%/minescript_logo.ico
Menu, Tray, Add ; Adds sepearter line
Menu, Tray, Add, UnHide, ShowGUI
Menu, FileMenu, Add, Open, MenuFileOpen
Menu, FileMenu, Add, Hide, HideGUI
Menu, FileMenu, Add, Exit, GUIClose
Menu, HelpMenu, Add, About, MenuHandler
Menu, OptionsMenu, Add, Fishing, MenuFishing
Menu, OptionsMenu, Add, AFK Mob, MenuAFK
Menu, OptionsMenu, Add, Concrete, MenuConcrete
Menu, OptionsMenu, Add, JumpFlying, MenuJumpFly
Menu, OptionsMenu, Add, MobKill, MenuMobKill
Menu, OptionsMenu, Add, Generator, MenuGenerator
Menu, ClickerMenu, Add, File, :FileMenu
Menu, ClickerMenu, Add, Help, :HelpMenu
Menu, ClickerMenu, Add, Options, :OptionsMenu
;===================================================================================================
; GUI-Default Welcome Screen
; Start screen asking user to select the target window to send keys to
;===================================================================================================
If (%ProgState% != 0)
{
Return
}
Gui, Start:Show, Center W300 H300, %windowTitle%
Gui, Start:Add, Pic, W280 H290 vpic_get, %A_Temp%/minescript_welcome.png
Return
;===================================================================================================
; Called when Ctrl+Alt+W is pressed and captures target window information, checks its a java prog
; and then creates the first window.
SelectWindow:
{
; Get mouse pos on screen and grab details of program
MouseGetPos, , , id, control
WinGetTitle, targettitle, ahk_id %id%
WinGetClass, targetclass, ahk_id %id%
If (DEBUG)
{
; Show information about the window such as it's title, ID, class, etc.
MsgBox, ahk_id %id%`nahk_class %targetclass%`n%targettitle%`nControl: %control%
}
; Check if the class of the program is a Minecraft Java Class
If (!InStr(targetclass, targetwinclass))
{
; Class of target program not a match so give a warning message
ErrorTitle := "Warning"
ErrorMsg := "The window which you have selected is not Minecraft! It might be unsafe to use this program on anything other than Minecraft if you don't know what you're doing. Do you wish to continue?"
MsgBox, 0x31, %ErrorTitle%, %ErrorMsg%
IfMsgBox, Cancel
ExitApp, 0
}
; Target window found, swap to next screen
ProgState = 1
Gui, Start:Destroy
Gui, Main:New, , %windowTitle%
Gui, Main:Menu, ClickerMenu
; New in progress GUI
; Gui, Font
; Gui, Font, s17
; Gui, Main:Add, Text, X15 Y15, Current Mode:
; Gui, Font
; Gui, Font, s9, Segoe UI
; testMessage := "AFK fish farms in 1.16+ aren't as efficient as they used to be, but are still great sources of enchanted books and rare items."
; Gui, Main:Add, Text, , %testMessage%
; Left GUI element group
Gui, Main:Add, Text, X10 Y15 , Target Window Title :
Gui, Main:Add, Text, , Windows HWIND is :
Gui, Main:Add, Text, , CURRENT MODE:
Gui, Main:Add, Text, W370 R3 vReminderText, To change mode of operation please select from Option menu.
Gui, Main:Add, Text, ,
Gui, Add, Slider, vMySlider gOnSliderChange W375 ToolTip Range0-1000 TickInterval100, MySlider
; Right GUI element group
Gui, Main:Add, Text, X150 Y15 vtargettitleText, %targettitle%
Gui, Main:Add, Text, vIDText, %id%
Gui, Main:Add, Text, vMode w100, None
; Gui, Main:Add, Text, vMode w100 X150 Y15, None
GuiControl, Main:Hide, MySlider
Gui, Main: Show, H400 H210
; Clear mouse clicks to target by sending UP to the keys:
; - `Right` and `Left` specifies which mouse button to press
; - the `NA` option improves reliability when the window isn't active, and
; - the `U` letter sends an up-event
ControlClick, , ahk_id %id%, , Right, , NAU
ControlClick, , ahk_id %id%, , Left, , NAU
Sleep 500
Return
}
;===================================================================================================
;Menu Functions
; Place holder - will allow users to load saved values
;===================================================================================================
MenuFileOpen:
{
;ModeText := JumpFlying
;GuiControl,,Mode, %ModeText%
Return
}
;===================================================================================================
ShowGUI:
{
Gui, Main:Show, H400 H210
Return
}
;===================================================================================================
HideGUI:
{
Gui, Main:Hide
Return
}
;===================================================================================================
MenuHandler:
{
; TODO: About menu action here
Return
}
; When the slider value is changed, 'submit' the GUI which saves all the values to their variables and hence gets the value of the slider.
OnSliderChange:
{
Gui, Submit, NoHide
Return
}
;===================================================================================================
; Switch to Fishing mode and update window
MenuFishing:
{
; Stop any current active AHK process
BreakLoop := 1
; Uses `n to insert line feeds in multi line text box.
GuiControl, Main:Text, Mode, Fishing
GuiControl, Main:Show, MySlider
GuiControl, Main:Text, ReminderText, CURRENT AVALIBLE OPTIONS:`no- Pressing ctrl + alt + f will start fishing`no- Pressing ctrl + alt + s will stop any AutoKey function above
ProgState := 2
Return
}
;===================================================================================================
; Switch to AFK mode and update window
MenuAFK:
{
; Stop and current active AHK process
BreakLoop := 1
; Uses `n to insert line feeds in multi line text box.
GuiControl, Main:Text, Mode, AFK Mob
GuiControl, Main:Hide, MySlider
GuiControl, Main:Text, ReminderText, CURRENT AVALIBLE OPTIONS:`no- Pressing ctrl + alt + m will start Mob Grinding`no- Pressing ctrl + alt + s will stop any AutoKey function above
ProgState := 4
Return
}
;===================================================================================================
; Switch to Concrete mode and update window
MenuConcrete:
{
; Stop and current active AHK process
BreakLoop := 1
; Uses `n to insert line feeds in multi line text box.
GuiControl, Main:Text, Mode, Concrete
GuiControl, Main:Hide, MySlider
GuiControl, Main:Text, ReminderText, CURRENT AVALIBLE OPTIONS:`no- Pressing ctrl + alt + c will start concrete farming`no- Pressing ctrl + alt + s will stop any AutoKey function above
ProgState := 3
Return
}
;===================================================================================================
; Switch to Flying mode and update window
MenuJumpFly:
{
; Stop and current active AHK process
BreakLoop := 1
; Uses `n to insert line feeds in multi line text box.
GuiControl, Main:Text, Mode, JumpFly
GuiControl, Main:Hide, MySlider
GuiControl, Main:Text, ReminderText, CURRENT AVALIBLE OPTIONS:`no- Pressing ctrl + alt + e will double hit space and fire a rocket in main hand
ProgState := 1
Return
}
MenuMobKill:
{
BreakLoop := 1
GuiControl, Main:Text, Mode, MobKill
GuiControl, Main:Hide, MySlider
GuiControl, Main:Text, ReminderText, CURRENT AVALIBLE OPTIONS:`no- Pressing ctrl + alt + k will start killing mobs`no- Pressing ctrl + alt + s will stop any AutoKey function above
ProgState := 5
Return
}
MenuGenerator:
{
BreakLoop := 1
GuiControl, Main:Text, Mode, Generator
GuiControl, Main:Hide, MySlider
GuiControl, Main:Text, ReminderText, CURRENT AVALIBLE OPTIONS:`no- Pressing ctrl + alt + g will start generator mining`no- Pressing ctrl + alt + s will stop any AutoKey function above
ProgState := 6
Return
}
;===================================================================================================
; Called when Ctrl+Alt+E is pressed.
; NOTE: Target window MUST be in focus for this to work
JumpFly:
{
If (ProgState != 1)
{
Return
}
Sleep 500
Send {Space down}
Sleep 75
Send {Space up}
Sleep 200
Send {Space down}
Sleep 75
Send {Space up}
Sleep 50
ControlClick, , ahk_id %id%, ,Right, , NAD
Sleep 100
ControlClick, , ahk_id %id%, ,Right, , NAU
Return
}
;===================================================================================================
; Called when Ctrl+Alt+C is pressed. Hold both RIGHT and LEFT click down.
Concrete:
{
If (ProgState != 3)
{
Return
}
BreakLoop := 0
While (BreakLoop = 0)
{
ControlClick, , ahk_id %id%, ,Right, , NAD
Sleep 500
ControlClick, , ahk_id %id%, ,Left, , NAD
sleep 100
If (BreakLoop = 1)
{
sleep 10
}
}
ControlClick, , ahk_id %id%, ,Left, , NAU
Sleep 100
ControlClick, , ahk_id %id%, ,Right, , NAU
Return
}
;===================================================================================================
; Called when Ctrl+Alt+F is pressed and continuly clicks RIGHT mouse key
Fishing:
{
If (ProgState != 2)
{
Return
}
BreakLoop := 0
Loop
{
If (BreakLoop = 1)
{
BreakLoop := 0
Break
}
Sleep %MySlider%
ControlClick, , ahk_id %id%, ,Right, , NAD
Sleep 100
ControlClick, , ahk_id %id%, ,Right, , NAU
}
Return
}
;==================================================================================================
; Called when Ctrl+Alt+M is pressed
MobGrind:
{
If (ProgState != 4)
{
Return
}
BreakLoop := 0
Delay := 0
Sleep 500
While (BreakLoop = 0)
{
; On each loop send RIGHT key down as it can be lost when switching focus
ControlClick, , ahk_id %id%, , Right, , NAD
if (BreakLoop = 1)
{
; On Ctrl+Alt+S detected forces a RIGHT mouse key UP
ControlClick, , ahk_id %id%, , Right, , NAU
Return
}
Sleep 100 ;100 ms
; Delay between LEFT clicks is controled by sleep delay above * value tested here (ie 12)
; Example = 100ms * 12 = 1.2 seconds
; This method allows AHK to better exit this mode and respond quicker to Stop command
If (Delay >= 12)
{
; If delay counter reached, reset counter and send a LEFT click
Delay := 0
Sleep 50
ControlClick, , ahk_id %id%, , Left, , NAD
Sleep 50
ControlClick, , ahk_id %id%, , Left, , NAU
}
Else
{
Delay++ ; Increase delay counter by 1
}
}
Sleep 100
; Force mouse keys UP at exit
ControlClick, , ahk_id %id%, , Right, , NAU
ControlClick, , ahk_id %id%, , Left, , NAU
Return
}
MobKill:
{
if (ProgState != 5)
{
Return
}
BreakLoop := 0
Delay := 0
Sleep 500
While (BreakLoop = 0)
{
Sleep 100 ;100 ms
; Delay between LEFT clicks is controled by sleep delay above * value tested here (ie 12)
; Example = 100ms * 12 = 1.2 seconds
; This method allows AHK to better exit this mode and respond quicker to Stop command
If (Delay >= 12)
{
; If delay counter reached, reset counter and send a LEFT click
Delay := 0
Sleep 50
ControlClick, , ahk_id %id%, , Left, , NAD
Sleep 50
ControlClick, , ahk_id %id%, , Left, , NAU
}
Else
{
Delay++ ; Increase delay counter by 1
}
}
Sleep 100
; Force mouse keys UP at exit
ControlClick, , ahk_id %id%, , Left, , NAU
Return
}
;===================================================================================================
; Called when Ctrl+Alt+g is pressed. Hold LEFT click down.
Generator:
{
If (ProgState != 6)
{
Return
}
BreakLoop := 0
While (BreakLoop = 0)
{
ControlClick, , ahk_id %id%, ,Left, , NAD
sleep 100
If (BreakLoop = 1)
{
sleep 10
}
}
ControlClick, , ahk_id %id%, ,Left, , NAU
Sleep 100
Return
}
;==================================================================================================
; Called when Ctrl+Alt+S is pressed at ANYTIME
; By setting the globle value of 'BreakLoop' to 1 this causes any running mode to exit under its own
;control without leaving key states in correctly. Due to Mouse loss of focus STOP will also force
;mouse keys UP.
Stop:
{
BreakLoop := 1
ControlClick, , ahk_id %id%, ,Right, , NAU
ControlClick, , ahk_id %id%, ,Left, , NAU
Sleep 500
Return
}
ESC:
GuiClose:
GuiEscape:
ExitApp