Advertisement
Guest User

Mario Pinball Land Bizhawk 2.3.1 Luascript

a guest
Jun 13th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.69 KB | None | 0 0
  1. local ScriptInfo = {"Super Mario Ball Luascript by Mugg1991",
  2.                     "v0.1",
  3.                     "31th May 2019",}
  4.  
  5. local AddressTable1 = {
  6. [1] = {1,"Lives",0xFFFFE0A0,"IWRAM",0x0,1,true},
  7. [2] = {1,"Score",0xFFFFE0A0,"IWRAM",0x4,4,true},
  8. [3] = {1,"Yellow coins",0xFFFFE0A0,"IWRAM",0x8,4,true},
  9. [4] = {1,"Blue coins",0xFFFFE0A0,"IWRAM",0xC,4,true},
  10. [5] = {1,"Red coins",0xFFFFE0A0,"IWRAM",0x10,4,true},
  11. [6] = {6,"Red coins timer",0xFFFFE0A0,"IWRAM",0x188,4,true},
  12. [7] = {1,"Blue pipe timer",0xFFFFE0A0,"IWRAM",0x1EB,4,true},
  13. [8] = {1,"Stars",0xFFFFE0A0,"IWRAM",0x14,1,true},
  14. [9] = {1,"Keys",0xFFFFE0A0,"IWRAM",0x22,1,true},
  15. [10] = {1,"Item",0xFFFFE0A0,"IWRAM",0x2C,1,true},
  16. [11] = {1,"Room",0xFFFFE0A0,"IWRAM",0x30,1,true},
  17. [12] = {6,"Clock time",0xFFFFE0A0,"IWRAM",0x154,4,true},
  18. [13] = {7,"Time Attack?",0xFFFFE0A0,"IWRAM",0x16C,0,true},
  19. [14] = {1,"Mario Ball size",0xFFFFE0A0,"IWRAM",0x64F6,1,true},
  20. [15] = {1,"Current room transition",0xFFFFE0A0,"IWRAM",0x6540,1,true}, -- D=None, 3=World Select, A=Down(can be death),
  21.                                                                     -- B=Start Credits(in Adventure)/Time Attack Win, 0=UpLeft, 1=Up, 2=UpRight
  22.                                                                     -- There's more but it's room-specific
  23. }
  24.  
  25. local AddressTable2 = {
  26. [1] = {0,"text0",0xFFB0B0B0},  
  27. [2] = {7,"text1",0xFFFFE0A0,"EWRAM",0x38970,0,true}
  28. }
  29.  
  30. local Displays = {
  31.     -- Name, active, col, x, y, width, height, offset of list, edit mode, table, entries shown
  32.     [1]= {"General", false, 0xFFFFE0A0, 40, 40, 168, 66, 0, false, AddressTable1,6}
  33.     --[2]= {"2", false, 0xFFFFB0C0, 40, 40, 168, 66, 0, false, AddressTable2,6}
  34. }
  35.  
  36. local Mouse = {
  37.     X               = 0,
  38.     Y               = 0,
  39.     XBefore         = 0,
  40.     YBefore         = 0,
  41.     clickedFrames   = 0,
  42.     clicked         = false
  43. }
  44.  
  45. local Color = {
  46.     Selected    = 0xB0A0A0A0,
  47.     Normal      = 0xA0303030,
  48.     Grey        = 0xA0C0C0C0
  49. }
  50.  
  51. function text(x, y, text, color, backcolor)
  52.     if backcolor==nil then backcolor=0x00000000 end
  53.     gui.drawText(x, y, text,color,backcolor,10,"Arial")
  54. end
  55.  
  56. function box(x,y,x2,y2)
  57.     gui.drawBox(x,y,x2,y2,0x00000000,0xD0000000)
  58. end
  59.  
  60. function boxNormal(x,y,x2,y2)
  61.     gui.drawBox(x,y,x2,y2,0xFF000000,0xA0000000)
  62. end
  63.  
  64. function boxSelected(x,y,x2,y2)
  65.     gui.drawBox(x,y,x2,y2,0xFF000000,0xA0505050)
  66. end
  67.  
  68. function arrowDown(xpos,ypos,col)
  69.     gui.drawLine(xpos,ypos,xpos+6,ypos,col)
  70.     gui.drawLine(xpos+1,ypos+1,xpos+5,ypos+1,col)
  71.     gui.drawLine(xpos+2,ypos+2,xpos+4,ypos+2,col)
  72.     gui.drawPixel(xpos+3,ypos+3,col)
  73. end
  74.  
  75. function arrowUp(xpos,ypos,col)
  76.     gui.drawLine(xpos,ypos,xpos+6,ypos,col)
  77.     gui.drawLine(xpos+1,ypos-1,xpos+5,ypos-1,col)
  78.     gui.drawLine(xpos+2,ypos-2,xpos+4,ypos-2,col)
  79.     gui.drawPixel(xpos+3,ypos-3,col)
  80. end
  81.  
  82. local totime = function(frames,fps)
  83.     hours = math.floor((frames/fps)/3600)
  84.     mins = math.floor((frames/fps)/60)%60
  85.     secs = math.floor(((frames/fps-mins*60)*100+0.5)/100) %60
  86.     ms = (frames % fps)/60 * 100
  87.     if hours==0 then
  88.         returnvalue = string.format("%02d:%02d.%02d",mins,secs,ms)
  89.     else
  90.         returnvalue = string.format("%02d:%02d:%02d.%02d",hours,mins,secs,ms)
  91.     end
  92.     return returnvalue
  93. end
  94.  
  95. function drawDisplayBox(id,bordercolor,color)
  96.     posx=Displays[id][4]
  97.     posy=Displays[id][5]
  98.     width=Displays[id][6]
  99.     height=Displays[id][7]
  100.    
  101.     if Mouse.clicked then
  102.  
  103.         if Mouse.X > posx and Mouse.X < posx+width and Mouse.Y > posy and Mouse.Y < posy+height then
  104.  
  105.             if Mouse.clickedFrames > 0 then
  106.                 menuscreen=0 -- close menu
  107.                
  108.                 posy = posy + (Mouse.Y-Mouse.YBefore) -- enables mouse drag
  109.                 posx = posx + (Mouse.X-Mouse.XBefore)
  110.  
  111.                 if posy < 0 then posy=0 -- prevents display from going offscreen
  112.                 elseif posy > 159-height then posy=159-height end
  113.                 if posx < 0 then posx=0
  114.                 elseif posx > 239-width then posx=239-width end
  115.            
  116.                 Displays[id][4]=posx
  117.                 Displays[id][5]=posy
  118.             end
  119.         end
  120.     end
  121.     gui.drawBox(posx,posy,posx+width,posy+height,bordercolor,color)
  122.     text(posx+3,posy-1,Displays[id][1],0xFF808080)
  123. end
  124.        
  125. function drawCloseButton(id)
  126.     width=Displays[id][6]
  127.     x=Displays[id][4]
  128.     y=Displays[id][5]
  129.    
  130.     drawButton(x+width-10,y,10,10,"x",Color.Grey,15,function()
  131.         Displays[id][2] = false
  132.     end)
  133. end
  134.  
  135. function drawEditButton(id)
  136.  
  137.     width=Displays[id][6]
  138.     x=Displays[id][4]
  139.     y=Displays[id][5]
  140.     if Displays[id][9] then col=Color.Selected
  141.     else col=Color.Normal end
  142.    
  143.     drawButton(x+width-25,y,12,10,"e",col,15,function()
  144.         Displays[id][9]=not Displays[id][9]
  145.     end)
  146. end
  147.  
  148. function drawButton(posx,posy,width,height,label,color,frequency,clickedfunction)
  149.     if Mouse.X>posx and Mouse.X<posx+width and Mouse.Y>posy and Mouse.Y<posy+height then
  150.             if Mouse.clicked and Mouse.clickedFrames%frequency==1 then  
  151.                 clickedfunction()
  152.             end
  153.         gui.drawBox(posx,posy,posx+width,posy+height,color-0x00303030,color+0x30303030)
  154.     else
  155.         gui.drawBox(posx,posy,posx+width,posy+height,color-0x00303030,color)
  156.     end
  157.     text(posx+1,posy-2,label,0xFFFFFFFF)
  158. end
  159.  
  160. function drawMenuButton(posx,posy,width,height,label,z,drawindicator,indicator,col,clickedfunction)
  161.     if Mouse.X>posx and Mouse.X<posx+width and Mouse.Y>posy and Mouse.Y<posy+height then
  162.         if Mouse.clicked and Mouse.clickedFrames==z then
  163.             menuscreen=0
  164.             clickedfunction()
  165.         end
  166.         boxSelected(posx,posy,posx+width,posy+height)
  167.     else
  168.         boxNormal(posx,posy,posx+width,posy+height)
  169.     end
  170.     text(posx+2,posy-1,label,col)
  171.    
  172.     if drawindicator then
  173.         if indicator then text(posx+width-10,posy,"o",0xFF80FF80)
  174.         else text(posx+width-10,posy-1,"x",0xFFFF9090) end
  175.     end
  176. end
  177.  
  178. local getChangeAmount = function(valueChangeAmount)
  179.     if Mouse.clickedFrames>540 then
  180.         valueChangeAmount=valueChangeAmount*1000000
  181.     elseif Mouse.clickedFrames>450 then
  182.         valueChangeAmount=valueChangeAmount*100000
  183.     elseif Mouse.clickedFrames>360 then
  184.         valueChangeAmount=valueChangeAmount*10000
  185.     elseif Mouse.clickedFrames>270 then
  186.         valueChangeAmount=valueChangeAmount*1000
  187.     elseif Mouse.clickedFrames>180 then
  188.         valueChangeAmount=valueChangeAmount*100
  189.     elseif Mouse.clickedFrames>90 then
  190.         valueChangeAmount=valueChangeAmount*10
  191.     end
  192.     return valueChangeAmount
  193. end
  194.  
  195. local addressTableSetValue = function(address, addressSize, addressEndian, newvalue)
  196.  
  197.     if addressSize==1 then
  198.         memory.write_u8(address,newvalue)
  199.     elseif addressSize==2 then
  200.         if addressEndian then
  201.             memory.write_u16_le(address,newvalue)
  202.         else
  203.             memory.write_u16_be(address,newvalue)
  204.         end            
  205.     elseif addressSize==3 then
  206.         if addressEndian then
  207.             memory.write_u24_le(address,newvalue)
  208.         else
  209.             memory.write_u24_be(address,newvalue)
  210.         end
  211.     elseif addressSize==4 then
  212.         if addressEndian then
  213.             memory.write_u32_le(address,newvalue)
  214.         else
  215.             memory.write_u32_be(address,newvalue)
  216.         end
  217.     end
  218.    
  219. end
  220.  
  221. local addressTableGetValue = function(address, addressSize, addressEndian, addressSigned)
  222.  
  223.     if addressSigned then
  224.         if addressSize==1 then
  225.             value=memory.read_s8(address)
  226.         elseif addressSize==2 then
  227.             if addressEndian then
  228.                 value=memory.read_s16_le(address)
  229.             else
  230.                 value=memory.read_s16_be(address)
  231.             end            
  232.         elseif addressSize==3 then
  233.             if addressEndian then
  234.                 value=memory.read_s24_le(address)
  235.             else
  236.                 value=memory.read_s24_be(address)
  237.             end
  238.         elseif addressSize==4 then
  239.             if addressEndian then
  240.                 value=memory.read_s32_le(address)
  241.             else
  242.                 value=memory.read_s32_be(address)
  243.             end
  244.         end
  245.     else
  246.         if addressSize==1 then
  247.             value=memory.read_u8(address)
  248.         elseif addressSize==2 then
  249.             if addressEndian then
  250.                 value=memory.read_u16_le(address)
  251.             else
  252.                 value=memory.read_u16_be(address)
  253.             end            
  254.         elseif addressSize==3 then
  255.             if addressEndian then
  256.                 value=memory.read_u24_le(address)
  257.             else
  258.                 value=memory.read_u24_be(address)
  259.             end
  260.         elseif addressSize==4 then
  261.             if addressEndian then
  262.                 value=memory.read_u32_le(address)
  263.             else
  264.                 value=memory.read_u32_be(address)
  265.             end
  266.         end
  267.     end
  268.    
  269.     return value   
  270. end
  271.  
  272. local DisplayAddressTable = function(display_id, has_arrows,  has_buttons,  display_description,  description_offset,  arrows_offset,  buttons_offset)
  273.    
  274.     inputTable=Displays[display_id][10]
  275.     xpos=Displays[display_id][4]
  276.     ypos=Displays[display_id][5]
  277.     memorydomainBefore=memory.getcurrentmemorydomain()
  278.     tableSize=table.getn(inputTable)
  279.     table_start=1
  280.     table_end=Displays[display_id][11]
  281.     table_iterations = 1
  282.     offset=Displays[display_id][8]
  283.     list_height = 8*(table_end - table_start)+14
  284.  
  285.     --display arrows:
  286.     if has_arrows then
  287.         --bottom arrow button
  288.         if (tableSize - offset) > table_end then
  289.             if Mouse.X>xpos+arrows_offset and Mouse.X<xpos+arrows_offset+12 and Mouse.Y>ypos+list_height and Mouse.Y<ypos+list_height+6 then
  290.                 if Mouse.clicked then
  291.                     Displays[display_id][8]=offset+1
  292.                 end
  293.                 arrowDown(xpos+arrows_offset+2,ypos+list_height,0xFFFFFFFF)
  294.             else
  295.                 arrowDown(xpos+arrows_offset+2,ypos+list_height,0xA0FFFFFF)
  296.             end
  297.         else
  298.             if offset < 0 then
  299.                 Displays[display_id][8]=0
  300.             end
  301.         end
  302.            
  303.         --top arrow button
  304.         if offset > 0 then
  305.             if Mouse.X>xpos+arrows_offset and Mouse.X<xpos+arrows_offset+12 and Mouse.Y>ypos+list_height-10 and Mouse.Y<ypos+list_height-4 then
  306.                 if Mouse.clicked then
  307.                     Displays[display_id][8]=offset-1
  308.                 end
  309.                 arrowUp(xpos+arrows_offset+2,ypos+list_height-6,0xFFFFFFFF)
  310.             else
  311.                 arrowUp(xpos+arrows_offset+2,ypos+list_height-6,0xA0FFFFFF)
  312.             end
  313.         end
  314.     end
  315.     -- applying display offset
  316.     table_start = table_start + offset
  317.     table_end   = table_end + offset
  318.  
  319.     -- going through the table
  320.     for i=table_start,table_end do --show a part of the list
  321.  
  322.         contenttype=inputTable[i][1]
  323.         description=inputTable[i][2]
  324.         textColor=inputTable[i][3]
  325.         memorydomain=inputTable[i][4]
  326.        
  327.         if contenttype==0 then  -- TITLE
  328.                
  329.             gui.drawBox(5+xpos,4+ypos+table_iterations*8,arrows_offset+xpos,12+ypos+table_iterations*8,0x00000000,0xFF505050)
  330.    
  331.         elseif contenttype==7 then -- BINARY
  332.            
  333.             memory.usememorydomain(memorydomain)
  334.             address=inputTable[i][5]
  335.             currentbit=inputTable[i][6]
  336.             value=memory.read_u8(address)
  337.  
  338.             value=bit.check(value, currentbit)
  339.            
  340.             if value then
  341.                 value="Yes"
  342.                 valueColor=0xFF80FF80
  343.             else
  344.                 value="No"
  345.                 valueColor=0xFFFF9090
  346.             end
  347.            
  348.             text(5+xpos,3+ypos+table_iterations*8,value,valueColor)
  349.        
  350.         else    -- OTHER TYPES 
  351.             memory.usememorydomain(memorydomain)
  352.             address=inputTable[i][5]
  353.             addressSize=inputTable[i][6]
  354.             addressEndian=inputTable[i][7] -- true:little endian, false:big endian
  355.             addressSigned=inputTable[i][8]
  356.             valueChangeAmount=1                  
  357.             value = addressTableGetValue(address,addressSize,addressEndian, addressSigned)
  358.            
  359.             if contenttype==6 then  -- show value as timer (framecount --> clock time)
  360.                 text(5+xpos,3+ypos+table_iterations*8,totime(value,60), textColor) 
  361.             else
  362.                 text(5+xpos,3+ypos+table_iterations*8,value, textColor)
  363.             end
  364.            
  365.         end
  366.        
  367.         if display_description then
  368.             text(xpos+description_offset,3+ypos+table_iterations*8,description, textColor)
  369.         end
  370.  
  371.         if has_buttons then
  372.            
  373.             if contenttype==7 then -- binary
  374.            
  375.                 drawButton(xpos+buttons_offset,4+ypos+table_iterations*8,21,8,"Set",Color.Normal,8,function()
  376.    
  377.                     currentvalue=memory.read_u8(address)
  378.  
  379.                     if bit.check(currentvalue,currentbit) then
  380.                         memory.write_u8(address, bit.clear(currentvalue,currentbit))
  381.                     else
  382.                         memory.write_u8(address, bit.set(currentvalue,currentbit)) 
  383.                     end
  384.                
  385.                 end)
  386.            
  387.             elseif contenttype~=0 then -- normal values
  388.            
  389.                 drawButton(xpos+buttons_offset,4+ypos+table_iterations*8,9,8,"-",Color.Normal,5,function()
  390.                     valueChangeAmount = getChangeAmount(valueChangeAmount) -- increases when holding mouse key 
  391.                     newvalue = value - valueChangeAmount
  392.                     addressTableSetValue(address,addressSize,addressEndian,newvalue)                   
  393.                 end)
  394.  
  395.                 drawButton(12+xpos+buttons_offset,4+ypos+table_iterations*8,9,8,"+",Color.Normal,5,function()
  396.                     valueChangeAmount = getChangeAmount(valueChangeAmount) -- increases when holding mouse key         
  397.                     newvalue = value + valueChangeAmount
  398.                     addressTableSetValue(address,addressSize,addressEndian,newvalue)               
  399.                 end)
  400.             end        
  401.         end
  402.         table_iterations=table_iterations+1
  403.     end
  404.     memory.usememorydomain(memorydomainBefore)
  405. end
  406.    
  407. local drawDisplay = function(id)
  408.     if Displays[id][4]~=nil then
  409.         drawDisplayBox(id, 0xFF202020,0xA0000000)
  410.         drawCloseButton(id)
  411.         drawEditButton(id)
  412.         if Displays[id][9] then
  413.             DisplayAddressTable(id,true,true,true,76,158,52)   
  414.         else
  415.             DisplayAddressTable(id,true,false,true,56,158,0)
  416.         end
  417.     end
  418. end
  419.  
  420. local Menu = {
  421.     [1] =       {   [0] = "Script",
  422.                     [1] = 1
  423.                     --[2] = 2
  424.                 }
  425. }
  426.  
  427. local drawMenu = function()
  428.  
  429.     verticalOffset=0
  430.  
  431.     for a=1,table.getn(Menu),1 do
  432.         drawMenuButton(-38+a*45,18,40,11,Menu[a][0],2,false,true,0xFFFFFFFF,function()
  433.             menuscreen=a
  434.         end)   
  435.        
  436.         if menuscreen==a then
  437.            
  438.             for b=1,table.getn(Menu[a]),1 do
  439.            
  440.                 id              = Menu[a][b]
  441.                 title           = Displays[id][1]
  442.                 indicator       = Displays[id][2]
  443.                 col             = Displays[id][3]
  444.                
  445.                 drawMenuButton(7,32+verticalOffset*10,72,10,title,1,true,indicator,col,function()
  446.                     Displays[id][2] = not indicator
  447.                 end)           
  448.                
  449.                 verticalOffset=verticalOffset+1
  450.             end        
  451.         end
  452.     end
  453.    
  454.     if Mouse.clicked and Mouse.clickedFrames==1 then
  455.            menuscreen = 0
  456.     end
  457. end
  458.  
  459. event.onloadstate(function()
  460.  
  461. end)
  462.  
  463. menuscreen=0
  464. frames=0
  465. console.clear()
  466. for i=1,table.getn(ScriptInfo),1 do
  467.     print(ScriptInfo[i])
  468. end
  469.  
  470. while true do
  471.  
  472.     Mouse.X = input.getmouse().X
  473.     Mouse.Y = input.getmouse().Y
  474.     Mouse.clicked = input.getmouse().Left
  475.    
  476.    
  477.     for i=1,table.getn(Displays) do -- all displays
  478.         if Displays[i][2] then
  479.             drawDisplay(i)
  480.         end
  481.     end
  482.  
  483.     drawMenu() -- menu
  484.  
  485.     Mouse.XBefore=Mouse.X
  486.     Mouse.YBefore=Mouse.Y
  487.     if Mouse.clicked then Mouse.clickedFrames = Mouse.clickedFrames + 1
  488.     else Mouse.clickedFrames = 0 end
  489.    
  490.    if client.ispaused() then
  491.         gui.DrawFinish()
  492.         emu.yield()
  493.     else
  494.         emu.frameadvance()
  495.     end
  496.    
  497.     frames=frames+1
  498. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement