Sandbox Mode in Super Auto Pets
Have you ever wanted to test theoretical battles in Super Auto Pets? Leveraging the power of man-in-the-middle proxies and an API tool, now you can!
TLDR: to quickly learn how to create your own custom battles with the sandbox tool skip to the quick guide here.
What is Super Auto Pets
Super Auto Pets is a game created by the developers at Team Wood Games. In a nutshell, the game is an auto-battler where over a series of rounds you continually improve your team of pets until you either run out of lives or gain enough trophies to win the game.
Pets can be obtained by rolling the shop in order to choose from a random selection of currently available pets at the current tier.
Within Super Auto Pets there is (at the time of this writing) no way in which you can choose exactly which pets you want without rolling the right pets and then rolling either the correct upgrades or similar pets in order to level up your pet. Due to this limitation, the desire to test different combinations of pets arises.
To run the local environment and start using the sandbox mode for Super Auto Pets, it helps to get an understanding of how the game is working under the hood.
Peeking Under the Hood
Super Auto Pets is a game created in Unity and interacts with an API in order to let players interact with the different parts of the application that change. For example, to play against other players, their teams need to be fetched from the server. When the game requests to view a battle it hits an API, something like:
https://api.teamwood.games/0.17/api/battle/get/aadf3fe3-9ad5-4567-bdfa-aab51dc41d68
If we simply try to access the above in a browser, we would see something similar to the following:
Drat. A 401 error means that we don’t have the right permissions to view this page. However, the Super Auto Pets game/engine does have the correct permissions in order to do so.
You can actually view what network requests the game is making, and view what the responses are from within the network tab of your browser’s developer tools. The way in which you access these are somewhat browser-specific, however, if you right-click anywhere outside of the game and click inspect it should open the browser’s developer tools. From there you can navigate to the network tab and view requests. It generally should start empty but as you do things like moving your pets around the screen you will be able to see requests being made and further inspect these requests.
To use the game engine to generate our own custom battles, we need to allow requests through for most things and intercept/slightly change those requests which we want to control. In our case, this will be the battle replays. Instead of getting the last battle and viewing that output, we will send a request to the server asking it to return the output for a battle that we choose. This is where the man in the middle proxy comes in.
API Interceptor Tool
This tool was built by the Github user bspammer, and is quite a brilliant trick. What we do is use the tool to modify the requests that the game receives by routing traffic through our own network proxy.
This image outlines how a man-in-the-middle proxy works:
Requests are sent from the game (client) and are intercepted by the local proxy before making requests to the Team Wood Games server. By doing this we are able to get the server to respond to arbitrary queries which we provide it, while appearing to come from a legitimate source (the game running from the browser).
Tools for installing the tool and running it are outlined below.
Prerequisites
Installation & Setup
Windows users can download Python 3 from https://www.python.org/downloads/.
Mac users can download Python from https://www.python.org/downloads/. If you don’t have an M1 chip, then you can select the Intel version. It can also be installed with brew:
brew install python3
Next, we need to install the mitm proxy tool which will be used as the proxy server.
Windows users can install the tool from https://mitmproxy.org/. Ensure that once it’s installed that the mitm proxy exe file is on your PATH to ensure that you can use it from the terminal.
Mac users can simply use:
brew install mitmproxy
Lastly, we need the super auto pets arbitrary replay tool. This can be either downloaded directly from here or cloned locally via. git.
git clone https://github.com/bspammer/super-auto-pets.git
Now that you have everything installed, it’s time to run it!
Running the Tool
Once you’ve got the appropriate software installed, you need to first run the proxy. There are helper scripts within the repo (start-proxy.sh for *nix users and start-proxy.ps1 for Windows users). However, ultimately you should be able to run the following from your command line in order to run the proxy server and start listening for Super Auto Pets battle requests:
mitmproxy --allow-hosts teamwood.games -s mitmproxy-plugin.py
What the above does is it starts the mitmproxy tool, and only reroutes requests from URLs that end in teamwood.games (the API server that routes Super Auto Pets requests). It then calls the python script mitmproxy-plugin.py which performs the battle logic on the requests.
With the proxy running, you now need to start routing your own traffic through the proxy. The proxy runs on http://127.0.0.1:8080 for mac users and http://localhost:8080 will work for Windows users.
Now you need to navigate to Super Auto Pets in the browser and play until you get to view your first battle. After this point, you should be able to now run the script to generate a battle:
python make-team.py
This should generate the default battle, and if all goes well you should be able to see the default generated battle of five fish vs. five worms rather than the previous battle that you had played. Congratulations 🎉 this is where the fun begins and you can start creating any battle you want.
To create your custom team, simply edit the make-team.py file and change the contents of either team_1, team_2, or both to what you desire. Once that’s done you can simply rerun the command above to use this team for your next replay.
As an example:
("fish", "lucky", 3, 10, 50, "abandon"),
The first value “fish” is the pet that will appear (the full list of pets can be found in data/animals.json.
The second value “lucky” is the perk or food that the pet will have. E.g. melon, mushroom, garlic, etc. The full list of perks can be found in data/perks.json.
The third value “3” is the level of the pet this can be either 1, 2, or 3.
The fourth value “10” is the attack of the pet. This can be higher than the normally capped value of 50 within the game. I’m not sure what the highest it can be is.
The fifth value “50” is the health of the pet. This can also be higher than 50.
The last value “abandon” is the hat that the pet wears. This has no implication on the outcome of the battle, but it is stylish and that’s important. You can find a full list of hats in data/hats.json.
Playing with the Beta Packs
The tool also supports arbitrary builds using the beta version of Super Auto Pets.
To access the beta version, use this link (can only play in the browser for the beta version). Then, simply follow the above instructions as before and you should be able to play with the new abilities and animations only available currently in the beta version of the game.
Note: the beta animals will work in the original game however, their images and perks will not work as intended. To get a more accurate battle, you must use the beta version of the application.
At the time of this writing, in order to use the beta animals, you will need to use the code from this branch to use the latest version of the API.
Tricks & Examples
Things you can change in your replay using the tool:
- You and your opponent’s display names (these can be edited in the generated-battle.json file).
- The random seed (affects the outcome when randomness is a determining factor in a battle).
- The background of the opponent and yourself
- Each pet’s individual hat
- The health and attack of each pet
- Use hats and perks that aren’t available in the base game
Contributing and Future Development
Currently, the tool only supports playing arbitrary battles. Due to a lot of the interactions of Super Auto Pets being API driven, it is possible that a lot more could be done with this tool.
For example:
- Allowing arbitrary pets in the shop with arbitrary money to be used and experimented with to discover optimal strategies for buying and selling pets
- An interface that allows non-developers to easily create and share super auto pets battles and replays
- A tool that determines optimal strategies
- Super Auto Pets puzzle mode. I.e. given a certain lineup, are you able to beat it under certain limitations? E.g. Can you beat 5, 50/50 fish with only 4, 25/25 pets?
Closing Thoughts
Thank you for getting this far! If you have any questions about the tool or need any help in getting set up, drop a comment below and I will do my best to assist you.
If you have any interesting builds, would love to see those in the comments as well.
Happy building, and dream on.