Skip to content

Commit

Permalink
Merge pull request #6 from Hammanek/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
Hammanek authored Aug 29, 2024
2 parents 9b5b238 + b0a57b3 commit 668b7fd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
6 changes: 5 additions & 1 deletion AutoAFK.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
settings = os.path.join(cwd, 'settings.ini')
config.read(settings)

version = "0.19.6"
version = "0.21"

repo_releases = requests.get('https://api.github.com/repos/Hammanek/AutoAFK/releases/latest')
json = repo_releases.json() if repo_releases and repo_releases.status_code == 200 else None
Expand Down Expand Up @@ -1084,6 +1084,10 @@ def dailies():
useBagConsumables()
if pauseOrStopEventCheck(app.dailies_pause_event, app.dailies_stop_event):
break # Exit the loop if stop event is set
if config.getboolean('DAILIES', 'levelup'):
levelUp()
if pauseOrStopEventCheck(app.dailies_pause_event, app.dailies_stop_event):
break # Exit the loop if stop event is set
printGreen('Dailies done!')

if config.getboolean('ADVANCED', 'enable_afkjourney'):
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Configure your MuMu Player client so that:
* DPI is 240
* AFK's language is set to English

Then download the latest [release](https://github.com/Hammanek/AutoAFK), unzip and run AutoAFK.exe.
Then download the latest [release](https://github.com/Hammanek/AutoAFK/releases/), unzip and run AutoAFK.exe.

# Road map
The following features will be added soon(tm)
Expand Down
10 changes: 5 additions & 5 deletions activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def pushTower(tower, formation=3, duration=1, app=None):
printWarning('No victory found, checking again in ' + str(config.get('PUSH', 'victoryCheck') + ' minutes.'))
click('buttons/cancel', retry=3, suppress=True, region=boundaries['cancelAB'])
else: # If we don't see 0 we assume victory. We exit the battle, clear victory screen and clear time limited rewards screen
printGreen('Victory found! Loading the ' + str(config.get('PUSH', 'formation') + ' formation for the current stage..'))
printGreen('Victory found! Loading formation for the current stage..')
click('buttons/exit', retry=3, suppress=True, region=boundaries['exitAB'])
click('buttons/pause', 0.8, retry=3, suppress=True, region=boundaries['pauseBattle']) # 3 retries as ulting heroes can cover the button
click('buttons/exitbattle', retry=2, suppress=True, region=boundaries['exitBattle'])
Expand Down Expand Up @@ -459,7 +459,7 @@ def pushCampaign(formation=3, duration=1,app=None):
click('buttons/cancel', retry=3, suppress=True, region=boundaries['cancelAB'])
wait((duration * 60) - 30) # Sleep for the wait duration
else: # If it's not 0 we have passed a stage
printGreen('Victory found! Loading the ' + str(config.get('PUSH', 'formation') + ' formation for the current stage..'))
printGreen('Victory found! Loading formation for the current stage..')
click('buttons/exit', suppress=True, retry=3, region=boundaries['exitAB'])
click('buttons/pause', confidence=0.8, retry=3, suppress=True, region=boundaries['pauseBattle']) # 3 retries as ulting heroes can cover the button
click('buttons/exitbattle', suppress=True, retry=3, region=boundaries['exitBattle'])
Expand Down Expand Up @@ -917,7 +917,7 @@ def handleBattleofBlood(battles=3):
clickXY(550, 1250, seconds=1)
clickXY(350, 1250, seconds=1)
clickXY(550, 1850, seconds=1)
if isVisible('buttons/confirm_small', retry=3, region=(600, 1220, 200, 80)):
if isVisible('buttons/confirm_small', retry=3, region=(600, 1240, 200, 80)):
clickXY(325, 1200)
clickXY(700, 1270)
# Place cards 3-4, click ready
Expand Down Expand Up @@ -1578,8 +1578,8 @@ def levelUp():
confirmLocation('ranhorn', region=boundaries['ranhornSelect'])
clickXY(700, 1500, seconds=2) # Resonating crystal
clickXY(520, 1860, seconds=2) # Level up
clickXY(710, 1260) # Confirm
if not isVisible("labels/reso_lvl_progress"):
clickXY(710, 1260, seconds=2) # Confirm
if not isVisible("buttons/level_up"):
for _ in range(10):
clickXY(520, 1860)
printGreen('Leveled up successfully')
Expand Down
Binary file added img/buttons/level_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/labels/reso_lvl_progress.png
Binary file not shown.
39 changes: 22 additions & 17 deletions tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ppadb.client import Client
from AutoAFK import settings, args
from pyscreeze import locate
from subprocess import Popen, PIPE
from subprocess import Popen, PIPE, STARTUPINFO, CREATE_NO_WINDOW
import time, datetime, os, configparser, sys
from PIL import Image
from shutil import which
Expand Down Expand Up @@ -50,14 +50,14 @@ def connect_device():
if os.path.exists(config.get('ADVANCED', 'emulatorpath')):
# Run the executable file
printGreen('Starting emulator...')
Popen(config.get('ADVANCED', 'emulatorpath'), shell=False)
Popen(config.get('ADVANCED', 'emulatorpath'), shell=False, startupinfo=STARTUPINFO(), creationflags=CREATE_NO_WINDOW)
minimize_window()
wait(3)
minimize_window()
else:
was_running = True

printGreen('Attempting to connect..')
printGreen('Attempting to connect...')

if connected is True: # Skip if we've ran through and connected succesfully already this session
waitUntilGameActive() # but still confirm we start from the right place
Expand All @@ -79,7 +79,7 @@ def connect_device():
printBlue('This usually means the port is wrong as there is no device present')
elif str(e) == 'ERROR: \'FAIL\' 0006closed':
printError('PPADB Error: ' + str(e) + ', retrying ' + str(connect_counter) + '/3')
printBlue('The selected port is not responding, is ADB enabled? Retrying..')
printBlue('The selected port is not responding, is ADB enabled? Retrying...')
else:
printError('PPADB Error: ' + str(e) + ', retrying ' + str(connect_counter) + '/3')
wait(3)
Expand Down Expand Up @@ -107,6 +107,10 @@ def connect_device():
if connected is True:
printGreen('Device: ' + str(device.serial) + ' successfully connected!')

if(float(device.shell('getprop ro.build.version.release')) < 7):
printWarning("Your android emulator is out of date, please update first!")
sys.exit(1)

scrcpyClient = scrcpy.Client(device=device.serial)
scrcpyClient.max_fps = max_fps
scrcpyClient.bitrate = bitrate
Expand Down Expand Up @@ -138,8 +142,8 @@ def configureADB():

# Restarting the ADB server solves 90% of issues with it
if config.getboolean('ADVANCED', 'adbrestart') is True:
Popen([adbpath, "kill-server"], stdout=PIPE).communicate()[0]
Popen([adbpath, "start-server"], stdout=PIPE).communicate()[0]
Popen([adbpath, "kill-server"], stdout=PIPE, startupinfo=STARTUPINFO(), creationflags=CREATE_NO_WINDOW).communicate()[0]
Popen([adbpath, "start-server"], stdout=PIPE, startupinfo=STARTUPINFO(), creationflags=CREATE_NO_WINDOW).communicate()[0]
else:
printWarning('ADB Restart disabled')

Expand All @@ -149,14 +153,14 @@ def configureADB():
if port == '':
port == 0 # So we don't throw a NaN error if the field's blank
if ':' in str(port):
printError('Port entered includes the : symbol, it should only be the last 4 or 5 digits not the full IP:Port address. Exiting..')
printError('Port entered includes the : symbol, it should only be the last 4 or 5 digits not the full IP:Port address. Exiting...')
sys.exit(1)
if int(port) == 5037:
printError('Port 5037 has been entered, this is the port of the ADB connection service not the emulator, check BlueStacks Settings - Preferences to get the ADB port number')
sys.exit(1)
printWarning('Port ' + str(config.get('ADVANCED', 'port')) + ' found in settings.ini, using that')
device = '127.0.0.1:' + str(config.get('ADVANCED', 'port'))
Popen([adbpath, 'connect', device], stdout=PIPE).communicate()[0]
Popen([adbpath, 'connect', device], stdout=PIPE, startupinfo=STARTUPINFO(), creationflags=CREATE_NO_WINDOW).communicate()[0]
adb_device = adb.device('127.0.0.1:' + str(config.get('ADVANCED', 'port')))
return adb_device

Expand All @@ -170,12 +174,12 @@ def configureADB():
# Last step is to find the port ourselves, this is Windows only as it runs a PowerShell command
if system() == 'Windows':
device = '127.0.0.1:' + str(portScan())
Popen([adbpath, 'connect', device], stdout=PIPE).communicate()[0]
Popen([adbpath, 'connect', device], stdout=PIPE, startupinfo=STARTUPINFO(), creationflags=CREATE_NO_WINDOW).communicate()[0]
adb_device = adb.device(device)
return adb_device

# If none of the above work we exit
printError('No device found! Exiting..')
printError('No device found! Exiting...')
sys.exit(1)

# This takes all Listening ports opened by HD-Player.exe and tries to connect to them with ADB
Expand All @@ -184,18 +188,18 @@ def portScan():
if system() != 'Windows' or not os.path.exists(adbpath):
adbpath = which('adb') # If we're not on Windows or can't find adb.exe in the working directory we try and find it in the PATH

printWarning('No ADB devices found connected already, and no configured port in settings. Manually scanning for the port..')
printWarning('No ADB devices found connected already, and no configured port in settings. Manually scanning for the port...')

# Powershell command that returns all listening ports in use by HD-Player.exe
ports = Popen(["powershell.exe", "Get-NetTCPConnection -State Listen | Where-Object OwningProcess -eq (Get-Process hd-player | Select-Object -ExpandProperty Id) | Select-Object -ExpandProperty LocalPort"], stdout=PIPE).communicate()[0]
ports = Popen(["powershell.exe", "Get-NetTCPConnection -State Listen | Where-Object OwningProcess -eq (Get-Process hd-player | Select-Object -ExpandProperty Id) | Select-Object -ExpandProperty LocalPort"], stdout=PIPE, startupinfo=STARTUPINFO(), creationflags=CREATE_NO_WINDOW).communicate()[0]
if len(ports.decode().splitlines()) > 0:
printWarning(str(len(ports.decode().splitlines())) + ' ports found, trying them..')
printWarning(str(len(ports.decode().splitlines())) + ' ports found, trying them...')

# Scan ports
for port in ports.decode().splitlines(): # Split by linebreak
port = int(port)
if port % 2 != 0: # ADB will only use odd port numbers
connectmessage = Popen([adbpath, 'connect', '127.0.0.1:' + str(port)], stdout=PIPE).communicate()[0]
connectmessage = Popen([adbpath, 'connect', '127.0.0.1:' + str(port)], stdout=PIPE, startupinfo=STARTUPINFO(), creationflags=CREATE_NO_WINDOW).communicate()[0]
if connectmessage.decode().split(' ')[0] == 'failed':
printError(connectmessage.decode().rstrip())
elif connectmessage.decode().split(' ')[0] == 'connected':
Expand All @@ -212,18 +216,18 @@ def expandMenus():
# Checks if AFK Arena process is running, if not we launch it
def afkRunningCheck():
if args['test']:
# printError('AFK Arena Test Server is not running, launching..')
# printError('AFK Arena Test Server is not running, launching...')
device.shell('monkey -p com.lilithgames.hgame.gp.id 1')
elif not args['test']:
# printError('AFK Arena is not running, launching..')
# printError('AFK Arena is not running, launching...')
device.shell('monkey -p com.lilithgame.hgame.gp 1')
if config.getboolean('ADVANCED', 'debug') is True:
print('Game check passed\n')

# Confirms that the game has loaded by checking for the campaign_selected button. We press a few buttons to navigate back if needed
# May also require a ClickXY over Campaign to clear Time Limited Deals that appear
def waitUntilGameActive():
printWarning('Searching for Campaign screen..')
printWarning('Searching for Campaign screen...')
loadingcounter = 0
timeoutcounter = 0
if args['dailies']:
Expand All @@ -232,6 +236,7 @@ def waitUntilGameActive():
loaded = 1

while loadingcounter < loaded:
afkRunningCheck()
clickXY(420, 50) # Neutral location for closing reward pop ups etc, should never be an in game button here
buttons = [os.path.join('buttons', 'campaign_unselected'), os.path.join('buttons', 'exitmenu_trial'), os.path.join('buttons', 'back')]
for button in buttons:
Expand Down

0 comments on commit 668b7fd

Please sign in to comment.