local PrintoutKey= "Z"
local R1u= memory.readbyte
local R2s= memory.readwordsigned
local W4s= memory.writedword
local R4s= memory.readdwordsigned
local Keys, LastKeys= input.get(), input.get()
local function UpdateKeys() LastKeys= Keys; Keys= input.get() end
local function Press(k) return Keys[k] and (not LastKeys[k]) end
local function GetString_word(addr,len)
local str= ""
for i= 0, len-1 do
local v= R1u(addr + 2*i)
if v == 0 then break end
str= str .. string.char(v)
end
str= str .. string.rep(" ",len-#str)
return str
end
local function Roll(rTbl)
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
local T= {0,0,0,0}
for i= 1, 4 do
T[i]= R4s(0x02034030+4*(i-1))
end
local z= savestate.create()
savestate.save(z)
local Error= 0
local M_Prize= {}
local E_Prize= {}
local function Fn()
local Y= 0
local Total= 0
local ValTotal= {[0]=0,0,0,0,0,0,0,0,0,0}
for k,v in pairs(M_Prize) do
local TypeTotal= 0
gui.text(0,Y,string.format("%2d:%s",k,
GetString_word(R4s(0x09EF7048+4*k),7)
),0x00FF00FF)
for i= 0, 9 do
gui.text(38+18*i,Y,string.format("%4d",v[i]))
ValTotal[i]= ValTotal[i]+v[i]
TypeTotal= TypeTotal+v[i]
end
gui.text(218,Y,string.format("%4d",TypeTotal),0x00FFFFFF)
Total= Total+TypeTotal
Y= Y+6
end
for i= 0, 9 do gui.text(38+18*i,Y,string.format("%4d",ValTotal[i]),0x00FFFFFF) end
gui.text(208,144,string.format("%8d",Total),0xFF8000FF)
local X= 0
for k,v in pairs(E_Prize) do
gui.text(X,152,string.format("%3d:%4d",k,v))
X= X+40
end
gui.text(208,152,string.format("%8d",Error),0xFF2000FF)
end
gui.register(Fn)
local function PrintData()
print("ID:Name | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9||Total")
print("--:-----------------|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----||-----")
local Total= 0
local ValTotal= {[0]=0,0,0,0,0,0,0,0,0,0}
for k,v in pairs(M_Prize) do
local TypeTotal= 0
local str= string.format("%2d:%s",k,
GetString_word(R4s(0x09EF7048+4*k),17)
)
for i= 0, 9 do
str= string.format("%s|%5d",str,v[i])
ValTotal[i]= ValTotal[i]+v[i]
TypeTotal= TypeTotal+v[i]
end
print(string.format("%s||%6d",str,TypeTotal))
Total= Total+TypeTotal
end
print()
local str= "Totals "
for i= 0, 9 do str= string.format("%s|%5d",str,ValTotal[i]) end
print(str)
print("Total: ",Total)
print()
for k,v in pairs(E_Prize) do
print(string.format("%3d:%s>> %d times",
k,
GetString_word(R4s(0x08F70ABC + k*0x34),17),
v
))
end
print("Fail count: ",Error)
end
local function LocateCombatAddr()
local addr= R4s(0x02039B84)
if addr == 0 then return false end
if R4s(addr-0x20) ~= -0x200 then return false end
if R4s(addr-0x08) ~= 0x081213DC then return false end
return addr
end
local function IdentifyPrize(obj_RAM)
local obj_PrizeCard= R4s(R4s(obj_RAM+0x10)+4)
local ID,val= R2s(obj_PrizeCard+0x3C),R2s(obj_PrizeCard+0x3E)
M_Prize[ID]= M_Prize[ID] or {[0]=0,0,0,0,0,0,0,0,0,0}
M_Prize[ID][val]= M_Prize[ID][val]+1
return true
end
local function HeartlessPrize(obj_RAM)
local CardID= R2s(obj_RAM+0x1A0)
E_Prize[CardID]= E_Prize[CardID] or 0
E_Prize[CardID]= E_Prize[CardID]+1
return true
end
local function SeekPrize(addr)
while addr ~= 0 do
local obj= R4s(addr)
local ROM_ptr= R4s(obj)
if ROM_ptr == 0x9EE75F0 then
return IdentifyPrize(R4s(obj+4))
elseif ROM_ptr == 0x9EE77A4 then
return HeartlessPrize(R4s(obj+4))
end
addr= R4s(addr+8)
end
return false
end
local function HandleFrame()
UpdateKeys()
if Press(PrintoutKey) then PrintData() end
emu.frameadvance()
end
local function Botty()
while true do
for i= 1, 4 do
W4s(0x02034030+4*(i-1),T[i])
end
for t= 0, 6 do HandleFrame() end
local addr= LocateCombatAddr()
if addr then
addr= R4s(addr+0x34)
if not SeekPrize(addr) then Error=Error+1 end
else
Error=Error+1
end
savestate.load(z)
table.insert(T,1,Roll(T)); T[5]= nil
end
end
Botty()
while true do
emu.frameadvance()
end