Advertisement
Guest User

savegame incomplete script mario luigi superstar saga bizhaw

a guest
Oct 3rd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.75 KB | None | 0 0
  1. ------ Settings Table ------
  2. local Settings = {
  3.     ["SavegamesX"]=60,
  4.     ["SavegamesY"]=60,
  5.     ["MyFont"]=2,
  6.     ["PaddingTop"]=0,
  7.     ["PaddingBottom"]=0
  8. }
  9.  
  10. ----- Misc Settings -----
  11. local clickedFrames = 0
  12. local clicked=false
  13. local X=0
  14. local Y=0
  15. local XBefore=0
  16. local YBefore=0
  17.  
  18.  
  19. ------ Extra Padding --------
  20. local PaddingLeft=0
  21. local PaddingRight=0
  22. local PaddingTop=0
  23. local PaddingBottom=0
  24.  
  25. local PaddingTopSetting=0 -- in "Add Space", before actually adding it to PaddingTop/Bottom
  26. local PaddingBottomSetting=0
  27.  
  28. ------ Read only stuff ------
  29. local FontTable = {{8,"SF Intermosaic B"},
  30.                    {10,"Arial"},
  31.                    {9,"MS Reference Sans Serif"},
  32.                    {9,"Square721 BT"},
  33.                    {9,"Century Gothic"}}  
  34. local ColorButtonSelected = 0xB0A0A0A0
  35. local ColorButtonNormal = 0xA0303030
  36.  
  37. ------ Game Version ------
  38. local GameVersion=0
  39. local GameVersionText=""
  40. if gameinfo.getromhash()=="7C303CDDE5061EE329296948060B875CB50BA410" then
  41.     GameVersion=1 -- usa
  42.     GameVersionText="USA"
  43. elseif gameinfo.getromhash()=="EDC538AC505BFCD337ABDD03B3A6F2744D81EAAB" then
  44.     GameVersion=2 -- jp
  45.     GameVersionText="Japan"
  46. elseif gameinfo.getromhash()=="FA2314C2FBE0DB1AB17175F8BE7CCEB0AB084EFC" then
  47.     GameVersion=3 -- eu
  48.     GameVersionText="Europe"
  49. else
  50.     GameVersion=4
  51.     GameVersionText="Game not recognized"
  52. end
  53.  
  54.  
  55. local Region=0
  56. if GameVersion==1 or GameVersion==3 then
  57.     Region=1 -- english
  58. elseif GameVersion==2 then
  59.     Region=2 --jp
  60. else Region=3 end  --not M+L
  61.  
  62.  
  63. local toboolean = function(string)
  64.     if string=="true" then
  65.         string=true
  66.     elseif string=="false" then
  67.         string=false
  68.     else
  69.         string=nil
  70.     end
  71.    
  72.     return string
  73. end
  74.  
  75. function text(x, y, text, color, backcolor)
  76.     if backcolor==nil then backcolor=0x00000000 end
  77.     gui.drawText(x, y, text,color,backcolor,FontTable[ Settings["MyFont"] ][1],FontTable[ Settings["MyFont"] ][2])
  78. end
  79.  
  80.  
  81. function box(x,y,x2,y2)
  82.     gui.drawBox(x,y,x2,y2,0x00000000,0xD0000000)
  83. end
  84.  
  85. function boxNormal(x,y,x2,y2)
  86.     gui.drawBox(x,y,x2,y2,0xFF000000,0xA0000000)
  87. end
  88.  
  89. function boxSelected(x,y,x2,y2)
  90.     gui.drawBox(x,y,x2,y2,0xFF000000,0xA0505050)
  91. end
  92.  
  93. function img(path,x,y)
  94.     gui.drawImage(path,x,y)
  95. end
  96.  
  97. function arrowDown(xpos,ypos,col)
  98.     gui.drawLine(xpos,ypos,xpos+6,ypos,col)
  99.     gui.drawLine(xpos+1,ypos+1,xpos+5,ypos+1,col)
  100.     gui.drawLine(xpos+2,ypos+2,xpos+4,ypos+2,col)
  101.     gui.drawPixel(xpos+3,ypos+3,col)
  102. end
  103.  
  104. function arrowUp(xpos,ypos,col)
  105.     gui.drawLine(xpos,ypos,xpos+6,ypos,col)
  106.     gui.drawLine(xpos+1,ypos-1,xpos+5,ypos-1,col)
  107.     gui.drawLine(xpos+2,ypos-2,xpos+4,ypos-2,col)
  108.     gui.drawPixel(xpos+3,ypos-3,col)
  109. end
  110.  
  111. function drawDisplayBox(posx,posy,width,height,bordercolor,color,colorchangesonhover,clickedfunction)
  112.  
  113.     if colorchangesonhover then
  114.  
  115.         if X > posx and X < posx+width and Y > posy and Y < posy+height then
  116.    
  117.             if clicked and clickedFrames > 0 then
  118.                 menuscreen=0 -- close menu
  119.                 clickedfunction() -- custom function passed in the parameter
  120.             end
  121.        
  122.             gui.drawBox(posx,posy,posx+width,posy+height,bordercolor,color-0x30000000)
  123.         else
  124.             gui.drawBox(posx,posy,posx+width,posy+height,bordercolor,color)
  125.         end
  126.     else
  127.         if X > posx and X < posx+width and Y > posy and Y < posy+height then
  128.    
  129.             if clicked and clickedFrames > 0 then
  130.                 menuscreen=0 -- close menu
  131.                 clickedfunction() -- custom function passed in the parameter
  132.             end
  133.  
  134.         end
  135.        
  136.             gui.drawBox(posx,posy,posx+width,posy+height,bordercolor,color)
  137.        
  138.     end
  139.    
  140. end
  141.  
  142.                         --posx,posy,width of the container                     
  143. function drawCloseButton(posx,posy,width,clickedfunction)
  144.    
  145.     if X>posx+width-10 and X<posx+width and Y>posy and Y<posy+10 then
  146.    
  147.         if clicked and clickedFrames==1 then
  148.             clickedfunction()
  149.         end
  150.         gui.drawBox(posx+width-10,posy,posx+width,posy+10,0xFF000000,0xA0C0C0C0)
  151.     else
  152.         gui.drawBox(posx+width-10,posy,posx+width,posy+10,0xFF000000,0xA0A0A0A0)
  153.     end
  154.    
  155.     text(posx+width-8,posy-(FontTable[ Settings["MyFont"] ][1]-8),"x",0xFFFFFFFF)
  156.    
  157. end
  158.  
  159.  
  160. function drawButton(posx,posy,width,height,label,color,frequency,clickedfunction)
  161.    
  162.     if X>posx and X<posx+width and Y>posy and Y<posy+height then
  163.    
  164.         if clicked and clickedFrames%frequency==1 then
  165.             clickedfunction()
  166.         end
  167.         gui.drawBox(posx,posy,posx+width,posy+height,color-0x00303030,color+0x30303030)
  168.     else
  169.         gui.drawBox(posx,posy,posx+width,posy+height,color-0x00303030,color)
  170.     end
  171.    
  172.     text(posx+2,posy-(FontTable[ Settings["MyFont"] ][1]-8),label,0xFFFFFFFF)
  173.    
  174. end
  175.  
  176.  
  177. local drawEditSavegames = function()
  178.  
  179.     memory.usememorydomain("EWRAM")
  180.     SavegamesX=Settings["SavegamesX"]
  181.     SavegamesY=Settings["SavegamesY"]
  182.     width=150
  183.     height=94
  184.  
  185.     drawDisplayBox(SavegamesX,SavegamesY,width,height,0xFF202020,0xA0000000,false, function()
  186.  
  187.             --what happens if clicked on:
  188.             SavegamesY = SavegamesY + (Y-YBefore) --enables mouse drag
  189.             SavegamesX = SavegamesX + (X-XBefore)
  190.  
  191.             if SavegamesY < 0 then SavegamesY=0 --prevents display from going offscreen
  192.             elseif SavegamesY > 159-height+PaddingTop+PaddingBottom then SavegamesY=159-height+PaddingTop+PaddingBottom end
  193.             if SavegamesX < 0 then SavegamesX=0
  194.             elseif SavegamesX > 239-width+PaddingLeft+PaddingRight then SavegamesX=239-width+PaddingLeft+PaddingRight end
  195.            
  196.             Settings["SavegamesY"]=SavegamesY
  197.             Settings["SavegamesX"]=SavegamesX
  198.     end)
  199.  
  200. -- slots in use
  201.     text(3+SavegamesX,12+SavegamesY,"slots in use:",0xFFFFFFFF)
  202.    
  203.     if bit.check(memory.read_u8(0x001e7e),0) then
  204.         text(83+SavegamesX,12+SavegamesY, "1", 0xFFFFFF00)
  205.     else
  206.         text(83+SavegamesX,12+SavegamesY, "1", 0x5FFFFFFF) 
  207.     end
  208.    
  209.     if bit.check(memory.read_u8(0x001e7e),1) then
  210.         text(90+SavegamesX,12+SavegamesY, "2", 0xFFFFFF00)
  211.     else
  212.         text(90+SavegamesX,12+SavegamesY, "2", 0x5FFFFFFF) 
  213.     end
  214.    
  215.     if bit.check(memory.read_u8(0x001e7e),2) then
  216.         text(97+SavegamesX,12+SavegamesY, "3", 0xFFFFFF00)
  217.     else
  218.         text(97+SavegamesX,12+SavegamesY, "3", 0x5FFFFFFF) 
  219.     end
  220.  
  221. -- current slot
  222.  
  223.     memory.usememorydomain("IWRAM")
  224.  
  225.     if bit.check(memory.read_u8(0x0d40),2) then
  226.         currentslot=2
  227.     elseif bit.check(memory.read_u8(0x0d40),3) then
  228.         currentslot=3
  229.     else
  230.         currentslot=1
  231.     end
  232.    
  233.     text(3+SavegamesX,22+SavegamesY,"current slot: ".. currentslot,0xFFFFFFFF)
  234.    
  235.     memory.usememorydomain("EWRAM")
  236.    
  237. -- copy 1 to 2
  238.     drawButton(SavegamesX+26,SavegamesY+34,70,10,"copy 1 to 2",ColorButtonNormal,20,function()
  239.        
  240.         --write values
  241.         for i=0,1783,1 do
  242.             memory.write_u8(0x002580+i, memory.read_u8(0x001e88+i) )
  243.         end    
  244.        
  245.         --set "slots in use" flag
  246.         if not bit.check(memory.read_u8(0x001e7e),1) then
  247.             memory.write_u8(   0x001e7e, bit.set(memory.read_u8(0x001e7e),1)   )
  248.         end
  249.        
  250.         editedMemory=true
  251.    
  252.     end)
  253.    
  254. -- copy 1 to 3
  255.     drawButton(SavegamesX+26,SavegamesY+46,70,10,"copy 1 to 3",ColorButtonNormal,20,function()
  256.        
  257.         --write values
  258.         for i=0,1783,1 do
  259.             memory.write_u8(0x002c78+i, memory.read_u8(0x001e88+i) )
  260.         end    
  261.        
  262.         --set "slots in use" flag
  263.         if not bit.check(memory.read_u8(0x001e7e),2) then
  264.             memory.write_u8(   0x001e7e, bit.set(memory.read_u8(0x001e7e),2)   )
  265.         end
  266.        
  267.         editedMemory=true
  268.    
  269.     end)
  270.  
  271.  
  272. -- close button
  273.     drawCloseButton(SavegamesX,SavegamesY,width,function()
  274.    
  275.         Settings["BoolEditSavegames"]=false
  276.         if Settings["BoolNotifications"] then print("Edit Savegames Display has been closed.") end
  277.    
  278.     end)
  279.  
  280.  
  281. -- other text:
  282.     text(3+SavegamesX,SavegamesY,"Edit Savegames",0xFF808080)
  283.     text(3+SavegamesX,58+SavegamesY,"sry, can't finish as long\nas I don't understand\nchecksums...",0xFFFF8020)
  284.  
  285. end
  286.  
  287.  
  288.  
  289. client.setwindowsize(2)
  290.  
  291. while true do
  292.  
  293.     memory.usememorydomain("EWRAM")
  294.  
  295.     X = input.getmouse().X + PaddingLeft
  296.     Y = input.getmouse().Y + PaddingTop
  297.     clicked = input.getmouse().Left
  298.    
  299.     if clicked then clickedFrames = clickedFrames + 1
  300.     else clickedFrames = 0 end
  301.  
  302.     drawEditSavegames()
  303.  
  304.     XBefore=X
  305.     YBefore=Y
  306.    
  307.     emu.frameadvance()
  308.  
  309.     clicked=false
  310.  
  311. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement