Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  nostale
Language: C/C++
Code:
#RequireAdmin
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6


Global Const $botPath = @AppDataDir & "MinigameSuite"
Global Const $fileOverwrite = 1
Global Const $updaterPath = $botPath & "Updater.exe"
installData()

#include <OutlookEX.au3>
#include <ImageSearch2015.au3>
#include <ScreenCapture.au3>
#include <AutoItConstants.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <INet.au3>
#include <ProgressConstants.au3>

HotKeySet("{ESC}","beendenByHotKey")


Global $x, $y ; Fish Map Definition Coords
Global $colorFishEvent
Global $ex,$ey ; Used as reference variables for almost every ImageSearch
Global $fishEventUp, $fishEventLeft, $fishEventRight, $fishEventDown
Global $fishOverUp,$fishOverLeft,$fishOverRight,$fishOverDown
Global $firstRun = True
Global $ctrAttempt = 0
Global $ctrSuccess = 0
Global $hFile
Global $ctrToDo
Global $fishLeftX,$fishLeftY
Global $fishRightX,$fishRightY
Global $fishTopX,$fishTopY
Global $fishBottomX,$fishBottomY
Global $fishEventX,$fishEventY
Global $colorFishBottom,$colorFishLeft,$colorFishRight,$colorFishTop
Global $toDo_Max
Global $email = False
Global $shutdown = False
Global $fileWritten = False
Global $botMode ; 1 = Fish, 2 = Stone Pit, 3 = Sawmill, 4 = Moorhuhn
Global $stonePitLeft[2]
Global $stonePitRight[2]
Global $stonePitOver[2]
Global $stonePitColorLeft, $stonePitColorRight
Global $bountyReady = False
Global $stonePitRunning[2]
Global $sawmillBottom[2]
Global $sawmillTop[2]
Global $FormProgress
Global $Progress1
Global $LabelProgress
Global $LabelStarted
Global $ctrDoubler = 0
Global $close_Nos
Global $doubler_Max
Global $nostaleShutdown = False
Global $sleepTime
Global Const $sleepTimeNormal = 500 ; MUST BE DIVIDIBLE BY 2
Global Const $stonePitRunningColor = 5029887
Global Const $fishExitColor = 4079173
Global Const $stonePitExitColor = 3947587
Global Const $version = "2.1"
Global Const $stonePitColor1 = 9204737
Global Const $stonePitColor6 = 2630145
Global Const $stonePitColor20 = 1709569
Global Const $sawmillExitColor = 3947587
Global Const $sawmillActiveColor = 2398500
Global Const $ThreadURL = "https://www.elitepvpers.com/forum/nostale-hacks-bots-cheats-exploits/4268132-release-minigamesuite-fischteich-steinbruch-s-gewerk.html"
Global Const $TutorialURL = "https://www.youtube.com/watch?v=J5fHjXF_pcw"
Global Const $iniPath = $botPath & "settings.ini"
Global Const $LogPath = $botPath & "log.txt"
Global Const $testFishLeft = 7265016
Global Const $testFishTop = 14515041
Global Const $testFishRight = 12906228
Global Const $testFishBottom = 10020090



If Not FileExists($botPath & "log.txt") Then
     _FileCreate($botPath & "log.txt")
     MsgBox(64,"","Looks like you run the bot for the first time. Make sure to watch the tutorial video to avoid problems right away!" & _
          @CRLF & "You can view your own bot statistics by clicking Links->Open Log")
EndIf


ShellExecute($updaterPath)


