zero00

InvisCharHelper

Jul 17th, 2021 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.83 KB | None | 0 0
  1. HERO_X = 0x17BD74;
  2. HERO_Y = 0x17BD75;
  3. HERO_DIR = 0x18b4c0;
  4.  
  5. POINTER_ADDR = 0x17daa0;
  6.  
  7. struct = {}
  8. cooldowns = {}
  9. cooldowns.INCREMENT_SLOT = 30;
  10. cooldowns.MOVE_CHARACTER_IN_FRONT_OF_HERO = 30;
  11. cooldowns.LOG_STRUCT = 30;
  12.  
  13. INCREMENT_SLOT_BUTTON = "P1 R2"
  14. MOVE_CHARACTER_IN_FRONT_OF_HERO_BUTTON = "P1 R3"
  15. LOG_STRUCT = "P1 Select"
  16.  
  17. function initializeRoom()
  18.   for i=0,6 do
  19.     emu.frameadvance()
  20.   end
  21.   FIRST_CHAR_ADDR = bit.band(mainmemory.read_u32_le(POINTER_ADDR), 0x00ffffff)
  22.   numChars = mainmemory.read_u8(FIRST_CHAR_ADDR - 0x10);
  23.   currentSlot = 0;
  24. end
  25.  
  26. function reduceCooldowns()
  27.   for cooldown,val in pairs(cooldowns) do
  28.     if (val > 0) then
  29.       cooldowns[cooldown] = val - 1
  30.     end
  31.   end
  32. end
  33.  
  34. function logStruct()
  35.   if (joypad.get()[LOG_STRUCT] and cooldowns.LOG_STRUCT == 0) then
  36.     console.log(struct)
  37.     cooldowns.LOG_STRUCT = 30;
  38.   end
  39. end
  40.  
  41. function incrementSlot()
  42.   if (joypad.get()[INCREMENT_SLOT_BUTTON] and cooldowns.INCREMENT_SLOT == 0) then
  43.     currentSlot = (currentSlot + 1) % (numChars + 1);
  44.     cooldowns.INCREMENT_SLOT = 30;
  45.   end
  46. end
  47.  
  48. function moveCharacterInFrontOfHero()
  49.   if (joypad.get()[MOVE_CHARACTER_IN_FRONT_OF_HERO_BUTTON] and cooldowns.MOVE_CHARACTER_IN_FRONT_OF_HERO == 0) then
  50.         local heroDir = mainmemory.read_u8(HERO_DIR)
  51.         local heroX = mainmemory.read_u8(HERO_X)
  52.         local heroY = mainmemory.read_u8(HERO_Y)
  53.         coords = {}
  54.         coords.X = heroX
  55.         coords.Y = heroY
  56.  
  57.         if (heroDir == 0) then
  58.             coords.Y = heroY + 2
  59.         elseif (heroDir == 1) then
  60.             coords.Y = heroY - 2
  61.         elseif (heroDir == 2) then
  62.             coords.X = heroX - 2
  63.         elseif (heroDir == 3) then
  64.             coords.X = heroX + 2
  65.         end
  66.  
  67.         mainmemory.write_u8(struct.address, coords.X)
  68.         mainmemory.write_u8(struct.address + 1, coords.Y)
  69.  
  70.     cooldowns.MOVE_CHARACTER_IN_FRONT_OF_HERO = 30;
  71.   end
  72. end
  73.  
  74. function readCharacterStructFromMemory(slot)
  75.   local struct = {}
  76.   local address = FIRST_CHAR_ADDR + (slot * 0x18);
  77.  
  78.   struct.slot = slot;
  79.   struct.address = address;
  80.  
  81.   struct.X = mainmemory.read_u8(address);
  82.   struct.Y = mainmemory.read_u8(address + 1);
  83.   struct.subpixelX = mainmemory.read_s8(address + 2);
  84.   struct.subpixelY = mainmemory.read_s8(address + 3);
  85.   struct.direction = mainmemory.read_u8(address + 4);
  86.   struct.movementSpeed = mainmemory.read_s8(address + 5);
  87.   struct.unknown1 = mainmemory.read_u16_le(address + 6);
  88.   struct.memAddress1 = mainmemory.read_u32_le(address + 8);
  89.   struct.memAddress2 = mainmemory.read_u32_le(address + 12);
  90.   struct.memAddress3 = mainmemory.read_u32_le(address + 16);
  91.   struct.unknown2 = mainmemory.read_u16_le(address + 20);
  92.   struct.unknown3 = mainmemory.read_u16_le(address + 22);
  93.   return struct
  94. end
  95.  
  96. function drawTextForStruct(struct)
  97.   local guiTextTemplate = [[
  98.   HeroX: %d, HeroY: %d
  99.   Address: 0x%06x, Slot: %d, Num Slots: %d
  100.   X: %d, Y: %d, sX: %d, sY: %d, D: %d, MS: %d
  101.   Unknown 1: 0x%04x
  102.   Unknown 2: 0x%04x
  103.   Unknown 3: 0x%04x
  104.   Address 1: 0x%08x
  105.   Address 2: 0x%08x
  106.   Address 3: 0x%08x
  107.   ]]
  108.  
  109.   local guiText = string.format(guiTextTemplate,
  110.     mainmemory.read_u8(HERO_X),
  111.     mainmemory.read_u8(HERO_Y),
  112.     struct.address, currentSlot, numChars,
  113.     struct.X, struct.Y, struct.subpixelX, struct.subpixelY, struct.direction, struct.movementSpeed,
  114.     struct.unknown1,
  115.     struct.unknown2,
  116.     struct.unknown3,
  117.     struct.memAddress1,
  118.     struct.memAddress2,
  119.     struct.memAddress3
  120.   )
  121.  
  122.   gui.drawText(0, 32, guiText, nil, nil, 16);
  123. end
  124.  
  125. initializeRoom()
  126.  
  127. while true do
  128.   local curFirstCharAddr = bit.band(mainmemory.read_u32_le(POINTER_ADDR), 0x00ffffff)
  129.   if (curFirstCharAddr ~= FIRST_CHAR_ADDR) then
  130.     gui.cleartext()
  131.     initializeRoom()
  132.   end
  133.   reduceCooldowns()
  134.   incrementSlot()
  135.   logStruct()
  136.   moveCharacterInFrontOfHero()
  137.   struct = readCharacterStructFromMemory(currentSlot)
  138.   drawTextForStruct(struct)
  139.   emu.frameadvance();
  140. end
Add Comment
Please, Sign In to add comment