diff --git a/manifest.json b/manifest.json index 8912a2a6..db14ca23 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "type": "native", "description": "A plugin engine for running LLSE plugins on LeviLamina", "author": "LiteLDev", - "version": "0.8.3", + "version": "0.8.4", "dependencies": [ { "name": "LegacyMoney" diff --git a/src/legacy/api/APIHelp.h b/src/legacy/api/APIHelp.h index c9c04113..19c29a88 100644 --- a/src/legacy/api/APIHelp.h +++ b/src/legacy/api/APIHelp.h @@ -12,6 +12,7 @@ #include #include + // 输出异常信息 inline void PrintException(const script::Exception& e) { lse::getSelfPluginInstance().getLogger().error("script::Exception: {0}\n{1}", e.message(), e.stacktrace()); diff --git a/src/legacy/api/ContainerAPI.cpp b/src/legacy/api/ContainerAPI.cpp index d2088e48..1bcff17e 100644 --- a/src/legacy/api/ContainerAPI.cpp +++ b/src/legacy/api/ContainerAPI.cpp @@ -4,7 +4,6 @@ #include "api/ItemAPI.h" #include "api/NativeAPI.h" #include "ll/api/utils/StringUtils.h" -#include "mc/nbt/CompoundTag.h" #include "mc/world/item/registry/ItemStack.h" //////////////////// Class Definition //////////////////// diff --git a/src/legacy/api/DatabaseAPI.cpp b/src/legacy/api/DatabaseAPI.cpp index 0a0874ea..a859a623 100644 --- a/src/legacy/api/DatabaseAPI.cpp +++ b/src/legacy/api/DatabaseAPI.cpp @@ -1,4 +1,5 @@ #include "api/DatabaseAPI.h" + using namespace DB; #define CATCH_AND_THROW(LOG) \ diff --git a/src/legacy/api/LlAPI.cpp b/src/legacy/api/LlAPI.cpp index 2ef8080c..8bbef528 100644 --- a/src/legacy/api/LlAPI.cpp +++ b/src/legacy/api/LlAPI.cpp @@ -2,10 +2,11 @@ #include "api/APIHelp.h" #include "engine/GlobalShareData.h" -#include "ll/api/plugin/PluginManager.h" -#include "ll/api/plugin/PluginManagerRegistry.h" -#include "ll/api/service/ServerInfo.h" -#include "ll/api/utils/WinUtils.h" +#include "ll/api/Versions.h" +#include "ll/api/mod/Mod.h" +#include "ll/api/mod/ModManager.h" +#include "ll/api/mod/ModManagerRegistry.h" +#include "ll/api/utils/SystemUtils.h" #include "lse/PluginManager.h" #include @@ -55,14 +56,14 @@ ClassDefine VersionClassBuilder = defineClass("Version") Local LlClass::getLanguage() { try { - return String::newString(ll::win_utils::getSystemLocaleName()); + return String::newString(ll::sys_utils::getSystemLocaleName()); } CATCH("Fail in LLSEGetLanguage") } Local LlClass::isWine() { try { - return Boolean::newBoolean(ll::win_utils::isWine()); + return Boolean::newBoolean(ll::sys_utils::isWine()); } CATCH("Fail in LLSEIsWine") } @@ -124,7 +125,7 @@ Local LlClass::getVersionStatus() { return Number::newNumber(0); } Local LlClass::registerPlugin(const Arguments& args) { return Boolean::newBoolean(true); } Local LlClass::getPluginInfo(const Arguments& args) { try { - auto plugin = lse::getPluginManager().getPlugin(args[0].asString().toString()); + auto plugin = lse::getPluginManager().getMod(args[0].asString().toString()); if (plugin) { auto result = Object::newObject(); @@ -167,8 +168,8 @@ Local LlClass::requireVersion(const Arguments& args) { return Boolean::ne Local LlClass::getAllPluginInfo(const Arguments& args) { try { Local plugins = Array::newArray(); - ll::plugin::PluginManagerRegistry::getInstance().forEachPluginWithType( - [&](std::string_view type, std::string_view name, ll::plugin::Plugin& plugin) { + ll::mod::ModManagerRegistry::getInstance().forEachModWithType( + [&](std::string_view type, std::string_view name, ll::mod::Mod& plugin) { // Create plugin object auto pluginObject = Object::newObject(); @@ -208,8 +209,8 @@ Local LlClass::getAllPluginInfo(const Arguments& args) { Local LlClass::listPlugins(const Arguments& args) { try { Local plugins = Array::newArray(); - ll::plugin::PluginManagerRegistry::getInstance().forEachPluginWithType( - [&](std::string_view type, std::string_view name, ll::plugin::Plugin&) { + ll::mod::ModManagerRegistry::getInstance().forEachModWithType( + [&](std::string_view type, std::string_view name, ll::mod::Mod&) { plugins.add(String::newString(name)); return true; } diff --git a/src/legacy/api/NbtAPI.cpp b/src/legacy/api/NbtAPI.cpp index 2ffa0bf4..248ed7e8 100644 --- a/src/legacy/api/NbtAPI.cpp +++ b/src/legacy/api/NbtAPI.cpp @@ -165,8 +165,7 @@ ClassDefine NbtCompoundClassBuilder = void TagToJson_Compound_Helper(ordered_json& res, CompoundTag* nbt); void TagToJson_List_Helper(ordered_json& res, ListTag* nbt) { - auto& list = nbt->mList; - for (auto& tag : list) { + for (auto& tag : *nbt) { switch (tag->getId()) { case Tag::Type::Byte: tag->as() = 4; @@ -188,10 +187,10 @@ void TagToJson_List_Helper(ordered_json& res, ListTag* nbt) { res.push_back(tag->as().data); break; case Tag::Type::String: - res.push_back(tag->as().data); + res.push_back(tag->as()); break; case Tag::Type::ByteArray: { - auto& bytes = tag->as().data; + auto& bytes = tag->as(); char tmpData[1024]; for (unsigned int i = 0; i < bytes.size(); ++i) { tmpData[i] = bytes[i]; @@ -243,10 +242,10 @@ void TagToJson_Compound_Helper(ordered_json& res, CompoundTag* nbt) { res.push_back({key, tag.as().data}); break; case Tag::Type::String: - res.push_back({key, tag.as().data}); + res.push_back({key, tag.as()}); break; case Tag::Type::ByteArray: { - auto& bytes = tag.as().data; + auto& bytes = tag.as(); char tmpData[1024]; for (unsigned int i = 0; i < bytes.size(); ++i) { tmpData[i] = bytes[i]; @@ -299,10 +298,10 @@ std::string TagToJson(Tag* nbt, int formatIndent) { result = std::to_string(nbt->as().data); break; case Tag::Type::String: - result = nbt->as().data; + result = nbt->as(); break; case Tag::Type::ByteArray: { - auto& bytes = nbt->as().data; + auto& bytes = nbt->as(); std::string tmpData; for (uchar data : bytes) { tmpData.push_back(data); @@ -813,7 +812,7 @@ Local NbtStringClass::getType(const Arguments& args) { return Number::new Local NbtStringClass::get(const Arguments& args) { try { - return String::newString(nbt->data); + return String::newString(nbt->toString()); } CATCH("Fail in NbtValueGet!") } @@ -831,7 +830,7 @@ Local NbtStringClass::set(const Arguments& args) { CHECK_ARGS_COUNT(args, 1); try { - nbt->data = args[0].toStr(); + *nbt = args[0].toStr(); return Boolean::newBoolean(true); } CATCH("Fail in NbtValueSet!") @@ -855,7 +854,7 @@ NbtByteArrayClass* NbtByteArrayClass::constructor(const Arguments& args) { std::unique_ptr arrayTag = std::make_unique(ByteArrayTag()); for (char c : buf.describeUtf8()) { - arrayTag->data.push_back(c); + arrayTag->push_back(c); } return new NbtByteArrayClass(args.thiz(), std::move(arrayTag)); } @@ -893,7 +892,7 @@ Local NbtByteArrayClass::getType(const Arguments& args) { return Number:: Local NbtByteArrayClass::get(const Arguments& args) { try { - auto& data = nbt->data; + auto& data = *nbt; char buf[1024]; for (unsigned int i = 0; i < data.size(); ++i) { buf[i] = data[i]; @@ -918,7 +917,7 @@ Local NbtByteArrayClass::set(const Arguments& args) { try { Local buf = args[0].asByteBuffer(); for (char c : buf.describeUtf8()) { - nbt->data.push_back(c); + nbt->push_back(c); } return Boolean::newBoolean(true); } @@ -1205,7 +1204,7 @@ Local NbtListClass::setString(const Arguments& args) { } else if (list[0].getId() != Tag::Type::String) { LOG_ERROR_WITH_SCRIPT_INFO("Set wrong type of element into NBT List!"); } else { - list[index].as_ptr()->data = args[1].toStr(); + list[index].as() = args[1].toStr(); } return this->getScriptObject(); @@ -1229,7 +1228,7 @@ Local NbtListClass::setByteArray(const Arguments& args) { } else { auto data = args[1].asByteBuffer(); for (char c : data.describeUtf8()) { - list[index].as_ptr()->data.push_back(c); + list[index].as_ptr()->push_back(c); } } return this->getScriptObject(); @@ -1242,7 +1241,7 @@ Local NbtListClass::setTag(const Arguments& args) { CHECK_ARG_TYPE(args[0], ValueKind::kNumber); try { - auto& list = nbt->mList; + auto& list = *nbt; auto index = args[0].toInt(); if (index >= list.size() || index < 0) { @@ -1317,7 +1316,7 @@ Local NbtListClass::removeTag(const Arguments& args) { CHECK_ARG_TYPE(args[0], ValueKind::kNumber); try { - auto& list = nbt->mList; + auto& list = *nbt; auto index = args[0].toInt(); if (index >= list.size() || index < 0) { @@ -1325,7 +1324,7 @@ Local NbtListClass::removeTag(const Arguments& args) { return Local(); } - list.erase(list.begin() + index); //===== delete? + list.erase(index); return this->getScriptObject(); } CATCH("Fail in NBT SetTag!"); @@ -1415,10 +1414,9 @@ Local NbtListClass::getTag(const Arguments& args) { Local NbtListClass::toArray(const Arguments& args) { try { - auto& list = nbt->mList; - Local arr = Array::newArray(); + Local arr = Array::newArray(); - for (auto& tag : list) { + for (auto& tag : *nbt) { arr.add(Tag2Value(tag.get(), true)); } return arr; @@ -1680,7 +1678,7 @@ Local NbtCompoundClass::setByteArray(const Arguments& args) { auto data = args[1].asByteBuffer(); ByteArrayTag baTag; for (char c : data.describeUtf8()) { - baTag.data.push_back(c); + baTag.push_back(c); } nbt->at(key) = baTag; return this->getScriptObject(); @@ -1924,7 +1922,7 @@ Local NbtStatic::newTag(const Arguments& args) { case Tag::Type::String: { StringTag tag; if (args.size() >= 2 && args[1].isString()) { - tag.data = args[1].toStr(); + tag = args[1].toStr(); } res = NbtStringClass::pack(std::move(&tag)); break; @@ -1934,7 +1932,7 @@ Local NbtStatic::newTag(const Arguments& args) { if (args.size() >= 2 && args[1].isByteBuffer()) { Local buf = args[1].asByteBuffer(); for (char data : buf.describeUtf8()) { - tag.data.push_back(data); + tag.push_back(data); } } res = NbtByteArrayClass::pack(std::move(&tag)); @@ -2010,7 +2008,7 @@ Local Tag2Value_CompoundHelper(CompoundTag* nbt, bool autoExpansion = fal Local Tag2Value_ListHelper(ListTag* nbt, bool autoExpansion = false) { Local res = Array::newArray(); - auto& list = nbt->as_ptr()->mList; + auto& list = nbt->as(); for (auto& tag : list) { switch (tag->getId()) { case Tag::Type::Byte: @@ -2032,10 +2030,10 @@ Local Tag2Value_ListHelper(ListTag* nbt, bool autoExpansion = false) { res.add(Number::newNumber(tag->as_ptr()->data)); break; case Tag::Type::String: - res.add(String::newString(tag->as_ptr()->data)); + res.add(String::newString(tag->as())); break; case Tag::Type::ByteArray: { - auto& data = tag->as_ptr()->data; + auto& data = tag->as(); char buf[1024]; for (unsigned int i = 0; i < data.size(); ++i) { buf[i] = data[i]; @@ -2084,10 +2082,10 @@ Local Tag2Value_CompoundHelper(CompoundTag* nbt, bool autoExpansion) { res.set(key, Number::newNumber(tag.get().as_ptr()->data)); break; case Tag::Type::String: - res.set(key, String::newString(tag.get().as_ptr()->data)); + res.set(key, String::newString(tag.get().as())); break; case Tag::Type::ByteArray: { - auto& data = tag.get().as_ptr()->data; + auto& data = tag.get().as(); char buf[1024]; for (unsigned int i = 0; i < data.size(); ++i) { buf[i] = data[i]; @@ -2134,10 +2132,10 @@ Local Tag2Value(Tag* nbt, bool autoExpansion) { value = Number::newNumber(nbt->as_ptr()->data); break; case Tag::Type::String: - value = String::newString(nbt->as_ptr()->data); + value = String::newString(nbt->as()); break; case Tag::Type::ByteArray: { - auto& data = nbt->as_ptr()->data; + auto& data = nbt->as(); char buf[1024]; for (unsigned int i = 0; i < data.size(); ++i) { buf[i] = data[i]; diff --git a/src/legacy/api/ServerAPI.cpp b/src/legacy/api/ServerAPI.cpp index 4fd247aa..12aab92a 100644 --- a/src/legacy/api/ServerAPI.cpp +++ b/src/legacy/api/ServerAPI.cpp @@ -2,8 +2,8 @@ #include "api/APIHelp.h" #include "api/McAPI.h" +#include "ll/api/service/Bedrock.h" #include "ll/api/utils/RandomUtils.h" -#include "main/SafeGuardRecord.h" #include "mc/network/ServerNetworkHandler.h" #include "mc/network/packet/SetTimePacket.h" diff --git a/src/legacy/engine/EngineOwnData.h b/src/legacy/engine/EngineOwnData.h index f347eef8..7071caa2 100644 --- a/src/legacy/engine/EngineOwnData.h +++ b/src/legacy/engine/EngineOwnData.h @@ -1,14 +1,12 @@ #pragma once - #include "dyncall/dyncall.h" -#include "ll/api/Logger.h" -#include "ll/api/i18n/I18n.h" #include "main/Configs.h" #include "utils/UsingScriptX.h" -#include +#include +#include +#include #include -#include #include #include diff --git a/src/legacy/engine/OperationCount.cpp b/src/legacy/engine/OperationCount.cpp index a4519342..fff461bb 100644 --- a/src/legacy/engine/OperationCount.cpp +++ b/src/legacy/engine/OperationCount.cpp @@ -1,7 +1,7 @@ #include "engine/OperationCount.h" #include "engine/GlobalShareData.h" -#include "ll/api/plugin/PluginManager.h" +#include "ll/api/mod/ModManager.h" #include "main/Configs.h" #include @@ -46,7 +46,7 @@ int OperationCount::get() { bool OperationCount::hasReachCount(int count) { return get() >= count; } bool OperationCount::hasReachMaxEngineCount() { - return hasReachCount(lse::getPluginManager().getPluginCount()); + return hasReachCount(lse::getPluginManager().getModCount()); return false; } diff --git a/src/legacy/legacyapi/command/DynamicCommand.cpp b/src/legacy/legacyapi/command/DynamicCommand.cpp index a2ff2b7a..0c097dcb 100644 --- a/src/legacy/legacyapi/command/DynamicCommand.cpp +++ b/src/legacy/legacyapi/command/DynamicCommand.cpp @@ -1,8 +1,6 @@ #include "DynamicCommand.h" #include "fmt/core.h" -#include "ll/api/Logger.h" -#include "ll/api/command/CommandRegistrar.h" #include "ll/api/memory/Closure.h" #include "ll/api/memory/Memory.h" #include "ll/api/utils/ErrorUtils.h" @@ -37,6 +35,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/src/legacy/legacyapi/db/ConnParams.cpp b/src/legacy/legacyapi/db/ConnParams.cpp index 6c8fa7d9..531924ed 100644 --- a/src/legacy/legacyapi/db/ConnParams.cpp +++ b/src/legacy/legacyapi/db/ConnParams.cpp @@ -1,8 +1,10 @@ #include "legacyapi/db/ConnParams.h" -#include "ll/api/Logger.h" #include "ll/api/utils/StringUtils.h" +#include +#include + namespace DB { #pragma region URL_Parser diff --git a/src/legacy/legacyapi/db/Stmt.h b/src/legacy/legacyapi/db/Stmt.h index c1f35122..3cc37dc1 100644 --- a/src/legacy/legacyapi/db/Stmt.h +++ b/src/legacy/legacyapi/db/Stmt.h @@ -1,7 +1,9 @@ #pragma once #include "legacyapi/db/Pointer.h" #include "legacyapi/db/RowSet.h" -#include "ll/api/Logger.h" + +#include +#include #define IF_ENDBG if (debugOutput) diff --git a/src/legacy/legacyapi/form/FormUI.cpp b/src/legacy/legacyapi/form/FormUI.cpp index 25433c94..3b13babf 100644 --- a/src/legacy/legacyapi/form/FormUI.cpp +++ b/src/legacy/legacyapi/form/FormUI.cpp @@ -1,11 +1,12 @@ #include "FormUI.h" #include "FormPacketHelper.h" -#include "ll/api/Logger.h" #include "lse/Entry.h" #include "mc/network/packet/ModalFormRequestPacket.h" #include "mc/network/packet/Packet.h" +#include +#include #include #include #include diff --git a/src/legacy/legacyapi/utils/FileHelper.cpp b/src/legacy/legacyapi/utils/FileHelper.cpp index ce858d32..d53bcac6 100644 --- a/src/legacy/legacyapi/utils/FileHelper.cpp +++ b/src/legacy/legacyapi/utils/FileHelper.cpp @@ -1,8 +1,6 @@ #include "FileHelper.h" #include "ll/api/utils/StringUtils.h" -#include "ll/api/utils/WinUtils.h" -#include "lse/Entry.h" #include #include diff --git a/src/legacy/legacyapi/utils/FileHelper.h b/src/legacy/legacyapi/utils/FileHelper.h index ab7c1231..90cbfaa1 100644 --- a/src/legacy/legacyapi/utils/FileHelper.h +++ b/src/legacy/legacyapi/utils/FileHelper.h @@ -1,9 +1,7 @@ #pragma once -#include "ll/api/Logger.h" - #include -#include -#include +#include +#include #include namespace lse::legacy { diff --git a/src/legacy/main/Global.h b/src/legacy/main/Global.h index 230327b3..e2703094 100644 --- a/src/legacy/main/Global.h +++ b/src/legacy/main/Global.h @@ -1,6 +1,5 @@ #pragma once -#include "ll/api/i18n/I18n.h" #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -8,13 +7,12 @@ #define CPPHTTPLIB_OPENSSL_SUPPORT #endif -#include "ll/api/Logger.h" -#include "ll/api/service/Bedrock.h" -#include "main/Configs.h" #include "mc/math/Vec3.h" #include "mc/world/level/BlockPos.h" -#include "utils/JsonHelper.h" +#include +#include +#include #include #include @@ -22,7 +20,7 @@ using std::string; using std::vector; // 全局工具 -extern ordered_json globalConfig; +extern nlohmann::ordered_json globalConfig; typedef unsigned long long QWORD; diff --git a/src/lse/Entry.cpp b/src/lse/Entry.cpp index 735e4c14..0da2640b 100644 --- a/src/lse/Entry.cpp +++ b/src/lse/Entry.cpp @@ -16,8 +16,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -68,14 +68,14 @@ Config config; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) std::shared_ptr pluginManager; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -std::unique_ptr> +std::unique_ptr> selfPluginInstance; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -void loadConfig(const ll::plugin::NativePlugin& self, Config& config); -void loadDebugEngine(const ll::plugin::NativePlugin& self); +void loadConfig(const ll::mod::NativeMod& self, Config& config); +void loadDebugEngine(const ll::mod::NativeMod& self); void registerPluginManager(const std::shared_ptr& pluginManager); -auto enable(ll::plugin::NativePlugin& /*self*/) -> bool { +auto enable(ll::mod::NativeMod& /*self*/) -> bool { auto& logger = getSelfPluginInstance().getLogger(); try { @@ -115,7 +115,7 @@ void initializeLegacyStuff() { MoreGlobal::Init(); } -auto load(ll::plugin::NativePlugin& self) -> bool { +auto load(ll::mod::NativeMod& self) -> bool { auto& logger = self.getLogger(); #ifdef NDEBUG ll::error_utils::setSehTranslator(); @@ -128,7 +128,7 @@ auto load(ll::plugin::NativePlugin& self) -> bool { config = Config(); pluginManager = std::make_shared(); - selfPluginInstance = std::make_unique>(self); + selfPluginInstance = std::make_unique>(self); loadConfig(self, config); @@ -153,14 +153,14 @@ auto load(ll::plugin::NativePlugin& self) -> bool { } } -void loadConfig(const ll::plugin::NativePlugin& self, Config& config) { +void loadConfig(const ll::mod::NativeMod& self, Config& config) { const auto& configFilePath = self.getConfigDir() / "config.json"; if (!ll::config::loadConfig(config, configFilePath) && !ll::config::saveConfig(config, configFilePath)) { throw std::runtime_error(fmt::format("cannot save default configurations to {}", configFilePath)); } } -void loadDebugEngine(const ll::plugin::NativePlugin& self) { +void loadDebugEngine(const ll::mod::NativeMod& self) { #ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS // NodeJs backend didn't enable debug engine now auto& scriptEngine = *EngineManager::newEngine(); @@ -169,7 +169,7 @@ void loadDebugEngine(const ll::plugin::NativePlugin& self) { BindAPIs(&scriptEngine); // Load BaseLib. - auto baseLibPath = self.getPluginDir() / "baselib" / BaseLibFileName; + auto baseLibPath = self.getModDir() / "baselib" / BaseLibFileName; auto baseLibContent = ll::file_utils::readFile(baseLibPath); if (!baseLibContent) { throw std::runtime_error(fmt::format("failed to read BaseLib at {}", baseLibPath.string())); @@ -181,7 +181,7 @@ void loadDebugEngine(const ll::plugin::NativePlugin& self) { } void registerPluginManager(const std::shared_ptr& pluginManager) { - auto& pluginManagerRegistry = ll::plugin::PluginManagerRegistry::getInstance(); + auto& pluginManagerRegistry = ll::mod::ModManagerRegistry::getInstance(); if (!pluginManagerRegistry.addManager(pluginManager)) { throw std::runtime_error("failed to register plugin manager"); @@ -200,7 +200,7 @@ auto getPluginManager() -> PluginManager& { return *pluginManager; } -auto getSelfPluginInstance() -> ll::plugin::NativePlugin& { +auto getSelfPluginInstance() -> ll::mod::NativeMod& { if (!selfPluginInstance) { throw std::runtime_error("selfPluginInstance is null"); } @@ -211,9 +211,9 @@ auto getSelfPluginInstance() -> ll::plugin::NativePlugin& { } // namespace lse extern "C" { -_declspec(dllexport) auto ll_plugin_load(ll::plugin::NativePlugin& self) -> bool { return lse::load(self); } +_declspec(dllexport) auto ll_plugin_load(ll::mod::NativeMod& self) -> bool { return lse::load(self); } -_declspec(dllexport) auto ll_plugin_enable(ll::plugin::NativePlugin& self) -> bool { return lse::enable(self); } +_declspec(dllexport) auto ll_plugin_enable(ll::mod::NativeMod& self) -> bool { return lse::enable(self); } // LegacyScriptEngine should not be disabled or unloaded currently. } diff --git a/src/lse/Entry.h b/src/lse/Entry.h index ea51335b..9747c9e0 100644 --- a/src/lse/Entry.h +++ b/src/lse/Entry.h @@ -3,7 +3,7 @@ #include "Config.h" #include "PluginManager.h" -#include +#include namespace lse { @@ -11,6 +11,6 @@ namespace lse { [[nodiscard]] auto getPluginManager() -> PluginManager&; -[[nodiscard]] auto getSelfPluginInstance() -> ll::plugin::NativePlugin&; +[[nodiscard]] auto getSelfPluginInstance() -> ll::mod::NativeMod&; } // namespace lse diff --git a/src/lse/Plugin.cpp b/src/lse/Plugin.cpp index 955f41fc..579340f4 100644 --- a/src/lse/Plugin.cpp +++ b/src/lse/Plugin.cpp @@ -2,14 +2,15 @@ #include "Entry.h" #include "legacy/engine/EngineOwnData.h" +#include "ll/api/mod/Mod.h" -#include +#include namespace lse { -Plugin::Plugin(const ll::plugin::Manifest& manifest) : ll::plugin::Plugin(manifest) {} +Plugin::Plugin(const ll::mod::Manifest& manifest) : ll::mod::Mod(manifest) {} -std::shared_ptr Plugin::current() { - return lse::getPluginManager().getPlugin(ENGINE_OWN_DATA()->pluginName); +std::shared_ptr Plugin::current() { + return lse::getPluginManager().getMod(ENGINE_OWN_DATA()->pluginName); } } // namespace lse diff --git a/src/lse/Plugin.h b/src/lse/Plugin.h index 4dd659b3..746b49ba 100644 --- a/src/lse/Plugin.h +++ b/src/lse/Plugin.h @@ -2,17 +2,17 @@ #include "PluginManager.h" -#include -#include +#include +#include namespace lse { -class Plugin : public ll::plugin::Plugin { +class Plugin : public ll::mod::Mod { friend PluginManager; public: - Plugin(const ll::plugin::Manifest& manifest); + Plugin(const ll::mod::Manifest& manifest); - static std::shared_ptr current(); + static std::shared_ptr current(); }; } // namespace lse diff --git a/src/lse/PluginManager.cpp b/src/lse/PluginManager.cpp index bba5832b..2a7461c1 100644 --- a/src/lse/PluginManager.cpp +++ b/src/lse/PluginManager.cpp @@ -13,8 +13,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -59,9 +59,9 @@ auto LLSERemoveAllExportedFuncs(script::ScriptEngine* engine) -> bool; namespace lse { -PluginManager::PluginManager() : ll::plugin::PluginManager(PluginManagerName) {} +PluginManager::PluginManager() : ll::mod::ModManager(PluginManagerName) {} -ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) { +ll::Expected<> PluginManager::load(ll::mod::Manifest manifest) { auto& logger = getSelfPluginInstance().getLogger(); #ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON std::filesystem::path dirPath = ll::plugin::getPluginsRoot() / manifest.name; // Plugin path @@ -123,7 +123,7 @@ ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) { logger.info("loading plugin {}", manifest.name); - if (hasPlugin(manifest.name)) { + if (hasMod(manifest.name)) { return ll::makeStringError("plugin already loaded"); } @@ -166,7 +166,7 @@ ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) { auto& self = getSelfPluginInstance(); #ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS // NodeJs backend load depends code in another place // Load BaseLib. - auto baseLibPath = self.getPluginDir() / "baselib" / BaseLibFileName; + auto baseLibPath = self.getModDir() / "baselib" / BaseLibFileName; auto baseLibContent = ll::file_utils::readFile(baseLibPath); if (!baseLibContent) { return ll::makeStringError(fmt::format("failed to read BaseLib at {}", baseLibPath.string())); @@ -174,8 +174,8 @@ ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) { scriptEngine.eval(baseLibContent.value()); #endif // Load the plugin entry. - auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / manifest.name); - auto entryPath = pluginDir / manifest.entry; + auto pluginDir = std::filesystem::canonical(ll::mod::getModsRoot() / manifest.name); + auto entryPath = pluginDir / manifest.entry; ENGINE_OWN_DATA()->pluginFileOrDirPath = ll::string_utils::u8str2str(entryPath.u8string()); #ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON if (!PythonHelper::loadPluginCode( @@ -212,10 +212,10 @@ ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) { } ExitEngineScope exit; #endif - plugin->onLoad([](ll::plugin::Plugin& plugin) { return true; }); - plugin->onUnload([](ll::plugin::Plugin& plugin) { return true; }); - plugin->onEnable([](ll::plugin::Plugin& plugin) { return true; }); - plugin->onDisable([](ll::plugin::Plugin& plugin) { return true; }); + plugin->onLoad([](ll::mod::Mod& plugin) { return true; }); + plugin->onUnload([](ll::mod::Mod& plugin) { return true; }); + plugin->onEnable([](ll::mod::Mod& plugin) { return true; }); + plugin->onDisable([](ll::mod::Mod& plugin) { return true; }); } catch (const Exception& e) { EngineScope engineScope(scriptEngine); auto error = @@ -234,7 +234,7 @@ ll::Expected<> PluginManager::load(ll::plugin::Manifest manifest) { return error; } - addPlugin(manifest.name, plugin); + addMod(manifest.name, plugin); return {}; } @@ -244,7 +244,7 @@ ll::Expected<> PluginManager::unload(std::string_view name) { try { - auto plugin = std::static_pointer_cast(getPlugin(name)); + auto plugin = std::static_pointer_cast(getMod(name)); logger.info("Unloading plugin {}", name); @@ -265,7 +265,7 @@ ll::Expected<> PluginManager::unload(std::string_view name) { #else scriptEngine.destroy(); // TODO: use unique_ptr to manage the engine. #endif - erasePlugin(name); + eraseMod(name); return {}; } catch (const std::exception& e) { diff --git a/src/lse/PluginManager.h b/src/lse/PluginManager.h index fe6c68ba..dcae8772 100644 --- a/src/lse/PluginManager.h +++ b/src/lse/PluginManager.h @@ -1,12 +1,13 @@ #pragma once -#include -#include +#include +#include +#include #include namespace lse { -class PluginManager : public ll::plugin::PluginManager { +class PluginManager : public ll::mod::ModManager { public: PluginManager(); @@ -18,7 +19,7 @@ class PluginManager : public ll::plugin::PluginManager { ~PluginManager() override = default; private: - ll::Expected<> load(ll::plugin::Manifest manifest) override; + ll::Expected<> load(ll::mod::Manifest manifest) override; ll::Expected<> unload(std::string_view name) override; }; diff --git a/src/lse/PluginMigration.cpp b/src/lse/PluginMigration.cpp index 5727edc2..e3fb358b 100644 --- a/src/lse/PluginMigration.cpp +++ b/src/lse/PluginMigration.cpp @@ -7,8 +7,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -53,7 +53,7 @@ auto migratePlugin(const PluginManager& pluginManager, const std::filesystem::pa const auto& pluginFileName = path.filename(); const auto& pluginFileBaseName = path.stem(); - const auto& pluginDir = ll::plugin::getPluginsRoot() / pluginFileBaseName; + const auto& pluginDir = ll::mod::getModsRoot() / pluginFileBaseName; if (std::filesystem::exists(pluginDir / pluginFileName)) { throw std::runtime_error(fmt::format( @@ -74,13 +74,13 @@ auto migratePlugin(const PluginManager& pluginManager, const std::filesystem::pa // Move plugin file. std::filesystem::rename(path, pluginDir / pluginFileName); - ll::plugin::Manifest manifest{ + ll::mod::Manifest manifest{ .entry = ll::string_utils::u8str2str(pluginFileName.u8string()), .name = ll::string_utils::u8str2str(pluginFileBaseName.u8string()), .type = pluginType, .dependencies = - std::unordered_set{ - ll::plugin::Dependency{ + std::unordered_set{ + ll::mod::Dependency{ .name = self.getManifest().name, }, }, }; @@ -123,7 +123,7 @@ auto migratePlugins(const PluginManager& pluginManager) -> void { // Discover plugins. logger.info("Discovering legacy plugins..."); - const auto& pluginBaseDir = ll::plugin::getPluginsRoot(); + const auto& pluginBaseDir = ll::mod::getModsRoot(); for (const auto& entry : std::filesystem::directory_iterator(pluginBaseDir)) { if (!entry.is_regular_file() || entry.path().extension() != PluginExtName) { diff --git a/tooth.json b/tooth.json index 694e8386..2c24f184 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/LiteLDev/LegacyScriptEngine", - "version": "0.8.3", + "version": "0.8.4", "info": { "name": "LegacyScriptEngine", "description": "A plugin engine for running LLSE plugins on LeviLamina", @@ -12,7 +12,7 @@ ] }, "dependencies": { - "gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.8.3", - "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.3" + "gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.8.4", + "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.8.4" } } diff --git a/tooth.lua.json b/tooth.lua.json index 5d7923b2..a3d8473f 100644 --- a/tooth.lua.json +++ b/tooth.lua.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-lua", - "version": "0.8.3", + "version": "0.8.4", "info": { "name": "LegacyScriptEngine with Lua backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", @@ -17,7 +17,7 @@ "github.com/LiteLDev/LegacyMoney": "0.8.x" }, "prerequisites": { - "github.com/LiteLDev/LeviLamina": "0.13.x" + "github.com/LiteLDev/LeviLamina": ">=0.13.4 <0.14.0" }, "files": { "place": [ diff --git a/tooth.nodejs.json b/tooth.nodejs.json index ab5896bf..b6dad29f 100644 --- a/tooth.nodejs.json +++ b/tooth.nodejs.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-nodejs", - "version": "0.8.3", + "version": "0.8.4", "info": { "name": "LegacyScriptEngine with NodeJs backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", @@ -19,7 +19,7 @@ "gitea.litebds.com/LiteLDev/node-binaries": "16.16.0" }, "prerequisites": { - "github.com/LiteLDev/LeviLamina": "0.13.x" + "github.com/LiteLDev/LeviLamina": ">=0.13.4 <0.14.0" }, "files": { "place": [ diff --git a/tooth.python.json b/tooth.python.json index 6508daab..7313f554 100644 --- a/tooth.python.json +++ b/tooth.python.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-python", - "version": "0.8.3", + "version": "0.8.4", "info": { "name": "LegacyScriptEngine with Python backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", @@ -18,7 +18,7 @@ "gitea.litebds.com/LiteLDev/python-binaries": "3.10.11" }, "prerequisites": { - "github.com/LiteLDev/LeviLamina": "0.13.x" + "github.com/LiteLDev/LeviLamina": ">=0.13.4 <0.14.0" }, "files": { "place": [ diff --git a/tooth.quickjs.json b/tooth.quickjs.json index 1fc4c7ad..3eccd397 100644 --- a/tooth.quickjs.json +++ b/tooth.quickjs.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs", - "version": "0.8.3", + "version": "0.8.4", "info": { "name": "LegacyScriptEngine with QuickJs backend", "description": "A plugin engine for running LLSE plugins on LeviLamina", @@ -17,7 +17,7 @@ "github.com/LiteLDev/LegacyMoney": "0.8.x" }, "prerequisites": { - "github.com/LiteLDev/LeviLamina": "0.13.x" + "github.com/LiteLDev/LeviLamina": ">=0.13.4 <0.14.0" }, "files": { "place": [ diff --git a/xmake.lua b/xmake.lua index dee1d25e..167b5e4a 100644 --- a/xmake.lua +++ b/xmake.lua @@ -9,7 +9,7 @@ add_requires( "legacymoney 0.8.1", "legacyparticleapi 0.8.1", "legacyremotecall 0.8.1", - "levilamina 0.13.3", + "levilamina 0.13.4", "lightwebsocketclient", "magic_enum", "nlohmann_json",