From 56b1a5964bcf728c084ab506776ffcdf60db1f98 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 4 Apr 2023 11:14:10 +0200 Subject: [PATCH] don't unload when nothing has been loaded --- cheats/chams.py | 14 +++++++++----- cheats/fov.py | 7 ++++++- cheats/noflash.py | 7 ++++++- utils.py | 5 +++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/cheats/chams.py b/cheats/chams.py index 618c9dc..2ec2f54 100644 --- a/cheats/chams.py +++ b/cheats/chams.py @@ -1,7 +1,7 @@ from struct import pack from hack import Hack -from utils import Color3i +from utils import Color3i, errors_unload class Chams(Hack): @@ -83,10 +83,14 @@ class Chams(Hack): # Aliases mem = self.pm offset = self.offsets - color = self.__default_color[0] - brightness = self.__default_color[1] - client = self.__client - engine = self.__engine + try: + color = self.__default_color[0] # type: ignore + brightness = self.__default_color[1] # type: ignore + client = self.__client + engine = self.__engine + except errors_unload(): + # No modification has been done + return # Loop all entities for i in range(1, 32): # 0 is world diff --git a/cheats/fov.py b/cheats/fov.py index e3ed02c..ab805a4 100644 --- a/cheats/fov.py +++ b/cheats/fov.py @@ -1,6 +1,7 @@ from win32api import GetAsyncKeyState from hack import Hack +from utils import errors_unload class Fov(Hack): @@ -55,7 +56,11 @@ class Fov(Hack): # Aliases mem = self.pm offset = self.offsets - local_player = self.__local_player + try: + local_player = self.__local_player + except errors_unload(): + # No modification has been done + return # Reset to default value if changed if self.__fov not in [None, self.__default_fov]: diff --git a/cheats/noflash.py b/cheats/noflash.py index 2a319d8..7a3a4e0 100644 --- a/cheats/noflash.py +++ b/cheats/noflash.py @@ -1,4 +1,5 @@ from hack import Hack, sleep +from utils import errors_unload class Noflash(Hack): @@ -34,7 +35,11 @@ class Noflash(Hack): # Aliases mem = self.pm offset = self.offsets - local_player = self.__local_player + try: + local_player = self.__local_player + except errors_unload(): + # No modification has been done + return # Reset to default value mem.write_float( diff --git a/utils.py b/utils.py index 54f3e38..6d2b5e0 100644 --- a/utils.py +++ b/utils.py @@ -151,3 +151,8 @@ class Color4f: a = round(self.a, max_precision) return f"{self.__class__.__name__}({r}, {g}, {b}, {a})" + + +def errors_unload(): + """Return error who can occurs when unloading cheats""" + return (TypeError, AttributeError)