Skip to content

Instantly share code, notes, and snippets.

@Ghostbird
Created January 4, 2023 22:40
Show Gist options
  • Save Ghostbird/770c9ba50c5da01fd88ef4f4793e922d to your computer and use it in GitHub Desktop.
Save Ghostbird/770c9ba50c5da01fd88ef4f4793e922d to your computer and use it in GitHub Desktop.
Automatically play the slot machine in Pokémon FireRed/LeafGreen (and maybe others) running on Android in an emulator.
#!/bin/sh
# Automatically play the slot machine in Pokémon FireRed/LeafGreen (and maybe others) running on Android in an emulator.
#
# REQUIREMENTS:
# - Android device with pokemon in suitable emulator e.g. John GBA / John GBAC
# - PC with:
# - POSIX compliant shell (duh)
# - adb installed and in PATH
#
#
# SETUP:
# 1. Enable USB debugging on your Android device
# 2. Connect the Android device to the PC via USB
# 3. Make a preliminary connection by running `adb shell ls` or something similar to verify access form the PC
# 4. EITHER Set up a hardware mapping in your emulator to use KEYCODE_DPAD_DOWN for D-pad Down and KEYCODE_A for the A button.
# OR Change this script to match a hardware mapping of your emulator
# Note: If you have a mechanism where you can "record" a keypress,
# you can manually run the adb commands from the script below to record them.
#
# USE:
# 1. Start the game in the emulator
# 2. Start the slot-machine minigame
# 3. Put the emulator in turbo mode to speed up the process
# 4. On the PC start this script
# 5. Abort the script once you have enough coins (e.g. Ctrl+C to SIGINT)
#
# NOTES:
# My emulator doesn't buffer input event, and misses a lot of events, even when playing normally.
# Therefore the default magnitude is 15, which means it presses the buttons 15 times in a row.
# If your emulator buffers events perfectly, you should run the script with 3 as argument
# which will only perform the exact button sequence necessary. (3×D-pad down, 3×Button A)
#
# TRIVIA:
# My credits just maxed out as I finished refactoring and documenting this script
if [ "$1" = '-h' ] || [ "$1" = '--help' ]
then
cat << EOF
USAGE: $0 [-h] [MAGNITUDE]
MAGNITUDE Times to repeat each keypress in the sequence. Default: 15
-h Print this text
EOF
exit 1
fi
magnitude=${1:-15}
echo "MAGNITUDE ${magnitude}"
while true
do
# SMAH DOWN
for i in $(seq $magnitude)
do
adb shell input keyevent KEYCODE_DPAD_DOWN
done
# SMASH A
for i in $(seq $magnitude)
do
adb shell input keyevent KEYCODE_A
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment