Skip to content

Additional packets support for command: ;packet #558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.lambda.mixin.accessor.network;

import net.minecraft.network.play.client.CPacketVehicleMove;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(value = CPacketVehicleMove.class)
public interface AccessorCPacketVehicleMove {
@Accessor(value = "x")
void setX(double x);

@Accessor(value = "y")
void setY(double y);

@Accessor(value = "z")
void setZ(double z);

@Accessor(value = "yaw")
void setYaw(float yaw);

@Accessor(value = "pitch")
void setPitch(float pitch);
}
72 changes: 61 additions & 11 deletions src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package com.lambda.client.command.commands

import com.lambda.client.command.ClientCommand
import com.lambda.client.event.SafeClientEvent
import com.lambda.client.mixin.extension.setValues
import com.lambda.client.mixin.extension.useEntityAction
import com.lambda.client.mixin.extension.useEntityId
import com.lambda.client.util.items.clickSlotUnsynced
import com.lambda.client.util.text.MessageSendHelper
import io.netty.buffer.Unpooled
import net.minecraft.entity.passive.EntityDonkey
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.inventory.ClickType
import net.minecraft.item.ItemStack
import net.minecraft.item.crafting.CraftingManager
import net.minecraft.network.Packet
import net.minecraft.network.PacketBuffer
import net.minecraft.network.play.client.*
import net.minecraft.util.EnumFacing
import net.minecraft.util.EnumHand
Expand All @@ -20,7 +25,7 @@ import net.minecraft.util.text.TextFormatting

object PacketCommand : ClientCommand(
name = "packet",
description = "Send any packet you want"
description = "Send (almost) any packet you want"
) {
init {
literal("Animation") {
Expand Down Expand Up @@ -89,8 +94,13 @@ object PacketCommand : ClientCommand(
}

literal("ClientStatus") {
executeSafe {
MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.")
enum<CPacketClientStatus.State>("state") { state ->
executeSafe {
deployPacket(
CPacketClientStatus(state.value),
"${state.value}"
)
}
}
}

Expand Down Expand Up @@ -144,8 +154,20 @@ object PacketCommand : ClientCommand(
}

literal("CustomPayload") {
executeSafe {
MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.")
string("channel") { channel ->
// todo: technically we need to be able to send more data types to fully utilize this packet, but I'm too lazy to implement it and it doesn't fit in well with commands
string("stringData") { data ->
executeSafe {
PacketBuffer(Unpooled.buffer())
.apply { writeString(data.value) }
.also {
deployPacket(
CPacketCustomPayload(channel.value, it),
"${channel.value} ${data.value}"
)
}
}
}
}
}

Expand Down Expand Up @@ -215,8 +237,22 @@ object PacketCommand : ClientCommand(
}

literal("PlaceRecipe") {
executeSafe {
MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.")
int("windowId") { windowId ->
string("recipe") { recipe ->
boolean("makeAll") { makeAll ->
executeSafe {
CraftingManager.REGISTRY.keys
.find { it.toString() == recipe.value }?.let {
CraftingManager.REGISTRY.getObject(it)?.let { iRecipe ->
deployPacket(
CPacketPlaceRecipe(windowId.value, iRecipe, makeAll.value),
"${windowId.value} ${recipe.value} ${makeAll.value}"
)
}
}
}
}
}
}
}

Expand Down Expand Up @@ -412,6 +448,7 @@ object PacketCommand : ClientCommand(
executeSafe {
val packet = CPacketUseEntity()
packet.useEntityId = id.value
packet.useEntityAction = CPacketUseEntity.Action.ATTACK

deployPacket(
packet,
Expand Down Expand Up @@ -459,16 +496,29 @@ object PacketCommand : ClientCommand(
}
}
}

literal("VehicleMove") {
executeSafe {
MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.")
double("x") { x ->
double("y") { y ->
double("z") { z ->
float("yaw") { yaw ->
float("pitch") { pitch ->
executeSafe {
deployPacket(
CPacketVehicleMove().setValues(x.value, y.value, z.value, yaw.value, pitch.value),
"${x.value} ${y.value} ${z.value} ${yaw.value} ${pitch.value}"
)
}
}
}
}
}
}
}
}

private fun SafeClientEvent.deployPacket(packet: Packet<*>, info: String) {
connection.sendPacket(packet)
// bypasses packet cancel :trollepic:
connection.networkManager.sendPacket(packet, null)
MessageSendHelper.sendChatMessage("Sent ${TextFormatting.GRAY}${packet.javaClass.name.split(".").lastOrNull()}${TextFormatting.DARK_RED} > ${TextFormatting.GRAY}$info")
}
}
14 changes: 10 additions & 4 deletions src/main/kotlin/com/lambda/client/mixin/extension/Network.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.lambda.client.mixin.extension

import com.lambda.mixin.accessor.network.*
import net.minecraft.network.play.client.CPacketChatMessage
import net.minecraft.network.play.client.CPacketCloseWindow
import net.minecraft.network.play.client.CPacketPlayer
import net.minecraft.network.play.client.CPacketUseEntity
import net.minecraft.network.play.client.*
import net.minecraft.network.play.server.*
import net.minecraft.util.text.ITextComponent

Expand Down Expand Up @@ -78,6 +75,15 @@ var CPacketUseEntity.useEntityAction: CPacketUseEntity.Action
(this as AccessorCPacketUseEntity).setAction(value)
}

fun CPacketVehicleMove.setValues(x: Double, y: Double, z: Double, yaw: Float, pitch: Float): CPacketVehicleMove {
(this as AccessorCPacketVehicleMove).setX(x)
(this as AccessorCPacketVehicleMove).setY(y)
(this as AccessorCPacketVehicleMove).setZ(z)
(this as AccessorCPacketVehicleMove).setYaw(yaw)
(this as AccessorCPacketVehicleMove).setPitch(pitch)
return this
}

var SPacketChat.textComponent: ITextComponent
get() = this.chatComponent
set(value) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.lambda.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"accessor.network.AccessorCPacketCloseWindow",
"accessor.network.AccessorCPacketPlayer",
"accessor.network.AccessorCPacketUseEntity",
"accessor.network.AccessorCPacketVehicleMove",
"accessor.network.AccessorSPacketChat",
"accessor.network.AccessorSPacketEntity",
"accessor.network.AccessorSPacketEntityHeadLook",
Expand Down