A photo of me playing a game using chess saber

This project was originally created for my AP Computer Science Principles final project. I did a lot of Beat Saber modding at the time, and I wanted to do something that would involve it. After a bit of thinking, I decided that it would be fun to make Beat Saber play a game that it wasn’t supposed to: chess.

I started by figuring out how I wanted to play chess. I decided that writing my own chess engine would be too complex, so I started figuring out how to use an existing engine. Since I had used chess.com in the past, I decided to start there. Since there’s no official API to make moves, I had to figure out one myself. Using the Chrome debugger, I was able to breakpoint functions and figure out which ones were called when you make moves. From there, I wrote a Chrome Extension that would inject a websocket client in to the game that could relay move commands from a server to the active game and extract the game state from an internal variable they left exposed.

I then starting working on the in-game elements. I first used blender to model a chess board and pieces that I could move around inside Beat Saber. Then, using a technique from another mod, I wrote some code to detect a specific level being played inside of Beat Saber and used that to put the player in a custom environment with all the chess elements. I could then host a websocket server for the Chrome Extension to connect to, and all the pieces were able to move. Finally was figuring out how to move pieces around. I decided that using existing input elements from the game would be more entertaining than making something fully custom. I decided to use blocks as buttons and make two rows that the player could use to input a position on the board. Using some code patching techniques, I overrode the movement logic of the blocks and make them position themselves in the button locations and send slice events to a central manager. With a small state machine, the buttons could then make the pieces move, and with that the entire project worked!

gullible