diff --git a/src/ll/api/command/Optional.h b/src/ll/api/command/Optional.h index f3fa0ed69c..8205a79ff8 100644 --- a/src/ll/api/command/Optional.h +++ b/src/ll/api/command/Optional.h @@ -47,28 +47,28 @@ class Optional { [[nodiscard]] constexpr T const& get() const& { if (!has_value()) { - throw std::runtime_error{"bad Optional access"}; + throw std::bad_optional_access{}; } return mValue; } [[nodiscard]] constexpr T& get() & { if (!has_value()) { - throw std::runtime_error{"bad Optional access"}; + throw std::bad_optional_access{}; } return mValue; } [[nodiscard]] constexpr T const&& get() const&& { if (!has_value()) { - throw std::runtime_error{"bad Optional access"}; + throw std::bad_optional_access{}; } return std::move(mValue); } [[nodiscard]] constexpr T&& get() && { if (!has_value()) { - throw std::runtime_error{"bad Optional access"}; + throw std::bad_optional_access{}; } return std::move(mValue); } diff --git a/src/ll/api/command/runtime/ParamKind.h b/src/ll/api/command/runtime/ParamKind.h index 0689587849..c06157ce3d 100644 --- a/src/ll/api/command/runtime/ParamKind.h +++ b/src/ll/api/command/runtime/ParamKind.h @@ -53,6 +53,7 @@ enum Kind : ParamKindType { FilePath, WildcardInt, WildcardActor, + // New types can only be added here, to keep the ABI stable. Count, }; } // namespace ParamKind @@ -82,7 +83,9 @@ using ParamKindList = meta::TypeList< CommandIntegerRange, CommandFilePath, CommandWildcardInt, - WildcardCommandSelector>; + WildcardCommandSelector + // New types can only be added here, to keep the ABI stable. + >; class ParamStorageType : public Optional> { public: diff --git a/src/ll/api/reflection/TypeName.h b/src/ll/api/reflection/TypeName.h index 24701f5499..d3c8756626 100644 --- a/src/ll/api/reflection/TypeName.h +++ b/src/ll/api/reflection/TypeName.h @@ -14,7 +14,7 @@ template consteval std::string_view getRawName() noexcept { #if defined(_MSC_VER) constexpr std::string_view n{__FUNCSIG__}; - constexpr std::string_view k{"name_of_impl<"}; + constexpr std::string_view k{"getRawName<"}; constexpr std::string_view l{">(void) noexcept"}; #else constexpr std::string_view n{__PRETTY_FUNCTION__}; @@ -30,7 +30,7 @@ template consteval std::string_view getRawName() noexcept { #if defined(_MSC_VER) constexpr std::string_view n{__FUNCSIG__}; - constexpr std::string_view k{"name_of_impl<"}; + constexpr std::string_view k{"getRawName<"}; constexpr std::string_view l{">(void) noexcept"}; #else constexpr std::string_view n{__PRETTY_FUNCTION__}; diff --git a/src/ll/api/utils/StacktraceUtils_win.cpp b/src/ll/api/utils/StacktraceUtils_win.cpp index 5223cd92f5..2d4d036fe1 100644 --- a/src/ll/api/utils/StacktraceUtils_win.cpp +++ b/src/ll/api/utils/StacktraceUtils_win.cpp @@ -214,23 +214,25 @@ SymbolLoader::~SymbolLoader() { StackTraceEntryInfo getInfo(StacktraceEntry const& entry) { DbgEngData data; + if (!data.tryInit()) { + return {}; + } + auto res = data.getInfo(entry.native_handle()); + if (res.name.contains('!')) { + return res; + } static auto processRange = sys_utils::getImageRange(); - if (&*processRange.begin() <= entry.native_handle() && entry.native_handle() < &*processRange.end()) { size_t length{}; uint disp{}; auto str = pl::symbol_provider::pl_lookup_symbol_disp(entry.native_handle(), &length, &disp); if (length) { - static auto processName = sys_utils::getModuleFileName(nullptr); - StackTraceEntryInfo res{disp, processName + '!' + str[0]}; + static auto processName = sys_utils::getModuleFileName(nullptr); + res = {disp, processName + '!' + str[0]}; pl::symbol_provider::pl_free_lookup_result(str); - return res; } } - if (!data.tryInit()) { - return {}; - } - return data.getInfo(entry.native_handle()); + return res; } std::string toString(StacktraceEntry const& entry) { diff --git a/src/mc/common/wrapper/optional_ref.h b/src/mc/common/wrapper/optional_ref.h index ff82dfd3c0..c4ff86278d 100644 --- a/src/mc/common/wrapper/optional_ref.h +++ b/src/mc/common/wrapper/optional_ref.h @@ -63,7 +63,7 @@ class optional_ref { [[nodiscard]] constexpr T& value() const { if (!has_value()) { - throw std::runtime_error{"bad optional_ref access"}; + throw std::bad_optional_access{}; } return *mPtr; } diff --git a/src/mc/server/SimulatedPlayer.cpp b/src/mc/server/SimulatedPlayer.cpp index fcf4ae34e6..815159d045 100644 --- a/src/mc/server/SimulatedPlayer.cpp +++ b/src/mc/server/SimulatedPlayer.cpp @@ -12,14 +12,10 @@ optional_ref SimulatedPlayer::create( DimensionType dimId, Vec2 const& rotation ) { - if (!ll::service::getServerNetworkHandler()) { - return nullptr; - } - auto ownerPtr = ll::service::getServerNetworkHandler()->createSimulatedPlayer( - name, - std::to_string(ll::random_utils::rand(INT64_MIN, -1)) - ); - auto player = ownerPtr.tryUnwrap(); + auto ownerPtr = ll::service::getServerNetworkHandler().and_then([&](auto& handler) { + return handler.createSimulatedPlayer(name, std::to_string(ll::random_utils::rand(INT64_MIN, -1))); + }); + auto player = ownerPtr.tryUnwrap(); if (!player) { return nullptr; } diff --git a/src/mc/world/actor/player/Player.cpp b/src/mc/world/actor/player/Player.cpp index 87a8ba3c4d..76d6fe42f6 100644 --- a/src/mc/world/actor/player/Player.cpp +++ b/src/mc/world/actor/player/Player.cpp @@ -56,14 +56,9 @@ std::string Player::getLocaleCode() const { } std::optional Player::getNetworkStatus() const { - if (!ll::service::getNetworkSystem()) { - return std::nullopt; - } - auto peer = ll::service::getNetworkSystem()->getPeerForUser(getNetworkIdentifier()); - if (!peer) { - return std::nullopt; - } - return peer->getNetworkStatus(); + return ll::service::getNetworkSystem() + .transform([&](auto& system) { return system.getPeerForUser(getNetworkIdentifier()); }) + .transform([](auto& peer) { return peer.getNetworkStatus(); }); } std::string Player::getRealName() const { @@ -75,15 +70,15 @@ std::string Player::getRealName() const { } void Player::disconnect(std::string_view reason) const { - if (!ll::service::getServerNetworkHandler()) { - return; - } - ll::service::getServerNetworkHandler()->disconnectClient( - getNetworkIdentifier(), - Connection::DisconnectFailReason::Unknown, - std::string{reason}, - false - ); + ll::service::getServerNetworkHandler().and_then([&](auto& handler) { + handler.disconnectClient( + getNetworkIdentifier(), + Connection::DisconnectFailReason::Unknown, + std::string{reason}, + false + ); + return true; + }); } void Player::sendMessage(std::string_view msg) const { TextPacket::createRawMessage(msg).sendTo(*this); } diff --git a/src/mc/world/level/BlockSource.h b/src/mc/world/level/BlockSource.h index 8dab749dcd..d3a32d7ef8 100644 --- a/src/mc/world/level/BlockSource.h +++ b/src/mc/world/level/BlockSource.h @@ -63,78 +63,78 @@ class BlockSource : public IBlockSource, public std::enable_shared_from_this&, class AABB const& intersectTestBox, bool withUnloadedChunks) const; // vIndex: 21 - virtual void + MCVAPI void fetchCollisionShapes(std::vector&, class AABB const&, bool, class optional_ref, std::vector*) const; // vIndex: 22 - virtual void + MCVAPI void fetchCollisionShapesAndBlocks(std::vector&, class AABB const&, bool, class optional_ref, std::vector*) const; // vIndex: 23 - virtual class AABB getTallestCollisionShape( + MCVAPI class AABB getTallestCollisionShape( class AABB const& intersectTestBox, float* actualSurfaceOffset, bool withUnloadedChunks, @@ -142,10 +142,10 @@ class BlockSource : public IBlockSource, public std::enable_shared_from_this& fetchAABBs(class AABB const& intersectTestBox, bool withUnloadedChunks); + MCVAPI std::vector& fetchAABBs(class AABB const& intersectTestBox, bool withUnloadedChunks); // vIndex: 27 - virtual std::vector& + MCVAPI std::vector& fetchCollisionShapes(class AABB const&, bool, std::optional, std::vector*); // vIndex: 28 - virtual class WeakRef getWeakRef(); + MCVAPI class WeakRef getWeakRef(); // vIndex: 29 - virtual void addListener(class BlockSourceListener& l); + MCVAPI void addListener(class BlockSourceListener& l); // vIndex: 30 - virtual void removeListener(class BlockSourceListener& l); + MCVAPI void removeListener(class BlockSourceListener& l); // vIndex: 31 - virtual gsl::span> + MCVAPI gsl::span> fetchEntities(class Actor const* except, class AABB const& bb, bool useHitbox, bool); // vIndex: 32 - virtual gsl::span> + MCVAPI gsl::span> fetchEntities(::ActorType, class AABB const&, class Actor const*, std::function); // vIndex: 33 - virtual bool + MCVAPI bool setBlock(class BlockPos const& pos, class Block const& block, int updateFlags, struct ActorBlockSyncMessage const* syncMsg, class Actor*); // vIndex: 34 - virtual short getMinHeight() const; + MCVAPI short getMinHeight() const; // vIndex: 35 - virtual short getMaxHeight() const; + MCVAPI short getMaxHeight() const; // vIndex: 36 - virtual class Dimension& getDimension() const; + MCVAPI class Dimension& getDimension() const; // vIndex: 37 - virtual class Dimension& getDimension(); + MCVAPI class Dimension& getDimension(); // vIndex: 38 - virtual class Dimension const& getDimensionConst() const; + MCVAPI class Dimension const& getDimensionConst() const; // vIndex: 39 - virtual class LevelChunk* getChunk(int x, int z) const; + MCVAPI class LevelChunk* getChunk(int x, int z) const; // vIndex: 40 - virtual class LevelChunk* getChunk(class ChunkPos const& pos) const; + MCVAPI class LevelChunk* getChunk(class ChunkPos const& pos) const; // vIndex: 41 - virtual class Level& getLevel(); + MCVAPI class Level& getLevel(); // vIndex: 42 - virtual class ILevel& getILevel() const; + MCVAPI class ILevel& getILevel() const; // vIndex: 43 - virtual class HitResult clip( + MCVAPI class HitResult clip( class Vec3 const& startPos, class Vec3 const& endPos, bool checkAgainstLiquid, @@ -221,31 +221,31 @@ class BlockSource : public IBlockSource, public std::enable_shared_from_this