User File #12750429891219382

Upload All User Files

#12750429891219382 - Sonic Advance. RNG scanner for ? Ring Box. v2

SA1_RNGv2.lua
946 downloads
Uploaded 2/17/2014 4:49 AM by FatRatKnight (see all 245)
This is the script that I made for Zeupar.
It predicts what will come out of that ? ring box. It also counts RNG rolls. It doesn't really do much else, but I am showing that I worked out the mechanics of the RNG to some extent.
So, uh... I'm un-hiding it now.
local R1u, R1s= memory.readbyte , memory.readbytesigned
local R2u, R2s= memory.readword , memory.readwordsigned
local R4u, R4s= memory.readdword, memory.readdwordsigned

--*****************************************************************************
local function Roll(r)
--*****************************************************************************
--    return bit.band(0xFFFFFFFF,(r*0x00196225)+0x3C6EF35F)

    rlo= r%0x10000
    rhi= bit.rshift(r,16)

    rlo= bit.band(rlo*0x00196225,0xFFFFFFFF)
    rhi= bit.band(rhi*0x00196225,0xFFFF)
    r= bit.band(rlo+bit.lshift(rhi,16)+0x3C6EF35F,0xFFFFFFFF)

    return r
end

--*****************************************************************************
local function Unroll(r)
--*****************************************************************************
--    return bit.band(0xFFFFFFFF,(r*0xAAE1E9AD)+0x310511CD)

    rlo= r%0x10000
    rhi= bit.rshift(r,16)

    rlo= bit.band(rlo*0xAAE1E9AD,0xFFFFFFFF)
    rhi= bit.band(rhi*0xAAE1E9AD,0xFFFF)
    r= bit.band(rlo+bit.lshift(rhi,16)+0x310511CD,0xFFFFFFFF)

    return r
end

local BigNum= 0xFFFFFFFF + 1
local RingVals= {[0]= 1,5,10,20,30,40}
local RingClrs= {[0]=0x808080C0,0xFF2000FF,0xFFA000FF,
                     0xFFFF00FF,0x00FF00FF,0x00FFFFFF}
--*****************************************************************************
local function ListQuestionRings(r)
--*****************************************************************************
    for i= 0, 22 do
        r= Roll(r)
        local v= r%BigNum
        gui.text(232,i*7,string.format("%2d",RingVals[v%6]),RingClrs[v%6])
    end
end

local count= 0
local OldR= 0
--*****************************************************************************
local function CountRNG(r)
--*****************************************************************************
    if OldR == r then return end -- Nothing to do...

    local PastR, FutureR= OldR, OldR
    OldR= r

-- Look for local changes
    for i= 1, 600 do
        PastR, FutureR= Unroll(PastR), Roll(FutureR)
        if FutureR == r then count= count+i; return end
        if PastR   == r then count= count-i; return end
    end

-- Uh, reset and look for long distance changes...
    OldR= 0
    for i= 0, 50000 do
        if OldR == r then count= i; return end
        OldR= Roll(OldR)
    end

-- Give up.
    count= -1; OldR= r
end

--*****************************************************************************
local function Fn()
--*****************************************************************************
    local r= R4s(0x03004C58)
    ListQuestionRings(r)
    CountRNG(r)
    gui.text(198,0,string.format("%8d",count))
end
gui.register(Fn)