Skip to content
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

PacketLogger Revamp #557

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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,12 @@
package com.lambda.mixin.accessor.network;

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

@Mixin(value = CPacketClientSettings.class)
public interface AccessorCPacketClientSettings {
@Accessor(value = "view")
int getView();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.lambda.mixin.accessor.network;

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

@Mixin(value = CPacketConfirmTransaction.class)
public interface AccessorCPacketConfirmTransaction {
@Accessor(value = "accepted")
boolean getAccepted();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lambda.mixin.accessor.network;

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

@Mixin(value = CPacketPlayerAbilities.class)
public interface AccessorCPacketPlayerAbilities {
@Accessor(value = "flySpeed")
float getFlySpeed();
@Accessor(value = "walkSpeed")
float getWalkSpeed();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.lambda.mixin.accessor.network;

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

@Mixin(value = CPacketResourcePackStatus.class)
public interface AccessorCPacketResourcePackStatus {
@Accessor(value = "action")
CPacketResourcePackStatus.Action getAction();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lambda.mixin.accessor.network;

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

import java.util.UUID;

@Mixin(value = CPacketSpectate.class)
public interface AccessorCPacketSpectate {
@Accessor(value = "id")
UUID getId();
}
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.lambda.mixin.accessor.network;

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

@Mixin(value = NetHandlerPlayClient.class)
public interface AccessorNetHandlerPlayClient {

@Accessor(value = "doneLoadingTerrain")
boolean isDoneLoadingTerrain();

@Accessor(value = "doneLoadingTerrain")
void setDoneLoadingTerrain(boolean loaded);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.lambda.mixin.accessor.network;

import net.minecraft.network.play.server.SPacketCloseWindow;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(value = SPacketCloseWindow.class)
public interface AccessorSPacketCloseWindow {
@Accessor(value = "windowId")
int getWindowId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.lambda.mixin.accessor.network;

import net.minecraft.network.play.server.SPacketMaps;
import net.minecraft.world.storage.MapDecoration;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(value = SPacketMaps.class)
public interface AccessorSPacketMaps {
@Accessor(value = "mapScale")
byte getMapScale();
@Accessor(value = "trackingPosition")
boolean getTrackingPosition();
@Accessor(value = "icons")
MapDecoration[] getIcons();
@Accessor(value = "minX")
int getMinX();
@Accessor(value = "minZ")
int getMinZ();
@Accessor(value = "columns")
int getColumns();
@Accessor(value = "rows")
int getRows();
@Accessor(value = "mapDataBytes")
byte[] getMapDataBytes();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.lambda.mixin.accessor.network;

import net.minecraft.network.play.server.SPacketWorldBorder;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(value = SPacketWorldBorder.class)
public interface AccessorSPacketWorldBorder {
@Accessor(value = "action")
SPacketWorldBorder.Action getAction();
@Accessor(value = "size")
int getSize();
@Accessor(value = "centerX")
double getCenterX();
@Accessor(value = "centerZ")
double getCenterZ();
@Accessor(value = "targetSize")
double getTargetSize();
@Accessor(value = "diameter")
double getDiameter();
@Accessor(value = "timeUntilTarget")
long getTimeUntilTarget();
@Accessor(value = "warningTime")
int getWarningTime();
@Accessor(value = "warningDistance")
int getWarningDistance();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.lambda.client.gui.hudgui.elements.misc

import com.lambda.client.event.SafeClientEvent
import com.lambda.client.gui.hudgui.LabelHud
import com.lambda.client.module.modules.player.PacketLogger
import java.util.*

internal object PacketLogViewer: LabelHud(
name = "PacketLogViewer",
category = Category.MISC,
description = "Displays the packet log"
) {

private val maxLines by setting("Max Lines", 50, 1..200, 1)
private val logs: MutableList<String> = Collections.synchronizedList(mutableListOf())
private val onlyWhenLoggerEnabled by setting("Only When Logger Enabled", true)
private val clearButton by setting("Clear", false, consumer = { _, _ ->
clear()
false
})

init {
visibleSetting.valueListeners.add { _, it ->
if (!it) {
clear()
}
}
}

override fun SafeClientEvent.updateText() {
displayText.clear()
if (onlyWhenLoggerEnabled && PacketLogger.isDisabled) return
if (logs.isNotEmpty() && (PacketLogger.logMode == PacketLogger.LogMode.ALL || PacketLogger.logMode == PacketLogger.LogMode.ONLY_HUD)) {
displayText.addLine("PacketLog Viewer", secondaryColor)
synchronized(logs) {
logs.forEach { log ->
displayText.addLine(log, primaryColor)
}
}
}
}

fun addPacketLog(log: String) {
synchronized(logs) {
logs.add(log)
if (logs.size > maxLines) {
logs.removeAt(0)
}
}
}

fun clear() {
synchronized(logs) {
logs.clear()
}
}
}
62 changes: 56 additions & 6 deletions src/main/kotlin/com/lambda/client/mixin/extension/Network.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
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
import net.minecraft.world.storage.MapDecoration
import java.util.*

var CPacketChatMessage.chatMessage: String
get() = this.message
set(value) {
(this as AccessorCPacketChatMessage).setMessage(value)
}
val CPacketClientSettings.view: Int
get() = (this as AccessorCPacketClientSettings).view

val CPacketCloseWindow.windowID: Int
get() = (this as AccessorCPacketCloseWindow).kbGetWindowID()

val CPacketConfirmTransaction.accepted: Boolean
get() = (this as AccessorCPacketConfirmTransaction).accepted

var CPacketPlayer.playerX: Double
get() = this.getX(0.0)
Expand Down Expand Up @@ -66,6 +68,15 @@ var CPacketPlayer.playerRotating: Boolean
(this as AccessorCPacketPlayer).rotating = value
}

val CPacketPlayerAbilities.flySpeed: Float
get() = (this as AccessorCPacketPlayerAbilities).flySpeed
val CPacketPlayerAbilities.walkSpeed: Float
get() = (this as AccessorCPacketPlayerAbilities).walkSpeed
val CPacketResourcePackStatus.action: CPacketResourcePackStatus.Action
get() = (this as AccessorCPacketResourcePackStatus).action
val CPacketSpectate.uuid: UUID
get() = (this as AccessorCPacketSpectate).id

var CPacketUseEntity.useEntityId: Int
get() = (this as AccessorCPacketUseEntity).id
set(value) {
Expand All @@ -84,6 +95,9 @@ var SPacketChat.textComponent: ITextComponent
(this as AccessorSPacketChat).setChatComponent(value)
}

val SPacketCloseWindow.windowId: Int
get() = (this as AccessorSPacketCloseWindow).windowId

var SPacketEntityVelocity.entityVelocityMotionX: Int
get() = this.motionX
set(value) {
Expand Down Expand Up @@ -120,6 +134,23 @@ var SPacketExplosion.explosionMotionZ: Float
(this as AccessorSPacketExplosion).setMotionZ(value)
}

val SPacketMaps.mapScale: Byte
get() = (this as AccessorSPacketMaps).mapScale
val SPacketMaps.trackingPosition: Boolean
get() = (this as AccessorSPacketMaps).trackingPosition
val SPacketMaps.icons: Array<MapDecoration>
get() = (this as AccessorSPacketMaps).icons
val SPacketMaps.minX: Int
get() = (this as AccessorSPacketMaps).minX
val SPacketMaps.minZ: Int
get() = (this as AccessorSPacketMaps).minZ
val SPacketMaps.columns: Int
get() = (this as AccessorSPacketMaps).columns
val SPacketMaps.rows: Int
get() = (this as AccessorSPacketMaps).rows
val SPacketMaps.mapDataBytes: ByteArray
get() = (this as AccessorSPacketMaps).mapDataBytes

var SPacketPlayerPosLook.playerPosLookYaw: Float
get() = this.yaw
set(value) {
Expand All @@ -142,4 +173,23 @@ var SPacketEntityHeadLook.entityHeadLookEntityId: Int
get() = (this as AccessorSPacketEntityHeadLook).entityId
set(value) {
(this as AccessorSPacketEntityHeadLook).entityId = value
}
}

val SPacketWorldBorder.action: SPacketWorldBorder.Action
get() = (this as AccessorSPacketWorldBorder).action
val SPacketWorldBorder.size: Int
get() = (this as AccessorSPacketWorldBorder).size
val SPacketWorldBorder.centerX: Double
get() = (this as AccessorSPacketWorldBorder).centerX
val SPacketWorldBorder.centerZ: Double
get() = (this as AccessorSPacketWorldBorder).centerZ
val SPacketWorldBorder.targetSize: Double
get() = (this as AccessorSPacketWorldBorder).targetSize
val SPacketWorldBorder.diameter: Double
get() = (this as AccessorSPacketWorldBorder).diameter
val SPacketWorldBorder.timeUntilTarget: Long
get() = (this as AccessorSPacketWorldBorder).timeUntilTarget
val SPacketWorldBorder.warningTime: Int
get() = (this as AccessorSPacketWorldBorder).warningTime
val SPacketWorldBorder.warningDistance: Int
get() = (this as AccessorSPacketWorldBorder).warningDistance
Loading