Skip to content

Instantly share code, notes, and snippets.

@adamf
Created November 7, 2017 17:24
Show Gist options
  • Save adamf/95b4a671b4840959c6d45b575289b2d9 to your computer and use it in GitHub Desktop.
Save adamf/95b4a671b4840959c6d45b575289b2d9 to your computer and use it in GitHub Desktop.
Lua code to read player data from StreetFighter II Turbo for SNES via BizHawk's Lua environment. Contains some bugs!
json = require "json"
function get_framecount()
return emu.framecount()
end
function get_p1_health()
return mainmemory.read_u8(0x000530)
end
function get_p2_health()
return mainmemory.read_u8(0x000730)
end
function get_p1_character()
return mainmemory.read_u8(0x0005D1)
end
function get_p2_character()
return mainmemory.read_u8(0x0007D1)
end
function get_p1_x()
return mainmemory.read_u16_le(0x000022)
end
function get_p2_x()
return mainmemory.read_u16_le(0x000026)
end
function get_p1_y()
return mainmemory.read_u8(0x00050A)
end
function get_p2_y()
return mainmemory.read_u8(0x00070A)
end
function is_p1_jumping()
return mainmemory.read_u8(0x0005EA) == 1
end
function is_p2_jumping()
return mainmemory.read_u8(0x0007EA) == 1
end
function p_height_delta()
return mainmemory.read_u8(0x0005ED)
end
function is_p1_crouching()
return mainmemory.read_u8(0x000544) == 1
end
function is_p2_crouching()
return mainmemory.read_u8(0x00744) == 1
end
function get_timer()
return mainmemory.read_u8(0x0018F3)
end
function is_round_started()
return get_timer() > 0 and get_timer() <= 152
end
function is_round_over()
return get_p1_health()==255 or get_p2_health()==255 or get_timer() <= 0
end
function get_round_result()
if get_p1_health()==255 then
return "P2"
elseif get_p2_health()==255 then
return "P1"
else
return "NOT_OVER"
end
end
function get_p1_buttons()
return joypad.get(1)
end
function get_p2_buttons()
return joypad.get(2)
end
function get_json_state()
return json.encode({frame = get_framecount(), timer = get_timer(), result = get_round_result(), round_started = is_round_started(), round_over = is_round_over(),
p1 = {
character = get_p1_character(),
health = get_p1_health(),
x = get_p1_x(),
y = get_p1_y(),
jumping = is_p1_jumping(),
crouching = is_p1_crouching(),
buttons = get_p1_buttons()
},
p2 = {
character = get_p2_character(),
health = get_p2_health(),
x = get_p2_x(),
y = get_p2_y(),
jumping = is_p2_jumping(),
crouching = is_p2_crouching(),
buttons = get_p2_buttons()
},
height_delta = p_height_delta()
})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment