User File #638632439571807402

Upload All User Files

#638632439571807402 (unlisted) - a

mlp_find_ptr.lua
9 downloads
Uploaded 9/29/2024 9:59 PM by CasualPokePlayer (see all 9)
a
--local X_POS_ADDR = 0x02000000 + 0x035538
--local MAX_DIFF = 0x030000
--local LOWER_BOUND = X_POS_ADDR - MAX_DIFF

--for i=0x880,0x47FFF,4 do
--	local possible_ptr = memory.read_u32_le(i, "Combined WRAM")
--	if (possible_ptr >= 0x02030000 and possible_ptr <= X_POS_ADDR) then
--		console.writeline(string.format("%08X: %08X", i, possible_ptr))
--	end
--end

--event.on_bus_write(function()
--	console.writeline(string.format("PC: %08X", emu.getregister("R15")))
--end, X_POS_ADDR)

client.SetClientExtraPadding(0, 0, 300, 0)

local function get_object_ptr(object_num)
	local object_ptr_offset = (object_num << 2) + 8
	return memory.read_u32_le(0x0300116C + object_ptr_offset, "System Bus")
end

local function get_num_objects()
	return memory.read_u32_le(0x0300116C + 4, "System Bus")
end

local function get_x_pos(object_ptr)
	return memory.read_s32_le(object_ptr + 0x1A8, "System Bus")
	--return memory.read_u32_le(object_ptr + 0x70, "System Bus")
end

local function get_y_pos(object_ptr)
	return memory.read_s32_le(object_ptr + 0x1AC, "System Bus")
	--return memory.read_u32_le(object_ptr + 0x74, "System Bus")
end

memory.read_u64_le = function(addr, domain)
	local l = memory.read_u32_le(addr, domain)
	local h = memory.read_u32_le(addr + 4, domain)
	return (h << 32) | l
end

--event.on_bus_write(function()
--	local r15 = emu.getregister("R15")
--	if (r15 == 0x08022F9E) then return end
--	console.writeline(string.format("PC: %08X", r15))
--end, 0x03000000 + 0x4DF4)

local object_x = {}
local object_y = {}

while true do
	local num_objects = get_num_objects()
	local player_object_index = nil
	if (num_objects > 0) then
		for i=0,num_objects-1 do
			local object_ptr = get_object_ptr(i)
			object_x[i] = get_x_pos(object_ptr)
			object_y[i] = get_y_pos(object_ptr)
			if (memory.read_u32_le(object_ptr) == 0x0802617C) then
				player_object_index = i
			end
		end
	end

	emu.frameadvance()

	num_objects = get_num_objects()
	if (num_objects > 0 and player_object_index) then
		for i=0,num_objects-1 do
			local object_ptr = get_object_ptr(i)
			if (memory.read_u32_le(object_ptr) == 0x0802617C) then
				local x_pos = get_x_pos(object_ptr)
				local y_pos = get_y_pos(object_ptr) 
				local x_speed = x_pos - object_x[player_object_index]
				local y_speed = y_pos - object_y[player_object_index]
				--gui.text(5, (i * 40) + 5, string.format("Object %d X Speed: %d", i, x_speed), nil, "topright")
				--gui.text(5, (i * 40) + 25, string.format("Object %d Y Speed: %d", i, y_speed), nil, "topright")
				gui.text(5, 5, string.format("Player X Pos: %.1f", x_pos / 256), nil, "topright")
				gui.text(5, 25, string.format("Player Y Pos: %.1f", y_pos / 256), nil, "topright")
				gui.text(5, 45, string.format("Player X Speed: %d", x_speed), nil, "topright")
				gui.text(5, 65, string.format("Player Y Speed: %d", y_speed), nil, "topright")
				gui.text(5, 85, string.format("Player Object Index %d/%d", player_object_index, i), nil, "topright")
			end
		end
	end

	gui.text(5, 105, string.format("RNG: %016X", memory.read_u64_le(0x4DF4, "IWRAM")), nil, "topright")
end