Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
1.7.2更新,新增onUseSignBlock事件
Browse files Browse the repository at this point in the history
  • Loading branch information
twoone3l committed Aug 20, 2021
1 parent 4b6e580 commit 7c71fbf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions BDSpyrunner/Header File/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions BDSpyrunner/Header File/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ enum class EventCode {
onSneak,
onBlockInteracted,
onFireSpread,
onBlockExploded
onBlockExploded,
onUseSignBlock,
};

const std::unordered_map<std::string, EventCode> events{
Expand Down Expand Up @@ -88,5 +89,6 @@ const std::unordered_map<std::string, EventCode> events{
{"onSneak",EventCode::onSneak},
{"onBlockInteracted",EventCode::onBlockInteracted},
{"onFireSpread",EventCode::onFireSpread},
{"onBlockExploded",EventCode::onBlockExploded}
{"onBlockExploded",EventCode::onBlockExploded},
{"onUseSignBlock",EventCode::onUseSignBlock},
};
5 changes: 5 additions & 0 deletions BDSpyrunner/Source File/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Block* BlockSource::getBlock(const BlockPos* bp) {
this, bp);
}

BlockActor* BlockSource::getBlockEntity(const BlockPos* bp) {
return SymCall<BlockActor*>("?getBlockEntity@BlockSource@@QEAAPEAVBlockActor@@AEBVBlockPos@@@Z",
this, bp);
}

bool BlockSource::setBlock(Block* b, BlockPos* bp) {
return SymCall<bool>("?setBlock@BlockSource@@QEAA_NAEBVBlockPos@@AEBVBlock@@HPEBUActorBlockSyncMessage@@@Z",
this, bp, b, 3, nullptr);
Expand Down
23 changes: 20 additions & 3 deletions BDSpyrunner/Source File/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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();
Expand All @@ -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<string&>("?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
//最小版本要求
Expand Down

0 comments on commit 7c71fbf

Please sign in to comment.