local function spiral_wrap_signed(value, bits)
    local modulus = 2 ^ bits
    value = value % modulus
    if value >= modulus / 2 then value = value - modulus end
    return value
end
local function spiral_mul_mod32(a, b)
    a = a % 4294967296
    b = b % 4294967296
    local a_low = a % 65536
    local a_high = (a - a_low) / 65536
    return (a_low * b + ((a_high * b) % 65536) * 65536) % 4294967296
end
local Mut0, Uh0_Cons, Mut1, Mut2, Us0_Some, Us0_None, Us1_Some, Us1_None, Us2_Drink, Us2_Engage, Us2_StepSomewhere, Us2_Stand, Us3_Some, Us3_None, get_environment_variable_1, env_text_0, disable_client_bot_2, mute_3, closure0, file_exists_5, log_flush_7, write_log_line_6, closure3, typed_c2, format_real_8, closure5, typed_c4, chasing_9, method11, method12, env_i32_10, player_present_14, parity_summary_15, method17, method18, method19, forget_dead_16, live_monster_21, scan_20, method23, remember_22, diagonal_south_27, diagonal_step_26, south_or_west_step_25, step_24, closure9, ticked_13, closure8, closure7, closure6, closure10, poll_4, closure1, closure11
Mut0 = function(l0) return { __tag = "Mut0", l0 = l0 } end

Uh0_Nil = (function() local shared = { tag = "Uh0_Nil" } return function() return shared end end)()
function Uh0_Cons(v0, v1, v2) return { tag = "Uh0_Cons",  _1 = v0,  _2 = v1,  _3 = v2 } end

Mut1 = function(l0) return { __tag = "Mut1", l0 = l0 } end

Mut2 = function(l0) return { __tag = "Mut2", l0 = l0 } end

function Us0_Some(v0) return { tag = "Us0_Some",  _1 = v0 } end
function Us0_None() return { tag = "Us0_None" } end

function Us1_Some(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9) return { tag = "Us1_Some",  _1 = v0,  _2 = v1,  _3 = v2,  _4 = v3,  _5 = v4,  _6 = v5,  _7 = v6,  _8 = v7,  _9 = v8,  _10 = v9 } end
function Us1_None() return { tag = "Us1_None" } end

function Us2_Drink() return { tag = "Us2_Drink" } end
function Us2_Engage() return { tag = "Us2_Engage" } end
function Us2_StepSomewhere() return { tag = "Us2_StepSomewhere" } end
function Us2_Stand() return { tag = "Us2_Stand" } end

function Us3_Some(v0, v1) return { tag = "Us3_Some",  _1 = v0,  _2 = v1 } end
function Us3_None() return { tag = "Us3_None" } end

function get_environment_variable_1(v0)
    local v1 = os.getenv(v0) or ""
    return v1
end

function env_text_0(v0, v1)
    local v2 = get_environment_variable_1(v0)
    local v3 = v2 == ""
    if v3 then
        return v1
    else
        return v2
    end
end

function disable_client_bot_2(v0)
    local v1 = g_settings.getNode("bot")
    local v2 = (v1) ~= nil
    local getv4 = function()
        if v2 then
            return v1
        else
            local v3 = {}
            return v3
        end
    end
    local v4 = getv4()
    do (v4)[v0] = { enabled = false } end
    g_settings.setNode("bot", v4)
    g_settings.save()
    return nil
end

function mute_3()
    g_settings.set("enableAudio", false)
    local v0 = g_sounds ~= nil
    if v0 then
        g_sounds.setAudioEnabled(false)
        g_sounds.stopAll()
        return nil
    else
    end
end

function closure0(capt)
    return function(dom)
        local v0 = "TIBIA_PROBE_HIDDEN"
        local v1 = get_environment_variable_1(v0)
        local v2 = v1 == "1"
        if v2 then
            g_window.move({ x = -32000, y = -32000 })
            g_window.hide()
        else
        end
        return mute_3()
    end
end

function file_exists_5(v0)
    local v1 = "r"
    local v2 = io.open(v0, v1)
    local v3 = (v2) ~= nil
    if v3 then
        do (v2):close() end
        return true
    else
        return false
    end
end

function log_flush_7()
    local v0 = table.concat(TibiaProbeLog, string.char(10))
    local v1 = "\n"
    local v2 = v0 .. v1 
    g_resources.writeFileContents("/tibia-probe.log", v2)
    return nil
end

function write_log_line_6(v0)
    local v1 = TibiaProbeLog == nil
    if v1 then
        TibiaProbeLog = {}
    else
    end
    table.insert(TibiaProbeLog, v0)
    g_logger.info(v0)
    return log_flush_7()
end

function closure3(capt)
    return function(dom)
        g_app.exit()
        return nil
    end
end

function typed_c2(capt)
    return function(v0)
        local v1 = tostring(v0)
        local v2 = "game login error: "
        local v3 = v2 .. v1 
        local v4 = "[tibia-probe] "
        local v5 = v4 .. v3 
        write_log_line_6(v5)
        local v6 = "finish: "
        local v7 = "game login error"
        local v8 = v6 .. v7 
        local v9 = v4 .. v8 
        write_log_line_6(v9)
        local v10 = g_game.isOnline()
        if v10 then
            g_game.safeLogout()
        else
        end
        local v11 = closure3(nil)
        scheduleEvent(v11, 2000)
        return nil
    end
end

function format_real_8(v0)
    local v1 = ""
    local v2 = { __tag = "Mut2", l0 = v1 }
    local v3 = tostring(v0)       
    local v4 = v2 ~= nil and v2.l0
    local v5 = v4 .. v3 
    v2.l0 = v5
    local v6 = v2 ~= nil and v2.l0
    return v6
end

function closure5(capt)
    local v0, v1, v2 = (table.unpack or unpack)(capt)
    return function(v3)
        local v4 = tostring(v2)
        local v5 = tostring(v3)
        local v6 = g_clock.millis()
        local v7 = v0 ~= nil and v0.l0
        local v8 = spiral_wrap_signed((v6 - v7), 32)
        local v9 = "server text ["
        local v10 = v9 .. v4 
        local v11 = "] t="
        local v12 = v10 .. v11 
        local v13 = format_real_8(v8)
        local v14 = v12 .. v13 
        local v15 = ": "
        local v16 = v14 .. v15 
        local v17 = v16 .. v5 
        local v18 = "[tibia-probe] "
        local v19 = v18 .. v17 
        return write_log_line_6(v19)
    end
end

function typed_c4(capt)
    local v0, v1 = (table.unpack or unpack)(capt)
    return function(v2)
        return closure5({ v0, v1, v2 })
    end
end

function chasing_9(v0)
    local getv3 = function()
        if v0 then
            local v1 = ChaseOpponent
            return v1
        else
            local v2 = DontChase
            return v2
        end
    end
    local v3 = getv3()
    local v4 = g_game.getChaseMode()
    local v5 = v4 ~= v3
    if v5 then
        g_game.setChaseMode(v3)
        return nil
    else
    end
end

function method11(v0, v1, v2)
    local v3 = v2 >= v1
    if v3 then
        return v1
    else
        local v4 = string.sub(v0, (v2)+1, (v2)+1)
        local v5 = v4 == " "
        local getv11 = function()
            if v5 then
                return true
            else
                local v6 = v4 == "\t"
                if v6 then
                    return true
                else
                    local v7 = v4 == "\r"
                    if v7 then
                        return true
                    else
                        local v8 = v4 == "\n"
                        return v8
                    end
                end
            end
        end
        local v11 = getv11()
        if v11 then
            local v12 = spiral_wrap_signed((v2 + 1), 32)
            return method11(v0, v1, v12)
        else
            return v2
        end
    end
end

function method12(v0, v1)
    local v2 = v1 <= 0
    if v2 then
        return -1
    else
        local v3 = spiral_wrap_signed((v1 - 1), 32)
        local v4 = string.sub(v0, (v3)+1, (v3)+1)
        local v5 = v4 == " "
        local getv11 = function()
            if v5 then
                return true
            else
                local v6 = v4 == "\t"
                if v6 then
                    return true
                else
                    local v7 = v4 == "\r"
                    if v7 then
                        return true
                    else
                        local v8 = v4 == "\n"
                        return v8
                    end
                end
            end
        end
        local v11 = getv11()
        if v11 then
            return method12(v0, v3)
        else
            return v3
        end
    end
end

function env_i32_10(v0, v1)
    local v2 = get_environment_variable_1(v0)
    local v3 = string.len(v2)
    local v4 = 0
    local v5 = method11(v2, v3, v4)
    local v6 = spiral_wrap_signed((v3 - 1), 32)
    local v7 = string.sub(v2, (v5)+1, (v6)+1)
    local v8 = string.len(v7)
    local v9 = method12(v7, v8)
    local v10 = string.sub(v7, (0)+1, (v9)+1)
    local v11 = (string.match(v10, "^%s*[+-]?%d+%s*$") ~= nil)
    local v12 = (tonumber(v10) or 0)
    local v13 = (math.modf(v12))
    local getv15 = function()
        if v11 then
            local v14 = v12 >= -2147483648.0
            return v14
        else
            return false
        end
    end
    local v15 = getv15()
    local getv17 = function()
        if v15 then
            local v16 = v12 <= 2147483647.0
            return v16
        else
            return false
        end
    end
    local v17 = getv17()
    local getv20 = function()
        if v17 then
            return Us0_Some(v13)
        else
            return Us0_None()
        end
    end
    local v20 = getv20()
    if v20 ~= nil and v20.tag == "Us0_None" then
        return v1
    elseif v20 ~= nil and v20.tag == "Us0_Some" then
        local v21 = v20._1
        return v21
    end
end

function player_present_14()
    local v0 = g_game.getLocalPlayer() ~= nil
    if v0 then
        local v1 = g_game.isOnline()
        return v1
    else
        return false
    end
end

function parity_summary_15()
    local v0 = ArenaParity ~= nil
    if v0 then
        local v1 = ArenaParity.summary()
        return v1
    else
        local v2 = ""
        return v2
    end
end

function method17(v0, v1)
    if v0 ~= nil and v0.tag == "Uh0_Cons" then
        local v2 = v0._1
        local v3 = v0._2
        local v4 = v0._3
        local v5 = method17(v4, v1)
        local v6 = (v3):isDead()
        if v6 then
            return Uh0_Cons(v2, v3, v5)
        else
            return v5
        end
    elseif v0 ~= nil and v0.tag == "Uh0_Nil" then
        return v1
    end
end

function method18(v0, v1)
    if v0 ~= nil and v0.tag == "Uh0_Cons" then
        local v2 = v0._1
        local v3 = v0._2
        local v4 = v0._3
        local v5 = method18(v4, v1)
        local v6 = (v3):isDead()
        local v7 = v6 == false
        if v7 then
            return Uh0_Cons(v2, v3, v5)
        else
            return v5
        end
    elseif v0 ~= nil and v0.tag == "Uh0_Nil" then
        return v1
    end
end

function method19(v0, v1)
    if v0 ~= nil and v0.tag == "Uh0_Cons" then
        local v2 = v0._1
        local v3 = v0._2
        local v4 = v0._3
        local v5 = spiral_wrap_signed((v1 + 1), 32)
        return method19(v4, v5)
    elseif v0 ~= nil and v0.tag == "Uh0_Nil" then
        return v1
    end
end

function forget_dead_16(v0)
    local v1 = v0 ~= nil and v0.l0
    local v2 = Uh0_Nil()
    local v3 = method17(v1, v2)
    local v4 = v0 ~= nil and v0.l0
    local v5 = Uh0_Nil()
    local v6 = method18(v4, v5)
    v0.l0 = v6
    local v7 = 0
    return method19(v3, v7)
end

function live_monster_21(v0)
    local v1 = (v0):isMonster()
    local getv4 = function()
        if v1 then
            local v2 = (v0):isDead()
            local v3 = v2 == false
            return v3
        else
            return false
        end
    end
    local v4 = getv4()
    if v4 then
        local v5 = (v0):getPosition() ~= nil
        return v5
    else
        return false
    end
end

function scan_20(v0, v1, v2, v3, v4, v5, v6)
    local v7 = v5 > v4
    if v7 then
        return v6
    else
        local v8 = spiral_wrap_signed((v5 + 1), 32)
        local v9 = (v3)[v5]
        local v10 = live_monster_21(v9)
        local getv33 = function()
            if v10 then
                local v11 = (v9):getPosition()
                local v12 = v11.x
                local v13 = v11.y
                local v14 = v11.z
                local v15 = v12 > v0
                local getv18 = function()
                    if v15 then
                        local v16 = spiral_wrap_signed((v12 - v0), 32)
                        return v16
                    else
                        local v17 = spiral_wrap_signed((v0 - v12), 32)
                        return v17
                    end
                end
                local v18 = getv18()
                local v19 = v13 > v1
                local getv22 = function()
                    if v19 then
                        local v20 = spiral_wrap_signed((v13 - v1), 32)
                        return v20
                    else
                        local v21 = spiral_wrap_signed((v1 - v13), 32)
                        return v21
                    end
                end
                local v22 = getv22()
                local v23 = v18 > v22
                local getv24 = function()
                    if v23 then
                        return v18
                    else
                        return v22
                    end
                end
                local v24 = getv24()
                local getv30 = function()
                    if v6 ~= nil and v6.tag == "Us3_None" then
                        local v28 = v24 < 999
                        return v28
                    elseif v6 ~= nil and v6.tag == "Us3_Some" then
                        local v25 = v6._1
                        local v26 = v6._2
                        local v27 = v24 < v26
                        return v27
                    end
                end
                local v30 = getv30()
                if v30 then
                    return Us3_Some(v5, v24)
                else
                    return v6
                end
            else
                return v6
            end
        end
        local v33 = getv33()
        return scan_20(v0, v1, v2, v3, v4, v8, v33)
    end
end

function method23(v0, v1, v2)
    if v1 ~= nil and v1.tag == "Uh0_Cons" then
        local v3 = v1._1
        local v4 = v1._2
        local v5 = v1._3
        local v6 = method23(v0, v5, v2)
        local v7 = v3 ~= v0
        if v7 then
            return Uh0_Cons(v3, v4, v6)
        else
            return v6
        end
    elseif v1 ~= nil and v1.tag == "Uh0_Nil" then
        return v2
    end
end

function remember_22(v0, v1)
    local v2 = (v1):getId()
    local v3 = v0 ~= nil and v0.l0
    local v4 = Uh0_Nil()
    local v5 = method23(v2, v3, v4)
    local v6 = Uh0_Cons(v2, v1, v5)
    v0.l0 = v6
    return nil
end

function diagonal_south_27(v0, v1)
    local v2 = v0 == 1
    local getv4 = function()
        if v2 then
            local v3 = v1 == 1
            return v3
        else
            return false
        end
    end
    local v4 = getv4()
    if v4 then
        local v5 = SouthEast
        local v6 = g_game.walk(v5) ~= false
        return v6
    else
        local v7 = v0 == -1
        local getv9 = function()
            if v7 then
                local v8 = v1 == 1
                return v8
            else
                return false
            end
        end
        local v9 = getv9()
        if v9 then
            local v10 = SouthWest
            local v11 = g_game.walk(v10) ~= false
            return v11
        else
            return false
        end
    end
end

function diagonal_step_26(v0, v1)
    local v2 = v0 == 1
    local getv4 = function()
        if v2 then
            local v3 = v1 == -1
            return v3
        else
            return false
        end
    end
    local v4 = getv4()
    if v4 then
        local v5 = NorthEast
        local v6 = g_game.walk(v5) ~= false
        return v6
    else
        local v7 = v0 == -1
        local getv9 = function()
            if v7 then
                local v8 = v1 == -1
                return v8
            else
                return false
            end
        end
        local v9 = getv9()
        if v9 then
            local v10 = NorthWest
            local v11 = g_game.walk(v10) ~= false
            return v11
        else
            return diagonal_south_27(v0, v1)
        end
    end
end

function south_or_west_step_25(v0, v1)
    local v2 = v0 == 0
    local getv4 = function()
        if v2 then
            local v3 = v1 == 1
            return v3
        else
            return false
        end
    end
    local v4 = getv4()
    if v4 then
        local v5 = South
        local v6 = g_game.walk(v5) ~= false
        return v6
    else
        local v7 = v0 == -1
        local getv9 = function()
            if v7 then
                local v8 = v1 == 0
                return v8
            else
                return false
            end
        end
        local v9 = getv9()
        if v9 then
            local v10 = West
            local v11 = g_game.walk(v10) ~= false
            return v11
        else
            return diagonal_step_26(v0, v1)
        end
    end
end

function step_24(v0, v1)
    local v2 = v0 == 0
    local getv4 = function()
        if v2 then
            local v3 = v1 == -1
            return v3
        else
            return false
        end
    end
    local v4 = getv4()
    if v4 then
        local v5 = North
        local v6 = g_game.walk(v5) ~= false
        return v6
    else
        local v7 = v0 == 1
        local getv9 = function()
            if v7 then
                local v8 = v1 == 0
                return v8
            else
                return false
            end
        end
        local v9 = getv9()
        if v9 then
            local v10 = East
            local v11 = g_game.walk(v10) ~= false
            return v11
        else
            return south_or_west_step_25(v0, v1)
        end
    end
