Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HERO_X = 0x17BD74;
- HERO_Y = 0x17BD75;
- HERO_DIR = 0x18b4c0;
- POINTER_ADDR = 0x17daa0;
- struct = {}
- cooldowns = {}
- cooldowns.INCREMENT_SLOT = 30;
- cooldowns.MOVE_CHARACTER_IN_FRONT_OF_HERO = 30;
- cooldowns.LOG_STRUCT = 30;
- INCREMENT_SLOT_BUTTON = "P1 R2"
- MOVE_CHARACTER_IN_FRONT_OF_HERO_BUTTON = "P1 R3"
- LOG_STRUCT = "P1 Select"
- function initializeRoom()
- for i=0,6 do
- emu.frameadvance()
- end
- FIRST_CHAR_ADDR = bit.band(mainmemory.read_u32_le(POINTER_ADDR), 0x00ffffff)
- numChars = mainmemory.read_u8(FIRST_CHAR_ADDR - 0x10);
- currentSlot = 0;
- end
- function reduceCooldowns()
- for cooldown,val in pairs(cooldowns) do
- if (val > 0) then
- cooldowns[cooldown] = val - 1
- end
- end
- end
- function logStruct()
- if (joypad.get()[LOG_STRUCT] and cooldowns.LOG_STRUCT == 0) then
- console.log(struct)
- cooldowns.LOG_STRUCT = 30;
- end
- end
- function incrementSlot()
- if (joypad.get()[INCREMENT_SLOT_BUTTON] and cooldowns.INCREMENT_SLOT == 0) then
- currentSlot = (currentSlot + 1) % (numChars + 1);
- cooldowns.INCREMENT_SLOT = 30;
- end
- end
- function moveCharacterInFrontOfHero()
- if (joypad.get()[MOVE_CHARACTER_IN_FRONT_OF_HERO_BUTTON] and cooldowns.MOVE_CHARACTER_IN_FRONT_OF_HERO == 0) then
- local heroDir = mainmemory.read_u8(HERO_DIR)
- local heroX = mainmemory.read_u8(HERO_X)
- local heroY = mainmemory.read_u8(HERO_Y)
- coords = {}
- coords.X = heroX
- coords.Y = heroY
- if (heroDir == 0) then
- coords.Y = heroY + 2
- elseif (heroDir == 1) then
- coords.Y = heroY - 2
- elseif (heroDir == 2) then
- coords.X = heroX - 2
- elseif (heroDir == 3) then
- coords.X = heroX + 2
- end
- mainmemory.write_u8(struct.address, coords.X)
- mainmemory.write_u8(struct.address + 1, coords.Y)
- cooldowns.MOVE_CHARACTER_IN_FRONT_OF_HERO = 30;
- end
- end
- function readCharacterStructFromMemory(slot)
- local struct = {}
- local address = FIRST_CHAR_ADDR + (slot * 0x18);
- struct.slot = slot;
- struct.address = address;
- struct.X = mainmemory.read_u8(address);
- struct.Y = mainmemory.read_u8(address + 1);
- struct.subpixelX = mainmemory.read_s8(address + 2);
- struct.subpixelY = mainmemory.read_s8(address + 3);
- struct.direction = mainmemory.read_u8(address + 4);
- struct.movementSpeed = mainmemory.read_s8(address + 5);
- struct.unknown1 = mainmemory.read_u16_le(address + 6);
- struct.memAddress1 = mainmemory.read_u32_le(address + 8);
- struct.memAddress2 = mainmemory.read_u32_le(address + 12);
- struct.memAddress3 = mainmemory.read_u32_le(address + 16);
- struct.unknown2 = mainmemory.read_u16_le(address + 20);
- struct.unknown3 = mainmemory.read_u16_le(address + 22);
- return struct
- end
- function drawTextForStruct(struct)
- local guiTextTemplate = [[
- HeroX: %d, HeroY: %d
- Address: 0x%06x, Slot: %d, Num Slots: %d
- X: %d, Y: %d, sX: %d, sY: %d, D: %d, MS: %d
- Unknown 1: 0x%04x
- Unknown 2: 0x%04x
- Unknown 3: 0x%04x
- Address 1: 0x%08x
- Address 2: 0x%08x
- Address 3: 0x%08x
- ]]
- local guiText = string.format(guiTextTemplate,
- mainmemory.read_u8(HERO_X),
- mainmemory.read_u8(HERO_Y),
- struct.address, currentSlot, numChars,
- struct.X, struct.Y, struct.subpixelX, struct.subpixelY, struct.direction, struct.movementSpeed,
- struct.unknown1,
- struct.unknown2,
- struct.unknown3,
- struct.memAddress1,
- struct.memAddress2,
- struct.memAddress3
- )
- gui.drawText(0, 32, guiText, nil, nil, 16);
- end
- initializeRoom()
- while true do
- local curFirstCharAddr = bit.band(mainmemory.read_u32_le(POINTER_ADDR), 0x00ffffff)
- if (curFirstCharAddr ~= FIRST_CHAR_ADDR) then
- gui.cleartext()
- initializeRoom()
- end
- reduceCooldowns()
- incrementSlot()
- logStruct()
- moveCharacterInFrontOfHero()
- struct = readCharacterStructFromMemory(currentSlot)
- drawTextForStruct(struct)
- emu.frameadvance();
- end
Add Comment
Please, Sign In to add comment