SHARE
TWEET

sf2-damage-watcher.lua

a guest Jun 27th, 2011 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print("Life/stun damage watcher for SF2 games in MAME-rr")
  2. print("written by Dammit, 6/27/2011")
  3.  
  4. --local P2_life = 30 --use this to test damage scaling
  5.  
  6. local base, space
  7. local life, stun, time = 0x2C, 0x5E, 0x5C
  8. local old_life, old_stun, old_time = {}, {}, {}
  9.  
  10. local function initialize()
  11.         for p = 1,2 do
  12.                 old_life[p] = memory.readword(base + space*(p-1) + life)
  13.                 old_stun[p] = memory.readword(base + space*(p-1) + stun)
  14.                 old_time[p] = memory.readword(base + space*(p-1) + time)
  15.         end
  16. end
  17.  
  18. emu.registerstart(function()
  19.         for _, game in ipairs({
  20.                 {base = 0xFF833C, space = 0x400, name = "hsf2"},
  21.                 {base = 0xFF844E, space = 0x400, name = "ssf2t"},
  22.                 {base = 0xFF83CE, space = 0x400, name = "ssf2"},
  23.                 {base = 0xFF83BE, space = 0x300, name = "sf2hf"},
  24.                 {base = 0xFF83BE, space = 0x300, name = "sf2ce"},
  25.                 {base = 0xFF83C6, space = 0x300, name = "sf2"},
  26.         }) do
  27.                 if emu.romname() == game.name or emu.parentname() == game.name then
  28.                         base, space = game.base, game.space
  29.                         initialize()
  30.                         print() print("now playing " .. game.name)
  31.                         print("player\tdamage\tstun\ttimeout")
  32.                         return
  33.                 end
  34.         end
  35.         error(emu.romname() .. ": not an SF2 game", 0)
  36. end)
  37.  
  38. savestate.registerload(function()
  39.         initialize()
  40. end)
  41.  
  42. if P2_life then
  43.         memory.writeword(base + space + life, P2_life)
  44.         memory.writeword(base + space + life-2, P2_life)
  45. end
  46.  
  47. emu.registerafter(function()
  48.         for p = 1,2 do
  49.                 local new = {
  50.                         life = memory.readword(base + space*(p-1) + life),
  51.                         stun = memory.readword(base + space*(p-1) + stun),
  52.                         time = memory.readword(base + space*(p-1) + time),
  53.                 }
  54.                 local diff = {
  55.                         life = new.life - old_life[p],
  56.                         stun = new.stun - old_stun[p],
  57.                         time = new.time - old_time[p],
  58.                 }
  59.                 if diff.life < 0 or diff.stun > 0 or diff.time > 0 then
  60.                         diff.time = ((old_time[p] > 0 or diff.life >= 0) and diff.time+1) or diff.time
  61.                         diff.stun = (diff.stun < 0 and "-") or diff.stun
  62.                         diff.time = (diff.time < 0 and "-") or diff.time
  63.                         print(string.format("%d\t%d\t%s\t%s", p, -diff.life, diff.stun, diff.time))
  64.                 end
  65.                 old_life[p], old_stun[p], old_time[p] = new.life, new.stun, new.time
  66.         end
  67. end)
  68.  
  69. gui.register(function()
  70.         gui.box(-0x01, -0x01, 0x0D, 0x18, 0x44444488, 0xffffff88)
  71.         gui.text(0x01, 0x00, string.format("%3d", old_life[1]), 0x00ff00ff)
  72.         gui.text(0x01, 0x08, string.format("%3d", old_stun[1]), 0x00ffffff)
  73.         gui.text(0x01, 0x10, string.format("%3d", old_time[1]), 0xffff00ff)
  74.         gui.box(emu.screenwidth()-0x0E, -0x01, emu.screenwidth(), 0x18, 0x44444488, 0xffffff88)
  75.         gui.text(emu.screenwidth()-0x0C, 0x00, string.format("%3d", old_life[2]), 0x00ff00ff)
  76.         gui.text(emu.screenwidth()-0x0C, 0x08, string.format("%3d", old_stun[2]), 0x00ffffff)
  77.         gui.text(emu.screenwidth()-0x0C, 0x10, string.format("%3d", old_time[2]), 0xffff00ff)
  78. end)
RAW Paste Data
Top