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); ProxyHandler handler = new ProxyHandler(this.proxy, this.connection, this.username);
this.connection.setNetHandler(handler); this.connection.setNetHandler(handler);
this.connection.sendPacket(new R02PacketLoginSuccess(Proxy.getOfflineUUID(this.username), this.username)); this.connection.sendPacket(new R02PacketLoginSuccess(Proxy.getOfflineUUID(this.username), this.username));
handler.setupPlayer(); handler.setupPlayer(0x7fffff00);
} }
public void onDisconnect(Connection connection, String reason) { public void onDisconnect(Connection connection, String reason) {

View file

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

View file

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

View file

@ -10,6 +10,13 @@ public class S0DPacketCollectItem extends EntityIdPacketClient implements Packet
{ {
private int collectedItemEntityId; 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. * 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 leash;
private int vehicleEntityId; private int vehicleEntityId;
public void replaceEntityId(int real, int spoofed) { public Packet replaceEntityId(int real, int spoofed) {
super.replaceEntityId(real, spoofed); super.replaceEntityId(real, spoofed);
if(this.vehicleEntityId == real) if(this.vehicleEntityId == real)
this.vehicleEntityId = spoofed; this.vehicleEntityId = spoofed;
return this;
} }
/** /**