Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Displays information for all objects on the bottom screen
- -- and top screen and GUI elements.
- -- This is completely safe to leaving running outside battles
- -- because the linked list contains 0 items and safely stop.
- -- I added the gameplay timer, battle timer, frame count, and
- -- lag count because DeSmuME's frame and lag counter would
- -- get in the way of the top screen object data.
- -- All displayed objects have their address listed for people
- -- interested in trying to break down their structs.
- local headOBAdr = 0x0235406C
- local tailOBAdr = 0x0235408C
- local headOTAdr = 0x0235C0F8
- local tailOTAdr = 0x0235C118
- local headGAdr = 0x02364184
- local tailGAdr = 0x023641A4
- local timeAdr = 0x02073AA4
- local timeBattleAdr = 0x02074E98
- local puckPassAdr = 0x023918CD
- function DEC_HEX(IN,i)
- local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
- while IN>0 do
- I=I+1
- IN,D=math.floor(IN/B),math.mod(IN,B)+1
- OUT=string.sub(K,D,D)..OUT
- end
- while i and i > string.len(OUT) do OUT = "0" .. OUT end
- return OUT
- end
- function readString(stringAdr)
- local index = 0
- local newString = ""
- local charBuffer
- while true do
- charBuffer = string.char(memory.readbyteunsigned(stringAdr + index))
- if charBuffer == "\0" then
- return newString
- else
- newString = newString .. charBuffer
- index = index + 1
- end
- end
- end
- function getGameplayTime()
- return memory.readdwordunsigned(timeAdr)
- end
- function getBattleTime()
- return memory.readdwordunsigned(timeBattleAdr)
- end
- -- Struct Functions
- function getAssetName(currPtr)
- return readString(memory.readdwordunsigned(currPtr+0x004))
- end
- function getIdent(currPtr)
- return memory.readdwordunsigned(currPtr+0x008)
- end
- function getIsValid(currPtr)
- return memory.readdwordunsigned(currPtr+0x00C) ~= 0xFFFFFFFF
- end
- function getNextPtr(currPtr)
- return memory.readdwordunsigned(currPtr+0x018)
- end
- -- Enemy Functions
- function getEnemyCurrHp(currPtr)
- return memory.readwordunsigned(currPtr+0x08C)
- end
- function setEnemyCurrHp(currPtr,hp)
- memory.writewordunsigned(currPtr+0x08C,hp)
- end
- function getEnemyMaxHp(currPtr)
- return memory.readwordunsigned(currPtr+0x08E)
- end
- function getEnemyInvuln(currPtr)
- return memory.readwordunsigned(currPtr+0x07A)
- end
- -- Pin Functions
- function getPinBootTime(currPtr)
- return memory.readwordunsigned(currPtr+0x068)
- end
- function getPinUses(currPtr)
- return memory.readwordunsigned(currPtr+0x064)
- end
- function getPinUsesMax(currPtr)
- return memory.readwordunsigned(currPtr+0x066)
- end
- -- Puck Functions
- function getPuckTravelTime(currPtr)
- return memory.readwordsigned(currPtr+0x7BC)
- end
- function getPuckDecay(currPtr)
- return memory.readdwordunsigned(currPtr+0x7CC)
- end
- function getPuckMultiplier(currPtr)
- return memory.readwordsigned(currPtr+0x7D0)
- end
- function getPuckHoldTime(currPtr)
- return memory.readwordsigned(currPtr+0x7D4)
- end
- function getPuckMultiplierChange(currPtr)
- local ratio = getPuckHoldTime(currPtr) / (930 - (memory.readbyteunsigned(puckPassAdr) * 30))
- if ratio >= 0.98 then
- return 50
- end
- if ratio >= 0.92 then
- return 20
- end
- if ratio >= 0.70 then
- return 10
- end
- return -100
- end
- function Data_Update_Bottom()
- local count
- local printStr = "Gameplay Time: " .. getGameplayTime()
- .. "\n" .. "Battle Time: " .. getBattleTime()
- .. "\n\n"
- local newStr
- -- Objects Bottom
- local currPtr = headOBAdr
- newStr = ""
- count = 0
- while memory.readdwordunsigned(currPtr) == 0x51342403 do
- currPtr = getNextPtr(currPtr) -- Skips Head
- local structName = getAssetName(currPtr)
- local continue = true
- if currPtr ~= tailOBAdr and getIsValid(currPtr) then
- if continue and structName == "EasyTask TCB" then
- -- May contain useful information to display later
- continue = false
- end
- if continue and structName == "_free_" then
- -- Allocated block that is no longer in use (garbage)
- continue = false
- end
- if continue and structName == "Tsk_BtlObs" then
- -- An obstacle on the field that can be moved/thrown
- continue = false
- end
- if continue and structName == "Tsk_BtlPlayer00" then
- -- Controllable(?) Neku on screen
- newStr = newStr
- .. DEC_HEX(currPtr,8)
- .. " - Neku"
- .. "\n"
- continue = false
- end
- if continue and structName == "Tsk_BtlPrizeItem" then
- newStr = newStr
- .. DEC_HEX(currPtr,8)
- .. " - Receive in: " .. getEnemyMaxHp(currPtr)
- .. "\n" .. DEC_HEX(getIdent(currPtr))
- .. "\t" .. structName
- .. "\n"
- continue = false
- end
- if continue then
- newStr = newStr
- .. DEC_HEX(currPtr,8)
- .. (
- (getEnemyInvuln(currPtr) > 0 and (" - Invuln: " .. getEnemyInvuln(currPtr)))
- or (" - HP: " .. getEnemyCurrHp(currPtr))
- )
- .. "\n" .. DEC_HEX(getIdent(currPtr))
- .. "\t" .. structName
- .. "\n"
- continue = false
- end
- else
- break
- end
- count = count + 1
- end
- if count > 0 then
- printStr = printStr .. "Object Count : " .. count .. "\n" .. newStr .. "\n"
- end
- -- GUI Bottom
- local currPtr = headGAdr
- newStr = ""
- count = 0
- while memory.readdwordunsigned(currPtr) == 0x51342403 and getNextPtr(currPtr) ~= tailGAdr do
- currPtr = getNextPtr(currPtr) -- Skips Head
- continue = true
- if getIsValid(currPtr) then
- if continue and getIdent(currPtr) == 0x000002C0 then
- -- A rebootable pin
- -- There are occasional false positives
- newStr = newStr
- .. DEC_HEX(currPtr,8)
- .. " - Pin"
- .. "\n-> " .. (
- (getPinUses(currPtr) > 0 and "Uses: " .. getPinUses(currPtr) .. "\t/ " .. getPinUsesMax(currPtr))
- or (getPinBootTime(currPtr) ~= 0xFFFF and "Boot:\t" .. getPinBootTime(currPtr))
- or "Booting Now..."
- )
- .. "\n"
- continue = false
- end
- if continue and getIdent(currPtr) == 0x000007E0 then
- -- Contains puck information
- newStr = newStr
- .. DEC_HEX(currPtr,8)
- .. " - Puck"
- .. "\n-> " .. (
- (getPuckTravelTime(currPtr) > 0 and "Travel: " .. getPuckTravelTime(currPtr))
- or "Hold: " .. getPuckHoldTime(currPtr) .. " (" .. (
- (getPuckMultiplierChange(currPtr) > 0 and "+" .. getPuckMultiplierChange(currPtr))
- or getPuckMultiplierChange(currPtr)
- )
- ) .. ")"
- .. "\n-> " .. "Multiplier: " .. getPuckMultiplier(currPtr)
- .. "\n"
- continue = false
- end
- if false and continue then
- newStr = newStr
- .. DEC_HEX(currPtr,8)
- .. "\tIdent:\t" .. DEC_HEX(getIdent(currPtr))
- .. "\n"
- continue = false
- end
- else
- break
- end
- count = count + 1
- end
- if count > 0 then
- printStr = printStr .. "GUI Count: " .. count .. "\n" .. newStr .. "\n"
- end
- -- Return Result
- return printStr
- end
- function Data_Update_Top()
- local count
- local printStr = "Frame: " .. emu.framecount() .. "\n"
- .. "Lag:" .. string.rep(" ",3+string.len(emu.framecount())-string.len(emu.lagcount())) .. emu.lagcount() .. "\n\n"
- local newStr
- -- Objects Bottom
- local currPtr = headOTAdr
- newStr = ""
- count = 0
- while memory.readdwordunsigned(currPtr) == 0x51342403 do
- currPtr = getNextPtr(currPtr) -- Skips Head
- local structName = getAssetName(currPtr)
- local continue = true
- if currPtr ~= tailOTAdr and getIsValid(currPtr) then
- if continue and structName == "EasyTask TCB" then
- -- May contain useful information to display later
- continue = false
- end
- if continue and structName == "_free_" then
- -- Allocated block that is no longer in use (garbage)
- continue = false
- end
- if continue and structName == "Tsk_BtlObs" then
- -- An obstacle on the field that can be moved/thrown
- continue = false
- end
- if continue and structName == "Tsk_BtlPlayer01" then
- -- Controllable(?) Shiki on screen?
- newStr = newStr
- .. DEC_HEX(currPtr,8)
- .. " - Shiki"
- .. "\n"
- continue = false
- end
- if continue and structName == "Tsk_BtlPrizeItem" then
- newStr = newStr
- .. DEC_HEX(currPtr,8)
- .. " - Receive in: " .. getEnemyMaxHp(currPtr)
- .. "\n" .. DEC_HEX(getIdent(currPtr))
- .. "\t" .. structName
- .. "\n"
- continue = false
- end
- if continue then
- newStr = newStr
- .. DEC_HEX(currPtr,8)
- .. (
- (getEnemyInvuln(currPtr) > 0 and (" - Invuln: " .. getEnemyInvuln(currPtr)))
- or (" - HP: " .. getEnemyCurrHp(currPtr))
- )
- .. "\n" .. DEC_HEX(getIdent(currPtr))
- .. "\t" .. structName
- .. "\n"
- continue = false
- end
- else
- break
- end
- count = count + 1
- end
- if count > 0 then
- printStr = printStr .. "Object Count : " .. count .. "\n" .. newStr .. "\n"
- end
- -- Return Result
- return printStr
- end
- function Data_Draw()
- gui.text(2,2,Data_Update_Bottom())
- gui.text(2,-190,Data_Update_Top())
- end
- gui.register(Data_Draw)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement