Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ChanceFromStep(randItem, step)
- local uVar1 = 0
- local uVar2 = 0
- local uVar3 = 0
- local temp = 0
- local temp2 = 0
- local temp3 = 0
- local temp4 = 0
- uVar3 = 1
- if step == 0 then
- return 0
- end
- if step < 0 then
- step = math.abs(step)
- end
- uVar1 = randItem
- if randItem < 0 then
- uVar1 = math.abs(randItem)
- end
- if step <= uVar1 then
- while step < 0x10000000 and step < uVar1 do
- step = bit.lshift(step, 0x4)
- uVar3 = bit.lshift(uVar3, 0x4)
- end
- while step < 0x80000000 and step < uVar1 do
- step = bit.lshift(step, 0x1)
- uVar3 = bit.lshift(uVar3, 0x1)
- end
- while true do
- uVar2 = 0
- if step <= uVar1 then
- uVar1 = uVar1 - step
- end
- if bit.rshift(step, 0x1) <= uVar1 then
- uVar1 = uVar1 - bit.rshift(step, 0x1)
- temp = bit.rshift(uVar3, 0x1)
- temp2 = bit.lshift(uVar3, 0x1f)
- uVar2 = bit.bor(temp, temp2)
- end
- if bit.rshift(step, 0x2) <= uVar1 then
- uVar1 = uVar1 - bit.rshift(step, 0x2)
- temp = bit.rshift(uVar3, 0x2)
- temp2 = bit.lshift(uVar3, 0x1e)
- temp3 = bit.bor(uVar2, temp)
- temp3 = bit.bor(temp3, temp2)
- uVar2 = temp3
- end
- if bit.rshift(step, 0x3) <= uVar1 then
- uVar1 = uVar1 - bit.rshift(step, 0x3)
- temp = bit.lshift(uVar3, 0x1d)
- uVar2 = bit.bor(uVar2, temp)
- end
- if uVar1 == 0 or bit.rshift(uVar3, 0x4) == 0 then
- break
- end
- step = bit.rshift(step, 0x4)
- uVar3 = bit.rshift(uVar3, 0x4)
- end
- -- stop @ PAK SRAM
- uVar2 = bit.band(uVar2, 0xe0000000)
- -- wasn't cleanly divisible, add back up until we are
- if uVar2 ~= 0 then
- if bit.band(bit.lshift(uVar3, 0x1d), uVar2) ~= 0 then
- uVar1 = uVar1 + bit.rshift(step, 0x3)
- end
- temp3 = bit.lshift(uVar3, 0x1e)
- temp4 = bit.rshift(uVar3, 0x2)
- temp2 = bit.bor(temp4, temp3)
- if bit.band(uVar2, temp2) ~= 0 then
- uVar1 = uVar1 + bit.rshift(step, 0x2)
- end
- temp3 = bit.lshift(uVar3, 0x1f)
- temp4 = bit.rshift(uVar3, 0x2)
- temp2 = bit.bor(temp4, temp3)
- if bit.band(uVar2, temp2) ~= 0 then
- uVar1 = uVar1 + bit.rshift(step, 0x1)
- end
- end
- end
- if randItem < 0 then
- uVar1 = -uVar1
- end
- return uVar1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement