mirror of
https://github.com/rawrafied/LastWarBot.git
synced 2026-04-16 17:02:19 +00:00
Initial Creation of Bot:
- a recreation of the auto-clicker app VP functionality with the Windows App version of Last War. - Additional functionalities: ---- Retarts the app every 5 mins. ---- Has functionality to check for pop-ups when app reloads (currently only handles lot domino) - Additional Files: ---- Has bare-bone scripts for alternative bot methods: via bluestacks/adb or using library pywin instead of win32. ---- Has initial import of image-processing library pytesseract. ---- Has image reference folder of some images to be used to optimize the bot. - Limitations: ---- Has to use mouse cursor (doesn't work in background) ---- Initial game file to launch is hard coded for dev location ---- Click locations associated with dev environment dimmensions, not dynamically derived.
This commit is contained in:
parent
072d29c666
commit
c992398144
61
Bluestacks/adbserver_manager.py
Normal file
61
Bluestacks/adbserver_manager.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
INITIAL CREATION: Rawrafied 1/3/25
|
||||||
|
DESCRIPTION:
|
||||||
|
- Main script to instantiate Last War Bot environment.
|
||||||
|
"""
|
||||||
|
# LIBRARY IMPORTS: ################################
|
||||||
|
#import sys
|
||||||
|
#import os
|
||||||
|
import subprocess
|
||||||
|
#path = os.getcwd() # Check current directory's path
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
from ppadb.client import Client as AdbClient
|
||||||
|
|
||||||
|
# ADBSERVER_MANAGER CLASS FUNCTIONS: ##########################
|
||||||
|
class adbserver_manager():
|
||||||
|
# MAIN FUNCTION:
|
||||||
|
def __init__(self, verbose):
|
||||||
|
# INITIALIZE CLASS VARIABLES
|
||||||
|
self.verbose = verbose
|
||||||
|
|
||||||
|
# INITIAL FUNCTION CALLS
|
||||||
|
print("INITIALIZING ADBSERVER_MANAGER")
|
||||||
|
self.run_server()
|
||||||
|
|
||||||
|
# INITIALIZE ADBSERVER TO INTERFACE WITH BLUESTACKS
|
||||||
|
def run_server(self):
|
||||||
|
# Run the adb server
|
||||||
|
adbexe_hc = "C:/Users/talks/AppData/Local/Android/Sdk/platform-tools/adb.exe"
|
||||||
|
#os.startfile(adbexe_hc)
|
||||||
|
self.adbserver = subprocess.run([adbexe_hc, "start-server"])
|
||||||
|
|
||||||
|
# List all devices
|
||||||
|
#apk_path = "example.apk"
|
||||||
|
#"HD-Player.exe"
|
||||||
|
|
||||||
|
# Default is local host "127.0.0.1" and 5037
|
||||||
|
self.clients = AdbClient(host="127.0.0.1", port=5037)
|
||||||
|
self.devices = self.clients.devices()
|
||||||
|
|
||||||
|
if self.verbose:
|
||||||
|
print ("client =\n" + str(self.clients))
|
||||||
|
print ("devices =\n" + str(self.devices))
|
||||||
|
|
||||||
|
# CHECK IF NO DEVICES ARE RUNNING
|
||||||
|
if len(self.devices) == 0:
|
||||||
|
print("NO DEVICES RUNNING")
|
||||||
|
# OPEN VP BOT BLUESTACKS
|
||||||
|
lastwarexe = "C:\Program Files\BlueStacks_nxt\HD-Player.exe"
|
||||||
|
instancet2r = "Pie64"
|
||||||
|
#instancet2r = "Pie64_1"
|
||||||
|
lastwarapp = 'com.fun.lastwar.gp'
|
||||||
|
# CALL THE ANDROID-APP/PACKAGE VIA THE ADB SHELL COMMAND
|
||||||
|
subprocess.run([lastwarexe, "shell", "--instance", instancet2r, "--cmd", "launchApp", "--package", 'com.fun.lastwar.gp'])
|
||||||
|
time.sleep(20) #PAUSE FOR 20 SECS
|
||||||
|
# CALL THE AUTOCLICKER APP
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
34
Bluestacks/vpbot.py
Normal file
34
Bluestacks/vpbot.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
INITIAL CREATION: Rawrafied 1/3/25
|
||||||
|
DESCRIPTION:
|
||||||
|
- Main script to instantiate Last War Bot environment.
|
||||||
|
"""
|
||||||
|
# LIBRARY IMPORTS: ################################
|
||||||
|
#import sys
|
||||||
|
#import os
|
||||||
|
#import subprocess
|
||||||
|
#path = os.getcwd() # Check current directory's path
|
||||||
|
|
||||||
|
#import pytessract
|
||||||
|
|
||||||
|
# BOT LIBRARY FILES
|
||||||
|
import adbserver_manager
|
||||||
|
|
||||||
|
# TESTING VARIABLES: ##############################
|
||||||
|
# Variables:
|
||||||
|
verbose = 1
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print ("test")
|
||||||
|
|
||||||
|
# VPBOT CLASS FUNCTIONS: ##########################
|
||||||
|
# MAIN FUNCTION:
|
||||||
|
def main():
|
||||||
|
print("INITIALIZING VPBOT INTELLIGENCE ASSISTANCE CODE")
|
||||||
|
adbmgr = adbserver_manager.adbserver_manager(verbose)
|
||||||
|
|
||||||
|
|
||||||
|
# MAIN SOFTWARE ###################################
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
BIN
Windows/ImageRef/Screenshot 2025-02-08 211603.png
Normal file
BIN
Windows/ImageRef/Screenshot 2025-02-08 211603.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 MiB |
BIN
Windows/ImageRef/Screenshot 2025-02-08 212424.png
Normal file
BIN
Windows/ImageRef/Screenshot 2025-02-08 212424.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.5 MiB |
BIN
Windows/ImageRef/Screenshot 2025-02-09 163615.png
Normal file
BIN
Windows/ImageRef/Screenshot 2025-02-09 163615.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
61
Windows/adbserver_manager.py
Normal file
61
Windows/adbserver_manager.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
INITIAL CREATION: Rawrafied 1/3/25
|
||||||
|
DESCRIPTION:
|
||||||
|
- Main script to instantiate Last War Bot environment.
|
||||||
|
"""
|
||||||
|
# LIBRARY IMPORTS: ################################
|
||||||
|
#import sys
|
||||||
|
#import os
|
||||||
|
import subprocess
|
||||||
|
#path = os.getcwd() # Check current directory's path
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
from ppadb.client import Client as AdbClient
|
||||||
|
|
||||||
|
# ADBSERVER_MANAGER CLASS FUNCTIONS: ##########################
|
||||||
|
class adbserver_manager():
|
||||||
|
# MAIN FUNCTION:
|
||||||
|
def __init__(self, verbose):
|
||||||
|
# INITIALIZE CLASS VARIABLES
|
||||||
|
self.verbose = verbose
|
||||||
|
|
||||||
|
# INITIAL FUNCTION CALLS
|
||||||
|
print("INITIALIZING ADBSERVER_MANAGER")
|
||||||
|
self.run_server()
|
||||||
|
|
||||||
|
# INITIALIZE ADBSERVER TO INTERFACE WITH BLUESTACKS
|
||||||
|
def run_server(self):
|
||||||
|
# Run the adb server
|
||||||
|
adbexe_hc = "C:/Users/talks/AppData/Local/Android/Sdk/platform-tools/adb.exe"
|
||||||
|
#os.startfile(adbexe_hc)
|
||||||
|
self.adbserver = subprocess.run([adbexe_hc, "start-server"])
|
||||||
|
|
||||||
|
# List all devices
|
||||||
|
#apk_path = "example.apk"
|
||||||
|
#"HD-Player.exe"
|
||||||
|
|
||||||
|
# Default is local host "127.0.0.1" and 5037
|
||||||
|
self.clients = AdbClient(host="127.0.0.1", port=5037)
|
||||||
|
self.devices = self.clients.devices()
|
||||||
|
|
||||||
|
if self.verbose:
|
||||||
|
print ("client =\n" + str(self.clients))
|
||||||
|
print ("devices =\n" + str(self.devices))
|
||||||
|
|
||||||
|
# CHECK IF NO DEVICES ARE RUNNING
|
||||||
|
if len(self.devices) == 0:
|
||||||
|
print("NO DEVICES RUNNING")
|
||||||
|
# OPEN VP BOT BLUESTACKS
|
||||||
|
lastwarexe = "C:\Program Files\BlueStacks_nxt\HD-Player.exe"
|
||||||
|
instancet2r = "Pie64"
|
||||||
|
#instancet2r = "Pie64_1"
|
||||||
|
lastwarapp = 'com.fun.lastwar.gp'
|
||||||
|
# CALL THE ANDROID-APP/PACKAGE VIA THE ADB SHELL COMMAND
|
||||||
|
subprocess.run([lastwarexe, "shell", "--instance", instancet2r, "--cmd", "launchApp", "--package", 'com.fun.lastwar.gp'])
|
||||||
|
time.sleep(20) #PAUSE FOR 20 SECS
|
||||||
|
# CALL THE AUTOCLICKER APP
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
39
Windows/appwindow_manager_pywin.py
Normal file
39
Windows/appwindow_manager_pywin.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
INITIAL CREATION: Rawrafied 1/3/25
|
||||||
|
DESCRIPTION:
|
||||||
|
- Class to manage interfacing with application
|
||||||
|
"""
|
||||||
|
# LIBRARY IMPORTS: ################################
|
||||||
|
import pywinauto
|
||||||
|
import pyautogui
|
||||||
|
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
# ADBSERVER_MANAGER CLASS FUNCTIONS: ##########################
|
||||||
|
class appwindow_manager_pywin():
|
||||||
|
# MAIN FUNCTION:
|
||||||
|
def __init__(self, verbose):
|
||||||
|
# INITIALIZE CLASS VARIABLES
|
||||||
|
self.verbose = verbose
|
||||||
|
self.appexedir = str('C:\\Users\\talks\\AppData\\Local\\TheLastWar\\Launch.exe')
|
||||||
|
self.appopen = 0
|
||||||
|
|
||||||
|
# INITIAL FUNCTION CALLS
|
||||||
|
print("INITIALIZING APPWINDOW_MANAGER")
|
||||||
|
self.open_window()
|
||||||
|
self.gotovpscreen()
|
||||||
|
|
||||||
|
# INITIALIZE CONNECTION BETWEEN SCRIPT AND APP
|
||||||
|
def open_window(self):
|
||||||
|
self.AppWindow = pywinauto.application().connection(title="Last War-Survival")
|
||||||
|
print (self.AppWindow)
|
||||||
|
|
||||||
|
|
||||||
|
# FUNCTION TO OPEN SECRETARY POSITION SCREEN:
|
||||||
|
def gotovpscreen(self):
|
||||||
|
print("GOING TO VP DISPLAY")
|
||||||
|
|
||||||
|
|
||||||
129
Windows/appwindow_manager_win.py
Normal file
129
Windows/appwindow_manager_win.py
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
INITIAL CREATION: Rawrafied 1/3/25
|
||||||
|
DESCRIPTION:
|
||||||
|
- Class to manage interfacing with application
|
||||||
|
"""
|
||||||
|
# LIBRARY IMPORTS: ################################
|
||||||
|
import win32gui
|
||||||
|
import win32con
|
||||||
|
import win32api
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
#TODO: Move to its own library
|
||||||
|
import pytesseract
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
# ADBSERVER_MANAGER CLASS FUNCTIONS: ##########################
|
||||||
|
class appwindow_manager():
|
||||||
|
# MAIN FUNCTION:
|
||||||
|
def __init__(self, verbose):
|
||||||
|
# INITIALIZE CLASS VARIABLES
|
||||||
|
self.verbose = verbose
|
||||||
|
self.appexedir = str('C:\\Users\\talks\\AppData\\Local\\TheLastWar\\Launch.exe')
|
||||||
|
#self.appexedir = str('LastWar')
|
||||||
|
self.appopen = 0
|
||||||
|
|
||||||
|
# INITIAL FUNCTION CALLS
|
||||||
|
print("INITIALIZING APPWINDOW_MANAGER")
|
||||||
|
self.open_window()
|
||||||
|
self.gotovpscreen()
|
||||||
|
print("INITIALIZATION DONE; RUNNING VP\nNOTE: Code is in progress. Temporary solution to exit program is by opening task manager via 'ctrl + shift + esc'")
|
||||||
|
while True:
|
||||||
|
self.runvp()
|
||||||
|
currentmin = datetime.now().strftime("%M")
|
||||||
|
print("Current min = "+currentmin)
|
||||||
|
if int(currentmin) % 15 == 0:
|
||||||
|
subprocess.call("TASKKILL /F /IM LastWar.exe", shell=True)
|
||||||
|
# Restart program every 5 mins
|
||||||
|
time.sleep(2)
|
||||||
|
currenttime = datetime.now().strftime("%H:%M")
|
||||||
|
print("INITIALIZING APPWINDOW_MANAGER @ "+str(currenttime))
|
||||||
|
self.open_window()
|
||||||
|
self.gotovpscreen()
|
||||||
|
print("INITIALIZATION DONE; RUNNING VP\nNOTE: Code is in progress. Temporary solution to exit program is by opening task manager via 'ctrl + alt + del'")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# INITIALIZE CONNECTION BETWEEN SCRIPT AND APP
|
||||||
|
def open_window(self):
|
||||||
|
self.AppWindow = win32gui.FindWindow(None, "Last War-Survival Game")
|
||||||
|
print (self.AppWindow)
|
||||||
|
|
||||||
|
if self.AppWindow:
|
||||||
|
win32gui.ShowWindow(self.AppWindow, win32con.SW_RESTORE)
|
||||||
|
AppWindowChild = win32gui.GetWindow(self.AppWindow,win32con.GW_CHILD)
|
||||||
|
print (AppWindowChild)
|
||||||
|
self.appopen = 1
|
||||||
|
else:
|
||||||
|
print("APP NOT OPEN; OPENING...")
|
||||||
|
subprocess.call(self.appexedir)
|
||||||
|
#subprocess.call("LastWar.exe")
|
||||||
|
WAITTIME = 20
|
||||||
|
time.sleep(WAITTIME)
|
||||||
|
if self.verbose:
|
||||||
|
print("WAITED " + str(WAITTIME) + " SECS")
|
||||||
|
self.opengamescenarios()
|
||||||
|
|
||||||
|
# SEND CLICKS TO GAME WINDOW
|
||||||
|
#TODO: CURRENTLY RELIES ON MOVING CURSOR; WANT IT TO SEND CLICKS IN BCKGND
|
||||||
|
def sendclick(self, x, y):
|
||||||
|
WAITTIME = 1
|
||||||
|
time.sleep(WAITTIME)
|
||||||
|
if self.verbose:
|
||||||
|
print("WAITED " + str(WAITTIME) + " SECS")
|
||||||
|
self.AppWindow = win32gui.FindWindow(None, "Last War-Survival Game")
|
||||||
|
rect = win32gui.GetWindowRect(self.AppWindow)
|
||||||
|
lparam = win32api.MAKELONG(100,680)
|
||||||
|
if self.verbose:
|
||||||
|
print(lparam)
|
||||||
|
print (rect)
|
||||||
|
win32api.SetCursorPos((x,y))
|
||||||
|
win32api.PostMessage(self.AppWindow, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lparam)
|
||||||
|
win32api.PostMessage(self.AppWindow, win32con.WM_LBUTTONUP, None, lparam)
|
||||||
|
|
||||||
|
# FUNCTION TO OPEN SECRETARY POSITION SCREEN:
|
||||||
|
def gotovpscreen(self):
|
||||||
|
print("GOING TO VP DISPLAY")
|
||||||
|
#self.sendclick(360, 80) # Click icon
|
||||||
|
#self.sendclick(760, 480) # Server num
|
||||||
|
self.sendclick(360, 80) # Click icon
|
||||||
|
self.sendclick(760, 280) # Server num
|
||||||
|
|
||||||
|
# FUNCTION TO RUN VIP CLICKS
|
||||||
|
def runvp(self):
|
||||||
|
for x in range(5):
|
||||||
|
if x < 3:
|
||||||
|
self.sendclick(650 - 100*(x-1), 470) # Click Position
|
||||||
|
else:
|
||||||
|
self.sendclick(650 - 100*(x-4), 320) # Click Position
|
||||||
|
self.sendclick(780, 590) # Click List
|
||||||
|
self.sendclick(720, 190) # Click Accept First Entry
|
||||||
|
self.sendclick(650, 660) # Click exit
|
||||||
|
self.sendclick(650, 660) # Click exit
|
||||||
|
def runvp_farleft(self):
|
||||||
|
for x in range(5):
|
||||||
|
if x < 3:
|
||||||
|
self.sendclick(290 - 100*(x-1), 450) # Click Position
|
||||||
|
else:
|
||||||
|
self.sendclick(290 - 100*(x-4), 300) # Click Position
|
||||||
|
self.sendclick(420, 590) # Click List
|
||||||
|
self.sendclick(380, 170) # Click Accept First Entry
|
||||||
|
self.sendclick(290, 650) # Click exit
|
||||||
|
self.sendclick(290, 650) # Click exit
|
||||||
|
|
||||||
|
def opengamescenarios(self):
|
||||||
|
currentday = int(datetime.today().weekday()) # Mon =0; Sun =6
|
||||||
|
currenthour = int(datetime.now().strftime("%H"))
|
||||||
|
print("Current Day = "+str(currentday)+"; Current hour = "+str(currenthour))
|
||||||
|
if currentday == 5 or(currentday == 6 and currenthour < 21) or (currentday == 4 and currenthour >= 21):
|
||||||
|
print("TODAY IS SUNDAY; ACCOUNT FOR LOOT DOMINO.")
|
||||||
|
#TEMP SOLN: on friday/saturday, loot domino. can exit via click outside menu.
|
||||||
|
self.sendclick(360, 80) # Click icon
|
||||||
|
#if currentday == 6:
|
||||||
|
#TEMP SOLN: Click for when there's capitol war
|
||||||
|
#self.sendclick(650, 450) # Click x
|
||||||
|
|
||||||
38
Windows/vpbot.py
Normal file
38
Windows/vpbot.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
INITIAL CREATION: Rawrafied 1/3/25
|
||||||
|
DESCRIPTION:
|
||||||
|
- Main script to instantiate Last War Bot environment.
|
||||||
|
"""
|
||||||
|
# LIBRARY IMPORTS: ################################
|
||||||
|
#import sys
|
||||||
|
#import os
|
||||||
|
#import subprocess
|
||||||
|
#path = os.getcwd() # Check current directory's path
|
||||||
|
|
||||||
|
|
||||||
|
# BOT LIBRARY FILES
|
||||||
|
import appwindow_manager_win
|
||||||
|
|
||||||
|
# TESTING VARIABLES: ##############################
|
||||||
|
# Variables:
|
||||||
|
verbose = False
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print ("test")
|
||||||
|
|
||||||
|
# VPBOT CLASS FUNCTIONS: ##########################
|
||||||
|
# MAIN FUNCTION:
|
||||||
|
def main():
|
||||||
|
print("INITIALIZING VPBOT INTELLIGENCE ASSISTANCE CODE")
|
||||||
|
|
||||||
|
#Variables:
|
||||||
|
role =["VPBOT"] # Options: VPBOT, FARMER, FIGHTER
|
||||||
|
firstopened = True
|
||||||
|
|
||||||
|
appwindow_mgr = appwindow_manager_win.appwindow_manager(verbose)
|
||||||
|
|
||||||
|
|
||||||
|
# MAIN SOFTWARE ###################################
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user