Amaraticando

Alpha - Snes9x dumper ghost

May 29th, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.32 KB | None | 0 0
  1. outprefix = "simpleghost"..tostring(math.random(9999999))
  2. dumpfile = outprefix..".smwg"
  3. nomovie = false
  4. sucess = io.output(dumpfile)
  5.  
  6. if not bit then bit = require"bit" end
  7.  
  8. local SMW = {
  9.     -- Game Modes
  10.     game_mode_overworld = 0x0e,
  11.     game_mode_level = 0x14,
  12.    
  13.     sprite_max = 12, -- maximum number of sprites
  14. }
  15.  
  16. local RAM = {
  17.     game_mode = 0x7e0100, --
  18.     real_frame = 0x7e0013,
  19.     effective_frame = 0x7e0014,
  20.     RNG = 0x7e148d,
  21.     current_level = 0x7e00fe,  -- plus 1
  22.     sprite_memory_header = 0x7e1692,
  23.     lock_animation_flag = 0x7e009d, --Most codes will still run if this is set, but almost nothing will move or animate.
  24.    
  25.     -- cheats
  26.     frozen = 0x7e13fb,
  27.     level_paused = 0x7e13d4,
  28.     level_index = 0x7e13bf,
  29.     room_index = 0x7e00ce,
  30.     level_flag_table = 0x7e1ea2,
  31.     level_exit_type = 0x7e0dd5,
  32.     midway_point = 0x7e13ce,
  33.    
  34.     -- Camera
  35.     x_camera = 0x7e001a,
  36.     y_camera = 0x7e001c,
  37.     vertical_scroll = 0x7e1412,  -- #$00 = Disable; #$01 = Enable; #$02 = Enable if flying/climbing/etc.
  38.    
  39.     -- Sprites
  40.     sprite_status = 0x7e14c8,
  41.     sprite_throw = 0x7e1504, --
  42.     chuckHP = 0x7e1528, --
  43.     sprite_stun = 0x7e1540,
  44.     sprite_contact_mario = 0x7e154c,
  45.     spriteContactSprite = 0x7e1564, --
  46.     spriteContactoObject = 0x7e15dc,  --
  47.     sprite_number = 0x7e009e,
  48.     sprite_x_high = 0x7e14e0,
  49.     sprite_x_low = 0x7e00e4,
  50.     sprite_y_high = 0x7e14d4,
  51.     sprite_y_low = 0x7e00d8,
  52.     sprite_x_sub = 0x7e14f8,
  53.     sprite_y_sub = 0x7e14ec,
  54.     sprite_x_speed = 0x7e00b6,
  55.     sprite_y_speed = 0x7e00aa,
  56.     sprite_x_offscreen = 0x7e15a0,
  57.     sprite_y_offscreen = 0x7e186c,
  58.     sprite_miscellaneous = 0x7e160e,
  59.     sprite_tongue_length = 0x7e151c,
  60.     sprite_tongue_timer = 0x7e1558,
  61.     sprite_buoyancy = 0x7e190e,
  62.    
  63.     -- Player
  64.     x = 0x7e0094,
  65.     y = 0x7e0096,
  66.     x_sub = 0x7e13da,
  67.     y_sub = 0x7e13dc,
  68.     x_speed = 0x7e007b,
  69.     x_subspeed = 0x7e007a,
  70.     y_speed = 0x7e007d,
  71.     direction = 0x7e0076,
  72.     is_ducking = 0x7e0073,
  73.     p_meter = 0x7e13e4,
  74.     take_off = 0x7e149f,
  75.     powerup = 0x7e0019,
  76.     cape_spin = 0x7e14a6,
  77.     cape_fall = 0x7e14a5,
  78.     flight_animation = 0x7e1407,
  79.     diving_status = 0x7e1409,
  80.     player_in_air = 0x7e0071,
  81.     climbing_status = 0x7e0074,
  82.     spinjump_flag = 0x7e140d,
  83.     player_blocked_status = 0x7e0077,
  84.     player_item = 0x7e0dc2, --hex
  85.     cape_x = 0x7e13e9,
  86.     cape_y = 0x7e13eb,
  87.     on_ground = 0x7e13ef,
  88.     can_jump_from_water = 0x7e13fa,
  89.     carrying_item = 0x7e148f,
  90.     mario_score = 0x7e0f34,
  91.    
  92.     -- Yoshi
  93.     yoshi_riding_flag = 0x7e187a,  -- #$00 = No, #$01 = Yes, #$02 = Yes, and turning around.
  94.    
  95.     -- Timer
  96.     --keep_mode_active = 0x7e0db1,
  97.     score_incrementing = 0x7e13d6,
  98.     end_level_timer = 0x7e1493,
  99.     multicoin_block_timer = 0x7e186b,
  100.     gray_pow_timer = 0x7e14ae,
  101.     blue_pow_timer = 0x7e14ad,
  102.     dircoin_timer = 0x7e190c,
  103.     pballoon_timer = 0x7e1891,
  104.     star_timer = 0x7e1490,
  105.     animation_timer = 0x7e1496,--
  106.     invisibility_timer = 0x7e1497,
  107.     fireflower_timer = 0x7e149b,
  108.     yoshi_timer = 0x7e18e8,
  109. }
  110.  
  111. -- ************
  112. -- COMPATIBILITY
  113.  
  114. memory.readsbyte = memory.readbytesigned
  115. memory.readsword = memory.readwordsigned
  116. local Prev_mode = nil  -- necessary, because only gui.register gets the correct RAM addresses without 1 frame delay
  117.  
  118. -- ************
  119.  
  120. local function get_game_mode()
  121.     return memory.readbyte(RAM.game_mode)
  122. end
  123.  
  124. local function player()
  125.     -- Read RAM
  126.     local x = memory.readsword(RAM.x)
  127.     local y = memory.readsword(RAM.y)
  128.     local x_speed = memory.readsbyte(RAM.x_speed)
  129.     local x_sub = memory.readbyte(RAM.x_sub)
  130.     local is_ducking = memory.readbyte(RAM.is_ducking)
  131.     local powerup = memory.readbyte(RAM.powerup)
  132.     local yoshi_riding_flag = memory.readbyte(RAM.yoshi_riding_flag)
  133.    
  134.     x_sub = math.floor(x_sub/0x10)
  135.    
  136.     -- Computes direction
  137.     local direction
  138.     if x_speed >= 0 then
  139.         direction = 1
  140.     else
  141.         direction = 0
  142.     end
  143.    
  144.     -- Computes hitbox size
  145.     local is_small = is_ducking ~= 0 or powerup == 0
  146.     local on_yoshi = yoshi_riding_flag ~= 0
  147.     local hitbox_size
  148.     if is_small and not on_yoshi then
  149.         hitbox_size = 0
  150.     elseif not is_small and not on_yoshi then
  151.         hitbox_size = 1
  152.     elseif is_small and on_yoshi then
  153.         hitbox_size = 2
  154.     else
  155.         hitbox_size = 3
  156.     end
  157.    
  158.     return x, x_sub, y, direction, hitbox_size
  159. end
  160.  
  161. local function dump_info_level(room_index)
  162.     local frame = emu.framecount() + 1
  163.     local mode = get_game_mode()
  164.     local real_frame = memory.readbyte(RAM.real_frame)
  165.     if mode == SMW.game_mode_level then
  166.         x, sub_x, y, direction, hitbox_size = player()
  167.     else
  168.         x, sub_x, y, direction, hitbox_size = 0, 0, 0, 0, 0
  169.     end
  170.    
  171.     local is_lagged = real_frame == previous_real_frame
  172.     if is_lagged then is_lagged = 1 else is_lagged = 0 end
  173.    
  174.     previous_real_frame = real_frame
  175.    
  176.     local sync = nil
  177.     if mode == 0x14 and Prev_mode == 0x13 then sync = 0x13 end -- Prev_mode, due to delay
  178.     local strline = string.format("%7d %2x %6x %1d %4d %x %4d %d %1d\n",
  179.                             frame, sync or mode, room_index, is_lagged, x, sub_x, y, direction, hitbox_size)
  180.     io.write(strline)
  181.    
  182.     Prev_mode = mode
  183.     return strline
  184. end
  185.  
  186. emu.registerbefore(function()
  187.     if not movie.playing() then gui.text(1, 16, "Put the movie in read-only mode")
  188.     else
  189.         local room_index = bit.lshift(memory.readbyte(RAM.room_index), 16) + bit.lshift(memory.readbyte(RAM.room_index + 1), 8) + memory.readbyte(RAM.room_index + 2)
  190.        
  191.         gui.text(1, 1, "RECORDING GHOST")
  192.         dump_info_level(room_index)
  193.     end
  194. end)
Add Comment
Please, Sign In to add comment