Jump to content

HGSS Lua Script doesn't work properly?


Giova

Recommended Posts

I'm using HGSS Kaphotics's lua script. This one:

mdword=memory.readdwordunsigned
mbyte=memory.readbyte
rshift=bit.rshift

-- Initialize on Script Startup
local frame = 0
local iframe = 0
local seed = 0
local initial = 0

memory.registerwrite(0x021D15AC, function() frame = frame + 1 end)
memory.registerwrite(0x0210F6CC, function() iframe = iframe + 1 end)

function buildseed()
delay=mdword(0x021D1138)
timehex=mdword(0x023FFDEC)
datehex=mdword(0x023FFDE8)
hour=string.format("%02X",(timehex%0x100)%0x40)	-- memory stores as decimal, but Lua reads as hex. Convert.
minute=string.format("%02X",(rshift(timehex%0x10000,8)))
second=string.format("%02X",(mbyte(0x02FFFDEE)))
year=string.format("%02X",(mbyte(0x02FFFDE8)))
month=string.format("%02X",(mbyte(0x02FFFDE9)))
day=string.format("%02X",(mbyte(0x02FFFDEA)))
ab=(month*day+minute+second)%256		-- Build Seed
cd=hour
cgd=delay%65536 +1 -- can tweak for calibration
abcd=ab*0x100+cd
efgh=(year+cgd)%0x10000
nextseed=ab*0x1000000+cd*0x10000+efgh		-- Seed is built
return nextseed		
end

function main()
currseed = mdword(0x021D15A8)
seed = mdword(0x021D15AC)

-- Detect initial seeding
if mdword(0x021D15AC) == currseed then
	initial = mdword(0x021D15A8)
	if currseed ~= 0x00000000 then
		iframe = 0
		frame = 0
	end
end
if mdword(0x021D15A8) == 0 then	-- if seed is 0, reset everything
	iframe = 0
	frame = 0	
end

-- Print variables in corner of bottom screen
if frame == 0 then
	gui.text(0,-10,string.format("Next Seed: %08X", buildseed()))
end
gui.text(0,180,string.format("Initial Seed: %08X", initial))
gui.text(0,170,string.format("Current Seed: %08X", currseed))
gui.text(0,160,string.format("IRNG Frame: %d", iframe))
gui.text(0,150,string.format("PRNG Frame: %d", frame))
gui.text(0,140,string.format("Delay: %d", mdword(0x021D1138)))
end

gui.register(main)

Can you tell me why PRNG Frame shows me always 0 and never grows up? Everything works well, but PRNG and IRNG frame are always 0.

[ATTACH=CONFIG]12993[/ATTACH]

Edited by Giova
Link to comment
Share on other sites

Found the problem. The wrong part of the code is this one:

memory.registerwrite(0x021D15AC, function() frame = frame + 1 end)
memory.registerwrite(0x0210F6CC, function() iframe = iframe + 1 end)

The first one has to be 0x021D15A8, because this is the address of the Current Seed. While 0x021D15AC is the address of the Initial Seed.

Can you tell me instead why, when i use save state, it only save the right Current Seed, Initial Seed and Delay, but doesn't save the Frame? Is there a way to fix this?

Edited by Giova
Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...