Amaraticando

Alpha - Lsnes dumper ghost

May 29th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | None | 0 0
  1. outprefix = "simpleghost"..tostring(random.integer(0, 999999))
  2. dumpfile = outprefix..".smwg"
  3. nomovie = false
  4. sucess = io.output(dumpfile)
  5.  
  6. local SMW = {
  7.     -- Game Modes
  8.     game_mode_overworld = 0x0e,
  9.     game_mode_level = 0x14,
  10.    
  11.     sprite_max = 12, -- maximum number of sprites
  12. }
  13.  
  14. dofile("smw-WRAM.lua", "C:\\SNES\\LUA\\") -- reads external file WRAM.lua
  15.  
  16. local function get_game_mode()
  17.     return memory.readbyte("WRAM", WRAM.game_mode)
  18. end
  19.  
  20. local function player()
  21.     if get_game_mode() ~= SMW.game_mode_level then print("Something went wrong!") return end  -- necessary?
  22.    
  23.     -- Read RAM
  24.     local x = memory.readsword("WRAM", WRAM.x)
  25.     local y = memory.readsword("WRAM", WRAM.y)
  26.     local x_speed = memory.readsbyte("WRAM", WRAM.x_speed)
  27.     local x_sub = memory.readbyte("WRAM", WRAM.x_sub)
  28.     local is_ducking = memory.readbyte("WRAM", WRAM.is_ducking)
  29.     local powerup = memory.readbyte("WRAM", WRAM.powerup)
  30.     local yoshi_riding_flag = memory.readbyte("WRAM", WRAM.yoshi_riding_flag)
  31.    
  32.     x_sub = math.floor(x_sub/0x10)  -- I don't like this transformation
  33.    
  34.     -- Computes direction
  35.     local direction
  36.     if x_speed >= 0 then
  37.         direction = 1
  38.     else
  39.         direction = 0
  40.     end
  41.    
  42.     -- Computes hitbox size
  43.     local is_small = is_ducking ~= 0 or powerup == 0
  44.     local on_yoshi = yoshi_riding_flag ~= 0
  45.     local hitbox_size
  46.     if is_small and not on_yoshi then
  47.         hitbox_size = 0
  48.     elseif not is_small and not on_yoshi then
  49.         hitbox_size = 1
  50.     elseif is_small and on_yoshi then
  51.         hitbox_size = 2
  52.     else
  53.         hitbox_size = 3
  54.     end
  55.    
  56.     return x, x_sub, y, direction, hitbox_size
  57. end
  58.  
  59. local function dump_info_level(room_index)
  60.     local frame = movie.currentframe() + 1
  61.     local mode = get_game_mode()
  62.     local real_frame = memory.readbyte("WRAM", WRAM.real_frame)
  63.     if mode == SMW.game_mode_level then
  64.         x, sub_x, y, direction, hitbox_size = player()
  65.     else
  66.         x, sub_x, y, direction, hitbox_size = 0, 0, 0, 0, 0
  67.     end
  68.    
  69.     local is_lagged = real_frame == previous_real_frame
  70.     if is_lagged then is_lagged = 1 else is_lagged = 0 end
  71.    
  72.     previous_real_frame = real_frame
  73.    
  74.     local strline = string.format("%7d %2x %6x %1d %4d %x %4d %d %1d\n",
  75.                             frame, mode, room_index, is_lagged, x, sub_x, y, direction, hitbox_size)
  76.     gui.text(0, 16, strline)
  77.     io.write(strline)
  78. end
  79.  
  80. function on_paint()
  81.     if not movie.readonly() then gui.text(1, 26, "Put the movie in read-only mode")
  82.     else
  83.         local room_index = bit.lshift(memory.readbyte("WRAM", WRAM.room_index), 16) + bit.lshift(memory.readbyte("WRAM", WRAM.room_index + 1), 8) + memory.readbyte("WRAM", WRAM.room_index + 2)
  84.    
  85.         gui.text(1, 1, "RECORDING GHOST")
  86.         dump_info_level(room_index)
  87.     end
  88. end
  89.  
  90. gui.repaint()
Add Comment
Please, Sign In to add comment