Skip to content

Commit

Permalink
Reduce unneeded math with reader index, check oldId == newId in versi…
Browse files Browse the repository at this point in the history
…oned EntityMaps
  • Loading branch information
Janmm14 committed Nov 9, 2023
1 parent 6dac2a5 commit 121d38f
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,28 @@ public void rewriteClientbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
int readerIndexAfterPID = packet.readerIndex();
switch ( packetId )
{
case 0x3A /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( wrapper, oldId, newId, readerIndex + packetIdLength + 4 );
rewriteInt( wrapper, oldId, newId, readerIndexAfterPID + 4 );
break;
case 0x48 /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.skipVarInt( packet );
rewriteVarInt( wrapper, oldId, newId, packet.readerIndex() );
break;
case 0x40 /* Attach Entity : PacketPlayOutMount */:
DefinedPacket.skipVarInt( packet );
jumpIndex = packet.readerIndex();
readerIndexAfterPID = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x30 /* Destroy Entities : PacketPlayOutEntityDestroy */:
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, jumpIndex );
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, readerIndexAfterPID );
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
EntityMap_1_9.rewriteSpawnObject( wrapper, oldId, newId );
break;
case 0x05 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex );
break;
case 0x2C /* Combat Event : PacketPlayOutCombatEvent */:
EntityMap_1_8.rewriteCombatEvent( wrapper, oldId, newId );
Expand All @@ -99,11 +98,11 @@ public void rewriteServerbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int readerIndexAfterPID = packet.readerIndex();

if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, readerIndexAfterPID );
}
packet.readerIndex( readerIndex );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,28 @@ public void rewriteClientbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
int readerIndexAfterPID = packet.readerIndex();
switch ( packetId )
{
case 0x3A /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( wrapper, oldId, newId, readerIndex + packetIdLength + 4 );
rewriteInt( wrapper, oldId, newId, readerIndexAfterPID + 4 );
break;
case 0x48 /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.skipVarInt( packet );
rewriteVarInt( wrapper, oldId, newId, packet.readerIndex() );
break;
case 0x40 /* Attach Entity : PacketPlayOutMount */:
DefinedPacket.skipVarInt( packet );
jumpIndex = packet.readerIndex();
readerIndexAfterPID = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x30 /* Destroy Entities : PacketPlayOutEntityDestroy */:
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, jumpIndex );
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, readerIndexAfterPID );
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
EntityMap_1_9.rewriteSpawnObject( wrapper, oldId, newId );
break;
case 0x05 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex );
break;
case 0x2C /* Combat Event : PacketPlayOutCombatEvent */:
EntityMap_1_8.rewriteCombatEvent( wrapper, oldId, newId );
Expand All @@ -100,11 +99,11 @@ public void rewriteServerbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int readerIndexAfterPID = packet.readerIndex();

if ( packetId == 0x1B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, readerIndexAfterPID );
}
packet.readerIndex( readerIndex );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,28 @@ public void rewriteClientbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
int readerIndexAfterPID = packet.readerIndex();
switch ( packetId )
{
case 0x3C /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( wrapper, oldId, newId, readerIndex + packetIdLength + 4 );
rewriteInt( wrapper, oldId, newId, readerIndexAfterPID + 4 );
break;
case 0x4A /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.skipVarInt( packet );
rewriteVarInt( wrapper, oldId, newId, packet.readerIndex() );
break;
case 0x42 /* Attach Entity : PacketPlayOutMount */:
DefinedPacket.skipVarInt( packet );
jumpIndex = packet.readerIndex();
readerIndexAfterPID = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x31 /* Destroy Entities : PacketPlayOutEntityDestroy */:
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, jumpIndex );
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, readerIndexAfterPID );
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
EntityMap_1_9.rewriteSpawnObject( wrapper, oldId, newId );
break;
case 0x05 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex );
break;
case 0x2C /* Combat Event : PacketPlayOutCombatEvent */:
EntityMap_1_8.rewriteCombatEvent( wrapper, oldId, newId );
Expand All @@ -100,11 +99,11 @@ public void rewriteServerbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int readerIndexAfterPID = packet.readerIndex();

if ( packetId == 0x1E /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, readerIndexAfterPID );
}
packet.readerIndex( readerIndex );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,28 @@ public void rewriteClientbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
int readerIndexAfterPID = packet.readerIndex();
switch ( packetId )
{
case 0x3D /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( wrapper, oldId, newId, readerIndex + packetIdLength + 4 );
rewriteInt( wrapper, oldId, newId, readerIndexAfterPID + 4 );
break;
case 0x4B /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.skipVarInt( packet );
rewriteVarInt( wrapper, oldId, newId, packet.readerIndex() );
break;
case 0x43 /* Attach Entity : PacketPlayOutMount */:
DefinedPacket.skipVarInt( packet );
jumpIndex = packet.readerIndex();
readerIndexAfterPID = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x32 /* Destroy Entities : PacketPlayOutEntityDestroy */:
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, jumpIndex );
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, readerIndexAfterPID );
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
EntityMap_1_9.rewriteSpawnObject( wrapper, oldId, newId );
break;
case 0x05 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex );
break;
case 0x2D /* Combat Event : PacketPlayOutCombatEvent */:
EntityMap_1_8.rewriteCombatEvent( wrapper, oldId, newId );
Expand All @@ -100,11 +99,11 @@ public void rewriteServerbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int readerIndexAfterPID = packet.readerIndex();

