Skip to content

Instantly share code, notes, and snippets.

@sagnew
Last active August 30, 2024 05:37
Show Gist options
  • Save sagnew/d62022ad929e479d61b4a9e631ff8c33 to your computer and use it in GitHub Desktop.
Save sagnew/d62022ad929e479d61b4a9e631ff8c33 to your computer and use it in GitHub Desktop.
DTMFighter

You will need to install and set up a SNES9X emulator that has Lua scripting functionality. This typically is labeled "rerecording" or something similar, and is usually the Windows version. If you are running Mac or Linux like I am, you will also need to install Wine. You will also need a ROM of Street Fighter II, or any other game of your choice.

I would link to the SNES emulator and the ROM directly, but that's technically illegal unless you own the console and games themselves in real life (I do). DM me for help if you can't find them elsewhere.

The code above are for the Flask app you'll need to run for the Twilio portion, and the Lua script you will have to run in the emulator.

from flask import Flask, request
from twilio.twiml.voice_response import VoiceResponse, Gather
app = Flask(__name__)
player2_number = '+18555950044'
buttons = ['Select', 'A', 'Up', 'B', 'Left',
'Start', 'Right', 'X', 'Down', 'Y']
@app.route('/voice', methods=['POST'])
def voice_response():
if 'Digits' in request.values:
choice = request.values['Digits']
if request.values['To'] == player2_number:
press_button(2, buttons[int(choice)])
else:
press_button(1, buttons[int(choice)])
resp = VoiceResponse()
gather = Gather(num_digits=1)
resp.append(gather)
resp.redirect('/voice')
return str(resp)
def press_button(player, button):
with open(f'button{player}.txt', 'w') as f:
f.write(button)
if __name__ == '__main__':
app.run(debug=True)
function read_file(filename)
local input = io.open(filename, 'r')
if input ~= nil then
io.input(input)
input_content = io.read()
io.close(input)
return input_content
end
end
function file_exists(filename)
local input = io.open(filename, 'r')
if input ~= nil then
return true
else
return false
end
end
function press_button(button, player)
input_table = {}
input_table[button] = true
for i=0, 40, 1 do
joypad.set(input_table, player)
emu.frameadvance()
end
end
while true do
button1 = read_file('button1.txt')
button2 = read_file('button2.txt')
if button1 ~= nil then
press_button(button1, 1)
os.remove('button1.txt')
end
if button2 ~= nil then
press_button(button2, 2)
os.remove('button2.txt')
end
emu.frameadvance()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment