Enjl

antizip

Aug 25th, 2020 (edited)
2,351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.84 KB | None | 0 0
  1. local az = {}
  2.  
  3. az.enabled = true
  4.  
  5. local stuckTimer = 0
  6. local stuckx
  7. local lastPlayerX = 0
  8. local hasPressedDown = false
  9. local wasOnSlope = false
  10. local unduckCollider = Colliders.Box(0,0,0,0)
  11. local regularPlayerHeight = 0
  12. local duckingPlayerHeight = 0
  13. local lastCharacter = nil
  14. local lastPowerup = nil
  15. local lastForcedState = 0
  16. local isDuckPowering = false
  17. local previousY = 0
  18. local freezeState = {
  19.     [1] = true,
  20.     [2] = true,
  21.     [4] = true,
  22.     [5] = true,
  23.     [11] = true,
  24.     [12] = true,
  25.     [41] = true,
  26. }
  27.  
  28. local function blockcheck(offset)
  29.     local y = player.y
  30.     local blocks = Block.getIntersecting(player.x, y + offset, player.x + player.width, y + offset + player.height)
  31.     local goodblocks = {}
  32.     for k,v in ipairs(blocks) do
  33.         if (Block.SOLID_MAP[v.id] or Block.PLAYERSOLID_MAP[v.id]) and (not v.isHidden) and v:mem(0x5C, FIELD_WORD) == 0 then
  34.             if Colliders.collide(player, v) then
  35.                 table.insert(goodblocks, v)
  36.             end
  37.         end
  38.     end
  39.     return #goodblocks > 0, goodblocks
  40. end
  41.  
  42. local function miniBlockCheck(x1, y1, blocks)
  43.     local collisionZone = Colliders.Box(x1, y1, player.width, player.height)
  44.  
  45.     for k,v in ipairs(blocks) do
  46.         if (not Block.SLOPE_MAP[v.id]) and Colliders.collide(collisionZone, v) then
  47.             return true
  48.         end
  49.     end
  50.     return false
  51. end
  52.  
  53. local function expandBlockChecks()
  54.     if wasOnSlope ~= 0 then return false end
  55.  
  56.     local x1 = player.x - 8
  57.     local y1 = player.y - 8
  58.     local x2 = player.x + player.width + 8
  59.     local y2 = player.y + player.height + 8
  60.     local blocks = Colliders.getColliding{
  61.         a = Colliders.Box(x1, y1, player.width + 16, player.height + 16),
  62.         b = Block.SOLID .. Block.PLAYERSOLID,
  63.         btype = Colliders.BLOCK,
  64.         filter = function(other)
  65.             if other.isHidden then return false end
  66.             if other:mem(0x5A, FIELD_WORD) == -1 then return false end
  67.             if other:mem(0x1C, FIELD_WORD) == -1 then return false end
  68.             if other:mem(0x1C, FIELD_WORD) == -1 then return false end
  69.             return true
  70.         end
  71.     }
  72.     x1 = x1 - player.width
  73.     y1 = y1 - player.height
  74.     local dodged = false
  75.     for i=x1, x2, 2 do
  76.         for j=y1, y2, 2 do
  77.             if not miniBlockCheck(i, j, blocks) then
  78.                 if dodged then
  79.                     local xw, yh = player.x, player.y
  80.                     local vec = vector(i-xw, j-yh)
  81.                     if vec.sqrlength < vector(dodged.x-xw, dodged.y-yh).sqrlength then
  82.                         dodged = vector(i,j)
  83.                     end
  84.                 else
  85.                     dodged = vector(i,j)
  86.                 end
  87.             end
  88.         end
  89.     end
  90.     if not dodged then
  91.         player:kill()
  92.         return true
  93.     else
  94.         if vector(dodged.x-player.x, dodged.y-player.y).length > 16 then
  95.             player:harm()
  96.         end
  97.         player.x = dodged.x
  98.         player.y = dodged.y
  99.         isStuckAtAll = false
  100.         return true
  101.     end
  102.     return false
  103. end
  104.  
  105. local function unstuck(px)
  106.     local isStuckAtAll, defaults = blockcheck(0)
  107.     if not isStuckAtAll and player.deathTimer == 0 then
  108.         stuckx = nil
  109.         return false
  110.     end
  111.     return expandBlockChecks()
  112. end
  113.  
  114. function az.onInitAPI()
  115.     registerEvent(az, "onTick")
  116.     registerEvent(az, "onDrawEnd")
  117. end
  118. function az.onDrawEnd()
  119.     previousY = player.y
  120.     if isDuckPowering then
  121.         previousY = previousY - duckingPlayerHeight
  122.     end
  123. end
  124.  
  125. function az.onTick()
  126.     if not az.enabled then return end
  127.     if freezeState[player.forcedState] then
  128.         if hasPressedDown then
  129.             player.y = previousY + duckingPlayerHeight
  130.             player:mem(0xD0, FIELD_DFLOAT, 14)
  131.             hasPressedDown = true
  132.             isDuckPowering = true
  133.         end
  134.         player.downKeyPressing = hasPressedDown
  135.     end
  136.  
  137.     if player.character ~= lastCharacter or (player.powerup ~= lastPowerup and lastForcedState ~= player.forcedState) then
  138.         local ps = player:getCurrentPlayerSetting()
  139.         lastCharacter = player.character
  140.         lastPowerup = player.powerup
  141.         regularPlayerHeight = ps.hitboxHeight
  142.         unduckCollider.width = player.width
  143.         unduckCollider.height = ps.hitboxDuckHeight
  144.     end
  145.  
  146.     lastForcedState = player.forcedState
  147.     if hasPressedDown and player.forcedState == 0 then
  148.         unduckCollider.x = player.x
  149.         unduckCollider.y = player.y + player.height - regularPlayerHeight
  150.         local _, _, blocks = Colliders.collideBlock(unduckCollider, Colliders.BLOCK_SOLID)
  151.         local cancel = false
  152.         for k,v in ipairs (blocks) do
  153.             if not v.isHidden then
  154.                 cancel = true
  155.                 break
  156.             end
  157.         end
  158.         if cancel then
  159.             player.keys.down = true
  160.             player:mem(0x12E, FIELD_WORD, -1)
  161.         end
  162.     end
  163.     if (not Defines.cheat_shadowmario) and player.deathTimer == 0 and player.forcedState == 0 and #Colliders.getColliding{
  164.         a = player,
  165.         b = Block.SOLID,
  166.         btype = Colliders.BLOCK,
  167.         filter = function(other)
  168.             if other.isHidden then return false end
  169.             if other:mem(0x5A, FIELD_WORD) == -1 then return false end
  170.             if other:mem(0x1C, FIELD_WORD) == -1 then return false end
  171.             if other:mem(0x5C, FIELD_WORD) == -1 then return false end
  172.             return true
  173.         end
  174.     } > 0 then
  175.         if stuckx == nil then
  176.             stuckx = lastPlayerX
  177.         end
  178.         stuckTimer = stuckTimer + 1
  179.         local px = player.x
  180.         player.x = stuckx
  181.         if stuckTimer >= 1 then
  182.             if not unstuck(px) then
  183.                 player.x = px
  184.             end
  185.         end
  186.     else
  187.         stuckTimer = 0
  188.         stuckx = nil
  189.     end
  190.     lastPlayerX = player.x
  191.     wasOnSlope = player:mem(0x48, FIELD_WORD)
  192.        
  193.     if player.forcedState == 0 then
  194.         if isDuckPowering then
  195.             player.y = player.y - duckingPlayerHeight
  196.         end
  197.         isDuckPowering = false
  198.         hasPressedDown = player.downKeyPressing
  199.     end
  200. end
  201.  
  202. return az
Add Comment
Please, Sign In to add comment