User File #62571211012919099

Upload All User Files

#62571211012919099 - GBA HM FoMT Mines X-Ray

HM FoMT.lua
359 downloads
Uploaded 4/9/2020 9:29 PM by dart193 (see all 5)
This is a script that allows one to see through rocks and soil in the Harvest Moon: Friends of Mineral Town. It shows up to two dots on each tile in the mine: upper one over rocks that shows what is inside this rock, and bottom one shows if there is something to dig in the ground.
By default, moneybags in the ground and junk ore inside rocks are hidden, but can be enabled via TOGGLE in the beginning of the file.
Dot colors show what contents are on the tile. Flashing dots show important contents like power berries, cursed tools or mythic stones. Staircases also have flashing dots since you need to dig one to proceed, but once you dig one, others automatically disappear. If you see a hollow white dot and a message in the console, this means that this item was not added in the script. Should not appear under normal circumstances.
There is a bug in the game where stones with Goddess/Kappa Jewels inside do not actually contain them. It can be fixed by going into any subscreen (like Rucksack, which can be accessed by A+B) while on the floor with the jewel. Note that for every floor that has a jewel, it can only drop that jewel once. A friendly reminder is shown when you reach a floor which contains stones that drops those jewels.
Two numbers to the left of info panel also show your current stamina and fatigue: cyan for stamina, purple for fatigue
In the upper right corner of the screen floor number is also shown, for convenience.
--TOGGLE
--This variable controls if only useful rocks/soils should be highlighted
--true: highlights everything except junk ore and coin bags
--false:highlights everything
local debugvaluables=true

--Memory
local CameraDomain="IWRAM"
local CameraXAddress=0x77BC
local CameraYAddress=0x77BE
local DataDomain="EWRAM"
local StaminaAddress=0x006A29
local FatigueAddress=0x006A2A
local TileDataAddress=0x007C68
local MineLevelAddress=0x039064

--Data
local CameraX
local CameraY
local Stamina
local Fatigue
local Tile
local MineLevel

local TileROCK
local TileTYPE
local TileDIRT

--Constants
local TYPE_SOIL=0x0
local TYPE_TILLED=0x1
local TYPE_STAIRSDOWN=0x2
local TYPE_STAIRSUP=0x3
local TYPE_STONE=0x4

local ROCK_EMPTY=0x00
local ROCK_TELEPORT=0x0A
local ROCK_JUNK=0x0C
local ROCK_COPPER=0x0D
local ROCK_SILVER=0x0E
local ROCK_GOLD=0x0F
local ROCK_MYSTRILE=0x10
local ROCK_ORICHALC=0x11
local ROCK_ADAMANTITE=0x12
local ROCK_MOONSTONE=0x13
local ROCK_SANDROSE=0x14
local ROCK_PINKDIAMOND=0x15
local ROCK_ALEXANDRITE=0x16
local ROCK_MYTHICSTONE=0x17
local ROCK_DIAMOND=0x18
local ROCK_EMERALD=0x19
local ROCK_RUBY=0x1A
local ROCK_TOPAZ=0x1B
local ROCK_PERIDOT=0x1C
local ROCK_FLUORITE=0x1D
local ROCK_AGATE=0x1E
local ROCK_AMETHYST=0x1F
local ROCK_GODDESS=0x20
local ROCK_KAPPA=0x21

local DIRT_EMPTY=0x00
local DIRT_STAIRSDOWN=0x01
local DIRT_MONEY=0x02
local DIRT_POWERBERRY=0x03
local DIRT_CURSEDSICKLE=0x04
local DIRT_CURSEDHOE=0x05
local DIRT_CURSEDAXE=0x06
local DIRT_CURSEDHAMMER=0x07
local DIRT_CURSEDWATERINGCAN=0x08
local DIRT_CURSEDFISHINGROD=0x09
local DIRT_BLACKGRASS=0x0B
local DIRT_RECIPE=0x22

