User File #23959481256092449

Upload All User Files

#23959481256092449 - Brave Fencer Musashi RNG Steps Lua

BFM RNG.lua
897 downloads
Uploaded 7/7/2015 12:05 AM by ALAKTORN (see all 34)
Prints: RNGvalue (#ofsteps)
function RNGStep(iRNG)
	local High1 = math.floor(iRNG / 65536)
	local Low1 = math.floor(iRNG % 65536)
	local High2 = math.floor(1103515245 / 65536)
	local Low2 = math.floor(1103515245 % 65536)
	 
	local NewHigh = (High1 * Low2 + High2 * Low1) % 65536;
	local NewLow = Low1 * Low2
	 
	return (NewHigh * 65536 + NewLow + 12345) % 4294967296;
	--return (1103515245 * iRNG + 12345) % 4294967296
end

function RNGSteps(iRNG, steps)
	for i = 1, steps do
		iRNG = RNGStep(iRNG)
	end
	return iRNG
end

function getNumSteps(oldRNG, newRNG, maxSearch)
	if oldRNG == -1 then
		return -2
	end
	if oldRNG == newRNG then
		return 0
	end
	for i = 1, maxSearch do
		oldRNG = RNGStep(oldRNG)
		if oldRNG == newRNG then
			return i
		end
	end
	return -1;
end

function readRNG()
	return memory.readdword(0x00078980)
end

RNG = -1
function printRNGChanges()
	newRNG = readRNG()
	if RNG ~= newRNG then
		print(newRNG .. " (" .. getNumSteps(RNG, newRNG, 1000) .. ")")
		RNG = newRNG
	end
end

-- Main loop
function main()
	printRNGChanges()
end

emu.registerbefore(main)