Blazephlozard

Tanzer Lua script

Apr 21st, 2023
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.69 KB | None | 0 0
  1. memory.usememorydomain("68K RAM")
  2. gui.defaultPixelFont("fceux")
  3.  
  4. green = 0xFF00FF00
  5. red = 0xFFFF0000
  6. white = 0xFFFFFFFF
  7. black = 0xFF000000
  8. blank = 0x00000000
  9.  
  10. --canvas = gui.createcanvas(600,600)
  11.  
  12. --client.SetGameExtraPadding(0,0,0,0)
  13. --480x270? aka 1920x1080 x4
  14. pleft = 60
  15. ptop = 23
  16. pright = 100
  17. pbottom = 23
  18. client.SetGameExtraPadding(pleft,ptop,pright,pbottom)
  19.  
  20. camera = memory.read_u16_be(0x582A)
  21. enemyHPs = {}
  22. for i=1,16 do
  23. enemyHPs[i] = memory.readbyte(0x1E96 + (i*0x70))
  24. end
  25.  
  26. --X range: 500 to startingX
  27. --Y range: 300 to 1000
  28.  
  29. function fastSpeed()
  30.     movie.setrerecordcounting(false)
  31.     client.speedmode(6399) --maximum?
  32.     client.SetSoundOn(false)
  33.     client.unpause()
  34. end
  35. function normalSpeed()
  36.     movie.setrerecordcounting(true)
  37.     client.speedmode(100)
  38.     client.SetSoundOn(true)
  39.     client.pause()
  40. end
  41.  
  42. function drawFlyoffs()
  43.     life = 30
  44.     for i=#flyoffs,1,-1 do
  45.         diff = emu.framecount() - flyoffs[i][2]
  46.         if (diff >= 0) then
  47.             gui.drawText(flyoffs[1][4]+pleft, flyoffs[1][5]+ptop - diff*(30/life), flyoffs[i][1], 0xFF000000 - math.floor((diff/life)*0xFF) * 0x1000000, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  48.             gui.drawText(flyoffs[1][4]-1+pleft, flyoffs[1][5]-1+ptop - diff*(30/life), flyoffs[i][1], flyoffs[i][3] - math.floor((diff/life)*0xFF) * 0x1000000, 0x00000000, 10, "Lucida Sans Typewriter", null, "right")
  49.             if (diff >= life) then
  50.                 table.remove(flyoffs,i)
  51.             end
  52.         else table.remove(flyoffs,i)
  53.         end
  54.     end
  55. end
  56.  
  57. function drawHitbox(addr,color,fill,firstTripleFrame,isMisc)
  58.         color = color or white
  59.         fill = fill or blank
  60.         firstTripleFrame = firstTripleFrame or false
  61.         debugThis = debugThis or false
  62.        
  63.         if (memory.readbyte(addr) > 0) then
  64.        
  65.         xpos = memory.read_s16_be(addr+0x07)
  66.         ypos = memory.read_s16_be(addr+0x0B)
  67.        
  68.         xoffset = memory.read_s16_be(addr+0x43)
  69.         yoffset = memory.read_s16_be(addr+0x47)
  70.         width = memory.read_u16_be(addr+0x4B)
  71.         height = memory.read_u16_be(addr+0x4F)
  72.        
  73.         --hacky but I can't find the RAM address that accounts for the oddity of triple jump's first frame hitbox
  74.         --it definitely goes 200 units right, it seems like it goes down a bit too
  75.         --0A88-0A8A seem suspect, but at the very least, they seem to let me know if it's leftward or rightward
  76.         if (firstTripleFrame and width == 400) then
  77.             if (memory.readbyte(0x0A8A) == 224) then
  78.                 xpos = xpos + 200
  79.             else
  80.                 xpos = xpos - 200
  81.             end
  82.             ypos = ypos + 16
  83.         end
  84.  
  85.         x1 = (xpos+xoffset)/4 - camera
  86.         x2 = (xpos+xoffset+width)/4 - camera
  87.         y1 = (ypos+yoffset)/4
  88.         y2 = (ypos+yoffset+height)/4
  89.        
  90.         if (isMisc) then
  91.         x1 = (xpos+xoffset)/4 - camera - 2
  92.         x2 = (xpos+xoffset+width)/4 - camera +2
  93.         y1 = (ypos+yoffset)/4 - 2
  94.         y2 = (ypos+yoffset+height)/4 + 2
  95.         end
  96.        
  97.         --gui.drawPixel(xpos/4-camera,ypos/4,green)
  98.         gui.drawBox(x1+pleft,y1+ptop,x2+pleft,y2+ptop,color,fill)
  99.         --canvas.DrawBox(x1,y1,x2,y2,color,fill)
  100.         --if (debugThis) then print(x1 .. " " .. x2 .. " " .. y1 .. " " .. y2) end
  101.         end
  102. end
  103. --drawHitbox(0x0A7A,red)
  104. --drawHitbox(0x4CEE,0xFFFF00FF)
  105. --testHitbox()
  106.  
  107. prevcamera = memory.read_u16_be(0x582A)
  108. prevgold = memory.readbyte(0x1E85)
  109. prevjumps = memory.readbyte(0x4D52)
  110. PrevFrameTimer = memory.readbyte(0x5541);
  111. PrevFrame = emu.framecount()
  112.  
  113. PrevX = 0
  114. XDiff = 0
  115. PrevY = 0
  116. YDiff = 0
  117.  
  118. XColor = "white"
  119. XDiffColor = "white"
  120. XSpdColor = "white"
  121. YColor = "white"
  122. YDiffColor = "white"
  123. YSpdColor = "white"
  124.  
  125. XPosTable = {}
  126. flyoffs = {}
  127.  
  128. while true do
  129.  
  130.     camera = memory.read_u16_be(0x582A)
  131.  
  132.     X = memory.read_u16_be(0x4CF5)
  133.     Y = memory.read_u16_be(0x4CF9)
  134.    
  135.     playerActive = memory.readbyte(0x4CEE)
  136.     bossActive = memory.readbyte(0x2CEA)
  137.  
  138.     --draw player hitboxes
  139.     drawHitbox(0x4CEE,0x80FF00FF,0x40FF00FF)
  140.  
  141.     totalEnemies = 0
  142.     totalProjectiles = 0
  143.     totalMisc = 0
  144.     totalItem = 0
  145.     totalAttack = 0
  146.     --draw 16 enemy slot hitboxes
  147.     for i = 0, 15 do
  148.         if (memory.readbyte(0x1782 + (i*0x70)) > 0) then
  149.             totalEnemies = totalEnemies + 1
  150.             drawHitbox((0x1782 + (i*0x70)),0x80FFFFFF,0x40FFFFFF)
  151.  
  152.             local enemyhp = memory.read_s16_be(0x17C0 + (i*0x70))
  153.             local lostthisframe = ""
  154.             if enemyhp > 0 then
  155.                 hpcolor = white
  156.                 if (enemyhp < enemyHPs[i+1]) then
  157.                     hpcolor = red
  158.                     lostthisframe = enemyhp - enemyHPs[i+1]
  159.                 end
  160.                 enemyHPs[i+1] = enemyhp
  161.                 enemyHPy = y2+1+ptop
  162.                 if (enemyHPy > 265) then enemyHPy = y1-9+ptop end
  163.               gui.pixelText(x1+pleft, enemyHPy, enemyhp, hpcolor, 0x80000000)
  164.               if (lostthisframe ~= "") then gui.pixelText(x1+pleft, enemyHPy+9, lostthisframe, hpcolor, 0x80000000) end
  165.             end
  166.         end
  167.     end
  168.    
  169.     --draw 16 projectile slot hitboxes
  170.     for i = 0, 15 do
  171.         if (memory.readbyte(0x1E96 + (i*0x70)) > 0) then
  172.             totalProjectiles = totalProjectiles + 1
  173.             drawHitbox((0x1E96 + (i*0x70)),0xB0000000,0x80000000)
  174.         end
  175.     end
  176.    
  177.     --draw 18 misc visual hitboxes
  178.     for i = 0, 17 do
  179.         if (memory.readbyte(0x0C46 + (i*0x70)) > 0) then
  180.             totalMisc = totalMisc + 1
  181.             drawHitbox((0x0C46 + (i*0x70)),0x8000FF00,0x6000FF00,false,true)
  182.         end
  183.     end
  184.    
  185.     --draw 16 item hitboxes
  186.     for i = 0, 15 do
  187.         if (memory.readbyte(0x037A + (i*0x70)) > 0) then
  188.             totalItem = totalItem + 1
  189.             drawHitbox((0x037A + (i*0x70)),0x60FFFF00,0x30FFFF00)
  190.         end
  191.     end
  192.    
  193.     --draw 4 player attack hitboxes
  194.     for i = 0, 3 do
  195.         if (memory.readbyte(0x0A7A + (i*0x70)) > 0) then
  196.             totalAttack = totalAttack + 1
  197.             isTriple = false
  198.             if (memory.readbyte(0x4D05) == 7 and i == 0) then isTriple = true end
  199.             drawHitbox(0x0A7A + (i*0x70),0x80FF0000,0x40FF0000,isTriple)
  200.  
  201.         end
  202.     end
  203.    
  204.     XDiff = X - PrevX;
  205.     if (emu.framecount() - 1 ~= PrevFrame and XPosTable[emu.framecount()-1] ~= nil) then XDiff = X - XPosTable[emu.framecount()-1] end
  206.     PrevX = X;
  207.     YDiff = Y - PrevY;
  208.     PrevY = Y;
  209.    
  210.     if (XPosTable[emu.framecount()] == null) then
  211.         XPosTable[emu.framecount()] = X;
  212.         XColor = "white";
  213.     elseif (XPosTable[emu.framecount()] == X) then
  214.         XColor = "white";
  215.     elseif (XPosTable[emu.framecount()] < X) then
  216.         XPosTable[emu.framecount()] = X;
  217.         XColor = "green";
  218.     else
  219.         XColor = "red";
  220.     end
  221.    
  222.     if XDiff>16 then
  223.         XDiffColor = "green"
  224.     elseif XDiff<16 and emu.framecount() - 1 == PrevFrame then
  225.         XDiffColor = "red"
  226.         --if (playerActive == 1 and camera ~= 0 and (bossActive ~= 1 or #flyoffs == 0)) then table.insert(flyoffs, {"moved " .. XDiff .. " at " .. emu.framecount(), emu.framecount(), red, 215,40}) end
  227.     else
  228.         XDiffColor = "white"
  229.     end
  230.    
  231.     --if (bossActive == 1) then gui.pixelText(130+pleft,2+ptop, "boss active?",red) end
  232.    
  233.     gui.pixelText(3+pleft, 2+ptop, string.format("% 6d",X),XColor)
  234.     --gui.pixelText(10, 18, string.format("% 9.3f",XSpd),XSpdColor)
  235.     gui.pixelText(3+pleft, 11+ptop, string.format("% 6d",XDiff),XDiffColor)
  236.    
  237.     gui.pixelText(40+pleft, 2+ptop, string.format("% 6d",Y),YColor)
  238.     --gui.pixelText(65, 18, string.format("% 9.3f",YSpd))
  239.     gui.pixelText(40+pleft, 11+ptop, string.format("% 6d",YDiff),YDiffColor)
  240.    
  241.     cameraX = memory.readbyte(0x1E85)
  242.     cameracolor = white
  243.     if (camera - prevcamera < 4) then
  244.         cameracolor = "red"
  245.         if (camera - prevcamera > 0) then table.insert(flyoffs, {"camera moved " .. (camera-prevcamera) .. " at " .. emu.framecount(), emu.framecount(), red, 215,40}) end
  246.     elseif (camera - prevcamera > 4) then cameracolor = "green" end
  247.     prevcamera = camera
  248.    
  249.     gold = memory.read_u16_be(0x1E84)
  250.     goldcolor = white
  251.     if (gold > prevgold) then goldcolor = "gold" end
  252.     prevgold = gold
  253.    
  254.     jumps = memory.readbyte(0x4D52)
  255.     if (memory.readbyte(0x8124) == 186 and memory.readbyte(0x8125) == 186) then
  256.         jumps = 3
  257.     end
  258.     jumpcolor = white
  259.     if (jumps > prevjumps) then jumpcolor = "green" end
  260.     if (jumps == 0) then jumpcolor = "red" end
  261.     prevjumps = jumps
  262.    
  263.     attackFrames = memory.readbyte(0x4D05)
  264.     specialBar = memory.readbyte(0x0374)
  265.     specialTenths = memory.readbyte(0x261B)
  266.    
  267.     specialcolor = red
  268.     if (specialBar == 24) then specialcolor = white
  269.         specialTenths = 0 end
  270.    
  271.     spawngroup = memory.readbyte(0x15DF)
  272.    
  273.     timercolor = white
  274.     BigFrameTimer = memory.read_u16_be(0x5540);
  275.     FrameTimer = memory.readbyte(0x5541);
  276.     --Check if the player object is active and camera isn't 0 before we tamper with lag frames
  277.     if (playerActive == 1 and camera ~= 0) then
  278.         --Determine Lag
  279.         tastudio.setlag(emu.framecount(),false)
  280.         if (BigFrameTimer ~= 0 and FrameTimer == PrevFrameTimer and PrevFrame ~= emu.framecount()) then
  281.             tastudio.setlag(emu.framecount(),true)
  282.         end
  283.     end
  284.     if (BigFrameTimer ~= 0 and FrameTimer == PrevFrameTimer and PrevFrame ~= emu.framecount()) then
  285.         timercolor = red
  286.     end
  287.     PrevFrameTimer = FrameTimer
  288.     PrevFrame = emu.framecount()
  289.    
  290.     textx = 3 + pleft
  291.     texty = 20 + ptop
  292.     gui.pixelText(textx, texty, string.format(" camera:%4d",camera),cameracolor)
  293.     texty = texty+9
  294.     gui.pixelText(textx, texty, string.format("   gold: %3d",gold),goldcolor)
  295.     texty = texty+9
  296.     gui.pixelText(textx, texty, "  jumps:   " .. jumps,jumpcolor)
  297.     texty = texty+9
  298.     gui.pixelText(textx, texty, " attack:   " .. attackFrames,white)
  299.     texty = texty+9
  300.     gui.pixelText(textx, texty, string.format("special:%2d.%1d",specialBar,specialTenths), specialcolor)
  301.     texty = texty+9
  302.     gui.pixelText(textx, texty, string.format("  timer:%4d",BigFrameTimer), timercolor)
  303.    
  304.     texty = 166 + ptop
  305.     gui.pixelText(textx, texty, string.format("spawn:    %2d",spawngroup),white)
  306.     texty = texty+9
  307.     gui.pixelText(textx, texty, string.format("enemy: %2d/16",totalEnemies),white)
  308.     texty = texty+9
  309.     gui.pixelText(textx, texty, string.format(" proj: %2d/16",totalProjectiles),white)
  310.     texty = texty+9
  311.     gui.pixelText(textx, texty, string.format(" misc: %2d/18",totalMisc),white)
  312.     texty = texty+9
  313.     gui.pixelText(textx, texty, string.format(" item: %2d/16",totalItem),white)
  314.     texty = texty+9
  315.     gui.pixelText(textx, texty, string.format(" attk:  %2d/4",totalAttack),white)
  316.     texty = texty+9
  317.    
  318.     drawFlyoffs()
  319.    
  320.     emu.frameadvance()
  321. end
  322.  
  323.  
Advertisement
Add Comment
Please, Sign In to add comment