Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- KatAM level mapping tool by Dotsarecool
- -- outputs a bunch of images of the level to be stitched together by another program
- local i = 0
- local x = 0
- local y = 0
- local done = false
- local level = -1;
- local w = 0
- local h = 0
- local BACKGROUND_LAYER_REGISTER = 0x3691
- local LEVEL_NUMBER = 0x20F40
- local LEVEL_WIDTH = 0x235EC
- local LEVEL_HEIGHT = 0x235EE
- -- camera position
- local CAMERA_X_POS = 0x23660
- local CAMERA_Y_POS = 0x23662
- -- "updated" camera position
- -- if camera is out of bounds, this register holds the camera position mod the level width/height
- local CAMERA_X_POS_2 = 0x23664
- local CAMERA_Y_POS_2 = 0x23666
- -- Start Main --
- console.writeline("Starting...")
- -- disable the background for prettier pictures
- memory.usememorydomain("IWRAM")
- memory.writebyte(BACKGROUND_LAYER_REGISTER, 0x08)
- memory.usememorydomain("EWRAM")
- -- grab level info
- level = memory.read_u16_le(LEVEL_NUMBER)
- -- grab width and height of level so we know how big the final map should be
- -- (I should have used these values to iterate over the level space, but these values were found after the majority of the script was written)
- w = memory.read_u16_le(LEVEL_WIDTH)
- h = memory.read_u16_le(LEVEL_HEIGHT)
- while not done do
- i = i + 1
- memory.write_s16_le(CAMERA_X_POS, x)
- memory.write_s16_le(CAMERA_Y_POS, y)
- emu.frameadvance()
- -- if we hit the right edge of the level
- if memory.read_s16_le(CAMERA_X_POS_2) ~= x then
- x = 0
- y = y + 20 * 8
- -- move camera down
- memory.write_s16_le(CAMERA_X_POS, x)
- memory.write_s16_le(CAMERA_Y_POS, y)
- emu.frameadvance()
- -- if we hit the bottom edge of the level
- if memory.read_s16_le(CAMERA_Y_POS_2) ~= y then
- -- we done, boys
- done = true
- end
- end
- if not done then
- local j = 0
- while j < 1 do -- set 1 to something higher to enable slow mode
- memory.write_s16_le(CAMERA_X_POS, x)
- memory.write_s16_le(CAMERA_Y_POS, y)
- --gui.drawText(20, 45, "x: " .. x)
- --gui.drawText(20, 55, "y: " .. y)
- emu.frameadvance()
- j = j + 1
- end
- -- save the image
- client.screenshot("C:/Users/Alex/Desktop/KatAM/level-" .. level .. "_w-" .. w .. "_h-" .. h .."/y-" .. y .."_x-" .. x .. ".png")
- x = x + 30 * 8
- end
- end
- memory.usememorydomain("IWRAM")
- -- enable background only
- memory.writebyte(BACKGROUND_LAYER_REGISTER, 0x01)
- emu.frameadvance()
- -- save image of the background
- client.screenshot("C:/Users/Alex/Desktop/KatAM/level-" .. level .. "_w-" .. w .. "_h-" .. h .."/b.png")
- -- restore background layers
- memory.writebyte(BACKGROUND_LAYER_REGISTER, 0x1B)
- console.writeline("Done.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement