User File #46843624007839304

Upload All User Files

#46843624007839304 - Position Display for GBA Cabbage Patch Kids

Cabbage Patch Kids.lua
612 downloads
Uploaded 5/2/2018 2:21 PM by ThunderAxe31 (see all 111)
Since the game uses many different addresses for the X and Y position of the player, I've decided to write a quick lua script that automatically tracks the addresses and shows them on screen. With some tweaks, the same code could be used for other games that feature the same problem.
Don't use it during the title screen, otherwise the script will crash.
--Cabbage Patch Kids script v1.0 by ThunderAxe31

local addr_masterpointer = 0x000410
local addr_offset_x      = 0x20
local addr_offset_y      = 0x24

local old_x_pixel    = 0
local old_x_subpixel = 0
local old_x_combined = 0
local old_y_pixel    = 0
local old_y_subpixel = 0
local old_y_combined = 0

local framecount = -1

if memory.usememorydomain("EWRAM") then
	while true do
		local masterpointer = memory.read_u32_le(addr_masterpointer) - 0x02000000
		
		local x_pixel = memory.read_s16_le(masterpointer + addr_offset_x + 1)
		local x_subpixel = memory.read_u8(masterpointer + addr_offset_x)
		local x_combined = memory.read_s32_le(masterpointer + addr_offset_x)
		local y_pixel = memory.read_s16_le(masterpointer + addr_offset_y + 1)
		local y_subpixel = memory.read_u8(masterpointer + addr_offset_y)
		local y_combined = memory.read_s32_le(masterpointer + addr_offset_y)
		
		local speed_x_pixel    = x_pixel - old_x_pixel
		local speed_x_subpixel = x_subpixel - old_x_subpixel
		local speed_x_combined = x_combined - old_x_combined
		local speed_y_pixel    = y_pixel - old_y_pixel
		local speed_y_subpixel = y_subpixel - old_y_subpixel
		local speed_y_combined = y_combined - old_y_combined
		
		if speed_x_pixel > 0 then speed_x_pixel = "+" .. speed_x_pixel end
		if speed_x_subpixel > 0 then speed_x_subpixel = "+" .. speed_x_subpixel end
		if speed_x_combined > 0 then speed_x_combined = "+" .. speed_x_combined end
		if speed_y_pixel > 0 then speed_y_pixel = "+" .. speed_y_pixel end
		if speed_y_subpixel > 0 then speed_y_subpixel = "+" .. speed_y_subpixel end
		if speed_y_combined > 0 then speed_y_combined = "+" .. speed_y_combined end
		
		if framecount ~= emu.framecount()-1 then
			speed_x_pixel    = ""
			speed_x_subpixel = ""
			speed_x_combined = ""
			speed_y_pixel    = ""
			speed_y_subpixel = ""
			speed_y_combined = ""
		end
		
		old_x_pixel    = x_pixel
		old_x_subpixel = x_subpixel
		old_x_combined = x_combined
		old_y_pixel    = y_pixel
		old_y_subpixel = y_subpixel
		old_y_combined = y_combined
		
		gui.pixelText(0, 132, "X position       | speed\npixel:   " .. string.format("%7s", x_pixel) .. string.format("%8s", speed_x_pixel) .. "\nsubpixel:" .. string.format("%7s", x_subpixel) .. string.format("%8s", speed_x_subpixel) .. "\ncombined:" .. string.format("%7s", x_combined) .. string.format("%8s", speed_x_combined) )
		
		gui.pixelText(143, 132, "Y position       | speed\npixel:   " .. string.format("%7s", y_pixel) .. string.format("%8s", speed_y_pixel) .. "\nsubpixel:" .. string.format("%7s", y_subpixel) .. string.format("%8s", speed_y_subpixel) .. "\ncombined:" .. string.format("%7s", y_combined) .. string.format("%8s", speed_y_combined) )
		
		framecount = emu.framecount()
		
		emu.frameadvance()
	end
end