diff --git a/main.py b/main.py index 5ddbd3e..b09f94a 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,22 @@ +from atexit import register from sys import argv from threading import Thread from cheat import Cheat, sleep + +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() + + if __name__ == "__main__": c_id = [] args = {} @@ -49,16 +63,8 @@ if __name__ == "__main__": t.daemon = True t.start() + register(do_on_exit) + # Don't close the main thread as cheats are daemons - try: - while True: - sleep(1000000) - except KeyboardInterrupt: - 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() + while True: + sleep(1000000)