Skip to content

Commit

Permalink
feat: hide seed from client when `client-side-chunk-generation-enable…
Browse files Browse the repository at this point in the history
…d` is set to `false` in `server.properties`
  • Loading branch information
wu-vincent committed May 26, 2024
1 parent fdd3179 commit 6080f12
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/bedrock/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class InternalComponentRegistry;
class InventoryTransaction;
class Item;
class ItemComponentPacket;
class ItemData;
class ItemInstance;
class ItemRegistryRef;
class ItemUseMethod;
Expand Down
68 changes: 68 additions & 0 deletions include/bedrock/network/protocol/game/start_game_packet.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <vector>

#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<ItemData> 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<std::pair<std::string, CompoundTag>> block_properties_; // +1608
};
25 changes: 25 additions & 0 deletions include/bedrock/network/syncher/synced_player_movement_settings.h
Original file line number Diff line number Diff line change
@@ -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);
26 changes: 26 additions & 0 deletions include/bedrock/server/packs/content_identity.h
Original file line number Diff line number Diff line change
@@ -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);
7 changes: 7 additions & 0 deletions include/bedrock/world/level/storage/level_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include "bedrock/bedrock.h"
#include "bedrock/world/level/storage/level_seed.h"

class LevelSettings {
Expand All @@ -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);
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 6080f12

Please sign in to comment.