if ( packetId == 0x1E /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, readerIndexAfterPID );
}
packet.readerIndex( readerIndex );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,28 @@ public void rewriteClientbound(PacketWrapper wrapper, int oldId, int newId, int
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
int readerIndexAfterPID = packet.readerIndex();
switch ( packetId )
{
case 0x40 /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( wrapper, oldId, newId, readerIndex + packetIdLength + 4 );
rewriteInt( wrapper, oldId, newId, readerIndexAfterPID + 4 );
break;
case 0x4F /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.skipVarInt( packet );
rewriteVarInt( wrapper, oldId, newId, packet.readerIndex() );
break;
case 0x46 /* Set Passengers : PacketPlayOutMount */:
DefinedPacket.skipVarInt( packet );
jumpIndex = packet.readerIndex();
readerIndexAfterPID = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x35 /* Destroy Entities : PacketPlayOutEntityDestroy */:
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, jumpIndex );
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, readerIndexAfterPID );
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
EntityMap_1_9.rewriteSpawnObject( wrapper, oldId, newId );
break;
case 0x05 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex );
break;
case 0x2F /* Combat Event : PacketPlayOutCombatEvent */:
EntityMap_1_8.rewriteCombatEvent( wrapper, oldId, newId );
Expand All @@ -100,11 +99,11 @@ public void rewriteServerbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int readerIndexAfterPID = packet.readerIndex();

if ( packetId == 0x28 /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, readerIndexAfterPID );
}
packet.readerIndex( readerIndex );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,28 @@ public void rewriteClientbound(PacketWrapper wrapper, int oldId, int newId, int
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
int readerIndexAfterPID = packet.readerIndex();
switch ( packetId )
{
case 0x44 /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( wrapper, oldId, newId, readerIndex + packetIdLength + 4 );
rewriteInt( wrapper, oldId, newId, readerIndexAfterPID + 4 );
break;
case 0x55 /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.skipVarInt( packet );
rewriteVarInt( wrapper, oldId, newId, packet.readerIndex() );
break;
case 0x4A /* Set Passengers : PacketPlayOutMount */:
DefinedPacket.skipVarInt( packet );
jumpIndex = packet.readerIndex();
readerIndexAfterPID = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x37 /* Destroy Entities : PacketPlayOutEntityDestroy */:
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, jumpIndex );
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, readerIndexAfterPID );
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
rewriteSpawnObject( wrapper, oldId, newId, 2, 101, 71 );
break;
case 0x05 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex );
break;
case 0x32 /* Combat Event : PacketPlayOutCombatEvent */:
EntityMap_1_8.rewriteCombatEvent( wrapper, oldId, newId );
Expand Down Expand Up @@ -104,11 +103,11 @@ public void rewriteServerbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int readerIndexAfterPID = packet.readerIndex();

if ( packetId == 0x2B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, readerIndexAfterPID );
}
packet.readerIndex( readerIndex );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,28 @@ public void rewriteClientbound(PacketWrapper wrapper, int oldId, int newId, int
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int jumpIndex = packet.readerIndex();
int readerIndexAfterPID = packet.readerIndex();
switch ( packetId )
{
case 0x45 /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( wrapper, oldId, newId, readerIndex + packetIdLength + 4 );
rewriteInt( wrapper, oldId, newId, readerIndexAfterPID + 4 );
break;
case 0x56 /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.skipVarInt( packet );
rewriteVarInt( wrapper, oldId, newId, packet.readerIndex() );
break;
case 0x4B /* Set Passengers : PacketPlayOutMount */:
DefinedPacket.skipVarInt( packet );
jumpIndex = packet.readerIndex();
readerIndexAfterPID = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x38 /* Destroy Entities : PacketPlayOutEntityDestroy */:
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, jumpIndex );
EntityMap_1_8.rewriteDestroyEntities( wrapper, oldId, newId, readerIndexAfterPID );
break;
case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */:
EntityMap_1_14.rewriteSpawnObject( wrapper, oldId, newId, 2, 102, 72 );
break;
case 0x05 /* Spawn Player : PacketPlayOutNamedEntitySpawn */:
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpawnPlayerUuid( wrapper, readerIndex );
break;
case 0x33 /* Combat Event : PacketPlayOutCombatEvent */:
EntityMap_1_8.rewriteCombatEvent( wrapper, oldId, newId );
Expand Down Expand Up @@ -104,11 +103,11 @@ public void rewriteServerbound(PacketWrapper wrapper, int oldId, int newId)
// Special cases
int readerIndex = packet.readerIndex();
int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex;
int readerIndexAfterPID = packet.readerIndex();

if ( packetId == 0x2B /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, packetIdLength );
EntityMap_1_8.rewriteSpectateUuid( wrapper, readerIndex, readerIndexAfterPID );
}
packet.readerIndex( readerIndex );
}
Expand Down
Loading

0 comments on commit 121d38f

Please sign in to comment.