Advertisement
Elipsis

Marble Madness Camera Hack (Lua Script)

Aug 26th, 2020
2,711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.45 KB | None | 0 0
  1. --Marble Madness camhack script for Aglar's run.
  2. --Script by TheAxeMan
  3. --
  4. --I usually put the rewind code in a separate module but combined it here for distribution.
  5. --
  6. --This module is designed to provide "frame rewind" where
  7. --holding down R and pressing frame advance once will bring
  8. --you back one frame. You should be able to pick up from
  9. --there with no trouble.
  10.  
  11. messagesToDisplay = {}
  12. dispCount = 0
  13. newframe = false
  14.  
  15. gui.register(
  16. function()
  17.   dispCount = dispCount+1
  18.   for i,m in pairs(messagesToDisplay) do
  19.     gui.text(m.x, m.y, m.text)
  20.   end;
  21.   newframe = false
  22. end
  23. )
  24.  
  25. local function addMessage(x, y, text)
  26.   table.insert(messagesToDisplay, {x=x, y=y, text=text})
  27. end;
  28. local function clearMessages()
  29.   messagesToDisplay = {}
  30. end;
  31.  
  32. local function readRewindButton()
  33.   keysPressed = input.get()
  34.   return keysPressed["R"];
  35. end;
  36.  
  37.  
  38. rewindSaveStateBuffer = {}
  39. rewindInputBuffer = {}
  40. rewindBufferDepth = 0
  41. rewindLastFramecount = movie.framecount()
  42. --This gets set to "rewind" when rewinding
  43. rewindLastFrameAction = "advance"
  44.  
  45.  
  46. function manageRewind()
  47.   if readRewindButton() then
  48.     if rewindBufferDepth > 2 then
  49.       addMessage(10,10, "rewinding")
  50.       local loadIndex = movie.framecount()-2
  51.       savestate.load(rewindSaveStateBuffer[loadIndex])
  52.       joypad.set(1, rewindInputBuffer[loadIndex+1])
  53.       rewindBufferDepth = rewindBufferDepth-1
  54.       --FCEU.frameadvance()
  55.       --clearMessages()
  56.       --newframe=true
  57.     elseif rewindBufferDepth <= 2 then
  58.       local loadIndex = movie.framecount()-1
  59.       savestate.load(rewindSaveStateBuffer[loadIndex])
  60.       --joypad.set(1, rewindInputBuffer[loadIndex])
  61.       addMessage(10,10, "end of buffer")
  62.     end;
  63.   else
  64.     --Add to buffer
  65.     local bufferIndex = movie.framecount()
  66.     if rewindSaveStateBuffer[bufferIndex] == nil then
  67.       rewindSaveStateBuffer[bufferIndex] = savestate.create()
  68.     end;
  69.     savestate.save(rewindSaveStateBuffer[bufferIndex])
  70.     rewindInputBuffer[bufferIndex] = joypad.read(1)
  71.     rewindBufferDepth = rewindBufferDepth + 1
  72.  
  73.   end;
  74.   addMessage(10,20, "Buffer depth is "..rewindBufferDepth)
  75.  
  76. end;
  77.  
  78.  
  79. function frameAdvanceWithRewind()
  80.   FCEU.frameadvance()
  81.   manageRewind();
  82.   clearMessages()
  83.   newframe=true
  84. end;
  85. function pauseWithRewind()
  86.   FCEU.pause()
  87.   manageRewind();
  88. end;
  89.  
  90. FCEU.pause()
  91.  
  92. while true do
  93.   --Aggressively move screen down
  94.   scrollpos = 50
  95.   --Be less aggressive at beginning of intermediate race
  96.   if movie.framecount() > 3050 and movie.framecount() < 3480 then scrollpos=100 end;
  97.   --Don't do this during part of aerial race
  98.   if movie.framecount() > 5100 and movie.framecount() < 5460 then scrollpos=300 end;
  99.   --if movie.framecount() > 5100 and movie.framecount() < 6000 then scrollpos=300 end;
  100.   --In the Silly race everything you know is wrong
  101.   if movie.framecount() > 6500 and movie.framecount() < 7800 then scrollpos = 300 end;
  102.   --Disable during Ultimate race to avoid desync
  103.   if movie.framecount() > 8400 then scrollpos=300 end;
  104.  
  105.   relpos = memory.readbyte(0x0450)
  106.   if relpos > scrollpos then
  107.     memory.writebyte(0x0450, 155)
  108.   end;
  109.  
  110.   --Special aerial fix
  111.   if movie.framecount() == 5500 then
  112.     memory.writebyte(0x00A0, 0x33)
  113.   end;
  114.  
  115.   --In the Silly race everything you know is wrong
  116.   if movie.framecount() > 6500 and movie.framecount() < 7800 then
  117.       --This forces screen to just keep scrolling.
  118.       memory.writebyte(0x0458, 127)
  119.   end;
  120.    
  121.   frameAdvanceWithRewind()
  122. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement