base: Rework speedhack detection to use TrueClock.

This commit is contained in:
Harvir 2014-08-24 11:54:36 +01:00
parent c987eac453
commit 815d186599
3 changed files with 15 additions and 5 deletions

View file

@ -9,6 +9,7 @@ sync-video #f
want-dev #f want-dev #f
preload-avatars #t preload-avatars #t
texture-anisotropic-degree 16 texture-anisotropic-degree 16
want-speedhack-fix #t
# Resource settings # Resource settings

View file

@ -12,6 +12,7 @@ preload-avatars #t
want-keep-alive #f want-keep-alive #f
texture-anisotropic-degree 16 texture-anisotropic-degree 16
language LANGUAGE_HERE language LANGUAGE_HERE
want-speedhack-fix #t
# Resources settings # Resources settings

View file

@ -28,6 +28,7 @@ from sys import platform
from DisplayOptions import DisplayOptions from DisplayOptions import DisplayOptions
import otp.ai.DiagnosticMagicWords import otp.ai.DiagnosticMagicWords
import time import time
from panda3d.core import TrueClock
class ToonBase(OTPBase.OTPBase): class ToonBase(OTPBase.OTPBase):
notify = DirectNotifyGlobal.directNotify.newCategory('ToonBase') notify = DirectNotifyGlobal.directNotify.newCategory('ToonBase')
@ -428,19 +429,26 @@ class ToonBase(OTPBase.OTPBase):
if config.GetBool('want-speedhack-fix', False): if config.GetBool('want-speedhack-fix', False):
# Start checking for speedhacks. # Start checking for speedhacks.
self.lastSpeedhackCheck = time.time() 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): 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 elapsed = time.time() - self.lastSpeedhackCheck
if elapsed < config.GetFloat('speedhack-interval', 10.0) - 1: tc_elapsed = self.trueClock.getLongTime() - self.lastTrueClockTime
# They responded too fast. This indicates that the TaskManager is running faster 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. # than normal, and possibly means they sped the process up.
self.__killSpeedHacker() self.__killSpeedHacker()
return task.done return task.done
# Clean! Lets wait until the next iteration... # Clean! Lets wait until the next iteration...
self.lastSpeedhackCheck = time.time() self.lastSpeedhackCheck = time.time()
return task.again self.lastTrueClockTime = self.trueClock.getLongTime()
return task.cont
def __killSpeedHacker(self): def __killSpeedHacker(self):
# go fuck yo' self and yo' cheat engine, fuck'r. # go fuck yo' self and yo' cheat engine, fuck'r.