From 6080f124a1fde58a3d5b1ec53bada60d1a49edfe Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 26 May 2024 14:54:03 +0100 Subject: [PATCH] feat: hide seed from client when `client-side-chunk-generation-enabled` is set to `false` in `server.properties` --- include/bedrock/forward.h | 1 + .../network/protocol/game/start_game_packet.h | 68 +++++++++++++++++++ .../syncher/synced_player_movement_settings.h | 25 +++++++ .../bedrock/server/packs/content_identity.h | 26 +++++++ .../world/level/storage/level_settings.h | 7 ++ .../network/protocol/start_game_packet.cpp | 31 +++++++++ 6 files changed, 158 insertions(+) create mode 100644 include/bedrock/network/protocol/game/start_game_packet.h create mode 100644 include/bedrock/network/syncher/synced_player_movement_settings.h create mode 100644 include/bedrock/server/packs/content_identity.h create mode 100644 src/endstone_runtime/bedrock/network/protocol/start_game_packet.cpp diff --git a/include/bedrock/forward.h b/include/bedrock/forward.h index 9abbcac05..06a0f9270 100644 --- a/include/bedrock/forward.h +++ b/include/bedrock/forward.h @@ -96,6 +96,7 @@ class InternalComponentRegistry; class InventoryTransaction; class Item; class ItemComponentPacket; +class ItemData; class ItemInstance; class ItemRegistryRef; class ItemUseMethod; diff --git a/include/bedrock/network/protocol/game/start_game_packet.h b/include/bedrock/network/protocol/game/start_game_packet.h new file mode 100644 index 000000000..7b2cbddc2 --- /dev/null +++ b/include/bedrock/network/protocol/game/start_game_packet.h @@ -0,0 +1,68 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include + +#include "bedrock/bedrock.h" +#include "bedrock/forward.h" +#include "bedrock/mce.h" +#include "bedrock/nbt/compound_tag.h" +#include "bedrock/network/protocol/packet.h" +#include "bedrock/network/syncher/synced_player_movement_settings.h" +#include "bedrock/server/packs/content_identity.h" +#include "bedrock/world/actor/actor_runtime_id.h" +#include "bedrock/world/actor/actor_unique_id.h" +#include "bedrock/world/level/game_type.h" +#include "bedrock/world/level/storage/level_settings.h" +#include "bedrock/world/math/vec2.h" +#include "bedrock/world/math/vec3.h" + +class NetworkPermissions { +public: + bool unknown; +}; + +class StartGamePacket : public Packet { +public: + BEDROCK_API virtual void write(BinaryStream &) const; + +private: + mutable LevelSettings settings_; // +48 + ActorUniqueID entity_id_; // +1296 + ActorRuntimeID runtime_id_; // +1304 + GameType game_type_; // +1312 + Vec3 position_; // +1316 + Vec2 rotation_; // +1328 + std::string level_id_; // +1336 + std::string level_name_; // +1368 + ContentIdentity template_content_identity_; // +1400 + mce::UUID world_template_id_; // +1424 + bool is_trial_; // +1440 + SyncedPlayerMovementSettings movement_settings_; // +1444 + std::uint64_t level_current_time_; // +1456 + int enchantment_seed_; // +1464 + std::string multiplayer_correlation_id_; // +1472 + std::vector item_data_; // +1504 + bool enable_item_stack_net_manager_; // +1528 + std::string server_version_; // +1536 + CompoundTag player_property_data_; // +1568 + std::uint64_t server_block_type_registry_checksum_; // +1592 + bool server_enabled_client_side_generation_; // +1600 + bool block_network_ids_are_hashes_; // +1601 + NetworkPermissions network_permissions_; // +1602 + std::vector> block_properties_; // +1608 +}; diff --git a/include/bedrock/network/syncher/synced_player_movement_settings.h b/include/bedrock/network/syncher/synced_player_movement_settings.h new file mode 100644 index 000000000..a8afd2b28 --- /dev/null +++ b/include/bedrock/network/syncher/synced_player_movement_settings.h @@ -0,0 +1,25 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once +#include "bedrock/bedrock.h" + +class SyncedPlayerMovementSettings { +public: +private: + char authority_mode_; + int rewind_history_size_; + bool server_auth_block_breaking_; +}; +BEDROCK_STATIC_ASSERT_SIZE(SyncedPlayerMovementSettings, 12, 12); diff --git a/include/bedrock/server/packs/content_identity.h b/include/bedrock/server/packs/content_identity.h new file mode 100644 index 000000000..5fa78a0ec --- /dev/null +++ b/include/bedrock/server/packs/content_identity.h @@ -0,0 +1,26 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "bedrock/bedrock.h" +#include "bedrock/mce.h" + +class ContentIdentity { +public: +private: + mce::UUID uuid_; + bool is_valid_; +}; +BEDROCK_STATIC_ASSERT_SIZE(ContentIdentity, 24, 24); diff --git a/include/bedrock/world/level/storage/level_settings.h b/include/bedrock/world/level/storage/level_settings.h index 8e53f7f88..8f3842c79 100644 --- a/include/bedrock/world/level/storage/level_settings.h +++ b/include/bedrock/world/level/storage/level_settings.h @@ -14,6 +14,7 @@ #pragma once +#include "bedrock/bedrock.h" #include "bedrock/world/level/storage/level_seed.h" class LevelSettings { @@ -30,4 +31,10 @@ class LevelSettings { private: LevelSeed64 seed_; +#ifdef _WIN32 + size_t pad_[1248 / 8 - 1]; +#else + size_t pad_[1072 / 8 - 1]; +#endif }; +BEDROCK_STATIC_ASSERT_SIZE(LevelSettings, 1248, 1072); diff --git a/src/endstone_runtime/bedrock/network/protocol/start_game_packet.cpp b/src/endstone_runtime/bedrock/network/protocol/start_game_packet.cpp new file mode 100644 index 000000000..b8c6866ba --- /dev/null +++ b/src/endstone_runtime/bedrock/network/protocol/start_game_packet.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "bedrock/network/protocol/game/start_game_packet.h" + +#include "endstone/detail/hook.h" + +void StartGamePacket::write(BinaryStream &stream) const +{ + if (!server_enabled_client_side_generation_) { + settings_.setRandomSeed({0}); + } + +#if _WIN32 + ENDSTONE_HOOK_CALL_ORIGINAL_NAME(&StartGamePacket::write, __FUNCDNAME__, this, stream); +#else + ENDSTONE_HOOK_CALL_ORIGINAL_NAME(&StartGamePacket::write, "_ZNK15StartGamePacket5writeER12BinaryStream", this, + stream); +#endif +}