end

function closure9(capt)
    local v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13 = (table.unpack or unpack)(capt)
    return function(dom)
        return ticked_13(v0, v1, v2, v3, v5, v6, v7, v8, v9, v10, v11, v12, v13, v4)
    end
end

function ticked_13(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
    local v14 = player_present_14()
    local v15 = v14 == false
    local getv379 = function()
        if v15 then
            local v16 = parity_summary_15()
            local v17 = v16 ~= ""
            if v17 then
                local v18 = "[tibia-probe] "
                local v19 = v18 .. v16 
                write_log_line_6(v19)
            else
            end
            local v20 = "finish: "
            local v21 = "offline"
            local v22 = v20 .. v21 
            local v23 = "[tibia-probe] "
            local v24 = v23 .. v22 
            write_log_line_6(v24)
            local v25 = g_game.isOnline()
            if v25 then
                g_game.safeLogout()
            else
            end
            local v26 = closure3(nil)
            scheduleEvent(v26, 2000)
            return Us1_None()
        else
            local v28 = g_clock.millis()
            local v29 = g_game.getLocalPlayer():getHealth()
            local v30 = spiral_wrap_signed((v4 + 1), 32)
            local v31 = v29 < v12
            local getv32 = function()
                if v31 then
                    return v29
                else
                    return v12
                end
            end
            local v32 = getv32()
            local v33 = v29 <= 0
            if v33 then
                local v34 = g_game.getLocalPlayer():getHealth()
                local v35 = g_game.getLocalPlayer():getExperience()
                local v36 = spiral_wrap_signed((v35 - v0), 32)
                local v37 = format_real_8(v30)
                local v38 = "ticks "
                local v39 = v38 .. v37 
                local v40 = " heals "
                local v41 = v39 .. v40 
                local v42 = format_real_8(v5)
                local v43 = v41 .. v42 
                local v44 = " strikes "
                local v45 = v43 .. v44 
                local v46 = format_real_8(v6)
                local v47 = v45 .. v46 
                local v48 = " holds "
                local v49 = v47 .. v48 
                local v50 = format_real_8(v7)
                local v51 = v49 .. v50 
                local v52 = format_real_8(v9)
                local v53 = " retreats "
                local v54 = v53 .. v52 
                local v55 = " cornered "
                local v56 = v54 .. v55 
                local v57 = format_real_8(v10)
                local v58 = v56 .. v57 
                local v59 = " gated "
                local v60 = v58 .. v59 
                local v61 = format_real_8(v11)
                local v62 = v60 .. v61 
                local v63 = " kills "
                local v64 = v62 .. v63 
                local v65 = format_real_8(v8)
                local v66 = v64 .. v65 
                local v67 = v51 .. v66 
                local v68 = format_real_8(v34)
                local v69 = " health "
                local v70 = v69 .. v68 
                local v71 = " lowest "
                local v72 = v70 .. v71 
                local v73 = format_real_8(v32)
                local v74 = v72 .. v73 
                local v75 = " experience +"
                local v76 = v74 .. v75 
                local v77 = format_real_8(v36)
                local v78 = v76 .. v77 
                local v79 = v67 .. v78 
                local v80 = "dead: "
                local v81 = v80 .. v79 
                local v82 = "[tibia-probe] "
                local v83 = v82 .. v81 
                write_log_line_6(v83)
                local v84 = parity_summary_15()
                local v85 = v84 ~= ""
                if v85 then
                    local v86 = v82 .. v84 
                    write_log_line_6(v86)
                else
                end
                local v87 = "finish: "
                local v88 = "death"
                local v89 = v87 .. v88 
                local v90 = v82 .. v89 
                write_log_line_6(v90)
                local v91 = g_game.isOnline()
                if v91 then
                    g_game.safeLogout()
                else
                end
                local v92 = closure3(nil)
                scheduleEvent(v92, 2000)
                return Us1_None()
            else
                local v94 = forget_dead_16(v3)
                local v95 = spiral_wrap_signed((v8 + v94), 32)
                local v96 = math.random(0, 3)
                local v97 = v96 == 0
                local getv106 = function()
                    if v97 then
                        return Us2_Drink()
                    else
                        local v99 = v96 == 1
                        if v99 then
                            return Us2_Engage()
                        else
                            local v101 = v96 == 2
                            if v101 then
                                return Us2_StepSomewhere()
                            else
                                return Us2_Stand()
                            end
                        end
                    end
                end
                local v106 = getv106()
                local getv300 = function()
                    if v106 ~= nil and v106.tag == "Us2_Drink" then
                        local v107 = g_clock.millis()
                        local v108 = v1 ~= nil and v1.l0
                        local v109 = spiral_wrap_signed((v107 - v108), 32)
                        local v110 = g_game.useInventoryItemWith(266, g_game.getLocalPlayer()) ~= false
                        if v110 then
                            local v111 = format_real_8(v29)
                            local v112 = "heal (potion) at health "
                            local v113 = v112 .. v111 
                            local v114 = " t="
                            local v115 = v113 .. v114 
                            local v116 = format_real_8(v109)
                            local v117 = v115 .. v116 
                            local v118 = "[tibia-probe] "
                            local v119 = v118 .. v117 
                            write_log_line_6(v119)
                        else
                            local v120 = format_real_8(v29)
                            local v121 = "heal dropped by the action gate at health "
                            local v122 = v121 .. v120 
                            local v123 = "[tibia-probe] "
                            local v124 = v123 .. v122 
                            write_log_line_6(v124)
                        end
                        if v110 then
                            local v125 = spiral_wrap_signed((v5 + 1), 32)
                            return { [1]=v30, [2]=v125, [3]=v6, [4]=v7, [5]=v95, [6]=v9, [7]=v10, [8]=v11, [9]=v32, [10]=v13 }
                        else
                            return { [1]=v30, [2]=v5, [3]=v6, [4]=v7, [5]=v95, [6]=v9, [7]=v10, [8]=v11, [9]=v32, [10]=v13 }
                        end
                    elseif v106 ~= nil and v106.tag == "Us2_Engage" then
                        local v136 = g_game.getLocalPlayer():getPosition()
                        local v137 = v136.x
                        local v138 = v136.y
                        local v139 = v136.z
                        local v140 = g_map.getSpectators({ x = v137, y = v138, z = v139 }, false)
                        local v141 = #(v140)
                        local v142 = 1
                        local v143 = Us3_None()
                        local v144 = scan_20(v137, v138, v139, v140, v141, v142, v143)
                        if v144 ~= nil and v144.tag == "Us3_None" then
                            return { [1]=v30, [2]=v5, [3]=v6, [4]=v7, [5]=v95, [6]=v9, [7]=v10, [8]=v11, [9]=v32, [10]=v13 }
                        elseif v144 ~= nil and v144.tag == "Us3_Some" then
                            local v145 = v144._1
                            local v146 = v144._2
                            local v147 = (v140)[v145]
                            local v148 = true
                            chasing_9(v148)
                            local v149 = g_game.getAttackingCreature()
                            local v150 = (v149) == (v147)
                            local v151 = v150 == false
                            if v151 then
                                g_game.attack(v147)
                                remember_22(v3, v147)
                                local v152 = (v147):getName()
                                local v153 = "strike "
                                local v154 = v153 .. v152 
                                local v155 = (v147):getPosition()
                                local v156 = v155.x
                                local v157 = v155.y
                                local v158 = v155.z
                                local v159 = format_real_8(v156)
                                local v160 = ""
                                local v161 = v160 .. v159 
                                local v162 = ","
                                local v163 = v161 .. v162 
                                local v164 = format_real_8(v157)
                                local v165 = v163 .. v164 
                                local v166 = v165 .. v162 
                                local v167 = format_real_8(v158)
                                local v168 = v166 .. v167 
                                local v169 = " at "
                                local v170 = v169 .. v168 
                                local v171 = " from "
                                local v172 = v170 .. v171 
                                local v173 = format_real_8(v137)
                                local v174 = v160 .. v173 
                                local v175 = v174 .. v162 
                                local v176 = format_real_8(v138)
                                local v177 = v175 .. v176 
                                local v178 = v177 .. v162 
                                local v179 = format_real_8(v139)
                                local v180 = v178 .. v179 
                                local v181 = v172 .. v180 
                                local v182 = v154 .. v181 
                                local v183 = " health "
                                local v184 = v182 .. v183 
                                local v185 = format_real_8(v29)
                                local v186 = v184 .. v185 
                                local v187 = "[tibia-probe] "
                                local v188 = v187 .. v186 
                                write_log_line_6(v188)
                            else
                            end
                            local v189 = spiral_wrap_signed((v6 + 1), 32)
                            return { [1]=v30, [2]=v5, [3]=v189, [4]=v7, [5]=v95, [6]=v9, [7]=v10, [8]=v11, [9]=v32, [10]=v13 }
                        end
                    elseif v106 ~= nil and v106.tag == "Us2_Stand" then
                        local v269 = spiral_wrap_signed((v7 + 1), 32)
                        return { [1]=v30, [2]=v5, [3]=v6, [4]=v269, [5]=v95, [6]=v9, [7]=v10, [8]=v11, [9]=v32, [10]=v13 }
                    elseif v106 ~= nil and v106.tag == "Us2_StepSomewhere" then
                        local v210 = v28 >= v13
                        local getv213 = function()
                            if v210 then
                                local v211 = g_game.getLocalPlayer():isWalking()
                                local v212 = v211 == false
                                return v212
                            else
                                return false
                            end
                        end
                        local v213 = getv213()
                        if v213 then
                            local v214 = math.random(1, 8)
                            local v215 = v214 == 1
                            local getv240 = function()
                                if v215 then
                                    return { [1]=0, [2]=-1, [3]=false }
                                else
                                    local v216 = v214 == 2
                                    local getv237 = function()
                                        if v216 then
                                            return { [1]=1, [2]=0, [3]=false }
                                        else
                                            local v217 = v214 == 3
                                            local getv234 = function()
                                                if v217 then
                                                    return { [1]=0, [2]=1, [3]=false }
                                                else
                                                    local v218 = v214 == 4
                                                    local getv231 = function()
                                                        if v218 then
                                                            return { [1]=-1, [2]=0, [3]=false }
                                                        else
                                                            local v219 = v214 == 5
                                                            local getv228 = function()
                                                                if v219 then
                                                                    return { [1]=1, [2]=-1, [3]=true }
                                                                else
                                                                    local v220 = v214 == 6
                                                                    local getv225 = function()
                                                                        if v220 then
                                                                            return { [1]=1, [2]=1, [3]=true }
                                                                        else
                                                                            local v221 = v214 == 7
                                                                            local getv222 = function()
                                                                                if v221 then
                                                                                    return { [1]=-1, [2]=1, [3]=true }
                                                                                else
                                                                                    return { [1]=-1, [2]=-1, [3]=true }
                                                                                end
                                                                            end
                                                                            local v222, v223, v224 = (table.unpack or unpack)(getv222())
                                                                            return { [1]=v222, [2]=v223, [3]=v224 }
                                                                        end
                                                                    end
                                                                    local v225, v226, v227 = (table.unpack or unpack)(getv225())
                                                                    return { [1]=v225, [2]=v226, [3]=v227 }
                                                                end
                                                            end
                                                            local v228, v229, v230 = (table.unpack or unpack)(getv228())
                                                            return { [1]=v228, [2]=v229, [3]=v230 }
                                                        end
                                                    end
                                                    local v231, v232, v233 = (table.unpack or unpack)(getv231())
                                                    return { [1]=v231, [2]=v232, [3]=v233 }
                                                end
                                            end
                                            local v234, v235, v236 = (table.unpack or unpack)(getv234())
                                            return { [1]=v234, [2]=v235, [3]=v236 }
                                        end
                                    end
                                    local v237, v238, v239 = (table.unpack or unpack)(getv237())
                                    return { [1]=v237, [2]=v238, [3]=v239 }
                                end
                            end
                            local v240, v241, v242 = (table.unpack or unpack)(getv240())
                            local v243 = step_24(v240, v241)
                            if v243 then
                                local v244 = spiral_wrap_signed((v9 + 1), 32)
                                local getv245 = function()
                                    if v242 then
                                        return 3
                                    else
                                        return 1
                                    end
                                end
                                local v245 = getv245()
                                local v246 = spiral_wrap_signed(spiral_mul_mod32(650, v245), 32)
                                local v247 = spiral_wrap_signed((v28 + v246), 32)
                                return { [1]=v30, [2]=v5, [3]=v6, [4]=v7, [5]=v95, [6]=v244, [7]=v10, [8]=v11, [9]=v32, [10]=v247 }
                            else
                                local v248 = spiral_wrap_signed((v11 + 1), 32)
                                return { [1]=v30, [2]=v5, [3]=v6, [4]=v7, [5]=v95, [6]=v9, [7]=v10, [8]=v248, [9]=v32, [10]=v13 }
                            end
                        else
                            return { [1]=v30, [2]=v5, [3]=v6, [4]=v7, [5]=v95, [6]=v9, [7]=v10, [8]=v11, [9]=v32, [10]=v13 }
                        end
                    end
                end
                local v300, v301, v302, v303, v304, v305, v306, v307, v308, v309 = (table.unpack or unpack)(getv300())
                local v310 = math.fmod(v300, 100)
                local v311 = v310 == 0
                if v311 then
                    local v312 = g_game.getLocalPlayer():getPosition()
                    local v313 = v312.x
                    local v314 = v312.y
                    local v315 = v312.z
                    local v316 = format_real_8(v313)
                    local v317 = ""
                    local v318 = v317 .. v316 
                    local v319 = ","
                    local v320 = v318 .. v319 
                    local v321 = format_real_8(v314)
                    local v322 = v320 .. v321 
                    local v323 = v322 .. v319 
                    local v324 = format_real_8(v315)
                    local v325 = v323 .. v324 
                    local v326 = g_game.getLocalPlayer():getHealth()
                    local v327 = g_game.getLocalPlayer():getExperience()
                    local v328 = spiral_wrap_signed((v327 - v0), 32)
                    local v329 = format_real_8(v300)
                    local v330 = "ticks "
                    local v331 = v330 .. v329 
                    local v332 = " heals "
                    local v333 = v331 .. v332 
                    local v334 = format_real_8(v301)
                    local v335 = v333 .. v334 
                    local v336 = " strikes "
                    local v337 = v335 .. v336 
                    local v338 = format_real_8(v302)
                    local v339 = v337 .. v338 
                    local v340 = " holds "
                    local v341 = v339 .. v340 
                    local v342 = format_real_8(v303)
                    local v343 = v341 .. v342 
                    local v344 = format_real_8(v305)
                    local v345 = " retreats "
                    local v346 = v345 .. v344 
                    local v347 = " cornered "
                    local v348 = v346 .. v347 
                    local v349 = format_real_8(v306)
                    local v350 = v348 .. v349 
                    local v351 = " gated "
                    local v352 = v350 .. v351 
                    local v353 = format_real_8(v307)
                    local v354 = v352 .. v353 
                    local v355 = " kills "
                    local v356 = v354 .. v355 
                    local v357 = format_real_8(v304)
                    local v358 = v356 .. v357 
                    local v359 = v343 .. v358 
                    local v360 = format_real_8(v326)
                    local v361 = " health "
                    local v362 = v361 .. v360 
                    local v363 = " lowest "
                    local v364 = v362 .. v363 
                    local v365 = format_real_8(v308)
                    local v366 = v364 .. v365 
                    local v367 = " experience +"
                    local v368 = v366 .. v367 
                    local v369 = format_real_8(v328)
                    local v370 = v368 .. v369 
                    local v371 = v359 .. v370 
                    local v372 = " player at "
                    local v373 = v371 .. v372 
                    local v374 = v373 .. v325 
                    local v375 = "[tibia-probe] "
                    local v376 = v375 .. v374 
                    write_log_line_6(v376)
                else
                end
                return Us1_Some(v300, v301, v302, v303, v304, v305, v306, v307, v308, v309)
            end
        end
    end
    local v379 = getv379()
    if v379 ~= nil and v379.tag == "Us1_None" then
        return nil
    elseif v379 ~= nil and v379.tag == "Us1_Some" then
        local v380 = v379._1
        local v381 = v379._2
        local v382 = v379._3
        local v383 = v379._4
        local v384 = v379._5
        local v385 = v379._6
        local v386 = v379._7
        local v387 = v379._8
        local v388 = v379._9
        local v389 = v379._10
        local v390 = g_clock.millis()
        local v391 = v1 ~= nil and v1.l0
        local v392 = spiral_wrap_signed((v390 - v391), 32)
        local v393 = "TIBIA_ARENA_RUN_MS"
        local v394 = 150000
        local v395 = env_i32_10(v393, v394)
        local v396 = v392 > v395
        if v396 then
            local v397 = g_game.getLocalPlayer():getHealth()
            local v398 = g_game.getLocalPlayer():getExperience()
            local v399 = spiral_wrap_signed((v398 - v0), 32)
            local v400 = format_real_8(v380)
            local v401 = "ticks "
            local v402 = v401 .. v400 
            local v403 = " heals "
            local v404 = v402 .. v403 
            local v405 = format_real_8(v381)
            local v406 = v404 .. v405 
            local v407 = " strikes "
            local v408 = v406 .. v407 
            local v409 = format_real_8(v382)
            local v410 = v408 .. v409 
            local v411 = " holds "
            local v412 = v410 .. v411 
            local v413 = format_real_8(v383)
            local v414 = v412 .. v413 
            local v415 = format_real_8(v385)
            local v416 = " retreats "
            local v417 = v416 .. v415 
            local v418 = " cornered "
            local v419 = v417 .. v418 
            local v420 = format_real_8(v386)
            local v421 = v419 .. v420 
            local v422 = " gated "
            local v423 = v421 .. v422 
            local v424 = format_real_8(v387)
            local v425 = v423 .. v424 
            local v426 = " kills "
            local v427 = v425 .. v426 
            local v428 = format_real_8(v384)
            local v429 = v427 .. v428 
            local v430 = v414 .. v429 
            local v431 = format_real_8(v397)
            local v432 = " health "
            local v433 = v432 .. v431 
            local v434 = " lowest "
            local v435 = v433 .. v434 
            local v436 = format_real_8(v388)
            local v437 = v435 .. v436 
            local v438 = " experience +"
            local v439 = v437 .. v438 
            local v440 = format_real_8(v399)
            local v441 = v439 .. v440 
            local v442 = v430 .. v441 
            local v443 = "end: "
            local v444 = v443 .. v442 
            local v445 = "[tibia-probe] "
            local v446 = v445 .. v444 
            write_log_line_6(v446)
            local v447 = parity_summary_15()
            local v448 = v447 ~= ""
            if v448 then
                local v449 = v445 .. v447 
                write_log_line_6(v449)
            else
            end
            local v450 = "finish: "
            local v451 = "run complete"
            local v452 = v450 .. v451 
            local v453 = v445 .. v452 
            write_log_line_6(v453)
            local v454 = g_game.isOnline()
            if v454 then
                g_game.safeLogout()
            else
            end
            local v455 = closure3(nil)
            scheduleEvent(v455, 2000)
            return nil
        else
            local v456 = g_game.getLocalPlayer():getExperience()
            local v457 = spiral_wrap_signed((v456 - v0), 32)
            local v458 = v457 >= v2
            if v458 then
                local v459 = g_clock.millis()
                local v460 = v1 ~= nil and v1.l0
                local v461 = spiral_wrap_signed((v459 - v460), 32)
                local v462 = format_real_8(v461)
                local v463 = "cleared at "
                local v464 = v463 .. v462 
                local v465 = " ms"
                local v466 = v464 .. v465 
                local v467 = "[tibia-probe] "
                local v468 = v467 .. v466 
                write_log_line_6(v468)
                local v469 = g_game.getLocalPlayer():getHealth()
                local v470 = g_game.getLocalPlayer():getExperience()
                local v471 = spiral_wrap_signed((v470 - v0), 32)
                local v472 = format_real_8(v380)
                local v473 = "ticks "
                local v474 = v473 .. v472 
                local v475 = " heals "
                local v476 = v474 .. v475 
                local v477 = format_real_8(v381)
                local v478 = v476 .. v477 
                local v479 = " strikes "
                local v480 = v478 .. v479 
                local v481 = format_real_8(v382)
                local v482 = v480 .. v481 
                local v483 = " holds "
                local v484 = v482 .. v483 
                local v485 = format_real_8(v383)
                local v486 = v484 .. v485 
                local v487 = format_real_8(v385)
                local v488 = " retreats "
                local v489 = v488 .. v487 
                local v490 = " cornered "
                local v491 = v489 .. v490 
                local v492 = format_real_8(v386)
                local v493 = v491 .. v492 
                local v494 = " gated "
                local v495 = v493 .. v494 
                local v496 = format_real_8(v387)
                local v497 = v495 .. v496 
                local v498 = " kills "
                local v499 = v497 .. v498 
                local v500 = format_real_8(v384)
                local v501 = v499 .. v500 
                local v502 = v486 .. v501 
                local v503 = format_real_8(v469)
                local v504 = " health "
                local v505 = v504 .. v503 
                local v506 = " lowest "
                local v507 = v505 .. v506 
                local v508 = format_real_8(v388)
                local v509 = v507 .. v508 
                local v510 = " experience +"
                local v511 = v509 .. v510 
                local v512 = format_real_8(v471)
                local v513 = v511 .. v512 
                local v514 = v502 .. v513 
                local v515 = "cleared: "
                local v516 = v515 .. v514 
                local v517 = v467 .. v516 
                write_log_line_6(v517)
                local v518 = parity_summary_15()
                local v519 = v518 ~= ""
                if v519 then
                    local v520 = v467 .. v518 
                    write_log_line_6(v520)
                else
                end
                local v521 = "finish: "
                local v522 = "cleared"
                local v523 = v521 .. v522 
                local v524 = v467 .. v523 
                write_log_line_6(v524)
                local v525 = g_game.isOnline()
                if v525 then
                    g_game.safeLogout()
                else
                end
                local v526 = closure3(nil)
                scheduleEvent(v526, 2000)
                return nil
            else
                local v527 = closure9({ v0, v1, v2, v3, v389, v380, v381, v382, v383, v384, v385, v386, v387, v388 })
                scheduleEvent(v527, 100)
                return nil
            end
        end
    end
end

function closure8(capt)
    local v0, v1, v2 = (table.unpack or unpack)(capt)
    return function(dom)
        local v3 = g_game.getLocalPlayer():getPosition()
        local v4 = v3.x
        local v5 = v3.y
        local v6 = v3.z
        local v7 = format_real_8(v4)
        local v8 = ""
        local v9 = v8 .. v7 
        local v10 = ","
        local v11 = v9 .. v10 
        local v12 = format_real_8(v5)
        local v13 = v11 .. v12 
        local v14 = v13 .. v10 
        local v15 = format_real_8(v6)
        local v16 = v14 .. v15 
        local v17 = "random control starts at "
        local v18 = v17 .. v16 
        local v19 = " (drink, engage, random step or stand, equal odds every "
        local v20 = v18 .. v19 
        local v21 = 100
        local v22 = format_real_8(v21)
        local v23 = v20 .. v22 
        local v24 = " ms)"
        local v25 = v23 .. v24 
        local v26 = "[tibia-probe] "
        local v27 = v26 .. v25 
        write_log_line_6(v27)
        local v28 = g_clock.millis()
        v0.l0 = v28
        local v29 = "TIBIA_ARENA_FULL_EXPERIENCE"
        local v30 = 90
        local v31 = env_i32_10(v29, v30)
        local v32 = 0
        local v33 = 0
        local v34 = 0
        local v35 = 0
        local v36 = 0
        local v37 = 0
        local v38 = 0
        local v39 = 0
        local v40 = 999
        local v41 = 0
        return ticked_13(v2, v0, v31, v1, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41)
    end
end

function closure7(capt)
    local v0, v1 = (table.unpack or unpack)(capt)
    return function(dom)
        local v2 = g_game.getLocalPlayer():getExperience()
        local v3 = false
        chasing_9(v3)
        g_game.setFightMode(FightBalanced)
        local v4 = closure8({ v0, v1, v2 })
        scheduleEvent(v4, 1000)
        return nil
    end
end

function closure6(capt)
    local v0, v1 = (table.unpack or unpack)(capt)
    return function(dom)
        local v2 = g_game.getLocalPlayer():getName()
        local v3 = g_game.getLocalPlayer():getHealth()
        local v4 = g_game.getLocalPlayer():getMana()
        local v5 = "in game as "
        local v6 = v5 .. v2 
        local v7 = " health "
        local v8 = v6 .. v7 
        local v9 = format_real_8(v3)
        local v10 = v8 .. v9 
        local v11 = " mana "
        local v12 = v10 .. v11 
        local v13 = format_real_8(v4)
        local v14 = v12 .. v13 
        local v15 = "[tibia-probe] "
        local v16 = v15 .. v14 
        write_log_line_6(v16)
        local v17 = closure7({ v0, v1 })
        scheduleEvent(v17, 1500)
        return nil
    end
end

function closure10(capt)
    local v0, v1, v2, v3, v4, v5 = (table.unpack or unpack)(capt)
    return function(dom)
        return poll_4(v0, v1, v2, v3, v4, v5)
    end
end

function poll_4(v0, v1, v2, v3, v4, v5)
    local v6 = v0 == ""
    local getv8 = function()
        if v6 then
            return true
        else
            return file_exists_5(v0)
        end
    end
    local v8 = getv8()
    if v8 then
        g_game.setClientVersion(1511)
        g_game.setProtocolVersion(g_game.getClientProtocolVersion(1511))
        g_game.chooseRsa("127.0.0.1")
        local v9 = typed_c2(nil)
        local v10 = function(message) (v9)(message) end
        local v11 = typed_c4({ v2, v3 })
        local v12 = function(mode, text) (v11)(mode)(text) end
        local v13 = closure6({ v4, v5 })
        connect(g_game, { onGameStart = v13, onLoginError = v10, onTextMessage = v12 })
        local v14 = "@god"
        local v15 = "@god\ngod"
        g_game.loginWorld(v14, "god", "OTServBR-Global", "127.0.0.1", 7172, v1, "", v15)
        return nil
    else
        local v16 = closure10({ v0, v1, v2, v3, v4, v5 })
        scheduleEvent(v16, 50)
        return nil
    end
end

function closure1(capt)
    local v0, v1, v2, v3, v4 = (table.unpack or unpack)(capt)
    return function(dom)
        local v5 = "TIBIA_LOGIN_GATE"
        local v6 = ""
        local v7 = env_text_0(v5, v6)
        return poll_4(v7, v0, v1, v2, v3, v4)
    end
end

function closure11(capt)
    return function(dom)
        local v0 = parity_summary_15()
        local v1 = v0 ~= ""
        if v1 then
            local v2 = "[tibia-probe] "
            local v3 = v2 .. v0 
            write_log_line_6(v3)
        else
        end
        local v4 = "finish: "
        local v5 = "timeout"
        local v6 = v4 .. v5 
        local v7 = "[tibia-probe] "
        local v8 = v7 .. v6 
        write_log_line_6(v8)
        local v9 = g_game.isOnline()
        if v9 then
            g_game.safeLogout()
        else
        end
        local v10 = closure3(nil)
        scheduleEvent(v10, 2000)
        return nil
    end
end

math.randomseed(os.time())
local v0 = { __tag = "Mut0", l0 = 0 }
local v1 = Uh0_Nil()
local v2 = { __tag = "Mut1", l0 = v1 }
local v3 = "TIBIA_ARENA_CHARACTER"
local v4 = "Knight Sample"
local v5 = env_text_0(v3, v4)
local v6 = "_1511"
local v7 = v5 .. v6 
disable_client_bot_2(v7)
local v8 = env_text_0(v3, v4)
local v9 = "TIBIA_PROBE_HIDDEN"
local v10 = get_environment_variable_1(v9)
local v11 = v10 == "1"
if v11 then
    g_window.move({ x = -32000, y = -32000 })
    g_window.hide()
else
end
mute_3()
local v12 = closure0(nil)
scheduleEvent(v12, 200)
scheduleEvent(v12, 1000)
local v13 = closure1({ v8, v0, v2, v0, v2 })
scheduleEvent(v13, 3000)
local v14 = closure11(nil)
scheduleEvent(v14, 200000)
return 0
