User File #16161040464663009

Upload All User Files

#16161040464663009 - Wario Land 3 - Navigation script

WL3Overlay.lua
1127 downloads
Uploaded 7/20/2014 7:10 PM by slamo (see all 61)
Displays an overlay identifying tiles in WL3, for use in navigating and visualizing glitch rooms.
Colors:
Red - Solid or unknown
Pink - Breakable (by Wario or other means)
Black - Doors (includes golf, exit, and auto-warp)
Brown - Ladder/climbable
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, 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)
	return (mainmemory.read_u16_le(0xd00+bit.band(tlookup*2,0xFF)))
end

while true do
	x = mainmemory.read_u16_be(0xa63) -- position in level
	y = mainmemory.read_u16_be(0xa61)
	camx = mainmemory.readbyte(0xa88) -- position relative to upper left camera edge
	camy = mainmemory.readbyte(0xa87)
	-- 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~=0x4020) and (ttype~=0x4821) and (ttype~=0x484c) and (ttype~=0x4262) then
				if (ttype==0x45CB) or (ttype==0x45FA) or (ttype==0x477e) or (ttype==0x46f9) or (ttype==0x47b0) or (ttype==0x47de) then -- door, golf door, exit, warp tile
					tcolor = 'BLACK' 
				elseif (ttype>0x49F0) and (ttype<0x54b4) then -- breakable
					tcolor = 'PINK'
				elseif (ttype==0x4208) or (ttype==0x49ae) or (ttype==0x423f) then -- platform
					tcolor = 'WHITE'
				elseif (ttype==0x42c3) or (ttype==0x42e5) or (ttype==0x42fe) or (ttype==0x4934) then -- ladder
					tcolor = 'BROWN'
				elseif (ttype>0x41a0) and (ttype<0x41ff) then -- water
					tcolor = 'BLUE'
				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