177 lines
7.7 KiB
Diff
177 lines
7.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cryptite <cryptite@gmail.com>
|
|
Date: Fri, 12 Aug 2022 10:48:03 -0500
|
|
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 37e193f57938047c8b886ed7d2816411392f94b4..e37c72e90e53908cb2f529265df54c22a692219a 100644
|
|
--- a/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
+++ b/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
@@ -135,6 +135,11 @@ public class SynchedEntityData {
|
|
}
|
|
|
|
public <T> void set(EntityDataAccessor<T> key, T value) {
|
|
+ //Slice start
|
|
+ set(key, value, null);
|
|
+ }
|
|
+
|
|
+ public <T> void set(EntityDataAccessor<T> key, T value, @Nullable T foreignValue) { // Slice end
|
|
SynchedEntityData.DataItem<T> datawatcher_item = this.getItem(key);
|
|
|
|
if (ObjectUtils.notEqual(value, datawatcher_item.getValue())) {
|
|
@@ -144,6 +149,11 @@ public class SynchedEntityData {
|
|
this.isDirty = true;
|
|
}
|
|
|
|
+ // Slice start
|
|
+ if (foreignValue != null && ObjectUtils.notEqual(foreignValue, datawatcher_item.getForeignValue())) {
|
|
+ datawatcher_item.setForeignValue(foreignValue);
|
|
+ }
|
|
+ // Slice end
|
|
}
|
|
|
|
// CraftBukkit start - add method from above
|
|
@@ -185,6 +195,25 @@ public class SynchedEntityData {
|
|
return list;
|
|
}
|
|
|
|
+ // Slice start
|
|
+ @Nullable
|
|
+ public List<SynchedEntityData.DataValue<?>> packForeignDirty() {
|
|
+ List<SynchedEntityData.DataValue<?>> list = null;
|
|
+ for (DataItem<?> dataItem : this.itemsById.values()) {
|
|
+ if (dataItem.isDirty(true)) {
|
|
+ dataItem.setForeignDirty(false);
|
|
+ if (list == null) {
|
|
+ list = new ArrayList();
|
|
+ }
|
|
+
|
|
+ list.add(dataItem.value());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return list;
|
|
+ }
|
|
+ // Slice end
|
|
+
|
|
@Nullable
|
|
public List<SynchedEntityData.DataValue<?>> getNonDefaultValues() {
|
|
List<SynchedEntityData.DataValue<?>> list = null;
|
|
@@ -291,11 +320,14 @@ public class SynchedEntityData {
|
|
T value;
|
|
private final T initialValue;
|
|
private boolean dirty;
|
|
+ @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() {
|
|
@@ -325,6 +357,35 @@ public class SynchedEntityData {
|
|
public SynchedEntityData.DataValue<T> value() {
|
|
return SynchedEntityData.DataValue.create(this.accessor, this.value);
|
|
}
|
|
+
|
|
+ // Slice start
|
|
+ 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;
|
|
+ }
|
|
+
|
|
+ public SynchedEntityData.DataItem<T> copy(boolean foreign) {
|
|
+ return new SynchedEntityData.DataItem<>(this.accessor, this.accessor.getSerializer().copy((foreign && this.foreignValue != null ? this.foreignValue : this.value)));
|
|
+ }
|
|
+ // Slice end
|
|
}
|
|
|
|
public static record DataValue<T>(int id, EntityDataSerializer<T> serializer, T value) { // CraftBukkit - decompile error
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
index 190e9761087baec5827d722a8281f0ffb6798341..6d5a3bf7f93ea96d8615aaab2f88c40f524aa888 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
@@ -367,7 +367,20 @@ public class ServerEntity {
|
|
|
|
if (list != null) {
|
|
this.trackedDataValues = datawatcher.getNonDefaultValues();
|
|
- 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) {
|
|
+ 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 127b87e687a5dcfb6dcdc09e9efc08114933e91b..282cee03458ce6fa16896d988ac4d1dc887e5501 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -3129,7 +3129,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
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 2ebb2e95241caf0393ed5db8f02776f566b88960..8b27a118c28baaaf4356174dd55351982560b548 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -637,7 +637,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) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index b32f44beab2c9790ee2da8403e362e8b3ecc6175..2c3b361d604b30cc114ecaa9874bc1f6cdcae22a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -2323,7 +2323,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 = getMaxHealth();
|
|
}
|