Skip to content

Commit

Permalink
feat: add UnlockCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Oct 11, 2023
1 parent 2e776be commit 530d4d1
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 1,497 deletions.
59 changes: 59 additions & 0 deletions src/ll/api/command/UnlockCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "ll/api/base/Global.h"
#include "ll/api/memory/Hook.h"
#include "ll/core/Config.h"

#include "magic_enum.hpp"

#include "mc/server/commands/CommandRegistry.h"
#include "mc/server/commands/CommandSelectorBase.h"


using namespace ll::memory;

LL_AUTO_TYPED_INSTANCE_HOOK(
UnlockCmdHookRegisterCommand,
HookPriority::Normal,
CommandRegistry,
&CommandRegistry::registerCommand,
void,
std::string const& name,
char const* description,
::CommandPermissionLevel permlevel,
CommandFlag flag1,
CommandFlag flag2 // useless, idiot
) {
if (ll::globalConfig.enableUnlockCmd) { flag1 |= CommandFlagValue::NotCheat; }

return origin(name, description, permlevel, flag1, flag2);
}

LL_AUTO_TYPED_INSTANCE_HOOK(
UnlockCmdHookIsExpansionAllowed,
HookPriority::Normal,
CommandSelectorBase,
&CommandSelectorBase::isExpansionAllowed,
bool,
CommandOrigin const& commandOrigin
) {
if (ll::globalConfig.enableUnlockCmd) { return true; }
return origin(commandOrigin);
}

LL_AUTO_TYPED_INSTANCE_HOOK(
UnlockCmdHookAddEnumValueConstraints,
HookPriority::Normal,
CommandRegistry,
&CommandRegistry::addEnumValueConstraints,
void,
std::string const& enumName,
std::vector<std::string> const& enumValues,
SemanticConstraint constraint
) {
using namespace magic_enum::bitwise_operators;
if (ll::globalConfig.enableUnlockCmd
&& magic_enum::enum_integer(constraint & SemanticConstraint::RequiresCheatsEnabled)) {
constraint = constraint & (~SemanticConstraint::RequiresCheatsEnabled);
constraint = constraint | SemanticConstraint::RequiresElevatedPermissions;
}
return origin(enumName, enumValues, constraint);
}
12 changes: 4 additions & 8 deletions src/ll/api/service/GlobalService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ LL_AUTO_TYPED_INSTANCE_HOOK(
(RakNet::RakPeer*)((RakNetConnector&)(*ll::Global<Minecraft>->getNetworkSystem().getRemoteConnector()))
.getPeer()
);
ll::Global<StructureManager>.init(ll::Global<Minecraft>->getStructureManager().get());
ll::Global<Level>.init(ll::Global<Minecraft>->getLevel());
ll::Global<ServerLevel>.init((ServerLevel*)ll::Global<Level>);
origin(ins);
Expand All @@ -75,11 +76,8 @@ LL_AUTO_TYPED_INSTANCE_HOOK(
std::string const& a1,
bool a2
) {
static bool initd = false;
if (!initd) {
initd = true;
ll::Global<ServerNetworkHandler>.init(this);
}
ll::Global<ServerNetworkHandler>.init(this);
unhook();
origin(a1, a2);
}

Expand All @@ -106,6 +104,7 @@ LL_AUTO_TYPED_INSTANCE_HOOK(
bool const
) {
ll::Global<PropertiesSettings>.init(this);
unhook();
return origin();
}

Expand All @@ -122,6 +121,3 @@ LL_AUTO_TYPED_INSTANCE_HOOK(
}

} // namespace

