Skip to content

Commit

Permalink
Dev Branch
Browse files Browse the repository at this point in the history
  • Loading branch information
yuceltoluyag committed Oct 3, 2023
1 parent 1cde534 commit 20de41c
Show file tree
Hide file tree
Showing 139 changed files with 17,065 additions and 83 deletions.
50 changes: 30 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

# Rise of Kingdom Bot

### **Main source**

- Link: https://github.com/yuceltoluyag/Rise-of-Kingdoms-Bot

### **Introduction**

Rise of Kingdom Bot can do following job: claim quests/vip/gifts, collecting resource, gathering resource, donate techology, train troops and pass verification.
Expand All @@ -26,6 +30,7 @@ If you like this project, give me a star or feedback , that is great help for me
- Enable Sunset Canyon.
- Enable LOST Canyon.
- Use Items(Some Features)
- Find device LDPlayer

Note: Don't forget to move your **'save'**, **'config.json'** and **'devices_config.json'** to new version folder

Expand Down Expand Up @@ -60,26 +65,27 @@ Note: Don't forget to move your **'save'**, **'config.json'** and **'devices_con

### Functions

| Name | Status |
| ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
| Automatically start the game when game is not running | **<u>Done</u>** |
| Automatically locating building | **<u>Done</u>** |
| Collecting resource, troops, and help alliance | **<u>Done</u>** |
| Produce material | **<u>Done</u>** |
| Open free chest in tavern | **<u>Done</u>** |
| Claim quest and daily objectives | **<u>Done</u>** |
| Claim VIP chest | **<u>Done</u>** |
| Claim Event | not yet |
| Collecting allied resource, gifs and donate technology | **<u>Done</u>** |
| Upgrade and train troops | <u>**Done**</u> |
| Attack barbarians | <u>**Done**</u> |
| Heal troops | <u>**Done**</u> |
| Gather resource | **<u>Done</u>** |
| Mystery Merchant | <u>**Done**</u> |
| A simple GUI | **<u>Done</u>** |
| Allow bot control multi-devices/emulator | **<u>Done</u>** |
| Pass verification with haoi API | **<u>not yet</u>** |
| Pass verification with 2captcha API | **<u>[BETA](https://github.com/yuceltoluyag/Rise-of-Kingdoms-Bot/releases/tag/0.0.1-Beta)</u> Please Test : )** |
| Name | Status |
| ------------------------------------------------------ | ------------------ |
| Automatically start the game when game is not running | **<u>Done</u>** |
| Automatically locating building | **<u>Done</u>** |
| Collecting resource, troops, and help alliance | **<u>Done</u>** |
| Produce material | **<u>Done</u>** |
| Open free chest in tavern | **<u>Done</u>** |
| Claim quest and daily objectives | **<u>Done</u>** |
| Claim VIP chest | **<u>Done</u>** |
| Claim Event | not yet |
| Collecting allied resource, gifs and donate technology | **<u>Done</u>** |
| Upgrade and train troops | <u>**Done**</u> |
| Attack barbarians | <u>**Done**</u> |
| Heal troops | <u>**Done**</u> |
| Gather resource | **<u>Done</u>** |
| Mystery Merchant | <u>**Done**</u> |
| A simple GUI | **<u>Done</u>** |
| Allow bot control multi-devices/emulator | **<u>Done</u>** |
| Pass verification with haoi API | **<u>not yet</u>** |
| Pass verification with 2captcha API | **<u>Done</u>** |
| Find devices | **<u>Done</u>** |

# Can it do captcha?

Expand Down Expand Up @@ -112,6 +118,10 @@ Note: Don't forget to move your **'save'**, **'config.json'** and **'devices_con

![](https://github.com/yuceltoluyag/Rise-of-Kingdoms-Bot/blob/main/docs/structure.png?raw=true)

- New ui:

![](https://github.com/yuceltoluyag/Rise-of-Kingdoms-Bot/blob/main/docs/new_ui.png?raw=true)

### Configurations

- Emulator resolution must be <u>**720x1280**</u> or <u>**1280x720**</u>
Expand Down
23 changes: 14 additions & 9 deletions adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ def connect_to_device(self, host='127.0.0.1', port=5555):
adb_path = resource_path(FilePaths.ADB_EXE_PATH.value)
cmd = build_command(adb_path, 'connect', "{}:{}".format(host, port))
ret = subprocess.check_output(cmd, shell=True, stderr=subprocess.PIPE, encoding="utf-8", timeout=2)
return self.get_device(host, port)
return self.get_device(host)

def get_client_devices(self):
return self.client.devices()

def get_device(self, host='127.0.0.1', port=5555):
device = self.client.device('{}:{}'.format(host, port))
try:
if device is None:
self.connect_to_device(host, port)
device = self.client.device('{}:{}'.format(host, port))
except Exception as e:
traceback.print_exc()
return None
device = self.client.device('{}'.format(host))
# try:
# if device is None:
# # self.connect_to_device(host, port)
# device = self.client.device('{}:{}'.format(host, port))
# except Exception as e:
# traceback.print_exc()
# return None
return device


Expand Down Expand Up @@ -59,3 +59,8 @@ def enable_adb(host='127.0.0.1', port=5037):
raise RuntimeError('Error: fail to start adb server. \n({})'.format(ret))

return adb

def initAdb():
client = PPADBClient(host="127.0.0.1", port=5037)
devices = client.devices()
return devices
Binary file added adb/AdbWinApi.dll
Binary file not shown.
Binary file added adb/AdbWinUsbApi.dll
Binary file not shown.
Binary file added adb/adb.exe
Binary file not shown.
3 changes: 2 additions & 1 deletion bot_related/device_gui_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ class GuiName(Enum):
MAP = 1
WINDOW = 2
WINDOW_TITLE = 3
# VERIFICATION_CHEST = 4
VERIFICATION_CHEST = 4
VERIFICATION_VERIFY = 5
VERIFICATION_CHEST1 = 7
# VERIFICATION_VERIFY_TITLE = 6
# VERIFICATION_CLOSE_REFRESH_OK = 7

Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"screenSize": [470, 850], "method": "none", "haoiUser": null, "haoiRebate": null, "twocaptchaKey": null}
{"screenSize": [470, 850], "method": "2captcha", "haoiUser": null, "haoiRebate": null, "twocaptchaKey": "7a266f2e2f0ed5b913773ce6b4253ef0"}
2 changes: 1 addition & 1 deletion devices_config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"name": "baba", "ip": "127.0.0.1", "port": "5555"}]
[{"serial_no": "127.0.0.1:5555"}, {"serial_no": "emulator-5554"}, {"serial_no": "emulator-5556"}]
Binary file added docs/new_ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions filepath/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
NEW_TROOPS = 'NEW_TROOPS'
TROOPS_MATCH = 'TROOPS_MATCH'
VERIFICATION_CHEST = 'VERIFICATION_CHEST'
VERIFICATION_CHEST1 = 'VERIFICATION_CHEST1'
VERIFICATION_VERIFY = 'VERIFICATION_VERIFY'
VERIFICATION_VERIFY_TITLE = 'VERIFICATION_VERIFY_TITLE'
VERIFICATION_CLOSE_REFRESH_OK = 'VERIFICATION_CLOSE_REFRESH_OK'
Expand Down
16 changes: 16 additions & 0 deletions filepath/file_relative_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,25 @@ class GuiCheckImagePathAndProps(Enum):
25,
WINDOW,
]
VERIFICATION_CHEST_IMG_PATH = [
'resource\\verification_chest_button.png',
(1280, 720),
(0, 0, 0, 0),
0.8,
25,
VERIFICATION_CHEST]
VERIFICATION_CHEST1_IMG_PATH = [
'resource\\verification_chest_button1.png',
(1280, 720),
(0, 0, 0, 0),
0.8,
25,
VERIFICATION_CHEST1]


