Skip to content

Commit

Permalink
feat: hook ResourcePackRepository::_initializePackSource
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Oct 14, 2024
1 parent c3ed44b commit 93c1560
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
10 changes: 7 additions & 3 deletions include/bedrock/resources/pack_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ class PackSource {
virtual ~PackSource() = 0;
virtual void forEachPackConst(ConstPackCallback callback) const = 0;
virtual void forEachPack(PackCallback callback) = 0;
[[nodiscard]] virtual PackOrigin getPackOrigin() const;
[[nodiscard]] virtual PackType getPackType() const;
[[nodiscard]] virtual PackOrigin getPackOrigin() const = 0;
[[nodiscard]] virtual PackType getPackType() const = 0;
virtual PackSourceReport load(IPackManifestFactory &factory,
Bedrock::NotNullNonOwnerPtr<const IContentKeyProvider> const &a3) = 0;
Bedrock::NotNullNonOwnerPtr<const IContentKeyProvider> const &) = 0;
};

class CompositePackSource : public PackSource {
public:
void addPackSource(PackSource *pack_source);
void clear();
std::vector<PackSource *> getPackSources();

private:
std::vector<PackSource *> pack_sources_;
};
10 changes: 9 additions & 1 deletion include/bedrock/resources/resource_pack_repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@

#include "bedrock/resources/resource_pack_repository_interface.h"

class ResourcePackRepository : public IResourcePackRepository {};
class ResourcePackRepository : public IResourcePackRepository {
public:
private:
ENDSTONE_HOOK void _initializePackSource(); // NOLINT

Bedrock::NotNullNonOwnerPtr<Core::FilePathManager> file_path_manager_; // +24
std::vector<std::unique_ptr<ResourcePack>> all_resource_packs_; // +40
std::unique_ptr<CompositePackSource> pack_source_; // +64
};
8 changes: 6 additions & 2 deletions python/src/endstone/_internal/symbols.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
timestamp = 1727987716
timestamp = 1728933927
version = "1.21.30"

[windows]
Expand Down Expand Up @@ -70,6 +70,8 @@ version = "1.21.30"
"?ToString@SystemAddress@RakNet@@QEBAX_NPEADD@Z" = 37138000
# RakPeerHelper
"?peerStartup@RakPeerHelper@@QEAA?AW4StartupResult@RakNet@@PEAVRakPeerInterface@3@AEBUConnectionDefinition@@W4PeerPurpose@1@@Z" = 8265632
# ResourcePackRepository
"?_initializePackSource@ResourcePackRepository@@AEAAXXZ" = 9253008
# SayCommand
"?_sendMessage@SayCommand@@CAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$optional@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@3@0AEBUCommandOriginIdentity@@AEAVLevel@@@Z" = 23116144
# Scoreboard
Expand Down Expand Up @@ -173,6 +175,8 @@ version = "1.21.30"
"_ZNK6RakNet13SystemAddress8ToStringEbPcc" = 134586416
# RakPeerHelper
"_ZN13RakPeerHelper11peerStartupEPN6RakNet16RakPeerInterfaceERK20ConnectionDefinitionNS_11PeerPurposeE" = 78459312
# ResourcePackRepository
"_ZN22ResourcePackRepository21_initializePackSourceEv" = 80958128
# SayCommand
"_ZN10SayCommand12_sendMessageERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEENS0_8optionalIS6_EES8_RK21CommandOriginIdentityR5Level" = 90709328
# Scoreboard
Expand Down Expand Up @@ -205,4 +209,4 @@ version = "1.21.30"
"_ZNK15StartGamePacket5writeER12BinaryStream" = 79691312
# TeleportCommand
"_ZN15TeleportCommand11applyTargetER5Actor14TeleportTargetb" = 90108320
"_ZN15TeleportCommand13computeTargetER5Actor4Vec3PS2_11AutomaticIDI9DimensioniERKNSt3__18optionalIN20RotationCommandUtils12RotationDataEEEi" = 90108704
"_ZN15TeleportCommand13computeTargetER5Actor4Vec3PS2_11AutomaticIDI9DimensioniERKNSt3__18optionalIN20RotationCommandUtils12RotationDataEEEi" = 90108704
30 changes: 30 additions & 0 deletions src/endstone_runtime/bedrock/resources/pack_source.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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/resources/pack_source.h"

void CompositePackSource::addPackSource(PackSource *pack_source)
{
pack_sources_.emplace_back(pack_source);
}

void CompositePackSource::clear()
{
pack_sources_.clear();
}

std::vector<PackSource *> CompositePackSource::getPackSources()
{
return pack_sources_;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@
// limitations under the License.

#include "bedrock/resources/resource_pack_repository.h"

#include "endstone/detail/hook.h"

void ResourcePackRepository::_initializePackSource()
{
ENDSTONE_HOOK_CALL_ORIGINAL(&ResourcePackRepository::_initializePackSource, this);
}

0 comments on commit 93c1560

Please sign in to comment.