Skip to content

Commit

Permalink
fix: fix setCustomResourcePackPath error
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamguxiang committed Sep 27, 2023
1 parent 560e039 commit a28abe0
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 36 deletions.
74 changes: 70 additions & 4 deletions LiteLoader/include/llapi/mc/Bedrock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,82 @@ struct CrashUploadStatus {
CrashUploadStatus(CrashUploadStatus const&) = delete;
CrashUploadStatus(CrashUploadStatus const&&) = delete;
};
template <typename T0>


class EnableNonOwnerReferences {
public:
struct ControlBlock {
EnableNonOwnerReferences* mPtr;
};

std::shared_ptr<ControlBlock> mControlBlock; // this+0x8

// prevent constructor by default
EnableNonOwnerReferences& operator=(EnableNonOwnerReferences const&) = delete;

public:
// NOLINTBEGIN
// symbol: ??1EnableNonOwnerReferences@Bedrock@@UEAA@XZ
virtual ~EnableNonOwnerReferences();

// symbol: ??0EnableNonOwnerReferences@Bedrock@@QEAA@XZ
MCAPI EnableNonOwnerReferences();

// symbol: ??0EnableNonOwnerReferences@Bedrock@@QEAA@AEBV01@@Z
MCAPI EnableNonOwnerReferences(class Bedrock::EnableNonOwnerReferences const&);

// NOLINTEND
};

template <typename T>
class NonOwnerPointer {
public:
std::shared_ptr<T0> mPtr;
std::shared_ptr<Bedrock::EnableNonOwnerReferences::ControlBlock> mControlBlock;

NonOwnerPointer(T0& a1) {
mPtr = std::make_shared<T0>(a1);
NonOwnerPointer(std::nullptr_t) noexcept {} // NOLINT

T* get() const {
return reinterpret_cast<T*>(mControlBlock.get());
}

explicit operator bool() const noexcept {
return get() != nullptr;
}

constexpr operator T*() const {
return get();
}

constexpr T* operator->() const {
return get();
}

constexpr decltype(auto) operator*() const {
return *get();
}
};

template <class T>
[[nodiscard]] bool operator==(const NonOwnerPointer<T>& self, nullptr_t) noexcept {
return self.get() == nullptr;
}

template <class T>
[[nodiscard]] std::strong_ordering operator<=>(const NonOwnerPointer<T>& self, nullptr_t) noexcept {
return self.get() <=> static_cast<T*>(nullptr);
}

template <class T1, class T2>
[[nodiscard]] bool operator==(const NonOwnerPointer<T1>& l, const NonOwnerPointer<T2>& r) noexcept {
return l.get() == r.get();
}

template <class T1, class T2>
[[nodiscard]] std::strong_ordering operator<=>(const NonOwnerPointer<T1>& l, const NonOwnerPointer<T2>& r) noexcept {
return l.get() <=> r.get();
}


struct StorageMigration {
enum class StorageMigrationType;
StorageMigration() = delete;
Expand Down
71 changes: 39 additions & 32 deletions LiteLoader/src/liteloader/ModifyPack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,42 @@
#include "llapi/mc/PackIdVersion.hpp"
#include "llapi/mc/PackSourceReport.hpp"

//namespace ModifyPack {
// vector<PackIdVersion> PackListCache;
//}
//
//THook(ResourcePack*, "??0ResourcePack@@QEAA@AEAVPack@@@Z",
// ResourcePack* self, Pack* a2) {
// auto Pack = original(self, a2);
// auto manifest = &Pack->getManifest();
// if (manifest && manifest->getPackOrigin() == PackOrigin::Dev) {
// ModifyPack::PackListCache.push_back(a2->getManifest().getIdentity());
// }
// return Pack;
//}
//
//THook(std::unique_ptr<ResourcePackStack>, "?deserialize@ResourcePackStack@@SA?AV?$unique_ptr@VResourcePackStack@@U?$default_delete@VResourcePackStack@@@std@@@std@@AEAV?$basic_istream@DU?$char_traits@D@std@@@3@AEBVIResourcePackRepository@@@Z",
// __int64 a2, ResourcePackRepository* a3) {
// auto Stack = original( a2, a3);
// for (auto& id : ModifyPack::PackListCache) {
// auto Pack = a3->getResourcePackForPackId(id);
// auto& SettingsFactory = a3->getPackSettingsFactory();
// auto settings = SettingsFactory.getPackSettings(Pack->getManifest());
// char gsl[16];
// auto gslPath = SymCall("??$?0PEAVResourcePack@@X@?$not_null@V?$NonOwnerPointer@VResourcePack@@@Bedrock@@@gsl@@QEAA@AEBV?$not_null@PEAVResourcePack@@@1@@Z",
// void*, char*, ResourcePack**)(gsl, &Pack);
// char size[480];
// auto Instance = SymCall("??0PackInstance@@QEAA@V?$not_null@V?$NonOwnerPointer@VResourcePack@@@Bedrock@@@gsl@@H_NPEAVPackSettings@@@Z",
// PackInstance*, char*, void*, int, bool, PackSettings*)(size, gslPath, 0, false, settings);
// Stack->add(*Instance, *(IResourcePackRepository*)a3, 0);
// }
// ModifyPack::PackListCache.clear();
// return Stack;
//}
namespace ModifyPack {
vector<std::string> PackListCache;
}

THook(ResourcePack*, "??0ResourcePack@@QEAA@AEAVPack@@@Z",
ResourcePack* self, Pack* a2) {
auto Pack = original(self, a2);
auto manifest = &Pack->getManifest();
if (manifest && manifest->getPackOrigin() == PackOrigin::Dev) {
ModifyPack::PackListCache.push_back(a2->getManifest().getIdentity().asString());
}
return Pack;
}

THook(std::unique_ptr<ResourcePackStack>,
"?deserialize@ResourcePackStack@@SA?AV?$unique_ptr@VResourcePackStack@@U?$default_delete@VResourcePackStack@@@"
"std@@@std@@AEAV?$basic_istream@DU?$char_traits@D@std@@@3@AEBV?$not_null@V?$NonOwnerPointer@$$"
"CBVIResourcePackRepository@@@Bedrock@@@gsl@@@Z",
std::istream* fileStream, gsl::not_null<Bedrock::NonOwnerPointer<IResourcePackRepository const>> const& a3) {
auto Stack = original(fileStream, a3);
for (auto id : ModifyPack::PackListCache) {
auto Pack = Global<ResourcePackRepository>->getResourcePackForPackId(PackIdVersion::fromString(id));
auto& SettingsFactory = Global<ResourcePackRepository>->getPackSettingsFactory();
auto settings = SettingsFactory.getPackSettings(Pack->getManifest());
char gsl[16];
auto gslPath = SymCall("??$?0PEAVResourcePack@@X@?$not_null@V?$NonOwnerPointer@VResourcePack@@@Bedrock@@@gsl@@"
"QEAA@AEBV?$not_null@PEAVResourcePack@@@1@@Z",
void*, char*, ResourcePack**)(gsl, &Pack);
char size[480];
auto Instance =
SymCall("??0PackInstance@@QEAA@V?$not_null@V?$NonOwnerPointer@VResourcePack@@@Bedrock@@@gsl@@H_"
"NPEAVPackSettings@@@Z",
PackInstance*, char*, void*, int, bool, PackSettings*)(size, gslPath, 0, false, settings);

Stack->add(*Instance, a3, 0);
}
ModifyPack::PackListCache.clear();
return Stack;
}

0 comments on commit a28abe0

Please sign in to comment.