-- Puts text on-screen (duh) function text ( x , y , str ) if str == nil then str = " nil" end ; if ( x >= 0 and x <= 255 and y >= 0 and y <= 240 ) then gui . text ( x , y , str ) end end -- Draws a rectangle from x1,y1 to x2, y2 function box ( x1 , y1 , x2 , y2 , color ) if ( x1 >= 0 and x1 <= 255 and x2 >= 0 and x2 <= 255 and y1 >= 0 and y1 <= 244 and y2 >= 0 and y2 <= 244 ) then --[[ local success = pcall(function() gui.drawbox(x1,y1,x2,y2,color); end); if not success then text(60, 150, string.format("%3d %3d %3d %3d", x1, y1, x2, y2)); FCEU.pause(); end; ]] gui . drawbox ( x1 , y1 , x2 , y2 , color ) end end -- Bisqwit's clone table feature. table . clone = function ( table ) local res = {} for k , v in pairs ( table ) do res [ k ] = v end return res end last = {}; inpt = { xmouse = 0 , ymouse = 0 }; function input . update () last = table . clone ( inpt ) inpt = input . get () end objectMap = {} objectMap [ 0 ] = " Player" objectMap [ 1 ] = " Magnet" objectMap [ 3 ] = " Mutant Dragonfly" objectMap [ 4 ] = " Splash" objectMap [ 5 ] = " Magnet Control Box" objectMap [ 7 ] = " Submarine" objectMap [ 8 ] = " Bomb" objectMap [ 11 ] = " Monster Shark" objectMap [ 12 ] = " Torpedo" objectMap [ 13 ] = " Bubble" objectMap [ 14 ] = " Trap Door" objectMap [ 18 ] = " Cable Cutting Scissors" objectMap [ 26 ] = " Dragonfly Box" objectMap [ 36 ] = " Death Glow" objectMap [ 46 ] = " Radium Plated Boots" objectMap [ 72 ] = " Cosmic Caterpillar" objectMap [ 75 ] = " Caterpillar Ball" function readObjectTable () local objects = {} for i = 0 , 15 do local object = {} object . sprite = memory . readbyte ( 0x0548 + i ) object . x = memory . readbyte ( 0x0558 + i ) object . y = memory . readbyte ( 0x0568 + i ) object . direction = memory . readbyte ( 0x0578 + i ) object . type = memory . readbyte ( 0x0588 + i ) object . offscreen = memory . readbyte ( 0x0598 + i ) object . state = memory . readbyte ( 0x05A8 + i ) object . height = memory . readbyte ( 0x05B8 + i ) object . width = memory . readbyte ( 0x05C8 + i ) table.insert ( objects , object ) end return objects end function drawObjects ( objectTable ) for i , object in ipairs ( objectTable ) do if object . type ~= 0xFF and object . offscreen == 0 then local name = " " if objectMap [ object . type ] ~= nil then name = objectMap [ object . type ] else name = string.format ( " %02X" , object . type ) end text ( 0 , 10 * i - 3 , i - 1 .. " : " .. name ) local x1 , y1 , x2 , y2 = getBoundingBox ( object ) box ( x1 , y1 , x2 , y2 , " #FF0000" ) end end end function getBoundingBox ( object ) local y = object . y if object . type == 0 then -- player if object . sprite ~= 1 then -- crouch y = y - 7 end end return object . x - object . width , y - ( object . height / 2 ), object . x + object . width , y + ( object . height / 2 ) end function getOverObjectNumber ( objectTable , x , y ) for i , object in ipairs ( objectTable ) do if object . type ~= 0xFF and object . offscreen == 0 then local x1 , y1 , x2 , y2 = getBoundingBox ( object ) if x >= x1 and x <= x2 and y >= y1 and y <= y2 then return i - 1 end end end end function updateCarry () if carrying == nil then if inpt . leftclick and not last . leftclick then carrying = getOverObjectNumber ( objectTable , inpt . xmouse , inpt . ymouse ) end text ( 0 , 0 , " " ) --Else last message lingers else if ( inpt . leftclick and not last . leftclick ) or ( memory . readbyte ( 0x0588 + carrying ) == 0xFF ) then carrying = nil else text ( 100 , 8 , " Carrying object " .. carrying ) memory . writebyte ( 0x0558 + carrying , inpt . xmouse ) memory . writebyte ( 0x0568 + carrying , inpt . ymouse ) end end end while true do objectTable = readObjectTable () --drawObjects(objectTable) input . update () updateCarry () FCEU . frameadvance () end