Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camhack support #1725

Merged
merged 6 commits into from
Nov 23, 2019
Merged

Camhack support #1725

merged 6 commits into from
Nov 23, 2019

Conversation

vadosnaprimer
Copy link
Contributor

@vadosnaprimer vadosnaprimer commented Nov 10, 2019

https://www.youtube.com/watch?v=uFl0ax-GYk8

For a test, mGBA core uses fake video and audio buffers and renders to them when we want to "skip" rendering. Proper setup would involve actually skipping rendering those inside the core.

For the camhack to work we have to save a state, hack memory, advance twice to see the changes, then load the state to prevent desync. Since we can omit the framebuffer in savestates, loading them can happen without updating the screen, so the hacked camera remains visible.

Advancing 2 frames automatically is done like tastudio does it when it seeks to a frame, only from lua now.

And the most questionable part is "invisible emulation", which is how Gens calls this IIRC, when everything that can distract or slow us down is skipped: sound, video, tools updates.

AVI dumping works as expected BTW. Couldn't make fps update while unpaused tho. Only updates if you press/hold frame advance.

New lua functions:

  • client.invisibleemulation()
  • client.seekframe()

Script for Sonic Advance:

local offX, offY, camX, camY
local addr_offX = 0x5B96
local addr_offY = 0x5B98
local addr_camX = 0x59D0
local addr_camY = 0x59D2

while true do
	client.invisibleemulation(true)
	local memorystate = memorysavestate.savecorestate()
	
	offX = mainmemory.read_u16_le(addr_offX)
	offY = mainmemory.read_u16_le(addr_offY)
	camX = mainmemory.read_u16_le(addr_camX)
	camY = mainmemory.read_u16_le(addr_camY)
	
	Xval = camX + offX - 128
	Yval = camY + offY - 80
	
	mainmemory.write_u16_le(addr_camX, Xval)
	mainmemory.write_u16_le(addr_camY, Yval)
	
	client.seekframe(emu.framecount()+1)
	client.invisibleemulation(false)
	client.seekframe(emu.framecount()+1)
	client.invisibleemulation(true)
	memorysavestate.loadcorestate(memorystate)
	memorysavestate.removestate(memorystate)
--	client.invisibleemulation(false)
	emu.frameadvance()
end

Tested with the first level of this movie
sonicadvance_test.zip

for a test, mGBA core uses fake video and audio buffers and renders to them when we want to "skip" rendering. proper setup would involve actually skipping rendering those inside the core.

for the camhack to work we have to save a state, hack memory, advance twice to see the changes, then load the state to prevent desync. since we can omit the framebuffer in savestates, loading them can happen without updating the screen, so the hacked camera remains visible.

advancing 2 frames automatically is done like tastudio does it when it seeks to a frame, only from lua now.

and the most questionable part is "invisible emulation", which is how Gens calls this IIRC, when everything that can distract or slow us down is skipped: sound, video, tools updates.

new lua functions:
- client.invisibleemulation()
- client.seekframe()
@vadosnaprimer vadosnaprimer changed the title Sketchy camhack support Camhack support Nov 20, 2019
feos added 2 commits November 23, 2019 12:21
add the script for Sonic Advance
@vadosnaprimer vadosnaprimer merged commit 5ca08b6 into TASEmulators:master Nov 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant