From 7c71fbf5906fba15733d1a98557b550a7ffab651 Mon Sep 17 00:00:00 2001 From: twoone3l <3197653242@qq.com> Date: Fri, 20 Aug 2021 22:58:04 +0800 Subject: [PATCH] =?UTF-8?q?1.7.2=E6=9B=B4=E6=96=B0=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9EonUseSignBlock=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BDSpyrunner/Header File/Block.h | 1 + BDSpyrunner/Header File/Event.h | 6 ++++-- BDSpyrunner/Source File/Block.cpp | 5 +++++ BDSpyrunner/Source File/mod.cpp | 23 ++++++++++++++++++++--- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/BDSpyrunner/Header File/Block.h b/BDSpyrunner/Header File/Block.h index 15692151..66e00404 100644 --- a/BDSpyrunner/Header File/Block.h +++ b/BDSpyrunner/Header File/Block.h @@ -15,6 +15,7 @@ struct BlockActor { }; struct BlockSource { Block* getBlock(const BlockPos* bp); + BlockActor* getBlockEntity(const BlockPos* bp); bool setBlock(Block* b, BlockPos* bp); void neighborChanged(const BlockPos* pos); void updateNeighborsAt(const BlockPos* pos); diff --git a/BDSpyrunner/Header File/Event.h b/BDSpyrunner/Header File/Event.h index 72f9df66..470c0367 100644 --- a/BDSpyrunner/Header File/Event.h +++ b/BDSpyrunner/Header File/Event.h @@ -44,7 +44,8 @@ enum class EventCode { onSneak, onBlockInteracted, onFireSpread, - onBlockExploded + onBlockExploded, + onUseSignBlock, }; const std::unordered_map events{ @@ -88,5 +89,6 @@ const std::unordered_map events{ {"onSneak",EventCode::onSneak}, {"onBlockInteracted",EventCode::onBlockInteracted}, {"onFireSpread",EventCode::onFireSpread}, -{"onBlockExploded",EventCode::onBlockExploded} +{"onBlockExploded",EventCode::onBlockExploded}, +{"onUseSignBlock",EventCode::onUseSignBlock}, }; diff --git a/BDSpyrunner/Source File/Block.cpp b/BDSpyrunner/Source File/Block.cpp index c31e075c..08ee89f6 100644 --- a/BDSpyrunner/Source File/Block.cpp +++ b/BDSpyrunner/Source File/Block.cpp @@ -33,6 +33,11 @@ Block* BlockSource::getBlock(const BlockPos* bp) { this, bp); } +BlockActor* BlockSource::getBlockEntity(const BlockPos* bp) { + return SymCall("?getBlockEntity@BlockSource@@QEAAPEAVBlockActor@@AEBVBlockPos@@@Z", + this, bp); +} + bool BlockSource::setBlock(Block* b, BlockPos* bp) { return SymCall("?setBlock@BlockSource@@QEAA_NAEBVBlockPos@@AEBVBlock@@HPEBUActorBlockSyncMessage@@@Z", this, bp, b, 3, nullptr); diff --git a/BDSpyrunner/Source File/mod.cpp b/BDSpyrunner/Source File/mod.cpp index bba43afb..34c5b24c 100644 --- a/BDSpyrunner/Source File/mod.cpp +++ b/BDSpyrunner/Source File/mod.cpp @@ -16,7 +16,7 @@ constexpr auto VERSION_1 = 1; constexpr auto VERSION_2 = 7; -constexpr auto VERSION_3 = 1; +constexpr auto VERSION_3 = 2; constexpr auto PLUGIN_PATH = L"plugins/py"; constexpr auto MODULE_NAME = "mc"; @@ -715,7 +715,7 @@ HOOK(onBlockInteracted, void, "?onBlockInteractedWith@VanillaServerGameplayEvent )) return original(_this, pl, bp); } -//方块爆炸(未测试) +//方块被爆炸破坏(未测试) HOOK(onBlockExploded, void, "?onExploded@Block@@QEBAXAEAVBlockSource@@AEBVBlockPos@@PEAVActor@@@Z", Block* _this, BlockSource* bs, BlockPos* bp, Actor* actor) { BlockLegacy* bl = bs->getBlock(bp)->getBlockLegacy(); @@ -729,7 +729,24 @@ HOOK(onBlockExploded, void, "?onExploded@Block@@QEBAXAEAVBlockSource@@AEBVBlockP )) return original(_this, bs, bp, actor); } - +//方块侧面放触发,点击牌子触发 +HOOK(onUseSingBlock, uintptr_t, "?use@SignBlock@@UEBA_NAEAVPlayer@@AEBVBlockPos@@E@Z", + uintptr_t _this, Player* a1, BlockPos* a2) { + BlockSource* bs = a1->getRegion(); + BlockActor* ba = bs->getBlockEntity(a2); + string text; + //获取沉浸式文本内容 + SymCall("?getImmersiveReaderText@SignBlockActor@@UEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAVBlockSource@@@Z", + ba, &text, bs); + if (EventCallBack(EventCode::onUseSignBlock, + "{s:O,s:s,s:[i,i,i]}", + "player", PyEntity_FromEntity(a1), + "text", text.c_str(), + "pos", a2->x, a2->y, a2->z + )) + return original(_this, a1, a2); + return 0; +} #pragma endregion #pragma region API Function //最小版本要求