This repository has been archived on 2023-09-02. You can view files and clone it, but cannot push or open issues or pull requests.
csh/main.py

75 lines
2 KiB
Python
Raw Normal View History

2023-04-03 04:20:35 +02:00
from atexit import register
2023-04-01 16:11:56 +02:00
from sys import argv
2023-03-30 21:00:20 +02:00
from threading import Thread
2023-03-30 11:26:52 +02:00
2023-04-06 11:37:37 +02:00
from cheat import Cheat, sleep # type: ignore
2023-03-30 11:26:52 +02:00
2023-04-03 04:20:35 +02:00
def do_on_exit():
"""Called when the program end"""
for fn in [c.cheats_list[i] for i in c_id]:
try:
unloader = getattr(c, f"{fn}_unload")
except:
pass
else:
print(f"Unload {fn}...")
unloader()
2023-03-30 11:26:52 +02:00
if __name__ == "__main__":
2023-04-01 16:11:56 +02:00
c_id = []
args = {}
2023-04-04 11:16:49 +02:00
wanted_list = []
2023-04-01 16:11:56 +02:00
if (len(argv) > 1):
# User wanna use offline offsets
if "--offline" in argv:
args["offline"] = True
# User gave a list of cheats
# Will bypass the interactive selection
2023-04-04 11:16:49 +02:00
wanted_list = [j for j in [i for i in argv if i.startswith(
2023-04-01 16:11:56 +02:00
"--list=")][0][7:].split(",")]
# Load cheat class
c = Cheat(**args)
2023-04-04 11:16:49 +02:00
# Load user list
c_id = [c.cheats_list.index(cheat) for cheat in wanted_list]
2023-04-01 16:11:56 +02:00
# Interactive selection
if (c_id == []):
# Cheat list
print("You can run multiples cheat at once, separate your choices with a space.")
print("Available cheats:")
for idx, cheat in enumerate(c.cheats_list):
print(f"#{idx + 1} - {cheat}")
while c_id == []:
try:
response = [int(i) for i in input("Enter ID: ").split(" ")]
2023-04-01 16:11:56 +02:00
for i in response:
2023-04-01 16:26:55 +02:00
if (i > len(c.cheats_list) or i <= 0):
raise IndexError
c_id.append(i - 1)
2023-04-01 16:11:56 +02:00
except KeyboardInterrupt:
2023-04-01 16:26:55 +02:00
print("Bye")
2023-04-01 16:11:56 +02:00
exit(1)
except:
2023-04-01 16:26:55 +02:00
c_id = []
2023-04-01 16:11:56 +02:00
print("Invalid ID.")
2023-03-30 21:00:20 +02:00
# Instanciate and run threads
2023-03-30 21:07:52 +02:00
for fn in [c.cheats_list[i] for i in c_id]:
print(f"Running {fn}...")
2023-03-30 21:00:20 +02:00
t = Thread(target=getattr(c, fn))
t.daemon = True
t.start()
2023-04-03 04:20:35 +02:00
register(do_on_exit)
2023-03-30 21:07:52 +02:00
# Don't close the main thread as cheats are daemons
2023-04-03 04:20:35 +02:00
while True:
sleep(1000000)