Skip to content

Commit

Permalink
feat: make command work on client
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Aug 12, 2024
1 parent b2de5fe commit 575b620
Show file tree
Hide file tree
Showing 32 changed files with 75 additions and 118 deletions.
3 changes: 3 additions & 0 deletions src-client/mc/util/VarIntDataInput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "mc/util/VarIntDataInput.h"

Bedrock::Result<std::string> VarIntDataInput::readLongStringResult() { return readStringResult(); }
3 changes: 3 additions & 0 deletions src-client/mc/util/VarIntDataOutput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "mc/util/VarIntDataOutput.h"

void VarIntDataOutput::writeLongString(std::string_view v) { writeString(v); }
3 changes: 2 additions & 1 deletion src/ll/api/command/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#include "ll/core/LeviLamina.h"

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

namespace ll::command::detail {
void printCommandError(::Command const& command, ::CommandOutput& output) noexcept {
auto lock = ll::Logger::lock();
try {
getLogger().error("Error in command {}:", command.getCommandName());
getLogger().error("Error in command {}:", command.mRegistry->symbolToString(command.mCommandSymbol));
output.error("command threw an exception");
} catch (...) {}
error_utils::printCurrentException(getLogger());
Expand Down
4 changes: 2 additions & 2 deletions src/ll/api/memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ LLNDAPI std::vector<std::string> lookupSymbol(FuncPtr func);
LLAPI void modify(void* ptr, size_t len, const std::function<void()>& callback);

template <class T>
inline void modify(T& ref, std::function<void(std::remove_cvref_t<T>&)> const& f) {
modify((void*)std::addressof(ref), sizeof(T), [&] { f((std::remove_cvref_t<T>&)(ref)); });
inline void modify(T& ref, std::function<void(std::remove_cv_t<T>&)> const& f) {
modify((void*)std::addressof(ref), sizeof(T), [&] { f((std::remove_cv_t<T>&)(ref)); });
}

template <class RTN = void, class... Args>
Expand Down
16 changes: 6 additions & 10 deletions src/mc/deps/core/Path.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ namespace Core {

class Path {
public:
class PathPart mPath;
explicit Path(std::filesystem::path const& path) : Path(path.u8string()) {}
explicit Path(std::u8string const& path) { mPath.mUtf8StdString = *reinterpret_cast<std::string const*>(&path); }
explicit Path(std::string const& path) { mPath.mUtf8StdString = path; }
PathPart mPath;
Path(std::filesystem::path const& path) : Path(path.u8string()) {}
Path(std::u8string const& path) { mPath.mUtf8StdString = *reinterpret_cast<std::string const*>(&path); }
Path(std::string const& path) { mPath.mUtf8StdString = path; }
Path(char const* path) { mPath.mUtf8StdString = path; }
Path() = default;

public:
// NOLINTBEGIN
MCAPI Path();

MCAPI explicit Path(char const*);

MCAPI bool operator==(class Core::Path const&) const;

MCAPI ~Path();

MCAPI static class Core::Result makeFailure(char const* format, class Core::Path&& path);

MCAPI static class Core::Path const EMPTY;
Expand Down
6 changes: 0 additions & 6 deletions src/mc/deps/core/PathPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ namespace Core {
class PathPart {
public:
std::string mUtf8StdString;

public:
// NOLINTBEGIN
MCAPI ~PathPart();

// NOLINTEND
};

}; // namespace Core
11 changes: 3 additions & 8 deletions src/mc/deps/core/common/bedrock/CallStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ struct CallStack {
// NOLINTBEGIN
MCAPI Context(std::string value, std::optional<::Bedrock::LogLevel>, std::optional<::LogAreaID> logArea);

MCAPI ~Context();

// NOLINTEND
};

Expand All @@ -50,24 +48,21 @@ struct CallStack {
std::optional<struct Bedrock::CallStack::Context>&& context
);

MCAPI ~FrameWithContext();

// NOLINTEND
};

public:
std::vector<Bedrock::CallStack::FrameWithContext> vector;

CallStack(struct Bedrock::CallStack const&) = default;
CallStack& operator=(struct Bedrock::CallStack const&) = default;

public:
// NOLINTBEGIN
MCAPI explicit CallStack(std::vector<struct Bedrock::CallStack::FrameWithContext>&& frames);

MCAPI CallStack(struct Bedrock::CallStack const&);

MCAPI explicit CallStack(struct Bedrock::CallStack::FrameWithContext&& frame);

MCAPI ~CallStack();

// NOLINTEND
};

Expand Down
2 changes: 0 additions & 2 deletions src/mc/nbt/Int64Tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class Int64Tag : public ::Tag {
// vIndex: 10
virtual uint64 hash() const;

MCAPI explicit Int64Tag(int64 data);

// NOLINTEND
};

Expand Down
4 changes: 2 additions & 2 deletions src/mc/nbt/ListTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ListTag : public ::Tag, public std::vector<UniqueTagPtr> {
using Tag::operator==;

public:
[[nodiscard]] constexpr ListTag() = default;

[[nodiscard]] constexpr ListTag(List tags) : List(std::move(tags)) {
if (!empty()) mType = front().getId();
}
Expand Down Expand Up @@ -55,8 +57,6 @@ class ListTag : public ::Tag, public std::vector<UniqueTagPtr> {
// vIndex: 10
virtual uint64 hash() const;

MCAPI ListTag();

MCAPI void add(std::unique_ptr<class Tag> tag);

MCAPI std::unique_ptr<class ListTag> copyList() const;
Expand Down
3 changes: 1 addition & 2 deletions src/mc/resources/ResourcePackRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

void ResourcePackRepository::addCustomResourcePackPath(std::filesystem::path const& path, PackType type) {

auto& DirectoryPackSource =
getPackSourceFactory().createDirectoryPackSource(Core::Path(path), type, PackOrigin::Dev);
auto& DirectoryPackSource = getPackSourceFactory().createDirectoryPackSource(path, type, PackOrigin::Dev);

ll::memory::dAccess<CompositePackSource*>(this, 96)->addPackSource(DirectoryPackSource);

Expand Down
2 changes: 0 additions & 2 deletions src/mc/server/commands/BlockStateCommandParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class BlockStateCommandParam {

MCAPI bool setBlockState(class Block const**, class CommandOutput& output) const;

MCAPI ~BlockStateCommandParam();

// NOLINTEND

// private:
Expand Down
4 changes: 0 additions & 4 deletions src/mc/server/commands/CommandFilePath.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ class CommandFilePath {

public:
// NOLINTBEGIN
MCAPI CommandFilePath();

MCAPI int findInvalidCharacter() const;

MCAPI std::string const& getText() const;

MCAPI ~CommandFilePath();

// NOLINTEND
};
2 changes: 2 additions & 0 deletions src/mc/server/commands/CommandFlag.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct CommandFlag {
public:
CommandFlagValue value;

CommandFlag() = default;

CommandFlag(CommandFlagValue value) : value(value) {} // NOLINT

[[nodiscard]] constexpr bool operator==(CommandFlag const& rhs) const noexcept { return value == rhs.value; }
Expand Down
13 changes: 7 additions & 6 deletions src/mc/server/commands/CommandIntegerRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

class CommandIntegerRange {
public:
int mMinValue; // this+0x0
int mMaxValue; // this+0x4
bool mInvert; // this+0x8
int mMinValue{}; // this+0x0
int mMaxValue{}; // this+0x4
bool mInvert{}; // this+0x8

CommandIntegerRange() = default;

public:
// NOLINTBEGIN
MCAPI CommandIntegerRange();

MCAPI CommandIntegerRange(int, int, bool, bool);
MCAPI
CommandIntegerRange(int, int, bool, bool);

MCAPI bool isWithinRange(int value) const;

Expand Down
4 changes: 2 additions & 2 deletions src/mc/server/commands/CommandItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class CommandItem {
uint64 mVersionId; // this+0x0
};

CommandItem() : mVersionId() {}

public:
// NOLINTBEGIN
MCAPI CommandItem();

MCAPI explicit CommandItem(uint64);

MCAPI CommandItem(int id, short version, bool);
Expand Down
4 changes: 0 additions & 4 deletions src/mc/server/commands/CommandMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ class CommandMessage {

public:
// NOLINTBEGIN
MCAPI CommandMessage();

MCAPI struct GenerateMessageResult generateMessage(class CommandOrigin const&, int) const;

MCAPI ~CommandMessage();

// NOLINTEND
};
28 changes: 7 additions & 21 deletions src/mc/server/commands/CommandParameterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,14 @@ class CommandParameterData {
int flagOffset
);

LLNDAPI bool operator==(CommandParameterData const& other) const;

public:
// NOLINTBEGIN
MCAPI CommandParameterData(class CommandParameterData const& p);
CommandParameterData& addOptions(::CommandParameterOption options) {
mOptions = (CommandParameterOption)((uchar)mOptions | (uchar)options);
return *this;
}

MCAPI CommandParameterData(
class Bedrock::typeid_t<class CommandRegistry> typeIndex,
ParseFn parser,
char const* name,
::CommandParameterDataType paramType,
char const* enumNameOrPostfix,
char const* subchain,
int offset,
bool optional,
int flagOffset
);

MCAPI class CommandParameterData&
addOptions(::CommandParameterOption options = CommandParameterOption::EnumAutocompleteExpansion);

MCAPI ~CommandParameterData();
LLNDAPI bool operator==(CommandParameterData const& other) const;

CommandParameterData(CommandParameterData const&) = default;
CommandParameterData& operator=(CommandParameterData const&) = default;
// NOLINTEND
};
4 changes: 2 additions & 2 deletions src/mc/server/commands/CommandPosition.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class CommandPosition {
bool mRelativeZ;
bool mLocal;

CommandPosition() = default;

public:
// NOLINTBEGIN
MCAPI CommandPosition();

MCAPI explicit CommandPosition(class Vec3 const&);

MCAPI class BlockPos getBlockPos(class Vec3 const& ref, class Vec3 const& offsetFromBase = {}) const;
Expand Down
4 changes: 4 additions & 0 deletions src/mc/server/commands/CommandRegistry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "mc/server/commands/CommandRegistry.h"
#include "mc/server/commands/CommandParameterData.h"

CommandRegistry::Overload::Overload(CommandVersion ver, FactoryFn* factory) : version(ver), alloc(factory) {}
11 changes: 3 additions & 8 deletions src/mc/server/commands/CommandRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ class CommandRegistry {
bool chaining; // this+0x2C
std::vector<Symbol> paramsSymbol; // this+0x30

public:
// NOLINTBEGIN
MCAPI Overload(class CommandVersion, std::unique_ptr<class Command> (*)(void));

// NOLINTEND
Overload(CommandVersion, std::unique_ptr<class Command> (*)(void));
};

class Symbol {
Expand All @@ -216,6 +212,8 @@ class CommandRegistry {

Symbol() = default;

Symbol(uint64 idx) : mValue((int)idx) {}

Symbol(Symbol const& other) : mValue(other.mValue) {}

Symbol(HardNonTerminal data) : mValue(static_cast<int>(data)) {}
Expand All @@ -227,13 +225,10 @@ class CommandRegistry {
return *this;
}


[[nodiscard]] inline bool operator==(Symbol const& other) const { return mValue == other.mValue; }

public:
// NOLINTBEGIN
MCAPI Symbol(uint64);

MCAPI uint64 toIndex() const;

MCAPI int value() const;
Expand Down
2 changes: 0 additions & 2 deletions src/mc/server/commands/CommandSelectorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ class CommandSelectorBase {

MCAPI void setVersion(int version);

MCAPI ~CommandSelectorBase();

// NOLINTEND

// protected:
Expand Down
10 changes: 0 additions & 10 deletions src/mc/server/commands/CommandWildcardInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,4 @@ class CommandWildcardInt {
public:
bool mIsWildcard; // this+0x0
int mValue; // this+0x4

public:
// NOLINTBEGIN
MCAPI CommandWildcardInt();

MCAPI int getValue() const;

MCAPI bool isWildcard() const;

// NOLINTEND
};
7 changes: 4 additions & 3 deletions src/mc/server/commands/RelativeFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

class RelativeFloat {
public:
float mOffset;
bool mRelative;
float mOffset{};
bool mRelative{};

RelativeFloat() = default;

public:
// NOLINTBEGIN
MCAPI RelativeFloat();

MCAPI RelativeFloat(float value, bool relative = true);

Expand Down
2 changes: 1 addition & 1 deletion src/mc/util/BigEndianStringByteInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BigEndianStringByteInput : public ::StringByteInput {

// NOLINTBEGIN
// vIndex: 0
virtual ~BigEndianStringByteInput();
virtual ~BigEndianStringByteInput() = default;

// vIndex: 3
virtual class Bedrock::Result<float> readFloatResult();
Expand Down
2 changes: 1 addition & 1 deletion src/mc/util/BigEndianStringByteOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BigEndianStringByteOutput : public ::StringByteOutput {

// NOLINTBEGIN
// vIndex: 0
virtual ~BigEndianStringByteOutput();
virtual ~BigEndianStringByteOutput() = default;

// vIndex: 3
virtual void writeFloat(float v);
Expand Down
2 changes: 1 addition & 1 deletion src/mc/util/StringByteInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StringByteInput : public ::BytesDataInput {
public:
// NOLINTBEGIN
// vIndex: 0
virtual ~StringByteInput();
virtual ~StringByteInput() = default;

// vIndex: 9
virtual class Bedrock::Result<void> readBytesResult(void*, uint64);
Expand Down
2 changes: 1 addition & 1 deletion src/mc/util/StringByteOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StringByteOutput : public ::BytesDataOutput {
public:
// NOLINTBEGIN
// vIndex: 0
virtual ~StringByteOutput();
virtual ~StringByteOutput() = default;

// vIndex: 9
virtual void writeBytes(void const* data, uint64 bytes);
Expand Down
Loading

0 comments on commit 575b620

Please sign in to comment.