function nextrng(r1, r2, r3)
return AND(XOR(SHIFT(r3, 5), SHIFT(r2, -11), SHIFT(r1, -1), SHIFT(r2, 15)),0xFFFF)
end
function rngsim(n)
local rngbase=0x03000000
local result = { memory.readword(rngbase+4), memory.readword(rngbase+2), memory.readword(rngbase+0) }
for i = 4, n do
result[i] = nextrng(result[i-3],result[i-2],result[i-1])
end
return result
end
function printstats(n)
if n == 255 then
n = "---"
end
return n
end
function setoperator()
if j == 0 then
op[ind] = "="
elseif j == 1 then
op[ind] = "<"
elseif j == 2 then
op[ind] = ">"
elseif j == 3 then
op[ind] = "<="
elseif j == 4 then
op[ind] = ">="
elseif j == 5 then
op[ind] = "!="
end
z = input.get()
if z.left and otherpressed["left"] == false then
otherpressed["left"] = true
j = j - 1
if j < 0 then
j = 5
end
elseif z.right and otherpressed["right"] == false then
otherpressed["right"] = true
j = j + 1
if j > 5 then
j = 0
end
elseif z.enter and otherpressed["enter"] == false then
otherpressed["enter"] = true
ind = ind + 1
j = 1
a1 = " "
a2 = " "
elseif z.H and otherpressed["H"] == false then
otherpressed["H"] = true
if hit[ind] == "" then
hit[ind] = true
else
hit[ind] = ""
end
end
if not z.left and not z.right and not z.enter and not z.H then
otherpressed["left"] = false
otherpressed["right"] = false
otherpressed["enter"] = false
otherpressed["H"] = false
end
end
function captureinput()
if op[ind] == "" then
for i = 0, 9 do
local s = tostring(i)
n = input.get()
if n[s] then
if numberpressed[s] == false then
numberpressed[s] = true
if a1 == " " then
a1 = i
rn[index] = tonumber(a1 .. "0")
else
a2 = i
rn[index] = tonumber(a1 .. a2)
index = index + 1
op[ind] = "<"
j = 1
end
break
end
else
numberpressed[s] = false
end
end
else
setoperator()
end
end
function emptyarray(x,n)
for i=1, n, 1 do
x[i] = ""
end
return x
end
function compareRN()
local limit = ind-1
local y, hits
d = 1
for i = 4, 501-limit, 1 do
y = 0
hits = 0
x = limit
list = {}
for a = 1, x, 1 do
if hit[a] == "" then
list[a] = math.floor(rngs[i-1+a+hits]/655.36)
else
list[a] = math.floor((math.floor(rngs[i-1+a+hits]/655.36)+math.floor(rngs[i+a+hits]/655.36))/2)
hits = hits + 1
x = x + 1
end
end
for a = 1, limit, 1 do
if op[a] == "<" then
if list[a] < rn[a] then
y = y + 1
end
elseif op[a] == ">" then
if list[a] > rn[a] then
y = y + 1
end
elseif op[a] == "<=" then
if list[a] <= rn[a] then
y = y + 1
end
elseif op[a] == ">=" then
if list[a] >= rn[a] then
y = y + 1
end
elseif op[a] == "!=" then
if list[a] ~= rn[a] then
y = y + 1
end
elseif op[a] == "=" then
if list[a] == rn[a] then
y = y + 1
end
end
end
if y == ind-1 then
if i == 4 then
gui.text(178,(i-1)*8,"-->","cyan")
else
gui.text(212,(i-1)*8,"-->","cyan")
end
if d < 4 then
dis[d] = i-4
d = d + 1
end
end
end
end
a1 = " "
a2 = " "
rn = {"","","","","","","","","",""}
op = {"","","","","","","","","",""}
hit = {"","","","","","","","","",""}
d = 1
dis = {"","",""}
index = 1
ind = 1
numberpressed = {}
for i = 0, 9, 1 do
local s = tostring(i)
numberpressed[s] = false
end
otherpressed = {}
otherpressed["left"] = false
otherpressed["right"] = false
otherpressed["enter"] = false
otherpressed["H"] = false
local filter = 0
local inputs = 0
local php = 0x0203E064
local phit = 0x0203E0C6
local pdmg = 0x0203E0CA
local pcrt = 0x0203E0CE
local ehp = 0x0203E062
local ehit = 0x0203E0C4
local edmg = 0x0203E0C8
local ecrt = 0x0203E0CC
function obtainedexp()
local level = 0x0202BD58
local experience = 0x0202BD59
local total = 0
for i = 0, 7, 1 do
total = total + (memory.readbyte(level+(i*72))*100)
if memory.readbyte(experience+(i*72)) ~= 255 then
total = total + memory.readbyte(experience+(i*72))
end
end
return total
end
while true do
local nsim = 20
rngs = rngsim(503)
for i = 1, nsim do
gui.text(228, 8*(i-1), string.format("%3d", rngs[i]/655.36))
end
gui.text(0,0,"Filter Mode: ")
c = input.get()
if c.Q then
filter = 1
elseif c.W then
filter = 0
inputs = 0
end
if filter == 0 then
gui.text(48,0," Off")
gui.text(0,16,"Player")
gui.text(0,24,"HP: " .. printstats(memory.readbyte(php)))
gui.text(0,32,"Hit: " .. printstats(memory.readbyte(phit)))
gui.text(0,40,"Damage: " .. printstats(memory.readbyte(pdmg)))
gui.text(0,48,"Crit: " .. printstats(memory.readbyte(pcrt)))
gui.text(0,64,"Enemy")
gui.text(0,72,"HP: " .. printstats(memory.readbyte(ehp)))
gui.text(0,80,"Hit: " .. printstats(memory.readbyte(ehit)))
gui.text(0,88,"Damage: " .. printstats(memory.readbyte(edmg)))
gui.text(0,96,"Crit: " .. printstats(memory.readbyte(ecrt)))
index = 1
end
if filter == 1 then
for i = 1, 10, 1 do
gui.text(0,8+(i*8),rn[i])
gui.text(20,8+(i*8),op[i])
if hit[i] == true then
gui.text(40,8+(i*8),"<- Hit")
end
end
if rn[1] ~= "" and inputs == 0 then
dis = emptyarray(dis,3)
compareRN()
end
n = input.get()
if n.I then
rn = emptyarray(rn,10)
index = 1
op = emptyarray(op,10)
ind = 1
hit = emptyarray(hit,10)
inputs = 1
elseif n.O or ind > 10 then
inputs = 0
end
if inputs == 1 then
joypad.set(1,{" "})
captureinput()
gui.text(132,0,"On")
elseif inputs == 0 then
gui.text(132,0,"Off")
if rn[1] ~= "" then
if dis[1] == "" then
gui.text(0,104,"Distance: ---")
elseif dis[1] ~= "" and dis[2] == "" then
gui.text(0,104,"Distance: " .. dis[1])
elseif dis[1] ~= "" and dis[2] ~= "" and dis[3] == "" then
gui.text(0,104,string.format("Distance: %d - %d",dis[1],dis[2]))
else
gui.text(0,104,string.format("Distance: %d - %d - %d",dis[1],dis[2],dis[3]))
end
end
end
gui.text(48,0," On -- Input Mode: ")
end
gui.text(210,0,"RNG1:")
gui.text(210,8,"RNG2:")
gui.text(210,16,"RNG3:")
gui.text(194,24,"Next RNs:")
emu.frameadvance()
end