fix entity ids

This commit is contained in:
Sen 2025-06-04 17:01:09 +02:00
parent a429447754
commit ff1006c73c
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
6 changed files with 50 additions and 35 deletions

View file

@ -71,7 +71,7 @@ public class LoginHandler implements Handler {
ProxyHandler handler = new ProxyHandler(this.proxy, this.connection, this.username);
this.connection.setNetHandler(handler);
this.connection.sendPacket(new R02PacketLoginSuccess(Proxy.getOfflineUUID(this.username), this.username));
handler.setupPlayer();
handler.setupPlayer(0x7fffff00);
}
public void onDisconnect(Connection connection, String reason) {

View file

@ -67,11 +67,12 @@ public class ProxyHandler extends User implements Handler {
private long lastSentPingPacket;
private volatile boolean connecting;
private volatile boolean connected;
private volatile boolean joined;
private int passwordAttempts;
private boolean wasClosed;
private volatile int signPreloaded;
private String completion;
private int spoofedId = -1;
private int realId = -1;
private static boolean isAllowedChar(char ch) {
return ch != 167 && ch >= 32 && ch != 127;
@ -106,8 +107,9 @@ public class ProxyHandler extends User implements Handler {
return this.username;
}
public void setupPlayer() {
this.sendToClient(new S01PacketJoinGame(0, true));
public void setupPlayer(int id) {
this.spoofedId = id;
this.sendToClient(new S01PacketJoinGame(id, true));
this.sendToClient(new S03PacketTimeUpdate(3000L, false));
this.sendToClient(new S26PacketMapChunkBulk(0, 64, 0));
this.sendToClient(new S08PacketPlayerPosLook(0.5, 65.0, 0.5, 0.0f, 0.0f));
@ -482,12 +484,12 @@ public class ProxyHandler extends User implements Handler {
public void processEntityAction(C0BPacketEntityAction packetIn) {
if(this.connected)
this.sendToServer(packetIn);
this.sendToServer(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void processUseEntity(C02PacketUseEntity packetIn) {
if(this.connected)
this.sendToServer(packetIn);
this.sendToServer(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void processClientStatus(C16PacketClientStatus packetIn) {
@ -649,12 +651,9 @@ public class ProxyHandler extends User implements Handler {
}
public void handleJoinGame(S01PacketJoinGame packetIn) {
this.sendToClient(packetIn);
if(!this.joined) {
this.joined = true;
this.sendToClient(new S07PacketRespawn(packetIn));
this.sendToClient(new S2EPacketCloseWindow());
}
this.realId = packetIn.getEntityId();
this.sendToClient(new S07PacketRespawn(packetIn));
// this.sendToClient(new S2EPacketCloseWindow());
}
public void handleSetCompressionLevel(S46PacketSetCompressionLevel packetIn) {
@ -682,19 +681,19 @@ public class ProxyHandler extends User implements Handler {
}
public void handleEntityVelocity(S12PacketEntityVelocity packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleEntityMetadata(S1CPacketEntityMetadata packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleSpawnPlayer(S0CPacketSpawnPlayer packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleEntityTeleport(S18PacketEntityTeleport packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleHeldItemChange(S09PacketHeldItemChange packetIn) {
@ -702,11 +701,11 @@ public class ProxyHandler extends User implements Handler {
}
public void handleEntityMovement(S14PacketEntity packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleEntityHeadLook(S19PacketEntityHeadLook packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleDestroyEntities(S13PacketDestroyEntities packetIn) {
@ -730,7 +729,7 @@ public class ProxyHandler extends User implements Handler {
}
public void handleCollectItem(S0DPacketCollectItem packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleChat(S02PacketChat packetIn) {
@ -738,11 +737,11 @@ public class ProxyHandler extends User implements Handler {
}
public void handleAnimation(S0BPacketAnimation packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleUseBed(S0APacketUseBed packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleSpawnMob(S0FPacketSpawnMob packetIn) {
@ -758,11 +757,11 @@ public class ProxyHandler extends User implements Handler {
}
public void handleEntityAttach(S1BPacketEntityAttach packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleEntityStatus(S19PacketEntityStatus packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleUpdateHealth(S06PacketUpdateHealth packetIn) {
@ -814,7 +813,7 @@ public class ProxyHandler extends User implements Handler {
}
public void handleEntityEquipment(S04PacketEntityEquipment packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleCloseWindow(S2EPacketCloseWindow packetIn) {
@ -826,7 +825,7 @@ public class ProxyHandler extends User implements Handler {
}
public void handleBlockBreakAnim(S25PacketBlockBreakAnim packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleMapChunkBulk(S26PacketMapChunkBulk packetIn) {
@ -850,7 +849,7 @@ public class ProxyHandler extends User implements Handler {
}
public void handleEntityEffect(S1DPacketEntityEffect packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleCombatEvent(S42PacketCombatEvent packetIn) {
@ -862,7 +861,7 @@ public class ProxyHandler extends User implements Handler {
}
public void handleCamera(S43PacketCamera packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleWorldBorder(S44PacketWorldBorder packetIn) {
@ -878,7 +877,7 @@ public class ProxyHandler extends User implements Handler {
}
public void handleRemoveEntityEffect(S1EPacketRemoveEntityEffect packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handlePlayerListItem(S38PacketPlayerListItem packetIn) {
@ -898,7 +897,7 @@ public class ProxyHandler extends User implements Handler {
}
public void handleEntityNBT(S49PacketUpdateEntityNBT packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
public void handleCustomPayload(S3FPacketCustomPayload packetIn) {
@ -926,6 +925,6 @@ public class ProxyHandler extends User implements Handler {
}
public void handleEntityProperties(S20PacketEntityProperties packetIn) {
this.sendToClient(packetIn);
this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId));
}
}

View file

@ -1,10 +1,14 @@
package proxy.packet;
public class EntityIdPacketClient {
import proxy.network.Packet;
import proxy.network.ProxyHandler;
public abstract class EntityIdPacketClient implements Packet<ProxyHandler> {
protected int entityId;
public void replaceEntityId(int real, int spoofed) {
public Packet replaceEntityId(int real, int spoofed) {
if(this.entityId == real)
this.entityId = spoofed;
return this;
}
}

View file

@ -1,10 +1,14 @@
package proxy.packet;
public class EntityIdPacketServer {
import proxy.network.Packet;
import proxy.network.ProxyHandler;
public abstract class EntityIdPacketServer implements Packet<ProxyHandler> {
protected int entityId;
public void replaceEntityId(int real, int spoofed) {
public Packet replaceEntityId(int real, int spoofed) {
if(this.entityId == spoofed)
this.entityId = real;
return this;
}
}

View file

@ -10,6 +10,13 @@ public class S0DPacketCollectItem extends EntityIdPacketClient implements Packet
{
private int collectedItemEntityId;
public Packet replaceEntityId(int real, int spoofed) {
super.replaceEntityId(real, spoofed);
if(this.collectedItemEntityId == real)
this.collectedItemEntityId = spoofed;
return this;
}
/**
* Reads the raw packet data from the data stream.
*/

View file

@ -11,10 +11,11 @@ public class S1BPacketEntityAttach extends EntityIdPacketClient implements Packe
private int leash;
private int vehicleEntityId;
public void replaceEntityId(int real, int spoofed) {
public Packet replaceEntityId(int real, int spoofed) {
super.replaceEntityId(real, spoofed);
if(this.vehicleEntityId == real)
this.vehicleEntityId = spoofed;
return this;
}
/**