Advertisement
Guest User

savegame incomplete script mario luigi superstar saga bizhaw

a guest
Oct 5th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.65 KB | None | 0 0
  1. ------ Settings Table ------
  2. local Settings = {
  3. ["SavegamesX"]=60,
  4. ["SavegamesY"]=20,
  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. local drawEditSavegames = function()
  177.  
  178. memory.usememorydomain("EWRAM")
  179. SavegamesX=Settings["SavegamesX"]
  180. SavegamesY=Settings["SavegamesY"]
  181. width=170
  182. height=115
  183.  
  184. drawDisplayBox(SavegamesX,SavegamesY,width,height,0xFF202020,0xA0000000,false, function()
  185.  
  186. --what happens if clicked on:
  187.  
  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.  
  199. end)
  200.  
  201. -- slots in use
  202. text(3+SavegamesX,12+SavegamesY,"slots in use:",0xFFFFFFFF)
  203.  
  204. if bit.check(memory.read_u8(0x001e7e),0) then
  205. text(83+SavegamesX,12+SavegamesY, "1", 0xFFFFFF00)
  206. else
  207. text(83+SavegamesX,12+SavegamesY, "1", 0x5FFFFFFF)
  208. end
  209.  
  210. if bit.check(memory.read_u8(0x001e7e),1) then
  211. text(90+SavegamesX,12+SavegamesY, "2", 0xFFFFFF00)
  212. else
  213. text(90+SavegamesX,12+SavegamesY, "2", 0x5FFFFFFF)
  214. end
  215.  
  216. if bit.check(memory.read_u8(0x001e7e),2) then
  217. text(97+SavegamesX,12+SavegamesY, "3", 0xFFFFFF00)
  218. else
  219. text(97+SavegamesX,12+SavegamesY, "3", 0x5FFFFFFF)
  220. end
  221.  
  222.  
  223. t=""
  224. if bit.check(memory.read_u8(0x001e7e),7) then
  225. t=t.."1"
  226. else
  227. t=t.."0"
  228. end
  229.  
  230. if bit.check(memory.read_u8(0x001e7e),6) then
  231. t=t.."1"
  232. else
  233. t=t.."0"
  234. end
  235.  
  236. if bit.check(memory.read_u8(0x001e7e),5) then
  237. t=t.."1"
  238. else
  239. t=t.."0"
  240. end
  241.  
  242. if bit.check(memory.read_u8(0x001e7e),4) then
  243. t=t.."1 "
  244. else
  245. t=t.."0 "
  246. end
  247.  
  248. if bit.check(memory.read_u8(0x001e7e),3) then
  249. t=t.."1"
  250. else
  251. t=t.."0"
  252. end
  253.  
  254. if bit.check(memory.read_u8(0x001e7e),2) then
  255. t=t.."1"
  256. else
  257. t=t.."0"
  258. end
  259.  
  260. if bit.check(memory.read_u8(0x001e7e),1) then
  261. t=t.."1"
  262. else
  263. t=t.."0"
  264. end
  265.  
  266. if bit.check(memory.read_u8(0x001e7e),0) then
  267. t=t.."1"
  268. else
  269. t=t.."0"
  270. end
  271.  
  272. text(114+SavegamesX,12+SavegamesY,t,0xFFFFFFFF)
  273.  
  274. -- current slot
  275.  
  276. memory.usememorydomain("IWRAM")
  277.  
  278. if bit.check(memory.read_u8(0x0d40),2) then
  279. currentslot=2
  280. elseif bit.check(memory.read_u8(0x0d40),3) then
  281. currentslot=3
  282. else
  283. currentslot=1
  284. end
  285.  
  286. text(3+SavegamesX,22+SavegamesY,"current slot: ".. currentslot,0xFFFFFFFF)
  287.  
  288. t=""
  289. if bit.check(memory.read_u8(0x0d40),7) then
  290. t=t.."1"
  291. else
  292. t=t.."0"
  293. end
  294.  
  295. if bit.check(memory.read_u8(0x0d40),6) then
  296. t=t.."1"
  297. else
  298. t=t.."0"
  299. end
  300.  
  301. if bit.check(memory.read_u8(0x0d40),5) then
  302. t=t.."1"
  303. else
  304. t=t.."0"
  305. end
  306.  
  307. if bit.check(memory.read_u8(0x0d40),4) then
  308. t=t.."1 "
  309. else
  310. t=t.."0 "
  311. end
  312.  
  313. if bit.check(memory.read_u8(0x0d40),3) then
  314. t=t.."1"
  315. else
  316. t=t.."0"
  317. end
  318.  
  319. if bit.check(memory.read_u8(0x0d40),2) then
  320. t=t.."1"
  321. else
  322. t=t.."0"
  323. end
  324.  
  325. if bit.check(memory.read_u8(0x0d40),1) then
  326. t=t.."1"
  327. else
  328. t=t.."0"
  329. end
  330.  
  331. if bit.check(memory.read_u8(0x0d40),0) then
  332. t=t.."1"
  333. else
  334. t=t.."0"
  335. end
  336.  
  337. text(114+SavegamesX,22+SavegamesY,t,0xFFFFFFFF)
  338.  
  339. memory.usememorydomain("EWRAM")
  340.  
  341. -- copy 1 to 2
  342. drawButton(SavegamesX+3,SavegamesY+34,70,10,"copy 1 to 2",ColorButtonNormal,20,function()
  343.  
  344. --write values
  345. for i=0,1783,1 do
  346. memory.write_u8(0x002580+i, memory.read_u8(0x001e88+i) )
  347. end
  348.  
  349. --set "slots in use" flag
  350. memory.write_u8( 0x001e7e, bit.set(memory.read_u8(0x001e7e),1) )
  351.  
  352. editedMemory=true
  353.  
  354. end)
  355.  
  356. -- copy 1 to 3
  357. drawButton(SavegamesX+3,SavegamesY+46,70,10,"copy 1 to 3",ColorButtonNormal,20,function()
  358.  
  359. --write values
  360. for i=0,1783,1 do
  361. memory.write_u8(0x002c78+i, memory.read_u8(0x001e88+i) )
  362. end
  363.  
  364. --set "slots in use" flag
  365. memory.write_u8( 0x001e7e, bit.set(memory.read_u8(0x001e7e),2) )
  366.  
  367. editedMemory=true
  368.  
  369. end)
  370.  
  371. -- copy 2 to 1
  372. drawButton(SavegamesX+3,SavegamesY+58,70,10,"copy 2 to 1",ColorButtonNormal,20,function()
  373.  
  374. --write values
  375. for i=0,1783,1 do
  376. memory.write_u8(0x001e88+i, memory.read_u8(0x002580+i) )
  377. end
  378.  
  379. --set "slots in use" flag
  380. memory.write_u8( 0x001e7e, bit.set(memory.read_u8(0x001e7e),0) )
  381.  
  382. editedMemory=true
  383.  
  384. end)
  385.  
  386. -- copy 2 to 3
  387. drawButton(SavegamesX+3,SavegamesY+70,70,10,"copy 2 to 3",ColorButtonNormal,20,function()
  388.  
  389. --write values
  390. for i=0,1783,1 do
  391. memory.write_u8(0x002c78+i, memory.read_u8(0x002580+i) )
  392. end
  393.  
  394. --set "slots in use" flag
  395. memory.write_u8( 0x001e7e, bit.set(memory.read_u8(0x001e7e),2) )
  396.  
  397. editedMemory=true
  398.  
  399. end)
  400.  
  401. -- copy 3 to 1
  402. drawButton(SavegamesX+3,SavegamesY+82,70,10,"copy 3 to 1",ColorButtonNormal,20,function()
  403.  
  404. --write values
  405. for i=0,1783,1 do
  406. memory.write_u8(0x001e88+i, memory.read_u8(0x002c78+i) )
  407. end
  408.  
  409. --set "slots in use" flag
  410. memory.write_u8( 0x001e7e, bit.set(memory.read_u8(0x001e7e),0) )
  411.  
  412. editedMemory=true
  413.  
  414. end)
  415.  
  416. -- copy 3 to 2
  417. drawButton(SavegamesX+3,SavegamesY+94,70,10,"copy 3 to 2",ColorButtonNormal,20,function()
  418.  
  419. --write values
  420. for i=0,1783,1 do
  421. memory.write_u8(0x002580+i, memory.read_u8(0x002c78+i) )
  422. end
  423.  
  424. --set "slots in use" flag
  425. memory.write_u8( 0x001e7e, bit.set(memory.read_u8(0x001e7e),1) )
  426.  
  427. editedMemory=true
  428.  
  429. end)
  430.  
  431.  
  432. -- current slot -> 1
  433. drawButton(SavegamesX+80,SavegamesY+34,80,10,"set slot=1",ColorButtonNormal,20,function()
  434.  
  435. memory.usememorydomain("IWRAM")
  436.  
  437. memory.write_u8( 0x000d40, bit.clear(memory.read_u8(0x000d40),2) )
  438. memory.write_u8( 0x000d40, bit.clear(memory.read_u8(0x000d40),3) )
  439.  
  440.  
  441. editedMemory=true
  442. memory.usememorydomain("EWRAM")
  443.  
  444. end)
  445.  
  446. -- current slot -> 2
  447. drawButton(SavegamesX+80,SavegamesY+46,80,10,"set slot=2",ColorButtonNormal,20,function()
  448.  
  449. memory.usememorydomain("IWRAM")
  450.  
  451. memory.write_u8( 0x000d40, bit.set(memory.read_u8(0x000d40),2) )
  452. memory.write_u8( 0x000d40, bit.clear(memory.read_u8(0x000d40),3) )
  453.  
  454.  
  455. editedMemory=true
  456. memory.usememorydomain("EWRAM")
  457.  
  458. end)
  459.  
  460. -- current slot -> 3
  461. drawButton(SavegamesX+80,SavegamesY+58,80,10,"set slot=3",ColorButtonNormal,20,function()
  462.  
  463. memory.usememorydomain("IWRAM")
  464.  
  465. memory.write_u8( 0x000d40, bit.set(memory.read_u8(0x000d40),3) )
  466. memory.write_u8( 0x000d40, bit.clear(memory.read_u8(0x000d40),2) )
  467.  
  468. editedMemory=true
  469. memory.usememorydomain("EWRAM")
  470.  
  471. end)
  472.  
  473. -- wipe 1
  474. drawButton(SavegamesX+80,SavegamesY+70,80,10,"wipe slot 1",ColorButtonNormal,20,function()
  475.  
  476. --delete values
  477. for i=0,1783,1 do
  478. memory.write_u8(0x001e88+i, 0 )
  479. end
  480.  
  481. --set "slots in use" flag
  482. memory.write_u8( 0x001e7e, bit.clear(memory.read_u8(0x001e7e),0) )
  483.  
  484. editedMemory=true
  485.  
  486. end)
  487.  
  488. -- wipe 2
  489. drawButton(SavegamesX+80,SavegamesY+82,80,10,"wipe slot 2",ColorButtonNormal,20,function()
  490.  
  491. --delete values
  492. for i=0,1783,1 do
  493. memory.write_u8(0x002580+i, 0 )
  494. end
  495.  
  496. --set "slots in use" flag
  497. memory.write_u8( 0x001e7e, bit.clear(memory.read_u8(0x001e7e),1) )
  498.  
  499. editedMemory=true
  500.  
  501. end)
  502.  
  503. -- wipe 3
  504. drawButton(SavegamesX+80,SavegamesY+94,80,10,"wipe slot 3",ColorButtonNormal,20,function()
  505.  
  506. --delete values
  507. for i=0,1783,1 do
  508. memory.write_u8(0x002c78+i, 0 )
  509. end
  510.  
  511. --set "slots in use" flag
  512. memory.write_u8( 0x001e7e, bit.clear(memory.read_u8(0x001e7e),2) )
  513.  
  514. editedMemory=true
  515.  
  516. end)
  517.  
  518.  
  519. -- close button
  520. drawCloseButton(SavegamesX,SavegamesY,width,function()
  521.  
  522. Settings["BoolEditSavegames"]=false
  523. if Settings["BoolNotifications"] then print("Edit Savegames Display has been closed.") end
  524.  
  525. end)
  526.  
  527.  
  528. -- other text:
  529. text(3+SavegamesX,SavegamesY,"Edit Savegames",0xFF808080)
  530. --text(3+SavegamesX,58+SavegamesY,"sry, can't finish as long\nas I don't understand\nchecksums...",0xFFFF8020)
  531.  
  532. end
  533.  
  534.  
  535.  
  536. client.setwindowsize(2)
  537.  
  538. while true do
  539.  
  540. memory.usememorydomain("EWRAM")
  541.  
  542. X = input.getmouse().X + PaddingLeft
  543. Y = input.getmouse().Y + PaddingTop
  544. clicked = input.getmouse().Left
  545.  
  546. if clicked then clickedFrames = clickedFrames + 1
  547. else clickedFrames = 0 end
  548.  
  549. drawEditSavegames()
  550.  
  551. XBefore=X
  552. YBefore=Y
  553.  
  554. emu.frameadvance()
  555.  
  556. clicked=false
  557.  
  558. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement