Join the DZone community and get the full member experience.Join For Free
- writing some simple games.
- hacking other games to see how they were written.
i’m going back to the good old days when we could ‘break’ the zx spectrum game and view the source, or disassemble the games on the atari st and hook/hack them through debuggers and monitors.
learn how to hack games
i encourage you to watch philip’s talk .
after watching philip at work i realized:
- i haven’t been using the find functionality in the source part of the browser dev tools.
- i had an over-reliance on adding breakpoints and don’t need to.
i had not been using
setintervalfrom the console.
after watching i went off and tried the cookie clicker game that philip demonstrates.
but i test things, why should i care?
- imagine that instead of having to use an automated tool to put the application into a certain state, or having to manually click around a do a lot of work.
- imagine that you could just write a few lines of code into the browser console and automate there.
- imagine that you could write a single line of code that would execute every second and ‘do stuff’ like click on a link, or close a dialog, or <insert something in here that you regularly have to do when you use an app>.
i describe an example later in this post of a one-line automated ‘bot’ that could play a game better than a human (me).
back to cookie clicker
and i did quite well.
i used a slightly different approach than philip used and found that
loops worked better for me than
when manipulating as i explored, in this game.
go beyond the for loop
i went off to find games where
was a better fit for me.
the world’s biggest pac-man
setintervalwas a great way to provide infinite lives, restoring a new life each time one was lost.
i had a few false starts with other games that looked promising but which either:
- had such obfuscated code i could make no headway.
- contained game crashing bugs.
i tried some typing games but encountered the “how do i trigger keyboard events” stumbling block.
automating ztype from the console
and then i went back to that old favourite zty.pe .
i’ve played zty.pe before. i really like it.
i suspect i might end up playing z-type quite a lot https://t.co/un6yg2srkx just to improve my typing you understand.— alan richardson (@eviltester) july 21, 2016
- i periodically still play “typing of the dead” on the dreamcast. yup. i have a dreamcast with a keyboard.
- i periodically still play “r-type” - primarily from “r-types” on the playstation one (yup, i still have a ps1).
given both of the above. i really like ztype even though i’m not very good at it.
if you can’t trigger keyboard events, how could you play ztype?
yes, i know what you’re thinking:
“but if i encountered the ‘how do i trigger keyboard events’ stumbling block, how do i automate zty.pe, which is all about keyboard events.”
well, zty.pe is pretty well-designed. it's almost as though it was built to be tested and automated.
- rather than add the ‘shoot’ functionality in the keyboard event hook, so that the only way to trigger it, is by issuing a keyboard event.
- the keyboard event calls a method, so the method can be called outside the keyboard event
if this was an app you were testing and automating, it means that you can automate most of the app by calling the ‘shoot’ method. and leave the risk of ‘do keyboard events fire on this platform’ to a much reduced test scope with a different test approach.
human vs. bot
i only managed to reach level 15, but my automated ‘bot’ reached level 93. you can see the results of my automating here on youtube .
i’m not going to explain exactly what i did since that would ruin the fun. and the video doesn’t show you how either.
but i’ll give some additional tips, some you might see in action in philip’s video:
- pretty print the source.
- use ‘find’ to search for classes and variable you find in the source.
- if you type something into the console and it comes back with ‘function’ then you need to find where the class is instantiated in the code.
- use ‘find’ to search for ‘new’ instantiations of the classes.
- you can do a lot of exploration and manipulation with ‘for’ loops.
for bots, you’ll need to use
i assign the result of
setintervalto a bot e.g.
ztypebot = setinterval(...)so that i can shut the bot down later with a
- find some ‘quick hacks’ that you can use early in your investigation to give you more room to find a better hack e.g. when automating ztype, i started with a bot that had infinite emps and triggered an emp every 2 seconds, and when that was working it gave me time to experiment with the objects and source to figure out how to make a bot that could shoot properly.
- keep notes as you go about what you tried, and how you found the objects.
- sometimes i start by working through the code and look for hints as philip demonstrates.
- sometimes i start by looking to see what code is triggered by the event listeners in the browser dev tools.
- sometimes i breakpoint code that i think is interesting.
- they key (and philip demonstrates this well) is to find the big ‘namespace’ type objects as early as possible.
and do make sure that you don’t submit any high scores after ‘cheating’ or ‘hacking’ in this way, it is most annoying to other people. a proxy tool can help avoid you accidentally sending a high score by blocking any high score submissions e.g. fiddler’s auto-responder works well for this.
- learn how to use the browser dev tools
- interacting with a running application
- exploring the internal object state of an application
- putting a running application into a specific state for testing automatically
- writing very small amounts of code to automate an application state
if you find any good games to play with, let me know.
Published at DZone with permission of Alan Richardson, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.