Advertisement
MrCheeze

pm_dynamic_memory.lua

Jul 31st, 2016
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. --advanced version: http://pastebin.com/kLNXUxcy
  2.  
  3. dynamic_memory_start = 0x2FB800
  4. dynamic_memory_end = 0x34F800
  5. dynamic_memory_len = dynamic_memory_end - dynamic_memory_start
  6. particle_table = 0x0B4378
  7.  
  8. while true do
  9.  
  10. addr = dynamic_memory_start
  11.  
  12. gui.drawBox(0, 0, client.bufferwidth(), 50, 0xFF000000, 0xFF000000)
  13.  
  14. used_memory = 0
  15. free_memory = 0
  16. used_count = 0
  17. free_count = 0
  18.  
  19. while addr >= dynamic_memory_start and addr < dynamic_memory_end do
  20. next_addr = memory.read_u32_be(addr) - 0x80000000
  21. blocksize = memory.read_u32_be(addr+0x4) + 4 --not including the 0xC bytes for the header
  22. in_use = memory.read_u16_be(addr+0x8)
  23. id = memory.read_u16_be(addr+0xA)
  24. if in_use == 1 then
  25. used_memory = used_memory + 0xC + blocksize
  26. used_count = used_count + 1
  27. bgcolor = 0xFF00FF00
  28. elseif in_use == 0 then
  29. free_memory = free_memory + 0xC + blocksize
  30. free_count = free_count + 1
  31. bgcolor = 0xFFFF0000
  32. else
  33. bgcolor = 0xFFFFFFFF --impossible
  34. end
  35. gui.drawBox((addr-dynamic_memory_start)*client.bufferwidth()/dynamic_memory_len-1, 0,
  36. (addr+0xC+blocksize-dynamic_memory_start)*client.bufferwidth()/dynamic_memory_len, 50, 0x40000000, bgcolor)
  37. --print(string.format("addr:%X next_addr:%X blocksize:%X in_use:%X id:%X", addr, next_addr, blocksize, in_use, id))
  38.  
  39. if next_addr ~= addr + 0xC + blocksize then
  40. break --shouldn't happen except on the last iteration, unless memory is corrupt.
  41. end
  42.  
  43. addr = next_addr
  44. end
  45. gui.text(30, 50, string.format("Used Memory: %X (%d blocks)", used_memory, used_count))
  46. gui.text(30, 65, string.format("Free Memory: %X (%d blocks)", free_memory, free_count))
  47.  
  48. particle_count = 0
  49. for i=0,0x5F do
  50. if memory.read_u32_be(particle_table + 4*i) > 0 then
  51. particle_count = particle_count + 1
  52. end
  53. end
  54.  
  55. gui.text(30, 80, string.format("Particle count: %d", particle_count))
  56.  
  57. emu.frameadvance()
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement