User File #19833044932372339

Upload All User Files

#19833044932372339 - Wario Land II - Navigation script v3

WL2Overlay.lua
1163 downloads
Uploaded 1/2/2015 4:03 AM by slamo (see all 61)
Update 1/1/15: Now displays secret exit doors.
Displays an overlay identifying tiles in WL2, for use in navigating and visualizing glitch rooms.
Colors:
Red - Solid or unknown
Pink - Breakable
Green - Doors...the tile properties for the doors are:
0x4ECD: Mini-game
0x4EDB: Regular door
0x4F3A: Normal exit
0x4F60: Secret exit
Blue - Water
White - Platform
The text in the upper left displays the tile properties of the blocks above, at, and below Wario respectively. The first column is the RAM address where the tile ID can be found. If this is above 0xA000 then it's accessing the RAM banks (where level data is normally kept) - between 0xA000-0xBFFF is bank 2, between 0xC000-0xDFFF is bank 3, and between 0xE000-0xFFFF is bank 4. The second column is the raw tile property.
local x, y, camx, camy, tref, ttype, ttypehigh, tcolor, warpdest

function bitswap (swappy)
	nib2 = bit.band(swappy,0xF)
	return (nib2*0x10+bit.rshift(swappy,4))
end

function gettile (wx,wy)
	hix = bit.rshift(bit.band(0xFF00,wx),8)
	hiy = bit.rshift(bit.band(0xFF00,wy),8)
	lox = bit.band(0xFF,wx)
	loy = bit.band(0xFF,wy)
	ccea = bit.band(bitswap(bit.band(hiy,0x0F))+bit.band(bitswap(loy),0x0F)+0xA0,0xFF)
	cceb = bitswap(bit.band(hix,0x0F))+bit.band(bitswap(lox),0x0F)
	rawloc = ccea*0x100+cceb -- not the final location!!! can vary if above 0xa000
	return (rawloc)
	-- return (bit.band(0x2000 + 0x100*math.floor(wy/16+1) + math.floor(wx/16),0x7FFF)) works for most space, not glitch rooms
end

function tileid (ntile)
	if (ntile >= 0xa000) then
		memory.usememorydomain('Cart RAM') -- where normal level data is
		realloc = ntile - 0x8000
	else
		memory.usememorydomain('System Bus')
		realloc = ntile
	end
	tlookup = memory.readbyte(realloc)
	memory.usememorydomain('ROM')
	return (memory.read_u16_le(0x7c002+tref+bit.band(tlookup*2,0xFF)))
end

while true do
	x = mainmemory.read_u16_be(0x153c) -- position in level
	y = mainmemory.read_u16_be(0x153a)
	camx = mainmemory.readbyte(0x660) -- position relative to upper left camera edge
	camy = mainmemory.readbyte(0x65f)
	tref = mainmemory.read_u16_be(0x704)
	-- warpdest = mainmemory.readbyte(0xa1) -- sector coordinates for a warp (??)
	-- 160x144
	--gui.drawText(3,130,string.format("%X",bit.rshift(warpdest,4))..' '..string.format("%X",bit.band(warpdest,0xF)))
	for i = -1,17,1 do
		for j = -1,17,1 do
			ttype = tileid(gettile(x-camx+15+16*i,y-camy+15+16*j))
			ttypehigh = bit.band(ttype,0xFF00)
			if (ttype~=0x47ab) and (ttype~=0x49a7) and not ((ttype>=0x4e29) and (ttype<=0x4e39)) and not ((ttype>=0x5400) and (ttype<=0x54ff)) then
			--if (ttype~=0x47ab) and (ttype~=0x4cf3) and (ttype~=0x4cef) and (ttype~=0x4d03) and (ttype~=0x4cff) and (ttype~=0x4e29) and (ttype~=0x4e35) and (ttype~=0x4f3a) then
				if (ttype==0x4ecd) or (ttype==0x4edb) or (ttype==0x4f3a) or (ttype==0x4f60) then -- door, minigame, exit
					tcolor = 'GREEN' 
				elseif (ttype==0x4e8a) then -- water
					tcolor = 'BLUE'
				elseif (ttype==0x4a10) then -- platform
					tcolor = 'WHITE'
				elseif (ttype>0x4a70) and (ttype<0x4d9f) or (ttype==0x4a10) then -- breakable
					tcolor = 'PINK'
				else -- solid or unknown
					tcolor = 'RED' 
				end
				gui.drawBox((camx-x)%16-8+16*i,(camy-y)%16-16+16*j,(camx-x)%16+7+16*i,(camy-y)%16+16*j-1,tcolor)
			end
		end
	end
	gui.drawText(3,3,string.format("%X",gettile(x,y-32))..' '..string.format("%X",tileid(gettile(x,y-32))))
	gui.drawText(3,12,string.format("%X",gettile(x,y-16))..' '..string.format("%X",tileid(gettile(x,y-16))))
	gui.drawText(3,21,string.format("%X",gettile(x,y))..' '..string.format("%X",tileid(gettile(x,y))))
	emu.frameadvance()
end