Jump to content
  • Advertisement
Sign in to follow this  
Nairb

iPhone Timer Drift

This topic is 2612 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to detect when the user advances their clock, since that's an easy way to cheat some game mechanics. The cheat detection only needs to work in the case where the user doesn't shut down the game.

The current implementation looks a little like this:
  • At the beginning of the game, save the time the game started using two timers - the "user modifiable clock" ( [NSDate timeIntervalSinceReferenceDate] ) and the "system clock" (mach_absolute_time or CACurrentMediaTime). These two timers will have different values but should grow at the same rate.
  • Every frame, diff the current values of the respective timers against the times we saved.
  • If the two differences are too far apart (within some margin of error), we know the clock has been tampered with, since the only way that should be possible is if the user changed their clock.

    This doesn't quite work out, though. On some devices, mach_absolute_time grows faster than [NSDate timeIntervalSinceReferenceDate]. This isn't behavior I'd expect - they should both be determining, well, time, but I guess one of these timers is not terribly accurate.

    Has anyone encountered this? It's a pretty niche problem.

    Cheers,
    --Brian

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!