aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt149
1 files changed, 99 insertions, 50 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt
index c9fecaf08..fdf023a06 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt
@@ -6,6 +6,8 @@ import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.LorenzVec
+import at.hannibal2.skyhanni.utils.NumberUtil.isInt
+import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.toLorenzVec
import net.minecraft.client.Minecraft
@@ -18,6 +20,7 @@ import net.minecraft.network.play.server.S0CPacketSpawnPlayer
import net.minecraft.network.play.server.S0EPacketSpawnObject
import net.minecraft.network.play.server.S0FPacketSpawnMob
import net.minecraft.network.play.server.S12PacketEntityVelocity
+import net.minecraft.network.play.server.S13PacketDestroyEntities
import net.minecraft.network.play.server.S14PacketEntity
import net.minecraft.network.play.server.S18PacketEntityTeleport
import net.minecraft.network.play.server.S19PacketEntityHeadLook
@@ -31,15 +34,38 @@ import net.minecraft.network.play.server.S2APacketParticles
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-class PacketTest {
- companion object {
+object PacketTest {
- private var enabled = false
+ private var enabled = false
+ private var full = false
- fun toggle() {
- enabled = !enabled
- ChatUtils.chat("Packet test: $enabled")
+ private val entityMap = mutableMapOf<Int, MutableList<Packet<*>>>()
+
+ fun command(args: Array<String>) {
+ if (args.size == 1 && args[0].isInt()) {
+ sendEntityPacketData(args[0].toInt())
+ return
+ }
+ if (args.size == 1 && (args[0] == "full" || args[0] == "all")) {
+ full = !full
+ ChatUtils.chat("Packet test full: $full")
+ return
+ }
+
+ toggle()
+ }
+
+ private fun sendEntityPacketData(id: Int) {
+ ChatUtils.chat("Packet Entity Data: $id")
+ entityMap[id]?.forEach {
+ it.print()
}
+ println("End of Data")
+ }
+
+ private fun toggle() {
+ enabled = !enabled
+ ChatUtils.chat("Packet test: $enabled")
}
@SubscribeEvent
@@ -67,7 +93,19 @@ class PacketTest {
fun onChatPacket(event: PacketEvent.ReceiveEvent) {
if (!enabled) return
val packet = event.packet
- val packetName = packet.javaClass.simpleName
+ packet.print()
+ if (packet is S13PacketDestroyEntities) {
+ packet.entityIDs.forEach {
+ entityMap.getOrDefault(it, mutableListOf()).add(packet)
+ }
+ } else {
+ val id = packet.getEntityId() ?: return
+ entityMap.getOrDefault(id, mutableListOf()).add(packet)
+ }
+ }
+
+ private fun Packet<*>.print() {
+ val packetName = javaClass.simpleName
// Keep alive
if (packetName == "S00PacketKeepAlive") return
@@ -94,54 +132,58 @@ class PacketTest {
// Others
if (packetName == "S29PacketSoundEffect") return
-// if (packetName == "S2APacketParticles") return
+ if (!full && packetName == "S2APacketParticles") return
// Entity
- if (packetName == "S13PacketDestroyEntities") return
+ if (this is S13PacketDestroyEntities) {
+ println("Receive: $packetName with IDs: ${entityIDs.joinToString(", ")}")
+ return
+ }
- if (packetName == "S18PacketEntityTeleport") return
- if (packetName == "S15PacketEntityRelMove") return
- if (packetName == "S04PacketEntityEquipment") return
+ if (!full) {
+ if (packetName == "S18PacketEntityTeleport") return
+ if (packetName == "S15PacketEntityRelMove") return
+ if (packetName == "S04PacketEntityEquipment") return
+ if (packetName == "S17PacketEntityLookMove") return
+ if (packetName == "S19PacketEntityHeadLook") return
+ if (packetName == "S16PacketEntityLook") return
+ if (packetName == "S12PacketEntityVelocity") return
+ if (packetName == "S1CPacketEntityMetadata") return
+ if (packetName == "S20PacketEntityProperties") return
+ if (packetName == "S0BPacketAnimation") return
+ }
// if (packetName == "S0EPacketSpawnObject") return
-// if (packetName == "S0BPacketAnimation") return
// if (packetName == "S06PacketUpdateHealth") return
-// if (packetName == "S17PacketEntityLookMove") return
-// if (packetName == "S16PacketEntityLook") return
-// if (packetName == "S19PacketEntityHeadLook") return
// if (packetName == "S1DPacketEntityEffect") return
-// if (packetName == "S12PacketEntityVelocity") return
// if (packetName == "S19PacketEntityStatus") return
-// if (packetName == "S1CPacketEntityMetadata") return
-// if (packetName == "S20PacketEntityProperties") return
// if (packetName == "S1BPacketEntityAttach") return
- val id = getEntityId(packet)
- val entity = getEntity(packet, id)
- val distance = getDistance(getLocation(packet, entity))
- if (distance > 10) return
+ buildString {
+ append("Receive: $packetName")
- if (entity != null) {
- if (entity == Minecraft.getMinecraft().thePlayer) {
-// println("own: $distance $packetName")
- return
- } else {
- println("other: $distance")
- }
- } else {
+ val id = getEntityId()
if (id != null) {
- return
+ append(" ID: $id")
}
-// if (packetName.contains("")) {
-//
-// }
- println("entity is null.")
- }
+ val entity = getEntity(this@print, id)
+ val distance = getDistance(getLocation(this@print, entity))
-// println("distance: $distance")
- println("Receive: $packetName")
- println(" ")
+ if (entity != null) {
+ if (entity == Minecraft.getMinecraft().thePlayer) {
+ append(" own")
+ return@buildString
+ } else {
+ append(" distance: $distance other")
+ }
+ } else {
+ if (id == null) {
+ return@buildString
+ }
+ append(" entity is null.")
+ }
+ }.let { println(it) }
}
private fun getDistance(location: LorenzVec?): Double {
@@ -194,16 +236,23 @@ class PacketTest {
return null
}
- private fun getEntityId(packet: Packet<*>) = when (packet) {
- is S1CPacketEntityMetadata -> packet.entityId
- is S20PacketEntityProperties -> packet.entityId
- is S04PacketEntityEquipment -> packet.entityID
- is S12PacketEntityVelocity -> packet.entityID
- is S1BPacketEntityAttach -> packet.entityId
- is S0BPacketAnimation -> packet.entityID
- is S18PacketEntityTeleport -> packet.entityId
- is S1DPacketEntityEffect -> packet.entityId
-
+ private fun Packet<*>.getEntityId() = when (this) {
+ is S1CPacketEntityMetadata -> entityId
+ is S20PacketEntityProperties -> entityId
+ is S04PacketEntityEquipment -> entityID
+ is S12PacketEntityVelocity -> entityID
+ is S1BPacketEntityAttach -> entityId
+ is S0BPacketAnimation -> entityID
+ is S18PacketEntityTeleport -> entityId
+ is S1DPacketEntityEffect -> entityId
+ is S0CPacketSpawnPlayer -> entityID
+ is S0FPacketSpawnMob -> entityID
+ is S0EPacketSpawnObject -> entityID
+ is S19PacketEntityHeadLook -> javaClass.getDeclaredField("entityId").makeAccessible().get(this) as Int
+ is S19PacketEntityStatus -> javaClass.getDeclaredField("entityId").makeAccessible().get(this) as Int
+ /* is S14PacketEntity.S15PacketEntityRelMove -> packet.javaClass.getDeclaredField("entityId").makeAccessible().get(packet) as Int
+ is S14PacketEntity.S16PacketEntityLook -> packet.javaClass.getDeclaredField("entityId").makeAccessible().get(packet) as Int
+ is S14PacketEntity.S17PacketEntityLookMove -> packet.javaClass.getDeclaredField("entityId").makeAccessible().get(packet) as Int */
else -> null
}
}