Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. function ChanceFromStep(randItem, step)
  2. local uVar1 = 0
  3. local uVar2 = 0
  4. local uVar3 = 0
  5. local temp = 0
  6. local temp2 = 0
  7. local temp3 = 0
  8. local temp4 = 0
  9.  
  10. uVar3 = 1
  11.  
  12. if step == 0 then
  13. return 0
  14. end
  15.  
  16. if step < 0 then
  17. step = math.abs(step)
  18. end
  19.  
  20. uVar1 = randItem
  21. if randItem < 0 then
  22. uVar1 = math.abs(randItem)
  23. end
  24.  
  25.  
  26. if step <= uVar1 then
  27. while step < 0x10000000 and step < uVar1 do
  28. step = bit.lshift(step, 0x4)
  29. uVar3 = bit.lshift(uVar3, 0x4)
  30. end
  31.  
  32.  
  33.  
  34. while step < 0x80000000 and step < uVar1 do
  35. step = bit.lshift(step, 0x1)
  36. uVar3 = bit.lshift(uVar3, 0x1)
  37. end
  38.  
  39.  
  40.  
  41. while true do
  42. uVar2 = 0
  43. if step <= uVar1 then
  44. uVar1 = uVar1 - step
  45. end
  46.  
  47.  
  48.  
  49. if bit.rshift(step, 0x1) <= uVar1 then
  50. uVar1 = uVar1 - bit.rshift(step, 0x1)
  51.  
  52.  
  53. temp = bit.rshift(uVar3, 0x1)
  54. temp2 = bit.lshift(uVar3, 0x1f)
  55.  
  56. uVar2 = bit.bor(temp, temp2)
  57. end
  58.  
  59. if bit.rshift(step, 0x2) <= uVar1 then
  60.  
  61. uVar1 = uVar1 - bit.rshift(step, 0x2)
  62.  
  63.  
  64. temp = bit.rshift(uVar3, 0x2)
  65. temp2 = bit.lshift(uVar3, 0x1e)
  66.  
  67. temp3 = bit.bor(uVar2, temp)
  68. temp3 = bit.bor(temp3, temp2)
  69.  
  70. uVar2 = temp3
  71. end
  72.  
  73. if bit.rshift(step, 0x3) <= uVar1 then
  74.  
  75. uVar1 = uVar1 - bit.rshift(step, 0x3)
  76.  
  77. temp = bit.lshift(uVar3, 0x1d)
  78.  
  79. uVar2 = bit.bor(uVar2, temp)
  80.  
  81. end
  82.  
  83. if uVar1 == 0 or bit.rshift(uVar3, 0x4) == 0 then
  84. break
  85. end
  86.  
  87. step = bit.rshift(step, 0x4)
  88. uVar3 = bit.rshift(uVar3, 0x4)
  89.  
  90. end
  91.  
  92.  
  93. -- stop @ PAK SRAM
  94. uVar2 = bit.band(uVar2, 0xe0000000)
  95.  
  96. -- wasn't cleanly divisible, add back up until we are
  97. if uVar2 ~= 0 then
  98.  
  99. if bit.band(bit.lshift(uVar3, 0x1d), uVar2) ~= 0 then
  100. uVar1 = uVar1 + bit.rshift(step, 0x3)
  101. end
  102.  
  103. temp3 = bit.lshift(uVar3, 0x1e)
  104. temp4 = bit.rshift(uVar3, 0x2)
  105.  
  106. temp2 = bit.bor(temp4, temp3)
  107.  
  108. if bit.band(uVar2, temp2) ~= 0 then
  109. uVar1 = uVar1 + bit.rshift(step, 0x2)
  110. end
  111.  
  112. temp3 = bit.lshift(uVar3, 0x1f)
  113. temp4 = bit.rshift(uVar3, 0x2)
  114.  
  115. temp2 = bit.bor(temp4, temp3)
  116.  
  117. if bit.band(uVar2, temp2) ~= 0 then
  118. uVar1 = uVar1 + bit.rshift(step, 0x1)
  119. end
  120.  
  121. end
  122.  
  123. end
  124.  
  125.  
  126. if randItem < 0 then
  127. uVar1 = -uVar1
  128. end
  129.  
  130. return uVar1
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement