test.ahk 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. IniRead, ApplicationPath, %A_WorkingDir%\config.ini, settings, ApplicationPath , ???
  2. IniRead, ApplicationDir, %A_WorkingDir%\config.ini, settings, ApplicationDir , ???
  3. IniRead, TestAccount, %A_WorkingDir%\config.ini, settings, TestAccount , ???
  4. IniRead, TestPw, %A_WorkingDir%\config.ini, settings, TestPw , ???
  5. log(Text){
  6. FileAppend, `r`n[%A_DD%.%A_MM%.%A_YYYY% %A_Hour%:%A_Min%:%A_Sec%] %Text%, log.log
  7. }
  8. log("------------------")
  9. log("Starting " ApplicationPath " at " ApplicationDir)
  10. ImgDir = %A_WorkingDir%\img
  11. log(ImgDir)
  12. Process,Close,start.exe
  13. Process,Close,patcher.exe
  14. Process,Close,game client.exe
  15. sleep, 500
  16. Run, %ApplicationPath%, %ApplicationDir%
  17. FindImg(Image, ByRef X, ByRef Y, MaxTries)
  18. {
  19. log("searching for "Image)
  20. global ImgDir
  21. Tries = 0
  22. loop
  23. {
  24. Tries++
  25. Sleep, 1000
  26. file := ImgDir "\" Image
  27. WinGetPos, WinX, WinY, WindowWidth, WindowHeight, A
  28. log("search")
  29. ImageSearch, X, Y, 0, 0, %WindowWidth%, %WindowHeight%, *10 %file%
  30. ifEqual, ErrorLevel, 2
  31. {
  32. log("Could not conduct the search for " file)
  33. return False
  34. } else ifEqual, ErrorLevel, 1
  35. {
  36. IfGreaterOrEqual, Tries, MaxTries
  37. {
  38. log("Could not find " file)
  39. return False
  40. }
  41. } else {
  42. Tries--
  43. log("Found " Image " after " Tries " unsuccessful tries")
  44. return True
  45. }
  46. }
  47. }
  48. ; Main Program
  49. log("waiting for Kolja-Strohm Games Patcher")
  50. If (not WinWaitActive Kolja-Strohm Games Patcher,,30)
  51. {
  52. log("Kolja-Strohm Games Patcher is not active after 30 seconds")
  53. ErrorExit()
  54. }
  55. Sleep, 1000
  56. if (FindImg("play.bmp", X, Y, 60))
  57. {
  58. log("Patching successful")
  59. } else {
  60. ErrorExit()
  61. }
  62. log("clicking at " X ", " Y)
  63. click,%X%,%Y%
  64. If (not WinWaitActive Game Client,,10)
  65. {
  66. log("Game Client is not active after 30 seconds")
  67. ErrorExit()
  68. } else
  69. {
  70. log("Game Client active")
  71. }
  72. if (not FindImg("login_label.bmp", X, Y, 10))
  73. {
  74. ErrorExit()
  75. }
  76. log("logging in as " TestAccount)
  77. Send, %TestAccount%
  78. Send, {Tab}
  79. Send, %TestPw%
  80. if (not FindImg("login_button.bmp", X, Y, 3))
  81. {
  82. ErrorExit()
  83. }
  84. X += 53
  85. Y += 14
  86. MouseMove, %X%, %Y%
  87. Click, down
  88. Sleep, 500
  89. Click, up
  90. if (not FindImg("logo.bmp", X, Y, 3))
  91. {
  92. ErrorExit()
  93. }
  94. CleanUp()
  95. ErrorExit()
  96. {
  97. Process,Close,start.exe
  98. Process,Close,patcher.exe
  99. Process,Close,game client.exe
  100. log("Exiting with code 1")
  101. Exit, 1
  102. }
  103. CleanUp()
  104. {
  105. Process,Close,start.exe
  106. Process,Close,patcher.exe
  107. Process,Close,game client.exe
  108. log("Exiting with code 0")
  109. Exit, 0
  110. }