User File #73828305163352813

Upload All User Files

#73828305163352813 - DK64 sync-dump.lua

dk64-sync-dump.lua
Game: Donkey Kong 64 ( N64, see all files )
184 downloads
Uploaded 8/29/2021 8:41 PM by Zinfidel (see all 12)
Sync script modified to work on very old versions of BizHawk, with code specific to syncing DK64.
-- feos, 2017
-- DK64 resync workflow
-- props to thecoreyburton

t = {}            -- array of state names found
count = 0         -- total states found, just for print()
av_paused = false -- pretend we have that info from the emu
offset = 10        -- av delay after stated frame

-- scan the script dir for states and store their names to array
function scandir()
	local popen = io.popen          -- use cmd
	local pfile = popen('dir states /b') -- cmd arguments
	local i = 0
	local index = 0
	local name = ""
	for filename in pfile:lines() do
		i = i + 1
		
		-- skip all but state files
		if filename:find(".State") then
			-- strip frame numbers
			name = string.gsub(filename, ".State", "")
			index = tonumber(name)
			t[index] = filename
			count = count + 1
		end
	end
	pfile:close()
end

scandir()
print("States found: " .. count) -- #t doesn't work for some reason (gaps in the table?)

last_frame = 0
while true do
	if movie.isloaded() then
		-- check if there's a state of "offset" frames back
		local name = t[emu.framecount() - offset]

		-- suspend av and load the state, with a delay
		if name and not av_paused then
			client.pause_av()
			av_paused = true
			savestate.load("states/" .. name)
			print("Loaded " .. name)
		end

		-- basic report you'd barely see
		if av_paused then
			gui.text(0, 40, "AV paused")
		end

		-- resume av when that frame occurs again
		if t[emu.framecount() - offset] and av_paused then
			client.unpause_av()
			av_paused = false
		end
	end
	emu.frameadvance()
end