Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- memory.usememorydomain("Main Memory")
- gui.defaultPixelFont("fceux")
- MODE_BIG = 0
- MODE_SMALL = 2
- MODE_TOPDOWN = 4
- green = 0xFF00FF00
- red = 0xFFFF0000
- white = 0xFFFFFFFF
- --HITBOX LUA BY DACICUS
- -- RAM
- local addr_pc_x_hb_l = 0xA0
- local addr_pc_x_hb_r = 0xA1
- local addr_pc_y_hb_u = 0xA2
- local addr_pc_y_hb_d = 0xA3
- local addr_en_num = 0x001D
- local addr_en_actv = 0x0980
- local addr_en_y_lo = 0x0FEA
- local addr_en_y_hi = 0x1060
- local addr_en_x_lo = 0x10D6
- local addr_en_x_hi = 0x114C
- local addr_en_type = 0x131D
- local addr_en_hp = 0x14D6
- -- ROM
- local addr_en_y_len = 0x57A9
- local addr_en_x_len = 0x56D3
- local hitboxxoffset = 6
- local hitboxyoffset = 10
- local function draw_pc_hitbox()
- local x_hb_l = memory.readbyte(addr_pc_x_hb_l)
- local x_hb_r = memory.readbyte(addr_pc_x_hb_r)
- local y_hb_u = memory.readbyte(addr_pc_y_hb_u)
- local y_hb_d = memory.readbyte(addr_pc_y_hb_d)
- gui.drawBox(x_hb_l - hitboxxoffset, y_hb_u - hitboxyoffset, x_hb_r - hitboxxoffset, y_hb_d - hitboxyoffset)
- end
- local function draw_en_hitbox()
- local num_en = memory.readbyte(addr_en_num)
- for i = 0, num_en - 1 do
- local en_actv = memory.readbyte(addr_en_actv + i)
- local e = memory.readbyte(addr_en_type + en_actv)
- local e_y = memory.read_s8(addr_en_y_hi + en_actv) * 0x100 + memory.read_u8(addr_en_y_lo + en_actv)
- local e_y_len = memory.readbyte(addr_en_y_len + e, "ROM")
- local e_x = memory.read_s8(addr_en_x_hi + en_actv) * 0x100 + memory.read_u8(addr_en_x_lo + en_actv)
- local e_x_len = memory.readbyte(addr_en_x_len + e, "ROM")
- gui.drawBox(e_x - e_x_len - hitboxxoffset, e_y - e_y_len - hitboxyoffset, e_x + e_x_len - hitboxxoffset, e_y + e_y_len - hitboxyoffset)
- local en_hp = memory.readbyte(addr_en_hp + en_actv)
- if en_hp > 0 then
- gui.drawText(e_x - hitboxxoffset, e_y - hitboxyoffset, string.format("%2x", en_hp))
- end
- end
- end
- print("Lucida Sans Typewriter font is necessary for this script to display")
- print("C = [C]heat infinite health")
- print("D = Toggle RAM [D]isplay")
- print("H = Toggle [H]itbox display (none, player, all)")
- function checkRAM()
- RAM_LEVEL_RESET = memory.read_u8(0x003D)
- --HUD stuff
- RAM_SCORE_BIG = memory.read_u8(0x0070) --first two digits
- RAM_SCORE_MED = memory.read_u8(0x0071) --middle two digits
- RAM_SCORE_SMALL = memory.read_u8(0x0072) --last two digits
- RAM_COINS = memory.read_u8(0x0073)
- RAM_SWORD = memory.read_u8(0x0074)
- --0075 looks to handle which legendary items you've obtained; 1 = first, 2 = second, 4 = last, so 7 = all 3
- RAM_HP = memory.read_u8(0x0076)
- --0077 looks to handle if you've upgraded your maximum candles; starts at 4
- RAM_SCROLL_AMMO = memory.read_u8(0x0078)
- RAM_COUNTDOWN = memory.read_u16_le(0x0079)
- RAM_HUD_X = memory.read_u8(0x0E0A)
- if (bossAddress ~= null) then
- prevbossHP = RAM_BOSS_HP
- RAM_BOSS_HP = memory.read_u8(bossAddress)
- else RAM_BOSS_HP = 0 end
- --position stuff?
- RAM_FOREGROUND_X_VEL = memory.read_s8(0x0091) --signed!
- RAM_CAMERA_X_POS_ASC = (memory.read_s8(0x0E2B) * 256) + memory.read_u8(0x0E23)
- RAM_Y_POS = memory.read_u8(0x1059)
- prevtopdownY = RAM_Y_POS_TOPDOWN
- RAM_Y_POS_TOPDOWN = memory.read_u8(0x0E27)
- RAM_Y_VEL = memory.read_s8(0x00A07) --signed!
- RAM_CAN_JUMP = memory.read_u8(0x0A00)
- prevslash = RAM_CAN_SLASH
- RAM_CAN_SLASH = memory.read_u8(0x0A0B)
- RAM_INVULN1 = memory.read_u8(0x00B4)
- RAM_INVULN2 = memory.read_u8(0x00BB)
- prevlevel = RAM_LEVEL
- RAM_LEVEL = memory.read_u8(0x0060)
- RAM_MODE = memory.read_u8(0x0061)
- --I've assumed 0, 2, and 4 are the only valid options for this, based on checking level 1-5
- if (RAM_MODE % 2 > 0 or RAM_MODE > 4) then print("weird mode detected") end
- RAM_RNG = memory.read_u16_le(0x004A)
- RAM_GLOBAL_TIMER = memory.read_u8(0x003F)
- end
- function convert(number) --for any variables where 16 = 10, 32 = 20, etc.
- result = number - (math.floor(number / 16) * 6)
- return result
- end
- --moved it to a separate function so it can be collapsed since a lot of this shouldn't need to be touched anymore and we never want it off
- function drawHUDOverlay()
- fullScore = string.format("%02d%02d%02d",convert(RAM_SCORE_BIG),convert(RAM_SCORE_MED),convert(RAM_SCORE_SMALL))
- coins = string.format("%02d",convert(RAM_COINS))
- sword = string.format("%02d",convert(RAM_SWORD))
- hp = string.format("% 3d",convert(RAM_HP))
- ammo = string.format("Ammo:% 4d",RAM_SCROLL_AMMO)
- bossHP = string.format("% 3d",RAM_BOSS_HP)
- gui.drawRectangle(0+xoffset,14,46,11,"black","black")
- gui.drawText(0+xoffset, 14, fullScore, null, 0x00000000, 12, "Lucida Sans Typewriter")
- gui.drawRectangle(64+xoffset,14,14,11,"black","black")
- gui.drawText(64+xoffset, 14, coins, null, 0x00000000, 12, "Lucida Sans Typewriter")
- if (RAM_HUD_X == 80 and fightingBoss) then
- gui.drawText(0, 1, "Coins: " .. coins, null, 0x00000000, 12, "Lucida Sans Typewriter")
- end
- gui.drawRectangle(88+xoffset,14,14,11,"black","black")
- gui.drawText(88+xoffset, 14, sword, null, 0x00000000, 12, "Lucida Sans Typewriter")
- gui.drawText(135+xoffset, 14, hp, null, 0x00000000, 12, "Lucida Sans Typewriter")
- if (RAM_SCROLL_AMMO > 0) then
- gui.drawText(182, 0, ammo, null, 0x00000000, 10, "Lucida Sans Typewriter")
- end
- --if (RAM_BOSS_HP > 0) then
- if (fightingBoss) then
- gui.drawText(215+xoffset, 14, bossHP, null, 0x00000000, 12, "Lucida Sans Typewriter")
- if (prevframecount == emu.framecount()-1 and RAM_BOSS_HP < prevbossHP) then
- flyoffColor = white
- if (#flyoffs > 0) then
- if (emu.framecount() - flyoffs[#flyoffs][2] > 3) then flyoffColor = red
- elseif (emu.framecount() - flyoffs[#flyoffs][2] < 3) then flyoffColor = green end
- end
- table.insert(flyoffs, {RAM_BOSS_HP - prevbossHP, emu.framecount(), flyoffColor})
- end
- end
- end
- function drawFlyoffs()
- for i=#flyoffs,1,-1 do
- diff = emu.framecount() - flyoffs[i][2]
- if (diff >= 0) then
- gui.drawText(129, 117 - diff*6, flyoffs[i][1], 0xFF000000 - diff*0x20000000, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(128, 116 - diff*6, flyoffs[i][1], flyoffs[i][3] - diff*0x20000000, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- if (diff > 6) then
- table.remove(flyoffs,i)
- end
- else table.remove(flyoffs,i)
- end
- end
- end
- --Keyboard states last frame and this frame
- prevks = input.get()
- curks = input.get()
- checkRAM()
- prevframecount = emu.framecount()
- x_accum = 0
- fightingBoss = false
- bossAddress = null
- cheating = false
- runDisplay = true
- runHitbox = 1
- prevlevel = RAM_LEVEL
- prevslash = RAM_CAN_SLASH
- prevtopdownY = RAM_Y_POS_TOPDOWN
- prevbossHP = RAM_BOSS_HP
- xp = {}
- xp = {[0] = {[-1] = 0, [0] = 0}}
- current_branch = 0
- enemyhealths = {}
- flyoffs = {}
- while true do
- curks = input.get()
- if (fightingBoss) then xoffset = -RAM_HUD_X else xoffset = 0 end --compute xoffset before updating RAM to make it look nicer
- checkRAM()
- --the if section
- if (RAM_HUD_X == 0 or RAM_MODE ~= MODE_BIG) then
- fightingBoss = false
- bossAddress = null
- elseif (RAM_HUD_X > 0 and RAM_MODE == MODE_BIG and RAM_LEVEL ~= 76) then
- if (bossAddress == null) then
- for i=0x14D6,0x1500 do
- if (memory.read_u8(i) >= 30) then bossAddress = i break end
- end
- end
- if (bossAddress ~= null) then fightingBoss = true end
- end
- if (prevlevel ~= RAM_LEVEL) then
- fightingBoss = false
- bossAddress = null
- end
- --I don't trust Select any more
- --I used to mark lag frames with Select, but non-lag Select inputs caused extra lag in the dragon level
- --[[if (tastudio.engaged() and not tastudio.getrecording() and not client.isseeking()) then
- if (not client.isseeking() and tastudio.islag(emu.framecount()-1)) then
- movie.setrerecordcounting(false)
- tastudio.submitinputchange(emu.framecount()-1, "P1 Select", true)
- tastudio.applyinputchanges()
- movie.setrerecordcounting(true)
- end
- end]]
- --the ram display section that can be turned off
- if (runDisplay) then
- x_pos = string.format("x_pos:% 5d",RAM_CAMERA_X_POS_ASC)
- gui.drawText(71, 39, x_pos, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(70, 38, x_pos, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- if (RAM_MODE == MODE_TOPDOWN) then
- y_pos = string.format("y_pos:% 5d",RAM_Y_POS_TOPDOWN)
- else
- y_pos = string.format("y_pos:% 5d",RAM_Y_POS)
- end
- gui.drawText(151, 39, y_pos, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(150, 38, y_pos, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- local x_spd_color
- if ( RAM_FOREGROUND_X_VEL < -2 ) then x_spd_color = "green"
- elseif ( RAM_FOREGROUND_X_VEL >= 0 ) then x_spd_color = "red"
- else x_spd_color = null end
- x_spd = string.format("x_spd:% 5d",-RAM_FOREGROUND_X_VEL)
- gui.drawText(71, 49, x_spd, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(70, 48, x_spd, x_spd_color, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- if (RAM_MODE == MODE_TOPDOWN) then
- y_spd = string.format("y_spd:% 5d",RAM_Y_POS_TOPDOWN - prevtopdownY)
- else
- y_spd = string.format("y_spd:% 5d",RAM_Y_VEL)
- end
- gui.drawText(151, 49, y_spd, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(150, 48, y_spd, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- --draw invuln vars
- invuln1 = string.format("invu1:% 5d",RAM_INVULN1)
- invuln2 = string.format("invu2:% 5d",RAM_INVULN2)
- gui.drawText(71, 59, invuln1, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(70, 58, invuln1, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(151, 59, invuln2, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(150, 58, invuln2, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- --draw can jump and can slash
- if (RAM_MODE == MODE_BIG) then
- --the "can jump" var is more complex in big mode
- --the "can slash" one I don't know yet
- if (RAM_CAN_JUMP == 2) then jump = "spawning"
- --NOTE: JUST landed means if you jump the PREVIOUS frame, you get a very short jump
- --could not find any RAM address that works on the frame of the short jump
- elseif (RAM_CAN_JUMP == 4) then jump = "JUST landed"
- elseif (RAM_CAN_JUMP == 6) then jump = "recovery"
- elseif (RAM_CAN_JUMP == 8) then jump = "walking"
- elseif (RAM_CAN_JUMP == 12) then jump = "kneeling"
- elseif (RAM_CAN_JUMP == 14) then jump = "unkneeled"
- elseif (RAM_CAN_JUMP == 16) then jump = "midair"
- elseif (RAM_CAN_JUMP == 24) then jump = "completed"
- else jump = string.format("unknown %d",RAM_CAN_JUMP) end
- slash = ""
- else
- jump = "jump?: no"
- if (RAM_CAN_JUMP == 4) then jump = "jump?: yes" end
- if (RAM_CAN_SLASH > 0 or prevslash > 0) then
- for i=0x150C,0x1549 do
- --reinitialize table at start of slash or if obvious rewinding has occurred
- if (not enemyhealths[i] or prevslash ~= RAM_CAN_SLASH+1) then enemyhealths[i] = memory.read_u8(i) end
- if (memory.read_u8(i) < enemyhealths[i]) then
- enemyhealths[i] = memory.read_u8(i)
- table.insert(flyoffs, {enemyhealths[i], emu.framecount(), white})
- end
- end
- slash = string.format("slash:% 5d",RAM_CAN_SLASH)
- else enemyhealths = {} --reset table if not slashing
- end
- if (RAM_CAN_SLASH == 0) then slash = "slash: yes" end
- end
- gui.drawText(71, 28, jump, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(70, 27, jump, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(151, 28, slash, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(150, 27, slash, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- rnghex = string.format("%04X", RAM_RNG)
- gui.drawText(231, 29, rnghex, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(230, 28, rnghex, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- if (RAM_COUNTDOWN > 0) then
- gui.drawText(231, 39, RAM_COUNTDOWN, "red", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(230, 38, RAM_COUNTDOWN, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- else
- gui.drawText(231, 39, RAM_GLOBAL_TIMER, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(230, 38, RAM_GLOBAL_TIMER, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- end
- --dragon heads
- if (RAM_LEVEL == 42) then
- head1 = string.format("H1:%2d", memory.read_u8(0x14DC))
- head2 = string.format("H2:%2d", memory.read_u8(0x14E3))
- head3 = string.format("H3:%2d", memory.read_u8(0x14EA))
- gui.drawText(231, 49, head1, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(230, 48, head1, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(231, 59, head2, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(230, 58, head2, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(231, 69, head3, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(230, 68, head3, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- end
- end
- drawHUDOverlay()
- drawFlyoffs()
- --The keyboard input section
- if (curks["C"] and not prevks["C"]) then
- cheating = not cheating
- end
- if (curks["D"] and not prevks["D"]) then
- runDisplay = not runDisplay
- end
- if (curks["H"] and not prevks["H"]) then
- runHitbox = runHitbox + 1
- if (runHitbox == 3) then runHitbox = 0 end
- end
- if (runHitbox >= 1) then
- draw_pc_hitbox()
- end
- if (runHitbox == 2) then
- draw_en_hitbox()
- end
- if (cheating) then
- memory.write_u8(0x0076, 73)
- gui.drawText(231, 28, "CHEATING", "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- gui.drawText(230, 27, "CHEATING", "red", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
- end
- prevks = curks
- prevframecount = emu.framecount()
- emu.frameadvance()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement