-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoCraftProphecies.au3
570 lines (462 loc) · 16.6 KB
/
AutoCraftProphecies.au3
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
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.5
Author: Hitagi
Script Function:
Seal prophecies and put it into inventory. Works on 1920x1080 fullscreen (or borderless).
#ce ----------------------------------------------------------------------------
#pragma compile(Console, true)
#pragma compile(x64, true)
#pragma compile(Icon, "ProphecyOrbRed.ico")
#pragma compile(Out, "build/AutoCraftProph.exe")
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <Misc.au3>
#include <Crypt.au3>
#include "include/Inventory.au3"
#include "include/Stash.au3"
#include "include/StashQuad.au3"
#include "include/Log_.au3"
#include "include/CSVPrefilledPrices.au3"
#include "include/CSV.au3"
HotKeySet("^k", "Start")
HotKeySet("^l", "Stop")
Global $hWnd
Global $g_isStarted = False
Global $g_isRestarted = True
Global $g_oDictNeededList
Global $g_sCsvDeletedPath
; From FileClose() DOCS: Upon termination, AutoIt automatically closes any files it opened, but calling FileClose() is still a good idea.
; Yep, it closes automatically. So, don't care of it.
Global $g_hCsvHwnd
Global Const $PropheciesPositions = [ [320, 256], [168, 315], [458, 315], [132, 480], [492, 480], [224, 640], [408, 640] ]
Global Const $ProphecySeekButtonPositions = [ [298, 770], [365, 787] ]
Global Const $ProphecySealButtonPositions = [ [298, 215], [365, 232], [389, 602], [458, 619] ]
#cs
WaitForStart
Only on Restart. Ask user to point Navali
No:
Stop Script
Yes:
Monitor LMB and save mouse cursor coordinates on click
Only on Restart. Ask user to point Stash
No:
Stop Script
Yes:
Monitor LMB and save mouse cursor coordinates on click
Check Prophecy Window is open
No:
Try click Navali position according user input
Check Prophecy Window is open
No:
Stop Script
Open Inventory if closed
Scan Inventory (for empty space)
If Inventory is full then
Scan Inventory (for prophecies)
No prophecies:
Stop Script (inventory full)
Try click Stash position according user input
Check Stash is open
No:
Stop Script
CtrlClick any prophecies to Stash
If Stash is full:
Stop Script
ContinueLoop
Check Prophecy Exists
Yes:
Click Seal Button
Check "not enough coins" dialog
Yes:
Stop Script
No:
Confirm Prophecy Sealing
Put item to inventory
Check if need to destroy item
Yes:
Destroy (with confirm)
No:
Click Seek Button
Check "not enough coins" dialog
Yes:
Stop Script
No:
Move to "Check Prophecy Window is open" step (ContinueLoop)
#ce
Main()
Func Main()
$hWnd = WinGetHandle("Path of " & 'E' & 'x' & 'i' & 'l' & 'e')
;$hWnd = WinGetHandle("XnView")
If @error Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle PoE")
Exit
EndIf
$pos = WinGetPos($hWnd)
If @error Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the $windowHeight")
Exit
EndIf
Global $g_iWindowOffsetLeft = $pos[0]
Global $g_iWindowOffsetTop = $pos[1]
Global $g_iWindowWidth = $pos[2]
Global $g_iWindowHeight = $pos[3]
Log_(@ScriptName & ' is ready. Open Navali Prophecies dialog and press Ctrl+K to start or Ctrl+L to pause!')
Local $aInventory[0]
$g_oDictNeededList = GetPrefilledPricesDict(@ScriptDir & '\ProphPrices\_prefilled-prices.tsv')
$g_sCsvDeletedPath = GetCsvDeletedPath()
$bCsvHeaderAdded = False
While True
WinWaitActive($hWnd)
Sleep(100)
If Not $g_isStarted Then
ContinueLoop
EndIf
If $g_isRestarted Then
Log_('Request user for Stash and Navali positions...')
If Not AskUserToPointCharacters() Then
Stop('The request for Stash and Navali was cancelled.')
ContinueLoop
EndIf
Sleep(200)
EndIf
InitInventorySettings()
;Do
$bIClosed = CheckInventoryClosed()
If $bIClosed Then
;If Not IsStorageVisible() Then
Log_('Opening inventory...')
Send('{i}')
EndIf
;Until Not $bIClosed
If Not UBound($aInventory) Or $g_isRestarted Then
$g_isRestarted = False
Log_('Scanning inventory...')
; Move cursor out of inventory
Log_('Move cursor out of inventory (3)')
MoveOutCursor()
$aInventory = StorageScan($COLOR_EMPTY, $COLOR_EMPTY_SHADE)
EndIf
If Not UBound($aInventory) Then
Log_('Inventory is full. Scanning inventory for Prophecies...')
$aProphecyInventory = StorageScan($COLOR_PROPHECY, $COLOR_PROPHECY_SHADE)
If UBound($aProphecyInventory) Then
Log_('Trying to move Prophecies to Stash...')
Send('{ESC}')
Sleep(100)
Log_('Opening Stash...')
ClickStash()
; Move cursor out of Stash
Log_('Move cursor out of Stash')
MoveOutCursor()
InitStashSettings()
If Not IsStorageVisible() Then
InitStashQuadSettings()
If Not IsStorageVisible() Then
Stop('No stash visible')
ContinueLoop
EndIf
EndIf
InitInventorySettings()
StorageCtrlClickItem($aProphecyInventory)
If @error Then
Stop()
ContinueLoop
EndIf
Send('{ESC}')
Sleep(100)
Else
Stop('Inventory is full.')
ContinueLoop
EndIf
EndIf
If CheckProphWindowOpen() Then
Log_('Prophecies window is Open')
Else
Log_('Trying to click Navali...')
; Move cursor out of inventory
Log_('Move cursor out of inventory (4)')
MoveOutCursor()
If Not CheckInventoryClosed() Then
Send('{ESC}')
Sleep(100)
EndIf
ClickNavali()
If Not CheckProphWindowOpen() Then
Stop('Prophecies window is Closed.')
ContinueLoop
EndIf
EndIf
; Move cursor out of inventory
;Log_('Move cursor out of inventory (2)')
;MouseMove(Random(300, 330, 1), Random(770, 780, 1))
If CheckInventoryClosed() Then
;If Not IsStorageVisible() Then
Log_('Opening inventory...')
Send('{i}')
EndIf
If CheckProphecyExist() Then
PressSeal()
Sleep(200)
If CheckEmptyWalletDialog() Then
Stop('Not enough Silver coins to Seal.')
ContinueLoop
EndIf
If CheckConfirmDialog() Then
PressConfirmDialog()
Else
Stop('Unknown problem in CheckConfirmDialog.')
ContinueLoop
EndIf
Log_('Put into inventory')
$iInventoryKey = StoragePutItem($aInventory)
If @error Then
Stop('Inventory is full.')
ContinueLoop
EndIf
Sleep(200)
$sItemInfo = GetItemInfo()
$aInfo = SplitProphecyInfo($sItemInfo)
If @error Then
; place is occupied
If IsNumber($iInventoryKey) Then
_ArrayDelete($aInventory, $iInventoryKey)
EndIf
LogE('Error in SplitProphecyInfo()')
ContinueLoop
EndIf
$sHash = String(_Crypt_HashData($aInfo[0] & $aInfo[1], $CALG_MD5))
If $g_oDictNeededList.Exists($sHash) Then
; place is occupied
If IsNumber($iInventoryKey) Then
_ArrayDelete($aInventory, $iInventoryKey)
EndIf
Else
Log_('Destroing item...')
Local $aHeader[0][3], $aRow[1][3] = [[$aInfo[0], $aInfo[1], $sHash]]
If Not $bCsvHeaderAdded Then
Local $aHeader[1][3] = [['Name', 'Title', 'Hash']]
$bCsvHeaderAdded = True
EndIf
CsvAppend($aRow, $aHeader, $g_sCsvDeletedPath, $g_hCsvHwnd)
MouseClick($MOUSE_CLICK_LEFT)
Sleep(50)
MouseClick($MOUSE_CLICK_LEFT, Random(1230, 1244, 1), MouseGetPos(1) + Random(0, 10, 1))
Sleep(200)
; confirm dialog
If PixelGetColor(1170, 570) = 0x612f07 Then
Send('{ENTER}')
;Send('{ESC}')
Sleep(10)
EndIf
EndIf
; Move cursor out of inventory
;Log_('Move cursor out of inventory (1)')
;MouseMove(Random(650, 1200, 1), Random(400, 800, 1))
;Stop('TODO.')
;ContinueLoop
Else
PressSeek()
Sleep(100)
If CheckEmptyWalletDialog() Then
Stop('Not enough Silver coins to Seek.')
ContinueLoop
EndIf
;ContinueLoop
EndIf
WEnd
EndFunc
Func Start($state = True)
$state = IsDeclared('state') ? $state : True ; Because HotKeySet ignore default values of arguments too!
$g_isRestarted = True
$g_isStarted = $state
Log_('Started: ' & $g_isStarted)
Beep($g_isStarted ? 250 : 200, 250)
EndFunc
Func Stop($reason = '')
$reason = IsDeclared('reason') ? $reason : 'User interrupt' ; Because HotKeySet ignore default values of arguments too!
If $reason Then Log_($reason)
Log_('Stopping the script...')
Start(False)
; ContinueLoop ; "ExitLoop/ContinueLoop" statements only valid from inside a For/Do/While loop.
EndFunc
Func CheckProphWindowOpen()
$left = $ProphecySeekButtonPositions[0][0]
$top = $ProphecySeekButtonPositions[0][1]
$right = $left + 3
$bottom = $top + 1
; Used 'Seek' button to check. It have 3 states...
Const $CHECKSUM = 409076213
Const $CHECKSUM_HOVER = 778699702
Const $CHECKSUM_DISABLED = 299827555
$checksumActual = PixelChecksum($left, $top, $right, $bottom, 1, $hWnd)
Log_('CheckProphWindowOpen: ' & $checksumActual, $LOG_LEVEL_DEBUG)
Return $CHECKSUM = $checksumActual Or $CHECKSUM_HOVER = $checksumActual Or $CHECKSUM_DISABLED = $checksumActual
EndFunc
Func CheckProphecyExist()
$left = $PropheciesPositions[6][0]
$top = $PropheciesPositions[6][1]
$right = $left + 3
$bottom = $top + 1
Const $CHECKSUM = 1554450471
$checksumActual = PixelChecksum($left, $top, $right, $bottom, 1, $hWnd)
Log_('CheckProphecyExist: ' & $checksumActual, $LOG_LEVEL_DEBUG)
Return $CHECKSUM = $checksumActual
EndFunc
Func PressSeek()
$x = Random($ProphecySeekButtonPositions[0][0], $ProphecySeekButtonPositions[1][0], 1)
$y = Random($ProphecySeekButtonPositions[0][1], $ProphecySeekButtonPositions[1][1], 1)
$speed = Random(10, 20, 1)
Log_('PressSeek')
MouseClick($MOUSE_CLICK_LEFT, $x, $y, 1, $speed)
EndFunc
Func PressSeal()
$x = Random($ProphecySealButtonPositions[2][0], $ProphecySealButtonPositions[3][0], 1)
$y = Random($ProphecySealButtonPositions[2][1], $ProphecySealButtonPositions[3][1], 1)
$speed = Random(10, 20, 1)
Log_('PressSeal')
MouseClick($MOUSE_CLICK_LEFT, $x, $y, 1, $speed)
EndFunc
Func CheckEmptyWalletDialog()
Const $POSITION_X = 962
Const $POSITION_Y = 508
Const $DELTA_X = 16
Const $DELTA_Y = 1
Const $CHECKSUM = 3145278307
$checksumActual = PixelChecksum($POSITION_X, $POSITION_Y, $POSITION_X + $DELTA_X, $POSITION_Y + $DELTA_Y, 1, $hWnd)
Log_('CheckEmptyWalletDialog: ' & $checksumActual, $LOG_LEVEL_DEBUG)
Return $CHECKSUM = $checksumActual
EndFunc
Func CheckConfirmDialog()
Const $POSITION_X = 820
Const $POSITION_Y = 541
Const $DELTA_X = 3
Const $DELTA_Y = 1
Const $CHECKSUM = 1266288032
$checksumActual = PixelChecksum($POSITION_X, $POSITION_Y, $POSITION_X + $DELTA_X, $POSITION_Y + $DELTA_Y, 1, $hWnd)
Log_('CheckConfirmDialog: ' & $checksumActual, $LOG_LEVEL_DEBUG)
Return $CHECKSUM = $checksumActual
EndFunc
Func PressConfirmDialog()
;$x = Random(777, 896, 1)
;$y = Random(542, 568, 1)
;$speed = Random(10, 20, 1)
Log_('PressConfirmDialog')
;MouseClick($MOUSE_CLICK_LEFT, $x, $y, 1, $speed)
Send('{ENTER}')
Sleep(100)
EndFunc
Func CheckInventoryClosed()
Const $POSITION_X = 1415
Const $POSITION_Y = 74
Const $DELTA_X = 7
Const $DELTA_Y = 1
Const $CHECKSUM = 3809219403
$checksumActual = PixelChecksum($POSITION_X, $POSITION_Y, $POSITION_X + $DELTA_X, $POSITION_Y + $DELTA_Y, 1, $hWnd)
Log_('CheckInventoryClosed: ' & $checksumActual, $LOG_LEVEL_DEBUG)
Return $CHECKSUM <> $checksumActual
EndFunc
Func AskUserToPointCharacters()
If Not IsDeclared('g_aNavaliPos') Then
Global $g_aNavaliPos[0]
EndIf
If Not IsDeclared('g_aStashPos') Then
Global $g_aStashPos[0]
EndIf
$iResult = MsgBox(UBound($g_aNavaliPos) ? $MB_CANCELTRYCONTINUE : $MB_OKCANCEL, 'Set position of NAVALI', _
'Close all ingame dialogs (Esc) and mouse click on the NAVALI.' & @CRLF & @CRLF & _
'Make sure NAVALI and Stash are close enough so that the character doesn''t move when you click on both.' & @CRLF & @CRLF & _
'Ok (Continue) to set the position, Cancel to adjust positions, Retry to use previous positions.')
If $iResult = $IDCANCEL Then
Return False
EndIf
If $iResult = $IDCONTINUE Or $iResult = $IDOK Then
$g_aNavaliPos = ListenForUserACtion()
If @error Then
Return False
EndIf
EndIf
$iResult = MsgBox(UBound($g_aStashPos) ? $MB_CANCELTRYCONTINUE : $MB_OKCANCEL, 'Set position of STASH', _
'Close all ingame dialogs (Esc) and mouse click on the STASH.' & @CRLF & @CRLF & _
'Make sure STASH and Navali are close enough so that the character doesn''t move when you click on both.' & @CRLF & @CRLF & _
'Also Make sure ACTIVE stash tab is for Prophecies purpose.' & @CRLF & @CRLF & _
'Ok (Continue) to set the position, Cancel to adjust positions, Retry to use previous positions')
If $iResult = $IDCANCEL Then
Return False
EndIf
If $iResult = $IDCONTINUE Or $iResult = $IDOK Then
$g_aStashPos = ListenForUserACtion()
If @error Then
Return False
EndIf
EndIf
Return True
EndFunc
Func ClickNavali()
Const $NAVALI_DIALOG_PROPH_POS_X = 870
Const $NAVALI_DIALOG_PROPH_WIDTH = 180
Const $NAVALI_DIALOG_PROPH_POS_Y = 183
Send('{CTRLDOWN}')
MouseClick($MOUSE_CLICK_LEFT, $g_aNavaliPos[0], $g_aNavaliPos[1])
Send('{CTRLUP}')
Sleep(250)
;MouseClick($MOUSE_CLICK_LEFT, Random($NAVALI_DIALOG_PROPH_POS_X, $NAVALI_DIALOG_PROPH_POS_X + $NAVALI_DIALOG_PROPH_WIDTH, 1), $NAVALI_DIALOG_PROPH_POS_Y)
;Sleep(150)
EndFunc
Func ClickStash()
MouseClick($MOUSE_CLICK_LEFT, $g_aStashPos[0], $g_aStashPos[1])
Sleep(150)
EndFunc
; '01' - Left mouse button {@see _IsPressed}
Func ListenForUserACtion($keyCode = '01')
Const $USER_CANCELED = 1
Local $hDLL = DllOpen("user32.dll")
Local $aResult[2]
While 1
If _IsPressed($keyCode, $hDLL) Then
Log_("ListenForUserACtion - Key was pressed.", $LOG_LEVEL_DEBUG)
; Wait until key is released.
While _IsPressed($keyCode, $hDLL)
Sleep(10)
WEnd
Log_("ListenForUserACtion - Key was released.", $LOG_LEVEL_DEBUG)
$aResult = MouseGetPos()
ExitLoop
ElseIf _IsPressed("1B", $hDLL) Then
Log_("The Esc Key was pressed, therefore we will stop listening action.", $LOG_LEVEL_DEBUG)
SetError($USER_CANCELED)
ExitLoop
EndIf
Sleep(10)
WEnd
DllClose($hDLL)
Return $aResult
EndFunc
Func StorageCtrlClickItem(ByRef $aInventory)
Const $ERROR_INTERRUPT = 1
$isError = False
Send('{CTRLDOWN}')
For $i = 0 To UBound($aInventory) - 1
If Not $g_isStarted Then
$isError = True
ExitLoop
EndIf
StorageClickItem($aInventory[$i][0], $aInventory[$i][1])
Sleep(200)
If Not CellCheckIsEmpty($aInventory[$i][0], $aInventory[$i][1]) Then
Stop('Looks like stash is full')
$isError = True
ExitLoop
EndIf
Next
Send('{CTRLUP}')
If $isError Then
SetError($ERROR_INTERRUPT)
EndIf
EndFunc
Func GetCsvDeletedPath()
Return @ScriptDir & '\ProphDeleted\' & StringFormat('%s-%s-%s_%s-%s.tsv', @YEAR, @MON, @MDAY, @HOUR, @MIN)
EndFunc
Func MoveOutCursor()
MouseMove($g_iWindowWidth / 2 + $g_iWindowOffsetLeft, $g_iWindowHeight / 2 + $g_iWindowOffsetTop)
EndFunc