-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathLineage2Rev.au3
More file actions
484 lines (384 loc) · 11.9 KB
/
Lineage2Rev.au3
File metadata and controls
484 lines (384 loc) · 11.9 KB
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
#RequireAdmin
#pragma compile(FileDescription, Raven Bot)
#pragma compile(ProductName, Raven Bot)
#pragma compile(ProductVersion, 0.10)
#pragma compile(FileVersion, 0.10)
#pragma compile(LegalCopyright, DarkJaden)
$sBotName = "Lineage 2 Revolution Bot"
$sBotVersion = "0.10"
$sBotTitle = "AutoIt " & $sBotName & " v" & $sBotVersion
#include <Bots/Util/SetLog.au3>
#include <Bots/Util/Time.au3>
#include <Bots/Util/CreateLogFile.au3>
#include <Bots/Util/_Sleep.au3>
#include <Bots/Util/Click.au3>
#include <Bots/Util/SaveImageToFile.au3>
#include <Bots/Util/Pixels/_CaptureRegion.au3>
#include <Bots/Util/Image Search/ImageSearch.au3>
#include <ScreenCapture.au3>
#include <Bots/GlobalVariables.au3>
#include <Bots/Config.au3>
#include <Bots/AutoFlow.au3>
#include <Bots/ScrollQuest.au3>
#include <Bots/WeeklyQuest.au3>
#include <Bots/AdenaDungeon.au3>
#include <Bots/DailyDungeon.au3>
#include <Bots/PvPBattle.au3>
#include <Bots/OmanTower.au3>
#include <Bots/MainQuest.au3>
#include <Bots/CleanRedDot.au3>
#include <Bots/Form/MainView.au3>
#include-once
Opt("MouseCoordMode", 2)
Opt("GUICoordMode", 2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)
Opt("TrayIconHide", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "mainViewClose", $mainView)
GUIRegisterMsg($WM_COMMAND, "GUIControl")
GUIRegisterMsg($WM_SYSCOMMAND, "GUIControl")
; Initialize
DirCreate($dirLogs)
DirCreate($dirCapture)
_GDIPlus_Startup()
CreateLogFile()
loadConfig()
applyConfig()
Func findWindow()
Local $found = False
Local $arr = StringSplit($setting_win_title, "|")
For $i = 1 To $arr[0]
$rect = WinGetPos($arr[$i])
If Not @error Then
$winList = WinList($arr[$i])
$count = $winList[0][0]
For $w = 1 To $count
$rect = WinGetPos( $winList[$w][1] )
If Not @error Then
If $rect[2] > $MinWinSize AND $rect[3] > $MinWinSize Then
$Title = $winList[$w][0]
$HWnD = $winList[$w][1]
$found = True
UpdateWindowRect()
EndIf
EndIf
If $found Then
ExitLoop
EndIf
Next
If $found Then
ExitLoop
EndIf
EndIf
Next
Return $found
EndFunc
; Just idle around
While 1
Sleep(10)
WEnd
Func runBot()
_log("START" )
$loopCount = 0
Local $iSec, $iMin, $iHour
Local $errorCount = 0
While $RunState
Local $hTimer = TimerInit()
$Restart = False
; Config re-apply
saveConfig()
loadConfig()
applyConfig()
; For Test
;ClickControlPos($POS_TOPMENU_BAG)
;ExitLoop
if $loopCount > 0 Then
_GUICtrlEdit_SetText($txtLog, "")
EndIf
SetLog("Start Loop : " & $loopCount + 1, $COLOR_PURPLE)
Local $res = AutoFlow()
If $res = False OR $RunState = False Then
If $res = False Then
SetLog("Error occurred..", $COLOR_RED)
$errorCount = $errorCount + 1
EndIf
If $errorCount > 3 Then
SetLog("Too many error occurred..", $COLOR_RED)
SaveImageToFile()
ExitLoop
EndIf
Else
$errorCount = 0
$loopCount = $loopCount + 1
Local $time = _TicksToTime(Int(TimerDiff($hTimer)), $iHour, $iMin, $iSec)
$lastElapsed = StringFormat("%02i:%02i:%02i", $iHour, $iMin, $iSec)
EndIf
ExitLoop ; for one loop test
WEnd
_log("Bye" )
btnStop()
EndFunc
Func GUIControl($hWind, $iMsg, $wParam, $lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0x0000FFFF)
Local $hCtrl = $lParam
#forceref $hWind, $iMsg, $wParam, $lParam
Switch $iMsg
Case 273
Switch $nID
Case $GUI_EVENT_CLOSE
mainViewClose()
Case $btnStop
btnStop()
EndSwitch
Case 274
Switch $wParam
Case 0xf060
mainViewClose()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>GUIControl
;------------------------------------------------------------------------------
;
; Util Function
;
;------------------------------------------------------------------------------
Func UpdateWindowRect()
$r = WinGetPos($HWnD)
If Not @error Then
If $r[2] > $MinWinSize AND $r[3] > $MinWinSize Then
$r[0] = $r[0] + $ThickFrameSize
$r[1] = $r[1] + $NoxTitleBarHeight
$r[2] = $r[2] + ($ThickFrameSize * 2)
$r[3] = $r[3] - $NoxTitleBarHeight - $ThickFrameSize
$WinRect = $r
_log("Nox Rect : " & $WinRect[0] & "," & $WinRect[1] & " " & $WinRect[2] & "x" & $WinRect[3])
EndIf
EndIf
EndFunc
Func ControlPos($posInfo)
Local $xy = StringSplit($posInfo, $PosXYSplitter)
Local $x = Number($xy[1]) * $WinRect[2] / 100
Local $y = Number($xy[2]) * $WinRect[3] / 100
$x = $x + $ThickFrameSize
$y = $y + $NoxTitleBarHeight
Local $pos = [$x, $y]
return $pos
EndFunc
Func ClickControlPos($posInfo, $clickCount = 1, $delayMsec = 300)
ClickPos(ControlPos($posInfo), $delayMsec * $setting_delay_rate, $clickCount)
EndFunc
Func ClickBagItem($pos, $clickCount = 1, $delayMsec = 300)
Local Const $MaxCol = 5
Local Const $ItemLeft = ControlPos($POS_BAG_ITEM_LEFT)
Local Const $ItemRight = ControlPos($POS_BAG_ITEM_RIGHT)
Local Const $ItemPanelWidth = $ItemRight[0] - $ItemLeft[0]
Local Const $ItemWidth = $ItemPanelWidth / $MaxCol
Local $itemX = $ItemLeft[0] + (($pos - 1) * $ItemWidth) + ($ItemWidth / 2)
Local $itemY = $ItemLeft[1] + ($ItemWidth / 2)
Local $itemPos = [$itemX, $itemY]
ClickPos($itemPos, $delayMsec, $clickCount)
EndFunc
Func IsNoxActivated()
Local $iState = WinGetState($HWnD)
If BitAND($iState, 8) Then
_log("Nox activated")
Return True
EndIf
_log("Nox Inactivated")
Return False
EndFunc
Func GetPixelColor($x, $y)
$x = $WinRect[0] + $x - $ThickFrameSize
$y = $WinRect[1] + $y - $NoxTitleBarHeight
Local $c = PixelGetColor($x, $y)
Return $c
EndFunc
Func SearchPixel($regionInfo, $PixelTolerance = 12)
Local $infoArr = StringSplit($regionInfo, "|")
Local $posArr = StringSplit($infoArr[1], "-")
If UBound($infoArr) - 1 >= 3 Then
$PixelTolerance = Number($infoArr[3])
EndIf
Local $WinX = $WinRect[0] - $ThickFrameSize
Local $WinY = $WinRect[1] - $NoxTitleBarHeight
Local $leftTopPos = ControlPos($posArr[1])
Local $rightBottomPos = ControlPos($posArr[2])
$x1 = $WinX + $leftTopPos[0]
$y1 = $WinY + $leftTopPos[1]
$x2 = $WinX + $rightBottomPos[0]
$y2 = $WinY + $rightBottomPos[1]
Local $colorArr = StringSplit($infoArr[2], ",")
Local $lastRet
For $c = 1 To UBound($colorArr) - 1
Local $color = StringStripWS($colorArr[$c], $STR_STRIPLEADING + $STR_STRIPTRAILING)
$aCoord = PixelSearch($x1, $y1, $x2, $y2, $color, $PixelTolerance, 1, $HWnD)
If Not @error Then
_log("SearchPixel OK: " & ($x1 - $WinX) & " x " & ($y1 - $WinY) & " => OK " & ($aCoord[0]) & " x " & ($aCoord[1]) & ", " & $color )
$lastRet = $aCoord
Else
_log("SearchPixel Failed: " & ($x1 - $WinX) & " x " & ($y1 - $WinY) & " => " & $color )
Return False
EndIf
Next
Return $lastRet
EndFunc
Func CheckForPixel($screenInfo, $PixelTolerance = 12)
Local $infoArr = StringSplit($screenInfo, "|")
Local $posArr = StringSplit($infoArr[1], ",")
If UBound($infoArr) - 1 >= 3 Then
$PixelTolerance = Number($infoArr[3])
EndIf
Local Const $RegionSize = 3
Local Const $WinX = $WinRect[0] - $ThickFrameSize
Local Const $WinY = $WinRect[1] - $NoxTitleBarHeight
$okCount = 0
For $p = 1 To UBound($posArr) - 1
Local $pos = ControlPos($posArr[$p])
$x = $WinX + $pos[0]
$y = $WinY + $pos[1]
Local $found = False
Local $colorArr = StringSplit($infoArr[2], ",")
Local $answerColor = PixelGetColor($x, $y)
For $c = 1 To UBound($colorArr) - 1
Local $color = StringStripWS($colorArr[$c], $STR_STRIPLEADING + $STR_STRIPTRAILING)
Local $aCoord = PixelSearch($x, $y, $x+$RegionSize, $y+$RegionSize, $color, $PixelTolerance)
If Not @error Then
_log("CheckForPixel : [" & $p & "] " & $pos[0] & " x " & $pos[1] & " => OK " & ($aCoord[0] - $WinX) & " x " & ($aCoord[1] - $WinY) & ", " & $color & " (" & Hex($answerColor) & ") <" & $PixelTolerance & ">");
$okCount = $okCount + 1
$found = True
ExitLoop
EndIf
Next
If $found = False Then
_log("CheckForPixel : " & $pos[0] & "(" & $x & ") x " & $pos[1] & "(" & $y & ") => FAIL (" & Hex($answerColor) & ") : " & $screenInfo)
ExitLoop
EndIf
Next
If $okCount == UBound($posArr) - 1 Then
Return True
EndIf
Return False
EndFunc
Func WaitForPixel($screenInfo)
Local Const $DefaultWaitMsec = 120000
Local Const $DefaultCaptureDelay = 2000
$timer = TimerInit()
Do
If _Sleep($DefaultCaptureDelay) Then ExitLoop
If CheckForPixel($screenInfo) Then
return True
EndIf
Until TimerDiff($timer) > $DefaultWaitMsec
return False
EndFunc
Func WaitSkipScreen()
return WaitForPixel($CHECK_SCREEN_SKIP)
EndFunc
Func CheckSkipScreen()
return CheckForPixel($CHECK_SCREEN_SKIP)
EndFunc
Func CheckAlertPortalScreen()
_log("CheckAlertPortalScreen called");
return CheckForPixel($CHECK_SCREEN_PORTALALERT)
EndFunc
Func CheckAlertInfoScreen($posInfoString = "53:67")
Local $screenInfoNew = StringReplace($CHECK_SCREEN_ALERT_INFO, "XXX", $posInfoString)
return CheckForPixel($screenInfoNew)
EndFunc
Func CheckAlertLowPowerScreen()
return CheckForPixel($CHECK_SCREEN_ALERT_LOW_POWER)
EndFunc
Func CheckScrollQuestEndScreen()
return CheckForPixel($CHECK_SCREEN_SCROLLQUEST_END)
EndFunc
Func CloseAdvertisingScreen()
If _Sleep(800) Then Return
_log("Check Advertising Screen.." );
If CheckForPixel($CHECK_SCREEN_ADVERTISING) Then
SetLog("Close Advertising", $COLOR_BLUE)
ClickControlPos($POS_ALERT_ALERT_ADVERTISING_DO_NOT_SEE_BUTTON, 1, 800)
ClickControlPos($POS_ALERT_ALERT_ADVERTISING_CLOSE_BUTTON, 1, 800)
If _Sleep(500) Then Return
EndIf
EndFunc
Func GoBackToMain()
SetLog("Go back to main", $COLOR_DARKGREY)
ClickControlPos($POS_BACK_LEFT_BUTTON, 2, 200)
ClickControlPos("50:50", 3, 100 )
EndFunc
Func ClickAutoAttackButton()
#cs ----------------------------------------------------------------------------
If CheckForPixel($CHECK_SCREEN_AUTO_ATTCK_ACTIVATED) = False Then
SetLog("Auto Attck Button Click #1", $COLOR_DARKGREY)
ClickControlPos($POS_AUTO_BATTLE_BUTTON, 1, 200)
Else
#ce ----------------------------------------------------------------------------
SetLog("Checking Auto Attack..", $COLOR_DARKGREY)
For $i = 0 To 2
If _Sleep(500) Then Return
; Search 'blue' circle for auto attack
$pos = SearchPixel( "64.8:90.3-70.3:99 | 0xBE841E | 9" ) ; yellow
If IsArray($pos) = False Then
$pos = SearchPixel( "64.8:90.3-70.3:99 | 0x2273A0 | 9" ) ; blue
EndIf
If IsArray($pos) = False Then
SetLog("Auto Attck Button Click #2", $COLOR_DARKGREY)
ClickControlPos($POS_AUTO_BATTLE_BUTTON, 1, 200)
Return
EndIf
Next
#cs ----------------------------------------------------------------------------
EndIf
#ce ----------------------------------------------------------------------------
EndFunc
Func MoveTopRoundTravel($checkActivated = True, $duration = 1200)
If $checkActivated = True Then
WinActivate($HWnD)
EndIf
$p = ControlPos($POS_JOYSTICK_CENTER)
Local Const $WinX = $WinRect[0] - $ThickFrameSize
Local Const $WinY = $WinRect[1] - $NoxTitleBarHeight
$x = $p[0]
$y = $p[1]
MouseMove($x, $y)
MouseDown($MOUSE_CLICK_LEFT)
MouseMove($x+100, $y)
_Sleep($duration)
MouseMove($x, -100)
_Sleep($duration)
MouseMove(-100, 0)
_Sleep($duration)
MouseUp($MOUSE_CLICK_LEFT)
EndFunc
Func ActionAttck($screenInfo, $maxSkill = 4, $normalAttack = True)
Local Const $CastDelay = 300
Local $skill = 0
While $RunState
If CheckForPixel($screenInfo, 10) Then
Return False
Else
If $normalAttack Then
ClickControlPos($POS_BATTLE_ATTACK_BUTTON)
EndIf
Switch $skill
Case 0
ClickControlPos($POS_BATTLE_RARE1_BUTTON)
Case 1
ClickControlPos($POS_BATTLE_RARE2_BUTTON)
Case 2
ClickControlPos($POS_BATTLE_SKILL1_BUTTON)
Case 3
ClickControlPos($POS_BATTLE_SKILL2_BUTTON)
Case 4
ClickControlPos($POS_BATTLE_SKILL3_BUTTON)
EndSwitch
$skill = $skill + 1
If $skill > $maxSkill Then
$skill = 0
EndIf
EndIf
WEnd
Return True
EndFunc