Skip to content

Commit 80727be

Browse files
committed
Fix Lua script that used client.seekframe.
1 parent 51275f3 commit 80727be

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Assets/Lua/GBA/SonicAdvance_CamHack.lua

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ local addr_offY = 0x5B98
66
local addr_camX = 0x59D0
77
local addr_camY = 0x59D2
88

9+
-- Seek forward to a given frame.
10+
-- This will unpause emulation, and restore the users' desired pause state when seeking is completed.
11+
local function seek_frame(frame)
12+
local pause = client.unpause()
13+
while emu.framecount() < frame do
14+
-- The user may pause mid-seek, perhaps even by accident.
15+
-- In this case, we will unpause but remember that the user wants to pause at the end.
16+
if client.ispaused() then
17+
pause = true
18+
client.unpause()
19+
end
20+
-- Yield, not frameadvance. With frameadvance we cannot detect pauses, since frameadvance would not return.
21+
-- This is true even if we have just called client.unpause.
22+
emu.yield()
23+
end
24+
25+
if pause then client.pause() end
26+
end
27+
928
while true do
1029
client.invisibleemulation(true)
1130
local memorystate = memorysavestate.savecorestate()
@@ -21,9 +40,9 @@ while true do
2140
mainmemory.write_u16_le(addr_camX, Xval)
2241
mainmemory.write_u16_le(addr_camY, Yval)
2342

24-
client.seekframe(emu.framecount()+1)
43+
seek_frame(emu.framecount()+1)
2544
client.invisibleemulation(false)
26-
client.seekframe(emu.framecount()+1)
45+
seek_frame(emu.framecount()+1)
2746
client.invisibleemulation(true)
2847
memorysavestate.loadcorestate(memorystate)
2948
memorysavestate.removestate(memorystate)

0 commit comments

Comments
 (0)