Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android mobile game "Survival Heroes" non-intrusive macros made wth AutoHotKey for Tencent's "Gameloop" emulator ran on 1280x720 resolution.
#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..
@manciuszz

This comment has been minimized.

Copy link
Owner Author

@manciuszz manciuszz commented Oct 20, 2019

Running this script will allow the user to:

  • quick slot scrolls into their respective places via SHIFT+1,3,4,5 hotkey combination
  • quick equip/discard items from inventory by placing users mouse above the item and pressing CTRL+E (to equip) / CTRL+D (to discard)

For example: with these feature its possible to quick equip custom armor, scrolls in a middle of a battle -> kind of a big deal.

  • toggle switch bag and map via hotkeys B and M.
  • take advantage of in-game auto-aim system to cast spells on enemies without having to cast it as a skillshot when needed by SHIFT+Q,W,E combination.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment