User File #638989149801544186

Upload All User Files

#638989149801544186 (unlisted) - Emma at the farm minigame 2 delay predictor

minigame2_delay_predictor_v2.lua
System: Nintendo DS
10 downloads
Uploaded 14 days ago by toca (see all 4)
A Lua script to find out how fast the second minigame can be completed depending on the date and time of the DS (which is how the RNG is initialized in this game)
local initialRNG = 0x12d5367b -- earliest time
local RNG = nil
local timeoffset = 0
local delaysequence = {}
local prevegg = -1
local currentegg = -1
local f = io.open("delaysequence_v2.txt", "w")

local function close_log()
	if f then
		f:flush()
		f:close()
		f = nil
	end
end

event.onexit(close_log, "file_closed")

local function advanceRNG(x)
	local RNGkey = 0x41C64E6D
	local RNGoffset = 0x3039
	y_righthalf = x%100000
	y_lefthalf = (x-y_righthalf)/100000
	local y = (((((y_lefthalf*RNGkey) % 2^32)*100000+((y_righthalf*RNGkey) % 2^32)) % 2^32)+RNGoffset) % 2^32
	return y
end

local function egg_generator(x)
	return (((x >> 16) & 0x7FFF)%4)
end

local function cooldown_generator(x)
	return (60 + 15*(((x >> 16) & 0x7FFF)%2))
end

local function generate_tables()
	prevegg = -1
	currentegg = -1
	delaysequence = {}	-- re-initialize
	for loop=1,9 do
		-- function 1: determine cooldown
			RNG=advanceRNG(RNG)
			table.insert(delaysequence,cooldown_generator(RNG))
		-- function 2: determine where next egg drops & store it
			while prevegg == currentegg do	-- if duplicate: try again
				RNG=advanceRNG(RNG)
				currentegg = egg_generator(RNG)
			end
			prevegg = currentegg
	end
end

for bigloop2=1,1000 do
	RNG = initialRNG
	for bigloop=1,8309 do	-- 8482-175+4 = 8311
		RNG = advanceRNG(RNG)
	end
	local minigamestartRNG = RNG
	generate_tables()
	local totaldelay = 0
	for _, v in ipairs(delaysequence) do totaldelay = totaldelay + v end
	f:write(string.format("%d\t %08x\t %08x\t %d\n",timeoffset,initialRNG,minigamestartRNG,totaldelay))
	initialRNG = initialRNG + 1
	timeoffset = timeoffset + 1
end