For Japanese version only
--[[This script is for Rockman Zero 2 Japanese version only.
Created by hellagels]]
--color for drop prediction
nothing = "white"
smallHP = 0x60FF0000
largeHP = "red"
fullHP = "black"
smallEC = 0x600000FF
largeEC = "blue"
extralife = "green"
--key for RNG cheating
RNG_forward = "Keypad2"
RNG_backward = "Keypad1"
-------------------------------------------------------------------------
function mul32(a, b)
-- separate the value into two 16-bit values to prevent type casting
local x, y, z = {}, {}, {}
x[1] = bit.band(a, 0xffff)
x[2] = bit.band(bit.rshift(a, 16), 0xffff)
y[1] = bit.band(b, 0xffff)
y[2] = bit.band(bit.rshift(b, 16), 0xffff)
-- calculate for each halfword
local v, c
v = x[1] * y[1]
z[1], c = bit.band(v, 0xffff), bit.rshift(v, 16)
v = c + x[2] * y[1] + x[1] * y[2]
z[2], c = bit.band(v, 0xffff), bit.rshift(v, 16)
-- compose them and return it
return bit.bor(z[1], bit.lshift(z[2], 16))
end
function add32(a, b)
return bit.band(a + b, 0xFFFFFFFF)
end
client.SetGameExtraPadding(0, 0, 64, 0)
color = {
smallHP ,
largeHP ,
fullHP ,
smallEC ,
largeEC ,
extralife }
multiplier = {
968044885 ,
1616881209 ,
171702449 ,
1731029601 ,
542013633 ,
244416897 ,
296043265 ,
315852289 ,
1338706945 ,
673585153 ,
1921789953 ,
1847091201 ,
3194881 ,
274825217 ,
1623392257 ,
1099300865 ,
51118081 ,
102236161 ,
204472321 ,
408944641 ,
817889281 ,
1635778561 ,
1124073473 ,
100663297 ,
201326593 ,
402653185 ,
805306369 ,
1610612737 ,
1073741825 ,
1 ,
1 }
adder = {
561051201 ,
59255510 ,
1040873596 ,
1687414328 ,
1036603760 ,
14431968 ,
1012579776 ,
1159641984 ,
719484672 ,
1348005376 ,
1258413056 ,
1061402624 ,
596078592 ,
1527701504 ,
102612992 ,
1278967808 ,
410451968 ,
820903936 ,
1641807872 ,
1136132096 ,
124780544 ,
249561088 ,
499122176 ,
998244352 ,
1996488704 ,
1845493760 ,
1543503872 ,
939524096 ,
1879048192 ,
1610612736 ,
1073741824 }
local RNG_backward_frame = 0
local RNG_forward_frame = 0
function RNG_alter()
user_input = input.get()
current_RNG = memory.read_u32_le(0x02E188,"EWRAM")
if user_input[RNG_backward] then
RNG_backward_frame = RNG_backward_frame + 1
else
RNG_backward_frame = 0
end
if RNG_backward_frame == 1 then
memory.write_u32_le(0x02E188, add32(mul32(current_RNG,0x39B33155),0x2170F641)%0x80000000,"EWRAM")
end
if user_input[RNG_forward] then
RNG_forward_frame = RNG_forward_frame + 1
else
RNG_forward_frame = 0
end
if RNG_forward_frame == 1 then
memory.write_u32_le(0x02E188, add32(mul32(current_RNG,0x000343FD),0x00269EC3)%0x80000000,"EWRAM")
end
end
pool_parameter = {}
for i = 0, 55 do
pool_parameter[i] = memory.read_u16_le(0x33266C + 2 * i,"ROM")
end
function get_RNG_table()
local tbl = {}
tbl[0] = memory.read_u32_le(0x02E188,"EWRAM")
for i=1,50 do
tbl[i] = add32(mul32(tbl[i-1],0x000343FD),0x00269EC3)%0x80000000
end
return tbl
end
function predict()
for pool_ID = 1,5 do
gui.drawBox(234+pool_ID*12,149,239+pool_ID*12,50,nothing, nothing)
gui.pixelText(235+pool_ID*12, 150, pool_ID)
local RNG_table = get_RNG_table()
for k = 1,50 do
local RNG_chipped = bit.rshift(bit.band(RNG_table[k], 0x00FF0000),16)
for j = 0, 6 do
if RNG_chipped < pool_parameter[pool_ID * 7 + j] then
item = j
break
end
end
if item > 0 then
gui.drawBox(234+pool_ID*12,151-k*2,239+pool_ID*12,150-k*2,color[item], color[item])
end
end
end
end
--algorithms by KSeptuple
function get_RNG_step(RNG)
local result = 0
for i = 1, 31 do
if bit.rshift(RNG, i - 1) % 2 == 1 then
RNG = add32(mul32(RNG, multiplier[i]), adder[i])
result = add32(result, bit.lshift(1, i - 1))
if RNG == 0 then
break
end
end
end
return result
end
substacter = {}
for i = 0x00, 0x20 do
substacter[i] = get_RNG_step(i)
end
function detect_pool()
pool = emu.getregister("R3")
gui.addmessage("Pool "..pool)
end
event.onmemoryexecute(detect_pool,0x0801DDE2)
while true do
RNG_alter()
RNG_string = string.format("%X",memory.read_u32_le(0x02E188,"EWRAM"))
gui.pixelText(242,8,"RNG: "..string.rep("0",8-string.len(RNG_string))..RNG_string)
map = memory.read_u32_le(0x036B34,"EWRAM")
gui.pixelText(242,16,"MAP: "..string.format("%X",map))
signed_RNG_step = (get_RNG_step(memory.read_u32_le(0x02E188,"EWRAM"))-substacter[map])
if signed_RNG_step > 0x4000000 then
signed_RNG_step = signed_RNG_step - 0x80000000
end
gui.pixelText(242,24,"STEP: "..signed_RNG_step)
predict()
if client.ispaused() then
gui.DrawFinish()
emu.yield()
else
emu.frameadvance()
end
end