GuiCheckImagePathAndPropsOrdered = [
GuiCheckImagePathAndProps.VERIFICATION_CHEST_IMG_PATH,
GuiCheckImagePathAndProps.VERIFICATION_CHEST1_IMG_PATH,
# GuiCheckImagePathAndProps.VERIFICATION_CLOSE_REFRESH_OK_BUTTON_IMAGE_PATH,
GuiCheckImagePathAndProps.VERIFICATION_VERIFY_BUTTON_IMAGE_PATH,
GuiCheckImagePathAndProps.MAP_BUTTON_IMG_PATH,
Expand Down
1 change: 1 addition & 0 deletions gui/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,5 @@ def load_device_config():
def write_device_config(config):
config_json = json.dumps(config)
with open(resource_path("devices_config.json"), 'w') as f:
f.write("") # Ghi lại một danh sách rỗng vào tập tin JSON
f.write(config_json)
100 changes: 55 additions & 45 deletions gui/device_list_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ def __init__(self, notebook, main_frame, cnf={}, **kwargs):
self.windows_size = [kwargs['width'], kwargs['height']]

self.devices_config = load_device_config()

self.main_frame = main_frame
adf = AddDeviceFrame(self, main_frame)
dlt = DeviceListTable(self, main_frame)

for config in self.devices_config:
dlt.add_row(config.get('name', 'None'), config['ip'], config['port'])
dlt.add_row(config.get('serial_no'))

adf.set_on_add_click(dlt.add_row)
adf.set_on_find_click(dlt.delete_all_row, dlt.add_row)
adf.grid(row=0, column=0, pady=(10, 0), sticky=N + W)
dlt.grid(row=1, column=0, pady=(10, 0), sticky=N + W)

Expand All @@ -39,9 +38,11 @@ def __init__(self, parent, main_frame, cnf={}, **kwargs):
self.title.grid(row=0, column=0, sticky=W, padx=(5, 0))
self.device_rows = []

def add_row(self, name, ip, port):
def delete_all_row(self):
self.device_rows.clear()
def add_row(self, serial_no):
try:
new_row = DeviceRow(self, self.main_frame, name, ip, port)
new_row = DeviceRow(self, self.main_frame, serial_no)
new_row.set_on_display_click(self.on_display_click)
new_row.set_on_del_click(self.on_delete_click)
self.device_rows.append(new_row)
Expand Down Expand Up @@ -85,31 +86,24 @@ def render(self):


class DeviceRow(Frame):
def __init__(self, device_list_table, main_frame, name, ip, port, cnf={}, **kwargs):
def __init__(self, device_list_table, main_frame, serial_no, cnf={}, **kwargs):
Frame.__init__(self, device_list_table, kwargs)

self.main_frame = main_frame
self.name = name
self.ip = ip
self.port = port

self.device = adb.bridge.get_device(ip, port)
self.device = adb.bridge.get_device(serial_no)
self.serial_no = serial_no
self.device_frame = None

self.name_label = Label(
self, text=self.name, bg='white', height=1, width=10)
self.ip_port_label = Label(
self, text='{}:{}'.format(ip, port), bg='white', height=1, width=19)
self, text=serial_no, bg='white', height=1, width=10)
self.status_label = Label(
self, text=DISCONNECTED if self.device is None else CONNECTED, bg='white', width=11
)

self.display_btn = Button(self, text='Display')
self.del_btn = Button(self, text='Delete')

self.name_label.grid(row=0, column=0, sticky=W, padx=(10, 0))
self.ip_port_label.grid(row=0, column=1, sticky=W, padx=(10, 0))
self.status_label.grid(row=0, column=2, sticky=W, padx=(10, 0))
self.display_btn.grid(row=0, column=3, sticky=W, padx=(10, 0))
self.del_btn.grid(row=0, column=4, sticky=W, padx=(10, 0))

Expand All @@ -119,9 +113,9 @@ def set_on_del_click(self, on_click=lambda self: self):
def set_on_display_click(self, on_click=lambda self: self):

def callback():
device = adb.bridge.get_device(self.ip, self.port)
device.name = self.name
device.save_file_prefix = f"{self.name}_{device.serial.replace(':', '_')}"
device = adb.bridge.get_device(self.serial_no)
device.name = self.serial_no
device.save_file_prefix = f"{self.serial_no}"
if device is None:
return
if self.device_frame is None:
Expand Down Expand Up @@ -150,48 +144,64 @@ def __init__(self, parent, cnf={}, **kwargs):
self.port_entry = Entry(self)

self.add_btn = Button(self, text='Add', width=10)
self.find_btn = Button(self, text='Find', width=10)

def ip_entry_validate_cmd(value, action_type):
if action_type == '1':
if not value[-1].isdigit() and value[-1] != '.':
return False
if value[0] == '0':
return False
# if action_type == '1':
# if not value[-1].isdigit() and value[-1] != '.':
# return False
# if value[0] == '0':
# return False
return True

def port_entry_validate_cmd(value, action_type):
if action_type == '1':
if not value[-1].isdigit():
return False
if value[0] == '0':
return False
# if action_type == '1':
# if not value[-1].isdigit():
# return False
# if value[0] == '0':
# return False
return True

self.name_entry.config(width=10)

self.ip_entry.config(width=15, validate='key', validatecommand=(
self.register(ip_entry_validate_cmd), '%P', '%d'
))
self.port_entry.config(width=8, validate='key', validatecommand=(
self.register(port_entry_validate_cmd), '%P', '%d'))
# self.ip_entry.config(width=15, validate='key')
# self.port_entry.config(width=8, validate='key')

# self.name_label.grid(row=0, column=0, sticky=W, padx=5)
# self.name_entry.grid(row=0, column=1, sticky=W, padx=5)
# self.ip_label.grid(row=0, column=2, sticky=W, padx=5)
# self.ip_entry.grid(row=0, column=3, sticky=W, padx=5)
# self.port_label.grid(row=0, column=4, sticky=W, padx=5)
# self.port_entry.grid(row=0, column=5, sticky=W, padx=5)
# self.add_btn.grid(row=0, column=6, sticky=W, padx=5)
self.find_btn.grid(row=0, column=6, sticky=W, padx=5)

def set_on_find_click(self, clear_row, onclick=lambda device,serial_no: None):
def callback():
clear_row()
list_devices = adb.initAdb()
self.master.devices_config = []
for device in list_devices:
onclick(device.get_serial_no())

self.master.devices_config.append(
{
'serial_no': device.get_serial_no(),
}
)
write_device_config(self.master.devices_config)

self.name_label.grid(row=0, column=0, sticky=W, padx=5)
self.name_entry.grid(row=0, column=1, sticky=W, padx=5)
self.ip_label.grid(row=0, column=2, sticky=W, padx=5)
self.ip_entry.grid(row=0, column=3, sticky=W, padx=5)
self.port_label.grid(row=0, column=4, sticky=W, padx=5)
self.port_entry.grid(row=0, column=5, sticky=W, padx=5)
self.add_btn.grid(row=0, column=6, sticky=W, padx=5)
self.find_btn.config(command=callback)

def set_on_add_click(self, on_click=lambda ip, port: None):
def callback():
name = self.name_entry.get()
ip = self.ip_entry.get()
port = self.port_entry.get()
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", ip) is None:
return
if not (1 <= int(port) <= 65535):
return
# if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", ip) is None:
# return
# if not (1 <= int(port) <= 65535):
# return
on_click(name, ip, port)
self.master.devices_config.append(
{
Expand Down
Binary file modified resource/verification_chest_button.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 added resource/verification_chest_button1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 20de41c

Please sign in to comment.