// fixme: remove or implement
template class ll::GlobalService<StructureManager>;
1 change: 0 additions & 1 deletion src/ll/core/LeviLamina.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ void checkProtocolVersion() {
if (TARGET_BDS_PROTOCOL_VERSION != currentProtocol) {
logger.warn(tr("ll.main.warning.protocolVersionNotMatch.1"), TARGET_BDS_PROTOCOL_VERSION, currentProtocol);
logger.warn(tr("ll.main.warning.protocolVersionNotMatch.2"));
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/ll/core/ModifyInfomation.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ll/api/LoggerAPI.h"
#include "ll/api/memory/Hook.h"
#include "mc/common/Common.h"

#include "mc/deps/core/common/debug/LogDetails.h"

Expand All @@ -16,7 +17,7 @@ std::unordered_map<unsigned int, decltype(serverLogger.debug)&> loggerMap = {

LL_AUTO_TYPED_INSTANCE_HOOK(
AppendLogEntryMetadataHook,
ll::memory::HookPriority::Normal,
HookPriority::Normal,
::BedrockLog::LogDetails,
&::BedrockLog::LogDetails::_appendLogEntryMetadata,
void,
Expand All @@ -33,7 +34,7 @@ MCAPI void BedrockLogOut(unsigned int priority, const char* pszFormat, ...);

LL_AUTO_STATIC_HOOK(
BedrockLogOutHook,
ll::memory::HookPriority::Normal,
HookPriority::Normal,
BedrockLogOut,
void,
unsigned int priority,
Expand Down
2 changes: 1 addition & 1 deletion src/ll/core/Version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#define LL_VERSION_COMMIT_SHA ${GIT_COMMIT}

#define TARGET_BDS_PROTOCOL_VERSION 568
#define TARGET_BDS_PROTOCOL_VERSION 618

#define LL_VERSION_TO_STRING_INNER(ver) #ver
#define LL_VERSION_TO_STRING(ver) LL_VERSION_TO_STRING_INNER(ver)
Expand Down
16 changes: 3 additions & 13 deletions src/mc/common/wrapper/optional_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class optional_ref {

constexpr optional_ref(std::nullptr_t) noexcept {}

// template <typename U>
// requires(IsCompatibleV<U>)
// constexpr optional_ref(std::optional<U> const& o)
// requires(std::is_const_v<T>)
// : ptr_(o ? &*o : nullptr) {}

template <typename U>
requires(IsCompatibleV<U>)
constexpr optional_ref(std::optional<U>& o) : ptr_(o ? &*o : nullptr) {}
Expand All @@ -34,10 +28,6 @@ class optional_ref {
requires(IsCompatibleV<U>)
constexpr optional_ref(U* p) : ptr_(p) {}

// template <typename U>
// requires(IsCompatibleV<U>)
// constexpr optional_ref(U const& r) : ptr_(std::addressof(r)) {}

template <typename U>
requires(IsCompatibleV<U>)
constexpr optional_ref(U& r) : ptr_(std::addressof(r)) {}
Expand All @@ -57,11 +47,11 @@ class optional_ref {
[[nodiscard]] constexpr T* as_ptr() const noexcept { return ptr_; }

constexpr T* operator->() const {
if (!has_value()) { throw std::bad_optional_access{}; }
if (!has_value()) { throw std::runtime_error{"bas optional_ref access"}; }
return ptr_;
}
[[nodiscard]] constexpr T& get() const {
if (!has_value()) { throw std::bad_optional_access{}; }
if (!has_value()) { throw std::runtime_error{"bas optional_ref access"}; }
return *ptr_;
}

Expand All @@ -78,7 +68,7 @@ class optional_ref {
}

[[nodiscard]] constexpr operator T&() const {
if (!has_value()) { throw std::bad_optional_access{}; }
if (!has_value()) { throw std::runtime_error{"bas optional_ref access"}; }
return *ptr_;
}

Expand Down
4 changes: 4 additions & 0 deletions src/mc/server/commands/CommandFlag.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ struct CommandFlag {
value = rhs.value | value;
return *this;
}
CommandFlag& operator|=(CommandFlagValue const& rhs) {
value = rhs | value;
return *this;
}
};
4 changes: 2 additions & 2 deletions src/mc/world/item/enchanting/Enchant.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class Enchant {
CrossbowQuickCharge = 0x23,
SoulSpeed = 0x24,
SwiftSneak = 0x25,
NumEnchantments = 0x26,
InvalidEnchantment = 0x27,
Count = 0x26,
Invalid = 0x27,
};

enum class Activation : int {
Expand Down
4 changes: 2 additions & 2 deletions src/mc/world/level/levelgen/structure/StructureTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void StructureTemplate::placeInWorld(
}


std::unique_ptr<StructureTemplate> StructureTemplate::create(std::string name, CompoundTag const& tag) {
std::unique_ptr<StructureTemplate> StructureTemplate::create(const std::string& name, CompoundTag const& tag) {
auto& unknownBlockRegistry = Global<StructureManager>->mUnknownBlockRegistry;
auto res = std::make_unique<StructureTemplate>(name, unknownBlockRegistry);
bool success{res->load(tag)};
Expand All @@ -33,7 +33,7 @@ std::unique_ptr<StructureTemplate> StructureTemplate::create(std::string name, C
}

std::unique_ptr<StructureTemplate> StructureTemplate::create(
std::string name,
const std::string& name,
BlockSource& blockSource,
BoundingBox const& boundingBox,
bool ignoreBlocks,
Expand Down
4 changes: 2 additions & 2 deletions src/mc/world/level/levelgen/structure/StructureTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class StructureTemplate {
) const;

// nullptr if invalid nbt
LLNDAPI static std::unique_ptr<StructureTemplate> create(std::string name, CompoundTag const& tag);
LLNDAPI static std::unique_ptr<StructureTemplate> create(const std::string& name, CompoundTag const& tag);

// always success
LLNDAPI static std::unique_ptr<StructureTemplate> create(
std::string name,
const std::string& name,
BlockSource& blockSource,
BoundingBox const& boundingBox,
bool ignoreBlocks = false,
Expand Down
160 changes: 0 additions & 160 deletions temp/FormPacketHelper.cpp

This file was deleted.

Loading

0 comments on commit 530d4d1

Please sign in to comment.