mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 08:19:26 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@1e7dd72 Remove 'fix Vanilla Minecart speed' patch (#10068) PaperMC/Paper@e7e1c8a Fix and add new scoreboard API (#10037) PaperMC/Paper@49f9f6f Add Registry#getKey (#10066) PaperMC/Paper@4adca3d Update to adventure 4.15 (#10045) PaperMC/Paper@ff7b9b0 Increase default custom payload channel size limit (#10006) PaperMC/Paper@1cda66e Hotfix Entity isInRain reobf issue PaperMC/Paper@61768e0 [ci skip] Remove no longer needed mappings change PaperMC/Paper@e035fd7 Updated Upstream (Bukkit/CraftBukkit/Spigot) PaperMC/Paper@c215ce1 [ci skip] cleanup patch diff from last commit PaperMC/Paper@4fdda9e Keep newlines in outdated client/server message (#10042) PaperMC/Paper@f483b38 fix NPE on EntityTeleportEvent getTo (#10016) PaperMC/Paper@dc62150 Catch async usage of playsound (#10021) PaperMC/Paper@0d6a0c3 Fix command block async message (again) (#10082) PaperMC/Paper@d1f507f Don't fire 2 game events for certain cauldron interactions (#8904) PaperMC/Paper@a401585 Fix campfire recipes not always outputting full result (#8754) PaperMC/Paper@88d28d6 Fix long loading screen when refreshing skins (#10026) PaperMC/Paper@c081104 Add experience points api (#9688) PaperMC/Paper@8221b08 Fix global sound event gamerule not being respected (#8727) PaperMC/Paper@3c0d6aa Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10085) PaperMC/Paper@2c3ccb8 Add drops to shear events (#5678) PaperMC/Paper@b2ffb1b Add PlayerShieldDisableEvent (#9177) PaperMC/Paper@2951732 Add HiddenPotionEffect API (#9910) PaperMC/Paper@e4ab50d Properly disallow async Player#chat (#8123) PaperMC/Paper@5e978d3 Fix Folia scheduler tasks not canceling when plugin disable (#10091) PaperMC/Paper@e56e53f Fix some component bugs in login disconnect packet (#10090) PaperMC/Paper@3484ae9 Call entity_die game event after event cancel check (#10096) PaperMC/Paper@0ae58c0 cleanup player death event adventure logic (#10095) PaperMC/Paper@1281f4f Make region/lock shift accessors per world PaperMC/Paper@983377b Correctly check if bucket dispenses will succeed for event (#10109) PaperMC/Paper@58e120b [ci skip] Remove extraneous diff added in 1.20.3 update (#10101) PaperMC/Paper@816bacc Call EntityChangeBlockEvent for cake eating (#10105) PaperMC/Paper@692db0c fix CustomModelData being removed (#10113) PaperMC/Paper@509876d Keep fully frozen entities fully activated (#10103) PaperMC/Paper@1fa48d1 include relative flags in PlayerTeleportEvent (#8190) PaperMC/Paper@ae001ae Fix untrack event not being called for all 'untracks' (#10110) PaperMC/Paper@259bc76 Pass system properties to maven repo session (#10117) PaperMC/Paper@b2a6d57 Validate ResourceLocation in NBT reading PaperMC/Paper@7eaff48 [ci skip] Replace some magic values with constant references PaperMC/Paper@19a6202 Fix experience & improvements to block events (#8067) PaperMC/Paper@8379027 Fix cmd permission levels for command blocks (#7404) PaperMC/Paper@a93acc4 Fix EntityChangePoseEvent being called during worldgen (#10120) PaperMC/Paper@25a99b1 Fix BlockDestroyEvents effectBlock not being set (#10131) PaperMC/Paper@a58e29d Fix a borked update of 'Properly handle BlockBreakEvent#isDropItems' (#10134) PaperMC/Paper@570cfb4 Validate missed resource location parsing PaperMC/Paper@e46276e Fixup NamespacedKey parsing PaperMC/Paper@f1c5f01 [ci skip] Fix typo PaperMC/Paper@07b956e Fix tests by disabling them
257 lines
11 KiB
Diff
257 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cryptite <cryptite@gmail.com>
|
|
Date: Wed, 6 Oct 2021 11:03:01 -0500
|
|
Subject: [PATCH] (Slice) Packet obfuscation and reduction
|
|
|
|
Minecraft is overzealous about packet updates for Entities. In Loka's case, we want to reduce as many unnecessary
|
|
packet updates as possible. This patch is likely to be updated over and over in terms of reducing packet sends.
|
|
|
|
In summary, this patch creates the concept of a "foreignValue" of a packet's data. We treat packets in two ways:
|
|
1) The packet sent to the player itself (the normal way). This always has all of the values as usual.
|
|
2) The packet data as seen by any other (foreign) players.
|
|
|
|
This patch adds the ability to set a "foreignValue" for an entity value so as to obfuscate data received by other players.
|
|
The current packets modified/obfuscated are the following:
|
|
|
|
# This reduces the amount of health packet updates as well which is great for players in combat.
|
|
|
|
# Air level packets are sent PER-TICK, and as such a player with any change in air level will only spam themselves
|
|
# with packets instead of every single player within tracking distance
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java b/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
index a043c382c37058032548a5192e17f5f816abe5a6..8e84afc92bef8192320dfe405609bf06ff0f9e15 100644
|
|
--- a/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
+++ b/src/main/java/net/minecraft/network/syncher/SynchedEntityData.java
|
|
@@ -39,6 +39,7 @@ public class SynchedEntityData {
|
|
private static final int GROW_FACTOR = 8;
|
|
private SynchedEntityData.DataItem<?>[] itemsArray = new SynchedEntityData.DataItem<?>[DEFAULT_ENTRY_COUNT];
|
|
// Paper end
|
|
+ private boolean isForeignDirty; // Slice
|
|
|
|
public SynchedEntityData(Entity trackedEntity) {
|
|
this.entity = trackedEntity;
|
|
@@ -165,6 +166,16 @@ public class SynchedEntityData {
|
|
}
|
|
|
|
public <T> void set(EntityDataAccessor<T> key, T value, boolean force) {
|
|
+ // Slice start
|
|
+ this.set(key, value, null, force);
|
|
+ }
|
|
+
|
|
+ public <T> void set(EntityDataAccessor<T> key, T value, T foreignValue) {
|
|
+ this.set(key, value, foreignValue, false);
|
|
+ }
|
|
+
|
|
+ public <T> void set(EntityDataAccessor<T> key, T value, T foreignValue, boolean force) {
|
|
+ // Slice end
|
|
SynchedEntityData.DataItem<T> datawatcher_item = this.getItem(key);
|
|
|
|
if (force || ObjectUtils.notEqual(value, datawatcher_item.getValue())) {
|
|
@@ -174,6 +185,12 @@ public class SynchedEntityData {
|
|
this.isDirty = true;
|
|
}
|
|
|
|
+ // Slice start
|
|
+ if (foreignValue != null && ObjectUtils.notEqual(foreignValue, datawatcher_item.getForeignValue())) {
|
|
+ datawatcher_item.setForeignValue(foreignValue);
|
|
+ this.isForeignDirty = true;
|
|
+ }
|
|
+ // Slice end
|
|
}
|
|
|
|
// CraftBukkit start - add method from above
|
|
@@ -183,6 +200,12 @@ public class SynchedEntityData {
|
|
}
|
|
// CraftBukkit end
|
|
|
|
+ // Slice start
|
|
+ public boolean isForeignDirty() {
|
|
+ return this.isForeignDirty;
|
|
+ }
|
|
+ // Slice end
|
|
+
|
|
public boolean isDirty() {
|
|
return this.isDirty;
|
|
}
|
|
@@ -215,6 +238,29 @@ public class SynchedEntityData {
|
|
return list;
|
|
}
|
|
|
|
+ // Slice start
|
|
+ @Nullable
|
|
+ public List<SynchedEntityData.DataValue<?>> packForeignDirty(List<DataValue<?>> unpackedData) {
|
|
+ List<SynchedEntityData.DataValue<?>> list = null;
|
|
+
|
|
+ for (DataValue<?> dataItem : unpackedData) {
|
|
+ DataItem<?> item = itemsById.get(dataItem.id());
|
|
+ if (item.isDirty(true)) {
|
|
+ item.setForeignDirty(false);
|
|
+
|
|
+ if (list == null) {
|
|
+ list = new ArrayList<>();
|
|
+ }
|
|
+
|
|
+ list.add(item.copy(true));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ this.isForeignDirty = false;
|
|
+ return list;
|
|
+ }
|
|
+ // Slice end
|
|
+
|
|
@Nullable
|
|
public List<SynchedEntityData.DataValue<?>> getNonDefaultValues() {
|
|
List<SynchedEntityData.DataValue<?>> list = null;
|
|
@@ -339,11 +385,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() {
|
|
@@ -370,6 +419,35 @@ public class SynchedEntityData {
|
|
return this.initialValue.equals(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.DataValue<T> copy(boolean foreign) {
|
|
+ return SynchedEntityData.DataValue.create(this.accessor, this.accessor.getSerializer().copy((foreign && this.foreignValue != null ? this.foreignValue : this.value)));
|
|
+ }
|
|
+ // Slice end
|
|
+
|
|
public SynchedEntityData.DataValue<T> value() {
|
|
return SynchedEntityData.DataValue.create(this.accessor, this.value);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
index 83c4639c2bdca4dc4281d9f5eca104af3063bfa5..f7d8aaededd39ce52a9d0105f66fd759635b5288 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
@@ -148,7 +148,7 @@ public class ServerEntity {
|
|
}
|
|
}
|
|
|
|
- if (this.tickCount % this.updateInterval == 0 || this.entity.hasImpulse || this.entity.getEntityData().isDirty()) {
|
|
+ if (this.tickCount % this.updateInterval == 0 || this.entity.hasImpulse || this.entity.getEntityData().isForeignDirty()) { // Slice
|
|
int i;
|
|
int j;
|
|
|
|
@@ -395,11 +395,23 @@ public class ServerEntity {
|
|
}
|
|
|
|
// Sakura start - visibility api
|
|
- private void broadcastEntityData(List<SynchedEntityData.DataValue<?>> packedValues) {
|
|
+ private void broadcastEntityData(SynchedEntityData datawatcher, List<SynchedEntityData.DataValue<?>> packedValues) {
|
|
Packet<?> packet0 = new ClientboundSetEntityDataPacket(this.entity.getId(), packedValues);
|
|
Packet<?> packet1 = null;
|
|
|
|
- if (this.entity.isPrimedTNT) {
|
|
+ // Slice start
|
|
+ if (this.entity instanceof ServerPlayer serverPlayer) {
|
|
+ serverPlayer.connection.send(packet0);
|
|
+ }
|
|
+
|
|
+ packedValues = datawatcher.packForeignDirty(packedValues);
|
|
+
|
|
+ if (packedValues != null) {
|
|
+ packet0 = new ClientboundSetEntityDataPacket(this.entity.getId(), packedValues);
|
|
+ }
|
|
+
|
|
+ if (packedValues != null && this.entity.isPrimedTNT) {
|
|
+ // Slice end
|
|
var copyOfDirtyItems = Lists.newArrayList(packedValues);
|
|
copyOfDirtyItems.removeIf((data) -> data.id() == 8);
|
|
|
|
@@ -426,7 +438,7 @@ public class ServerEntity {
|
|
|
|
if (list != null) {
|
|
this.trackedDataValues = datawatcher.getNonDefaultValues();
|
|
- this.broadcastEntityData(list); // Sakura - visibility api
|
|
+ this.broadcastEntityData(datawatcher, list); // Sakura - visibility api
|
|
}
|
|
|
|
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 218866882e3b08b1eb46b2a286bc7fe480db9c74..7fad22ee8a24399acbae6a9bc07ad5de39d41020 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -3399,7 +3399,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
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/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
index 1a018e1d2b6dd93be5e6209a2d52eade0b356f58..0cf39ea76902e62b712057fe1bb80e3af8190fc4 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -110,7 +110,7 @@ public class FallingBlockEntity extends Entity {
|
|
}
|
|
|
|
public void setStartPos(BlockPos pos) {
|
|
- this.entityData.set(FallingBlockEntity.DATA_START_POS, pos);
|
|
+ this.entityData.set(FallingBlockEntity.DATA_START_POS, pos, BlockPos.ZERO); // Slice
|
|
}
|
|
|
|
public BlockPos getStartPos() {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
index 0be7c39fbb19a0cdca3f5dc779c2690df5f08647..cc30c119f519e7cd947ab40beae56e493e977176 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -196,7 +196,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
}
|
|
|
|
public void setFuse(int fuse) {
|
|
- this.entityData.set(PrimedTnt.DATA_FUSE_ID, fuse);
|
|
+ this.entityData.set(PrimedTnt.DATA_FUSE_ID, fuse, (fuse / 10) * 10); // Slice
|
|
}
|
|
|
|
public int getFuse() {
|
|
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 ccc1caafb0ada52c7b99b7358253826f5390843e..ad8114246633498c22d615f1bc669ea83f97c930 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -644,7 +644,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) {
|