From 842c51e2e3962cf61873e95fd5043de4eec1de3a Mon Sep 17 00:00:00 2001 From: ShrBox Date: Wed, 3 May 2023 19:49:32 +0800 Subject: [PATCH 1/7] fix: PlayerDestroyEvent #1249 --- LiteLoader/src/llapi/EventAPI.cpp | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/LiteLoader/src/llapi/EventAPI.cpp b/LiteLoader/src/llapi/EventAPI.cpp index 1f41a56aff..c4844b8005 100644 --- a/LiteLoader/src/llapi/EventAPI.cpp +++ b/LiteLoader/src/llapi/EventAPI.cpp @@ -1324,30 +1324,9 @@ TInstanceHook(void*, "?die@ServerPlayer@@UEAAXAEBVActorDamageSource@@@Z", Server /////////////////// PlayerDestroy /////////////////// -// TInstanceHook(bool, "?destroyBlock@SurvivalMode@@UEAA_NAEBVBlockPos@@E@Z", -// SurvivalMode, BlockPos a3, unsigned __int8 a4) -//{ -// IF_LISTENED(PlayerDestroyBlockEvent) -// { -// if (getPlayer()->isPlayer()) -// { -// PlayerDestroyBlockEvent ev{}; -// ev.mPlayer = getPlayer(); -// auto bl = Level::getBlockInstance(a3, getPlayer()->getDimensionId()); -// ev.mBlockInstance = bl; -// if (!ev.call()) -// { -// return false; -// } -// } -// } -// IF_LISTENED_END(PlayerDestroyBlockEvent) -// return original(this, a3, a4); -// } - -TInstanceHook(bool, "?destroyBlock@GameMode@@UEAA_NAEBVBlockPos@@E@Z", GameMode, BlockPos a3, unsigned __int8 a4) { +TInstanceHook(bool, "?destroyBlock@SurvivalMode@@UEAA_NAEBVBlockPos@@E@Z", GameMode, BlockPos a3, unsigned __int8 a4) { auto player = getPlayer(); - if (player != nullptr && player->isPlayer()) { + if (player && player->isPlayer()) { IF_LISTENED(PlayerDestroyBlockEvent) { PlayerDestroyBlockEvent ev{}; ev.mPlayer = player; From 57c5d2206afd8e3c966a0567e0460d37a2279ce9 Mon Sep 17 00:00:00 2001 From: ShrBox Date: Wed, 3 May 2023 22:13:55 +0800 Subject: [PATCH 2/7] fix: CommandParameter #1248 --- LiteLoader/include/llapi/mc/Bedrock.hpp | 52 ++++++++----------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/LiteLoader/include/llapi/mc/Bedrock.hpp b/LiteLoader/include/llapi/mc/Bedrock.hpp index e10e6301ae..3eff654a1f 100644 --- a/LiteLoader/include/llapi/mc/Bedrock.hpp +++ b/LiteLoader/include/llapi/mc/Bedrock.hpp @@ -24,6 +24,7 @@ class Value; class CommandIntegerRange; struct ActorDefinitionIdentifier; class CommandItem; +class CommandBlockName; #undef BEFORE_EXTRA @@ -161,7 +162,8 @@ template <> MCAPI typeid_t type_id(); template <> MCAPI typeid_t type_id>(); -// template MCAPI typeid_t type_id(); +template<> +MCAPI typeid_t type_id(); template<> MCAPI typeid_t type_id(); template <> @@ -172,8 +174,6 @@ template <> MCAPI typeid_t type_id(); template <> MCAPI typeid_t type_id(); -template <> -MCAPI typeid_t type_id(); //template <> //MCAPI typeid_t type_id>(); template <> @@ -198,46 +198,26 @@ template <> MCAPI typeid_t type_id>(); template <> MCAPI typeid_t type_id>(); -// template MCAPI typeid_t type_id(); +template<> +MCAPI typeid_t type_id(); template <> MCAPI typeid_t type_id(); - -// template MCAPI typeid_t type_id(); - -template <> -inline typeid_t type_id() { - static typeid_t id = - *(typeid_t*)dlsym_real("??$type_id@VCommandRegistry@@PEBUActorDefinitionIdentifier@@@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ"); -// static typeid_t id = ([]() -> typeid_t { -// CommandParameterData data = -// SymCall("??$mandatory@VRideCommand@@PEBUActorDefinitionIdentifier@@@commands@@YA?AVCommandParameterData@@PEQRideCommand@@PEBUActorDefinitionIdentifier@@PEBDPEQ2@_N@Z", -// CommandParameterData, void*, char const*, uintptr_t)(nullptr, "entityType", 0); -// return data.tid; -// })(); - return id; -}; - -template <> -inline typeid_t type_id() { - static typeid_t id = *(typeid_t*)dlsym_real( - "??$type_id@VCommandRegistry@@VCommandItem@@@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ"); - return id; -}; +template<> +MCAPI typeid_t type_id(); //template <> -//inline typeid_t type_id() { -// static typeid_t id = *(typeid_t*)dlsym_real( -// "??$type_id@VCommandRegistry@@H@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ"); +//inline typeid_t type_id() { +// static typeid_t id = +// *(typeid_t*)dlsym_real("??$type_id@VCommandRegistry@@PEBUActorDefinitionIdentifier@@@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ"); +//// static typeid_t id = ([]() -> typeid_t { +//// CommandParameterData data = +//// SymCall("??$mandatory@VRideCommand@@PEBUActorDefinitionIdentifier@@@commands@@YA?AVCommandParameterData@@PEQRideCommand@@PEBUActorDefinitionIdentifier@@PEBDPEQ2@_N@Z", +//// CommandParameterData, void*, char const*, uintptr_t)(nullptr, "entityType", 0); +//// return data.tid; +//// })(); // return id; //}; -template <> -inline typeid_t type_id() { - static typeid_t id = *(typeid_t*)dlsym_real( - "??$type_id@VCommandRegistry@@VCommandBlockName@@@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ"); - return id; -}; - #undef AFTER_EXTRA /** From 3dd3cf3f32d0ec135c649000e95f3844b25fb17d Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 4 May 2023 22:19:12 +0800 Subject: [PATCH 3/7] fix: Actor.getAllEffects #1252 (#1254) --- ScriptEngine/src/api/EntityAPI.cpp | 12 ++++++++---- ScriptEngine/src/api/PlayerAPI.cpp | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ScriptEngine/src/api/EntityAPI.cpp b/ScriptEngine/src/api/EntityAPI.cpp index 1551389bd8..74a1686237 100644 --- a/ScriptEngine/src/api/EntityAPI.cpp +++ b/ScriptEngine/src/api/EntityAPI.cpp @@ -1513,13 +1513,17 @@ Local EntityClass::getAllEffects() { if (!actor) { return Local(); } - auto effects = actor->getAllEffects(); - if (effects.size() == 0) { + if (!actor->getActiveEffectCount()) { return Local(); } Local effectList = Array::newArray(); - for (auto effect : effects) - effectList.add(Number::newNumber((int)effect.getId())); + for (unsigned int i = 0; i <= 30; i++) { + if (actor->getEffect(i)) { + effectList.add(Number::newNumber((int)i)); + } else { + break; + } + } return effectList; } CATCH("Fail in getAllEffects!") diff --git a/ScriptEngine/src/api/PlayerAPI.cpp b/ScriptEngine/src/api/PlayerAPI.cpp index e9dcc24ea6..9d95756906 100644 --- a/ScriptEngine/src/api/PlayerAPI.cpp +++ b/ScriptEngine/src/api/PlayerAPI.cpp @@ -3159,13 +3159,17 @@ Local PlayerClass::getAllEffects() { if (!player) { return Local(); } - auto effects = player->getAllEffects(); - if (effects.size() == 0) { + if (!player->getActiveEffectCount()) { return Local(); } Local effectList = Array::newArray(); - for (auto effect : effects) - effectList.add(Number::newNumber((int)effect.getId())); + for (unsigned int i = 0; i <= 30; i++) { + if (player->getEffect(i)) { + effectList.add(Number::newNumber((int)i)); + } else { + break; + } + } return effectList; } CATCH("Fail in getAllEffects!") From 5b6c4ab5c8d2fa811f6bd4bd98923e3fc676ddd9 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Fri, 5 May 2023 19:08:12 +0800 Subject: [PATCH 4/7] fix: PlayerLeftEvent #1255 (#1257) --- LiteLoader/src/llapi/EventAPI.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/LiteLoader/src/llapi/EventAPI.cpp b/LiteLoader/src/llapi/EventAPI.cpp index c4844b8005..147b0c0388 100644 --- a/LiteLoader/src/llapi/EventAPI.cpp +++ b/LiteLoader/src/llapi/EventAPI.cpp @@ -354,15 +354,27 @@ TInstanceHook(bool, "?setLocalPlayerAsInitialized@ServerPlayer@@QEAAXXZ", Server } /////////////////// PlayerLeft /////////////////// -THook(void, "?disconnect@ServerPlayer@@QEAAXXZ", ServerPlayer* player) { +TInstanceHook(void, "?disconnect@ServerPlayer@@QEAAXXZ", ServerPlayer) { IF_LISTENED(PlayerLeftEvent) { PlayerLeftEvent ev{}; - ev.mPlayer = player; - ev.mXUID = player->getXuid(); + ev.mPlayer = (Player*)this; + ev.mXUID = this->getXuid(); ev.call(); } IF_LISTENED_END(PlayerLeftEvent) - return original(player); + return original(this); +} + +#include "llapi/mc/SimulatedPlayer.hpp" +TInstanceHook(void, "?simulateDisconnect@SimulatedPlayer@@QEAAXXZ", SimulatedPlayer) { + IF_LISTENED(PlayerLeftEvent) { + PlayerLeftEvent ev{}; + ev.mPlayer = (Player*)this; + ev.mXUID = this->getXuid(); + ev.call(); + } + IF_LISTENED_END(PlayerLeftEvent) + return original(this); } /////////////////// PlayerRespawn /////////////////// From 165ad7aa613bcf65f58404e84708687cd6ca4c15 Mon Sep 17 00:00:00 2001 From: ShrBox Date: Fri, 5 May 2023 19:36:54 +0800 Subject: [PATCH 5/7] fix: getAllEffects --- ScriptEngine/src/api/EntityAPI.cpp | 2 -- ScriptEngine/src/api/PlayerAPI.cpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/ScriptEngine/src/api/EntityAPI.cpp b/ScriptEngine/src/api/EntityAPI.cpp index 74a1686237..dfdc4fc927 100644 --- a/ScriptEngine/src/api/EntityAPI.cpp +++ b/ScriptEngine/src/api/EntityAPI.cpp @@ -1520,8 +1520,6 @@ Local EntityClass::getAllEffects() { for (unsigned int i = 0; i <= 30; i++) { if (actor->getEffect(i)) { effectList.add(Number::newNumber((int)i)); - } else { - break; } } return effectList; diff --git a/ScriptEngine/src/api/PlayerAPI.cpp b/ScriptEngine/src/api/PlayerAPI.cpp index 9d95756906..73e3630c2f 100644 --- a/ScriptEngine/src/api/PlayerAPI.cpp +++ b/ScriptEngine/src/api/PlayerAPI.cpp @@ -3166,8 +3166,6 @@ Local PlayerClass::getAllEffects() { for (unsigned int i = 0; i <= 30; i++) { if (player->getEffect(i)) { effectList.add(Number::newNumber((int)i)); - } else { - break; } } return effectList; From 1cef4e6ffd937047b15b3f46f51c6f3a0dc26acc Mon Sep 17 00:00:00 2001 From: ShrBox Date: Sat, 6 May 2023 20:12:28 +0800 Subject: [PATCH 6/7] Revert "feat: add 'RaidMobSpawnEvent' event (#1229)" This reverts commit 43328f32fcbd7985d5130ffb3c89d6dd33d69dbe. --- LiteLoader/include/llapi/EventAPI.h | 33 ----------------------------- LiteLoader/src/llapi/EventAPI.cpp | 20 ----------------- ScriptEngine/src/api/EventAPI.cpp | 11 ---------- 3 files changed, 64 deletions(-) diff --git a/LiteLoader/include/llapi/EventAPI.h b/LiteLoader/include/llapi/EventAPI.h index 5e3bf03ad7..4e6d3ad4a9 100644 --- a/LiteLoader/include/llapi/EventAPI.h +++ b/LiteLoader/include/llapi/EventAPI.h @@ -51,7 +51,6 @@ class BlockLegacy; class ArmorStand; class Objective; struct ScoreboardId; -class Village; /** * @brief The event system. @@ -714,38 +713,6 @@ class MobSpawnedEvent : public EventTemplate { Vec3 mPos; int mDimensionId = -1; }; -/** - * @brief An event that Raid mob spawn. - * - * @note This event cannot be suppressed. - */ -class RaidMobSpawnEvent : public EventTemplate { -public: - - /** - * @brief Village Center generated by which village raid - * - */ - Vec3 mVillageCenter; - - /** - * @brief Spawn Pos; - * - */ - Vec3 mPos; - - /** - * @brief Raid spawn wave number - * - */ - int mWaveNum; - - /** - * @brief Spawn Entity IDs; - * - */ - int mActorNum; -}; /* endregion */ diff --git a/LiteLoader/src/llapi/EventAPI.cpp b/LiteLoader/src/llapi/EventAPI.cpp index 147b0c0388..6011c31db6 100644 --- a/LiteLoader/src/llapi/EventAPI.cpp +++ b/LiteLoader/src/llapi/EventAPI.cpp @@ -300,7 +300,6 @@ DECLARE_EVENT_DATA(PlayerBedEnterEvent); DECLARE_EVENT_DATA(ScriptPluginManagerEvent); DECLARE_EVENT_DATA(MobTrySpawnEvent); DECLARE_EVENT_DATA(MobSpawnedEvent); -DECLARE_EVENT_DATA(RaidMobSpawnEvent); DECLARE_EVENT_DATA(FormResponsePacketEvent); DECLARE_EVENT_DATA(ResourcePackInitEvent); DECLARE_EVENT_DATA(PlayerOpenInventoryEvent); @@ -2125,25 +2124,6 @@ TClasslessInstanceHook(void, "?_setRespawnStage@EndDragonFight@@AEAAXW4RespawnAn } } -#include "llapi/mc/Village.hpp" - -TInstanceHook(void, - "?_spawnRaidGroup@Village@@AEBA_NVVec3@@EAEAV?$unordered_set@UActorUniqueID@@U?$hash@UActorUniqueID@@@" - "std@@U?$equal_to@UActorUniqueID@@@3@V?$allocator@UActorUniqueID@@@3@@std@@@Z", - Village, Vec3 pos, unsigned char num, std::unordered_set& actorIDs) { - // actorIDs其实是std::unordered_set,懒得写hash函数 - original(this, pos, num, actorIDs); - IF_LISTENED(RaidMobSpawnEvent) { - RaidMobSpawnEvent ev{}; - ev.mVillageCenter = this->getCenter(); - ev.mPos = pos; - ev.mWaveNum = num; - ev.mActorNum = actorIDs.size(); - ev.call(); - } - IF_LISTENED_END(RaidMobSpawnEvent) -} - #include "llapi/impl/FormPacketHelper.h" #include "llapi/mc/Json.hpp" diff --git a/ScriptEngine/src/api/EventAPI.cpp b/ScriptEngine/src/api/EventAPI.cpp index 0ef9b68943..a24d4630bf 100644 --- a/ScriptEngine/src/api/EventAPI.cpp +++ b/ScriptEngine/src/api/EventAPI.cpp @@ -89,7 +89,6 @@ enum class EVENT_TYPES : int { /* Entity Events */ onMobDie, onMobHurt, - onRaidMobSpawn, onEntityExplode, onProjectileHitEntity, onWitherBossDestroy, @@ -840,16 +839,6 @@ void EnableEventListener(int eventId) { }); break; - case EVENT_TYPES::onRaidMobSpawn: - Event::RaidMobSpawnEvent::subscribe([](const RaidMobSpawnEvent& ev) { - IF_LISTENED(EVENT_TYPES::onRaidMobSpawn) { - CallEvent(EVENT_TYPES::onRaidMobSpawn, IntPos::newPos(ev.mVillageCenter), IntPos::newPos(ev.mPos), - Number::newNumber(ev.mWaveNum), Number::newNumber(ev.mActorNum)); - } - IF_LISTENED_END(EVENT_TYPES::onRaidMobSpawn) - }); - break; - case EVENT_TYPES::onStepOnPressurePlate: Event::EntityStepOnPressurePlateEvent::subscribe([](const EntityStepOnPressurePlateEvent& ev) { IF_LISTENED(EVENT_TYPES::onStepOnPressurePlate) { From 7f8b1beead2bc0a5580f73d044ced128d2105f91 Mon Sep 17 00:00:00 2001 From: ShrBox Date: Sat, 6 May 2023 20:23:50 +0800 Subject: [PATCH 7/7] chore: update release note --- RELEASE_NOTES.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e23f9e2536..52b18503ce 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,12 +1,11 @@ -# Release 2.13.0-beta.1 +# Release 2.13.0 ![BDS 1.19.81.01](https://img.shields.io/badge/BDS-1.19.81.01-blue?style=for-the-badge) ![Protocol 582](https://img.shields.io/badge/Protocol-582-orange?style=for-the-badge) ## Added -feat: add 'RaidMobSpawnEvent' event (#1229) (by @Qiuzhizhe) feat(llse): effect method of Entity(#1225) (#1236) (by @harryxi) -feat: adapt to 1.19.81 (#1237) (by @ShrBox @dreamguxiang @OEOTYAN @quizhizhe) +feat: adapt to 1.19.81 (#1237) (by @ShrBox @dreamguxiang @OEOTYAN @quizhizhe @Tsubasa6848) ## Changed