--Colors - tiles
local TYPECOLORS={}

TYPECOLORS[TYPE_SOIL]=0
TYPECOLORS[TYPE_TILLED]=0
TYPECOLORS[TYPE_STAIRSDOWN]=0
TYPECOLORS[TYPE_STAIRSUP]=0
TYPECOLORS[TYPE_STONE]=0
--Colors - rock contents
local ROCKCOLORS={}

ROCKCOLORS[ROCK_EMPTY]=0
ROCKCOLORS[ROCK_TELEPORT]="black"
ROCKCOLORS[ROCK_JUNK]="darkslategray"
ROCKCOLORS[ROCK_COPPER]="saddlebrown"
ROCKCOLORS[ROCK_SILVER]="silver"
ROCKCOLORS[ROCK_GOLD]="gold"
ROCKCOLORS[ROCK_MYSTRILE]="blue"
ROCKCOLORS[ROCK_ORICHALC]="lightgray"
ROCKCOLORS[ROCK_ADAMANTITE]="cyan"
ROCKCOLORS[ROCK_MOONSTONE]="lightgray"
ROCKCOLORS[ROCK_SANDROSE]="lightpink"
ROCKCOLORS[ROCK_PINKDIAMOND]="pink"
ROCKCOLORS[ROCK_ALEXANDRITE]="forestgreen"
ROCKCOLORS[ROCK_MYTHICSTONE]="black"
ROCKCOLORS[ROCK_DIAMOND]="lightcyan"
ROCKCOLORS[ROCK_EMERALD]="green"
ROCKCOLORS[ROCK_RUBY]="red"
ROCKCOLORS[ROCK_TOPAZ]="yellow"
ROCKCOLORS[ROCK_PERIDOT]="limegreen"
ROCKCOLORS[ROCK_FLUORITE]="mediumspringgreen"
ROCKCOLORS[ROCK_AGATE]="orange"
ROCKCOLORS[ROCK_AMETHYST]="purple"
ROCKCOLORS[ROCK_GODDESS]="black"
ROCKCOLORS[ROCK_KAPPA]="black"

--Colors - dirt contents
local DIRTCOLORS={}

DIRTCOLORS[DIRT_EMPTY]=0
DIRTCOLORS[DIRT_STAIRSDOWN]="orange"
DIRTCOLORS[DIRT_MONEY]="yellow"
DIRTCOLORS[DIRT_POWERBERRY]="red"
DIRTCOLORS[DIRT_CURSEDSICKLE]="pink"
DIRTCOLORS[DIRT_CURSEDHOE]="pink"
DIRTCOLORS[DIRT_CURSEDAXE]="pink"
DIRTCOLORS[DIRT_CURSEDHAMMER]="pink"
DIRTCOLORS[DIRT_CURSEDFISHINGROD]="pink"
DIRTCOLORS[DIRT_CURSEDWATERINGCAN]="pink"
DIRTCOLORS[DIRT_BLACKGRASS]="black"
DIRTCOLORS[DIRT_RECIPE]="gray"

--Output
local debugstring
local debugprint
local debugcounter

local rainbow

if(debugvaluables==true) then
	DIRTCOLORS[DIRT_MONEY]=0
	ROCKCOLORS[ROCK_JUNK]=0
end

