9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-19 14:59:30 +00:00
Files
SakuraMC/patches/server/0013-Slice-Packet-obfuscation-and-reduction.patch
Samsuik 7de1cfbc8f Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@a80d31b Log command execution exceptions if debug=true (#10130)
PaperMC/Paper@ec19620 Use a ConcurrentHashMap for enum mappings for BlockData (#10161)
PaperMC/Paper@f28caff Limit ResourceLocation length to nbt string tag length
PaperMC/Paper@a0ffb57 [ci skip] Small cleanup to mc utils patch
PaperMC/Paper@8c8862f Also check for the actual character length in ResourceLocation validation
PaperMC/Paper@e84621a [ci skip] Add more patch identifying comments
PaperMC/Paper@c0e4697 [ci skip] Add more patch identifying comments
PaperMC/Paper@17275ff [ci skip] add more comments & move 1 hunk to correct patch
PaperMC/Paper@78fcb8e [ci skip] Update contributing guidelines to include identifying commit titles in comments (#10162)
PaperMC/Paper@8657cd9 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10164)
PaperMC/Paper@c151c95 Fixup AsyncPreLoginEvent patches
PaperMC/Paper@93a848c Readd missed line
PaperMC/Paper@f9fdedf [ci skip] Add more patch identifying comments, merge related patches
PaperMC/Paper@0ef5984 [ci skip] Add more patch identifying comments, merge related patches
PaperMC/Paper@848a396 Add mob goal generator (#9980)
PaperMC/Paper@ebf97bd [ci skip] Add more patch identifying comments
PaperMC/Paper@94807a1 [ci skip] Minor cleanup and patch merges
PaperMC/Paper@5e73c55 [ci skip] Add more identifying patch comments
PaperMC/Paper@3e20d3a [ci skip] Add more identifying patch comments
PaperMC/Paper@f61ebdc Fix issue with kick event causes being passed improperly
PaperMC/Paper@106c67a [ci skip] Add more identifying patch comments
PaperMC/Paper@cc693ce [ci skip] Add more identifying patch comments, merge related patches
PaperMC/Paper@eeb6afc [ci skip] Add more identifying patch comments, merge related patches
PaperMC/Paper@1c956ab [ci skip] Add more identifying patch comments, merge related patches
PaperMC/Paper@42e88a8 [ci skip] Add more identifying patch comments
PaperMC/Paper@8e41ef4 Add visual blockdata api for primed tnt (#10146)
PaperMC/Paper@68c3297 [ci skip] Add more identifying patch comments
PaperMC/Paper@4a98986 Add back Reduce allocation of Vec3D by entity tracker patch (#10179)
PaperMC/Paper@b48d737 Async world data IO saving (#10171)
PaperMC/Paper@8d94596 [ci skip] Add more identifying patch comments
PaperMC/Paper@f7dd304 [ci skip] Add more identifying patch comments
PaperMC/Paper@98e6d20 [ci skip] Add more identifying patch comments
PaperMC/Paper@e9e0bc1 [ci skip] Add more identifying patch comments
PaperMC/Paper@d9df6bc [ci skip] Add more patch identifying comments, cleanup
PaperMC/Paper@27cabc1 [ci skip] Add more patch identifying comments
PaperMC/Paper@684319f [ci skip] Add more patch identifying comments
PaperMC/Paper@9eb0b38 [ci skip] Add more patch identifying comments
PaperMC/Paper@25013d9 [ci skip] Move some disruptive patches back
PaperMC/Paper@484d6bf [ci skip] Move some disruptive patches back
PaperMC/Paper@52619e7 [ci skip] Add more patch identifying comments
PaperMC/Paper@e660379 [ci skip] Move some disruptive patches back
PaperMC/Paper@c57d1aa Move diffs around to compile without later ones applied
PaperMC/Paper@581b101 Add world to Entity AddTo/RemoveFrom Events (#10183)
PaperMC/Paper@24dc2bf Add BlockStateMeta#clearBlockState (#10160)
PaperMC/Paper@76da4bc Expose LootTable of DecoratedPot (#10023)
PaperMC/Paper@11645e3 [ci skip] (Mostly) finish adding identifying patch comments
PaperMC/Paper@51bef80 [ci skip] Remove removed patches
PaperMC/Paper@ad2cf68 [ci skip] Move chunk system patch back a bit
PaperMC/Paper@d405ff1 [ci skip] Fixup last commit
PaperMC/Paper@a4a08b7 [ci skip] Move chunk system patch a bit back
PaperMC/Paper@b700460 Convert average tick value in the GUI to the correct granularity
PaperMC/Paper@1831240 [ci skip] Move chunk system patch back
PaperMC/Paper@b03f255 Finish moving patches back and improving compilable state
PaperMC/Paper@bd2fd61 [ci skip] Fixup a few bad comments
PaperMC/Paper@fe53b0e Updated Upstream (Bukkit/CraftBukkit/Spigot)
PaperMC/Paper@1ed50da Fix javadoc errors, remove unused classes
PaperMC/Paper@7f7d05a [ci skip] Remove IRC link from the README (#10194)
PaperMC/Paper@ed130f1 [ci skip] clarify javadocs for Block#getDrops (#10153)
PaperMC/Paper@4643b0d Shulker duplicate event (#10135)
PaperMC/Paper@b333831 Make spawn egg colours visible (#10158)
PaperMC/Paper@0cc3a7e Disable memory reserve allocating (#10180)
PaperMC/Paper@3841722 Properly check if a loot table exists (#10190)
PaperMC/Paper@b3c8108 [ci skip] Fix incorrect documentation for BlockDropItemEvent (#10175)
PaperMC/Paper@294347b [ci skip] Cleanup events (#10202)
PaperMC/Paper@87ce7c7 Small refactor of Paper plugin context preparation
PaperMC/Paper@7f856a1 Fix sleeping pos desync
PaperMC/Paper@8bc5be8 Add missing catch
PaperMC/Paper@c5d168c More provider source fixup
PaperMC/Paper@9e171ef Improve tag parser handling, move hunks out of chunk system patch
PaperMC/Paper@934cd77 Lifecycle Event System (#9629)
PaperMC/Paper@534659e Fix NotNull locales (#10216)
PaperMC/Paper@9c04729 Add Arrow/Stinger Removal Time API (#10193)
PaperMC/Paper@69b52b4 Check for server JARs in plugin directory (#10228)
PaperMC/Paper@cbe62d9 Add Conduit API (#10195)
PaperMC/Paper@97c0120 Fix fox drops on death (#8862)
PaperMC/Paper@581fb30 itemstack expose tooltip lines (#10185)
PaperMC/Paper@99bae59 Propagate failed to bind to port error (#10235)
PaperMC/Paper@bf6e803 Fix WaterBottleSplashEvent not forwarding hit result (#10203)
PaperMC/Paper@2fa2d32 Fix possible StackOverflowError for some dispenser iteractions (#8524)
PaperMC/Paper@e6a5215 Properly track the changed item from dispense events (#8658)
PaperMC/Paper@4b58a85 Fire BlockPreDispenseEvent for droppers (#10226)
PaperMC/Paper@cde5587 Add getChunkSnapshot includeLightData parameter (#10234)
PaperMC/Paper@31699ae Updated Upstream (Bukkit/CraftBukkit) (#10242)
PaperMC/Paper@37df121 Fix BlockState being set to null for damage events (#10252)
PaperMC/Paper@7f85940 Updated Upstream (Bukkit) (#10255)
PaperMC/Paper@7ccefdc Fire entity knockback event for ownerless tnt (#7171)
PaperMC/Paper@a07d526 [ci skip] Fix JavaDoc mistake in BlockPistonRetractEvent (#10250)
PaperMC/Paper@9a66f2b [ci skip] Fix javadoc mistake in PluginMeta (#10258)
PaperMC/Paper@1964b22 Scoreboard objective number format api (#10036)
PaperMC/Paper@d95341e FluidState API (#9951)
PaperMC/Paper@351923d Run round-trip adventure codec tests with JSON, NBT, and Java ops. Use JavaOps for conversions. (#10031)
PaperMC/Paper@4939f87 Add more ResourceLocation checks, some cleanup
2024-02-20 15:26:46 +00:00

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 58b602e550258c1062ee940bc46538dac95d8979..50c6647ef3755c3712bf095c14c820019d6318e1 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 - Perf: array backed synched entity data
+ 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 cce8f45c15b9a9acfbf9b769f7670cfd0969d62f..4237442c649845ffb0ff613e6c76ca478191e950 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;
@@ -401,11 +401,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);
@@ -432,7 +444,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 38d416b4d9acf811f862cd2fbf88de8dfcef077c..9a7b9f72531dfaecb55c089eea412e81ee00ef65 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3402,7 +3402,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 3b0c6dbe6b473e2249846f894f85770d5f46ded8..85da566b151d6c9995b5c41333c4cd05235c1d70 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 9d92561eb38431ac01416900420793c21f89d82f..46680f551f83b91581440d89a1c35c048db03638 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -188,7 +188,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 5ca1f834f311a87323ced2578535e66efa14e47f..d89e7f021cc4ac61550ca5dbf660323fc1aec01f 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -645,7 +645,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) {