User File #24508776408376192

Upload All User Files

#24508776408376192 - Mega Man 4 RNG predictor

MegaMan 4.lua
1116 downloads
Uploaded 7/31/2015 5:48 PM by Truncated (see all 22)
RNG viewer and predictor.
Has a few bugs. Does not handle lag. Does not handle load state.
RNG1 = memory.readbyte(0xE4)
RNG2 = memory.readbyte(0xE5)
RNG3 = memory.readbyte(0xE6)
RNG4 = memory.readbyte(0xE7)
	
PRNG1 = 0;
PRNG2 = 0;
PRNG3 = 0;
PRNG4 = 0;

function drawMMVals()

	mmXScroll = memory.readbytesigned(0x25);
	mmXPosPix = memory.readbyte(0x27);
	mmXPosSub = memory.readbyte(0x318);
	
	mmXScreen = mmXPosPix-mmXScroll;
	
	mmXSpeedPix = memory.readbyte(0x3C0);
	mmXSpeedSub = memory.readbyte(0x3A8);
	mmXDirection = memory.readbytesigned(0x31);
	
	if(mmXPrev == mmXPosPix) then
	
		mmXDirection = 0;
		
	end
	
	mmXPrev = mmXPosPix;
	
	if(mmXDirection == 2) then
	
		mmXSpeedPix = -mmXSpeedPix;
		mmXSpeedSub = -mmXSpeedSub;
		
	elseif(mmXDirection == 0) then
		
		mmXSpeedPix = 0;
		mmXSpeedSub = 0;
		
	end;
	
	mmYScroll = memory.readbytesigned(0x26);
	mmYPosPix = memory.readbyte(0x378);
	mmYPosSub = memory.readbyte(0x360);
	
	mmYScreen = mmYPosPix-mmYScroll;
	
	mmYSpeedPix = memory.readbytesigned(0x3F0);
	mmYSpeedSub = memory.readbytesigned(0x3D8);
	
	gui.text(mmXScreen, mmYScreen, "[" .. mmXPosPix .. "." .. mmXPosSub .. "," .. mmYPosPix .. "." .. mmYPosSub .. "]");
	gui.text(mmXScreen, mmYScreen + 7, "[" .. mmXSpeedPix .. "." .. mmXSpeedSub .. "," .. mmYSpeedPix .. "." .. mmYSpeedSub .. "]");
	
end;

function PredictRNG()
	RNG1AND2 = bit.band(RNG1, 0x02)
	RNG2AND2 = bit.band(RNG2, 0x02)
	XORAND2 = bit.bxor(RNG1AND2, RNG2AND2)
	CARRY1 = bit.band(RNG1, 0x01)
	CARRY2 = bit.band(RNG2, 0x01)
	CARRY3 = bit.band(RNG3, 0x01)
	PRNG1 = bit.rshift(RNG1, 1) + XORAND2 * 0x40
	PRNG2 = bit.rshift(RNG2, 1) + CARRY1 * 0x80
	PRNG3 = bit.rshift(RNG3, 1) + CARRY2 * 0x80
	PRNG4 = bit.rshift(RNG4, 1) + CARRY3 * 0x80


	RNG1 = memory.readbyte(0xE4)
	RNG2 = memory.readbyte(0xE5)
	RNG3 = memory.readbyte(0xE6)
	RNG4 = memory.readbyte(0xE7)

	changecol1 = "red"
	if RNG1 == PRNG1 then
		changecol1 = "green"
	end
	changecol2 = "red"
	if RNG2 == PRNG2 then
		changecol2 = "green"
	end
	changecol3 = "red"
	if RNG3 == PRNG3 then
		changecol3 = "green"
	end
	changecol4 = "red"
	if RNG4 == PRNG4 then
		changecol4 = "green"
	end
	
	gui.text(150, 220, string.format("RNG:"), "gray");
	gui.text(175, 220, string.format("%2X", RNG1), changecol1);
	gui.text(190, 220, string.format("%2X", RNG2), changecol2);
	gui.text(205, 220, string.format("%2X", RNG3), changecol3);
	gui.text(220, 220, string.format("%2X", RNG4), changecol4);
	
	
		
end 


while true do
	drawMMVals();
	PredictRNG();
	emu.frameadvance();
end;