User File #72251233920543466

Upload All User Files

#72251233920543466 (unlisted) -

ace_detection.lua
25 downloads
Uploaded 6/19/2021 8:06 PM by CasualPokePlayer (see all 9)
local FF80_writes = 0;
local FF81_writes = 0;
local FF82_writes = 0;
local FF83_writes = 0;
local FF84_writes = 0;
local FF85_writes = 0;
local FF86_writes = 0;
local FF87_writes = 0;
local FF88_writes = 0;
local FF89_writes = 0;

local MAX_DMA_WRITES = 3; -- exceeding this indicates player corruption of this routine
-- normal game operation only writes to this area 3 times per power cycle
-- 1 when BIOS writes here with logo data
-- 1 when the game does a global RAM clear
-- 1 when the game actually writes in the routine

function ace_detected()
	client.pause();
	local pc = emu.getregister("PC");
    console.write("ACE DETECTED AT $"..string.format("%04X",pc));
	console.write("\n");
end

function ace_possibly_detected_0()
	FF80_writes = FF80_writes + 1;
	if FF80_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function ace_possibly_detected_1()
	FF81_writes = FF81_writes + 1;
	if FF81_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function ace_possibly_detected_2()
	FF82_writes = FF82_writes + 1;
	if FF82_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function ace_possibly_detected_3()
	FF83_writes = FF83_writes + 1;
	if FF83_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function ace_possibly_detected_4()
	FF84_writes = FF84_writes + 1;
	if FF84_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function ace_possibly_detected_5()
	FF85_writes = FF85_writes + 1;
	if FF85_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function ace_possibly_detected_6()
	FF86_writes = FF86_writes + 1;
	if FF86_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function ace_possibly_detected_7()
	FF87_writes = FF87_writes + 1;
	if FF87_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function ace_possibly_detected_8()
	FF88_writes = FF88_writes + 1;
	if FF88_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function ace_possibly_detected_9()
	FF89_writes = FF89_writes + 1;
	if FF89_writes > MAX_DMA_WRITES then
		ace_detected()
	end
end

function filter_ram()
	local pc = emu.getregister("PC");
	if ((pc > 0x7FFF and pc < 0xFF80) or (pc > 0xFF89)) then
		ace_detected();
	end
end

event.onmemoryexecuteany(filter_ram)

event.onmemorywrite(ace_possibly_detected_0,0xFF80);
event.onmemorywrite(ace_possibly_detected_1,0xFF81);
event.onmemorywrite(ace_possibly_detected_2,0xFF82);
event.onmemorywrite(ace_possibly_detected_3,0xFF83);
event.onmemorywrite(ace_possibly_detected_4,0xFF84);
event.onmemorywrite(ace_possibly_detected_5,0xFF85);
event.onmemorywrite(ace_possibly_detected_6,0xFF86);
event.onmemorywrite(ace_possibly_detected_7,0xFF87);
event.onmemorywrite(ace_possibly_detected_8,0xFF88);
event.onmemorywrite(ace_possibly_detected_9,0xFF89);

while true do
	local cur_input = movie.getinput(emu.framecount());
	if cur_input["P1 Power"] then
		FF80_writes = 0;
		FF81_writes = 0;
		FF82_writes = 0;
		FF83_writes = 0;
		FF84_writes = 0;
		FF85_writes = 0;
		FF86_writes = 0;
		FF87_writes = 0;
		FF88_writes = 0;
		FF89_writes = 0;
	end
    emu.frameadvance();
end