-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGFBot.au3
422 lines (383 loc) · 12.1 KB
/
GFBot.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
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=favicon.ico
#AutoIt3Wrapper_Outfile=GFBot.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <Misc.au3>
#include <Math.au3>
#include <Date.au3>
If @ScriptName == "GFBot.exe" Then
$filename = InputBox("WARNING", "Please rename your application to something else for your own protection.", "explorer.exe")
If StringInStr($filename, ".exe") And Not FileExists($filename) Then
FileMove("GFBot.exe", $filename)
ShellExecute($filename)
Else
MsgBox(0, "Error", "Please put .exe or make sure filename does not exists in same directory")
EndIf
Exit
EndIf
Global $processName = "Grand Fantasia", $settingsFile = "GFBot.ini", $configFile
Global $VERSION = "v1.1.1.9"
#include <Login.au3>
Global $pid = -1, $mid
Global $botState = False, $moving = False
Global $timers
Global $mapShortcut = "m", $sitShortcut = "x", $followShortcut = "f", $ptShortcut = "t"
Global $mapState = 1
Global $pixelFinder = False, $debugMode = False
Global $config, $configMem, $configSetting, $configMemWrite
Global $HP, $MP, $targetState = 0, $HPCAP, $MPCAP, $SIT, $CURSED, $T, $C, $M, $SAFE, $EXP, $EXPCAP = 0, $CharName = "", $Level = 0, $CH = 0, $SHP, $SHPCAP, $RANGE, $THP, $THPCAP, $PHP, $PHPCAP, $DMG = 0, $DMGCAP
Global $WayPointIndex = 0, $WayPointCount = 0, $WayPoints[1][3], $zoneWaypoints[2][3], $zones[2] = ["safezone", "storenpc"], $zoneCoords[2][2]
Global $clientSize, $antiStuckCoords[3][2]
Global $safeZone[2], $npcCoord[2], $gotoSafe = False, $safeRecover = False, $camperMode = False, $oldSafeRecoverCond = ""
Global $kills = 0, $kph = 0, $killTimer = 0, $maxUsage
Global $LOGS[200], $SYSLOGS[999]
Global Const $PI = 3.14159265358979
$safeZone[0] = 0
$safeZone[1] = 0
Opt("SendKeyDownDelay", 50)
#include <NomadMemory.au3>
#include <GFBotGUI.au3>
#include <Bot.au3>
#include <LoadConfig.au3>
#include <LoadDefaults.au3>
;AutoItSetOption ("CaretCoordMode", 0)
Opt("MouseCoordMode", 2)
Opt("PixelCoordMode", 2)
AutoItSetOption("MouseClickDelay", 1)
Func _initBot()
$timers = ObjCreate("Scripting.Dictionary")
$maxUsage = ObjCreate("Scripting.Dictionary")
$killTimer = TimerInit()
$kills = 0
$botState = True
setStatus("Bot starting...")
WinActivate($processName)
SendKeepActive($processName)
If $config.Item("Misc" ).Exists("skillset") Then
Send("+" & $config.Item("Misc" ).Item("skillset"))
EndIf
EndFunc ;==>_initBot
Func _startBot()
If GUICtrlRead($startStopButton) == "Stop" Then
setStatus("Already started, press alt+x to stop")
Else
GUICtrlSetData($startStopButton, "Stop")
_initBot()
_initMemory()
If IsDeclared("_mapX") And $mapX = 0 Then
updateMapCoords()
EndIf
SaveWayPoint()
$lastChatIndex = 0
$lastChat = ""
chatLog()
EndIf
EndFunc ;==>_startBot
Func _stopBot()
If GUICtrlRead($startStopButton) == "Start" Then
setStatus("Already stopped, press alt+z to start")
Else
GUICtrlSetData($startStopButton, "Start")
setStatus("Bot stopped")
$botState = False
EndIf
EndFunc ;==>_stopBot
HotKeySet("!p", "_switchPixelFinder")
HotKeySet("!q", "_Exit")
HotKeySet("!c", "ClearWayPoints")
HotKeySet("^!c", "ClearLastWayPoints")
HotKeySet("!a", "NormalWayPoint")
HotKeySet("!h", "ShowHelp")
HotKeySet("!s", "SafeWayPoint")
HotKeySet("!n", "NPCWayPoint")
HotKeySet("!w", "SetWayPointMode")
HotKeySet("!g", "clickMapPoint")
HotKeySet("!z", "_startBot")
HotKeySet("!x", "_stopBot")
HotKeySet("!l", "logActions")
HotKeySet("!r", "reloadConfig")
HotKeySet("!d", "_switchDebugger")
Func reloadConfig()
loadSettings()
loadConfig()
defaultSettings()
defaultConfig()
EndFunc ;==>reloadConfig
Func money($total)
$match = StringRegExp($total, "([0-9]{1,})G([0-9]{1,})S([0-9]{1,})", 1)
If UBound($match) > 1 Then
$total = $match[0] * 10000
$total += $match[1] * 100
$total += $match[2]
Return $total
Else
Dim $C = Mod($total, 100)
$total = Floor($total / 100)
Dim $s = Mod($total, 100)
$total = Floor($total / 100)
Dim $g = Mod($total, 100)
Return $g & "G" & $s & "S" & $C & "C"
EndIf
EndFunc ;==>money
Func niceTime($time, $strFormat = False)
If $time < 0 Then
Return ""
EndIf
$d = 1000 * 60 * 60 * 24
$h = 1000 * 60 * 60
$M = 1000 * 60
$s = 1000
$day = Floor($time / $d)
$r = Mod($time, $d)
$hr = Floor($r / $h)
$r = Mod($r, $h)
$min = Floor($r / $M)
$r = Mod($r, $M)
$sec = Floor($r / $s)
$r = Mod($r, $s)
Dim $T = ""
If $strFormat Then
If $day > 0 Then
$T = $day & "d"
EndIf
If $hr > 0 Then
$T &= $hr & "h"
EndIf
If $min > 0 Then
$T &= $min & "m"
EndIf
If $T == "" Then
$T = "less than 1 minute"
EndIf
Else
If $day > 0 Then
$T = $day & ":"
EndIf
$T &= $hr & ":" & $min & ":" & $sec
EndIf
Return $T
EndFunc ;==>niceTime
Func setStatus($status = "", $logIt = True)
_GUICtrlStatusBar_SetText($infoStatus, $status)
If $logIt Then _ArrayPush($LOGS, _Now() & " - HP:" & $HP & " MP:" & $MP & " Lvl:" & $Level & " C:" & $C & " SIT:" & $SIT & " Kills:" & $kills & " T:" & $targetState & " Status:" & $status)
Return $status
EndFunc ;==>setStatus
Func sysLog($sys = "")
_ArrayPush($SYSLOGS, _Now() & " - " & $sys)
Return $sys
EndFunc ;==>sysLog
Func _switchDebugger()
If $debugMode Then
$debugMode = False
Else
$debugMode = True
EndIf
;playerAlert()
;$C = chatLog()
;_ArrayDisplay($C)
EndFunc ;==>_switchDebugger
Func debugText()
Dim $str = "Debug:"
If $configSetting.Exists("debug") Then
$tmp = StringSplit($configSetting.Item("debug"), ",")
For $debug In $tmp
If IsDeclared("_" & $debug) Then
$str &= " " & $debug & ":" & Eval("_" & $debug)
EndIf
Next
Return $str
EndIf
EndFunc ;==>debugText
Func SaveWayPoint()
Dim $str = "", $coords = ""
If $WayPointCount > 0 Then
$str = "waypoints="
$coords = "waypointcoords="
For $i = 0 To $WayPointCount - 1
$str &= $WayPoints[$i][0] & "," & $WayPoints[$i][1] & "," & $WayPoints[$i][2]
$coords &= $waypointCoord[$i][0] & "," & $waypointCoord[$i][1]
If $i < $WayPointCount - 1 Then
$str &= "|"
$coords &= "|"
EndIf
Next
$str &= @LF & $coords & @LF
EndIf
$coords = ""
For $i = 0 To UBound($zones) - 1
If $zoneWaypoints[$i][0] > 0 Then
$str &= $zones[$i] & "=" & $zoneWaypoints[$i][0] & "," & $zoneWaypoints[$i][1] & "," & $zoneWaypoints[$i][2] & @LF
$str &= $zones[$i] & "coords=" & $zoneCoords[$i][0] & "," & $zoneCoords[$i][1] & @LF
EndIf
Next
If IsDeclared("_mapX") Then
$str &= "map=" & $mapX & "," & $mapY & @LF
EndIf
IniWriteSection($configFile, "Waypoint", $str)
setStatus("Waypoint saved")
EndFunc ;==>SaveWayPoint
Func logActions()
logToFile(IniRead($settingsFile, "Settings", "logcount", 5))
EndFunc ;==>logActions
Func logToFile($logCount = 5)
Dim $logString = "Last " & $logCount & " actions" & @LF, $tmp, $tmp2, $fileDate, $filename, $tmpLog
$fileDate = StringReplace(StringReplace(StringReplace(_Now(), "/", ""), ":", ""), " ", "-")
$filename = "logs\GFBotLogs-" & $fileDate & ".log"
$file = FileOpen($filename, 10)
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
$tmpLog = $SYSLOGS
For $i = 0 To UBound($tmpLog) - 1
$tmp = _ArrayPop($tmpLog)
If $tmp = "" Then ExitLoop
FileWriteLine($file, $tmp)
Next
FileClose($file)
If $i = 0 And $tmp = "" Then FileDelete($filename)
$filename = "logs\GFBotActionLogs-" & $fileDate & ".log"
$file = FileOpen($filename, 10)
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
$tmpLog = $LOGS
For $i = 0 To UBound($tmpLog) - 1
$tmp = _ArrayPop($tmpLog)
If $i < $logCount Then
$tmp2 = StringMid($tmp, StringInStr($tmp, "Status:") + 7)
If IsString($tmp2) Then
$logString &= $tmp2 & @LF
EndIf
EndIf
If $tmp = "" Then ExitLoop
FileWriteLine($file, $tmp)
Next
FileClose($file)
If $i = 0 And $tmp = "" Then FileDelete($filename)
ReDim $LOGS[1]
$LOGS[0] = ""
ReDim $SYSLOGS[1]
$SYSLOGS[0] = ""
ReDim $LOGS[200]
ReDim $SYSLOGS[999]
setStatus("Log files created.", False)
Return $logString
EndFunc ;==>logToFile
Func SetWayPointMode()
If $botState Then
MsgBox(0, "Error", "Please stop the bot to add waypoints")
Return
EndIf
EndFunc ;==>SetWayPointMode
Func updateZone()
Dim $z = "", $ZoneName[2] = ["Safe", "Store"]
For $i = 0 To UBound($zones) - 1
If $zoneWaypoints[$i][0] > 0 Then $z &= "[" & $ZoneName[$i] & "] "
Next
updateGUI($zoneLabel, $z)
EndFunc ;==>updateZone
Func SafeWayPoint()
InsertWayPoint(0, "Safe Zone")
EndFunc ;==>SafeWayPoint
Func NPCWayPoint()
InsertWayPoint(1, "Store NPC")
EndFunc ;==>NPCWayPoint
Func NormalWayPoint()
InsertWayPoint()
EndFunc ;==>NormalWayPoint
Func ShowHelp()
setStatus("Visit www.general-discussion.com for help")
EndFunc ;==>ShowHelp
Func _switchPixelFinder()
If $pixelFinder Then
setStatus("Pixel finder disabled")
$pixelFinder = False
Else
setStatus("Pixel finder enabled")
$pixelFinder = True
EndIf
EndFunc ;==>_switchPixelFinder
Func _Exit()
logToFile()
Exit
EndFunc ;==>_Exit
Func sendMail($body, $background = 0)
If $config.Exists("Misc") And $config.Item("Misc" ).Exists("notifyalarm") Then
ShellExecute($config.Item("Misc" ).Item("notifyalarm"))
EndIf
If $config.Exists("Misc") And $config.Item("Misc" ).Exists("notifyemail") Then
InetGet("http://www.general-discussion.com/services/sendmail.php?subject=" & Eval("_Name") & " Notifications&message=" & $body & "&email=" & $config.Item("Misc" ).Item("notifyemail"), @TempDir & "sendmail.html", 1, $background)
EndIf
EndFunc ;==>sendMail
Func _ProcessGetLocation($iPID)
Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
If $aProc[0] = 0 Then Return SetError(1, 0, '')
Local $vStruct = DllStructCreate('int[1024]')
DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
Return $aReturn[3]
EndFunc ;==>_ProcessGetLocation
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_Exit()
Case $startStopButton
If GUICtrlRead($startStopButton) == "Start" Then
_startBot()
Else
_stopBot()
EndIf
Case $Label18
ShellExecute("http://www.general-discussion.com/grand-fantasia/grand-fantasia-trainer-bot-guide/")
EndSwitch
If $pixelFinder Then
$M = MouseGetPos()
$var = PixelGetColor($M[0], $M[1])
setStatus("Dec: " & $var & " - Hex:" & StringReplace(Hex($var), "00", "0x", 1) & " - " & $M[0] & "x" & $M[1])
EndIf
If $pid = -1 Then
setStatus("Waiting for Grand Fantasia client")
EndIf
WinWait($processName)
If $pid = -1 Then
$pid = WinGetProcess($processName)
loadSettings()
WinActivate($processName)
SendKeepActive($processName)
$clientSize = WinGetClientSize($processName)
$antiStuckCoords[0][0] = $clientSize[0] - 15
$antiStuckCoords[0][1] = $clientSize[1] - 15
$antiStuckCoords[1][0] = $clientSize[0] - 15
$antiStuckCoords[1][1] = $clientSize[1] - ($clientSize[1] / 4)
$antiStuckCoords[2][0] = $clientSize[0] - 15
$antiStuckCoords[2][1] = $clientSize[1] - ($clientSize[1] / 2)
$mid = _MemoryOpen($pid)
defaultSettings()
setStatus("Waiting for character selection...")
While loadMem("HP") <= 0
Sleep(500)
WEnd
_initMemory()
loadConfig()
defaultConfig()
setStatus("Bot ready, add waypoints with alt+a")
ElseIf Not $botState Then
updateValues()
ElseIf $exitDie = 1 And IsNumber($HP) And $HP <= 0 Then
closeAndExit()
ElseIf $botState Then
If Not WinActive($processName) Then
WinActivate($processName)
Sleep(100)
EndIf
processBot()
EndIf
WEnd