User File #17161206946737814

Upload All User Files

#17161206946737814 - Kingdom Hearts: Chain of Memories -- Shop script v0 (WIP)

KH_Shop_v0.lua
761 downloads
Uploaded 9/3/2014 8:12 PM by FatRatKnight (see all 245)
Version zero. Because it definitely needs more work.
On the left side are the raw 100-sided dice rolls. Jump a few times to get an idea as to what order the numbers are in.
Along the top is the predicted card values: The two-digit number is the raw 100-sided die roll for the identifier, the one-digit number is the value, and it is yellow if the card is premium.
Somehow, I missed the part where the pack quality varies. The prediction likely works with the basic pack. Probably falls apart if you pick something with a fancier binding than the leaf one. What else don't I know? I like to analyze things, so it's no trouble at all.
local R4s= memory.readdwordsigned

--*****************************************************************************
local function Roll(rTbl)  -- [1], [2], [3], [4]
--*****************************************************************************
    return bit.band(0xFFFFFFFF,bit.bxor(
        bit.lshift(rTbl[2], 2),bit.lshift(rTbl[4], 1),
        bit.rshift(rTbl[1],30),bit.rshift(rTbl[3],31)
    ))
end

--100-sided dice roll. Just feed it an RNG value!
local function d100(r)  return bit.band(r,0x00007FFF) % 100  end


--#############################################################################

local T= {0,0,0,0}
local Count= 0
--*****************************************************************************
local function CountRNG()
--*****************************************************************************
-- Updates the script's stored RNG. Will also count RNG rolls since.
-- If the script can't find a match in 1000 rolls, it resets the counter.

    for i= 0, 1000 do
        local Match= true
        for j= 1, 4 do
            Match= Match and (T[j] == R4s(0x02034030+4*(j-1)))
        end
        if Match then  Count= Count+i; return end

-- No match this time. Roll our stored value, and check for a match next time.
        table.insert(T,1,Roll(T))
        T[5]= nil
    end

--Give up. Reset counter and our stored RNG value.
    for i= 1, 4 do
        T[i]= R4s(0x02034030+4*(i-1))
        Count= 0
    end
end


local d100count= 75 -- How many to list? Try to have 15 or more, please.
--*****************************************************************************
local function d100Scan()
--*****************************************************************************
-- Would like CountRNG to first update the script's stored RNG.

    local t= {T[1],T[2],T[3],T[4]} -- Get a copy of the stored RNG!
    local d100tbl= {} -- I'll hold my RNG values here.

    for i= 0, d100count-1 do
        table.insert(t,1,Roll(t)); t[5]= nil
        d100tbl[i]= d100(t[1])
    end

    return d100tbl
end

local StripeColors= {[0]=0xFFFFFFFF,0xC0C0C0FF}
--*****************************************************************************
local function Display_d100tbl(d100tbl)
--*****************************************************************************
-- Its only purpose is to display a list of numbers.
    for i= 0, d100count-1 do
        local X= math.floor(i/15)
        local Y= (i%15)*7 + X
        local clr= StripeColors[X%2]
        X= X*10

        gui.text(X,Y,string.format("%2d",d100tbl[i]),clr)
    end
end

local tbl_card_val= {
[0]=0,0,0,0,0,1,1,1,1,1, -- 0~ 9
    1,1,1,1,1,1,1,1,1,1, --10~19
    2,2,2,2,2,2,2,2,2,2, --20~29
    2,2,2,2,2,3,3,3,3,3, --30~39
    3,3,3,3,3,3,3,3,3,3, --40~49
    3,4,4,4,4,4,4,4,4,4, --50~59
    4,4,4,4,4,5,5,5,5,5, --60~69
    5,5,5,5,5,6,6,6,6,6, --70~79
    6,6,6,6,6,7,7,7,7,7, --80~89
    7,8,8,8,8,8,9,9,9,9  --90~99
}

--*****************************************************************************
local function PredictCards(d100tbl)
--*****************************************************************************
--There are three aspects to generating a card:
--  * Identifier, what card it is
--  * Value, a number from 0 to 9
--  * Premium, how shiny it is
--Item cards do not use the third RNG, so this script will fail to properly
--identify cards when you pick item or mix packs.

    for i= 0, 4 do
        local id, val, sp= d100tbl[i*3+0],d100tbl[i*3+1],d100tbl[i*3+2]

        val= tbl_card_val[val]

        local clr
        if sp < 10 then sp= "+"; clr= 0xFFFF00FF
        else            sp= ":"; clr= 0xFFFFFFFF
        end

        gui.text(100+i*20,2,string.format("%2d%s%d",id,sp,val),clr)
    end
end

--*****************************************************************************
local function Fn()
--*****************************************************************************
    CountRNG()
    local Tbl= d100Scan()
    Display_d100tbl(Tbl)
    PredictCards(Tbl)

--[[
    for i= 1, 4 do
        gui.text(0,7*i,string.format("%8X",T[5-i]))
    end
    local T2= {T[1],T[2],T[3],T[4]}
    for i= 5,20 do
        table.insert(T2,1,Roll(T2)); T2[5]= nil
        gui.text(  0,7*i,string.format("%8X",T2[1]),0x00FF00FF)
        local d100= bit.band(T2[1],0x7FFF)%100 -- Dice, man. Hundred sides.
        gui.text( 28,7*i,string.format("%3d",d100),0x00FFFFFF)
        gui.text( 40,7*i,tbl_card_val[d100],0xFFFF00FF)
    end
--    gui.text(  0,0,string.format("%8X",Roll(T)),0x00FF00FF)
    gui.text( 36,0,string.format("%6d",Count))
]]--
end
gui.register(Fn)

--0203A992 - 0203A99B = Moogle Room 0-9