while true do
	emu.frameadvance()
	--The script works only in mines, although the actual value stores location ID
	MineLevel=memory.read_u16_le(MineLevelAddress,DataDomain)%256-52
	if(MineLevel<0==false) then	
		debugstring=""
		debugcounter=0
		debugprint=false
		CameraX=memory.read_u16_le(CameraXAddress,CameraDomain)
		CameraY=memory.read_u16_le(CameraYAddress,CameraDomain)
		Stamina=memory.read_u8(StaminaAddress,DataDomain)
		Fatigue=bit.band(memory.read_u8(FatigueAddress,DataDomain),0x7F)
		rainbow=0xFF000000+(0x090807*(emu.framecount()))%0x1000000
		ROCKCOLORS[ROCK_KAPPA]=rainbow
		ROCKCOLORS[ROCK_GODDESS]=rainbow
		ROCKCOLORS[ROCK_TELEPORT]=rainbow
		rainbow=0xFF000000+(0x222222*(emu.framecount()%8))%0x1000000
		ROCKCOLORS[ROCK_MYTHICSTONE]=rainbow
		ROCKCOLORS[ROCK_PINKDIAMOND]=rainbow
		ROCKCOLORS[ROCK_ALEXANDRITE]=rainbow
		rainbow=0xFF000000+(0x080800*(emu.framecount()))%0x1000000
		DIRTCOLORS[DIRT_STAIRSDOWN]=rainbow
		rainbow=0xFF000000+(0x100000*(emu.framecount()))%0x1000000
		DIRTCOLORS[DIRT_POWERBERRY]=rainbow
		rainbow=0xFF000000+(0x080808*(emu.framecount()%32))%0x1000000
		DIRTCOLORS[DIRT_CURSEDSICKLE]=rainbow
		DIRTCOLORS[DIRT_CURSEDHOE]=rainbow
		DIRTCOLORS[DIRT_CURSEDAXE]=rainbow
		DIRTCOLORS[DIRT_CURSEDHAMMER]=rainbow
		DIRTCOLORS[DIRT_CURSEDWATERINGCAN]=rainbow
		DIRTCOLORS[DIRT_CURSEDFISHINGROD]=rainbow
		for row=0,27 do
			for column=0,27 do
				Tile=memory.read_u16_le(TileDataAddress+column*2+row*56,DataDomain)
				TileTYPE=bit.band(Tile,0x000F)
				TileROCK=bit.band(Tile,0x03F0)/16
				TileDIRT=bit.band(Tile,0xFC00)/1024
				if(TYPECOLORS[TileTYPE]~=0) then
					gui.drawRectangle(17+column*16-CameraX,57+row*16-CameraY,13,13,TYPECOLORS[TileTYPE],TYPECOLORS[TileTYPE])
				end
				if(DIRTCOLORS[TileDIRT]~=0) then
					gui.drawRectangle(27+column*16-CameraX,67+row*16-CameraY,3,3,DIRTCOLORS[TileDIRT],DIRTCOLORS[TileDIRT])	
				end
				if(ROCKCOLORS[TileROCK]~=0) then
					gui.drawRectangle(27+column*16-CameraX,57+row*16-CameraY,3,3,ROCKCOLORS[TileROCK],ROCKCOLORS[TileROCK])	
				end
				if(DIRTCOLORS[TileDIRT]==nil or ROCKCOLORS[TileROCK]==nil or TYPECOLORS[TileTYPE]==nil) then
					debugprint=true
					debugstring=debugstring..tostring(TileDIRT)..' '..tostring(TileROCK)..' '..tostring(TileTYPE)..'\t'
				end
				if(TileROCK==ROCK_GODDESS or TileROCK==ROCK_KAPPA) then
					debugcounter=debugcounter+1
				end
			end
			debugstring=debugstring..'\n'
		end
		gui.pixelText(116,140,Stamina,"cyan",0)
		gui.pixelText(116,149,Fatigue,"purple",0)
		if(debugcounter>0) then
			--There seem to be an error in the game when stones that are supposed
			--to drop jewels won't do that no matter what.
			--
			--This is a bug that can be fixed by entering any subscreen.
			--Namely, rucksack or diary screen. After that, a rock that contains
			--a jewel will drop it if it was not obtained on the current floor.
			gui.pixelText(1,1,"Activate subscreen to fix jewel drop bug.","red","black")
		end
		gui.pixelText(220,1,"B"..MineLevel,"white","black")
		if(debugprint==true) then
			console.clear()
			console.log(debugstring)
		end
	end
end