186 lines
8.1 KiB
Diff
186 lines
8.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cryptite <cryptite@gmail.com>
|
|
Date: Sat, 16 Nov 2024 09:26:55 -0600
|
|
Subject: [PATCH] Packet obfuscation and reduction
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java b/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
index 0f99733660f91280e4c6262cf75b3c9cae86f65a..8845497071ca3be0e439b454f1f2d14f0f74e842 100644
|
|
--- a/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
+++ b/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
@@ -63,15 +63,29 @@ public class SynchedEntityData {
|
|
}
|
|
|
|
public <T> void set(EntityDataAccessor<T> key, T value, boolean force) {
|
|
+ // Slice start
|
|
+ this.set(key, value, force, null);
|
|
+ }
|
|
+
|
|
+ public <T> void set(EntityDataAccessor<T> key, T value, @Nullable T foreignValue) {
|
|
+ this.set(key, value, false, foreignValue);
|
|
+ }
|
|
+
|
|
+ public <T> void set(EntityDataAccessor<T> key, T value, boolean force, @Nullable T foreignValue) { // Slice end
|
|
SynchedEntityData.DataItem<T> datawatcher_item = this.getItem(key);
|
|
|
|
+ // Slice start
|
|
+ if (foreignValue != null && ObjectUtils.notEqual(foreignValue, datawatcher_item.getForeignValue())) {
|
|
+ datawatcher_item.setForeignValue(foreignValue);
|
|
+ }
|
|
+ // Slice end
|
|
+
|
|
if (force || ObjectUtils.notEqual(value, datawatcher_item.getValue())) {
|
|
datawatcher_item.setValue(value);
|
|
this.entity.onSyncedDataUpdated(key);
|
|
datawatcher_item.setDirty(true);
|
|
this.isDirty = true;
|
|
}
|
|
-
|
|
}
|
|
|
|
// CraftBukkit start - add method from above
|
|
@@ -108,6 +122,26 @@ public class SynchedEntityData {
|
|
}
|
|
}
|
|
|
|
+ // Slice start
|
|
+ @Nullable
|
|
+ public List<SynchedEntityData.DataValue<?>> packForeignDirty() {
|
|
+ List<SynchedEntityData.DataValue<?>> list = null;
|
|
+
|
|
+ for (DataItem<?> dataItem : this.itemsById) {
|
|
+ if (dataItem.isDirty(true)) {
|
|
+ dataItem.setForeignDirty(false);
|
|
+ if (list == null) {
|
|
+ list = new ArrayList();
|
|
+ }
|
|
+
|
|
+ list.add(dataItem.foreignValue != null ? dataItem.foreignValue() : dataItem.value());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return list;
|
|
+ }
|
|
+ // Slice end
|
|
+
|
|
@Nullable
|
|
public List<SynchedEntityData.DataValue<?>> getNonDefaultValues() {
|
|
List<SynchedEntityData.DataValue<?>> list = null;
|
|
@@ -171,11 +205,14 @@ public class SynchedEntityData {
|
|
T value;
|
|
private final T initialValue;
|
|
private boolean dirty;
|
|
+ private @Nullable T foreignValue = null; // Slice
|
|
+ private boolean foreignDirty; // Slice
|
|
|
|
public DataItem(EntityDataAccessor<T> data, T value) {
|
|
this.accessor = data;
|
|
this.initialValue = value;
|
|
this.value = value;
|
|
+ this.foreignDirty = true; //Slice
|
|
}
|
|
|
|
public EntityDataAccessor<T> getAccessor() {
|
|
@@ -205,6 +242,36 @@ public class SynchedEntityData {
|
|
public SynchedEntityData.DataValue<T> value() {
|
|
return SynchedEntityData.DataValue.create(this.accessor, this.value);
|
|
}
|
|
+
|
|
+
|
|
+ // Slice start
|
|
+ public SynchedEntityData.DataValue<T> foreignValue() {
|
|
+ return SynchedEntityData.DataValue.create(this.accessor, this.foreignValue);
|
|
+ }
|
|
+
|
|
+ public void setForeignValue(T foreignValue) {
|
|
+ this.foreignValue = foreignValue;
|
|
+ this.foreignDirty = true;
|
|
+ }
|
|
+
|
|
+ public @Nullable T getForeignValue() {
|
|
+ return foreignValue;
|
|
+ }
|
|
+
|
|
+ public boolean isDirty(boolean foreign) {
|
|
+ if (foreign) {
|
|
+ //There must be a foreign value in order for this to be dirty, otherwise we consider this a normal
|
|
+ //value and check the normal dirty flag.
|
|
+ return foreignValue == null || this.foreignDirty;
|
|
+ }
|
|
+
|
|
+ return this.dirty;
|
|
+ }
|
|
+
|
|
+ public void setForeignDirty(boolean dirty) {
|
|
+ this.foreignDirty = dirty;
|
|
+ }
|
|
+ // Slice end
|
|
}
|
|
|
|
public static record DataValue<T>(int id, EntityDataSerializer<T> serializer, T value) {
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
index 90eb4927fa51ce3df86aa7b6c71f49150a03e337..357f1d375cd92ce73516c6baceffe8dd89b9e499 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
@@ -449,7 +449,20 @@ public class ServerEntity {
|
|
|
|
if (list != null) {
|
|
this.trackedDataValues = datawatcher.getNonDefaultValues();
|
|
- this.broadcastAndSend(new ClientboundSetEntityDataPacket(this.entity.getId(), list));
|
|
+// this.broadcastAndSend(new ClientboundSetEntityDataPacket(this.entity.getId(), list));
|
|
+ // Slice start
|
|
+ ClientboundSetEntityDataPacket dataPacket = new ClientboundSetEntityDataPacket(this.entity.getId(), list);
|
|
+ if (this.entity instanceof ServerPlayer serverPlayer) {
|
|
+ serverPlayer.connection.send(dataPacket);
|
|
+ }
|
|
+
|
|
+ //Get the packedData that the original packet has, and then determine if any of those are changed in
|
|
+ //the foreign version. If null, nothing to notify foreign trackers about.
|
|
+ List<SynchedEntityData.DataValue<?>> dirtyItems = datawatcher.packForeignDirty();
|
|
+ if (dirtyItems != null) {
|
|
+ this.broadcast.accept(new ClientboundSetEntityDataPacket(this.entity.getId(), dirtyItems));
|
|
+ }
|
|
+ // Slice end
|
|
}
|
|
|
|
if (this.entity instanceof LivingEntity) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 77cc9ae3f5d71454c3b75c44cf53bcfbc5f3eb84..a46df2ccbae85cdbdb7a19825a89c1797337d270 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -3670,7 +3670,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
this.entityData.markDirty(Entity.DATA_AIR_SUPPLY_ID);
|
|
return;
|
|
}
|
|
- this.entityData.set(Entity.DATA_AIR_SUPPLY_ID, event.getAmount());
|
|
+ this.entityData.set(Entity.DATA_AIR_SUPPLY_ID, event.getAmount(), getMaxAirSupply()); // Slice
|
|
// CraftBukkit end
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
index 551da84c834132d106457c123e1b195e4be904b8..e4041c58a23d3eaefd01402635f714404f3c82cf 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -676,7 +676,7 @@ public abstract class Player extends LivingEntity {
|
|
public void increaseScore(int score) {
|
|
int j = this.getScore();
|
|
|
|
- this.entityData.set(Player.DATA_SCORE_ID, j + score);
|
|
+ this.entityData.set(Player.DATA_SCORE_ID, j + score, 0); // Slice
|
|
}
|
|
|
|
public void startAutoSpinAttack(int riptideTicks, float riptideAttackDamage, ItemStack stack) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index adf8f0ddde16f08b10cd733eeabf9d40db77001b..c92c59d18a218b8b34b94dca874291d0f95a678a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -2864,7 +2864,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
this.sendHealthUpdate();
|
|
}
|
|
}
|
|
- this.getHandle().getEntityData().set(net.minecraft.world.entity.LivingEntity.DATA_HEALTH_ID, (float) this.getScaledHealth());
|
|
+ this.getHandle().getEntityData().set(net.minecraft.world.entity.LivingEntity.DATA_HEALTH_ID, (float) this.getScaledHealth(), isDead() ? 0f : 20f); // Slice
|
|
|
|
this.getHandle().maxHealthCache = this.getMaxHealth();
|
|
}
|