User File #16322306121342073

Upload All User Files

#16322306121342073 - Wario Land II - Navigation script v2

WL2Overlay.lua
1113 downloads
Uploaded 7/28/2014 1:28 AM by slamo (see all 61)
Fixed version of the WL2 navigation script.
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) then -- door, minigame, exit
					tcolor = 'BLACK' 
				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