From 8db100a2d21b33589f161e05c1da8cb32a0c9e0a Mon Sep 17 00:00:00 2001 From: RimuruChan <42002296+RimuruChan@users.noreply.github.com> Date: Thu, 18 Jan 2024 23:00:49 +0800 Subject: [PATCH] refactor: create new pch file and fix some header include problem (#1440) --- .clangd | 16 +++++++------- .gitignore | 3 +++ src/ll/api/Global.h | 10 +++++++++ src/ll/api/Logger.cpp | 6 ++--- .../{UnorderedStringMap.h => Containers.h} | 0 src/ll/api/command/DynamicCommand.cpp | 4 ++-- src/ll/api/{base => data}/DependencyGraph.h | 5 ++--- src/ll/api/{base => data}/KeyValueDB.cpp | 2 +- src/ll/api/{base => data}/KeyValueDB.h | 4 ++-- src/ll/api/{base => data}/Version.h | 4 ++-- src/ll/api/event/EventBus.cpp | 6 ++--- src/ll/api/event/EventId.h | 4 ++-- .../api/event/filesystem/FileActionEvent.cpp | 8 +++---- .../api/event/server/ServerStartedEvent.cpp | 2 +- .../api/event/server/ServerStoppingEvent.cpp | 2 +- src/ll/api/form/ModalForm.cpp | 12 +++++----- src/ll/api/i18n/I18nAPI.h | 2 +- src/ll/api/io/FileUtils.cpp | 2 +- src/ll/api/io/FileUtils.h | 2 +- src/ll/api/memory/Hook.cpp | 2 +- src/ll/api/memory/Memory.cpp | 2 +- src/ll/api/memory/PatchHelper.h | 8 +++---- src/ll/api/plugin/Manifest.h | 6 ++--- src/ll/api/plugin/Plugin.cpp | 2 +- src/ll/api/plugin/Plugin.h | 2 +- src/ll/api/plugin/PluginManager.h | 2 +- src/ll/api/plugin/PluginManagerRegistry.h | 2 +- src/ll/api/schedule/Task.cpp | 4 ++-- src/ll/api/service/Bedrock.cpp | 2 +- src/ll/api/service/PlayerInfo.cpp | 2 +- src/ll/api/{ => service}/ServerInfo.cpp | 2 +- src/ll/api/{ => service}/ServerInfo.h | 2 +- src/ll/api/service/ServiceId.h | 4 ++-- src/ll/api/service/ServiceManager.cpp | 4 ++-- src/ll/api/thread/GlobalThreadPauser.cpp | 4 ++-- src/ll/api/thread/ThreadPool.h | 4 ++-- src/ll/api/thread/TickSyncSleep.h | 4 ++-- .../{base/Base64.h => utils/Base64Utils.h} | 4 ++-- .../ErrorInfo.cpp => utils/ErrorUtils.cpp} | 8 +++---- .../{base/ErrorInfo.h => utils/ErrorUtils.h} | 4 ++-- src/ll/api/{base/Hash.h => utils/HashUtils.h} | 6 ++--- .../{base/Random.h => utils/RandomUtils.h} | 4 ++-- src/ll/api/utils/StacktraceUtils.cpp | 6 ++--- src/ll/api/utils/StacktraceUtils.h | 2 ++ src/ll/api/utils/StringUtils.h | 1 + src/ll/api/utils/WinUtils.h | 2 ++ src/ll/core/Config.cpp | 6 ++--- src/ll/core/CrashLogger.cpp | 22 +++++++++---------- src/ll/core/LeviLamina.cpp | 10 ++++----- src/ll/core/plugin/NativePluginManager.cpp | 6 ++--- src/ll/core/plugin/PluginRegistrar.cpp | 12 +++++----- src/ll/core/tweak/BuiltinCommands.cpp | 2 +- src/ll/core/tweak/ModifyInfomation.cpp | 2 +- src/ll/test/ConfigTest.cpp | 6 ++--- src/ll/test/EventTest.cpp | 6 ++--- src/ll/test/PtrTest.cpp | 10 ++++----- src/ll/test/ScheduleTest.cpp | 14 ++++++------ src/ll/test/TestDynamicCommand.cpp | 4 ++-- src/mc/deps/core/mce/UUID.cpp | 4 ++-- src/mc/deps/core/mce/UUID.h | 4 ++-- .../math/vector/component/base/VectorBase.h | 12 ++++++---- src/mc/nbt/SnbtDumpImpl.cpp | 4 ++-- src/mc/nbt/SnbtParseImpl.cpp | 8 +++---- src/mc/server/SimulatedPlayer.cpp | 4 ++-- src/mc/server/commands/CommandRegistry.cpp | 4 ++-- xmake.lua | 2 +- 66 files changed, 176 insertions(+), 155 deletions(-) create mode 100644 src/ll/api/Global.h rename src/ll/api/base/{UnorderedStringMap.h => Containers.h} (100%) rename src/ll/api/{base => data}/DependencyGraph.h (98%) rename src/ll/api/{base => data}/KeyValueDB.cpp (99%) rename src/ll/api/{base => data}/KeyValueDB.h (94%) rename src/ll/api/{base => data}/Version.h (99%) rename src/ll/api/{ => service}/ServerInfo.cpp (97%) rename src/ll/api/{ => service}/ServerInfo.h (93%) rename src/ll/api/{base/Base64.h => utils/Base64Utils.h} (96%) rename src/ll/api/{base/ErrorInfo.cpp => utils/ErrorUtils.cpp} (98%) rename src/ll/api/{base/ErrorInfo.h => utils/ErrorUtils.h} (97%) rename src/ll/api/{base/Hash.h => utils/HashUtils.h} (90%) rename src/ll/api/{base/Random.h => utils/RandomUtils.h} (95%) diff --git a/.clangd b/.clangd index 797c8f303f..fec3985a31 100644 --- a/.clangd +++ b/.clangd @@ -1,15 +1,15 @@ Diagnostics: - Suppress: + Suppress: - "-Wmicrosoft-enum-forward-reference" - "-Wc++11-narrowing" - "-Wc++2b-extensions" - "-Wmicrosoft-cast" CompileFlags: - Add: + Add: - "-ferror-limit=0" - - "-D__FUNCTION__=\"dummy\"" - - "-Yumc/_HeaderOutputPredefine.h" - - "-FImc/_HeaderOutputPredefine.h" # clangd bug can't find pch file - Remove: - - "/Yu_HeaderOutputPredefine.h" - - "/FI_HeaderOutputPredefine.h" + - '-D__FUNCTION__="dummy"' + - "-Yusrc/ll/api/Global.h" + - "-FIsrc/ll/api/Global.h" # clangd bug can't find pch file + Remove: + - "/YuGlobal.h" + - "/FIGlobal.h" diff --git a/.gitignore b/.gitignore index 4f80a4cf3d..214ac9e3c8 100644 --- a/.gitignore +++ b/.gitignore @@ -557,3 +557,6 @@ fabric.properties # MkDocs /site/ + +# Test +src/ll/test/include_all.cpp diff --git a/src/ll/api/Global.h b/src/ll/api/Global.h new file mode 100644 index 0000000000..f8589db0aa --- /dev/null +++ b/src/ll/api/Global.h @@ -0,0 +1,10 @@ +#pragma once + +#include "mc/_HeaderOutputPredefine.h" + +#include "ll/api/base/Concepts.h" +#include "ll/api/base/Containers.h" +#include "ll/api/base/Macro.h" +#include "ll/api/base/Meta.h" +#include "ll/api/base/StdInt.h" +#include "ll/api/base/ToString.h" diff --git a/src/ll/api/Logger.cpp b/src/ll/api/Logger.cpp index 2c033967df..1be0ef7cdd 100644 --- a/src/ll/api/Logger.cpp +++ b/src/ll/api/Logger.cpp @@ -2,9 +2,9 @@ #include "ll/api/Logger.h" -#include "ll/api/base/ErrorInfo.h" -#include "ll/api/base/Hash.h" #include "ll/api/io/FileUtils.h" +#include "ll/api/utils/ErrorUtils.h" +#include "ll/api/utils/HashUtils.h" #include "ll/api/utils/StringUtils.h" #include "ll/core/Config.h" @@ -68,7 +68,7 @@ void Logger::OutputStream::print(std::string_view s) const noexcept { try { fmt::print( "\x1b[31mERROR IN LOGGER API:\n{}\x1b[91m\n{}\x1b[0m\n", - error_info::makeExceptionString(std::current_exception()), + error_utils::makeExceptionString(std::current_exception()), tou8str(s) ); } catch (...) { diff --git a/src/ll/api/base/UnorderedStringMap.h b/src/ll/api/base/Containers.h similarity index 100% rename from src/ll/api/base/UnorderedStringMap.h rename to src/ll/api/base/Containers.h diff --git a/src/ll/api/command/DynamicCommand.cpp b/src/ll/api/command/DynamicCommand.cpp index 14369eb1f2..3729649d75 100644 --- a/src/ll/api/command/DynamicCommand.cpp +++ b/src/ll/api/command/DynamicCommand.cpp @@ -1,8 +1,8 @@ #include "ll/api/command/DynamicCommand.h" #include "ll/api/Logger.h" -#include "ll/api/base/ErrorInfo.h" #include "ll/api/memory/Closure.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/core/Config.h" #include "ll/core/LeviLamina.h" @@ -97,7 +97,7 @@ auto const ParameterSizeMap = std::unordered_map{ inline void OutputError(const std::string& command, const std::string& func = __builtin_FUNCTION()) { auto lock = ll::Logger::lock(); - ll::error_info::printCurrentException(logger); + ll::error_utils::printCurrentException(logger); logger.error("In Function ({})", func); logger.error("In Command <{}>", command); } diff --git a/src/ll/api/base/DependencyGraph.h b/src/ll/api/data/DependencyGraph.h similarity index 98% rename from src/ll/api/base/DependencyGraph.h rename to src/ll/api/data/DependencyGraph.h index 0f89093886..f7937a0970 100644 --- a/src/ll/api/base/DependencyGraph.h +++ b/src/ll/api/data/DependencyGraph.h @@ -1,11 +1,10 @@ #pragma once -#include #include #include #include -namespace ll { +namespace ll::inline data { template class DependencyGraph { struct Data { @@ -121,4 +120,4 @@ class DependencyGraph { return {sorted, unsorted}; } }; -} // namespace ll +} // namespace ll::inline data diff --git a/src/ll/api/base/KeyValueDB.cpp b/src/ll/api/data/KeyValueDB.cpp similarity index 99% rename from src/ll/api/base/KeyValueDB.cpp rename to src/ll/api/data/KeyValueDB.cpp index fb467e4814..17411dbe49 100644 --- a/src/ll/api/base/KeyValueDB.cpp +++ b/src/ll/api/data/KeyValueDB.cpp @@ -10,7 +10,7 @@ #include "ll/api/io/FileUtils.h" #include "ll/core/LeviLamina.h" -using namespace ll; +using namespace ll::data; class KeyValueDB::KeyValueDBImpl { public: diff --git a/src/ll/api/base/KeyValueDB.h b/src/ll/api/data/KeyValueDB.h similarity index 94% rename from src/ll/api/base/KeyValueDB.h rename to src/ll/api/data/KeyValueDB.h index e4314b902a..7b82c0743e 100644 --- a/src/ll/api/base/KeyValueDB.h +++ b/src/ll/api/data/KeyValueDB.h @@ -9,7 +9,7 @@ #include "ll/api/base/Macro.h" -namespace ll { +namespace ll::inline data { class KeyValueDB { private: class KeyValueDBImpl; @@ -40,4 +40,4 @@ class KeyValueDB { LLNDAPI std::vector getAllKeys() const; }; -} // namespace ll +} // namespace ll::inline data diff --git a/src/ll/api/base/Version.h b/src/ll/api/data/Version.h similarity index 99% rename from src/ll/api/base/Version.h rename to src/ll/api/data/Version.h index 1feca804b4..c47662b3c9 100644 --- a/src/ll/api/base/Version.h +++ b/src/ll/api/data/Version.h @@ -9,7 +9,7 @@ #include "ll/api/utils/StringUtils.h" -namespace ll { +namespace ll::inline data { namespace detail { @@ -301,4 +301,4 @@ namespace literals { } } // namespace literals -} // namespace ll +} // namespace ll::inline data diff --git a/src/ll/api/event/EventBus.cpp b/src/ll/api/event/EventBus.cpp index 686a9419e4..1b0e532c2e 100644 --- a/src/ll/api/event/EventBus.cpp +++ b/src/ll/api/event/EventBus.cpp @@ -6,9 +6,9 @@ #include #include "ll/api/Logger.h" -#include "ll/api/base/ErrorInfo.h" #include "ll/api/event/EmitterBase.h" #include "ll/api/thread/SharedRecursiveMutex.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/core/LeviLamina.h" namespace ll::event { @@ -43,7 +43,7 @@ class CallbackStream { l->pluginPtr.expired() ? "unknown plugin" : l->pluginPtr.lock()->getManifest().name ); } catch (...) {} - error_info::printCurrentException(logger); + error_utils::printCurrentException(logger); } } } @@ -66,7 +66,7 @@ class CallbackStream { pluginName ); } catch (...) {} - error_info::printCurrentException(logger); + error_utils::printCurrentException(logger); } } } diff --git a/src/ll/api/event/EventId.h b/src/ll/api/event/EventId.h index bd41ace06f..00fe01b81c 100644 --- a/src/ll/api/event/EventId.h +++ b/src/ll/api/event/EventId.h @@ -1,7 +1,7 @@ #pragma once -#include "ll/api/base/Hash.h" #include "ll/api/reflection/Reflection.h" +#include "ll/api/utils/HashUtils.h" namespace ll::event { class EventId { @@ -11,7 +11,7 @@ class EventId { [[nodiscard]] constexpr explicit EventId(std::string_view name) noexcept : name(name), - hash(ll::hash::do_hash(name)) {} + hash(ll::hash_utils::do_hash(name)) {} [[nodiscard]] constexpr bool operator==(EventId other) const noexcept { return hash == other.hash && name == other.name; diff --git a/src/ll/api/event/filesystem/FileActionEvent.cpp b/src/ll/api/event/filesystem/FileActionEvent.cpp index ea0afc1383..176024849c 100644 --- a/src/ll/api/event/filesystem/FileActionEvent.cpp +++ b/src/ll/api/event/filesystem/FileActionEvent.cpp @@ -13,10 +13,10 @@ #include #include -#include "ll/api/base/ErrorInfo.h" #include "ll/api/event/Emitter.h" #include "ll/api/event/EventBus.h" #include "ll/api/io/FileUtils.h" +#include "ll/api/utils/ErrorUtils.h" #include "windows.h" @@ -58,7 +58,7 @@ class FileWatcher : public Emitter { closeEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr); if (!closeEvent) { - throw ll::error_info::getWinLastError(); + throw ll::error_utils::getWinLastError(); } @@ -121,7 +121,7 @@ class FileWatcher : public Emitter { switch (WaitForMultipleObjects(2, handles.data(), FALSE, INFINITE)) { case WAIT_OBJECT_0: { if (!GetOverlappedResult(directoryHandle, &overlapped_buffer, &bytes_returned, TRUE)) { - throw ll::error_info::getWinLastError(); + throw ll::error_utils::getWinLastError(); } async_pending = false; @@ -224,7 +224,7 @@ class FileWatcher : public Emitter { ); // file with attributes to copy if (directory == INVALID_HANDLE_VALUE) { - throw ll::error_info::getWinLastError(); + throw ll::error_utils::getWinLastError(); } return directory; } diff --git a/src/ll/api/event/server/ServerStartedEvent.cpp b/src/ll/api/event/server/ServerStartedEvent.cpp index f1cb9aeb78..e52074cc4a 100644 --- a/src/ll/api/event/server/ServerStartedEvent.cpp +++ b/src/ll/api/event/server/ServerStartedEvent.cpp @@ -1,7 +1,7 @@ #include "ll/api/event/server/ServerStartedEvent.h" -#include "ll/api/ServerInfo.h" #include "ll/api/event/Emitter.h" #include "ll/api/memory/Hook.h" +#include "ll/api/service/ServerInfo.h" #include "mc/world/events/ServerInstanceEventCoordinator.h" diff --git a/src/ll/api/event/server/ServerStoppingEvent.cpp b/src/ll/api/event/server/ServerStoppingEvent.cpp index 1b7a3926c2..7b39ee8bae 100644 --- a/src/ll/api/event/server/ServerStoppingEvent.cpp +++ b/src/ll/api/event/server/ServerStoppingEvent.cpp @@ -1,7 +1,7 @@ #include "ll/api/event/server/ServerStoppingEvent.h" -#include "ll/api/ServerInfo.h" #include "ll/api/event/Emitter.h" #include "ll/api/memory/Hook.h" +#include "ll/api/service/ServerInfo.h" #include "mc/nbt/CompoundTag.h" diff --git a/src/ll/api/form/ModalForm.cpp b/src/ll/api/form/ModalForm.cpp index 84fb47b8b5..8a90a87721 100644 --- a/src/ll/api/form/ModalForm.cpp +++ b/src/ll/api/form/ModalForm.cpp @@ -82,12 +82,12 @@ ModalForm::ModalForm( Callback callback ) : impl(std::make_unique( - std::move(title), - std::move(content), - std::move(buttonLeft), - std::move(buttonRight), - std::move(callback) -)) {} + std::move(title), + std::move(content), + std::move(buttonLeft), + std::move(buttonRight), + std::move(callback) + )) {} ModalForm::~ModalForm() = default; diff --git a/src/ll/api/i18n/I18nAPI.h b/src/ll/api/i18n/I18nAPI.h index 1a70e6a965..e51866cac4 100644 --- a/src/ll/api/i18n/I18nAPI.h +++ b/src/ll/api/i18n/I18nAPI.h @@ -1,7 +1,7 @@ #pragma once #include "ll/api/base/Concepts.h" -#include "ll/api/base/UnorderedStringMap.h" +#include "ll/api/base/Containers.h" #include "ll/api/io/FileUtils.h" #include "ll/api/utils/StringUtils.h" diff --git a/src/ll/api/io/FileUtils.cpp b/src/ll/api/io/FileUtils.cpp index ca65ffe673..0de4bfc623 100644 --- a/src/ll/api/io/FileUtils.cpp +++ b/src/ll/api/io/FileUtils.cpp @@ -3,7 +3,7 @@ #include #include "ll/api/Logger.h" -#include "ll/api/ServerInfo.h" +#include "ll/api/service/ServerInfo.h" #include "ll/api/utils/StringUtils.h" #include "ll/core/Config.h" diff --git a/src/ll/api/io/FileUtils.h b/src/ll/api/io/FileUtils.h index 155862fa27..89deb63725 100644 --- a/src/ll/api/io/FileUtils.h +++ b/src/ll/api/io/FileUtils.h @@ -7,7 +7,7 @@ #include #include "ll/api/base/Macro.h" -#include "ll/api/base/Version.h" +#include "ll/api/data/Version.h" namespace ll::inline utils::file_utils { diff --git a/src/ll/api/memory/Hook.cpp b/src/ll/api/memory/Hook.cpp index 69f17f5f44..b0f02830d2 100644 --- a/src/ll/api/memory/Hook.cpp +++ b/src/ll/api/memory/Hook.cpp @@ -1,7 +1,7 @@ #include "ll/api/memory/Hook.h" #include "ll/api/Logger.h" -#include "ll/api/ServerInfo.h" #include "ll/api/memory/Memory.h" +#include "ll/api/service/ServerInfo.h" #include "ll/api/utils/StacktraceUtils.h" #include "ll/api/utils/WinUtils.h" #include "pl/Hook.h" diff --git a/src/ll/api/memory/Memory.cpp b/src/ll/api/memory/Memory.cpp index deb4622b2d..81a910da79 100644 --- a/src/ll/api/memory/Memory.cpp +++ b/src/ll/api/memory/Memory.cpp @@ -6,7 +6,7 @@ #include "pl/SymbolProvider.h" #include "ll/api/Logger.h" -#include "ll/api/ServerInfo.h" +#include "ll/api/service/ServerInfo.h" #include "ll/api/thread/GlobalThreadPauser.h" #include "ll/api/utils/StringUtils.h" #include "ll/api/utils/WinUtils.h" diff --git a/src/ll/api/memory/PatchHelper.h b/src/ll/api/memory/PatchHelper.h index 5cfae1a882..b7e4c4932a 100644 --- a/src/ll/api/memory/PatchHelper.h +++ b/src/ll/api/memory/PatchHelper.h @@ -51,11 +51,11 @@ namespace ll::utils { template struct PatchHelper { - uchar data[len]; + uchar data[len]; using ref_t = uchar (&)[len]; - constexpr bool operator==(ref_t ref) const noexcept { return memcmp(data, ref, sizeof data) == 0; } - constexpr bool operator!=(ref_t ref) const noexcept { return memcmp(data, ref, sizeof data) != 0; } - constexpr bool operator==(PatchHelper const& ref) const noexcept { + constexpr bool operator==(ref_t ref) const noexcept { return memcmp(data, ref, sizeof data) == 0; } + constexpr bool operator!=(ref_t ref) const noexcept { return memcmp(data, ref, sizeof data) != 0; } + constexpr bool operator==(PatchHelper const& ref) const noexcept { return memcmp(data, ref.data, sizeof data) == 0; } constexpr bool operator!=(PatchHelper const& ref) const noexcept { diff --git a/src/ll/api/plugin/Manifest.h b/src/ll/api/plugin/Manifest.h index a80749f3f1..2599ecfeb0 100644 --- a/src/ll/api/plugin/Manifest.h +++ b/src/ll/api/plugin/Manifest.h @@ -5,8 +5,8 @@ #include #include -#include "ll/api/base/Hash.h" -#include "ll/api/base/Version.h" +#include "ll/api/data/Version.h" +#include "ll/api/utils/HashUtils.h" namespace ll::plugin { struct Dependency { @@ -23,7 +23,7 @@ template <> struct hash { size_t operator()(ll::plugin::Dependency const& d) const noexcept { size_t hash = std::hash{}(d.name); - ll::hash::hashCombine(std::hash>{}(d.version), hash); + ll::hash_utils::hashCombine(std::hash>{}(d.version), hash); return hash; } }; diff --git a/src/ll/api/plugin/Plugin.cpp b/src/ll/api/plugin/Plugin.cpp index 3d0ac02a1e..874c56362e 100644 --- a/src/ll/api/plugin/Plugin.cpp +++ b/src/ll/api/plugin/Plugin.cpp @@ -1,9 +1,9 @@ #include "ll/api/plugin/Plugin.h" -#include "ll/api/ServerInfo.h" #include "ll/api/event/EventBus.h" #include "ll/api/event/server/ServerStartedEvent.h" #include "ll/api/service/Bedrock.h" +#include "ll/api/service/ServerInfo.h" namespace ll::plugin { diff --git a/src/ll/api/plugin/Plugin.h b/src/ll/api/plugin/Plugin.h index 8561ae4c78..d4599dddb3 100644 --- a/src/ll/api/plugin/Plugin.h +++ b/src/ll/api/plugin/Plugin.h @@ -4,7 +4,7 @@ #include #include "ll/api/Logger.h" -#include "ll/api/base/UnorderedStringMap.h" +#include "ll/api/base/Containers.h" #include "ll/api/plugin/Manifest.h" #include "mc/common/wrapper/optional_ref.h" diff --git a/src/ll/api/plugin/PluginManager.h b/src/ll/api/plugin/PluginManager.h index f874bb00b1..a6d6401a2a 100644 --- a/src/ll/api/plugin/PluginManager.h +++ b/src/ll/api/plugin/PluginManager.h @@ -6,7 +6,7 @@ #include #include -#include "ll/api/base/UnorderedStringMap.h" +#include "ll/api/base/Containers.h" #include "ll/api/plugin/Plugin.h" namespace ll::plugin { diff --git a/src/ll/api/plugin/PluginManagerRegistry.h b/src/ll/api/plugin/PluginManagerRegistry.h index 81ad15daa3..8242ac2a45 100644 --- a/src/ll/api/plugin/PluginManagerRegistry.h +++ b/src/ll/api/plugin/PluginManagerRegistry.h @@ -1,7 +1,7 @@ #pragma once -#include "ll/api/base/DependencyGraph.h" #include "ll/api/base/Macro.h" +#include "ll/api/data/DependencyGraph.h" #include "ll/api/plugin/PluginManager.h" namespace ll::plugin { diff --git a/src/ll/api/schedule/Task.cpp b/src/ll/api/schedule/Task.cpp index 819b79b13e..2747c31b4d 100644 --- a/src/ll/api/schedule/Task.cpp +++ b/src/ll/api/schedule/Task.cpp @@ -3,7 +3,7 @@ #include #include "ll/api/Logger.h" -#include "ll/api/base/ErrorInfo.h" +#include "ll/api/utils/ErrorUtils.h" namespace ll::schedule { inline namespace task { @@ -42,7 +42,7 @@ void printScheduleError() noexcept { try { logger.error("Error in schedule thread [{}]:", std::this_thread::get_id()); } catch (...) {} - error_info::printCurrentException(logger); + error_utils::printCurrentException(logger); } } // namespace detail diff --git a/src/ll/api/service/Bedrock.cpp b/src/ll/api/service/Bedrock.cpp index 418d47cc00..e7183f9c64 100644 --- a/src/ll/api/service/Bedrock.cpp +++ b/src/ll/api/service/Bedrock.cpp @@ -16,9 +16,9 @@ #include "mc/world/Minecraft.h" #include "mc/world/events/ServerInstanceEventCoordinator.h" -#include "ll/api/base/Hash.h" #include "ll/api/memory/Hook.h" #include "ll/api/reflection/Reflection.h" +#include "ll/api/utils/HashUtils.h" #include "ll/core/LeviLamina.h" namespace ll::service::inline bedrock { diff --git a/src/ll/api/service/PlayerInfo.cpp b/src/ll/api/service/PlayerInfo.cpp index c59318a597..ab4c2f3da7 100644 --- a/src/ll/api/service/PlayerInfo.cpp +++ b/src/ll/api/service/PlayerInfo.cpp @@ -2,7 +2,7 @@ #include -#include "ll/api/base/KeyValueDB.h" +#include "ll/api/data/KeyValueDB.h" #include "ll/api/event/EventBus.h" #include "ll/api/event/player/PlayerJoinEvent.h" diff --git a/src/ll/api/ServerInfo.cpp b/src/ll/api/service/ServerInfo.cpp similarity index 97% rename from src/ll/api/ServerInfo.cpp rename to src/ll/api/service/ServerInfo.cpp index 76f693bba9..9a77b5df24 100644 --- a/src/ll/api/ServerInfo.cpp +++ b/src/ll/api/service/ServerInfo.cpp @@ -1,4 +1,4 @@ -#include "ll/api/ServerInfo.h" +#include "ll/api/service/ServerInfo.h" #include "ll/api/service/Bedrock.h" #include "ll/core/Version.h" #include "mc/common/BuildInfo.h" diff --git a/src/ll/api/ServerInfo.h b/src/ll/api/service/ServerInfo.h similarity index 93% rename from src/ll/api/ServerInfo.h rename to src/ll/api/service/ServerInfo.h index 57fbb14051..0980871728 100644 --- a/src/ll/api/ServerInfo.h +++ b/src/ll/api/service/ServerInfo.h @@ -2,7 +2,7 @@ #include -#include "ll/api/base/Version.h" +#include "ll/api/data/Version.h" namespace ll { enum class ServerStatus { diff --git a/src/ll/api/service/ServiceId.h b/src/ll/api/service/ServiceId.h index e97ea33a90..68f36ea850 100644 --- a/src/ll/api/service/ServiceId.h +++ b/src/ll/api/service/ServiceId.h @@ -1,7 +1,7 @@ #pragma once -#include "ll/api/base/Hash.h" #include "ll/api/reflection/Reflection.h" +#include "ll/api/utils/HashUtils.h" namespace ll::service { @@ -17,7 +17,7 @@ class ServiceId { [[nodiscard]] constexpr ServiceId(std::string_view name, size_t version) noexcept : name(name), version(version), - hash(ll::hash::hashCombine(ll::hash::do_hash(name), version)) {} + hash(ll::hash_utils::hashCombine(ll::hash_utils::do_hash(name), version)) {} template [[nodiscard]] constexpr ServiceId(auto_name_t, size_t version) noexcept diff --git a/src/ll/api/service/ServiceManager.cpp b/src/ll/api/service/ServiceManager.cpp index cb8f76ac32..0b4e9dacca 100644 --- a/src/ll/api/service/ServiceManager.cpp +++ b/src/ll/api/service/ServiceManager.cpp @@ -34,8 +34,8 @@ namespace std { template <> struct hash { size_t operator()(ll::service::ServiceInfo const& info) const noexcept { - return ll::hash::hashCombine( - ll::hash::hashCombine(std::hash{}(info.name), std::hash{}(info.version)), + return ll::hash_utils::hashCombine( + ll::hash_utils::hashCombine(std::hash{}(info.name), std::hash{}(info.version)), std::hash{}(info.pluginName) ); } diff --git a/src/ll/api/thread/GlobalThreadPauser.cpp b/src/ll/api/thread/GlobalThreadPauser.cpp index 5c864331f8..a65db7b00b 100644 --- a/src/ll/api/thread/GlobalThreadPauser.cpp +++ b/src/ll/api/thread/GlobalThreadPauser.cpp @@ -1,6 +1,6 @@ #include "ll/api/thread/GlobalThreadPauser.h" -#include "ll/api/base/ErrorInfo.h" +#include "ll/api/utils/ErrorUtils.h" #include "windows.h" @@ -10,7 +10,7 @@ namespace ll::thread { GlobalThreadPauser::GlobalThreadPauser() { HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); if (h == INVALID_HANDLE_VALUE) { - throw error_info::getWinLastError(); + throw error_utils::getWinLastError(); } static auto processId = GetCurrentProcessId(); auto threadId = GetCurrentThreadId(); diff --git a/src/ll/api/thread/ThreadPool.h b/src/ll/api/thread/ThreadPool.h index 5c48448e07..82cc383c82 100644 --- a/src/ll/api/thread/ThreadPool.h +++ b/src/ll/api/thread/ThreadPool.h @@ -10,7 +10,7 @@ #include #include -#include "ll/api/base/ErrorInfo.h" +#include "ll/api/utils/ErrorUtils.h" namespace ll::thread { class ThreadPool { @@ -25,7 +25,7 @@ class ThreadPool { explicit ThreadPool(size_t nThreads = 1) { for (size_t i = 0; i < nThreads; ++i) { workers.emplace_back([this] { - ll::error_info::setSehTranslator(); + ll::error_utils::setSehTranslator(); for (;;) { std::function task; { diff --git a/src/ll/api/thread/TickSyncSleep.h b/src/ll/api/thread/TickSyncSleep.h index 495f12b3a4..d194c559b7 100644 --- a/src/ll/api/thread/TickSyncSleep.h +++ b/src/ll/api/thread/TickSyncSleep.h @@ -15,8 +15,8 @@ namespace detail { LLETAPI std::mutex listMutex; LLETAPI std::atomic_size_t tickListSize; LLETAPI std::vector>, - std::reference_wrapper>>> + std::reference_wrapper>, + std::reference_wrapper>>> tickList; LLAPI void notify(); }; // namespace detail diff --git a/src/ll/api/base/Base64.h b/src/ll/api/utils/Base64Utils.h similarity index 96% rename from src/ll/api/base/Base64.h rename to src/ll/api/utils/Base64Utils.h index 5c9088b559..fe1ddc832d 100644 --- a/src/ll/api/base/Base64.h +++ b/src/ll/api/utils/Base64Utils.h @@ -4,7 +4,7 @@ #include "ll/api/base/StdInt.h" -namespace ll::base64 { +namespace ll::inline utils::base64_utils { namespace detail { constexpr uchar encodeLookup(uchar c) { return "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -87,4 +87,4 @@ constexpr std::string decode(std::string_view str) { } return out; } -} // namespace ll::base64 +} // namespace ll::inline utils::base64_utils diff --git a/src/ll/api/base/ErrorInfo.cpp b/src/ll/api/utils/ErrorUtils.cpp similarity index 98% rename from src/ll/api/base/ErrorInfo.cpp rename to src/ll/api/utils/ErrorUtils.cpp index 1fab964917..379808fa4a 100644 --- a/src/ll/api/base/ErrorInfo.cpp +++ b/src/ll/api/utils/ErrorUtils.cpp @@ -1,4 +1,4 @@ -#include "ll/api/base/ErrorInfo.h" +#include "ll/api/utils/ErrorUtils.h" #include @@ -22,7 +22,7 @@ #include "ll/api/utils/StacktraceUtils.h" #endif -namespace ll::error_info { +namespace ll::inline utils::error_utils { UntypedException::UntypedException(const EXCEPTION_RECORD& er) : exception_object(reinterpret_cast(er.ExceptionInformation[1])), @@ -136,7 +136,7 @@ seh_exception::seh_exception(uint ntStatus, _EXCEPTION_POINTERS* expPtr) : std::system_error(std::error_code{(int)ntStatus, ntstatus_category()}), expPtr(expPtr) {} -void setSehTranslator() { _set_se_translator(error_info::translateSEHtoCE); } +void setSehTranslator() { _set_se_translator(error_utils::translateSEHtoCE); } std::system_error getWinLastError() noexcept { return std::error_code{(int)GetLastError(), u8system_category()}; } @@ -336,4 +336,4 @@ void printCurrentException(ll::Logger& logger, std::exception_ptr const& e) noex } catch (...) {} logger.error("unknown error"); } -} // namespace ll::error_info +} // namespace ll::inline utils::error_utils diff --git a/src/ll/api/base/ErrorInfo.h b/src/ll/api/utils/ErrorUtils.h similarity index 97% rename from src/ll/api/base/ErrorInfo.h rename to src/ll/api/utils/ErrorUtils.h index 75ceb5bbb4..4765b83f8e 100644 --- a/src/ll/api/base/ErrorInfo.h +++ b/src/ll/api/utils/ErrorUtils.h @@ -22,7 +22,7 @@ struct _EXCEPTION_RECORD; // NOLINT(bugprone-reserved-identifier) struct _CONTEXT; // NOLINT(bugprone-reserved-identifier) struct _EXCEPTION_POINTERS; // NOLINT(bugprone-reserved-identifier) -namespace ll::error_info { +namespace ll::inline utils::error_utils { class seh_exception : public std::system_error { private: @@ -105,4 +105,4 @@ inline void printException(ll::Logger& l, T const& e) noexcept { printCurrentException(l, std::make_exception_ptr(e)); } -} // namespace ll::error_info +} // namespace ll::inline utils::error_utils diff --git a/src/ll/api/base/Hash.h b/src/ll/api/utils/HashUtils.h similarity index 90% rename from src/ll/api/base/Hash.h rename to src/ll/api/utils/HashUtils.h index 75d009d3fe..ec14aaf5d9 100644 --- a/src/ll/api/base/Hash.h +++ b/src/ll/api/utils/HashUtils.h @@ -4,7 +4,7 @@ #include "ll/api/base/StdInt.h" -namespace ll::hash { +namespace ll::inline utils::hash_utils { template constexpr void hashCombine(T const& v, size_t& seed) { @@ -44,8 +44,8 @@ template [[nodiscard]] constexpr uint64 hashType(T const& v) { return do_hash2({reinterpret_cast(std::addressof(v)), sizeof(T)}); } -} // namespace ll::hash +} // namespace ll::inline utils::hash_utils namespace ll::hash_literals { -[[nodiscard]] constexpr uint64 operator""_h(char const* x, size_t len) { return ll::hash::do_hash({x, len}); } +[[nodiscard]] constexpr uint64 operator""_h(char const* x, size_t len) { return ll::hash_utils::do_hash({x, len}); } } // namespace ll::hash_literals diff --git a/src/ll/api/base/Random.h b/src/ll/api/utils/RandomUtils.h similarity index 95% rename from src/ll/api/base/Random.h rename to src/ll/api/utils/RandomUtils.h index c899767936..02df99d718 100644 --- a/src/ll/api/base/Random.h +++ b/src/ll/api/utils/RandomUtils.h @@ -8,7 +8,7 @@ #include "ll/api/base/StdInt.h" -namespace ll::random { +namespace ll::inline utils::random_utils { template inline T rand(T upBound = 0) { @@ -67,4 +67,4 @@ inline T leftCloseIntervalRand(T min = 0, T max = 1) { return rand(min, max); } -} // namespace ll::random +} // namespace ll::inline utils::random_utils diff --git a/src/ll/api/utils/StacktraceUtils.cpp b/src/ll/api/utils/StacktraceUtils.cpp index 5706f72514..83a8995f06 100644 --- a/src/ll/api/utils/StacktraceUtils.cpp +++ b/src/ll/api/utils/StacktraceUtils.cpp @@ -3,8 +3,8 @@ #include #include "fmt/format.h" -#include "ll/api/base/ErrorInfo.h" #include "ll/api/io/FileUtils.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/api/utils/StringUtils.h" #include "windows.h" @@ -171,7 +171,7 @@ SymbolLoader::SymbolLoader() : handle(GetCurrentProcess()) { return; } if (!SymInitializeW(handle, nullptr, true)) { - throw error_info::getWinLastError(); + throw error_utils::getWinLastError(); } count++; DWORD options = SymGetOptions(); @@ -183,7 +183,7 @@ SymbolLoader::SymbolLoader(std::string_view extra) : handle(GetCurrentProcess()) return; } if (!SymInitializeW(handle, string_utils::str2wstr(extra).c_str(), true)) { - throw error_info::getWinLastError(); + throw error_utils::getWinLastError(); } count++; DWORD options = SymGetOptions(); diff --git a/src/ll/api/utils/StacktraceUtils.h b/src/ll/api/utils/StacktraceUtils.h index 89cc847087..afcd0d5c26 100644 --- a/src/ll/api/utils/StacktraceUtils.h +++ b/src/ll/api/utils/StacktraceUtils.h @@ -2,10 +2,12 @@ #if _HAS_CXX23 #include +#include #include #include #include "ll/api/base/Macro.h" +#include "ll/api/base/StdInt.h" struct _CONTEXT; // NOLINT(bugprone-reserved-identifier) diff --git a/src/ll/api/utils/StringUtils.h b/src/ll/api/utils/StringUtils.h index 6c049ceecd..a7f491cf02 100644 --- a/src/ll/api/utils/StringUtils.h +++ b/src/ll/api/utils/StringUtils.h @@ -4,6 +4,7 @@ #include #include +#include "ll/api/base/Concepts.h" #include "ll/api/base/Macro.h" #include "ll/api/base/StdInt.h" diff --git a/src/ll/api/utils/WinUtils.h b/src/ll/api/utils/WinUtils.h index 87d5f7bc8f..dcebf0469a 100644 --- a/src/ll/api/utils/WinUtils.h +++ b/src/ll/api/utils/WinUtils.h @@ -5,6 +5,8 @@ #include #include +#include + #include "ll/api/base/Macro.h" #include "ll/api/base/StdInt.h" diff --git a/src/ll/core/Config.cpp b/src/ll/core/Config.cpp index 7a2c6e6d73..84cae17d5a 100644 --- a/src/ll/core/Config.cpp +++ b/src/ll/core/Config.cpp @@ -1,6 +1,6 @@ #include "ll/core/Config.h" #include "ll/api/Config.h" -#include "ll/api/base/ErrorInfo.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/core/LeviLamina.h" namespace ll { @@ -23,7 +23,7 @@ bool loadLeviConfig() { return true; } catch (...) { logger.error("ll.config.load.fail"_tr); - ll::error_info::printCurrentException(logger); + ll::error_utils::printCurrentException(logger); return false; } } @@ -34,7 +34,7 @@ bool saveLeviConfig() { res = ll::config::saveConfig(globalConfig, leviConfigPath); } catch (...) { logger.error("ll.config.save.fail"_tr); - ll::error_info::printCurrentException(logger); + ll::error_utils::printCurrentException(logger); return false; } if (!res) { diff --git a/src/ll/core/CrashLogger.cpp b/src/ll/core/CrashLogger.cpp index 0b6ea36a09..f31a3a91c9 100644 --- a/src/ll/core/CrashLogger.cpp +++ b/src/ll/core/CrashLogger.cpp @@ -3,9 +3,9 @@ #include #include "ll/api/Logger.h" -#include "ll/api/ServerInfo.h" -#include "ll/api/base/ErrorInfo.h" -#include "ll/api/base/Version.h" +#include "ll/api/data/Version.h" +#include "ll/api/service/ServerInfo.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/api/utils/StacktraceUtils.h" #include "ll/api/utils/StringUtils.h" #include "ll/api/utils/WinUtils.h" @@ -52,7 +52,7 @@ bool CrashLogger::startCrashLoggerProcess() { )); if (!CreateProcess(nullptr, cmd.data(), &sa, &sa, true, 0, nullptr, nullptr, &si, &pi)) { crashLogger.error("ll.crashLogger.error.cannotCreateDaemonProcess"_tr); - error_info::printException(crashLogger, error_info::getWinLastError()); + error_utils::printException(crashLogger, error_utils::getWinLastError()); return false; } @@ -176,7 +176,7 @@ static void dumpSystemInfo() { static void dumpStacktrace(_CONTEXT const& c) { try { crashInfo.logger.info("Stacktrace:"); - auto str = stacktrace_utils::toString(error_info::stacktraceFromContext(c)); + auto str = stacktrace_utils::toString(error_utils::stacktraceFromContext(c)); for (auto& sv : splitByPattern(str, "\n")) { crashInfo.logger.info(" |{}", sv); } @@ -206,7 +206,7 @@ static bool genMiniDumpFile(PEXCEPTION_POINTERS e) { auto hDumpFile = CreateFileW(dumpFilePath.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (hDumpFile == INVALID_HANDLE_VALUE || hDumpFile == nullptr) { - throw error_info::getWinLastError(); + throw error_utils::getWinLastError(); } MINIDUMP_EXCEPTION_INFORMATION dumpInfo; @@ -226,7 +226,7 @@ static bool genMiniDumpFile(PEXCEPTION_POINTERS e) { nullptr )) { CloseHandle(hDumpFile); - throw error_info::getWinLastError(); + throw error_utils::getWinLastError(); } CloseHandle(hDumpFile); std::error_code ec; @@ -270,7 +270,7 @@ static LONG unhandledExceptionFilter(_In_ struct _EXCEPTION_POINTERS* e) { genMiniDumpFile(e); } catch (...) { crashInfo.logger.error("!!! Error In GenMiniDumpFile !!!"); - ll::error_info::printCurrentException(crashInfo.logger); + ll::error_utils::printCurrentException(crashInfo.logger); } stacktrace_utils::SymbolLoader symbol{}; @@ -280,7 +280,7 @@ static LONG unhandledExceptionFilter(_In_ struct _EXCEPTION_POINTERS* e) { crashInfo.logger.info("Exception:"); try { - auto str = error_info::makeExceptionString(error_info::createExceptionPtr(*e->ExceptionRecord)); + auto str = error_utils::makeExceptionString(error_utils::createExceptionPtr(*e->ExceptionRecord)); for (auto& sv : string_utils::splitByPattern(str, "\n")) { crashInfo.logger.info(" |{}", sv); } @@ -302,11 +302,11 @@ static LONG unhandledExceptionFilter(_In_ struct _EXCEPTION_POINTERS* e) { crashInfo.logger.info(""); crashInfo.logger.info("Modules:"); if (!EnumerateLoadedModulesW64(crashInfo.process, dumpModules, nullptr)) { - throw error_info::getWinLastError(); + throw error_utils::getWinLastError(); } } catch (...) { crashInfo.logger.error("!!! Error In CrashLogger !!!"); - ll::error_info::printCurrentException(crashInfo.logger); + ll::error_utils::printCurrentException(crashInfo.logger); crashInfo.logger.error(""); crashInfo.logger.error("\n{}", ll::stacktrace_utils::toString(std::stacktrace::current())); } diff --git a/src/ll/core/LeviLamina.cpp b/src/ll/core/LeviLamina.cpp index 1aae20ac0b..6087ae1569 100644 --- a/src/ll/core/LeviLamina.cpp +++ b/src/ll/core/LeviLamina.cpp @@ -4,11 +4,11 @@ #include #include "ll/api/Logger.h" -#include "ll/api/ServerInfo.h" -#include "ll/api/base/ErrorInfo.h" #include "ll/api/memory/Hook.h" #include "ll/api/service/Bedrock.h" #include "ll/api/service/PlayerInfo.h" +#include "ll/api/service/ServerInfo.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/core/Config.h" #include "ll/core/CrashLogger.h" #include "ll/core/Version.h" @@ -25,7 +25,7 @@ namespace ll { -using namespace hash; +using namespace hash_utils; using namespace hash_literals; using namespace i18n_literals; @@ -184,7 +184,7 @@ void startCrashLogger() { } void leviLaminaMain() { - error_info::setSehTranslator(); + error_utils::setSehTranslator(); // Prohibit pop-up windows to facilitate automatic restart SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT); @@ -264,7 +264,7 @@ LL_AUTO_STATIC_HOOK(LeviLaminaMainHook, HookPriority::High, "main", int, int arg try { leviLaminaMain(); } catch (...) { - ll::error_info::printCurrentException(logger); + ll::error_utils::printCurrentException(logger); } auto res = origin(argc, argv); setServerStatus(ServerStatus::Default); diff --git a/src/ll/core/plugin/NativePluginManager.cpp b/src/ll/core/plugin/NativePluginManager.cpp index 16cbd8dcc9..e30056616f 100644 --- a/src/ll/core/plugin/NativePluginManager.cpp +++ b/src/ll/core/plugin/NativePluginManager.cpp @@ -1,5 +1,5 @@ #include "ll/core/plugin/NativePluginManager.h" -#include "ll/api/base/ErrorInfo.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/core/LeviLamina.h" #include "windows.h" @@ -17,7 +17,7 @@ bool NativePluginManager::load(Manifest manifest) { auto entry = getPluginsRoot() / manifest.name / manifest.entry; auto lib = LoadLibrary(entry.c_str()); if (!lib) { - error_info::printException(logger, error_info::getWinLastError()); + error_utils::printException(logger, error_utils::getWinLastError()); return false; } auto plugin = std::make_shared(std::move(manifest), lib); @@ -49,7 +49,7 @@ bool NativePluginManager::unload(std::string_view name) { return false; } if (!FreeLibrary((HMODULE)ptr->getHandle())) { - error_info::printException(logger, error_info::getWinLastError()); + error_utils::printException(logger, error_utils::getWinLastError()); return false; } erasePlugin(name); diff --git a/src/ll/core/plugin/PluginRegistrar.cpp b/src/ll/core/plugin/PluginRegistrar.cpp index e67cb67ef0..5b66e219e7 100644 --- a/src/ll/core/plugin/PluginRegistrar.cpp +++ b/src/ll/core/plugin/PluginRegistrar.cpp @@ -3,11 +3,11 @@ #include #include -#include "ll/api/base/ErrorInfo.h" #include "ll/api/event/Emitter.h" #include "ll/api/io/FileUtils.h" #include "ll/api/memory/Hook.h" #include "ll/api/reflection/Deserialization.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/core/LeviLamina.h" #include "ll/core/plugin/NativePluginManager.h" @@ -53,7 +53,7 @@ static std::expected loadManifest(std::filesystem::path cons try { reflection::deserialize(manifest, json); } catch (...) { - error_info::printCurrentException(logger); + error_utils::printCurrentException(logger); return std::unexpected{DirState::Error}; } if (manifest.name != dirName) { @@ -243,11 +243,11 @@ LL_TYPE_INSTANCE_HOOK( try { registrar.enablePlugin(name); } catch (...) { - error_info::printCurrentException(logger); + error_utils::printCurrentException(logger); } } } catch (...) { - error_info::printCurrentException(logger); + error_utils::printCurrentException(logger); } } LL_TYPE_INSTANCE_HOOK( @@ -263,11 +263,11 @@ LL_TYPE_INSTANCE_HOOK( try { registrar.disablePlugin(name); } catch (...) { - error_info::printCurrentException(logger); + error_utils::printCurrentException(logger); } } } catch (...) { - error_info::printCurrentException(logger); + error_utils::printCurrentException(logger); } origin(); } diff --git a/src/ll/core/tweak/BuiltinCommands.cpp b/src/ll/core/tweak/BuiltinCommands.cpp index 8987f5c5d7..9bbee8dbaa 100644 --- a/src/ll/core/tweak/BuiltinCommands.cpp +++ b/src/ll/core/tweak/BuiltinCommands.cpp @@ -1,8 +1,8 @@ #include "ll/api/Logger.h" -#include "ll/api/ServerInfo.h" #include "ll/api/event/EventBus.h" #include "ll/api/event/server/ServerStartedEvent.h" #include "ll/api/service/Bedrock.h" +#include "ll/api/service/ServerInfo.h" #include "ll/core/Config.h" #include "mc/network/packet/Packet.h" diff --git a/src/ll/core/tweak/ModifyInfomation.cpp b/src/ll/core/tweak/ModifyInfomation.cpp index 71b8731ce8..7a30bb4909 100644 --- a/src/ll/core/tweak/ModifyInfomation.cpp +++ b/src/ll/core/tweak/ModifyInfomation.cpp @@ -1,5 +1,5 @@ -#include "ll/api/ServerInfo.h" #include "ll/api/memory/Hook.h" +#include "ll/api/service/ServerInfo.h" #include "ll/core/LeviLamina.h" #include "ll/core/Version.h" diff --git a/src/ll/test/ConfigTest.cpp b/src/ll/test/ConfigTest.cpp index 25d259e836..bc1eb40678 100644 --- a/src/ll/test/ConfigTest.cpp +++ b/src/ll/test/ConfigTest.cpp @@ -1,9 +1,9 @@ #include "nlohmann/json.hpp" #include "ll/api/Config.h" -#include "ll/api/base/ErrorInfo.h" -#include "ll/api/base/Version.h" +#include "ll/api/data/Version.h" #include "ll/api/memory/Hook.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/core/LeviLamina.h" #include "mc/server/ServerInstance.h" @@ -148,7 +148,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK(ConfigTest, HookPriority::Normal, ServerInstance, &Se nlohmann::ordered_json::parse(R"({"structure":{"hello":""}})", nullptr, false, true) ); } catch (...) { - ll::error_info::printCurrentException(ll::logger); + ll::error_utils::printCurrentException(ll::logger); } ll::logger.debug("789\xDB\xFE"); diff --git a/src/ll/test/EventTest.cpp b/src/ll/test/EventTest.cpp index aa721fbc0a..910bceffea 100644 --- a/src/ll/test/EventTest.cpp +++ b/src/ll/test/EventTest.cpp @@ -1,9 +1,9 @@ -#include "ll/api/base/ErrorInfo.h" #include "ll/api/event/Cancellable.h" #include "ll/api/event/EventBus.h" #include "ll/api/event/filesystem/FileActionEvent.h" #include "ll/api/memory/Hook.h" #include "ll/api/schedule/Scheduler.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/core/LeviLamina.h" #include "mc/server/ServerInstance.h" #include "mc/world/events/ServerInstanceEventCoordinator.h" @@ -36,11 +36,11 @@ #include "ll/api/base/FixedString.h" -#include "ll/api/base/Hash.h" +#include "ll/api/utils/HashUtils.h" struct myTypeList2 : ll::meta::DynamicTypeList {}; -using namespace ll::hash; +using namespace ll::hash_utils; using namespace ll::hash_literals; class TestEventB : public ll::event::Event { diff --git a/src/ll/test/PtrTest.cpp b/src/ll/test/PtrTest.cpp index 5d3ed5d943..58fef406b8 100644 --- a/src/ll/test/PtrTest.cpp +++ b/src/ll/test/PtrTest.cpp @@ -8,7 +8,7 @@ #include "mc/world/level/block/registry/BlockTypeRegistry.h" #include "mc/world/level/material/Material.h" -#include "ll/api/base/ErrorInfo.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/api/utils/StacktraceUtils.h" #include "ll/core/LeviLamina.h" @@ -96,13 +96,13 @@ LL_AUTO_TYPE_INSTANCE_HOOK( ) { std::cout << "type_hash " << entt::type_hash>::value() << std::endl; - ll::error_info::printException(ll::logger, ll::error_info::getWinLastError()); + ll::error_utils::printException(ll::logger, ll::error_utils::getWinLastError()); try { char* pp = (char*)(0x123); *pp = 'a'; } catch (...) { - ll::error_info::printCurrentException(ll::logger); + ll::error_utils::printCurrentException(ll::logger); } try { @@ -110,7 +110,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK( int b = 2 / a; std::cout << "b = " << b << std::endl; } catch (...) { - ll::error_info::printCurrentException(ll::logger); + ll::error_utils::printCurrentException(ll::logger); } try { try { @@ -125,7 +125,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK( std::throw_with_nested(std::system_error(std::error_code{1, std::generic_category()}, "run() failed")); } } catch (...) { - ll::error_info::printCurrentException(ll::logger); + ll::error_utils::printCurrentException(ll::logger); } // throw std::runtime_error("Test New Crash Logger"); diff --git a/src/ll/test/ScheduleTest.cpp b/src/ll/test/ScheduleTest.cpp index 02b3b28d25..aa452de745 100644 --- a/src/ll/test/ScheduleTest.cpp +++ b/src/ll/test/ScheduleTest.cpp @@ -1,8 +1,8 @@ #include "ll/api/Logger.h" -#include "ll/api/base/Random.h" #include "ll/api/memory/Hook.h" #include "ll/api/schedule/Scheduler.h" +#include "ll/api/utils/RandomUtils.h" #include "mc/server/ServerInstance.h" #include "mc/server/ServerLevel.h" #include "mc/world/events/ServerInstanceEventCoordinator.h" @@ -21,7 +21,7 @@ GameTickScheduler s3; #include "mc/network/packet/TextPacket.h" -#include "ll/api/base/DependencyGraph.h" +#include "ll/api/data/DependencyGraph.h" #pragma warning(push) #pragma warning(disable : 4723) @@ -43,7 +43,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK( schedulelogger.info( "hi, 100_tick life {} ramdom {}", ll::chrono::GameTickClock::now().time_since_epoch(), - ll::random::rand() + ll::random_utils::rand() ); }); @@ -53,7 +53,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK( schedulelogger.warn( "hi, 5s gt {} ramdom {}", ll::chrono::GameTickClock::now().time_since_epoch(), - ll::random::rand() + ll::random_utils::rand() ); }); }); @@ -63,12 +63,12 @@ LL_AUTO_TYPE_INSTANCE_HOOK( schedulelogger.info( "hi, 0.1min game {} random {}", ll::chrono::GameTickClock::now().time_since_epoch(), - ll::random::rand() + ll::random_utils::rand() ); - auto random = ll::random::rand(); + auto random = ll::random_utils::rand(); random /= 0; schedulelogger.info("{}", random); - throw std::system_error(std::error_code(0, ll::error_info::hresult_category())); + throw std::system_error(std::error_code(0, ll::error_utils::hresult_category())); }); // s2.add(0.3min, [&] { diff --git a/src/ll/test/TestDynamicCommand.cpp b/src/ll/test/TestDynamicCommand.cpp index 91ccc53741..6e0f812cb4 100644 --- a/src/ll/test/TestDynamicCommand.cpp +++ b/src/ll/test/TestDynamicCommand.cpp @@ -1,8 +1,8 @@ #include "ll/api/Logger.h" -#include "ll/api/base/Hash.h" #include "ll/api/command/DynamicCommand.h" #include "ll/api/service/Bedrock.h" +#include "ll/api/utils/HashUtils.h" #include "ll/core/LeviLamina.h" #include "mc/server/commands/ServerCommands.h" #include "mc/world/actor/Actor.h" @@ -17,7 +17,7 @@ using Param = DynamicCommand::ParameterData; using ParamType = DynamicCommand::ParameterType; using ParamIndex = DynamicCommandInstance::ParameterIndex; -using namespace ll::hash; +using namespace ll::hash_utils; using namespace ll::hash_literals; using namespace ll::chrono_literals; using namespace ll::i18n_literals; diff --git a/src/mc/deps/core/mce/UUID.cpp b/src/mc/deps/core/mce/UUID.cpp index 7c114e6179..05e88914c9 100644 --- a/src/mc/deps/core/mce/UUID.cpp +++ b/src/mc/deps/core/mce/UUID.cpp @@ -1,4 +1,4 @@ #include "mc/deps/core/mce/UUID.h" -#include "ll/api/base/Random.h" +#include "ll/api/utils/RandomUtils.h" -mce::UUID mce::UUID::random() { return {ll::random::rand(), ll::random::rand()}; } +mce::UUID mce::UUID::random() { return {ll::random_utils::rand(), ll::random_utils::rand()}; } diff --git a/src/mc/deps/core/mce/UUID.h b/src/mc/deps/core/mce/UUID.h index 778a93675a..d04080da04 100644 --- a/src/mc/deps/core/mce/UUID.h +++ b/src/mc/deps/core/mce/UUID.h @@ -1,6 +1,6 @@ #pragma once -#include "ll/api/base/Hash.h" +#include "ll/api/utils/HashUtils.h" #include "mc/_HeaderOutputPredefine.h" namespace mce { @@ -18,7 +18,7 @@ class UUID { LLNDAPI static mce::UUID random(); [[nodiscard]] inline mce::UUID fromStringHash(std::string_view sv) { - return {ll::hash::do_hash(sv), ll::hash::do_hash2(sv)}; + return {ll::hash_utils::do_hash(sv), ll::hash_utils::do_hash2(sv)}; } [[nodiscard]] inline explicit operator bool() const { return !isEmpty(); } diff --git a/src/mc/math/vector/component/base/VectorBase.h b/src/mc/math/vector/component/base/VectorBase.h index 11fd7c2f3c..e27bccdce4 100644 --- a/src/mc/math/vector/component/base/VectorBase.h +++ b/src/mc/math/vector/component/base/VectorBase.h @@ -7,11 +7,12 @@ #include #include "ll/api/base/Concepts.h" -#include "ll/api/base/Hash.h" #include "ll/api/base/Macro.h" #include "ll/api/base/Meta.h" +#include "ll/api/utils/HashUtils.h" namespace ll::math { + template struct has_toString : std::false_type {}; @@ -93,11 +94,14 @@ struct LL_EBO VectorBase : concepts::VectorBaseTag { size_t res = 0; forEachComponent([&](size_t iter) constexpr { if constexpr (std::is_integral_v) { - hash::hashCombine(hash::hashType(static_cast(this)->template get(iter)), res); + hash_utils::hashCombine( + hash_utils::hashType(static_cast(this)->template get(iter)), + res + ); } else if constexpr (has_hash::value) { - hash::hashCombine(static_cast(this)->template get(iter).hash(), res); + hash_utils::hashCombine(static_cast(this)->template get(iter).hash(), res); } else { - hash::hashCombine( + hash_utils::hashCombine( std::hash()(static_cast(this)->template get(iter)), res ); diff --git a/src/mc/nbt/SnbtDumpImpl.cpp b/src/mc/nbt/SnbtDumpImpl.cpp index fcb65516e7..89f99f471d 100644 --- a/src/mc/nbt/SnbtDumpImpl.cpp +++ b/src/mc/nbt/SnbtDumpImpl.cpp @@ -2,7 +2,7 @@ #include #include "ll/api/Logger.h" -#include "ll/api/base/Base64.h" +#include "ll/api/utils/Base64Utils.h" #include "ll/api/utils/StringUtils.h" #include "mc/common/ColorFormat.h" #include "mc/deps/core/mce/Color.h" @@ -80,7 +80,7 @@ std::string toDumpString(std::string const& str, fmt::color defaultc, std::strin res = res.substr(1, res.size() - 2); } catch (...) { base64 = true; - res = "\"" + ll::base64::encode(str) + "\""; + res = "\"" + ll::base64_utils::encode(str) + "\""; } } } diff --git a/src/mc/nbt/SnbtParseImpl.cpp b/src/mc/nbt/SnbtParseImpl.cpp index 4ca2e8b9fa..c28fa42ea2 100644 --- a/src/mc/nbt/SnbtParseImpl.cpp +++ b/src/mc/nbt/SnbtParseImpl.cpp @@ -1,5 +1,5 @@ -#include "ll/api/base/Base64.h" -#include "ll/api/base/Hash.h" +#include "ll/api/utils/Base64Utils.h" +#include "ll/api/utils/HashUtils.h" #include "mc/nbt/CompoundTag.h" namespace ll::nbt::detail { @@ -10,7 +10,7 @@ bool isTrivialNbtStringChar(char c) { return isalnum(c) || c == '-' || c == '+' namespace { using namespace ll::hash_literals; -using namespace ll::hash; +using namespace ll::hash_utils; using namespace ll::nbt::detail; bool scanComment(std::string_view& s) noexcept { @@ -257,7 +257,7 @@ std::optional parseString(std::string_view& s) { case '\"': { if (starts == '\"') { if (s.starts_with(" /*BASE64*/")) { - return ll::base64::decode(res); + return ll::base64_utils::decode(res); } return res; } diff --git a/src/mc/server/SimulatedPlayer.cpp b/src/mc/server/SimulatedPlayer.cpp index 0e6d5a96df..d7967114f0 100644 --- a/src/mc/server/SimulatedPlayer.cpp +++ b/src/mc/server/SimulatedPlayer.cpp @@ -1,5 +1,5 @@ #include "mc/server/SimulatedPlayer.h" -#include "ll/api/base/Random.h" +#include "ll/api/utils/RandomUtils.h" #include "ll/api/service/Bedrock.h" #include "mc/common/wrapper/OwnerPtrT.h" #include "mc/deps/core/string/HashedString.h" @@ -19,7 +19,7 @@ optional_ref SimulatedPlayer::create( } OwnerPtrT ownerPtr = ll::service::getServerNetworkHandler()->createSimulatedPlayer( name, - std::to_string(random::rand(INT64_MIN, -1)) + std::to_string(random_utils::rand(INT64_MIN, -1)) ); auto player = ownerPtr.tryUnwrap(); if (!player) { diff --git a/src/mc/server/commands/CommandRegistry.cpp b/src/mc/server/commands/CommandRegistry.cpp index 19cb1ed543..678896a3b2 100644 --- a/src/mc/server/commands/CommandRegistry.cpp +++ b/src/mc/server/commands/CommandRegistry.cpp @@ -1,5 +1,5 @@ #include "mc/server/commands/CommandRegistry.h" -#include "ll/api/base/ErrorInfo.h" +#include "ll/api/utils/ErrorUtils.h" #include "ll/core/Config.h" #include "ll/core/LeviLamina.h" #include "mc/server/commands/CommandParameterData.h" @@ -113,7 +113,7 @@ bool CommandRegistry::unregisterCommand(std::string const& name) { mAliases.erase(command); return true; } catch (...) { - ll::error_info::printCurrentException(ll::logger); + ll::error_utils::printCurrentException(ll::logger); } return false; } diff --git a/xmake.lua b/xmake.lua index b75a183fce..83ad3d4a8f 100644 --- a/xmake.lua +++ b/xmake.lua @@ -120,7 +120,7 @@ target("LeviLamina") set_exceptions("none") set_kind("shared") set_languages("c++20") - set_pcxxheader("src/mc/_HeaderOutputPredefine.h") + set_pcxxheader("src/ll/api/Global.h") set_symbols("debug") if has_config("tests") then