Created
October 20, 2019 15:47
-
-
Save manciuszz/c93437429bb5d224ffc24488f296881a to your computer and use it in GitHub Desktop.
Android mobile game "Survival Heroes" non-intrusive macros made wth AutoHotKey for Tencent's "Gameloop" emulator ran on 1280x720 resolution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv | |
; #Warn | |
#UseHook | |
#MaxThreadsPerHotkey 2 | |
#MaxHotkeysPerInterval 99000000 | |
#HotkeyInterval 99000000 | |
#KeyHistory 0 | |
#Persistent | |
#SingleInstance force | |
ListLines Off | |
Process, Priority, , H ; Set process priority to High -> if unstable, comment or remove this line | |
SetBatchLines, -1 | |
SetKeyDelay, -1, -1 | |
SetMouseDelay, -1 | |
SetDefaultMouseSpeed, 0 | |
SetWinDelay, -1 | |
SetControlDelay, -1 | |
SendMode Input | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
runAsAdmin() { ; Always 'Run As Administrator' | |
static _ := runAsAdmin() | |
if (not A_IsAdmin) { | |
Run *RunAs "%A_ScriptFullPath%" | |
ExitApp | |
return | |
} | |
} | |
global emulatorExe := "ahk_exe " . "AndroidEmulator.exe" ; "Gameloop" executable process name. | |
class SearchArea { | |
viaPixelColor(x, y) { | |
PixelGetColor, foundColor, % x, % y, Fast RGB | |
return foundColor != "" | |
} | |
viaPixelSearch(searchAreaObject, colorID, colorVariance := 0) { | |
topLeftCorner := [searchAreaObject.1, searchAreaObject.2] | |
bottomRightCorner := [searchAreaObject.3, searchAreaObject.4] | |
PixelSearch, Px, Py, topLeftCorner.1, topLeftCorner.2, bottomRightCorner.1, bottomRightCorner.2, colorID, colorVariance, Fast RGB | |
; MouseMove,% Px, % Py ; debug position | |
return Px && Py | |
} | |
} | |
class Clicker { | |
getCurrentPos() { | |
MouseGetPos, x, y | |
return { x: x, y: y } | |
} | |
nonIntrusiveClick(x, y) { ; Note: Requires administrator privileges to work. | |
ControlClick, % "x"x . " y"y, % emulatorExe,,,, NA | |
} | |
} | |
; Note: Optimized for 1280x720 resolution... relative to the window - NOT SCREEN COORDS. | |
class StateManagement { | |
isClosable() { | |
return SearchArea.viaPixelSearch([980, 70, 1230, 140], "0xb4d5ee") ; Search for the "X" button color | |
} | |
} | |
class Macros { | |
clickCurrentPosition() { | |
currentPos := Clicker.getCurrentPos() | |
Click, currentPos.x, currentPos.y | |
this.sleepInterval() | |
} | |
sleepInterval(sleepTime := 25) { | |
Sleep, % sleepTime | |
} | |
quickSlot(slotId) { | |
static slotMap := { 1: { x: 830, y: 375 }, 2: { x: 920, y: 375 }, 3: { x: 1010, y: 375 }, 4: { x: 1115, y: 375 } } | |
this.clickCurrentPosition() | |
Clicker.nonIntrusiveClick(820, 705) ; Click on the "Add to Hotbar" button | |
this.sleepInterval() | |
Clicker.nonIntrusiveClick(slotMap[slotId].x, slotMap[slotId].y) ; Click on the item slot area | |
} | |
quickEquip() { | |
this.clickCurrentPosition() | |
Clicker.nonIntrusiveClick(995, 705) ; Click Equip Button | |
} | |
quickDiscard() { | |
this.clickCurrentPosition() | |
Clicker.nonIntrusiveClick(1155, 705) ; Click Discard Button | |
this.sleepInterval() | |
Clicker.nonIntrusiveClick(775, 505) ; Click Accept button when discarding stacked items | |
} | |
quickBag() { | |
if (!this.closeWindow()) { | |
Clicker.nonIntrusiveClick(1230, 330) | |
} | |
} | |
quickMap() { | |
if (!this.closeWindow()) { | |
Clicker.nonIntrusiveClick(1230, 275) | |
} | |
} | |
closeWindow() { | |
if (StateManagement.isClosable()) { | |
Clicker.nonIntrusiveClick(1175, 85) | |
return true | |
} | |
return false | |
} | |
} | |
; test() { | |
; MsgBox % StateManagement.isClosable() | |
; } | |
#If WinActive(emulatorExe) ; Hotkeys will work only then the process is in the foreground... | |
~+1:: Macros.quickSlot(1) | |
~+3:: Macros.quickSlot(2) | |
~+4:: Macros.quickSlot(3) | |
~+5:: Macros.quickSlot(4) | |
~^E:: Macros.quickEquip() | |
~^D:: Macros.quickDiscard() | |
~B:: Macros.quickBag() | |
~M:: Macros.quickMap() | |
~ESC:: Macros.closeWindow() | |
~+Q:: Clicker.nonIntrusiveClick(975, 680) | |
~+W:: Clicker.nonIntrusiveClick(1020, 545) | |
~+E:: Clicker.nonIntrusiveClick(1170, 475) | |
; ^XButton2:: test() ; test functions button.. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running this script will allow the user to: