3 min read

Reverse Engineering (Attempting to) the Jstris Replay System (IN PROGRESS)

Table of Contents

Introduction

I somewhat got interested in Tetris a while back. I’m not entirely sure why, but something about seeing people be able to clear blocks on a screen insanely fast gave me something to aspire towards, and it was a game that didn’t require an hour of dedicated attention for each match.

After around a year of playing between study breaks and work, I managed to get my 40 line sprint down a LOT to around 50 seconds (around 90th percentile worldwide), which I was proud of, but still left much to be desired. I felt like I had reached a point where I had pretty much maxed out the parts that were rewarding to max out (fixing finesse, learning 6-3 stacking, doing some basic t-spins, etc) and didn’t really want to put more effort in.

Here’s a replay (totally sped NOT up x2)

my tetris 40L sprint

Essentially all of this is to say I wasn’t as good as I wanted to be. Watching my replay back, despite spending tedious amounts of time studying theory, practicing, and finding immense joy in improving a little bit everyday, I lacked the most important thing. External validation. My gameplay wasn’t impressive looking to the laypeople, which meant NONE of that mattered. This blog post is me applying my technical skills to my most important project yet, achieving fake greatness by making it on the Jstris leaderboard through unlawful (but not necessarily unethical) means to boost my self esteem.

Inspiration

I eventually had reached a point where I was good enough to where I wanted to share clips with my friends, and then realized how the replay system worked. It gave you a data string that looks very similar to this:

N4IgxiBcoG5QzAOngGhAZwPYDMAuARAJ0wAc...(much more)

It kind of looks nonsensical, and I thought initially it was a hash that corresponded to some replay stored on the servers, but then I quickly realized some things that made me realize this held the entire replay in this line of text and that it was some sort of encrypted file. There are a few reasons for this.

  1. A replay of clearing 20 lines yields a string half as long as a replay clearing 40 lines.
  2. Placing the same starting blocks in the same positions yield the same starting string.
  3. Going into inspect element and using the replay in an offline environment still allows the program to decrypt the replay string and display it in the console.

These all looked pretty promising, and I thought with some dedicated time, it would be possible to crack the Jstris replay string (possibly allowing me to synthesize a fake one that could beat the world record). This project has been in the works for a while now, and I hate to bait the two people who read my blog, but I’ve made some good progress and I’m excited to share some results soon so please stay tuned.