From 9a31f363f86bf0cf5f2cef3768345e7d35bde796 Mon Sep 17 00:00:00 2001 From: KobeBryant114514 <116721335+KobeBryant114514@users.noreply.github.com> Date: Wed, 7 May 2025 21:22:34 +0800 Subject: [PATCH] feat: adapt to GMLIB v1.0.2 --- lib/GMLIB_API-JS.d.ts | 3 +++ lib/GMLIB_API-JS.js | 11 ++++++++++ src/CompatibilityApi.cpp | 8 ++++++-- src/PlaceholderApi.cpp | 44 +++++++++++++++++++++++++++++----------- xmake.lua | 2 +- 5 files changed, 53 insertions(+), 15 deletions(-) diff --git a/lib/GMLIB_API-JS.d.ts b/lib/GMLIB_API-JS.d.ts index bb7ad7b..502a065 100644 --- a/lib/GMLIB_API-JS.d.ts +++ b/lib/GMLIB_API-JS.d.ts @@ -1556,6 +1556,9 @@ interface Player { slot: number ): Item; + /** (GMLIB & Glacie)获取客户端版本协议*/ + getNetworkProtocolVersion(): number + /** (GMLIB)发送更新更新物品数据包 */ sendInventorySlotPacket( /** 容器ID */ diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index a6c352c..1bc3b9f 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -376,6 +376,8 @@ const GMLIB_API = { entityHasType: ll.import("GMLIB_API", "entityHasType"), /** 获取实体类型ID @type {function(Entity):number} */ getEntityTypeId: ll.import("GMLIB_API", "getEntityTypeId"), + /** 获取实体类型ID @type {function(Entity):number} */ + getPlayerProtocolVersion: ll.import("GMLIB_API", "getPlayerProtocolVersion"), }; /** LRCA的二进制流数据包导出接口 */ @@ -3034,6 +3036,15 @@ LLSE_Player.prototype.sendInventorySlotPacket = GMLIB_API.sendInventorySlotPacket(this, containerId, slot, item); }; +LLSE_Player.prototype.getNetworkProtocolVersion = + /** + * 获取客户端版本协议 + * @returns {number} + */ + function (containerId, slot, item) { + GMLIB_API.getPlayerProtocolVersion(this); + }; + LLSE_Container.prototype.getContainerType = /** * 获取容器类型 diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index d610789..cb19b3b 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -152,7 +152,8 @@ void Export_Compatibility_API() { ); RemoteCall::exportAs("GMLIB_API", "getVersion_LRCA", []() -> std::string { return LIB_VERSION.to_string(); }); RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string { - return GMLIB_VERSION_TO_STRING(GMLIB_VERSION_MAJOR) "." GMLIB_VERSION_TO_STRING(GMLIB_VERSION_MINOR + return GMLIB_VERSION_TO_STRING(GMLIB_VERSION_MAJOR) "." GMLIB_VERSION_TO_STRING( + GMLIB_VERSION_MINOR ) "." GMLIB_VERSION_TO_STRING(GMLIB_VERSION_PATCH); }); RemoteCall::exportAs( @@ -582,7 +583,7 @@ void Export_Compatibility_API() { return player->attack(*entity, SharedTypes::Legacy::ActorDamageCause::EntityAttack); }); RemoteCall::exportAs("GMLIB_API", "playerPullInEntity", [](Player* player, Actor* entity) -> void { - if (auto component = player->getEntityContext().tryGetComponent()){ + if (auto component = player->getEntityContext().tryGetComponent()) { component->pullInEntity(*player, *entity); } }); @@ -951,4 +952,7 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getEntityTypeId", [](Actor* entity) -> int { return (int)entity->getEntityTypeId(); }); + RemoteCall::exportAs("GMLIB_API", "getPlayerProtocolVersion", [](Player* player) -> int { + return ((GMPlayer*)player)->getNetworkProtocolVersion(); + }); } \ No newline at end of file diff --git a/src/PlaceholderApi.cpp b/src/PlaceholderApi.cpp index 26f38d4..eeb9e08 100644 --- a/src/PlaceholderApi.cpp +++ b/src/PlaceholderApi.cpp @@ -23,10 +23,14 @@ void registerPlayerPlaceholder( [Call = RemoteCall::importAs)>( PluginName, FuncName - )](optional_ref actor, std::unordered_map const& params, auto&&... + )](optional_ref actor, ll::StringMap const& params, auto&&... ) -> std::optional { if (actor.has_value() && ((Actor*)actor.as_ptr())->isPlayer()) { - return Call((Player*)actor.as_ptr(), params); + std::unordered_map paramMap; + for (auto& [key, val] : params) { + paramMap[key] = val; + } + return Call((Player*)actor.as_ptr(), paramMap); } return std::nullopt; }, @@ -55,8 +59,13 @@ void registerServerPlaceholder( [Call = RemoteCall::importAs)>( PluginName, FuncName - )](auto, std::unordered_map const& params, auto&&... - ) -> std::optional { return Call(params); }, + )](auto, ll::StringMap const& params, auto&&...) -> std::optional { + std::unordered_map paramMap; + for (auto& [key, val] : params) { + paramMap[key] = val; + } + return Call(paramMap); + }, mod ); }; @@ -80,8 +89,8 @@ void registerStaticPlaceholder( if (mod.expired()) return; PlaceholderAPI::registerPlaceholder( PAPIName, - [Call = RemoteCall::importAs(PluginName, FuncName)](auto&&... - ) -> std::optional { return Call(); }, + [Call = RemoteCall::importAs(PluginName, FuncName)](auto&&...) + -> std::optional { return Call(); }, mod ); }; @@ -128,10 +137,13 @@ void registerPlaceholder(std::string const& placeholder, std::string const& func std::string(Actor*, std::unordered_map, std::string)>( pluginName, funcName - )](optional_ref actor, - std::unordered_map const& params, - std::string const& language) -> std::optional { - auto result = Call((Actor*)actor.as_ptr(), params, language); + )](optional_ref actor, ll::StringMap const& params, std::string const& language + ) -> std::optional { + std::unordered_map paramMap; + for (auto& [key, val] : params) { + paramMap[key] = val; + } + auto result = Call((Actor*)actor.as_ptr(), paramMap, language); return result == "" ? std::nullopt : std::optional(result); }, mod @@ -157,7 +169,11 @@ std::string getValue( std::unordered_map params, std::string const& language ) { - return PlaceholderAPI::getValue(placeholder, std::nullopt, params, language).value_or(""); + ll::StringMap paramMap; + for (auto& [key, val] : params) { + paramMap[key] = val; + } + return PlaceholderAPI::getValue(placeholder, std::nullopt, paramMap, language).value_or(""); } std::string getValueFromActor( std::string const& placeholder, @@ -165,7 +181,11 @@ std::string getValueFromActor( std::unordered_map params, std::string const& language ) { - return PlaceholderAPI::getValue(placeholder, (GMActor*)actor, params, language).value_or(""); + ll::StringMap paramMap; + for (auto& [key, val] : params) { + paramMap[key] = val; + } + return PlaceholderAPI::getValue(placeholder, (GMActor*)actor, paramMap, language).value_or(""); } } // namespace NewPapiRemoteCall diff --git a/xmake.lua b/xmake.lua index 4661caa..7be90b2 100644 --- a/xmake.lua +++ b/xmake.lua @@ -8,7 +8,7 @@ if not has_config("vs_runtime") then set_runtimes("MD") end -add_requires("levilamina", {configs = {target_type = "server"}}) +add_requires("levilamina 1.1.1", {configs = {target_type = "server"}}) add_requires("legacyremotecall") add_requires("levibuildscript") add_requires("ilistenattentively")