Advertisement
Guest User

katam lua 0.3

a guest
Oct 7th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.21 KB | None | 0 0
  1. local ScriptInfo = {"KATAM Luascript by Mugg1991",
  2.                     "v0.3",
  3.                     "7th Oct 2017",}
  4.  
  5. local AddressTableGeneral= {
  6. [1] = {1,"Camera X",0xFFFFE0A0,"EWRAM",0x23660,2,true},
  7. [2] = {1,"Camera Y",0xFFFFE0A0,"EWRAM",0x23662,2,true},
  8. [3] = {1,"-",0xFFFFE0A0,"EWRAM",0x0,1,true},
  9. [4] = {1,"-",0xFFFFE0A0,"EWRAM",0x0,1,true},
  10. [5] = {1,"-",0xFFFFE0A0,"EWRAM",0x0,1,true},
  11. [6] = {1,"-",0xFFFFE0A0,"EWRAM",0x0,1,true}
  12. }
  13.  
  14. local AddressTableFlags= {
  15. [1] = {0,"Mirror Shards",0xFFB0B0B0},  
  16. [2] = {7,"Kracko",0xFFFFE0A0,"EWRAM",0x38970,0,true},
  17. [3] = {7,"King Golem",0xFFFFE0A0,"EWRAM",0x38970,1,true},
  18. [4] = {7,"Master Hand",0xFFFFE0A0,"EWRAM",0x38970,2,true},
  19. [5] = {7,"Gobbler",0xFFFFE0A0,"EWRAM",0x38970,3,true},
  20. [6] = {7,"Wiz",0xFFFFE0A0,"EWRAM",0x38970,4,true},
  21. [7] = {7,"Moley",0xFFFFE0A0,"EWRAM",0x38970,5,true},
  22. [8] = {7,"Mega Titan",0xFFFFE0A0,"EWRAM",0x38970,6,true},
  23. [9] = {7,"D. Metaknight",0xFFFFE0A0,"EWRAM",0x38970,7,true},
  24.  
  25. [10] = {0,"Misc",0xFFB0B0B0},  
  26. [11] = {7,"Ability Room",0xFFFFE0A0,"EWRAM",0x28C58,0,true},
  27.  
  28. [12] = {0,"Area 1",0xFFB0B0B0},        
  29. [13] = {7,"Switch 1",0xFFFFE0A0,"EWRAM",0x28C18,0,true},
  30. [14] = {7,"Big Chest",0xFFFFE0A0,"EWRAM",0x38960,5,true},
  31. [15] = {7,"Chest",0xFFFFE0A0,"EWRAM",0x38960,3,true},
  32. [16] = {7,"Chest",0xFFFFE0A0,"EWRAM",0x38961,0,true},
  33. [17] = {7,"Chest",0xFFFFE0A0,"EWRAM",0x38961,1,true},
  34.  
  35. [18] = {0,"Area 2",0xFFB0B0B0},    
  36. [19] = {7,"Switch 1",0xFFFFE0A0,"EWRAM",0x28C14,0,true},
  37. [20] = {7,"Lever",0xFFFFE0A0,"EWRAM",0x38962,2,true},  
  38. [21] = {7,"Big Chest",0xFFFFE0A0,"EWRAM",0x38961,7,true},
  39. [22] = {7,"Chest",0xFFFFE0A0,"EWRAM",0x38962,1,true},
  40.  
  41. [23] = {0,"Area 3",0xFFB0B0B0},    
  42. [24] = {7,"Switch 1",0xFFFFE0A0,"EWRAM",0x28C28,0,true},
  43. [25] = {7,"Switch 2",0xFFFFE0A0,"EWRAM",0x28C24,0,true},
  44.  
  45. [26] = {0,"Area 4",0xFFB0B0B0},    
  46. [27] = {7,"Switch 1",0xFFFFE0A0,"EWRAM",0x28C44,0,true},
  47. [28] = {7,"Switch 2",0xFFFFE0A0,"EWRAM",0x28C4C,0,true},   
  48.  
  49. [29] = {0,"Area 5",0xFFB0B0B0},
  50. [30] = {7,"Switch 1",0xFFFFE0A0,"EWRAM",0x28C34,0,true},
  51. [31] = {7,"Switch 2",0xFFFFE0A0,"EWRAM",0x28C38,0,true},
  52. [32] = {7,"Lever",0xFFFFE0A0,"EWRAM",0x38969,5,true},      
  53.  
  54. [33] = {0,"Area 6",0xFFB0B0B0},    
  55. [34] = {7,"Switch 1",0xFFFFE0A0,"EWRAM",0x28C1C,0,true},
  56. [35] = {7,"Switch 2",0xFFFFE0A0,"EWRAM",0x28C20,0,true},
  57. [36] = {7,"Lever",0xFFFFE0A0,"EWRAM",0x38968,1,true},
  58.  
  59. [37] = {0,"Area 7",0xFFB0B0B0},
  60. [38] = {7,"Switch 1",0xFFFFE0A0,"EWRAM",0x28C3C,0,true},
  61. [39] = {7,"Switch 2",0xFFFFE0A0,"EWRAM",0x28C40,0,true},       
  62.  
  63. [40] = {0,"Area 8",0xFFB0B0B0},
  64. [41] = {7,"Switch 1",0xFFFFE0A0,"EWRAM",0x28C2C,0,true},
  65. [42] = {7,"Switch 2",0xFFFFE0A0,"EWRAM",0x28C30,0,true},   
  66. [43] = {7,"Lever",0xFFFFE0A0,"EWRAM",0x38969,2,true},  
  67.  
  68. [44] = {0,"Area 9",0xFFB0B0B0},
  69. [45] = {7,"Switch 1",0xFFFFE0A0,"EWRAM",0x28C48,0,true},   
  70. }
  71.  
  72. local AddressTableKirby= {
  73. [1] = {1,"X",0xFFFFB0C0,"EWRAM",0x020F20,4,true,false},
  74. [2] = {1,"Y",0xFFFFB0C0,"EWRAM",0x020F24,4,true,false},
  75. [3] = {1,"X Speed",0xFFFFB0C0,"EWRAM",0x020F30,2,true,true},
  76. [4] = {1,"Y Speed",0xFFFFB0C0,"EWRAM",0x020F32,2,true,true},
  77. [5] = {1,"Hitbox Offset X",0xFFFFB0C0,"EWRAM",0x020F18,1,true,true},
  78. [6] = {1,"Hitbox Offset Y",0xFFFFB0C0,"EWRAM",0x020F19,1,true,true},
  79. [7] = {1,"Hitbox Width",0xFFFFB0C0,"EWRAM",0x020F1A,1,true,true},
  80. [8] = {1,"Hitbox Height",0xFFFFB0C0,"EWRAM",0x020F1B,1,true,true},
  81. [9] = {1,"Ability",0xFFFFB0C0,"EWRAM",0x020FE3,1,true,false},
  82. [10] = {1,"Health",0xFFFFB0C0,"EWRAM",0x020FE0,1,true,false},
  83. [11] = {1,"Max Health",0xFFFFB0C0,"EWRAM",0x020FE1,1,true,false},
  84. [12] = {1,"Lives",0xFFFFB0C0,"EWRAM",0x020FE2,1,true,false},
  85. [13] = {1,"Phone Battery",0xFFFFB0C0,"EWRAM",0x020FBC,1,true,false},
  86. [14] = {1,"Room",0xFFFFB0C0,"EWRAM",0x020FE6,2,true,false}
  87. }
  88.  
  89. local AddressTableYellow= {
  90. [1] = {1,"X",0xFFFFE060,"EWRAM",0x0210C8,4,true,false},
  91. [2] = {1,"Y",0xFFFFE060,"EWRAM",0x0210CC,4,true,false},
  92. [3] = {1,"X Speed",0xFFFFE060,"EWRAM",0x0210D8,2,true,true},
  93. [4] = {1,"Y Speed",0xFFFFE060,"EWRAM",0x0210DA,2,true,true},
  94. [5] = {1,"Ability",0xFFFFE060,"EWRAM",0x02118B,1,true,false},
  95. [6] = {1,"Health",0xFFFFE060,"EWRAM",0x021188,1,true,false},
  96. [7] = {1,"Max Health",0xFFFFE060,"EWRAM",0x021189,1,true,false},
  97. [8] = {1,"Room",0xFFFFE060,"EWRAM",0x02118E,2,true,false}
  98. }
  99.  
  100. local AddressTableRed= {
  101. [1] = {1,"X",0xFFFF9090,"EWRAM",0x021270,4,true,false},
  102. [2] = {1,"Y",0xFFFF9090,"EWRAM",0x021274,4,true,false},
  103. [3] = {1,"X Speed",0xFFFF9090,"EWRAM",0x021280,2,true,true},
  104. [4] = {1,"Y Speed",0xFFFF9090,"EWRAM",0x021282,2,true,true},
  105. [5] = {1,"Ability",0xFFFF9090,"EWRAM",0x021333,1,true,false},
  106. [6] = {1,"Health",0xFFFF9090,"EWRAM",0x021330,1,true,false},
  107. [7] = {1,"Max Health",0xFFFF9090,"EWRAM",0x021331,1,true,false},
  108. [8] = {1,"Room",0xFFFF9090,"EWRAM",0x021336,2,true,false}
  109. }
  110.  
  111. local AddressTableGreen= {
  112. [1] = {1,"X",0xFFC0FF80,"EWRAM",0x021418,4,true,false},
  113. [2] = {1,"Y",0xFFC0FF80,"EWRAM",0x02141C,4,true,false},
  114. [3] = {1,"X Speed",0xFFC0FF80,"EWRAM",0x021428,2,true,true},
  115. [4] = {1,"Y Speed",0xFFC0FF80,"EWRAM",0x02142A,2,true,true},
  116. [5] = {1,"Ability",0xFFC0FF80,"EWRAM",0x0214DB,1,true,false},
  117. [6] = {1,"Health",0xFFC0FF80,"EWRAM",0x0214D8,1,true,false},
  118. [7] = {1,"Max Health",0xFFC0FF80,"EWRAM",0x0214D9,1,true,false},
  119. [8] = {1,"Room",0xFFC0FF80,"EWRAM",0x0214DE,2,true,false}
  120. }
  121.  
  122. local Displays = {
  123.     -- Name, active, col, x, y, width, height, offset of list, edit mode, table, entries shown
  124.     [1]= {"General", false, 0xFFFFE0A0, 40, 40, 146, 34, 0, false, AddressTableGeneral,2},
  125.     [2]= {"Kirby", false, 0xFFFFB0C0, 40, 40, 146, 66, 0, false, AddressTableKirby,6},
  126.     [3]= {"Yellow", false, 0xFFFFE060, 40, 40, 146, 66, 0, false, AddressTableYellow,6},
  127.     [4]= {"Red", false, 0xFFFF9090, 40, 40, 146, 66, 0, false, AddressTableRed,6},
  128.     [5]= {"Green", false, 0xFFC0FF80, 40, 40, 146, 66, 0, false, AddressTableGreen,6},
  129.     [6]= {"Flags", false, 0xFFFFE0A0, 40, 40, 146, 82, 0, false, AddressTableFlags,8},
  130.     [7]= {"Hitboxes", false, 0xFFFFE0A0, nil}
  131. }
  132.  
  133. local Enemies = {}
  134. local Other = {}
  135.  
  136. local HelperKirby = {
  137.     [1]={"Yellow",0xFFFFE060},
  138.     [2]={"Red",0xFFFF9090},
  139.     [3]={"Green",0xFFC0FF80}
  140. }
  141.  
  142. local HitboxSettings = {
  143.     [1]={"Kirby",true},
  144.     [2]={"Enemy",true},
  145.     [3]={"Attack",true}
  146. }
  147.  
  148. local Mouse = {
  149.     X               = 0,
  150.     Y               = 0,
  151.     XBefore         = 0,
  152.     YBefore         = 0,
  153.     clickedFrames   = 0,
  154.     clicked         = false
  155. }
  156.  
  157. local Color = {
  158.     Selected    = 0xB0A0A0A0,
  159.     Normal      = 0xA0303030,
  160.     Grey        = 0xA0C0C0C0
  161. }
  162.  
  163. function text(x, y, text, color, backcolor)
  164.     if backcolor==nil then backcolor=0x00000000 end
  165.     gui.drawText(x, y, text,color,backcolor,10,"Arial")
  166. end
  167.  
  168. function box(x,y,x2,y2)
  169.     gui.drawBox(x,y,x2,y2,0x00000000,0xD0000000)
  170. end
  171.  
  172. function boxNormal(x,y,x2,y2)
  173.     gui.drawBox(x,y,x2,y2,0xFF000000,0xA0000000)
  174. end
  175.  
  176. function boxSelected(x,y,x2,y2)
  177.     gui.drawBox(x,y,x2,y2,0xFF000000,0xA0505050)
  178. end
  179.  
  180. function arrowDown(xpos,ypos,col)
  181.     gui.drawLine(xpos,ypos,xpos+6,ypos,col)
  182.     gui.drawLine(xpos+1,ypos+1,xpos+5,ypos+1,col)
  183.     gui.drawLine(xpos+2,ypos+2,xpos+4,ypos+2,col)
  184.     gui.drawPixel(xpos+3,ypos+3,col)
  185. end
  186.  
  187. function arrowUp(xpos,ypos,col)
  188.     gui.drawLine(xpos,ypos,xpos+6,ypos,col)
  189.     gui.drawLine(xpos+1,ypos-1,xpos+5,ypos-1,col)
  190.     gui.drawLine(xpos+2,ypos-2,xpos+4,ypos-2,col)
  191.     gui.drawPixel(xpos+3,ypos-3,col)
  192. end
  193.  
  194. function drawDisplayBox(id,bordercolor,color)
  195.     posx=Displays[id][4]
  196.     posy=Displays[id][5]
  197.     width=Displays[id][6]
  198.     height=Displays[id][7]
  199.    
  200.     if Mouse.clicked then
  201.  
  202.         if Mouse.X > posx and Mouse.X < posx+width and Mouse.Y > posy and Mouse.Y < posy+height then
  203.  
  204.             if Mouse.clickedFrames > 0 then
  205.                 menuscreen=0 -- close menu
  206.                
  207.                 posy = posy + (Mouse.Y-Mouse.YBefore) -- enables mouse drag
  208.                 posx = posx + (Mouse.X-Mouse.XBefore)
  209.  
  210.                 if posy < 0 then posy=0 -- prevents display from going offscreen
  211.                 elseif posy > 159-height then posy=159-height end
  212.                 if posx < 0 then posx=0
  213.                 elseif posx > 239-width then posx=239-width end
  214.            
  215.                 Displays[id][4]=posx
  216.                 Displays[id][5]=posy
  217.             end
  218.         end
  219.     end
  220.     gui.drawBox(posx,posy,posx+width,posy+height,bordercolor,color)
  221.     text(posx+3,posy-1,Displays[id][1],0xFF808080)
  222. end
  223.        
  224. function drawCloseButton(id)
  225.     width=Displays[id][6]
  226.     x=Displays[id][4]
  227.     y=Displays[id][5]
  228.    
  229.     drawButton(x+width-10,y,10,10,"x",Color.Grey,15,function()
  230.         Displays[id][2] = false
  231.     end)
  232. end
  233.  
  234. function drawEditButton(id)
  235.  
  236.     width=Displays[id][6]
  237.     x=Displays[id][4]
  238.     y=Displays[id][5]
  239.     if Displays[id][9] then col=Color.Selected
  240.     else col=Color.Normal end
  241.    
  242.     drawButton(x+width-25,y,12,10,"e",col,15,function()
  243.         Displays[id][9]=not Displays[id][9]
  244.     end)
  245. end
  246.  
  247. function drawButton(posx,posy,width,height,label,color,frequency,clickedfunction)
  248.     if Mouse.X>posx and Mouse.X<posx+width and Mouse.Y>posy and Mouse.Y<posy+height then
  249.             if Mouse.clicked and Mouse.clickedFrames%frequency==1 then  
  250.                 clickedfunction()
  251.             end
  252.         gui.drawBox(posx,posy,posx+width,posy+height,color-0x00303030,color+0x30303030)
  253.     else
  254.         gui.drawBox(posx,posy,posx+width,posy+height,color-0x00303030,color)
  255.     end
  256.     text(posx+1,posy-2,label,0xFFFFFFFF)
  257. end
  258.  
  259. function drawMenuButton(posx,posy,width,height,label,z,drawindicator,indicator,col,clickedfunction)
  260.     if Mouse.X>posx and Mouse.X<posx+width and Mouse.Y>posy and Mouse.Y<posy+height then
  261.         if Mouse.clicked and Mouse.clickedFrames==z then
  262.             menuscreen=0
  263.             clickedfunction()
  264.         end
  265.         boxSelected(posx,posy,posx+width,posy+height)
  266.     else
  267.         boxNormal(posx,posy,posx+width,posy+height)
  268.     end
  269.     text(posx+2,posy-1,label,col)
  270.    
  271.     if drawindicator then
  272.         if indicator then text(posx+width-10,posy,"o",0xFF80FF80)
  273.         else text(posx+width-10,posy-1,"x",0xFFFF9090) end
  274.     end
  275. end
  276.  
  277. local getChangeAmount = function(valueChangeAmount)
  278.     if Mouse.clickedFrames>540 then
  279.         valueChangeAmount=valueChangeAmount*1000000
  280.     elseif Mouse.clickedFrames>450 then
  281.         valueChangeAmount=valueChangeAmount*100000
  282.     elseif Mouse.clickedFrames>360 then
  283.         valueChangeAmount=valueChangeAmount*10000
  284.     elseif Mouse.clickedFrames>270 then
  285.         valueChangeAmount=valueChangeAmount*1000
  286.     elseif Mouse.clickedFrames>180 then
  287.         valueChangeAmount=valueChangeAmount*100
  288.     elseif Mouse.clickedFrames>90 then
  289.         valueChangeAmount=valueChangeAmount*10
  290.     end
  291.     return valueChangeAmount
  292. end
  293.  
  294. local addressTableSetValue = function(address, addressSize, addressEndian, newvalue)
  295.  
  296.     if addressSize==1 then
  297.         memory.write_u8(address,newvalue)
  298.     elseif addressSize==2 then
  299.         if addressEndian then
  300.             memory.write_u16_le(address,newvalue)
  301.         else
  302.             memory.write_u16_be(address,newvalue)
  303.         end            
  304.     elseif addressSize==3 then
  305.         if addressEndian then
  306.             memory.write_u24_le(address,newvalue)
  307.         else
  308.             memory.write_u24_be(address,newvalue)
  309.         end
  310.     elseif addressSize==4 then
  311.         if addressEndian then
  312.             memory.write_u32_le(address,newvalue)
  313.         else
  314.             memory.write_u32_be(address,newvalue)
  315.         end
  316.     end
  317.    
  318. end
  319.  
  320. local addressTableGetValue = function(address, addressSize, addressEndian, addressSigned)
  321.  
  322.     if addressSigned then
  323.         if addressSize==1 then
  324.             value=memory.read_s8(address)
  325.         elseif addressSize==2 then
  326.             if addressEndian then
  327.                 value=memory.read_s16_le(address)
  328.             else
  329.                 value=memory.read_s16_be(address)
  330.             end            
  331.         elseif addressSize==3 then
  332.             if addressEndian then
  333.                 value=memory.read_s24_le(address)
  334.             else
  335.                 value=memory.read_s24_be(address)
  336.             end
  337.         elseif addressSize==4 then
  338.             if addressEndian then
  339.                 value=memory.read_s32_le(address)
  340.             else
  341.                 value=memory.read_s32_be(address)
  342.             end
  343.         end
  344.     else
  345.         if addressSize==1 then
  346.             value=memory.read_u8(address)
  347.         elseif addressSize==2 then
  348.             if addressEndian then
  349.                 value=memory.read_u16_le(address)
  350.             else
  351.                 value=memory.read_u16_be(address)
  352.             end            
  353.         elseif addressSize==3 then
  354.             if addressEndian then
  355.                 value=memory.read_u24_le(address)
  356.             else
  357.                 value=memory.read_u24_be(address)
  358.             end
  359.         elseif addressSize==4 then
  360.             if addressEndian then
  361.                 value=memory.read_u32_le(address)
  362.             else
  363.                 value=memory.read_u32_be(address)
  364.             end
  365.         end
  366.     end
  367.    
  368.     return value   
  369. end
  370.  
  371. local DisplayAddressTable = function(display_id, has_arrows,  has_buttons,  display_description,  description_offset,  arrows_offset,  buttons_offset)
  372.    
  373.     inputTable=Displays[display_id][10]
  374.     xpos=Displays[display_id][4]
  375.     ypos=Displays[display_id][5]
  376.     memorydomainBefore=memory.getcurrentmemorydomain()
  377.     tableSize=table.getn(inputTable)
  378.     table_start=1
  379.     table_end=Displays[display_id][11]
  380.     table_iterations = 1
  381.     offset=Displays[display_id][8]
  382.     list_height = 8*(table_end - table_start)+14
  383.  
  384.     --display arrows:
  385.     if has_arrows then
  386.         --bottom arrow button
  387.         if (tableSize - offset) > table_end then
  388.             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
  389.                 if Mouse.clicked and Mouse.clickedFrames%3==1 then
  390.                     Displays[display_id][8]=offset+1
  391.                 end
  392.                 arrowDown(xpos+arrows_offset+2,ypos+list_height,0xFFFFFFFF)
  393.             else
  394.                 arrowDown(xpos+arrows_offset+2,ypos+list_height,0xA0FFFFFF)
  395.             end
  396.         else
  397.             if offset < 0 then
  398.                 Displays[display_id][8]=0
  399.             end
  400.         end
  401.            
  402.         --top arrow button
  403.         if offset > 0 then
  404.             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
  405.                 if Mouse.clicked and Mouse.clickedFrames%3==1 then
  406.                     Displays[display_id][8]=offset-1
  407.                 end
  408.                 arrowUp(xpos+arrows_offset+2,ypos+list_height-6,0xFFFFFFFF)
  409.             else
  410.                 arrowUp(xpos+arrows_offset+2,ypos+list_height-6,0xA0FFFFFF)
  411.             end
  412.         end
  413.     end
  414.     -- applying display offset
  415.     table_start = table_start + offset
  416.     table_end   = table_end + offset
  417.  
  418.     -- going through the table
  419.     for i=table_start,table_end do --show a part of the list
  420.  
  421.         contenttype=inputTable[i][1]
  422.         description=inputTable[i][2]
  423.         textColor=inputTable[i][3]
  424.         memorydomain=inputTable[i][4]
  425.        
  426.         if contenttype==0 then  -- TITLE
  427.                
  428.             gui.drawBox(5+xpos,4+ypos+table_iterations*8,arrows_offset+xpos,12+ypos+table_iterations*8,0x00000000,0xFF505050)
  429.    
  430.         elseif contenttype==7 then -- BINARY
  431.            
  432.             memory.usememorydomain(memorydomain)
  433.             address=inputTable[i][5]
  434.             currentbit=inputTable[i][6]
  435.             value=memory.read_u8(address)
  436.  
  437.             value=bit.check(value, currentbit)
  438.            
  439.             if value then
  440.                 value="Yes"
  441.                 valueColor=0xFF80FF80
  442.             else
  443.                 value="No"
  444.                 valueColor=0xFFFF9090
  445.             end
  446.            
  447.             text(5+xpos,3+ypos+table_iterations*8,value,valueColor)
  448.        
  449.         else    -- OTHER TYPES 
  450.             memory.usememorydomain(memorydomain)
  451.             address=inputTable[i][5]
  452.             addressSize=inputTable[i][6]
  453.             addressEndian=inputTable[i][7] -- true:little endian, false:big endian
  454.             addressSigned=inputTable[i][8]
  455.             valueChangeAmount=1                  
  456.             value = addressTableGetValue(address,addressSize,addressEndian, addressSigned)
  457.             text(5+xpos,3+ypos+table_iterations*8,value, textColor)
  458.         end
  459.        
  460.         if display_description then
  461.             text(xpos+description_offset,3+ypos+table_iterations*8,description, textColor)
  462.         end
  463.  
  464.         if has_buttons then
  465.            
  466.             if contenttype==7 then -- binary
  467.            
  468.                 drawButton(xpos+buttons_offset,4+ypos+table_iterations*8,21,8,"Set",Color.Normal,8,function()
  469.    
  470.                     currentvalue=memory.read_u8(address)
  471.  
  472.                     if bit.check(currentvalue,currentbit) then
  473.                         memory.write_u8(address, bit.clear(currentvalue,currentbit))
  474.                     else
  475.                         memory.write_u8(address, bit.set(currentvalue,currentbit)) 
  476.                     end
  477.                
  478.                 end)
  479.            
  480.             elseif contenttype~=0 then -- normal values
  481.            
  482.                 drawButton(xpos+buttons_offset,4+ypos+table_iterations*8,9,8,"-",Color.Normal,5,function()
  483.                     valueChangeAmount = getChangeAmount(valueChangeAmount) -- increases when holding mouse key 
  484.                     newvalue = value - valueChangeAmount
  485.                     addressTableSetValue(address,addressSize,addressEndian,newvalue)                   
  486.                 end)
  487.  
  488.                 drawButton(12+xpos+buttons_offset,4+ypos+table_iterations*8,9,8,"+",Color.Normal,5,function()
  489.                     valueChangeAmount = getChangeAmount(valueChangeAmount) -- increases when holding mouse key         
  490.                     newvalue = value + valueChangeAmount
  491.                     addressTableSetValue(address,addressSize,addressEndian,newvalue)               
  492.                 end)
  493.             end        
  494.         end
  495.         table_iterations=table_iterations+1
  496.     end
  497.     memory.usememorydomain(memorydomainBefore)
  498. end
  499.    
  500. local drawDisplay = function(id)
  501.     if Displays[id][4]~=nil then
  502.         drawDisplayBox(id, 0xFF202020,0xA0000000)
  503.         drawCloseButton(id)
  504.         drawEditButton(id)
  505.         if Displays[id][9] then
  506.             DisplayAddressTable(id,true,true,true,66,132,42)   
  507.         else
  508.             DisplayAddressTable(id,true,false,true,46,132,0)
  509.         end
  510.     end
  511. end
  512.  
  513. local updateEnemies = function(enemyTableSize,fullSearch)
  514.  
  515.     memory.usememorydomain("EWRAM")
  516.     count=1
  517.     Enemies = {}
  518.     address=0x0
  519.     found=false
  520.     if fullSearch then end_address=0x36FF
  521.     else end_address=enemyTableSize*0xBC + 0x2F0 end
  522.    
  523.     while address < end_address do     
  524.         if memory.read_u32_le(address)== 0x1FFFFFF
  525.         and memory.read_u8(address-1)~= 255 then
  526.             Enemies[count]=address
  527.             count=count+1
  528.             found=true
  529.         end
  530.         if found then address=address+0x04
  531.                  else address=address+0x01
  532.         end
  533.     end
  534. end
  535.  
  536. local updateOther = function(enemyTableSize)
  537.  
  538.     memory.usememorydomain("IWRAM")
  539.     count=1
  540.     Other = {}
  541.     address=0x3CB0
  542.     end_address=0x477F
  543.    
  544.     while address < end_address do
  545.         if memory.read_u32_le(address)== 0xFFFFFFFF
  546.         and memory.read_u8(address-1)~= 255 then
  547.             Other[count]=address
  548.             count=count+1
  549.         end
  550.         address=address+0x04
  551.     end
  552.  
  553. end
  554.  
  555. local drawEnemies = function()  -- Enemies
  556.  
  557.     local buttoncol,color,subcolor,verticalOffset=0
  558.     local info=""
  559.     local counterOffset=0
  560.     local enemyTableSize = table.getn(Enemies) 
  561.     local otherTableSize = table.getn(Other)   
  562.    
  563.     memory.usememorydomain("EWRAM")
  564.     local cameraX = memory.read_u16_le(0x23660)
  565.     local cameraY = memory.read_u16_le(0x23662)
  566.    
  567.     --buttons
  568.     for s=1,table.getn(HitboxSettings) do
  569.         if HitboxSettings[s][2] then buttoncol=Color.Selected
  570.         else buttoncol=Color.Normal end
  571.         drawButton(14+s*40,0,36,9,HitboxSettings[s][1],buttoncol,15,function()
  572.             HitboxSettings[s][2]=not HitboxSettings[s][2]
  573.         end)
  574.     end
  575.    
  576.     if HitboxSettings[1][2] then
  577.         --display kirby hitbox         
  578.             --!! careful: It's expected to be EWRAM here
  579.         for i=0,3 do
  580.             offset  =i*0x1A8
  581.             room = memory.read_u16_le(0x020FE6+offset)
  582.             kirbyX   = memory.read_u24_le(0x020F21+offset)
  583.             kirbyY   = memory.read_u24_le(0x020F25+offset)
  584.             hitboxX  = memory.read_s8(0x020F18+offset)
  585.             hitboxY  = memory.read_s8(0x020F19+offset)
  586.             width  = memory.read_s8(0x020F1A+offset)
  587.             height = memory.read_s8(0x020F1B+offset)
  588.             x=kirbyX-cameraX+hitboxX    -- screen x
  589.             y=kirbyY-cameraY+hitboxY    -- screen y
  590.             x2=x+width*2
  591.             y2=y+height*2  
  592.            
  593.             if i>0
  594.             and room ~= memory.read_u16_le(0x020FE6) then --kirby is in different room
  595.                 color=HelperKirby[i][2]
  596.                 subcolor=HelperKirby[i][2]
  597.             else -- same room
  598.                 color=0xFFFFFFFF
  599.                 subcolor=0x00000000
  600.             end
  601.             gui.drawBox(x,y,x2,y2,color) -- hitbox rectangle
  602.         end
  603.     end
  604.    
  605.     if HitboxSettings[2][2] then
  606.         --update enemy
  607.         if  enemyTableSize==0
  608.         or  frames%12==0 then
  609.             updateEnemies(enemyTableSize,false)
  610.         end
  611.  
  612.         --display
  613.         enemyTableSize = table.getn(Enemies)   
  614.         if enemyTableSize>0 then
  615.             memory.usememorydomain("EWRAM")
  616.             for s=1,enemyTableSize do
  617.  
  618.                 offset = Enemies[s]
  619.                 extrainfo=""           
  620.                 status   = memory.read_u8(offset+0x32)
  621.                 enemyX   = memory.read_u24_le(offset+0x44)
  622.                 enemyY   = memory.read_u24_le(offset+0x48)
  623.                 hitboxX  = memory.read_s8(offset+0x3B)
  624.                 hitboxY  = memory.read_s8(offset+0x3C)
  625.                 width  = memory.read_s8(offset+0x3D)
  626.                 height = memory.read_s8(offset+0x3E)
  627.                 heldAliveBy = memory.read_s8(offset+0x59)
  628.                 ID = memory.read_u8(offset+0x85)
  629.                 health = memory.read_s8(offset+0x83)
  630.                 x=enemyX-cameraX+hitboxX    -- screen x
  631.                 y=enemyY-cameraY+hitboxY    -- screen y
  632.                 x2=x+width*2
  633.                 y2=y+height*2
  634.                 x3=x+width      -- center
  635.  
  636.                 if Mouse.X > x-4 and Mouse.X < x2+4 and Mouse.Y > y-4 and Mouse.Y < y2+4 then
  637.                     color = 0xFF00FFFF
  638.                     subcolor = 0x80000000
  639.                     verticalOffset = -36
  640.                     info = health .. " HP\n" ..enemyX .. " X\n" ..enemyY .. " Y"       
  641.                 else
  642.                     color = 0xFF00FFFF
  643.                     subcolor = 0x80000000
  644.                     verticalOffset = -13
  645.                     info = health .. " HP"
  646.                 end
  647.                
  648.                 if status==0 then
  649.                     color=color - 0x80000000
  650.                     subcolor=subcolor - 0x40000000
  651.                     if HelperKirby[heldAliveBy] ~= nil then
  652.                         gui.drawLine(x,y2+1,x2,y2+1,HelperKirby[heldAliveBy][2])
  653.                     end
  654.                 end
  655.            
  656.                 text(x3-8,y+verticalOffset,info,color,subcolor) -- information
  657.                 gui.drawBox(x,y,x2,y2,color) -- hitbox rectangle
  658.             end
  659.             text(176,-2,"enemies: " .. enemyTableSize .. "   ." ,0xFFFFFF00,0x80000000)            
  660.             counterOffset=counterOffset+12
  661.         end
  662.     end
  663.    
  664.     if HitboxSettings[3][2] then
  665.         --update other
  666.         if  otherTableSize==0
  667.         or  frames%4==0 then
  668.             updateOther(otherTableSize)
  669.         end
  670.  
  671.         --display
  672.         otherTableSize = table.getn(Other) 
  673.         if otherTableSize>0 then
  674.             memory.usememorydomain("IWRAM")
  675.             for s=1,otherTableSize do
  676.  
  677.                 offset = Other[s]          
  678.                 status   = memory.read_u8(offset-0x27)
  679.                 status2      = memory.read_u8(offset-0x25)
  680.                 otherX   = memory.read_u16_le(offset+0x11)
  681.                 otherY   = memory.read_u16_le(offset+0x15)
  682.                 hitboxX  = memory.read_s8(offset+0x8)
  683.                 hitboxY  = memory.read_s8(offset+0x9)
  684.                 width  = memory.read_s8(offset+0xA)
  685.                 height = memory.read_s8(offset+0xB)
  686.                 damage = memory.read_s8(offset+0x33)
  687.                 x=otherX-cameraX+hitboxX    -- screen x
  688.                 y=otherY-cameraY+hitboxY    -- screen y
  689.                 x2=x+width*2
  690.                 y2=y+height*2
  691.                
  692.                 if not bit.check(status, 4)
  693.                 and (status2 == 0xA0
  694.                     or status2 == 0xA2
  695.                     or status2 == 0x10) then
  696.                     gui.drawBox(x,y,x2,y2,0xFFFF4000)
  697.                     text(x,y-13,damage .. " dmg",0xFFFF4000,0x40000000)
  698.                 end
  699.             end
  700.             text(176,-2+counterOffset,"attack: " .. otherTableSize .. "          ." ,0xFFFF4000,0x80000000)            
  701.         end
  702.     end
  703. end
  704.  
  705. local Menu = {
  706.     [1] =       {   [0] = "Script",
  707.                     [1] = 2,
  708.                     [2] = 3,
  709.                     [3] = 4,
  710.                     [4] = 5,
  711.                     [5] = 1,
  712.                     [6] = 6,
  713.                     [7] = 7
  714.                 }
  715. }
  716.  
  717. local drawMenu = function()
  718.  
  719.     verticalOffset=0
  720.  
  721.     for a=1,table.getn(Menu),1 do
  722.         drawMenuButton(-38+a*45,18,40,11,Menu[a][0],2,false,true,0xFFFFFFFF,function()
  723.             menuscreen=a
  724.         end)   
  725.        
  726.         if menuscreen==a then
  727.            
  728.             for b=1,table.getn(Menu[a]),1 do
  729.            
  730.                 id              = Menu[a][b]
  731.                 title           = Displays[id][1]
  732.                 indicator       = Displays[id][2]
  733.                 col             = Displays[id][3]
  734.                
  735.                 drawMenuButton(7,32+verticalOffset*10,72,10,title,1,true,indicator,col,function()
  736.                     Displays[id][2] = not indicator
  737.                 end)           
  738.                
  739.                 verticalOffset=verticalOffset+1
  740.             end        
  741.         end
  742.     end
  743.    
  744.     if Mouse.clicked and Mouse.clickedFrames==1 then
  745.            menuscreen = 0
  746.     end
  747. end
  748.  
  749. event.onloadstate(function()
  750.     updateEnemies(3,true)
  751.     updateOther(3)
  752. end)
  753.  
  754. updateEnemies(3,true)
  755. updateOther(3)
  756. menuscreen=0
  757. frames=0
  758. console.clear()
  759. for i=1,table.getn(ScriptInfo),1 do
  760.     print(ScriptInfo[i])
  761. end
  762.  
  763. while true do
  764.  
  765.     Mouse.X = input.getmouse().X
  766.     Mouse.Y = input.getmouse().Y
  767.     Mouse.clicked = input.getmouse().Left
  768.    
  769.     if Displays[7][2] then  -- enemies
  770.         drawEnemies()
  771.     end
  772.    
  773.     for i=1,table.getn(Displays) do -- all displays
  774.         if Displays[i][2] then
  775.             drawDisplay(i)
  776.         end
  777.     end
  778.        
  779.     drawMenu() -- menu
  780.  
  781.     Mouse.XBefore=Mouse.X
  782.     Mouse.YBefore=Mouse.Y
  783.     if Mouse.clicked then Mouse.clickedFrames = Mouse.clickedFrames + 1
  784.     else Mouse.clickedFrames = 0 end
  785.    
  786.    if client.ispaused() then
  787.         gui.DrawFinish()
  788.         emu.yield()
  789.     else
  790.         emu.frameadvance()
  791.     end
  792.    
  793.     frames=frames+1
  794. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement