User File #65650966036547896

Upload All User Files

#65650966036547896 -

memory corruption visualizer.lua
433 downloads
Uploaded 8/26/2020 2:13 PM by hellagels (see all 14)
require("bit")

function getShift()
	MyPositionX=memory.readwordsigned(0x02000462)
	MyPositionSubX=memory.readword(0x02000460)/65536
	MyPositionY=memory.readwordsigned(0x02000466)
	MyPositionSubY=memory.readword(0x02000464)/65536
	CameraX=memory.readwordsigned(0x0200A446)
	CameraY=memory.readwordsigned(0x0200A44A)
	X=MyPositionX+MyPositionSubX+CameraX
	Y=MyPositionY+MyPositionSubY+CameraY
	XShift=math.floor(X/256)
	YShift=math.floor(Y/256)
	map_xy = memory.readword(0x02000070)
	map_castle = map_xy % 2
	map_x = ((map_xy - map_castle) % 0x100 / 2)
	map_x2 = map_x % 32
	map_y = (map_xy - map_x * 2 - map_castle)/0x100
	XShift2 = math.floor((XShift+map_x)/32)
	YShift2 = math.floor((YShift+map_y)/40)
	Shift = YShift2 + XShift2 - 1
	return Shift
end

function getcastle()
	map_xy = memory.readword(0x02000070)
	map_castle = map_xy % 2
	return map_castle
end

function drawcross()
	MyPositionX=memory.readwordsigned(0x02000462)
	MyPositionSubX=memory.readword(0x02000460)/65536
	MyPositionY=memory.readwordsigned(0x02000466)
	MyPositionSubY=memory.readword(0x02000464)/65536
	CameraX=memory.readwordsigned(0x0200A446)
	CameraY=memory.readwordsigned(0x0200A44A)
	X=MyPositionX+MyPositionSubX+CameraX
	Y=MyPositionY+MyPositionSubY+CameraY
	map_xy = memory.readword(0x02000070)
	map_castle = map_xy % 2
	map_x = ((map_xy - map_castle) % 0x100 / 2)
	map_x2 = map_x % 32
	map_y = (map_xy - map_x * 2 - map_castle)/0x100
	XShift=(math.floor(X/64)+map_x2*4)%128
	YShift=(math.floor(Y/64)+map_y*4)%160
	gui.line(XShift+62,0,XShift+62,159,"#FFFF8888")
	gui.line(64-2,YShift,191-2,YShift,"#FFFF8888")
end

function line1()
	for i=0,19, 1 do
		Shift =getShift()*320
		castle = getcastle()
		txt=bit.tohex(0x020001CC+16*i+castle*4+Shift,-8)
		txt2=bit.tohex(0x020001CC+16*i+castle*4+Shift+8,-8)
		gui.text(28,8*i-2,txt)
		gui.text(192,8*i+2,txt2)
	end
end

function line2()
	for k = 0,1,1 do
		for i=0,39, 1 do
			Shift =getShift()*320
			castle = getcastle()
			a = memory.readbyte(0x020001CC + i * 8 + Shift + k*2 + castle*4)
			for j = 1, 8, 1 do
				b = a%2
				if b == 1 then
					gui.drawbox(j*4+k*64+64-6, i*4,j*4+k*64+64-6+2, i*4+2,"#00FFFFFF")
				else
					gui.drawbox(j*4+k*64+64-6, i*4,j*4+k*64+64-6+2, i*4+2,"#008888FF")
				end
				a = (a-b)/2
			end
		end
	end
end

function line3()
	for k = 0,1,1 do
		for i=0,39, 1 do
			Shift =getShift()*320
			castle = getcastle()
			a = memory.readbyte(0x020001CC + i * 8 + Shift + k*2+1 + castle*4)
			for j = 1, 8, 1 do
				b = a%2
				if b == 1 then
					gui.drawbox(j*4+k*64+96-6, i*4,j*4+k*64+96-6+2, i*4+2,"#00FF00FF")
				else
					gui.drawbox(j*4+k*64+96-6, i*4,j*4+k*64+96-6+2, i*4+2,"#008800FF")
				end
				a = (a-b)/2
			end
		end
	end
end

function showall()
	gui.drawbox(0,0,239,159,"black")
	line1()
	line2()
	line3()
	drawcross()
end

gui.register(showall)