User File #46583544987304682

Upload All User Files

#46583544987304682 (unlisted) - Luminous Arc RNGs Lua

Luminous Arc RNGs.lua
99 downloads
Uploaded 4/20/2018 9:15 PM by ALAKTORN (see all 34)
-- RNG addresses
function readRNGs()
	return memory.readdword(0x0215B384), memory.readdword(0x021376A4), memory.readdword(0x021474AC) -- USA version
end

-- RNG calculations
function RNGStep(iRNG)
	local High1 = math.floor(iRNG / 65536)
	local Low1 = math.floor(iRNG % 65536)
	local High2 = math.floor(1566083941 / 65536)
	local Low2 = math.floor(1566083941 % 65536)
	 
	local NewHigh = (High1 * Low2 + High2 * Low1) % 65536;
	local NewLow = Low1 * Low2
	 
	return (NewHigh * 65536 + NewLow + 2531011) % 4294967296;
	--return (1566083941 * iRNG + 2531011) % 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 == newRNG then
		return 0
	end
	for i = 1, maxSearch do
		oldRNG = RNGStep(oldRNG)
		if oldRNG == newRNG then
			return i
		end
	end
	return -1;
end
--[[
a = 1747795628
b = 1027477479   
print(getNumSteps(a, b, 10000))
]]

function InvRNGStep(iRNG)
	local High1 = math.floor(iRNG / 65536)
	local Low1 = math.floor(iRNG % 65536)
	local High2 = math.floor(1786162797 / 65536)
	local Low2 = math.floor(1786162797 % 65536)
	 
	local NewHigh = (High1 * Low2 + High2 * Low1) % 65536;
	local NewLow = Low1 * Low2
	 
	return (NewHigh * 65536 + NewLow + 3284393209) % 4294967296;
	--return (1786162797 * iRNG + 3284393209) % 4294967296
end

function InvRNGSteps(iRNG, steps)
	for i = 1, steps do
		iRNG = InvRNGStep(iRNG)
	end
	return iRNG
end
--[[
c = 3675429441
d = 1   
print(InvRNGSteps(c, d))
]]

RNG1 = -1
RNG2 = -1
RNG3 = -1
function printRNGChanges()
	Frame = memory.readdword(0x023FFC3C) -- USA version
	newRNG1, newRNG2, newRNG3 = readRNGs()
	if RNG1 ~= newRNG1 then
		numSteps = getNumSteps(RNG1, newRNG1, 1000)
		if numSteps ~= -1 then
			print("Movement RNG: " .. newRNG1 .. " (" .. numSteps .. ")" .. " at frame " .. Frame)
		-- Unknown advance
		else print("Movement RNG: " .. newRNG1 .. " at frame " .. Frame)
		end
		RNG1 = newRNG1
	end
	if RNG2 ~= newRNG2 then
		numSteps = getNumSteps(RNG2, newRNG2, 1000)
		if numSteps ~= -1 then
			print("Encounter RNG: " .. newRNG2 .. " (" .. numSteps .. ")" .. " at frame " .. Frame)
		-- Unknown advance
		else print("Encounter RNG: " .. newRNG2 .. " at frame " .. Frame)
		end
		RNG2 = newRNG2
	end
	if RNG3 ~= newRNG3 then
		numSteps = getNumSteps(RNG3, newRNG3, 1000)
		if numSteps ~= -1 then
			print("Dmg/hit RNG: " .. newRNG3 .. " (" .. numSteps .. ")" .. " at frame " .. Frame)
		-- Unknown advance
		else print("Dmg/hit RNG: " .. newRNG3 .. " at frame " .. Frame)
		end
		RNG3 = newRNG3
	end
end
--memory.registerwrite(0x0215B384, printRNGChanges)

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

emu.registerbefore(main)