Advertisement
Blazephlozard

Genpei lua

Dec 17th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.02 KB | None | 0 0
  1. memory.usememorydomain("Main Memory")
  2. gui.defaultPixelFont("fceux")
  3.  
  4. MODE_BIG = 0
  5. MODE_SMALL = 2
  6. MODE_TOPDOWN = 4
  7.  
  8. green = 0xFF00FF00
  9. red = 0xFFFF0000
  10. white = 0xFFFFFFFF
  11.  
  12. --HITBOX LUA BY DACICUS
  13. -- RAM
  14. local addr_pc_x_hb_l = 0xA0
  15. local addr_pc_x_hb_r = 0xA1
  16. local addr_pc_y_hb_u = 0xA2
  17. local addr_pc_y_hb_d = 0xA3
  18.  
  19. local addr_en_num  = 0x001D
  20. local addr_en_actv = 0x0980
  21. local addr_en_y_lo = 0x0FEA
  22. local addr_en_y_hi = 0x1060
  23. local addr_en_x_lo = 0x10D6
  24. local addr_en_x_hi = 0x114C
  25. local addr_en_type = 0x131D
  26. local addr_en_hp   = 0x14D6
  27.  
  28. -- ROM
  29. local addr_en_y_len = 0x57A9
  30. local addr_en_x_len = 0x56D3
  31.  
  32. local hitboxxoffset = 6
  33. local hitboxyoffset = 10
  34.  
  35. local function draw_pc_hitbox()
  36.   local x_hb_l = memory.readbyte(addr_pc_x_hb_l)
  37.   local x_hb_r = memory.readbyte(addr_pc_x_hb_r)
  38.   local y_hb_u = memory.readbyte(addr_pc_y_hb_u)
  39.   local y_hb_d = memory.readbyte(addr_pc_y_hb_d)
  40.   gui.drawBox(x_hb_l - hitboxxoffset, y_hb_u - hitboxyoffset, x_hb_r - hitboxxoffset, y_hb_d - hitboxyoffset)
  41. end
  42.  
  43. local function draw_en_hitbox()
  44.   local num_en = memory.readbyte(addr_en_num)
  45.   for i = 0, num_en - 1 do
  46.     local en_actv = memory.readbyte(addr_en_actv + i)
  47.     local e = memory.readbyte(addr_en_type + en_actv)
  48.     local e_y = memory.read_s8(addr_en_y_hi + en_actv) * 0x100 + memory.read_u8(addr_en_y_lo + en_actv)
  49.     local e_y_len = memory.readbyte(addr_en_y_len + e, "ROM")
  50.     local e_x = memory.read_s8(addr_en_x_hi + en_actv) * 0x100 + memory.read_u8(addr_en_x_lo + en_actv)
  51.     local e_x_len = memory.readbyte(addr_en_x_len + e, "ROM")
  52.     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)
  53.  
  54.     local en_hp = memory.readbyte(addr_en_hp + en_actv)
  55.     if en_hp > 0 then
  56.       gui.drawText(e_x - hitboxxoffset, e_y - hitboxyoffset, string.format("%2x", en_hp))
  57.     end
  58.   end
  59. end
  60.  
  61. print("Lucida Sans Typewriter font is necessary for this script to display")
  62. print("C = [C]heat infinite health")
  63. print("D = Toggle RAM [D]isplay")
  64. print("H = Toggle [H]itbox display (none, player, all)")
  65.  
  66. function checkRAM()
  67.     RAM_LEVEL_RESET = memory.read_u8(0x003D)
  68.    
  69.     --HUD stuff
  70.     RAM_SCORE_BIG = memory.read_u8(0x0070) --first two digits
  71.     RAM_SCORE_MED = memory.read_u8(0x0071) --middle two digits
  72.     RAM_SCORE_SMALL = memory.read_u8(0x0072) --last two digits
  73.     RAM_COINS = memory.read_u8(0x0073)
  74.     RAM_SWORD = memory.read_u8(0x0074)
  75.     --0075 looks to handle which legendary items you've obtained; 1 = first, 2 = second, 4 = last, so 7 = all 3
  76.     RAM_HP = memory.read_u8(0x0076)
  77.     --0077 looks to handle if you've upgraded your maximum candles; starts at 4
  78.     RAM_SCROLL_AMMO = memory.read_u8(0x0078)
  79.     RAM_COUNTDOWN = memory.read_u16_le(0x0079)
  80.     RAM_HUD_X = memory.read_u8(0x0E0A)
  81.     if (bossAddress ~= null) then
  82.         prevbossHP = RAM_BOSS_HP
  83.         RAM_BOSS_HP = memory.read_u8(bossAddress)
  84.     else RAM_BOSS_HP = 0 end
  85.    
  86.     --position stuff?
  87.     RAM_FOREGROUND_X_VEL = memory.read_s8(0x0091) --signed!
  88.     RAM_CAMERA_X_POS_ASC = (memory.read_s8(0x0E2B) * 256) + memory.read_u8(0x0E23)
  89.    
  90.     RAM_Y_POS = memory.read_u8(0x1059)
  91.     prevtopdownY = RAM_Y_POS_TOPDOWN
  92.     RAM_Y_POS_TOPDOWN = memory.read_u8(0x0E27)
  93.     RAM_Y_VEL = memory.read_s8(0x00A07) --signed!
  94.    
  95.     RAM_CAN_JUMP = memory.read_u8(0x0A00)
  96.     prevslash = RAM_CAN_SLASH
  97.     RAM_CAN_SLASH = memory.read_u8(0x0A0B)
  98.  
  99.     RAM_INVULN1 = memory.read_u8(0x00B4)
  100.     RAM_INVULN2 = memory.read_u8(0x00BB)
  101.    
  102.     prevlevel = RAM_LEVEL
  103.     RAM_LEVEL = memory.read_u8(0x0060)
  104.     RAM_MODE = memory.read_u8(0x0061)
  105.     --I've assumed 0, 2, and 4 are the only valid options for this, based on checking level 1-5
  106.     if (RAM_MODE % 2 > 0 or RAM_MODE > 4) then print("weird mode detected") end
  107.    
  108.     RAM_RNG = memory.read_u16_le(0x004A)
  109.     RAM_GLOBAL_TIMER = memory.read_u8(0x003F)
  110. end
  111.  
  112. function convert(number) --for any variables where 16 = 10, 32 = 20, etc.
  113.     result = number - (math.floor(number / 16) * 6)
  114.     return result
  115. end
  116.  
  117. --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
  118. function drawHUDOverlay()
  119.     fullScore = string.format("%02d%02d%02d",convert(RAM_SCORE_BIG),convert(RAM_SCORE_MED),convert(RAM_SCORE_SMALL))
  120.     coins = string.format("%02d",convert(RAM_COINS))
  121.     sword = string.format("%02d",convert(RAM_SWORD))
  122.     hp = string.format("% 3d",convert(RAM_HP))
  123.     ammo = string.format("Ammo:% 4d",RAM_SCROLL_AMMO)
  124.     bossHP = string.format("% 3d",RAM_BOSS_HP)
  125.    
  126.     gui.drawRectangle(0+xoffset,14,46,11,"black","black")
  127.     gui.drawText(0+xoffset, 14, fullScore, null, 0x00000000, 12, "Lucida Sans Typewriter")
  128.    
  129.     gui.drawRectangle(64+xoffset,14,14,11,"black","black")
  130.     gui.drawText(64+xoffset, 14, coins, null, 0x00000000, 12, "Lucida Sans Typewriter")
  131.    
  132.     if (RAM_HUD_X == 80 and fightingBoss) then
  133.         gui.drawText(0, 1, "Coins: " .. coins, null, 0x00000000, 12, "Lucida Sans Typewriter")
  134.     end
  135.    
  136.     gui.drawRectangle(88+xoffset,14,14,11,"black","black")
  137.     gui.drawText(88+xoffset, 14, sword, null, 0x00000000, 12, "Lucida Sans Typewriter")
  138.    
  139.     gui.drawText(135+xoffset, 14, hp, null, 0x00000000, 12, "Lucida Sans Typewriter")
  140.     if (RAM_SCROLL_AMMO > 0) then
  141.         gui.drawText(182, 0, ammo, null, 0x00000000, 10, "Lucida Sans Typewriter")
  142.     end
  143.    
  144.     --if (RAM_BOSS_HP > 0) then
  145.     if (fightingBoss) then
  146.         gui.drawText(215+xoffset, 14, bossHP, null, 0x00000000, 12, "Lucida Sans Typewriter")
  147.         if (prevframecount == emu.framecount()-1 and RAM_BOSS_HP < prevbossHP) then
  148.             flyoffColor = white
  149.             if (#flyoffs > 0) then
  150.                 if (emu.framecount() - flyoffs[#flyoffs][2] > 3) then flyoffColor = red
  151.                 elseif (emu.framecount() - flyoffs[#flyoffs][2] < 3) then flyoffColor = green end
  152.             end
  153.             table.insert(flyoffs, {RAM_BOSS_HP - prevbossHP, emu.framecount(), flyoffColor})
  154.         end
  155.     end
  156. end
  157.  
  158. function drawFlyoffs()
  159.  
  160.     for i=#flyoffs,1,-1 do
  161.         diff = emu.framecount() - flyoffs[i][2]
  162.         if (diff >= 0) then
  163.             gui.drawText(129, 117 - diff*6, flyoffs[i][1], 0xFF000000 - diff*0x20000000, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  164.             gui.drawText(128, 116 - diff*6, flyoffs[i][1], flyoffs[i][3] - diff*0x20000000, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  165.             if (diff > 6) then
  166.                 table.remove(flyoffs,i)
  167.             end
  168.         else table.remove(flyoffs,i)
  169.         end
  170.     end
  171. end
  172.  
  173. --Keyboard states last frame and this frame
  174. prevks = input.get()
  175. curks = input.get()
  176.  
  177. checkRAM()
  178. prevframecount = emu.framecount()
  179.  
  180. x_accum = 0
  181. fightingBoss = false
  182. bossAddress = null
  183. cheating = false
  184. runDisplay = true
  185. runHitbox = 1
  186. prevlevel = RAM_LEVEL
  187. prevslash = RAM_CAN_SLASH
  188. prevtopdownY = RAM_Y_POS_TOPDOWN
  189. prevbossHP = RAM_BOSS_HP
  190.  
  191. xp = {}
  192. xp = {[0] = {[-1] = 0, [0] = 0}}
  193. current_branch = 0
  194. enemyhealths = {}
  195. flyoffs = {}
  196.  
  197. while true do
  198.     curks = input.get()
  199.     if (fightingBoss) then xoffset = -RAM_HUD_X else xoffset = 0 end --compute xoffset before updating RAM to make it look nicer
  200.    
  201.     checkRAM()
  202.    
  203.    
  204.    
  205.     --the if section
  206.     if (RAM_HUD_X == 0 or RAM_MODE ~= MODE_BIG) then
  207.         fightingBoss = false
  208.         bossAddress = null
  209.     elseif (RAM_HUD_X > 0 and RAM_MODE == MODE_BIG and RAM_LEVEL ~= 76) then
  210.         if (bossAddress == null) then
  211.             for i=0x14D6,0x1500 do
  212.                 if (memory.read_u8(i) >= 30) then bossAddress = i break end
  213.             end
  214.         end
  215.         if (bossAddress ~= null) then fightingBoss = true end
  216.     end
  217.  
  218.     if (prevlevel ~= RAM_LEVEL) then
  219.         fightingBoss = false
  220.         bossAddress = null
  221.     end
  222.     --I don't trust Select any more
  223.     --I used to mark lag frames with Select, but non-lag Select inputs caused extra lag in the dragon level
  224.     --[[if (tastudio.engaged() and not tastudio.getrecording() and not client.isseeking()) then
  225.         if (not client.isseeking() and tastudio.islag(emu.framecount()-1)) then
  226.             movie.setrerecordcounting(false)
  227.             tastudio.submitinputchange(emu.framecount()-1, "P1 Select", true)
  228.             tastudio.applyinputchanges()
  229.             movie.setrerecordcounting(true)
  230.         end
  231.     end]]
  232.  
  233.     --the ram display section that can be turned off
  234.     if (runDisplay) then
  235.         x_pos = string.format("x_pos:% 5d",RAM_CAMERA_X_POS_ASC)
  236.         gui.drawText(71, 39, x_pos, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  237.         gui.drawText(70, 38, x_pos, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  238.        
  239.         if (RAM_MODE == MODE_TOPDOWN) then
  240.             y_pos = string.format("y_pos:% 5d",RAM_Y_POS_TOPDOWN)
  241.         else
  242.             y_pos = string.format("y_pos:% 5d",RAM_Y_POS)
  243.         end
  244.         gui.drawText(151, 39, y_pos, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  245.         gui.drawText(150, 38, y_pos, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  246.  
  247.         local x_spd_color
  248.         if ( RAM_FOREGROUND_X_VEL < -2 ) then x_spd_color = "green"
  249.         elseif ( RAM_FOREGROUND_X_VEL >= 0 ) then x_spd_color = "red"
  250.         else x_spd_color = null end
  251.         x_spd = string.format("x_spd:% 5d",-RAM_FOREGROUND_X_VEL)
  252.         gui.drawText(71, 49, x_spd, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  253.         gui.drawText(70, 48, x_spd, x_spd_color, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  254.        
  255.         if (RAM_MODE == MODE_TOPDOWN) then
  256.             y_spd = string.format("y_spd:% 5d",RAM_Y_POS_TOPDOWN - prevtopdownY)
  257.         else
  258.             y_spd = string.format("y_spd:% 5d",RAM_Y_VEL)
  259.         end
  260.         gui.drawText(151, 49, y_spd, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  261.         gui.drawText(150, 48, y_spd, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  262.        
  263.         --draw invuln vars
  264.        
  265.         invuln1 = string.format("invu1:% 5d",RAM_INVULN1)
  266.         invuln2 = string.format("invu2:% 5d",RAM_INVULN2)
  267.         gui.drawText(71, 59, invuln1, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  268.         gui.drawText(70, 58, invuln1, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  269.         gui.drawText(151, 59, invuln2, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  270.         gui.drawText(150, 58, invuln2, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  271.        
  272.        
  273.         --draw can jump and can slash
  274.         if (RAM_MODE == MODE_BIG) then
  275.             --the "can jump" var is more complex in big mode
  276.             --the "can slash" one I don't know yet
  277.             if (RAM_CAN_JUMP == 2) then jump = "spawning"
  278.             --NOTE: JUST landed means if you jump the PREVIOUS frame, you get a very short jump
  279.             --could not find any RAM address that works on the frame of the short jump
  280.             elseif (RAM_CAN_JUMP == 4) then jump = "JUST landed"
  281.             elseif (RAM_CAN_JUMP == 6) then jump = "recovery"
  282.             elseif (RAM_CAN_JUMP == 8) then jump = "walking"
  283.             elseif (RAM_CAN_JUMP == 12) then jump = "kneeling"
  284.             elseif (RAM_CAN_JUMP == 14) then jump = "unkneeled"
  285.             elseif (RAM_CAN_JUMP == 16) then jump = "midair"
  286.             elseif (RAM_CAN_JUMP == 24) then jump = "completed"
  287.             else jump = string.format("unknown %d",RAM_CAN_JUMP) end
  288.             slash = ""
  289.         else
  290.             jump = "jump?:   no"
  291.             if (RAM_CAN_JUMP == 4) then jump = "jump?:  yes" end
  292.             if (RAM_CAN_SLASH > 0 or prevslash > 0) then
  293.                 for i=0x150C,0x1549 do
  294.                     --reinitialize table at start of slash or if obvious rewinding has occurred
  295.                     if (not enemyhealths[i] or prevslash ~= RAM_CAN_SLASH+1) then enemyhealths[i] = memory.read_u8(i) end
  296.                     if (memory.read_u8(i) < enemyhealths[i]) then
  297.                         enemyhealths[i] = memory.read_u8(i)
  298.                         table.insert(flyoffs, {enemyhealths[i], emu.framecount(), white})
  299.                     end
  300.                 end
  301.                 slash = string.format("slash:% 5d",RAM_CAN_SLASH)
  302.             else enemyhealths = {} --reset table if not slashing
  303.             end
  304.             if (RAM_CAN_SLASH == 0) then slash = "slash:  yes" end
  305.         end
  306.         gui.drawText(71, 28, jump, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  307.         gui.drawText(70, 27, jump, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  308.        
  309.         gui.drawText(151, 28, slash, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  310.         gui.drawText(150, 27, slash, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  311.  
  312.         rnghex = string.format("%04X", RAM_RNG)
  313.        
  314.         gui.drawText(231, 29, rnghex, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  315.         gui.drawText(230, 28, rnghex, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  316.        
  317.         if (RAM_COUNTDOWN > 0) then
  318.             gui.drawText(231, 39, RAM_COUNTDOWN, "red", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  319.             gui.drawText(230, 38, RAM_COUNTDOWN, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  320.         else
  321.             gui.drawText(231, 39, RAM_GLOBAL_TIMER, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  322.             gui.drawText(230, 38, RAM_GLOBAL_TIMER, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  323.         end
  324.        
  325.         --dragon heads
  326.         if (RAM_LEVEL == 42) then
  327.             head1 = string.format("H1:%2d", memory.read_u8(0x14DC))
  328.             head2 = string.format("H2:%2d", memory.read_u8(0x14E3))
  329.             head3 = string.format("H3:%2d", memory.read_u8(0x14EA))
  330.             gui.drawText(231, 49, head1, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  331.             gui.drawText(230, 48, head1, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  332.             gui.drawText(231, 59, head2, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  333.             gui.drawText(230, 58, head2, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  334.             gui.drawText(231, 69, head3, "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  335.             gui.drawText(230, 68, head3, null, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  336.         end
  337.        
  338.     end
  339.    
  340.     drawHUDOverlay()
  341.     drawFlyoffs()
  342.    
  343.     --The keyboard input section
  344.     if (curks["C"] and not prevks["C"]) then
  345.         cheating = not cheating
  346.     end
  347.     if (curks["D"] and not prevks["D"]) then
  348.         runDisplay = not runDisplay
  349.     end
  350.     if (curks["H"] and not prevks["H"]) then
  351.         runHitbox = runHitbox + 1
  352.         if (runHitbox == 3) then runHitbox = 0 end
  353.     end
  354.    
  355.     if (runHitbox >= 1) then
  356.         draw_pc_hitbox()
  357.     end
  358.     if (runHitbox == 2) then
  359.         draw_en_hitbox()
  360.     end
  361.    
  362.     if (cheating) then
  363.         memory.write_u8(0x0076, 73)
  364.         gui.drawText(231, 28, "CHEATING", "black", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  365.         gui.drawText(230, 27, "CHEATING", "red", 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  366.     end
  367.    
  368.     prevks = curks
  369.     prevframecount = emu.framecount()
  370.     emu.frameadvance()
  371. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement