forked from faisalraja/gfbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.au3
1527 lines (1468 loc) · 47.9 KB
/
Bot.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
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
Dim $lostDelay = 25000, $stuckDelay = 1000, $safeCond = "$HP < (15/100) * $HPCAP", $safeRecoverCond = "$HP = $HPCAP AND $MP = $MPCAP", $sitCond = "1 = 0"
Dim $escapeFight = 0, $lastEscapeFight, $waypointRadius = 0, $sitActions[1], $safeRunActions, $waitActions[1], $exitLevel = 0, $exitTimer = 0, $exitBot = False, $escapeFromSafe = False
Dim $memRealTime, $memPerLevel, $memPerKill
Dim $ignoreMonsters = "", $attackMonsters = "", $killWait = False, $statusAtk, $statusDef, $Zoom, $safeStatus = "", $playerAlertDelay = 60000 * 5, $trainOffset = Dec("2B4"), $collectOffset = Dec("2A8")
Dim $escapeHex, $radius, $waypointRetry, $arrowHex, $lastIndex = 0, $lastPartyHP = 0, $partyListPointer, $ignoreAntiKs = False, $partyIndex = 0, $exitDie = 1
Dim $lastTarget = 0, $lostTimes = 0, $miniMapWidth = 140, $stuckIndex = -1, $lastCoords, $groupData, $firstExp = 0, $firstGold = 0, $lastTargetHP = 0, $minSprStamina = 100
Dim $targetIgnoreDistance, $targetAttackDistance, $fightStuckDelay = 8000, $waypointDelay = 3000, $rangeBugCounter = 0, $freezeDelay = "stuckDelay", $safeSitDelay = 120000, $checkListDelay = 10000
Dim $waypointCoord[1][2], $playerAlert, $oldSafeCond = "", $lastChat = "", $lastChatIndex = 0, $allowLoot = False, $partyMembers = 0, $cursorDistance = 50, $mapX = 0, $mapY = 0
Dim $BreakWeapon = False, $BreakArmor = False, $gotoStore = False, $dest = "safe zone", $inventoryFull = False, $destRange = 0, $maplessAntiSleep = 3000, $autoRoute = 0, $doAntiStuck = False
Dim $lootMessage = "[System]There is nothing to pick up.", $backpackFull = "[System]You do not have enough space in your backpack."
Dim $chatCommands[3] = ["SAFESIT", "NOTIFY","QUIT"], $wpm = 60, $shortcutCommands[5] = ["REVIVE", "SAFESIT", "SUMMON_SPR_1", "SUMMON_SPR_2", "SUMMON_SPR_3"], $chatSys = 1, $antiStuck = True, $spriteChat = 10
Func loadMem($type)
Select
Case $type == "RealTime"
$mem = $memRealTime
Case $type == "PerKill"
$mem = $memPerKill
Case $type == "PerLevel"
$mem = $memPerLevel
Case Else
If $configMem.Exists($type & "_DataType") Then
$val = ReadMemoryOffset($configMem.Item($type), 0 , $configMem.Item($type & "_DataType"))
Else
$val = ReadMemoryOffset($configMem.Item($type))
EndIf
GlobalAssign($type, $val)
Return $val
EndSelect
writeMem($type)
For $i = 1 To UBound($mem) - 1
If $configMem.Exists($mem[$i] & "_DataType") Then
$value = ReadMemoryOffset($configMem.Item($mem[$i]), 0 , $configMem.Item($mem[$i] & "_DataType"))
Else
$value = ReadMemoryOffset($configMem.Item($mem[$i]))
EndIf
GlobalAssign($mem[$i], $value)
Next
EndFunc
Func writeMem($type, $data = 0)
Select
Case $type == "RealTime"
$mem = $memRealTime
Case $type == "PerKill"
$mem = $memPerKill
Case $type == "PerLevel"
$mem = $memPerLevel
Case Else
If $configMem.Exists($type & "_DataType") Then
$val = WriteMemoryOffset($data, $configMem.Item($type), 0 , $configMem.Item($type & "_DataType"))
Else
$val = WriteMemoryOffset($data, $configMem.Item($type))
EndIf
GlobalAssign($type, $data)
Return $data
EndSelect
$memKeys = $configMemWrite.Keys
For $write In $memKeys
$search = _ArraySearch($mem, $write)
If $search <> -1 Then
$data = $configMemWrite.Item($write)
If $configMem.Exists($write & "_DataType") Then
$value = WriteMemoryOffset($data, $configMem.Item($write), 0 , $configMem.Item($write & "_DataType"))
Else
$value = WriteMemoryOffset($data, $configMem.Item($write))
EndIf
GlobalAssign($write, $data)
EndIf
Next
EndFunc
Func _initMemory()
loadMem("PerLevel")
If IsDeclared("_Name") Then
updateGUI($nameLabel, Eval("_Name"))
EndIf
If IsDeclared("_ExpCap") Then
$EXPCAP = Eval("_ExpCap")
$firstExp = Eval("_Exp")
updateGUI($expProgress, Floor(($firstExp/$EXPCAP)*100))
EndIf
$Level = Eval("_Level")
$firstGold = Eval("_Gold")
$statusAtk = Eval("_Atk")
$statusDef = Eval("_Def")
updateGUI($levelLabel, $Level)
If $exitLevel = $Level Then
$safeCond = "1=1"
$exitBot = True
setStatus("Exit level activated")
EndIf
EndFunc
Func updateValues()
If $pid <> -1 Then
;Status
loadMem("RealTime")
If IsDeclared("_TargetName") And Not StringRegExp(Eval("_TargetName"), "^[A-Za-z]{1,}[A-Za-z0-9\-_ ]{1,}[^\s]{2,}[A-Za-z0-9\-_ ]{1,}") Then
Dim $tmpTargetPointer = $configMem.Item("TargetName")
ReDim $tmpTargetPointer[UBound($tmpTargetPointer) + 1]
$tmpTargetPointer[UBound($tmpTargetPointer) - 1] = "0"
GlobalAssign("TargetName", ReadMemoryOffset($tmpTargetPointer, 0, $configMem.Item("TargetName_DataType")))
EndIf
If $HP - Eval("_HP") > 0 Then $DMG = $HP - Eval("_HP")
$lastTargetHP = $THP
$SIT = Eval("_Sit")
$CURSED = Eval("_Curse")
$MP = Eval("_MP")
$MPCAP = Eval("_MPCAP")
$HPCAP = Eval("_HPCAP")
$DMGCAP = $HPCAP
$HP = Eval("_HP")
$CH = Eval("_Charge")
$SHP = Eval("_SHP")
$SHPCAP = Eval("_SHPCap")
$THP = Eval("_TargetHP")
$THPCAP = Eval("_TargetHPCap")
$targetState = Eval("_Target")
If $targetState = 1 Then
$RANGE = Round(getDistance(Eval("_tX"), Eval("_tY"), Eval("_pX"), Eval("_pY")), 1)
Else
$RANGE = 0
EndIf
If $lastTarget = 1 And $targetState = 0 And $botState And Not $gotoSafe Then
If $killWait Then
setStatus("Killed " & Eval("_TargetName"))
$kills += 1
$ignoreAntiKs = False
$allowLoot = True
$maxUsage.RemoveAll()
$antiStuck = True
;If $timers.Exists($freezeDelay) Then $timers.remove($freezeDelay)
EndIf
$DMG = 0
$killWait = False
$lastTarget = 0
updateGUI($etLabel, niceTime(TimerDiff($killTimer), True))
$kph = Ceiling(($kills * 1000 * 60 * 60) / TimerDiff($killTimer))
loadMem("PerKill")
$EXP = Eval("_Exp")
$EPH = Ceiling((($EXP - $firstExp) * 1000 * 60 * 60) / TimerDiff($killTimer))
updateGUI($ephLabel, $EPH)
$GOLD = Eval("_Gold")
$GPH = Ceiling((($GOLD - $firstGold) * 1000 * 60 * 60) / TimerDiff($killTimer))
updateGUI($goldLabel, money($GOLD - $firstGold))
updateGUI($gphLabel, money($GPH))
updateGUI($killsLabel, $kills)
updateGUI($kphLabel, $kph)
If $EXPCAP > 0 And $botState Then
If $Level < Eval("_Level") Then
setStatus("You gained a level!")
_initMemory()
EndIf
updateGUI($expProgress, Floor(($EXP/$EXPCAP)*100))
updateGUI($ttlLabel, niceTime((($EXPCAP - $EXP)/$EPH) * 60 * 60 * 1000, True))
EndIf
If $CURSED = 0 And IsDeclared("_Atk") And IsDeclared("_Def") Then
If $BreakArmor And $statusDef <> Eval("_Def") Then
$BreakArmor = False
$statusDef = Eval("_Def")
ElseIf $BreakWeapon And $statusAtk <> Eval("_Atk") Then
$BreakWeapon = False
$statusAtk = Eval("_Atk")
ElseIf $statusAtk > Eval("_Atk") Or $statusDef > Eval("_Def") Then
If Not breakGambits() Then
$safeCond = "1=1"
$exitBot = True
setStatus("Equipment broke")
Else
If $statusAtk > Eval("_Atk") Then
$BreakWeapon = True
$statusAtk = Eval("_Atk")
EndIf
If $statusDef > Eval("_Def") Then
$BreakArmor = True
$statusDef = Eval("_Def")
EndIf
EndIf
EndIf
EndIf
ElseIf $targetState = 1 Then
$lastTarget = 1
EndIf
;If $moving Then
; $M = 1
;Else
; $M = 0
;EndIf
$C = $CURSED
$T = $targetState
Sleep(100)
Dim $st = "Good"
If $CURSED = 1 Then
$st = "Cursed "
EndIf
If $debugMode Then
setStatus(debugText())
EndIf
updateGUI($rangeLabel, $RANGE)
updateGUI($statusLabel, $st)
updateGUI($chargeLabel, $CH)
updateGUI($hpProgress, Floor(($HP / $HPCAP) * 100))
updateGUI($mpProgress, Floor(($MP / $MPCAP) * 100))
EndIf
EndFunc
Func updateGUI($ctrl, $val)
If GUICtrlRead($ctrl) <> $val Then
GUICtrlSetData($ctrl, $val)
EndIf
EndFunc
Func breakGambits()
Dim $gambits = $config.Item("Gambits").Keys
For $g In $gambits
If StringInStr($config.Item("Gambits").Item($g), "$Break") > 0 Then Return True
Next
Return False
EndFunc
Dim $mapNegCoords = 4294967294
Func updateMapCoords()
$mapX = Eval("_mapX")
$mapY = Eval("_mapY")
If $mapX > $mapNegCoords - 800 Then $mapX += $mapNegCoords * -1
If $mapY > $mapNegCoords - 600 Then $mapY += $mapNegCoords * -1
EndFunc
Func mapToggle($open = 1)
While loadMem("map") <> $open
Send($mapShortcut)
Sleep(200)
WEnd
EndFunc
Func mapAlign()
If Not IsDeclared("_mapX") Then Return
Dim $x = loadMem("mapX"), $y = loadMem("mapY"), $mX, $mY
If $x > $mapNegCoords - 800 Then $x += $mapNegCoords * -1
If $y > $mapNegCoords - 600 Then $y += $mapNegCoords * -1
If getDistance($x, $y, $mapX, $mapY) > 1 Then
If $x > 0 Then
$mX = $x + 10
ElseIf $x < 0 Then
$mX = $x + 790
EndIf
If $y > 0 Then
$mY = $y + 10
ElseIf $y < 0 Then
$mY = $y + 550
EndIf
$t = _Atan2($mapY - $y, $mapX - $x)
$d = getDistance($x,$y,$mapX,$mapY)
$dx = Cos($t) * $d + $mX
$dy = Sin($t) * $d + $mY
MouseUp("left")
Sleep(50)
MouseMove($mX, $mY, 10)
MouseDown("left")
Sleep(50)
MouseMove($dx, $dy, 50)
MouseUp("left")
Sleep(50)
EndIf
EndFunc
Func processChatActions()
Dim $chats = chatLog()
For $i = UBound($chats) - 1 To 0
If StringInStr($lootMessage, $chats[$i]) > 0 Then
$allowLoot = False
setStatus("System no loot detected")
If $targetState = 0 Then clickMapPoint(False)
ElseIf StringInStr($backpackFull, $chats[$i]) > 0 Then
$allowLoot = False
setStatus("System backpack full detected")
$inventoryFull = True
If $targetState = 0 Then clickMapPoint(False)
Else
processChatGambits($chats[$i])
EndIf
Next
EndFunc
Func chatAction($g, $c = "")
If $g[3] == "SAFESIT" Then
If $oldSafeCond = "" Then
$oldSafeCond = $safeCond
$safeCond = "1=1"
$safeStatus = ", " & setStatus("Chat safesit action activated")
Else
$safeCond = $oldSafeCond
$oldSafeCond = ""
$safeStatus = ", " & setStatus("Chat safesit action expired")
EndIf
ElseIf $g[3] == "NOTIFY" And $c <> "" Then
sendMail($c, 1)
setStatus("Chat NOTIFY activated")
ElseIf $g[3] == "QUIT" And $c <> "" Then
$oldSafeCond = $safeCond
$safeCond = "1=1"
$exitBot = True
$safeStatus = ", " & setStatus("Chat quit action activated")
EndIf
EndFunc
Func processChatGambits($chat = "")
Dim $actions = $config.Item("ChatGambits").Keys, $gambit, $tmp, $aKey, $cond2 = False, $cond1 = False
For $a In $actions
$aKey = "chat_" & $a
$gambit = $config.Item("ChatGambits").Item($a)
$g = StringSplit($gambit[1], "-")
If $timers.Exists($aKey) And TimerDiff($timers.Item($aKey)) >= $gambit[4] Then
$timers.Remove($aKey)
If _ArraySearch($chatCommands, $gambit[3]) <> -1 Then chatAction($gambit)
EndIf
If $gambit[2] = "" Then
$cond2 = True
Else
$cond2 = StringInStr(StringMid($chat, StringInStr($chat, ":") + 1), $gambit[2]) > 0
EndIf
If $gambit[1] = "" Then
$cond1 = True
Else
$cond1 = StringInStr($chat, "[" & $g[1] & "]") = 1
If $cond1 And $g[0] = 2 Then $cond1 = StringInstr(StringMid($chat, StringInStr($chat, "]") + 1, StringInStr($chat, ":") - 1), $g[2])
EndIf
If $chat <> "" And $cond1 And $cond2 And Not $timers.Exists($aKey) Then
If StringRegExp($gambit[3], "[A-Za-z0-9_]{1,}") And $config.Item("Shortcut").Exists($gambit[3]) Then
Send($config.Item("Shortcut").Item($gambit[3]))
If $config.Item("ActionDelay").Exists($gambit[3]) Then
Sleep($config.Item("ActionDelay").Item($gambit[3]))
Else
Sleep(200)
EndIf
ElseIf _ArraySearch($chatCommands, $gambit[3]) = -1 Then
setStatus("ChatGambits " & $chat & " - " & $a)
If $g[0] > 0 And $g[1] = "Whisper" Then
Send("^r")
Else
Send("^s")
EndIf
Sleep(200)
Send($gambit[3], 1)
Sleep((Ubound(StringSplit($gambit[3], " ")) / $wpm) * 60 * 1000)
Send("^s")
Sleep(200)
Send("{ENTER}")
Else
chatAction($gambit, $chat)
EndIf
$timers.Add($aKey, TimerInit())
sysLog("Chat - " & $a & " - " & $chat)
Return
ElseIf StringInStr($chat, "[Say]") = 1 Or StringInStr($chat, "[Whisper]") = 1 Then
sysLog("Chat - " & $chat)
EndIf
Next
EndFunc
Func chatLog()
If $chatSys = 1 Then
Return chatLogRead()
Else
Return chatLogWrite()
EndIf
EndFunc
Func chatLogWrite()
Dim $off1 = Dec("4"), $off2 = Dec("22"), $chatPointer, $tmpLog, $chat, $pattern = "^[A\[ ]{1,}[A-Za-z0-9]{1,}.*", $tmp, $chatStr, $chatLogs[10], $newChats[1], $chatIndex = $lastChatIndex
If Not $configMem.Exists("Chat") Then Return
$chatPointer = $configMem.Item("Chat")
If $lastChatIndex > 10 Then
$startIndex = $lastChatIndex - 10
Else
$startIndex = 0
EndIf
For $i = $startIndex To 77
$chatPointer[4] = Hex(Dec("0") + ($off1 * $i))
$tmp = ""
$chatStr = ""
$chat = ReadMemoryOffset($chatPointer, 0, "char[50]")
If StringLeft($chat, 1) = "|" Then ContinueLoop
If StringRegExp($chat, $pattern) Then
$tmpChatPointer = $chatPointer
If StringLeft($chat,1) = " " And Ubound($chatLogs) > 1 Then
$chatStr = _ArrayPop($chatLogs) & $chat
Else
$chatStr = $chat
EndIf
Else
$tmpLog = $chatPointer
ReDim $tmpLog[7]
$tmpLog[6] = "0"
$tmpChatPointer = $tmpLog
$chat = ReadMemoryOffset($tmpLog, 0, "char[50]")
If StringLeft($chat, 1) = "|" Then ContinueLoop
If StringRegExp($chat, $pattern) Then
$tmpLog[6] = Hex(Dec($tmpLog[6]) + $off2)
$tmp = ReadMemoryOffset($tmpLog, 0, "char[50]")
If StringLeft($chat,1) = " " And Ubound($chatLogs) > 1 Then
$chatStr = _ArrayPop($chatLogs) & $chat
Else
$chatStr = $chat
EndIf
If StringRegExp($tmp, $pattern) And Not StringInStr($chatStr, $tmp) Then $chatStr &= $tmp
EndIf
EndIf
If $chatStr <> "" And Not StringInStr($chatStr, "You whisper to") And Not StringInStr($chatStr, "]" & Eval("_Name") & ":") Then
If Not IsArray($chatLogs) Then ReDim $chatLogs[10]
_ArrayPush($chatLogs, $chatStr)
$lastChatIndex = $i
WriteMemoryOffset("|" & StringRight($chat, StringLen($chat) - 1), $tmpChatPointer, 0, "char[" & StringLen($chat) & "]")
EndIf
Next
For $i = 0 To Ubound($chatLogs) - 1
$chat = _ArrayPop($chatLogs)
If "" == $chat Then ExitLoop
$newChats[UBound($newChats) - 1] = $chat
ReDim $newChats[Ubound($newChats) + 1]
Next
If UBound($newChats) > 1 Then
ReDim $newChats[UBound($newChats) - 1]
$lastChat = $newChats[0]
EndIf
Return $newChats
EndFunc
Func chatLogRead()
Dim $off1 = Dec("4"), $off2 = Dec("22"), $chatPointer, $tmpLog, $chat, $pattern = "^[A\[ ]{1,}[A-Za-z0-9]{1,}.*", $tmp, $chatStr, $chatLogs[10], $newChats[1], $chatIndex = $lastChatIndex, $lastTmp = ""
If Not $configMem.Exists("Chat") Then Return
$chatPointer = $configMem.Item("Chat")
If $lastChatIndex > 10 Then
$startIndex = $lastChatIndex - 10
Else
$startIndex = 0
EndIf
For $i = $startIndex To 77
$chatPointer[4] = Hex(Dec("0") + ($off1 * $i))
$tmp = ""
$chatStr = ""
$chat = ReadMemoryOffset($chatPointer, 0, "char[50]")
If StringRegExp($chat, $pattern) Then
If StringLeft($chat,1) = " " And Ubound($chatLogs) > 1 Then
$chatStr = _ArrayPop($chatLogs) & $chat
Else
$chatStr = $chat
EndIf
;_ArrayPush($chatLogs, $tmp & $chat)
Else
$tmpLog = $chatPointer
ReDim $tmpLog[7]
$tmpLog[6] = "0"
$chat = ReadMemoryOffset($tmpLog, 0, "char[50]")
If StringRegExp($chat, $pattern) Then
$tmpLog[6] = Hex(Dec($tmpLog[6]) + $off2)
$tmp = ReadMemoryOffset($tmpLog, 0, "char[50]")
If StringLeft($chat,1) = " " And Ubound($chatLogs) > 1 Then
$chatStr = _ArrayPop($chatLogs) & $chat
Else
$chatStr = $chat
EndIf
If StringRegExp($tmp, $pattern) And Not StringInStr($chatStr, $tmp) Then $chatStr &= $tmp
;_ArrayPush($chatLogs, $tmp & $chat)
EndIf
EndIf
If $chatStr <> "" And Not StringInStr($chatStr, "You whisper to") And Not StringInStr($chatStr, "]" & Eval("_Name") & ":") Then
If Not IsArray($chatLogs) Then ReDim $chatLogs[10]
If $lastTmp <> $chatStr Then _ArrayPush($chatLogs, $chatStr)
$lastChatIndex = $i
$lastTmp = $chatStr
EndIf
Next
If $lastChat = "" Then $lastChat = $chatLogs[UBound($chatLogs) - 1]
For $i = 0 To UBound($chatLogs) - 1
$chat = _ArrayPop($chatLogs)
If $lastChat == $chat Then ExitLoop
$newChats[UBound($newChats) - 1] = $chat
ReDim $newChats[Ubound($newChats) + 1]
Next
If UBound($newChats) > 1 Then ReDim $newChats[UBound($newChats) - 1]
If $newChats[0] <> "" Then $lastChat = $newChats[0]
Return $newChats
EndFunc
Func playerAlert()
If $zoneWaypoints[0][0] = 0 Then Return
Dim $nOff = Dec("4"), $listPointer = $configMem.Item("ListStart"), $player = "", $pattern = "^[A-Za-z0-9_\-]{1,}$", $tmpPointer
For $i = 1 To 14
$listPointer[2] = Hex($i * $nOff)
$player = ReadMemoryOffset($listPointer, 0, "char[50]")
If Not StringRegExp($player, $pattern) Then
$tmpPointer = $listPointer
ReDim $tmpPointer[UBound($tmpPointer) + 1]
$tmpPointer[UBound($tmpPointer) - 1] = "0"
$player = ReadMemoryOffset($tmpPointer, 0, "char[50]")
If Not StringRegExp($player, $pattern) Then ContinueLoop
EndIf
If $player <> "" And $player <> Eval("_Name") And (StringInStr($player, "GS") = 1 Or _ArraySearch($playerAlert, $player) <> -1) Then
If $oldSafeCond = "" And Not $timers.Exists("playeralert") Then
$oldSafeCond = $safeCond
$safeCond = "2=2"
$safeStatus = ", " & setStatus("Player alert! " & $player)
sysLog("Player alert - " & $player)
$timers.Add("playeralert", TimerInit())
Return
EndIf
EndIf
Next
EndFunc
Func checkList()
If Not IsArray($playerAlert) Or $zoneWaypoints[0][0] = 0 Then Return
Dim $nOff = Dec("a8"), $lOff = Dec("1F8"), $lStart = Dec("930"), $currentChar[2], $listPointer, $locPointer, $hasAlert = False
$listPointer = $configMem.Item("ListStart")
$locPointer = $listPointer
$locPointer[UBound($locPointer) - 1] = Hex(Dec($locPointer[UBound($locPointer) - 1]) + $lStart)
Do
$currentChar[0] = ReadMemoryOffset($listPointer, 0, "char[50]")
$currentChar[1] = ReadMemoryOffset($locPointer, 0, "char[50]")
;MsgBox(0,"ASD", loadMem("CurrentLoc") & "-" & $currentChar[0] & "-"& $currentChar[1])
If loadMem("CurrentLoc") == $currentChar[1] And ($playerAlert[0] == "all" Or _ArraySearch($playerAlert, $currentChar[0]) <> -1) Then
$hasAlert = True
If $oldSafeCond == "" Then
$oldSafeCond = $safeCond
$safeCond = "3=3"
$safeStatus = ", " & setStatus("Player alert! " & $currentChar[0])
EndIf
EndIf
$listPointer[UBound($locPointer) - 1] = Hex(Dec($listPointer[UBound($listPointer) - 1]) + $nOff)
$locPointer[UBound($locPointer) - 1] = Hex(Dec($locPointer[UBound($locPointer) - 1]) + $lOff)
Until $currentChar[1] == "Offline" Or $currentChar[1] == ""
If Not $hasAlert And $oldSafeCond = "3=3" Then
$safeCond = $oldSafeCond
$oldSafeCond = ""
$safeStatus = ", " & setStatus("Player alert expired")
EndIf
EndFunc
Func sit($sit = 1)
While loadMem("Sit") <> $sit
Send($sitShortcut)
Sleep(200)
WEnd
EndFunc
Func getDistance($x1, $y1, $x2, $y2)
return Sqrt((Abs($x1-$x2))^2 + (Abs($y1-$y2))^2)
EndFunc
Func arrivedBot()
Dim $x, $y, $i = - 1, $r = $radius
$coord = getPosition()
If Not IsArray($coord) Then Return False
If $gotoStore Then
$i = 1
ElseIf $gotoSafe Then
$i = 0
EndIf
If $i >= 0 Then
$x = $zoneCoords[$i][0]
$y = $zoneCoords[$i][1]
$m = $zoneWaypoints[$i][2]
Else
$x = $waypointCoord[$lastIndex][0]
$y = $waypointCoord[$lastIndex][1]
$m = $WayPoints[$lastIndex][2]
EndIf
;If $m = 0 Then $r = 3
If getDistance($x, $y, $coord[0], $coord[1]) <= $r Then
;setCurrentWaypoint()
Return True
Else
Return False
EndIf
EndFunc
Func clickMapPoint($next = True)
Dim $x, $y, $m
If Not $next Then
$WayPointIndex = $lastIndex
EndIf
If $WayPointCount = 0 Then
Return
EndIf
If $WayPointCount = $WayPointIndex Then
$WayPointIndex = 0
EndIf
If Not WinActive($processName) Then
WinActivate($processName)
Sleep(100)
EndIf
If $gotoStore Then
$x = $zoneWaypoints[1][0]
$y = $zoneWaypoints[1][1]
$m = $zoneWaypoints[1][2]
ElseIf $gotoSafe Then
$x = $zoneWaypoints[0][0]
$y = $zoneWaypoints[0][1]
$m = $zoneWaypoints[0][2]
Else
$lastIndex = $WayPointIndex
updateGUI($waypointLabel, ($WayPointIndex + 1) & "/" & $WayPointCount)
$x = $WayPoints[$WayPointIndex][0]
$y = $WayPoints[$WayPointIndex][1]
$m = $WayPoints[$WayPointIndex][2]
$WayPointIndex += 1
EndIf
mapToggle($m)
MouseUp("left")
Sleep(100)
If $m = 0 Then
;If $timers.Exists($freezeDelay) Then $timers.remove($freezeDelay)
moveMouse($x, $y)
MouseDown("left")
Sleep(100)
MouseUp("left")
Sleep(50)
writeDestination($x, $y)
Else
mapAlign()
MouseMove($x, $y, 0)
Sleep(100)
MouseDown("left")
Sleep(100)
MouseUp("left")
Sleep(50)
EndIf
EndFunc
Func writeDestination($x, $y)
writeMem("mX", $x)
writeMem("mY", $y)
EndFunc
Func moveMouse($x2, $y2)
Dim $x1 = Eval("_pX"), $y1 = Eval("_pY")
Dim $angle = (_ATan2($y2 - $y1, $x2 - $x1) / $PI) * 180, $currentAngle = Eval("_Direction"), $radianDeg = 57.2957795, $t, $dx, $dy, $direction = 0
Dim $centerX = $clientSize[0]/2, $centerY = $clientSize[1]/2, $dist = $cursorDistance, $x , $y, $rotateAngle = 0
If $currentAngle > 0 Then
$currentAngle = ($PI * 2) - $currentAngle
Else
$currentAngle = Abs($currentAngle)
EndIf
$currentAngle *= $radianDeg
$currentAngle = $currentAngle - 90
If $currentAngle < 0 Then $currentAngle += 360
$screenAngle = $angle + 180
$t = $screenAngle * $PI / 180
$dx = -Cos($t) * $dist
$dy = Sin($t) * $dist
If $currentAngle < 90 Then
$t = (Abs(90 - $currentAngle) * $PI / 180) * - 1
Else
$t = Abs($currentAngle - 90) * $PI / 180
EndIf
$x = ($dx * Cos($t)) - ($dy * Sin($t))
$y = ($dy * Cos($t)) + ($dx * Sin($t))
$x += $centerX
$y += $centerY
MouseMove($x, $y, 0)
$rotateAngle = $currentAngle - 180
If loadMem("Cursor") = 1 Then
$doAntiStuck = True
$t = $screenAngle * $PI / 180
$dx = -Cos($t) * ($dist * 2)
$dy = Sin($t) * ($dist * 2)
While loadMem("Cursor") = 1
If $rotateAngle < 0 Then $rotateAngle += 360
$rotateAngle += 10
If $rotateAngle < 90 Then
$t = (Abs(90 - $rotateAngle) * $PI / 180) * - 1
Else
$t = Abs($rotateAngle - 90) * $PI / 180
EndIf
$x = (($dx * Cos($t)) - ($dy * Sin($t))) + $centerX
$y = (($dy * Cos($t)) + ($dx * Sin($t))) + $centerY
MouseMove($x, $y, 0)
Sleep(10)
WEnd
EndIf
EndFunc
Func removeTarget()
; MouseUp("left")
; Sleep(100)
; MouseMove($antiStuckCoords[0][0], $antiStuckCoords[0][1], 0)
; Sleep(100)
; MouseClick("right",$antiStuckCoords[0][0], $antiStuckCoords[0][1], 2, 100)
; Sleep(100)
writeMem("Target", 0)
EndFunc
Func getWayPoint($which = "next")
Dim $nWP
If $which == "next" Then
$nWP = $WayPointIndex + 1
Else
$nWP = $lastIndex + 1
EndIf
If $WayPointCount = $nWP - 1 Then
$nWP = 1
EndIf
Return $nWP
EndFunc
Func getPosition() ;$inGame = False, $who = "player"
Dim $pos[2] ;, $position
;If $WayPoints[$lastIndex][2] = 0 Or $inGame And IsDeclared("_pX") Then
$pos[0] = loadMem("pX")
$pos[1] = loadMem("pY")
Return $pos
;Else
; $position = PixelSearch(0,0, $clientSize[0] - $miniMapWidth, $clientSize[1], $arrowHex, 5, 1)
;EndIf
;If IsArray($position) Then
; Return $position
;Else
; Return 0
;EndIf
EndFunc
Func checkDestRange()
Dim $pos, $destR
$pos = getPosition()
$destR = getDistance($pos[0], $pos[1], $WayPoints[$lastIndex][0],$WayPoints[$lastIndex][1])
If $destR > $destRange Then
clickMapPoint(False)
$destRange = $destR
EndIf
EndFunc
Func setCurrentWaypoint()
$coord = getPosition()
If $gotoStore Then
$zoneCoords[1][0] = $coord[0]
$zoneCoords[1][1] = $coord[1]
ElseIf $gotoSafe Then
$zoneCoords[0][0] = $coord[0]
$zoneCoords[0][1] = $coord[1]
Else
$waypointCoord[$lastIndex][0] = $coord[0]
$waypointCoord[$lastIndex][1] = $coord[1]
EndIf
EndFunc
Func moveBot()
Dim $useStuckDelay, $scanTop
$delayName = "moveDelay"
$delayMove = "MovingTime"
If ($targetState = 0 And Not $camperMode And $WayPointCount > 0) Or ($gotoSafe And Not $safeRecover) Then
If Not $timers.Exists($freezeDelay) Then
$lastCoords = getPosition()
;If $WayPoints[$lastIndex][2] = 0 And $stuckDelay = 200 Then $stuckDelay = 1000
If IsArray($lastCoords) Then
$timers.add($freezeDelay, TimerInit())
$scanTop = 0
EndIf
ElseIf TimerDiff($timers.Item($freezeDelay)) > 100 Then
$currentCoords = getPosition()
;MsgBox(0,"ASD", $currentCoords[0] &"x" & $currentCoords[1] &"="& $lastCoords[0]&"x"& $lastCoords[1])
If Floor(getDistance($currentCoords[0], $currentCoords[1], $lastCoords[0], $lastCoords[1])) <= 0 Then
If loadMem("map") = 0 And Not $doAntiStuck Then
clickMapPoint(False)
Else
Do
$findEscape = PixelSearch($clientSize[0] - 125, 54 + $scanTop, $clientSize[0] - 45, 114, $escapeHex, 5, Random(30,50))
$scanTop += 10
If $scanTop + 54 > 114 Then
$scanTop = 0
EndIf
Until IsArray($findEscape)
If IsArray($findEscape) Then
MouseUp("left")
Sleep(100)
MouseMove($findEscape[0], $findEscape[1], 0)
Sleep(100)
MouseDown("left")
Sleep(100)
MouseUp("left")
If Eval("_map") = 0 Then
Sleep($maplessAntiSleep)
Else
Sleep(700)
EndIf
clickMapPoint(False)
Sleep(500)
If $gotoSafe Then
setStatus("Stuck, rerouting to " & $dest)
Else
setStatus("Stuck, rerouting to waypoint " & getWayPoint("last"))
EndIf
EndIf
$antiStuck = True
$doAntiStuck = False
EndIf
EndIf
If $timers.Exists($freezeDelay) Then $timers.remove($freezeDelay)
EndIf
ElseIf $targetState = 1 And $timers.Exists($freezeDelay) Then
$timers.remove($freezeDelay)
EndIf
If $gotoSafe Then
If Not arrivedBot() Then
clickMapPoint()
EndIf
Return
ElseIf $WayPointCount == 0 Then
Return
EndIf
If $antiStuck Or ($targetState = 0 And $WayPoints[$lastIndex][2] = 1) Then ; And $moving == True
setStatus("Continue to waypoint " & getWayPoint("last"))
clickMapPoint(False)
$antiStuck = False
EndIf
If arrivedBot() And Not $gotoSafe Then ;$moving == true AND
Dim $status = "Arrived at waypoint " & getWayPoint("last")
If $WayPointCount > 1 Then
$status &= " moving to next waypoint " & getWayPoint()
EndIf
setStatus($status)
;setCurrentWaypoint()
;$moving = false
$lostTimes = 0
If $escapeFromSafe Then
$escapeFromSafe = False
$escapeFight = $lastEscapeFight
EndIf
clickMapPoint()
;setCurrentWaypoint(False)
;$moving = true
If $timers.Exists($delayMove) Then
$timers.remove($delayMove)
EndIf
$timers.add($delayMove, TimerInit())
ElseIf $timers.Exists("MovingTime") Then
If $lostDelay < TimerDiff($timers.Item($delayMove)) Then
$timers.remove($delayMove)
;$moving = false
$lostTimes += 1
If $lostTimes <= $waypointRetry Then
$WayPointIndex = $lastIndex
setStatus("Can't find waypoint, retry("& $lostTimes &") moving " & getWayPoint("last"))
Else
setStatus("Can't find waypoint, moving to next waypoint " & getWayPoint())
$lostTimes = 0
EndIf
clickMapPoint()
EndIf
EndIf
EndFunc
Func ClearWayPoints()
$lastIndex = 0
$WayPointIndex = 0
$WayPointCount = 0
$mapX = 0
$mapY = 0
ReDim $WayPoints[1][3]
ReDim $waypointCoord[1][2]
updateGUI($waypointLabel, $WayPointCount)
setStatus("Waypoints cleared")
EndFunc
Func ClearLastWayPoints()
If $WayPointCount <= 0 Then Return
$lastIndex = 0
$WayPointIndex = 0
$WayPointCount -= 1
ReDim $WayPoints[$WayPointCount][3]
ReDim $waypointCoord[$WayPointCount][2]
updateGUI($waypointLabel, $WayPointCount)
setStatus("Last waypoint deleted")
EndFunc
Func getWaypointPos()
Dim $coords[3]
If loadMem("map") = 0 Then
$coords[0] = Round(loadMem("pX"))
$coords[1] = Round(loadMem("pY"))
Else
$coords = MouseGetPos()
ReDim $coords[3]
EndIf
$coords[2] = loadMem("map")
Return $coords
EndFunc
Func InsertWayPoint($t = -1, $type = "")
If Not WinActive($processName) Then
WinActivate($processName)
EndIf
updateValues()
If $t <> -1 Then
$coords = getWaypointPos()
$zoneWaypoints[$t][0] = $coords[0]
$zoneWaypoints[$t][1] = $coords[1]
$zoneWaypoints[$t][2] = $coords[2]
If $coords[2] = 0 Then
$zoneCoords[$t][0] = $coords[0]
$zoneCoords[$t][1] = $coords[1]
Else
$zoneCoords[$t][0] = Number(loadMem("mapdX"))
$zoneCoords[$t][1] = Number(loadMem("mapdY"))
EndIf
updateZone()
setStatus($type & " waypoint added")
Else
If $WayPointCount = 0 Then
$WayPointIndex = 0
EndIf
$WayPointCount = $WayPointCount + 1
ReDim $WayPoints[$WayPointCount][3]
ReDim $waypointCoord[$WayPointCount][2]
$coords = getWaypointPos()
$WayPoints[$WayPointCount-1][0] = $coords[0]
$WayPoints[$WayPointCount-1][1] = $coords[1]
$WayPoints[$WayPointCount-1][2] = loadMem("map")
If $WayPoints[$WayPointCount-1][2] = 0 Then
$waypointCoord[$WayPointCount-1][0] = $coords[0]
$waypointCoord[$WayPointCount-1][1] = $coords[1]
Else
$waypointCoord[$WayPointCount-1][0] = Number(loadMem("mapdX"))
$waypointCoord[$WayPointCount-1][1] = Number(loadMem("mapdY"))
EndIf
updateGUI($waypointLabel, $WayPointCount)
setStatus("Waypoint " & $WayPointCount & " added")
EndIf
EndFunc
Func getTargetRange()
Dim $distance = getDistance(loadMem("pX"), loadMem("pY"), loadMem("tX"), loadMem("tY"))
$RANGE = Round($distance,1)
updateGUI($rangeLabel, $RANGE)
Return $distance
EndFunc
Func monsterDetect()
If $killWait And $timers.Exists("FightStuck") Then
If TimerDiff($timers.Item("FightStuck")) > $fightStuckDelay And ($THP = $THPCAP Or $THP = $lastTargetHP) Then
$killWait = False
$timers.remove("FightStuck")
$targetState = 0
removeTarget()
setStatus("Ignored " & Eval("_TargetName") & ", can't reach")
clickMapPoint()
EndIf
ElseIf $targetState = 1 And IsDeclared("_TargetName") Then
Sleep(100)
$targetDistance = getTargetRange()
If IsArray($attackMonsters) And _ArraySearch($attackMonsters, Eval("_TargetName")) = -1 And $targetDistance > $targetIgnoreDistance Then
$targetState = 0
setStatus("Ignored " & Eval("_TargetName") & ", not in attack list")
ElseIf IsArray($ignoreMonsters) And _ArraySearch($ignoreMonsters, Eval("_TargetName")) <> -1 And $targetDistance > $targetIgnoreDistance Then
$targetState = 0
setStatus("Ignored " & Eval("_TargetName") & ", ignored list")
EndIf
If $targetState = 1 Then
If $targetAttackDistance > 0 And $targetDistance > $targetAttackDistance Then
$targetState = 0
setStatus("Ignored " & Eval("_TargetName") & ", too far")
ElseIf $waypointRadius > 0 Then
Dim $tooFar = False
For $i = 0 To $WayPointCount - 1
If IsNumber($waypointCoord[$i][0]) And IsNumber($waypointCoord[$i][1]) And $targetDistance > $targetIgnoreDistance And $waypointRadius < getDistance($waypointCoord[$i][0], $waypointCoord[$i][1], Eval("_tX"), Eval("_tY")) Then
$tooFar = True
EndIf
Next
If $tooFar Then
$targetState = 0
setStatus("Ignored " & Eval("_TargetName") & ", outside waypoint radius")
EndIf
EndIf
EndIf
If IsDeclared("_TargetHP") And $targetState = 1 Then
If Eval("_TargetHP") < Eval("_TargetHPCap") And $targetDistance > $targetIgnoreDistance And Not $ignoreAntiKs Then
$targetState = 0
setStatus("Ignored " & Eval("_TargetName") & ", Anti-KS")
EndIf
EndIf
EndIf
If Not $killWait And $targetState = 1 Then
$killWait = True
$maxUsage.RemoveAll()
If $timers.Exists("FightStuck") Then
$timers.remove("FightStuck")
EndIf
$timers.add("FightStuck", TimerInit())
setStatus("Fighting " & Eval("_TargetName"))
EndIf
$T = $targetState
EndFunc
Func closeAndExit()
sendMail(logToFile(IniRead($settingsFile,"Settings","logcount", 5)))
Sleep(1000)