diff --git a/config/dev.prc b/config/dev.prc index 3be06d3c..53aefac8 100644 --- a/config/dev.prc +++ b/config/dev.prc @@ -9,6 +9,7 @@ sync-video #f want-dev #f preload-avatars #t texture-anisotropic-degree 16 +want-speedhack-fix #t # Resource settings diff --git a/config/public_client.prc b/config/public_client.prc index ff19ba9a..d5d881f9 100644 --- a/config/public_client.prc +++ b/config/public_client.prc @@ -12,6 +12,7 @@ preload-avatars #t want-keep-alive #f texture-anisotropic-degree 16 language LANGUAGE_HERE +want-speedhack-fix #t # Resources settings diff --git a/toontown/toonbase/ToonBase.py b/toontown/toonbase/ToonBase.py index b852a40c..8470e61f 100644 --- a/toontown/toonbase/ToonBase.py +++ b/toontown/toonbase/ToonBase.py @@ -28,6 +28,7 @@ from sys import platform from DisplayOptions import DisplayOptions import otp.ai.DiagnosticMagicWords import time +from panda3d.core import TrueClock class ToonBase(OTPBase.OTPBase): notify = DirectNotifyGlobal.directNotify.newCategory('ToonBase') @@ -428,19 +429,26 @@ class ToonBase(OTPBase.OTPBase): if config.GetBool('want-speedhack-fix', False): # Start checking for speedhacks. self.lastSpeedhackCheck = time.time() - taskMgr.doMethodLater(config.GetFloat('speedhack-interval', 10.0), self.__speedhackCheckTick, 'speedhack-tick') + self.trueClock = TrueClock.getGlobalPtr() + self.lastTrueClockTime = self.trueClock.getLongTime() + taskMgr.add(self.__speedhackCheckTick, 'speedhack-tick') def __speedhackCheckTick(self, task): - # Check if the time elapsed is less than interval-1 (1 second extra just in case) + # Compare the time elapsed for time.time() and TrueClock. If the TrueClock is more + # than 1 second ahead, assume that it's running faster than normal. + # If the system time is dragged backwards between 2 iterations, this might cause + # problems (as the TrueClock would then be ahead). elapsed = time.time() - self.lastSpeedhackCheck - if elapsed < config.GetFloat('speedhack-interval', 10.0) - 1: - # They responded too fast. This indicates that the TaskManager is running faster + tc_elapsed = self.trueClock.getLongTime() - self.lastTrueClockTime + if tc_elapsed > elapsed + 1: + # They responded too fast. This indicates that the TrueClock is running faster # than normal, and possibly means they sped the process up. self.__killSpeedHacker() return task.done # Clean! Lets wait until the next iteration... self.lastSpeedhackCheck = time.time() - return task.again + self.lastTrueClockTime = self.trueClock.getLongTime() + return task.cont def __killSpeedHacker(self): # go fuck yo' self and yo' cheat engine, fuck'r.