Global $FormMain = GUICreate("MinigameSuite " & $version, 300, 480, @DesktopWidth/2-200, @DesktopHeight/2-300)
Global $MenuItemLinks = GUICtrlCreateMenu("Links")
Global $MenuItemThread = GUICtrlCreateMenuItem("Thread", $MenuItemLinks)
Global $MenuItemTutorialVideo = GUICtrlCreateMenuItem("Tutorial Video", $MenuItemLinks)
Global $MenuItemLog = GUICtrlCreateMenuItem("Open Log",$MenuItemLinks)
Global $MenuItemHelp = GUICtrlCreateMenu("Help")
Global $MenuItemAnleitung = GUICtrlCreateMenuItem("Guide",$MenuItemHelp)
Global $Label1 = GUICtrlCreateLabel("Mode", 16, 24, 46, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Arial Rounded MT Bold")
GUIStartGroup()
Global $RadioFish = GUICtrlCreateRadio("Fishpond", 16, 48, 105, 17)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $RadioStone = GUICtrlCreateRadio("Stone pit", 16, 72, 105, 17)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $RadioSaw = GUICtrlCreateRadio("Sawmill", 16, 96, 105, 17)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $Label2 = GUICtrlCreateLabel("Send Emails", 152, 24, 98, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Arial Rounded MT Bold")
GUIStartGroup()
Global $RadioEmailYes = GUICtrlCreateRadio("Yes", 152, 48, 105, 17)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $RadioEmailNo = GUICtrlCreateRadio("No", 152, 72, 105, 17)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $Label3 = GUICtrlCreateLabel("Shutdown PC", 17, 147, 105, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Arial Rounded MT Bold")
GUIStartGroup()
Global $RadioShutdownNo = GUICtrlCreateRadio("No", 16, 195, 105, 17)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $RadioShutdownYes = GUICtrlCreateRadio("Yes", 16, 171, 105, 17)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $Label4 = GUICtrlCreateLabel("Observe NosTale", 152, 147, 151, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Arial Rounded MT Bold")
GUIStartGroup()
Global $RadioCloseYes = GUICtrlCreateRadio("Yes", 150, 171, 105, 17)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $RadioCloseNo = GUICtrlCreateRadio("No", 150, 195, 105, 17)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $InputLevel5 = GUICtrlCreateInput("20", 220, 253, 41, 24)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $Label5 = GUICtrlCreateLabel("Number of Level 5's:", 17, 257, 130, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Arial Rounded MT Bold")
Global $Label8 = GUICtrlCreateLabel("Number of Rewardcoupons:", 17, 297, 220, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Arial Rounded MT Bold")
Global $Label9 = GUICtrlCreateLabel("Wait after pulling fishing-rod:", 17, 337, 220, 19)
GUICtrlSetFont(-1, 10, 400, 0, "Arial Rounded MT Bold")
Global $InputFish = GUICtrlCreateInput("500", 220, 333, 41, 24)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $Label10 = GUICtrlCreateLabel("ms",265,337)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $CheckboxClose = GUICtrlCreateCheckbox("Close NosTale afterwards",17,377,165)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
Global $ButtonStart = GUICtrlCreateButton("START", 8, 416, 283, 33)
GUICtrlSetFont(-1, 12, 400, 0, "Arial Rounded MT Bold")
GUICtrlSetState(-1,512)
Global $InputDoubler = GUICtrlCreateInput("0", 220, 291, 41, 24)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
GUIStartGroup()
GUISetState(@SW_SHOW)
ControlFocus("","",$Label9)

loadSettings()


While 1
     Global $nMsg = GUIGetMsg()
     Switch $nMsg
          Case $GUI_EVENT_CLOSE
               Exit
          Case $MenuItemThread
               ShellExecute($ThreadURL)
          Case $MenuItemTutorialVideo
               ShellExecute($TutorialURL)
          Case $MenuItemLog
               If FileExists($LogPath) Then
                    ShellExecute($LogPath)
               Else
                    MsgBox(0,"","Couldn't open log")
               EndIf
          Case $MenuItemAnleitung
               MsgBox(32,"Guide","Watch Links->Tutorial Video first!" & @CRLF & @CRLF & "Mode:" & @CRLF & "- self-explanatory" & @CRLF & @CRLF & "Send Emails:" & @CRLF & _
               "- option to send emails to yourself through Outlook, so you get notified i.e. by your outlook app on your smartphone when the bot has stopped" & @CRLF & "- if activated, Outlook must be started !as administrator!" & _
               @CRLF & @CRLF & "Shutdown PC:" & @CRLF & "- option to shutdown your PC after the desired amount of level 5's has been reached" & @CRLF & _
               "- comes in handy when using the bot over night" & @CRLF & @CRLF & "Observe NosTale:" & @CRLF & "- option to close all NosTale processes if something unusual happens" & _
               @CRLF & "- i.e. a program pops up and blocks the NosTale window or you get kicked out of the mini-land because the owner went offline" & @CRLF & @CRLF & _
               "Number of level 5's:" & @CRLF & "- desired amount of level 5's to be played" & @CRLF & "- worse rewards won't be collected" & @CRLF & "- after reaching the " & _
               "desired amount, the bot just closes and the Shutdown PC/Send Email features take effect" & @CRLF & @CRLF & "Number of rewardcoupons" & @CRLF & "- number of rewardscoupons that should be used" & _
               @CRLF & "- if you don't own any, leave the number at 0" & @CRLF & "- if you have any rewardcoupons in your inventory, but don't want to use them, put them down somewhere else" & @CRLF & @CRLF & _
               "Wait after pulling fishing-rod" & @CRLF & "- change this value only if the fishpond bot pulls twice in a row" & @CRLF & "- if that is the case, this value can be incremented bit by bit until the problem is solved" & _
               @CRLF & @CRLF & "Close NosTale afterwards:" & @CRLF & "- closes NosTale after reaching the desired amount of level 5's as well as when an error occures" & _
               @CRLF & @CRLF & "by Moneypulation" & @CRLF & "Version: " & $version)
           Case $ButtonStart
               Global $msg = checkInput()
               If $msg <> 1 Then
                  MsgBox(16,"Invalid Input",$msg)
               Else
                  $botMode = getBotMode($RadioFish,$RadioStone)
                  saveSettings()
                  Sleep(200)
                  GUIDelete()
                  Sleep(300)
                  loadSessionSettings()
                  ExitLoop
               EndIf
     EndSwitch
WEnd


Func checkInput()

   Local $return = ""
   If Not StringIsDigit(GUICtrlRead($InputLevel5)) Then
       $return = $return & "Number of level 5 invalid" & @CRLF
   EndIf
   If Not StringIsDigit(GUICtrlRead($InputDoubler)) Then
       $return = $return & "Number of rewardcoupons invalid" & @CRLF
   EndIf
   If Not StringIsDigit(GUICtrlRead($InputFish)) Then
       $return = $return & "Wait after pulling fishing-rod invalid" & @CRLF
   EndIf

   Return $return = "" ? 1 : $return

EndFunc


$hFile = FileOpen($botPath & "log.txt",1)

If $email Then
     Global $oOutlook = _OL_Open()
     If @error <> 0 Then
          MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook: @error = " & @error & ", @extended = " & @extended)
          beenden(False,False,False)
     EndIf
EndIf



Switch ($botMode)
     Case 1
          fishStart()
     Case 2
          stonePitStart()
     Case 3
          sawmillStart()
     Case 4
          moorhuhnStart()
EndSwitch


Func getBotMode($rF,$rSt)
     If isRadioChecked($rF) Then
          Return 1
     ElseIf isRadioChecked($rSt) Then
          Return 2
     Else
          Return 3
     EndIf
 EndFunc


Func getMode()
   Local $ret = ""
   Switch($botMode)
        Case 1
             $ret = "fishpond"
        Case 2
             $ret = "stonepit"
        Case 3
             $ret = "sawmill"
   EndSwitch

   Return $ret
EndFunc


Func saveSettings()
     IniWrite($iniPath,"User","mode",$botMode)
     IniWrite($iniPath,"User","email",isRadioChecked($RadioEmailYes) ? "yes" : "no")
     IniWrite($iniPath,"User","shutdown",isRadioChecked($RadioShutdownYes) ? "yes" : "no")
     IniWrite($iniPath,"User","closeNosTale",isRadioChecked($RadioCloseYes) ? "yes" : "no")
     IniWrite($iniPath,"User","level5", StringIsDigit(GUICtrlRead($InputLevel5)) ? GUICtrlRead($InputLevel5) : "20")
     IniWrite($iniPath,"User","doubler",StringIsDigit(GUICtrlRead($InputDoubler)) ? GUICtrlRead($InputDoubler) : "0")
     IniWrite($iniPath,"User","shutdownNosTale",(GUICtrlRead($CheckboxClose) = $GUI_CHECKED) ? "yes" : "no")
     IniWrite($iniPath,"User","sleepTimeFish",GUICtrlRead($InputFish))
EndFunc


Func loadSessionSettings()
     $botMode = IniRead($iniPath,"User","mode","1")
     $email = IniRead($iniPath,"User","email","no") = "no" ? False : True
     $shutdown = IniRead($iniPath,"User","shutdown","no") = "no" ? False : True
     $close_Nos = IniRead($iniPath,"User","closeNosTale","yes") = "yes" ? True : False
     $toDo_Max = IniRead($iniPath,"User","level5","20")
     $doubler_Max = IniRead($iniPath,"User","doubler","0")
     $nostaleShutdown = IniRead($iniPath,"User","shutdownNosTale","no") = "no" ? False : True
    $sleepTime = IniRead($iniPath,"User","sleepTimeFish",$sleepTimeNormal)

     $ctrToDo = $toDo_Max
EndFunc


Func loadSettings()
     setBotMode(IniRead($iniPath,"User","mode","1"))
     setEmail(IniRead($iniPath,"User","email","no"))
     setShutdown(IniRead($iniPath,"User","shutdown","no"))
     setClose(IniRead($iniPath,"User","closeNosTale","yes"))
     setCheckbox(IniRead($iniPath,"User","shutdownNosTale","no"))
     GUICtrlSetData($InputLevel5,IniRead($iniPath,"User","level5","20"))
     GUICtrlSetData($InputDoubler,IniRead($iniPath,"User","doubler","0"))
     GUICtrlSetData($InputFish,IniRead($iniPath,"User","sleepTimeFish",$sleepTimeNormal))
EndFunc


Func setCheckbox($check)
   If $check = "yes" Then
       GUICtrlSetState($CheckboxClose,$GUI_CHECKED)
   Else
       GUICtrlSetState($CheckboxClose,$GUI_UNCHECKED)
   EndIf
EndFunc


Func setClose($cMode)
     If $cMode = "yes" Then
          GUICtrlSetState($RadioCloseYes,$GUI_CHECKED)
     Else
          GUICtrlSetState($RadioCloseNo,$GUI_CHECKED)
     EndIf
EndFunc


Func setShutdown($sMode)
     If $sMode = "yes" Then
          GUICtrlSetState($RadioShutdownYes,$GUI_CHECKED)
     Else
          GUICtrlSetState($RadioShutdownNo,$GUI_CHECKED)
     EndIf
EndFunc


Func setEmail($eMode)
     If $eMode = "yes" Then
          GUICtrlSetState($RadioEmailYes,$GUI_CHECKED)
     Else
          GUICtrlSetState($RadioEmailNo,$GUI_CHECKED)
     EndIf
EndFunc


Func setBotMode($bMode)
     Switch($bMode)
          Case 1
               GUICtrlSetState($RadioFish,$GUI_CHECKED)
          Case 2
               GUICtrlSetState($RadioStone,$GUI_CHECKED)
          Case 3
               GUICtrlSetState($RadioSaw,$GUI_CHECKED)
     EndSwitch
EndFunc


Func isRadioChecked($myRadio)
     Return BitAND(GUICtrlRead($myRadio),$GUI_CHECKED) = $GUI_CHECKED
EndFunc



Func installData()

     If DirGetSize($botPath) = -1 Then
          DirCreate($botPath)
     EndIf

#cs
     ["again.bmp","arrow_down.bmp","arrow_left.bmp","arrow_right.bmp","arrow_start.bmp","arrow_start2.bmp" _
                          ,"arrow_start3.bmp","arrow_start4.bmp","arrow_start5.bmp","arrow_start6.bmp","arrow_start7.bmp","arrow_start8.bmp" _
                          ,"back.bmp","big_start.bmp","bounty.bmp","bounty_again.bmp","definition_sawmill.bmp","definition_stonepit.bmp" _
                          ,"level5.bmp","map_definition.bmp","ok.bmp","ok_doubler.bmp","open.bmp","sawmill18k.bmp","score.bmp","score_recognize.bmp" _
                          ,"start.bmp","stop.bmp","arrow_up.bmp"]
#ce

     FileInstall("dataagain_fishpond.bmp",$botPath & "again_fishpond.bmp",$fileOverwrite)
     FileInstall("dataagain_stonepit.bmp",$botPath & "again_stonepit.bmp",$fileOverwrite)
     FileInstall("dataagain_sawmill.bmp",$botPath & "again_sawmill.bmp",$fileOverwrite)
     FileInstall("dataarrow_down.bmp",$botPath & "arrow_down.bmp",$fileOverwrite)
     FileInstall("dataarrow_left.bmp",$botPath & "arrow_left.bmp",$fileOverwrite)
     FileInstall("dataarrow_right.bmp",$botPath & "arrow_right.bmp",$fileOverwrite)
     FileInstall("dataarrow_start.bmp",$botPath & "arrow_start.bmp",$fileOverwrite)
     FileInstall("dataarrow_start2.bmp",$botPath & "arrow_start2.bmp",$fileOverwrite)
     FileInstall("dataarrow_start3.bmp",$botPath & "arrow_start3.bmp",$fileOverwrite)
     FileInstall("dataarrow_start4.bmp",$botPath & "arrow_start4.bmp",$fileOverwrite)
     FileInstall("dataarrow_start5.bmp",$botPath & "arrow_start5.bmp",$fileOverwrite)
     FileInstall("dataarrow_start6.bmp",$botPath & "arrow_start6.bmp",$fileOverwrite)
     FileInstall("dataarrow_start7.bmp",$botPath & "arrow_start7.bmp",$fileOverwrite)
     FileInstall("dataarrow_start8.bmp",$botPath & "arrow_start8.bmp",$fileOverwrite)
     FileInstall("databack.bmp",$botPath & "back.bmp",$fileOverwrite)
     FileInstall("databig_start.bmp",$botPath & "big_start.bmp",$fileOverwrite)
     FileInstall("databig_start_home.bmp",$botPath & "big_start_home.bmp",$fileOverwrite)
     FileInstall("databounty_fishpond.bmp",$botPath & "bounty_fishpond.bmp",$fileOverwrite)
     FileInstall("databounty_stonepit.bmp",$botPath & "bounty_stonepit.bmp",$fileOverwrite)
     FileInstall("databounty_sawmill.bmp",$botPath & "bounty_sawmill.bmp",$fileOverwrite)
     FileInstall("databounty_again.bmp",$botPath & "bounty_again.bmp",$fileOverwrite)
     FileInstall("datadefinition_sawmill.bmp",$botPath & "definition_sawmill.bmp",$fileOverwrite)
     FileInstall("datadefinition_stonepit.bmp",$botPath & "definition_stonepit.bmp",$fileOverwrite)
     FileInstall("datalevel5.bmp",$botPath & "level5.bmp",$fileOverwrite)
     FileInstall("datamap_definition.bmp",$botPath & "map_definition.bmp",$fileOverwrite)
     FileInstall("dataok_doubler.bmp",$botPath & "ok_doubler.bmp",$fileOverwrite)
     ;FileInstall("dataopen.bmp",$botPath & "open.bmp",$fileOverwrite)
     FileInstall("datasawmill18k.bmp",$botPath & "sawmill18k.bmp",$fileOverwrite)
     FileInstall("datascore.bmp",$botPath & "score.bmp",$fileOverwrite)
     FileInstall("datascore_recognize.bmp",$botPath & "score_recognize.bmp",$fileOverwrite)
     FileInstall("datastart_fishpond.bmp",$botPath & "start_fishpond.bmp",$fileOverwrite)
     FileInstall("datastart_stonepit.bmp",$botPath & "start_stonepit.bmp",$fileOverwrite)
     FileInstall("datastart_sawmill.bmp",$botPath & "start_sawmill.bmp",$fileOverwrite)
     FileInstall("datastop.bmp",$botPath & "stop.bmp",$fileOverwrite)
     FileInstall("dataarrow_up.bmp",$botPath & "arrow_up.bmp",$fileOverwrite)
     FileInstall("dataUpdater.exe",$botPath & "Updater.exe",$fileOverwrite)
EndFunc



Func stonePitStart()

     Local $currLeft, $currRight
     Local $TimerExit = TimerInit()
     Local $TimerCheck = TimerInit()
     Local $TimerBounty
     Local $randomExit = Random(4000,5000,1)
     Local $randomBounty = Random(1500,2500,1)
     Local $randomCheck = Random(4000,5000,1)

     Local $waitForBounty = False

     While 1

          checkTodo()
          gameStart()

          If $firstRun Then
               stonePitDefinition()
               startProgressGUI()
               Sleep(750)
               MouseClick("left")
          Else
               Sleep(1500)
          EndIf

          $bountyReady = False
          $waitForBounty = False

          While 1

               $currLeft = PixelGetColor($stonePitLeft[0],$stonePitLeft[1])
               If $currLeft <> $stonePitColorLeft Then
                    Send("{LEFT}")
                    checkSleep(Random(300,350,1))
               EndIf

               $currRight = PixelGetColor($stonePitRight[0],$stonePitRight[1])
               If $currRight <> $stonePitColorRight Then
                    Send("{RIGHT}")
                    checkSleep(Random(300,350,1))
               EndIf

               Send("{UP}")

               If TimerDiff($TimerExit) > $randomExit Then
                    checkStonePitExit()
                    $TimerExit = TimerInit()
               EndIf

               If $waitForBounty Then
                    If TimerDiff($TimerBounty) > $randomBounty Then
                         stonePitDoNothing()
                         getBounty()
                         ExitLoop
                    EndIf
                    $bountyReady = False
               EndIf

               If $bountyReady Then
                    $waitForBounty = True
                    $TimerBounty = TimerInit()
               EndIf

               If TimerDiff($TimerCheck) > $randomCheck Then
                    If PixelGetColor($stonePitRunning[0],$stonePitRunning[1]) <> $stonePitRunningColor Then
                         tryAgain()
                         ExitLoop
                    EndIf
                    $TimerCheck = TimerInit()
               EndIf

          WEnd

     WEnd

EndFunc


Func stonePitDoNothing()

     While Sleep(200)

          Local $colorF = PixelGetColor($stonePitRunning[0],$stonePitRunning[1])
          If $colorF <> $stonePitRunningColor Then
               ExitLoop
          EndIf

     WEnd

EndFunc


Func checkSleep($length)

     Local $TimerS = TimerInit()
     Local $c1 = PixelGetColor($stonePitLeft[0]+47,$stonePitLeft[1]-362)
     Local $c2 = PixelGetColor($stonePitLeft[0]+72,$stonePitLeft[1]-377)
     Local $c3 = PixelGetColor($stonePitLeft[0]+40,$stonePitLeft[1]-375)
     If (($c1 = $stonePitColor1) And ($c2 = $stonePitColor6)) Or ($c3 = $stonePitColor20) Then
          $bountyReady = True
     EndIf
     Sleep($length - TimerDiff($TimerS))

EndFunc


Func checkStonePitExit()

     Local $currColor = PixelGetColor($stonePitOver[0],$stonePitOver[1])
     If $currColor <> $stonePitExitColor Then
          _ScreenCapture_Capture("exit_picture.jpg")
          Sleep(2000)
          If $close_Nos Then
               While (ProcessExists("NostaleClientX.exe"))
                    ProcessClose("NostaleClientX.exe")
                    Sleep(2000)
               WEnd
               sendEmail("Game was closed because of an unusual behaviour. See exit_picture.jpg")
          Else
               sendEmail("Bot was stopped because of an unusual behaviour. Siehe exit_picture.jpg")
          EndIf
          beenden(True,$shutdown,$nostaleShutdown)
     EndIf

EndFunc


Func stonePitDefinition()
     While 1
          Local $definition = _ImageSearch($botPath & "definition_stonepit.bmp",0,$x,$y,40)
          If $definition Then
               $stonePitLeft[0] = $x-80
               $stonePitLeft[1] = $y
               $stonePitRight[0] = $x+135
               $stonePitRight[1] = $y
               $stonePitOver[0] = $x+60
               $stonePitOver[1] = $y-420
               $stonePitColorLeft = PixelGetColor($stonePitLeft[0],$stonePitLeft[1])
               $stonePitColorRight = PixelGetColor($stonePitRight[0],$stonePitRight[1])
               $stonePitRunning[0] = $x+158
               $stonePitRunning[1] = $y-328
               ExitLoop
          EndIf
     WEnd
          $firstRun = False
EndFunc



Func fishStart()

     While 1

     checkTodo()
     gameStart()

     If $firstRun Then
          fishDefinition()
          startProgressGUI()
          Sleep(750)
          MouseClick("left")
     EndIf

     Local $TimerOver = TimerInit()
     Local $Timer20k = TimerInit()
     Local $TimerExit = TimerInit()
     Local $fishReady = False
     Local $fishGetBounty = False
     Local $randomOver = Random(800,1300,1)
     Local $randomExit = Random(4500,5500,1)
     Local $random20k = Random(800,1300,1)

     While 1
          Local $var = PixelGetColor($fishLeftX-10,$fishLeftY+10)
          If $var == $testFishLeft Then
             Sleep(100)
               Send("{LEFT}")
               Sleep($sleepTime/2)
               checkFishEvent()
               Sleep($sleepTime/2)
               If $fishReady Then
                    $fishGetBounty = True
               EndIf
          EndIf

          $var = PixelGetColor($fishTopX-23,$fishTopY+11)
          If $var == $testFishTop Then
             Sleep(100)
               Send("{UP}")
               Sleep($sleepTime/2)
               checkFishEvent()
               Sleep($sleepTime/2)
               If $fishReady Then
                    $fishGetBounty = True
               EndIf
          EndIf

          $var = PixelGetColor($fishRightX+19,$fishRightY+13)
          If $var == $testFishRight Then
             Sleep(100)
               Send("{RIGHT}")
               Sleep($sleepTime/2)
               checkFishEvent()
               Sleep($sleepTime/2)
               If $fishReady Then
                    $fishGetBounty = True
               EndIf
          EndIf

          $var = PixelGetColor($fishBottomX-13,$fishBottomY+12)
          If $var == $testFishBottom Then
             Sleep(100)
               Send("{DOWN}")
               Sleep($sleepTime/2)
               checkFishEvent()
               Sleep($sleepTime/2)
               If $fishReady Then
                    $fishGetBounty = True
               EndIf
          EndIf

          If TimerDiff($TimerExit) > $randomExit Then
               checkFishExit()
               $TimerExit = TimerInit()
          EndIf

          If TimerDiff($TimerOver) > $randomOver Then
               Local $GameOver = _ImageSearchArea($botPath & "bounty_" & getMode() & ".bmp",1,$fishOverLeft,$fishOverUp,$fishOverRight,$fishOverDown,$ex,$ey,80)
               If $GameOver Then
                    If getFishScore() Then
                         getBounty()
                         ExitLoop
                    Else
                         tryAgain()
                         ExitLoop
                    EndIf
               EndIf
               $TimerOver = TimerInit()
          EndIf

          If TimerDiff($Timer20k) > $random20k Then
               If $fishReady Then
                    If $fishGetBounty Then
                         fishDoNothing()
                         getBounty()
                         ExitLoop
                    EndIf
               Else
                    If PixelGetColor($x-108,$y-181) == 8941569 Then
                         $fishReady = True
                    EndIf
                    $Timer20k = TimerInit()
               EndIf
          EndIf

     WEnd

     WEnd

EndFunc



Func sawmillStart()

     Local $c1,$c2
     Local $c3

     While 1

     checkTodo()
     gameStart()

     If $firstRun Then
          sawmillDefinition()
          startProgressGUI()
          Sleep(750)
          MouseClick("left")
          $firstRun = False
     EndIf

     Local $TimerRight = TimerInit()
     Local $TimerExit = TimerInit()
     Local $TimerActive = TimerInit()
     Local $randomExit = Random(4000,5000,1)
     Local $randomActive = Random(2000,3000,1)

     While 1

          Local $psTop = PixelSearch($sawmillTop[0]-5,$sawmillTop[1],$sawmillTop[0],$sawmillTop[1]+5,0xC79038,25)
          If IsArray($psTop) Then
               Send("{LEFT}")
               Sleep(50)
          EndIf

          If TimerDiff($TimerRight) > 50 Then
               Local $psBottom = PixelSearch($sawmillBottom[0]-5,$sawmillBottom[1]-5,$sawmillBottom[0],$sawmillBottom[1]+5,0xC79038,25)
               If IsArray($psBottom) Then
                    Send("{RIGHT}")
                    $TimerRight = TimerInit()
               EndIf
          EndIf

          $c1 = PixelGetColor($sawmillTop[0]-9,$sawmillTop[1]-203)
          ;$c2 = PixelGetColor($sawmillTop[0]+10,$sawmillTop[1]-194)
          $c2 = PixelGetColor($sawmillTop[0]+15,$sawmillTop[1]-189)
          $c3 = PixelGetColor($sawmillTop[0]-11,$sawmillTop[1]-200)
          If     (($c1 = 6443265) And ($c2 = 7363841) Or ($c3 = 8941569)) Then  ;($c2 = 13017856))
               sawmillDoNothing()
               Sleep(Random(100,150,1))
               getBounty()
               ExitLoop
          EndIf

          If TimerDiff($TimerExit) > $randomExit Then
               checkSawmillExit()
               $TimerExit = TimerInit()
          EndIf

          If TimerDiff($TimerActive) > $randomActive Then
               If checkSawmillActive() Then ExitLoop
               $TimerActive = TimerInit()
          EndIf

     WEnd

     WEnd

EndFunc


Func checkSawmillActive()
     Local $c5 = PixelGetColor($sawmillTop[0]+270,$sawmillTop[1]-132)
     If Not ($c5 = $sawmillActiveColor) Then
          Local $is = _ImageSearch($botPath & "sawmill18k.bmp",1,$x,$y,20)
          If $is Then
               getBounty()
          Else
               tryAgain()
          EndIf
          Return True
     EndIf
     Return False
EndFunc


Func checkSawmillExit()

     If Not (PixelGetColor($sawmillTop[0]-45,$sawmillTop[1]-247) == $sawmillExitColor) Then
          _ScreenCapture_Capture("exit_picture.jpg")
          Sleep(2000)
          If $close_Nos Then
               While (ProcessExists("NostaleClientX.exe"))
                    ProcessClose("NostaleClientX.exe")
                    Sleep(2000)
               WEnd
               sendEmail("Game was closed because of an unusual behaviour. See exit_picture.jpg")
          Else
               sendEmail("Bot was stopped because of an unusual behaviour. See exit_picture.jpg")
          EndIf
          beenden(True,$shutdown,$nostaleShutdown)
     EndIf

EndFunc


Func sawmillDoNothing()

     While 1

          Local $col = PixelGetColor($sawmillTop[0]-175,$sawmillTop[1]-112)
          If $col <> 12757864 Then
               ExitLoop
          EndIf

     WEnd

EndFunc



Func sawmillDefinition()

     While 1

          Local $saw = _ImageSearch($botPath & "definition_sawmill.bmp",0,$x,$y,20)
          If $saw Then
               $sawmillTop[0] = $x+45
               $sawmillTop[1] = $y-8
               $sawmillBottom[0] = $x+45
               $sawmillBottom[1] = $y+96
               ExitLoop
          EndIf

     WEnd

EndFunc


Func moorhuhnStart()
     ; To Be Implemented
EndFunc

Func checkTodo()
     If $ctrToDo <= 0 Then
          sendEmail("Bot terminated successfully")
          beenden(True,$shutdown,$nostaleShutdown)
     EndIf
EndFunc


Func fishDefinition()
     While 1
          Local $definition = _ImageSearch($botPath & "map_definition.bmp",0,$x,$y,40)
          If $definition Then
               $fishLeftX = $x-157
               $fishLeftY = $y-6
               $fishTopX = $x-3
               $fishTopY = $y-54
               $fishRightX = $x+84
               $fishRightY = $y-9
               $fishBottomX = $x-41
               $fishBottomY = $y+52
               $fishEventX = $x+171
               $fishEventY = $y+8

               $fishEventUp = $y - 53
               $fishEventLeft = $x - 320
               $fishEventDown = $y + 95
               $fishEventRight = $x + 236

               $fishOverUp = $y+10
               $fishOverLeft = $x
               $fishOverDown = $y+120
               $fishOverRight = $x+167

               #cs
               OLD (German Client)
               $fishOverUp = $y+44
               $fishOverLeft = $x+20
               $fishOverDown = $y+86
               $fishOverRight = $x+167
               #ce

               $colorFishLeft = PixelGetColor($fishLeftX-10,$fishLeftY+10)
               $colorFishTop = PixelGetColor($fishTopX-23,$fishTopY+11)
               $colorFishRight = PixelGetColor($fishRightX+19,$fishRightY+13)
               $colorFishBottom = PixelGetColor($fishBottomX-13,$fishBottomY+12)
               $colorFishEvent = PixelGetColor($fishEventX,$fishEventY)
               ExitLoop
          EndIf
     WEnd
          $firstRun = False
EndFunc


Func checkFishExit()

     If Not (PixelGetColor($x,$y-229) == $fishExitColor) Then
          _ScreenCapture_Capture("exit_picture.jpg")
          Sleep(2000)
          If $close_Nos Then
               While (ProcessExists("NostaleClientX.exe"))
                    ProcessClose("NostaleClientX.exe")
                    Sleep(Random(1500,3000,1))
               WEnd
               sendEmail("Game was closed because of an unusual behaviour. See exit_picture.jpg")
          Else
               sendEmail("Bot was stopped because of an unusual behaviour. See exit_picture.jpg")
          EndIf

          beenden(True,$shutdown,$nostaleShutdown)
     EndIf

EndFunc


Func fishDoNothing()

     Local $TimerTooLong = TimerInit()
     Local $TimerSendArrow = TimerInit()
     Local $randomLong = Random(28000,35000,1)
     Local $randomArrow = Random(600,850,1)

     While 1

          Local $bnty = _ImageSearch($botPath & "bounty_" & getMode() & ".bmp",1,$ex,$ey,60)
          If $bnty Then
               ExitLoop
          EndIf

          If TimerDiff($TimerTooLong) > $randomLong Then
               throw_error("20.000 points reached, but no reward found")
               beenden(True,$shutdown,$nostaleShutdown)
          EndIf

          If TimerDiff($TimerSendArrow) > $randomArrow Then
             Switch(Random(0,3,1))
               Case 0
                  Send("{LEFT}")
               Case 1
                  Send("{RIGHT}")
               Case 2
                  Send("{UP}")
               Case 3
                  Send("{DOWN}")
               EndSwitch
               $TimerSendArrow = TimerInit()
          EndIf

     WEnd

EndFunc


Func sendEmail($data)

Local $attach = $data = "Bot terminated successfully" ? "" : @ScriptDir & "exit_picture.jpg"

If $email Then
     Local $sCurrentUser = $oOutlook.GetNameSpace("MAPI").CurrentUser.Name
     _OL_Wrapper_SendMail($oOutlook, $sCurrentUser, "", "", "Bot has stopped", $data , $attach , $olFormatHTML, $olImportanceHigh)
     If @error <> 0 Then
          MsgBox(16, "OutlookEX UDF: _OutlookSendMail Wrapper Script", "Error sending mail. @error = " & @error & ", @extended: " & @extended)
     EndIf
EndIf

    If $nostaleShutdown Then
        While (ProcessExists("NostaleClientX.exe"))
            ProcessClose("NostaleClientX.exe")
            Sleep(1000)
        WEnd
     EndIf

     If Not $shutdown Then MsgBox(64,"",getResult() & $data)
     beenden(True,$shutdown,$nostaleShutdown)

EndFunc


Func gameStart()

     Local $mode = getMode()
     While 1

          Local $spiel = _ImageSearch($botPath & "start_" & $mode & ".bmp",1,$ex,$ey,10)
          If $spiel Then
              ToolTip("")
              Sleep(Random(10,400,1))
               MouseClick("left",$ex+Random(0,120,1),$ey+Random(16,25,1),1,4)
               MouseMove($ex,$ey+100,4)
               ExitLoop
           EndIf
           If $firstRun Then
               ToolTip("Searching start button..")
           EndIf
     WEnd

EndFunc


Func tryAgain()

     Local $try = _WaitForImageSearch($botPath & "again_" & getMode() & ".bmp",5,1,$ex,$ey,60)
     If $try Then
          MouseClick("left",$ex+Random(0,35,1),$ey+Random(15,20,1),1,4)
          MouseMove($x,$y+250,4)
          $ctrAttempt += 1
     Else
          throw_error('"Try again" not found')
     EndIf

EndFunc


Func startProgressGUI()

     $FormProgress = GUICreate("Progress", 313, 114, 5, 5)
     $Progress1 = GUICtrlCreateProgress(24, 16, 262, 33, $WS_BORDER)
     GUICtrlSetData(-1, 0)
     $LabelStarted = GUICtrlCreateLabel("Started: 00:00", 192, 88, 99, 17)
     GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
     $LabelProgress = GUICtrlCreateLabel("0/0", 136, 56, 75, 20)
     GUICtrlSetFont(-1, 10, 400, 0, "Verdana")
     GUISetState(@SW_SHOW)

     GUICtrlSetData($LabelStarted,"Started: " & @HOUR & ":" & @MIN)
     GUICtrlSetData($LabelProgress,"0/" & $toDo_Max)
     WinSetOnTop($FormProgress,"",1)

EndFunc


Func updateProgressGUI()

     GUICtrlSetData($LabelProgress,$ctrSuccess & "/" & $toDo_Max)
     If $toDo_Max <> 0 Then
          Local $percent = Round(($ctrSuccess/$toDo_Max)*100)
          GUICtrlSetData($Progress1,$percent)
     EndIf

EndFunc


Func closeProgressGUI()
     GUIDelete($FormProgress)
EndFunc


Func throw_error($data)
     _ScreenCapture_Capture("exit_picture.jpg")
     Sleep(3000)
     sendEmail($data)
EndFunc


Func getResult()
     Local $sRate = ((Round($ctrSuccess/$ctrAttempt,2) > 0) And (Round($ctrSuccess/$ctrAttempt,2) < 100)) ? (Round($ctrSuccess/$ctrAttempt,2) * 100) : 0
     Local $str = "[" & @HOUR & ":" & @MIN & ":" & @SEC & "]" & @CRLF & "To do: " & $toDo_Max & @CRLF & "Done: " & $ctrSuccess & @CRLF & "Attempts: " & $ctrAttempt & @CRLF & "Success rate: " & $sRate & "%" & @CRLF & @CRLF
     If Not $fileWritten Then
          FileWrite($hFile, @MDAY & "." & @MON & "." & @YEAR & " " & $str)
          $fileWritten = True
     EndIf
     Return $str
EndFunc


Func checkDoubler()

     If $ctrDoubler < $doubler_Max Then
          Local $doub = _WaitForImageSearch($botPath & "ok_doubler.bmp",5,1,$ex,$ey,60)
          If $doub Then
               MouseClick("left",$ex+Random(-7,0,1),$ey+Random(-20,-15,1),1,4)
               Sleep(300)
               $ctrDoubler += 1
          Else
               throw_error("rewardcoupon not found")
          EndIf
     EndIf

EndFunc


Func getBounty()

     Local $bounty = _WaitForImageSearch($botPath & "bounty_" & getMode() & ".bmp",5,1,$ex,$ey,60)
     If $bounty Then
          If getMode() = "fishpond" or getMode() = "stonepit" Then
               MouseClick("left",$ex+Random(-15,15,1),$ey+Random(18,24,1),1,4)
          Else
               MouseClick("left",$ex+Random(-15,15,1),$ey+Random(-15,-10,1),1,4)
          EndIf
          MouseMove($x,$y+250,4)
          Sleep(200)
          Local $poziom5 = _WaitForImageSearch($botPath & "poziom5.bmp",5,1,$ex,$ey,60)
          If $poziom5 Then
               MouseClick("left",$ex+Random(0,3,1),$ey+Random(0,3,1),1,4)
               MouseMove($x,$y+250,4)
               Sleep(200)
               checkDoubler()
               Local $again = _WaitForImageSearch($botPath & "bounty_again.bmp",5,1,$ex,$ey,60)
               If $again Then
                    MouseClick("left",$ex+Random(-1,10,1),$ey+Random(5,12,1),1,4)
                    MouseMove($x,$y+250,4)
                    $ctrSuccess += 1
                    $ctrAttempt += 1
                    $ctrToDo -= 1
                    updateProgressGUI()
                    Sleep(300)
                    Local $ok = findBack()
                    If $ok[0] Then
                         MouseClick("left",$ok[1]+Random(-5,5,1),$ok[2]+Random(8,18,1),1,4)
                         Sleep(750)
                         game_stop()
                         Sleep(1500)
                         fill_points()
                         Sleep(1500)
                         arrow_and_open()
                         Sleep(1000)
                         big_start()
                    EndIf
                    Else
                    throw_error('"Try again" not found')
               EndIf
                    Else
               throw_error("Level 5 not found")
          EndIf
                    Else
          throw_error("Reward not found")
     EndIf

EndFunc


Func findBack()

     Local $timerFindBack = TimerInit()
     Local $returnArray[3]
     $returnArray[0] = False
     $returnArray[1] = 0
     $returnArray[2] = 0

     While True

          If TimerDiff($timerFindBack) > 1500 Then
               Return $returnArray
          EndIf

          Local $back = _ImageSearch($botPath & "back.bmp",1,$ex,$ey,10)
          If $back Then
               $returnArray[0] = True
               $returnArray[1] = $ex
               $returnArray[2] = $ey
               Return $returnArray
          EndIf

          Local $spiel = _ImageSearch($botPath & "start.bmp",1,$ex,$ey,10)
          If $spiel Then
               Return $returnArray
          EndIf

     WEnd

EndFunc



Func big_start()

     Local $TimerMax = TimerInit()
     While 1
          Local $big_start = _ImageSearch($botPath & "big_start.bmp",1,$ex,$ey,20)
          If $big_start Then
               MouseClick("left",$ex+Random(0,20,1),$ey+Random(0,20,1),1,4)
               ExitLoop
          EndIf
          Local $big_start_home = _ImageSearch($botPath & "big_start_home.bmp",1,$ex,$ey,20)
          If $big_start_home Then
               MouseClick("left",$ex+Random(5,10,1),$ey+Random(18,23,1),1,4)
               ExitLoop
          EndIf

          If TimerDiff($TimerMax) > 5000 Then
               throw_error("Big Start not found")
          EndIf
     WEnd
EndFunc


Func arrow_and_open()

     Local $arrows[8] = [$botPath & "arrow_start.bmp",$botPath & "arrow_start2.bmp",$botPath & "arrow_start3.bmp",$botPath & "arrow_start4.bmp", _
     $botPath & "arrow_start5.bmp",$botPath & "arrow_start6.bmp",$botPath & "arrow_start7.bmp",$botPath & "arrow_start8.bmp"]
     For $i = 0 To UBound($arrows)-1 Step 1
          Local $arrow_start = _ImageSearch($arrows[$i],1,$ex,$ey,50)
          If $arrow_start Then
               MouseClick("left",$ex+Random(-3,3,1),$ey+Random(38,43,1),1,4)
               Return
          EndIf
     Next
     throw_error("Couldn't restart minigame after filling up points")

EndFunc


Func fill_points()
     Local $tmp_toDO = $ctrToDo
     For $i = 0 To 3 Step 1
          If $tmp_toDO > 0 Then
               Send("0")
               Sleep(Random(1400,2800,1))
               Send("{ENTER}")
               Sleep(Random(1400,2800,1))
               $tmp_toDO -= 5
          EndIf
     Next
EndFunc


Func game_stop()
     Local $game_stop = _WaitForImageSearch($botPath & "stop.bmp",5,1,$ex,$ey,50)
     If $game_stop Then
          MouseClick("left",$ex+Random(0,7,1),$ey+Random(8,18,1),1,4)
     Else
          throw_error("Stop button not found")
     EndIf
EndFunc


Func getFishScore()

     Local $TimerScore = TimerInit()

     While 1
          Local $score_recognize = _ImageSearch($botPath & "score_recognize.bmp",1,$ex,$ey,60)
          If $score_recognize Then
               Local $score = _ImageSearch($botPath & "score.bmp",1,$ex,$ey,40)
               If $score Then
                    Return True
               Else
                    Return False
               EndIf
          EndIf

          If TimerDiff($TimerScore) > 10000 Then Return False
     WEnd

EndFunc



Func checkFishEvent()

     If PixelGetColor($x+171,$y+8) == 197379 Then
          playEvent()
     EndIf

EndFunc


Func playEvent()

     Local $top,$left,$right,$bottom

     While 1

          $top = _ImageSearchArea($botPath & "arrow_up.bmp",1,$fishEventLeft,$fishEventUp,$fishEventRight,$fishEventDown,$ex,$ey,80)
          If $top Then
               Send("{UP}")
               Sleep(Random(200,250,1))
               If eventDone() Then ExitLoop
          EndIf

          $left = _ImageSearchArea($botPath & "arrow_left.bmp",1,$fishEventLeft,$fishEventUp,$fishEventRight,$fishEventDown,$ex,$ey,80)
          If $left Then
               Send("{LEFT}")
               Sleep(Random(200,250,1))
               If eventDone() Then ExitLoop
          EndIf

          $right = _ImageSearchArea($botPath & "arrow_right.bmp",1,$fishEventLeft,$fishEventUp,$fishEventRight,$fishEventDown,$ex,$ey,80)
          If $right Then
               Send("{RIGHT}")
               Sleep(Random(200,250,1))
               If eventDone() Then ExitLoop
          EndIf

          $bottom = _ImageSearchArea($botPath & "arrow_down.bmp",1,$fishEventLeft,$fishEventUp,$fishEventRight,$fishEventDown,$ex,$ey,80)
          If $bottom Then
               Send("{DOWN}")
               Sleep(Random(200,250,1))
               If eventDone() Then ExitLoop
          EndIf

          If eventDone() Then ExitLoop

     WEnd

EndFunc


Func eventDone()

     If PixelGetColor($x+171,$y+8) == 197379 Then
          Return False
     Else
          Sleep($sleepTime/2)
          Return True
     EndIf

EndFunc


Func beendenByHotKey()
     beenden(True,False,False)
EndFunc


Func beenden($writeFile,$shutdown,$nosShutdown)
     If $writeFile Then
          getResult()
          FileClose($hFile)
     EndIf
     If $email Then _OL_Close($oOutlook)
    If $nosShutdown Then
        While (ProcessExists("NostaleClientX.exe"))
            ProcessClose("NostaleClientX.exe")
            Sleep(1000)
        WEnd
     EndIf
     If $shutdown Then
          Shutdown(5)
          Sleep(5000)
     EndIf
     Exit
EndFunc
          
Comments: