Skip to content

Commit

Permalink
fixes from wdal
Browse files Browse the repository at this point in the history
  • Loading branch information
SPRAVEDLIVO committed May 8, 2021
1 parent cd22e36 commit 50e0cac
Show file tree
Hide file tree
Showing 35 changed files with 189 additions and 169 deletions.
8 changes: 5 additions & 3 deletions src/main/kotlin/rat/poison/RatPoison.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import rat.poison.game.CSGO
import rat.poison.game.offsets.EngineOffsets.dwbSendPackets
import rat.poison.overlay.App
import rat.poison.scripts.*
import rat.poison.scripts.aim.*
import rat.poison.scripts.aim.flatAim
import rat.poison.scripts.aim.handleFireKey
import rat.poison.scripts.aim.pathAim
import rat.poison.scripts.aim.setAim
import rat.poison.scripts.visuals.*
import rat.poison.utils.Settings
import rat.poison.utils.WebSocket
import rat.poison.utils.detectLocale
import rat.poison.utils.generalUtil.loadSettingsFromFiles
import rat.poison.utils.generalUtil.loadSkinSettings
import rat.poison.utils.generalUtil.stringToIntList
import rat.poison.utils.loadMigration
import java.awt.Robot
import java.io.File
Expand All @@ -46,7 +48,7 @@ data class sWeapon(var tSkinID: Int, var tStatTrak: Int, var tWear: Float, var t
const val TITLE = "RatPoison"
const val BRANCH = "Beta"
const val F_VERSION = "1.8"
const val M_VERSION = "1.8.5.6"
const val M_VERSION = "1.8.5.7"
var LOADED_CONFIG = "DEFAULT"
var oWeaponSize = oWeapon::class.java.declaredFields.size

Expand Down
84 changes: 28 additions & 56 deletions src/main/kotlin/rat/poison/game/Entities.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package rat.poison.game

import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
import rat.poison.game.entity.EntityType
import rat.poison.game.entity.Player
import rat.poison.game.hooks.forceResetIteration
import rat.poison.settings.MAX_ENTITIES
import rat.poison.utils.lists.ForEntitiesList

@Volatile
var me: Player = 0
Expand All @@ -12,76 +14,46 @@ var clientState: ClientState = 0
@Volatile
var meTeam: Long = 0

typealias EntityList = Object2ObjectArrayMap<EntityType, MutableList<EntityContext>>
typealias EntityList = Object2ObjectOpenHashMap<EntityType, ForEntitiesList>

var entitiesValues = arrayOfNulls<MutableList<EntityContext>>(MAX_ENTITIES)
var entitiesValues = arrayOfNulls<ForEntitiesList>(MAX_ENTITIES)
var entitiesValuesCounter = 0

val entities: EntityList = EntityList(EntityType.size).apply {
for (type in EntityType.cachedValues) {
val list = mutableListOf<EntityContext>()
val list = ForEntitiesList()
put(type, list)
entitiesValues[entitiesValuesCounter++] = list
}
}

fun entityByType(type: EntityType): EntityContext? = entities[type]?.firstOrNull()
data class EntityCache(var created: Long, var ents: ArrayList<EntityContext>, var iterating: Boolean = false)
val entityCache = Object2ObjectArrayMap<String, EntityCache>()
//private const val emptyString = ""
internal inline fun forEntities(vararg types: EntityType, iterateWeapons: Boolean = false, iterateGrenades: Boolean = false, identifier: String = "", crossinline body: (EntityContext) -> Unit) {
var get = entityCache[identifier]

if (get == null || System.currentTimeMillis() - get.created > 2000) {
if (get != null) {
get.ents.clear()
get.created = System.currentTimeMillis()
internal inline fun iterateByTypes(types: Array<EntityType>, crossinline body: (EntityContext) -> Unit) {
for (typeIdx in 0 until types.size) {
if (forceResetIteration) {
break
}
else {
val tmpClass = EntityCache(System.currentTimeMillis(), ArrayList())
get = tmpClass
entityCache[identifier] = tmpClass
}
val col = if (types.isEmpty()) EntityType.cachedValues else types
for (i in 0 until col.size) {
val entType = col[i]
val ents = entities[entType] ?: continue
for (i1 in 0 until ents.size) {
val ent = ents[i1]
get.ents.add(ent)
ent.run(body)
}
}
if (iterateWeapons) {
for (i in 0 until EntityType.weaponsTypes.size) {
val entType = EntityType.weaponsTypes[i]
val ents = entities[entType] ?: continue
for (i1 in 0 until ents.size) {
val ent = ents[i1]
get.ents.add(ent)
ent.run(body)
}
}
}
if (iterateGrenades) {
for (i in 0 until EntityType.grenadeTypes.size) {
val entType = EntityType.grenadeTypes[i]
val ents = entities[entType] ?: continue
for (i1 in 0 until ents.size) {
val ent = ents[i1]
get.ents.add(ent)
ent.run(body)
}
val let = entities[types[typeIdx]] ?: continue
let.completeTasks()
let.iterating = true
for (entIdx in 0 until let.cachedValues.size) {
if (forceResetIteration) {
break
}
val ent = let.getOrNull(entIdx) ?: continue
ent.run(body)
}
let.iterating = false
}
else {
if (!get.iterating) {
get.iterating = true
for (i in 0 until get.ents.size) {
get.ents[i].run(body)
}
get.iterating = false
}
}

internal inline fun forEntities(types: Array<EntityType>, iterateWeapons: Boolean = false, iterateGrenades: Boolean = false, crossinline body: (EntityContext) -> Unit) {
iterateByTypes(types, body)
if (iterateGrenades) {
iterateByTypes(EntityType.grenadeTypes, body)
}
if (iterateWeapons) {
iterateByTypes(EntityType.weaponsTypes, body)
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/rat/poison/game/WorldToScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import rat.poison.game.CSGO.gameHeight
import rat.poison.game.CSGO.gameWidth
import rat.poison.game.offsets.ClientOffsets.dwViewMatrix
import rat.poison.utils.Vector
import rat.poison.utils.threadLocalPointer
import rat.poison.utils.extensions.getFloatArray
import rat.poison.utils.threadLocalPointer

val w2sViewMatrix = Array(4) { DoubleArray(4) }
private val DEFAULT_VECTOR = Vector()
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/rat/poison/game/entity/EntityType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ enum class EntityType(val weapon: Boolean = false, val grenade: Boolean = false,

companion object {
val cachedValues = values()
val weaponsTypes = cachedValues.filter { it.weapon }
val grenadeTypes = cachedValues.filter { it.grenade }
val weaponsTypes = cachedValues.filter { it.weapon }.toTypedArray()
val grenadeTypes = cachedValues.filter { it.grenade }.toTypedArray()
val size = cachedValues.size

private fun byID(id: Long) = cachedValues.firstOrNull { it.id == id }
Expand Down
24 changes: 10 additions & 14 deletions src/main/kotlin/rat/poison/game/hooks/EntityIteration.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package rat.poison.game.hooks

import com.sun.jna.platform.win32.WinNT
import io.ktor.util.*
import rat.poison.dbg
import rat.poison.game.*
import rat.poison.game.CSGO.GLOW_OBJECT_SIZE
Expand All @@ -22,11 +21,11 @@ import rat.poison.game.offsets.EngineOffsets.dwClientState_MapDirectory
import rat.poison.game.offsets.EngineOffsets.dwGameDir
import rat.poison.game.offsets.EngineOffsets.dwSignOnState
import rat.poison.scripts.detectMap
import rat.poison.scripts.nameChange
import rat.poison.scripts.sendPacket
import rat.poison.settings.*
import rat.poison.utils.*
import rat.poison.utils.extensions.uint
import java.lang.Float.intBitsToFloat
import java.util.concurrent.atomic.AtomicLong
import kotlin.properties.Delegates

Expand All @@ -38,18 +37,24 @@ private fun shouldReset() = System.currentTimeMillis() - lastCleanup.get() >= CL

private fun reset() {
for (i in entitiesValues) {
i?.removeAll(i)
i?.clear()
}

lastCleanup.set(System.currentTimeMillis())
}

var forceResetIteration = false


private const val strBufMemorySize = 128
private val strBufMemory = threadLocalPointer(strBufMemorySize)
private var signOnState by Delegates.observable(SignOnState.MAIN_MENU) { _, old, new ->
if (old != new) {
if (new.name == SignOnState.IN_GAME.name) {
forceResetIteration = true
after(1000) {
forceResetIteration = false
}
after(10000) {
shouldPostProcess = true
}
Expand Down Expand Up @@ -79,7 +84,6 @@ private var signOnState by Delegates.observable(SignOnState.MAIN_MENU) { _, old,
// }

inGame = true
nameChange = ""

if (PROCESS_ACCESS_FLAGS and WinNT.PROCESS_VM_OPERATION > 0) {
try {
Expand All @@ -93,10 +97,6 @@ private var signOnState by Delegates.observable(SignOnState.MAIN_MENU) { _, old,

sendPacket(true)
} else {
if (new.name == SignOnState.MAIN_MENU.name) { //disconnected
WebSocket.createSendTask("deleteInfo")
}

shouldPostProcess = false
inGame = false
sendPacket(true)
Expand All @@ -114,7 +114,6 @@ fun updateCursorEnable() { //Call when needed
}

var toneMapController = 0L

private val positionVector = Vector()
fun constructEntities() = every(500, continuous = true) {
updateCursorEnable()
Expand All @@ -131,7 +130,6 @@ fun constructEntities() = every(500, continuous = true) {
if (shouldReset()) reset()

var dzMode = false

for (glowIndex in 0..glowObjectCount) {
val glowAddress = glowObject + (glowIndex * GLOW_OBJECT_SIZE)
val entity = csgoEXE.uint(glowAddress)
Expand All @@ -140,9 +138,8 @@ fun constructEntities() = every(500, continuous = true) {
val type = EntityType.byEntityAddress(entity)
if (type != EntityType.NULL) {
val tmpPos = entity.absPosition(positionVector)
val check = (tmpPos.x in -2.0F..2.0F && tmpPos.y in -2.0F..2.0F && tmpPos.z in -2.0F..2.0F)

if (!check) {
if (!tmpPos.isZero()) {
val context = contexts[glowIndex].set(entity, glowAddress, glowIndex, type) //remove contexts[]

with(entities[type]!!) {
Expand Down Expand Up @@ -182,7 +179,6 @@ fun constructEntities() = every(500, continuous = true) {
}
}
}

DANGER_ZONE = dzMode
GAME_SENSITIVITY = java.lang.Float.intBitsToFloat((clientDLL.uint(dwSensitivity) xor (clientDLL.address + dwSensitivityPtr)).toInt()).toDouble()
GAME_SENSITIVITY = intBitsToFloat((clientDLL.uint(dwSensitivity) xor (clientDLL.address + dwSensitivityPtr)).toInt()).toDouble()
}
6 changes: 3 additions & 3 deletions src/main/kotlin/rat/poison/scripts/Backtrack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ private val boneMemory = threadLocalPointer(boneMemorySize)
private val meAngVec = Vector()
private var bestFov = 5F
private val boneVec = Vector()
//private val positionVector = Vector()
private const val id = "backtrack"
private val forEntsList = arrayOf(EntityType.CCSPlayer)

fun constructRecords() {
bestFov = 5F
val clientAngle = clientState.angle(meAngVec)

val boneMemory = boneMemory.get()

forEntities(EntityType.CCSPlayer, identifier = id) {
forEntities(forEntsList) {
val ent = it.entity

if (ent.dead() || ent == me || ent.team() == meTeam) return@forEntities
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/rat/poison/scripts/BlockBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun unPress() {
private val mePos = Vector()
private val meAng = Vector()
private val closestPos = Vector()
private const val forEntsId = "blockbot"
private val forEntsList = arrayOf(EntityType.CCSPlayer)
fun blockBot() = every(2, inGameCheck = true) {
if (!curSettings.bool["BLOCK_BOT"] || !keyPressed(curSettings.int["BLOCK_BOT_KEY"])) {
unPress()
Expand All @@ -55,7 +55,7 @@ fun blockBot() = every(2, inGameCheck = true) {
var closestTarget = -1L
val maxDist = curSettings.int["BLOCK_BOT_DISTANCE"]

forEntities(EntityType.CCSPlayer, identifier = forEntsId) {
forEntities(forEntsList) {
val entity = it.entity
if (entity == me || entity.dead() || entity.dead() || entity <= 0) return@forEntities

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/rat/poison/scripts/HeadWalk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ internal fun headWalk() = every(2, inGameCheck = true) {
}
}

private const val id = "headwalk"
private val forEntsList = arrayOf(EntityType.CCSPlayer)
internal fun onPlayerHead() : Boolean {
var entPos : Angle
onEnt = 0L

forEntities(EntityType.CCSPlayer, identifier = id) {
forEntities(forEntsList) {
val entity = it.entity
if (entity == me || !entity.onGround()) return@forEntities

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/rat/poison/scripts/RCS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun rcs() = every(15, inGameCheck = true) {
val shotsFired = me.shotsFired()
val p = me.punch(punchVec)

val isZero = lastAppliedRCS.invalid()
val isZero = lastAppliedRCS.isZero()
val forceSet = (shotsFired == 0 && !isZero || meCurWepEnt.bullets() <= 0)

if (forceSet || /*!finishPunch ||*/ shotsFired > 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/rat/poison/scripts/Ranks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import rat.poison.utils.extensions.uint
import rat.poison.utils.saving

var ranksPlayerList = Array(64) { RanksPlayer() }
private const val id = "ranks"
private val forEntsList = arrayOf(EntityType.CCSPlayer)
//works with every down to 30, if you ever crash due to this then dn
fun ranks() = every(5000, true, inGameCheck = true) { //Rebuild every second

Expand All @@ -28,7 +28,7 @@ fun ranks() = every(5000, true, inGameCheck = true) { //Rebuild every second
//Bruh -- fix later
updatingRanks = true
var max = 0
forEntities(EntityType.CCSPlayer, identifier = id) {
forEntities(forEntsList) {
val entity = it.entity
val entID = (CSGO.csgoEXE.uint(entity + ClientOffsets.dwIndex) - 1).toInt()
if (entID > 64 || entID < 0) return@forEntities
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/rat/poison/scripts/Scanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.nio.file.StandardOpenOption
import java.util.*
import javax.script.ScriptException
import kotlin.system.exitProcess
private const val id = "scanner"
private val forEntsList = arrayOf(EntityType.CCSPlayer)
fun scanner() {
println("Type help for options\n")

Expand Down Expand Up @@ -176,7 +176,7 @@ fun scanner() {
println("Team Name Rank Kills Deaths K/D Wins Money")
println("====== ================================ ===== ===== ====== ==== ===== =====")
try {
forEntities(EntityType.CCSPlayer, identifier = id) {
forEntities(forEntsList) {
val entity = it.entity
var entTeam = when (entity.team()) {
3L -> "CT"
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/rat/poison/scripts/SpectatorList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import rat.poison.overlay.opened
import rat.poison.ui.uiPanels.specListText
import rat.poison.utils.every
import rat.poison.utils.extensions.readIndex
private const val id = "spectatorlist"
private val forEntsList = arrayOf(EntityType.CCSPlayer)
internal fun spectatorList() = every(100, inGameCheck = true) {
if (!curSettings.bool["SPECTATOR_LIST"] || !curSettings.bool["MENU"]) {
return@every
Expand All @@ -23,7 +23,7 @@ internal fun spectatorList() = every(100, inGameCheck = true) {

val playerSpecTarget = csgoEXE.readIndex(me + dwIndex)

forEntities(EntityType.CCSPlayer, identifier = id) {
forEntities(forEntsList) {
val entity = it.entity

if (entity.isSpectating() && !entity.hltv() && !entity.dormant()) {
Expand Down

0 comments on commit 50e0cac

Please sign in to comment.