Advertisement
MrCheeze

pm_dynamic_memory_advanced.lua

Sep 25th, 2016
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. --simple version: http://pastebin.com/wEj2Bgxe
  2.  
  3. romhash = gameinfo.getromhash()
  4.  
  5. if romhash == "B9CCA3FF260B9FF427D981626B82F96DE73586D3" then --JAP
  6. dynamic_memory_start = 0x2FB800
  7. dynamic_memory_end = 0x34F800
  8. particle_table = 0x0B4378
  9. current_menu_pointer = 0x10D85C
  10. selected_menu_item = 0x10D808
  11. menu_code_pointer = 0x159400
  12. elseif romhash == "3837F44CDA784B466C9A2D99DF70D77C322B97A0" then --USA
  13. dynamic_memory_start = 0x2FB800
  14. dynamic_memory_end = 0x34F800
  15. particle_table = 0x0B4398
  16. current_menu_pointer = 0x10D69C
  17. selected_menu_item = 0x10D648
  18. menu_code_pointer = 0x1543C0
  19. else
  20. print(romhash)
  21. end
  22.  
  23. UPDATE_EVERY_N_FRAMES = 1
  24.  
  25. dynamic_memory_len = dynamic_memory_end - dynamic_memory_start
  26.  
  27. event.onexit(function() gui.DrawNew("native") end)
  28.  
  29. while true do
  30. if emu.framecount() % UPDATE_EVERY_N_FRAMES == 0 or client.ispaused() then
  31. gui.DrawNew("native") --coordinates are now based on screen pixels rather than game pixels, and stuff is not erased automatically each frame.
  32.  
  33. particle_count = 0
  34. for i=0,0x5F do
  35. particle_ptr = memory.read_u32_be(particle_table + 4*i)
  36. if particle_ptr > 0 then
  37. particle_count = particle_count + 1
  38. end
  39. end
  40.  
  41. gui.drawText(24, 80, string.format("Particle count: %d", particle_count))
  42.  
  43. if true then
  44.  
  45. addr = dynamic_memory_start
  46.  
  47. gui.drawBox(0, 0, client.screenwidth(), 50, 0xFF000000, 0xFF000000)
  48.  
  49. used_memory = 0
  50. free_memory = 0
  51. used_count = 0
  52. free_count = 0
  53.  
  54. hack_all_blocks_except_last_to_in_use = input.get()["F"]
  55. dump_block_list = input.get()["G"]
  56.  
  57. while addr >= dynamic_memory_start and addr < dynamic_memory_end do
  58. next_addr = memory.read_u32_be(addr) - 0x80000000
  59. blocksize = memory.read_u32_be(addr+0x4) --not including the 0x10 bytes for the header
  60.  
  61. if hack_all_blocks_except_last_to_in_use and next_addr > addr then
  62. memory.write_u16_be(addr+0x8, 1)
  63. end
  64.  
  65. in_use = memory.read_u16_be(addr+0x8)
  66. id = memory.read_u16_be(addr+0xA)
  67. unused = memory.read_u32_be(addr+0xC) --just padding to make pointers align to 0x10, apparently...?
  68.  
  69. if in_use == 1 then
  70. used_memory = used_memory + 0x10 + blocksize
  71. used_count = used_count + 1
  72. bgcolor = 0xFF00FF00
  73. if blocksize == 0x330 then bgcolor = 0xFF0000FF end
  74. elseif in_use == 0 then
  75. free_memory = free_memory + 0x10 + blocksize
  76. free_count = free_count + 1
  77. bgcolor = 0xFFFF0000
  78. else
  79. bgcolor = 0xFFFFFFFF --impossible
  80. end
  81. gui.drawBox((addr-dynamic_memory_start)*client.screenwidth()/dynamic_memory_len-1, 0, (addr+0x10+blocksize-dynamic_memory_start)*client.screenwidth()/dynamic_memory_len+1, 50, 0x40000000, bgcolor)
  82. if dump_block_list then
  83. print(string.format("addr:%X next_addr:%X used:%X blocksize:%X id:%X", addr, next_addr, in_use, blocksize, id))
  84. end
  85.  
  86. if next_addr ~= addr + 0x10 + blocksize then
  87. break --shouldn't happen except on the last iteration, unless memory is corrupt.
  88. end
  89.  
  90. addr = next_addr
  91. end
  92. if hack_all_blocks_except_last_to_in_use then
  93. for addr2 = addr+0xC,dynamic_memory_end-4,4 do
  94. memory.write_u32_be(addr2, 0xDEADBEEF)
  95. end
  96. print("Filled last block with DEADBEEF, marked other blocks as used.")
  97. end
  98.  
  99. gui.drawText(24, 50, string.format("Used Memory: %X (%d blocks)", used_memory, used_count))
  100. gui.drawText(24, 65, string.format("Free Memory: %X (%d blocks)", free_memory, free_count))
  101.  
  102. end
  103.  
  104. menu_code_block = memory.read_u32_be(menu_code_pointer)
  105.  
  106. if menu_code_block > 0x80000000 then
  107. unknown = memory.read_u32_be(menu_code_block - 0x80000000)
  108. menu_code_1 = memory.read_u32_be(menu_code_block - 0x80000000 + 4)
  109. menu_code_2 = memory.read_u32_be(menu_code_block - 0x80000000 + 8)
  110. gui.drawText(24, 95, string.format("Menu Code: %X %X %X", unknown, menu_code_1, menu_code_2))
  111. end
  112.  
  113. menu = memory.read_u32_be(current_menu_pointer)
  114.  
  115. if menu > 0x80000000 then
  116. menu_icons = menu - 0x80000000
  117. menu_list_text = menu_icons + 33*4
  118. menu_values = menu_list_text + 33*4
  119. menu_enabled = menu_values + 33*4
  120. menu_extra_numbers = menu_enabled + 33*4 --price / upgrade icons
  121. menu_bottom_text = menu_extra_numbers + 33*4
  122. menu_info = menu_bottom_text + 33*4
  123.  
  124. shape = memory.read_u32_be(menu_info)
  125. double_dip_text_modifier = memory.read_u32_be(menu_info+4)
  126. double_dip_count = memory.read_u32_be(menu_info+8)
  127. length = memory.read_u32_be(menu_info+12)
  128. item_selected_when_opened = memory.read_u32_be(menu_info+16)
  129. item_selected_when_closed = memory.read_u16_be(menu_info+20)
  130.  
  131. selected = memory.read_s32_be(selected_menu_item)
  132.  
  133. gui.drawText(24, 110, string.format("Menu Shape: %X Length: %X Location: %X Selected: %d", shape, length, menu_icons, selected))
  134.  
  135. for i=-1,32 do
  136. if i >= length and i > 0 then break end
  137.  
  138. color = 0xFFFFFFFF
  139. if i==selected then
  140. color = 0xFFFFFF00
  141. end
  142.  
  143. icon = memory.read_u32_be(menu_icons + 4*i)
  144. list_text_group = memory.read_u16_be(menu_list_text + 4*i)
  145. list_text_value = memory.read_u16_be(menu_list_text+2 + 4*i)
  146. value = memory.read_u32_be(menu_values + 4*i)
  147. enabled = memory.read_u32_be(menu_enabled + 4*i)
  148. extra_number = memory.read_u32_be(menu_extra_numbers + 4*i)
  149. bottom_text_group = memory.read_u16_be(menu_bottom_text + 4*i)
  150. bottom_text_value = memory.read_u16_be(menu_bottom_text+2 + 4*i)
  151. gui.drawText(24, 140+15*i, string.format("%2d: Value=%X Icon=%X ListText=%X:%X Enabled=%X ExtraNum=%X BottomText=%X:%X", i, value, icon, list_text_group, list_text_value, enabled, extra_number, bottom_text_group, bottom_text_value), color)
  152. end
  153. end
  154.  
  155. end
  156. emu.frameadvance()
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement