-
Notifications
You must be signed in to change notification settings - Fork 0
/
LDPlayerManager.py
193 lines (175 loc) · 7.54 KB
/
LDPlayerManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import os
import subprocess
import time
from pynput.mouse import Button, Controller
class LDPlayerManager:
def __init__(self, ldconsole_path, dnconsole_path):
self.ldconsole_path = ldconsole_path
self.dnconsole_path = dnconsole_path
def run_command(self, cmd):
if cmd[0] == "touch":
# Format the command as a string
cmd_str = " ".join(cmd)
# Use the dnconsole_path to run the command
os.system(f"{self.dnconsole_path} {cmd_str}")
else:
# Use the ldconsole_path to run the command
result = subprocess.run([self.ldconsole_path] + cmd, capture_output=True, text=True)
return result.stdout
def list_instances(self):
cmd = ["list2"]
result = subprocess.run([self.dnconsole_path] + cmd, capture_output=True, text=True)
instances = [line.split(",")[1] for line in result.stdout.splitlines()[1:] if line]
#print(f"list_instances output: {result.stdout}") # debug print
return instances
def get_all_instances_status(self):
cmd = ['list2']
result = subprocess.run([self.dnconsole_path] + cmd, capture_output=True, text=True)
instances = {}
for line in result.stdout.splitlines():
data = line.split(',')
if len(data) >= 6:
name = data[1].strip()
started = data[4].strip()
if started == '1':
status = 'running'
else:
status = 'stopped'
else:
status = 'unknown'
instances[name] = status
return instances
def print_instance_table(self, instance_statuses, status_filter=None):
print("\nInstance Dashboard:")
print("ID".ljust(5), "Instance Name".ljust(30), "Status")
running_instances = []
stopped_instances = []
unknown_instances = []
for instance, status in instance_statuses.items():
if status == "running":
running_instances.append(instance)
elif status == "stopped":
stopped_instances.append(instance)
else:
unknown_instances.append(instance)
if status_filter == "running":
instances = running_instances
elif status_filter == "stopped":
instances = stopped_instances
else:
instances = running_instances + stopped_instances + unknown_instances
for idx, instance in enumerate(instances, start=1):
status = instance_statuses[instance]
print(str(idx).ljust(5), instance.ljust(30), status)
print("\nSummary:")
print(f"{len(running_instances)} instances running")
print(f"{len(stopped_instances)} instances stopped")
print(f"{len(unknown_instances)} instances in an unknown state")
def start_instance(self, instance_name):
cmd = ["launch", "--name", instance_name]
self.run_command(cmd)
# Wait for the instance to start up
time.sleep(5)
# Start the Roblox app
cmd = ["runapp", "--name", instance_name, "--packagename", "com.roblox.client"]
self.run_command(cmd)
# Wait for the app to start up
time.sleep(10)
# Simulate a click on a specific coordinate
mouse = Controller()
mouse.position = (130, 482)
mouse.press(Button.left)
mouse.release(Button.left)
def stop_instance(self, instance_name):
cmd = ["quit", "--name", instance_name]
self.run_command(cmd)
def restart_instance(self, instance_name):
self.stop_instance(instance_name)
self.start_instance(instance_name)
# Wait for the instance to start up
time.sleep(5)
# Start the Roblox app
cmd = ["runapp", "--name", instance_name, "--packagename", "com.roblox.client"]
self.run_command(cmd)
# Wait for the app to start up
time.sleep(10)
# Click on a specific coordinate
cmd = ["input", "touch", str(130), str(482), str(1000)]
self.run_command(cmd)
ldconsole_path = r"C:\LDPlayer\LDPlayer9\ldconsole.exe" # Replace with the path to your ldconsole.exe
dnconsole_path = r"C:\LDPlayer\LDPlayer9\dnconsole.exe" # Replace with the path to your dnconsole.exe
manager = LDPlayerManager(ldconsole_path, dnconsole_path)
instances = manager.list_instances()
def print_instance_table(instance_statuses):
print("\nInstance Dashboard:")
print("ID\tInstance Name\tStatus")
for idx, (instance, status) in enumerate(instance_statuses.items(), start=1):
print(f"{idx}\t{instance}\t{status}")
def get_action():
print("\nActions:")
print("1. Start instance")
print("2. Stop instance")
print("3. Restart instance")
print("4. Refresh dashboard")
print("5. Exit")
instance_statuses = manager.get_all_instances_status()
manager.print_instance_table(instance_statuses)
while True:
get_action()
choice = input("Enter your choice: ")
if choice in ["1", "2", "3"]:
if choice == "1":
action = "start"
valid_instances = [instance for instance, status in instance_statuses.items() if status == "stopped"]
elif choice == "2":
action = "stop"
valid_instances = [instance for instance, status in instance_statuses.items() if status == "running"]
else:
action = "restart"
valid_instances = [instance for instance, status in instance_statuses.items() if status == "running"]
if not valid_instances:
print(f"No valid instances to {action}.")
continue
print("Instances:")
for idx, instance in enumerate(valid_instances, start=1):
print(f"{idx}. {instance}")
instance_index = int(input("Enter the index of the instance: ")) - 1
instance_name = valid_instances[instance_index]
status = instance_statuses[instance_name]
try:
if instance_index < 0 or instance_index >= len(valid_instances):
print("Invalid instance index.")
continue
instance_name = valid_instances[instance_index]
status = instance_statuses[instance_name]
except ValueError:
print("Invalid instance index.")
continue
if choice == "1":
if status == "stopped":
manager.start_instance(instance_name)
instance_statuses[instance_name] = "running"
print(f"Started instance {instance_name}")
else:
print("Instance is already running.")
elif choice == "2":
if status == "running":
manager.stop_instance(instance_name)
instance_statuses[instance_name] = "stopped"
print(f"Stopped instance {instance_name}")
else:
print("Instance is not running.")
elif choice == "3":
if status == "running":
manager.restart_instance(instance_name)
print(f"Restarted instance {instance_name}")
else:
print("Instance is not running.")
elif choice == "4":
instance_statuses = manager.get_all_instances_status()
manager.print_instance_table(instance_statuses)
elif choice == "5":
print("Exiting LDPlayer Dashboard...")
break
else:
print("Invalid choice. Please enter a number between 1 and 5.")