Created
April 10, 2023 23:12
-
-
Save its-jackson/7422cba7e824092cc4b0848f611a4de2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scripts.kotlin.api | |
import org.tribot.script.sdk.MyPlayer | |
import org.tribot.script.sdk.query.Query | |
import java.security.MessageDigest | |
import kotlin.math.abs | |
import kotlin.math.cos | |
import kotlin.math.ln | |
import kotlin.math.sqrt | |
import kotlin.random.Random | |
// Based on the values of variable1 and variable2 for each player, | |
// the lambda might return true always, never, or sometimes. | |
// If the threshold is greater than 1 (e.g., variable1 is 60 and variable2 is 40), | |
// the lambda will always return true, and the player will always do the specific action. | |
// If the threshold is equal to 0 (e.g., variable1 is 0), | |
// the lambda will never return true, and the player will never do the specific action. | |
// If the threshold is between 0 and 1, | |
// the probability of returning true depends on the ratio of variable1 to variable2. | |
// The closer the threshold is to 1, the higher the probability that it will be triggered; | |
// the closer the threshold is to 0, the lower the probability. | |
fun getVariableBasedTriggerCondition(): (PlayerBehaviorProfile) -> Boolean { | |
return { player: PlayerBehaviorProfile -> | |
val threshold = player.variable1 / player.variable2 | |
java.util.Random().nextDouble() < threshold | |
} | |
} | |
fun isAnyPlayerNearby(player: PlayerBehaviorProfile) = getVariableBasedTriggerCondition().invoke(player) && Query.players().isAny | |
data class DistributionParameters(val mean: Double, val standardDeviation: Double) | |
// This approach provides a higher level of encryption | |
// for the relationship between the username and the random seed, | |
// making it more difficult to reverse-engineer. | |
data class PlayerBehaviorProfile( | |
private val username: String = MyPlayer.getUsername(), | |
private val variable1Parameters: DistributionParameters, | |
private val variable2Parameters: DistributionParameters | |
) { | |
val variable1: Double | |
val variable2: Double | |
init { | |
val randomSeed = computeSha256Hash(username) | |
val random = Random(randomSeed) | |
variable1 = abs(generateNormalVariable(random, variable1Parameters.mean, variable1Parameters.standardDeviation)) | |
variable2 = abs(generateNormalVariable(random, variable2Parameters.mean, variable2Parameters.standardDeviation)) | |
} | |
private fun computeSha256Hash(text: String): Long { | |
val bytes = text.toByteArray() | |
val digest = MessageDigest.getInstance("SHA-256") | |
val hashedBytes = digest.digest(bytes) | |
return hashedBytes.fold(0L) { acc, byte -> (acc shl 8) or byte.toLong() } | |
} | |
private fun generateNormalVariable(random: Random, mean: Double, stdDev: Double): Double { | |
val u1 = random.nextDouble() | |
val u2 = random.nextDouble() | |
val z0 = sqrt(-2.0 * ln(u1)) * cos(2.0 * Math.PI * u2) | |
return mean + (z0 * stdDev) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment