From f24c726a81d5995a0768f4add69627f9b8f119d1 Mon Sep 17 00:00:00 2001 From: Qiuzhizhe <42761326+quizhizhe@users.noreply.github.com> Date: Fri, 17 Mar 2023 22:29:15 -0700 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E8=8C=83Event=E9=87=8C=E7=9A=84?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LiteLoader/src/llapi/EventAPI.cpp | 831 ++++++++++-------------------- 1 file changed, 283 insertions(+), 548 deletions(-) diff --git a/LiteLoader/src/llapi/EventAPI.cpp b/LiteLoader/src/llapi/EventAPI.cpp index 68402be..b51125b 100644 --- a/LiteLoader/src/llapi/EventAPI.cpp +++ b/LiteLoader/src/llapi/EventAPI.cpp @@ -208,7 +208,7 @@ bool EventManager::callToPlugin(std::string pluginName, EVENT& ev) { /////////////////////////////// Event Declare /////////////////////////////// #define DECLARE_EVENT_DATA(EVENT) \ - template class EventManager; \ + template class Event::EventManager; \ /*********************** For Compatibility ***********************/ \ std::list>> EventTemplate::listeners; \ std::list>> EventTemplate::listenersNoConst; @@ -307,23 +307,25 @@ DECLARE_EVENT_DATA(ResourcePackInitEvent); /////////////////// PreJoin /////////////////// TClasslessInstanceHook(void, "?sendLoginMessageLocal@ServerNetworkHandler@@QEAAXAEBVNetworkIdentifier@@" "AEBVConnectionRequest@@AEAVServerPlayer@@@Z", - NetworkIdentifier* Ni, ConnectionRequest* a3, ServerPlayer* sp) { + NetworkIdentifier* networkIdentifier, + ConnectionRequest* connectionRequest, + ServerPlayer* serverPlayer) { IF_LISTENED(PlayerPreJoinEvent) { PlayerPreJoinEvent ev{}; - ev.mPlayer = sp; - ev.mIP = Ni->getIP(); - ev.mXUID = sp->getXuid(); + ev.mPlayer = serverPlayer; + ev.mIP = networkIdentifier->getIP(); + ev.mXUID = serverPlayer->getXuid(); if (!ev.call()) return; } IF_LISTENED_END(PlayerPreJoinEvent) - return original(this, Ni, a3, sp); + return original(this, networkIdentifier, connectionRequest, serverPlayer); } /////////////////// PlayerJoin /////////////////// TInstanceHook(bool, "?onReady_ClientGeneration@ServerNetworkHandler@@QEAAXAEAVPlayer@@AEBVNetworkIdentifier@@@Z", - ServerNetworkHandler,Player* player,NetworkIdentifier *net) { + ServerNetworkHandler,Player* player,NetworkIdentifier *networkIdentifier) { IF_LISTENED(PlayerJoinEvent) { PlayerJoinEvent ev{}; ev.mPlayer = player; @@ -332,46 +334,48 @@ TClasslessInstanceHook(void, "?sendLoginMessageLocal@ServerNetworkHandler@@QEAAX return false; } IF_LISTENED_END(PlayerJoinEvent) - return original(this,player,net); + return original(this,player,networkIdentifier); } /////////////////// PlayerLeft /////////////////// TInstanceHook(void, "?_onPlayerLeft@ServerNetworkHandler@@AEAAXPEAVServerPlayer@@_N@Z", - ServerNetworkHandler,ServerPlayer* sp,char a3) { + ServerNetworkHandler,ServerPlayer* serverPlayer,bool skipMessage) { IF_LISTENED(PlayerLeftEvent) { PlayerLeftEvent ev{}; - ev.mPlayer = sp; - ev.mXUID = sp->getXuid(); + ev.mPlayer = serverPlayer; + ev.mXUID = serverPlayer->getXuid(); ev.call(); } IF_LISTENED_END(PlayerLeftEvent) - return original(this,sp,a3); + return original(this,serverPlayer,skipMessage); } /////////////////// PlayerRespawn /////////////////// TClasslessInstanceHook(void, "?handle@?$PacketHandlerDispatcherInstance@VPlayerActionPacket@@$0A@@@UEBAXAEBVNetworkIdentifier@@AEAVNetEventCallback@@AEAV?$shared_ptr@VPacket@@@std@@@Z", - NetworkIdentifier* id, ServerNetworkHandler* handler, void* pPacket) { + NetworkIdentifier* networkIdentifier, + ServerNetworkHandler* serverNetworkHandler, + void* pPacket) { PlayerActionPacket* packet = *(PlayerActionPacket**)pPacket; if (packet->actionType == PlayerActionType::Respawn) { IF_LISTENED(PlayerRespawnEvent) { PlayerRespawnEvent ev{}; - ev.mPlayer = packet->getPlayerFromPacket(handler, id); + ev.mPlayer = packet->getPlayerFromPacket(serverNetworkHandler, networkIdentifier); if (!ev.mPlayer) return; ev.call(); } IF_LISTENED_END(PlayerRespawnEvent) } - return original(this, id, handler, pPacket); + return original(this, networkIdentifier, serverNetworkHandler, pPacket); } /////////////////// PlayerChat /////////////////// TInstanceHook(void, "?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@AEBVTextPacket@@@Z", - ServerNetworkHandler, NetworkIdentifier* id, TextPacket* text) { + ServerNetworkHandler, NetworkIdentifier* networkIdentifier, TextPacket* text) { IF_LISTENED(PlayerChatEvent) { Event::PlayerChatEvent ev{}; - ev.mPlayer = this->getServerPlayer(*id); + ev.mPlayer = this->getServerPlayer(*networkIdentifier); if (!ev.mPlayer) return; ev.mMessage = text->mMessage; @@ -380,7 +384,7 @@ TInstanceHook(void, "?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@A text->mMessage = ev.mMessage; } IF_LISTENED_END(PlayerChatEvent); - return original(this, id, text); + return original(this, networkIdentifier, text); } /////////////////// PlayerChangeDim /////////////////// @@ -397,24 +401,24 @@ public: // 更换符号 TClasslessInstanceHook(bool, "?requestPlayerChangeDimension@Level@@QEAAXAEAVPlayer@@V?$unique_ptr@VChangeDimensionRequest@@U?$default_delete@VChangeDimensionRequest@@@std@@@std@@@Z", - Player* sp, std::unique_ptr request) { + Player* player, std::unique_ptr request) { - if (request->mToDimensionId == sp->getDimensionId()) - return original(this, sp, std::move(request)); + if (request->mToDimensionId == player->getDimensionId()) + return original(this, player, std::move(request)); // printf("PlayerChangeDimension Player:%s, DimensionID:%s\n",sp->getNameTag().c_str(),request->mToDimensionId); IF_LISTENED(PlayerChangeDimEvent) { PlayerChangeDimEvent ev{}; - ev.mPlayer = sp; + ev.mPlayer = player; ev.mToDimensionId = request->mToDimensionId; if (!ev.call()) return false; } IF_LISTENED_END(PlayerChangeDimEvent) - return original(this, sp, std::move(request)); + return original(this, player, std::move(request)); } -int num = 0; + /////////////////// PlayerJump /////////////////// TInstanceHook(void, "?jumpFromGround@Player@@UEAAXXZ", Player) { IF_LISTENED(PlayerJumpEvent) { @@ -429,37 +433,37 @@ TInstanceHook(void, "?jumpFromGround@Player@@UEAAXXZ", Player) { /////////////////// PlayerSneak /////////////////// //不清楚这个符合能不能正常触发 TClasslessInstanceHook(void, "?onActorSneakChanged@ScriptServerActorEventListener@@UEAA?AW4EventResult@@AEAVActor@@_N@Z", - Actor* ac, bool isSneaking) { + Actor* actor, bool isSneaking) { // printf("PlayerSneak Player:%s, IsSneaking:%s\n",ac->getNameTag().c_str(),isSneaking); IF_LISTENED(PlayerSneakEvent) { PlayerSneakEvent ev{}; - ev.mPlayer = (Player*)ac; + ev.mPlayer = (Player*)actor; ev.mIsSneaking = isSneaking; ev.call(); isSneaking = ev.mIsSneaking; } IF_LISTENED_END(PlayerSneakEvent) - return original(this, ac, isSneaking); + return original(this, actor, isSneaking); } /////////////////// PlayerAttackEntity /////////////////// //同名函数没有了伤害原因参数 TInstanceHook(bool, "?attack@Player@@UEAA_NAEAVActor@@@Z", - Player, Actor* ac) { + Player, Actor* actor) { IF_LISTENED(PlayerAttackEvent) { PlayerAttackEvent ev{}; ev.mPlayer = this; - ev.mTarget = ac; - ev.mAttackDamage = this->calculateAttackDamage(*ac); + ev.mTarget = actor; + ev.mAttackDamage = this->calculateAttackDamage(*actor); if (!ev.call()) return false; - ac = ev.mTarget; + actor = ev.mTarget; } IF_LISTENED_END(PlayerAttackEvent) - return original(this, ac); + return original(this, actor); } /////////////////// PlayerAttackBlock /////////////////// @@ -480,41 +484,43 @@ TInstanceHook(void, "?jumpFromGround@Player@@UEAAXXZ", Player) { /////////////////// PlayerTakeItem /////////////////// TInstanceHook(bool, "?take@Player@@QEAA_NAEAVActor@@HH@Z", - Player, Actor* actor, int a2, int a3) { + Player, Actor* actor, int orgCount, int favoredSlot) { IF_LISTENED(PlayerPickupItemEvent) { - ItemStack* it = nullptr; + ItemStack* itemStack = nullptr; if (actor->isItemActor()) - it = ((ItemActor*)actor)->getItemStack(); + itemStack = ((ItemActor*)actor)->getItemStack(); PlayerPickupItemEvent ev{}; ev.mPlayer = this; ev.mItemEntity = actor; - ev.mItemStack = it; + ev.mItemStack = itemStack; if (!ev.call()) return false; } IF_LISTENED_END(PlayerPickupItemEvent) - return original(this, actor, a2, a3); + return original(this, actor, orgCount, favoredSlot); } -bool isQDrop; -bool isDieDrop; +namespace { + bool isQDrop; + bool isDieDrop; +} /////////////////// PlayerDropItem /////////////////// TInstanceHook(bool, "?drop@Player@@UEAA_NAEBVItemStack@@_N@Z", - Player, ItemStack* it, bool a3) { + Player, ItemStack* itemStack, bool randomly) { if (isQDrop) - return original(this, it, a3); + return original(this, itemStack, randomly); if (isDieDrop) - return original(this, it, a3); + return original(this, itemStack, randomly); IF_LISTENED(PlayerDropItemEvent) { PlayerDropItemEvent ev{}; ev.mPlayer = this; - ev.mItemStack = it; + ev.mItemStack = itemStack; if (!ev.call()) return false; } IF_LISTENED_END(PlayerDropItemEvent) - return original(this, it, a3); + return original(this, itemStack, randomly); } /////////////////// PlayerConsumeTotem /////////////////// @@ -574,376 +580,103 @@ TInstanceHook(void, "?onEffectRemoved@ServerPlayer@@MEAAXAEAVMobEffectInstance@@ // 没有这个符号 // 更换点位 TClasslessInstanceHook(void, "?startDestroyBlock@GameMode@@UEAA_NAEBVBlockPos@@EAEA_N@Z", - Player* pl, BlockPos* bp, unsigned __int8 face, bool *hasDestroyedBlock) { + Player* player, BlockPos* blockPos, unsigned __int8 face, bool *hasDestroyedBlock) { IF_LISTENED(PlayerStartDestroyBlockEvent) { PlayerStartDestroyBlockEvent ev{}; - ev.mPlayer = pl; - ev.mBlockInstance = Level::getBlockInstance(bp, Level::getBlockSource(pl)); + ev.mPlayer = player; + ev.mBlockInstance = Level::getBlockInstance(blockPos, Level::getBlockSource(player)); ev.call(); } IF_LISTENED_END(PlayerStartDestroyBlockEvent) - return original(this, pl, bp,face,hasDestroyedBlock); + return original(this, player, blockPos,face,hasDestroyedBlock); } /////////////////// PlayerPlaceBlock /////////////////// #include // 符号变更 TInstanceHook(char, "?checkBlockPermissions@BlockSource@@QEAA_NAEAVActor@@AEBVBlockPos@@EAEBVItemStack@@_N@Z", - BlockSource, Actor* ac, BlockPos* bp, unsigned __int8 facing, ItemStackBase* item, bool a6) { - if (ac->isPlayer()) { + BlockSource, Actor* actor, BlockPos* blockPos, unsigned __int8 facing, ItemStackBase* item, bool generateParticle) { + if (actor->isPlayer()) { IF_LISTENED(PlayerPlaceBlockEvent) { - auto pl = (Player*)ac; + auto player = (Player*)actor; PlayerPlaceBlockEvent ev{}; - ev.mPlayer = pl; - ev.mBlockInstance = this->getBlockInstance(*bp); + ev.mPlayer = player; + ev.mBlockInstance = this->getBlockInstance(*blockPos); if (!ev.call()) { // this pointer is not used. - ((ItemUseInventoryTransaction*)nullptr)->resendBlocksAroundArea(*pl, *bp, facing); + ((ItemUseInventoryTransaction*)nullptr)->resendBlocksAroundArea(*player, *blockPos, facing); return false; } } IF_LISTENED_END(PlayerPlaceBlockEvent) } - return original(this, ac, bp, facing, item, a6); + return original(this, actor, blockPos, facing, item, generateParticle); } /////////////////// BlockPlacedByPlayerEvent /////////////////// TClasslessInstanceHook(void, "?sendBlockPlacedByPlayer@BlockEventCoordinator@@QEAAXAEAVPlayer@@AEBVBlock@@AEBVBlockPos@@_N@Z", - Player* pl, Block* bl, BlockPos* bp, bool a5) + Player* player, Block* block, BlockPos* blockPos, bool isUnderwater) { IF_LISTENED(BlockPlacedByPlayerEvent) { BlockPlacedByPlayerEvent ev{}; - ev.mPlayer = pl; - ev.mBlockInstance = BlockInstance::createBlockInstance(bl, *bp, pl->getDimensionId()); + ev.mPlayer = player; + ev.mBlockInstance = BlockInstance::createBlockInstance(block, *blockPos, player->getDimensionId()); ev.call(); } IF_LISTENED_END(BlockPlacedByPlayerEvent) - original(this, pl, bl, bp, a5); + original(this, player, block, blockPos, isUnderwater); } -/* -#include -#include -TInstanceHook(bool, "?_useOn@BlockItem@@MEBA_NAEAVItemStack@@AEAVActor@@VBlockPos@@EAEBVVec3@@@Z", - Item, ItemStack* a2, Actor* ac, BlockPos* a4, unsigned __int8 a5, class Vec3* a6) -{ - IF_LISTENED(PlayerPlaceBlockEvent) - { - Block* RenderBlock; - auto RegionConst = ac->getBlockSource(); - if (!a2->getCount()) { - return 0; - } - auto& bls = this->getLegacyBlock(); - if (bls && bls.get() != 0i64) - RenderBlock = const_cast(&bls.get()->getRenderBlock()); - else - RenderBlock = const_cast(BedrockBlocks::mAir); - if (RegionConst->mayPlace(*RenderBlock, *a4, a5, (class Actor*)ac, 0)) { - if (Player::isValid((Player*)ac)) - { - PlayerPlaceBlockEvent ev{}; - ev.mPlayer = (Player*)ac; - ev.mBlockInstance = BlockInstance::createBlockInstance(Block::create(RenderBlock->getTypeName(), a2->getAux()), *a4, (int)RegionConst->getDimensionId()); - if (!ev.call()) - return false; - } - } - } - IF_LISTENED_END(PlayerPlaceBlockEvent) - - return original(this, a2, ac, a4, a5,a6); -} - -TClasslessInstanceHook(bool, "?_useOn@BambooBlockItem@@UEBA_NAEAVItemStack@@AEAVActor@@VBlockPos@@EAEBVVec3@@@Z", - ItemStack* a2, Actor* a3, BlockPos a4, unsigned char a5, Vec3* a6) -{ - IF_LISTENED(PlayerPlaceBlockEvent) - { - if (Player::isValid((Player*)a3)) - { - auto& bs = a3->getRegion(); - auto onBlockPos = a4.relative(a5, -1); - auto onBlock = &bs.getBlock(onBlockPos).getDefaultState(); - auto underBlock = &bs.getBlock(a4.relative(0, 1)).getDefaultState(); - if (onBlock == VanillaBlocks::mBambooBlock || onBlock == VanillaBlocks::mBambooSapling - || underBlock == VanillaBlocks::mBambooBlock || underBlock == VanillaBlocks::mBambooSapling) - return original(this, a2, a3, a4, a5, a6); // listen in BlockSource::mayPlace - - PlayerPlaceBlockEvent ev{}; - ev.mPlayer = (Player*)a3; - ev.mBlockInstance = BlockInstance::createBlockInstance(const_cast(VanillaBlocks::mBambooSapling), a4, (int)a3->getDimensionId()); - if (!ev.call()) - return false; - } - } - IF_LISTENED_END(PlayerPlaceBlockEvent) - return original(this, a2, a3, a4, a5, a6); -} - -//THook(bool, "?_useOn@BannerItem@@UEBA_NAEAVItemStack@@AEAVActor@@VBlockPos@@EMMM@Z", __int64 a1, ItemStackBase* a2, Actor* a3, const struct BlockPos* a4, unsigned __int8 a5, int a6, int a7, int a8) -//{ -// IF_LISTENED(PlayerPlaceBlockEvent) -// { -// if (Player::isValid((Player*)a3)) -// { -// PlayerPlaceBlockEvent ev{}; -// ev.mPlayer = (Player*)a3; -// ev.mBlockInstance = BlockInstance::createBlockInstance(const_cast(a2->getBlock()), *a4, (int)a3->getDimensionId()); -// if (!ev.call()) -// return false; -// } -// } -// IF_LISTENED_END(PlayerPlaceBlockEvent) -// return original(a1, a2, a3, a4, a5, a6); -//} - -TClasslessInstanceHook(bool, "?_tryUseOn@BedItem@@AEBA_NAEAVItemStackBase@@AEAVActor@@VBlockPos@@EAEBVVec3@@@Z", - ItemStackBase *a2, Actor* a3, BlockPos a4, unsigned char a5, Vec3* a6) -{ - IF_LISTENED(PlayerPlaceBlockEvent) - { - if (Player::isValid((Player*)a3)) - { - PlayerPlaceBlockEvent ev{}; - ev.mPlayer = (Player*)a3; - ev.mBlockInstance = BlockInstance::createBlockInstance(const_cast(VanillaBlocks::mBed), a4, (int)a3->getDimensionId()); - if (!ev.call()) - return false; - } - } - IF_LISTENED_END(PlayerPlaceBlockEvent) - return original(this, a2, a3, a4, a5, a6); -} - -TClasslessInstanceHook(bool, "?_useOn@DyePowderItem@@EEBA_NAEAVItemStack@@AEAVActor@@VBlockPos@@EAEBVVec3@@@Z", - ItemStack* a2, Actor* a3, BlockPos a4, unsigned char a5, Vec3* a6) -{ - IF_LISTENED(PlayerPlaceBlockEvent) - { - if (Player::isValid((Player*)a3)) - { - PlayerPlaceBlockEvent ev{}; - ev.mPlayer = (Player*)a3; - auto& PlacementBlock = VanillaBlocks::mCocoa->getPlacementBlock(*a3, a4, a5, a4.toVec3(), 0); - ev.mBlockInstance = BlockInstance::createBlockInstance(const_cast(&PlacementBlock), a4, (int)a3->getDimensionId()); - if (!ev.call()) - return false; - } - } - IF_LISTENED_END(PlayerPlaceBlockEvent) - return original(this, a2, a3, a4, a5, a6); -} - -TClasslessInstanceHook(bool, "?_useOn@DoorItem@@EEBA_NAEAVItemStack@@AEAVActor@@VBlockPos@@EAEBVVec3@@@Z", - ItemStack* a2, Actor* a3, BlockPos a4, unsigned char a5, Vec3* a6) -{ - IF_LISTENED(PlayerPlaceBlockEvent) - { - if (Player::isValid((Player*)a3)) - { - PlayerPlaceBlockEvent ev{}; - ev.mPlayer = (Player*)a3; - const Block* v11 = nullptr; - switch (dAccess(this)) - { - case 0: - v11 = VanillaBlocks::mWoodenDoor; - break; - case 1: - v11 = VanillaBlocks::mWoodenDoorSpruce; - break; - case 2: - v11 = VanillaBlocks::mWoodenDoorBirch; - break; - case 3: - v11 = VanillaBlocks::mWoodenDoorJungle; - break; - case 4: - v11 = VanillaBlocks::mWoodenDoorAcacia; - break; - case 5: - v11 = VanillaBlocks::mWoodenDoorDarkOak; - break; - case 6: - v11 = VanillaBlocks::mIronDoor; - break; - case 7: - v11 = VanillaBlocks::mCrimsonDoor; - break; - case 8: - v11 = VanillaBlocks::mWarpedDoor; - break; - case 9: - v11 = VanillaBlocks::mMangroveDoor; - break; - } - if (!v11) return false; - ev.mBlockInstance = BlockInstance::createBlockInstance(const_cast(v11), {a4.x, a4.y + 1, a4.z}, (int)a3->getDimensionId()); - if (!ev.call()) - return false; - } - } - IF_LISTENED_END(PlayerPlaceBlockEvent) - return original(this, a2, a3, a4, a5, a6); -} - -TClasslessInstanceHook(bool, "?_useOn@RedStoneDustItem@@EEBA_NAEAVItemStack@@AEAVActor@@VBlockPos@@EAEBVVec3@@@Z", - ItemStack* a2, Actor* a3, BlockPos a4, unsigned char a5, Vec3* a6) -{ - IF_LISTENED(PlayerPlaceBlockEvent) - { - if (Player::isValid((Player*)a3)) - { - PlayerPlaceBlockEvent ev{}; - ev.mPlayer = (Player*)a3; - ev.mBlockInstance = BlockInstance::createBlockInstance(const_cast(VanillaBlocks::mRedStoneDust), a4, (int)a3->getDimensionId()); - if (!ev.call()) - return false; - } - } - IF_LISTENED_END(PlayerPlaceBlockEvent) - return original(this, a2, a3, a4, a5, a6); -} - -//THook(bool, "?_useOn@SignItem@@UEBA_NAEAVItemStack@@AEAVActor@@VBlockPos@@EMMM@Z", -// class SignItem* a1, ItemStack* a2, Actor* a3, BlockPos a4, unsigned char a5, Vec3* a6) -//{ -// IF_LISTENED(PlayerPlaceBlockEvent) -// { -// if (Player::isValid((Player*)a3)) -// { -// auto& blockMap = dAccess>>(a1, 552); // SignItem::SignItem -// auto& signType = dAccess(a1, 568); // SignItem::SignItem -// auto block = a5 == 1 ? blockMap[signType].first : blockMap[signType].second; -// PlayerPlaceBlockEvent ev{}; -// ev.mPlayer = (Player*)a3; -// ev.mBlockInstance = BlockInstance::createBlockInstance(block, a4, (int)a3->getDimensionId()); -// if (!ev.call()) -// return false; -// } -// } -// IF_LISTENED_END(PlayerPlaceBlockEvent) -// return original(a1, a2, a3, a4, a5, a6); -//} - -TInstanceHook(bool, "?_calculatePlacePos@SignItem@@EEBA_NAEAVItemStackBase@@AEAVActor@@AEAEAEAVBlockPos@@@Z", - SignItem, ItemStackBase* a2, Actor* a3, unsigned char& a4, class BlockPos* a5) -{ - auto rtn = original(this, a2, a3, a4, a5); - if (!rtn) - return rtn; - IF_LISTENED(PlayerPlaceBlockEvent) - { - if (Player::isValid((Player*)a3)) - { - // map> blockMap - auto& blockMap = dAccess>>(this, 552); // SignItem::SignItem - auto& signType = dAccess(this, 568); // SignItem::SignItem - auto block = a4 == 1 ? blockMap[signType].first : blockMap[signType].second; - PlayerPlaceBlockEvent ev{}; - ev.mPlayer = (Player*)a3; - ev.mBlockInstance = BlockInstance::createBlockInstance(block, *a5, (int)a3->getDimensionId()); - if (!ev.call()) - return false; - } - } - IF_LISTENED_END(PlayerPlaceBlockEvent) - return rtn; -} - -//THook(bool, "?_useOn@BlockPlanterItem@@MEBA_NAEAVItemStack@@AEAVActor@@VBlockPos@@EMMM@Z", -// class BlockPlanterItem* a1, ItemStack* a2, Actor* a3, BlockPos a4, unsigned char a5, Vec3* a6) -//{ -// IF_LISTENED(PlayerPlaceBlockEvent) -// { -// if (Player::isValid((Player*)a3)) -// { -// PlayerPlaceBlockEvent ev{}; -// ev.mPlayer = (Player*)a3; -// ev.mBlockInstance = BlockInstance::createBlockInstance(dAccess(a1, 69*8), a4, (int)a3->getDimensionId()); -// if (!ev.call()) -// return false; -// } -// } -// IF_LISTENED_END(PlayerPlaceBlockEvent) -// return original(a1, a2, a3, a4, a5, a6); -//} - -#include -TInstanceHook(bool, "?useOn@SeedItemComponentLegacy@@QEAA_NAEAVItemStack@@AEAVActor@@AEBVBlockPos@@EAEBVVec3@@@Z", - SeedItemComponentLegacy, ItemStack* a2, Actor* a3, BlockPos const* a4, unsigned char a5, Vec3 const* a6) -{ - IF_LISTENED(PlayerPlaceBlockEvent) - { - if (Player::isValid((Player*)a3)) - { - //if (!this->_canPlant(a3->getRegion().getBlock(*a4))) - // return original(this, a2, a3, a4, a5, a6); - auto growthDirection = dAccess(this, 42); - auto blockPos = a4->relative(growthDirection, 1); - auto block = dAccess(this); - PlayerPlaceBlockEvent ev{}; - ev.mPlayer = (Player*)a3; - ev.mBlockInstance = BlockInstance::createBlockInstance(block, blockPos, (int)a3->getDimensionId()); - if (!ev.call()) - return false; - } - } - IF_LISTENED_END(PlayerPlaceBlockEvent) - return original(this, a2, a3, a4, a5, a6); -} -*/ /////////////////// PlayerOpenContainer /////////////////// // 符号更换 TClasslessInstanceHook(__int64, "?onPlayerOpenContainer@VanillaServerGameplayEventListener@@UEAA?AW4EventResult@@AEAVPlayer@@W4ContainerType@@AEBVBlockPos@@UActorUniqueID@@@Z", - Player* pl, ContainerType type, BlockPos *pos,ActorUniqueID actorUniqueId) { - if (pl->isPlayer()) { + Player* player, ContainerType type, BlockPos *blockPos,ActorUniqueID actorUniqueId) { + if (player->isPlayer()) { IF_LISTENED(PlayerOpenContainerEvent) { PlayerOpenContainerEvent ev{}; - ev.mPlayer = pl; - ev.mBlockInstance = Level::getBlockInstance(pos, pl->getDimensionId()); + ev.mPlayer = player; + ev.mBlockInstance = Level::getBlockInstance(blockPos, player->getDimensionId()); ev.mContainer = ev.mBlockInstance.getContainer(); if (!ev.call()) return 0; } IF_LISTENED_END(PlayerOpenContainerEvent) } - return original(this, pl,type,pos,actorUniqueId); + return original(this, player,type,blockPos,actorUniqueId); } /////////////////// PlayerCloseContainer /////////////////// // chest TInstanceHook(bool, "?stopOpen@ChestBlockActor@@UEAAXAEAVPlayer@@@Z", - ChestBlockActor, Player* pl) { + ChestBlockActor, Player* player) { IF_LISTENED(PlayerCloseContainerEvent) { - BlockActor* ba = (BlockActor*)((char*)this - 248); // IDA ChestBlockActor::stopOpen - BlockPos bp = ba->getPosition(); + BlockActor* blockActor = (BlockActor*)((char*)this - 248); // IDA ChestBlockActor::stopOpen + BlockPos blockPos = blockActor->getPosition(); PlayerCloseContainerEvent ev{}; - ev.mPlayer = pl; - ev.mBlockInstance = Level::getBlockInstance(bp, pl->getDimensionId()); - ev.mContainer = Level::getBlockInstance(bp, pl->getDimensionId()).getContainer(); + ev.mPlayer = player; + ev.mBlockInstance = Level::getBlockInstance(blockPos, player->getDimensionId()); + ev.mContainer = Level::getBlockInstance(blockPos, player->getDimensionId()).getContainer(); ev.call(); } IF_LISTENED_END(PlayerCloseContainerEvent) - return original(this, pl); + return original(this, player); } // barrel TClasslessInstanceHook(bool, "?stopOpen@BarrelBlockActor@@UEAAXAEAVPlayer@@@Z", - Player* pl) { + Player* player) { IF_LISTENED(PlayerCloseContainerEvent) { - BlockActor* ba = (BlockActor*)((char*)this - 248); // IDA ChestBlockActor::stopOpen - BlockPos bp = ba->getPosition(); + BlockActor* blockActor = (BlockActor*)((char*)this - 248); // IDA ChestBlockActor::stopOpen + BlockPos blockPos = blockActor->getPosition(); PlayerCloseContainerEvent ev{}; - ev.mPlayer = pl; - ev.mBlockInstance = Level::getBlockInstance(bp, pl->getDimensionId()); - ev.mContainer = Level::getBlockInstance(bp, pl->getDimensionId()).getContainer(); + ev.mPlayer = player; + ev.mBlockInstance = Level::getBlockInstance(blockPos, player->getDimensionId()); + ev.mContainer = Level::getBlockInstance(blockPos, player->getDimensionId()).getContainer(); ev.call(); } IF_LISTENED_END(PlayerCloseContainerEvent) - return original(this, pl); + return original(this, player); } /////////////////// PlayerInventoryChange /////////////////// @@ -966,17 +699,17 @@ TInstanceHook(void, "?inventoryChanged@Player@@UEAAXAEAVContainer@@HAEBVItemStac /////////////////// PlayerMove /////////////////// // 更改符号 TInstanceHook(void, "?move@Player@@UEAAXAEBVVec3@@@Z", - Player, Vec3* pos) { + Player, Vec3* vec3) { IF_LISTENED(PlayerMoveEvent) { if (this->isMoving()) { PlayerMoveEvent ev{}; ev.mPlayer = this; - ev.mPos = *pos; + ev.mPos = *vec3; ev.call(); } } IF_LISTENED_END(PlayerMoveEvent) - return original(this, pos); + return original(this, vec3); } /////////////////// PlayerSprint /////////////////// @@ -1000,22 +733,22 @@ TInstanceHook(void, "?setSprinting@Mob@@UEAAX_N@Z", #include /////////////////// PlayerSetArmor /////////////////// TInstanceHook(void, "?setArmor@Player@@UEAAXW4ArmorSlot@@AEBVItemStack@@@Z", - Player, unsigned slot, ItemStack* it) { - original(this, slot, it); + Player, unsigned slot, ItemStack* itemStack) { + original(this, slot, itemStack); IF_LISTENED(PlayerSetArmorEvent) { if (this->isPlayer()) { PlayerSetArmorEvent ev{}; ev.mPlayer = this; ev.mSlot = slot; - ev.mArmorItem = it; + ev.mArmorItem = itemStack; if (!ev.call()) { auto& uid = getUniqueID(); - this->add(*it); + this->add(*itemStack); getArmorContainer().setItem(slot, ItemStack::EMPTY_ITEM); Schedule::delay([uid] { - auto sp = Global->getPlayer(uid); - if (sp) - sp->refreshInventory(); + auto player = Global->getPlayer(uid); + if (player) + player->refreshInventory(); }, 1); } @@ -1026,16 +759,16 @@ TInstanceHook(void, "?setSprinting@Mob@@UEAAX_N@Z", /////////////////// PlayerUseRespawnAnchor /////////////////// TInstanceHook(bool, "?trySetSpawn@RespawnAnchorBlock@@CA_NAEAVPlayer@@AEBVBlockPos@@AEAVBlockSource@@AEAVLevel@@@Z", - Player, BlockPos* bp, BlockSource* bs, Level* a4) { + Player, BlockPos* blockPos, BlockSource* blockSource, Level* level) { IF_LISTENED(PlayerUseRespawnAnchorEvent) { PlayerUseRespawnAnchorEvent ev{}; ev.mPlayer = this; - ev.mBlockInstance = Level::getBlockInstance(bp, bs); + ev.mBlockInstance = Level::getBlockInstance(blockPos, blockSource); if (!ev.call()) return false; } IF_LISTENED_END(PlayerUseRespawnAnchorEvent) - return original(this, bp, bs, a4); + return original(this, blockPos, blockSource, level); } /////////////////// PlayerOpenContainerScreen /////////////////// @@ -1052,12 +785,12 @@ TInstanceHook(bool, "?canOpenContainerScreen@Player@@UEAA_NXZ", Player) { /////////////////// PlayerCmdEvent & ConsoleCmd /////////////////// TClasslessInstanceHook(MCRESULT*, "?executeCommand@MinecraftCommands@@QEBA?AUMCRESULT@@V?$shared_ptr@VCommandContext@@@std@@_N@Z", - MCRESULT* rtn, std::shared_ptr context, bool print) { - Player* sp; + MCRESULT* mcResult, std::shared_ptr context, bool print) { + Player* player; string cmd; try { - sp = context->getOrigin().getPlayer(); + player = context->getOrigin().getPlayer(); cmd = context->getCmd(); if (!cmd.empty() && cmd.at(0) == '/') { cmd = cmd.substr(1, cmd.size() - 1); @@ -1065,25 +798,25 @@ TInstanceHook(bool, "?canOpenContainerScreen@Player@@UEAA_NXZ", Player) { if (!Util::isValidUTF8(cmd)) { logger.error("Detected invalid utf-8 character, command will not be executed"); - return rtn; + return mcResult; } } catch (...) { - return rtn; + return mcResult; } if (ll::isDebugMode() && ll::globalConfig.tickThreadId != std::this_thread::get_id()) { logger.warn("The thread executing the command \"{}\" is not the \"MC_SERVER\" thread", cmd); } - if (sp) { + if (player) { // PlayerCmd IF_LISTENED(PlayerCmdEvent) { PlayerCmdEvent ev{}; ev.mCommand = cmd; - ev.mPlayer = sp; - ev.mResult = rtn; + ev.mPlayer = player; + ev.mResult = mcResult; if (!ev.call()) - return rtn; + return mcResult; if (ev.mCommand.empty() || ev.mCommand.at(0) != '/') context->getCmd() = "/" + ev.mCommand; @@ -1098,7 +831,7 @@ TInstanceHook(bool, "?canOpenContainerScreen@Player@@UEAA_NXZ", Player) { ev.mCommand = cmd; if (!ev.call()) - return rtn; + return mcResult; if (ev.mCommand.empty() || ev.mCommand.at(0) != '/') context->getCmd() = "/" + ev.mCommand; @@ -1107,7 +840,7 @@ TInstanceHook(bool, "?canOpenContainerScreen@Player@@UEAA_NXZ", Player) { } IF_LISTENED_END(ConsoleCmdEvent) } - return original(this, rtn, context, print); + return original(this, mcResult, context, print); } /////////////////// PlayerExperienceAddEvent /////////////////// @@ -1125,10 +858,10 @@ TInstanceHook(void, "?addExperience@Player@@UEAAXH@Z", Player, int exp) { ////////////// PlayerInteractEntity ////////////// TInstanceHook(void, "?handle@ItemUseOnActorInventoryTransaction@@UEBA?AW4InventoryTransactionError@@AEAVPlayer@@_N@Z", - ServerNetworkHandler, ServerPlayer* sp, bool unk) { + ServerNetworkHandler, ServerPlayer* serverPlayer, bool unk) { IF_LISTENED(PlayerInteractEntityEvent) { PlayerInteractEntityEvent ev{}; - ev.mPlayer = sp; + ev.mPlayer = serverPlayer; ev.mTargetId = dAccess(this);//正确 ev.mInteractiveMode = static_cast(dAccess(this));//看起来应该正确 if (!ev.call()) @@ -1136,60 +869,60 @@ TInstanceHook(void, "?handle@ItemUseOnActorInventoryTransaction@@UEBA?AW4Invento } IF_LISTENED_END(PlayerInteractEntityEvent) - return original(this, sp, unk); + return original(this, serverPlayer, unk); } /////////////////// CmdBlockExecute /////////////////// TInstanceHook(bool, "?_performCommand@BaseCommandBlock@@AEAA_NAEAVBlockSource@@AEBVCommandOrigin@@AEA_N@Z", - BaseCommandBlock, BlockSource* a2, CommandOrigin* a3, bool* a4) { + BaseCommandBlock, BlockSource* blockSource, CommandOrigin* commandOrigin, bool* markForSaving) { IF_LISTENED(CmdBlockExecuteEvent) { CmdBlockExecuteEvent ev{}; ev.mCommand = this->getCommand(); - if ((OriginType)a3->getOriginType() == OriginType::MinecartBlock) { + if ((OriginType)commandOrigin->getOriginType() == OriginType::MinecartBlock) { ev.mIsMinecart = true; - ev.mMinecart = a3->getEntity(); + ev.mMinecart = commandOrigin->getEntity(); } else { ev.mIsMinecart = false; - ev.mBlockInstance = Level::getBlockInstance(a3->getBlockPosition(), a2); + ev.mBlockInstance = Level::getBlockInstance(commandOrigin->getBlockPosition(), blockSource); } if (!ev.call()) return false; } IF_LISTENED_END(CmdBlockExecuteEvent) - return original(this, a2, a3, a4); + return original(this, blockSource, commandOrigin, markForSaving); } /////////////////// BlockInteracted /////////////////// TClasslessInstanceHook(unsigned short, "?onBlockInteractedWith@VanillaServerGameplayEventListener@@UEAA?AW4EventResult@@AEAVPlayer@@AEBVBlockPos@@@Z", - Player* pl, BlockPos* bp) { + Player* player, BlockPos* blockPos) { IF_LISTENED(BlockInteractedEvent) { BlockInteractedEvent ev{}; - ev.mPlayer = pl; - ev.mBlockInstance = Level::getBlockInstance(bp, pl->getDimensionId()); + ev.mPlayer = player; + ev.mBlockInstance = Level::getBlockInstance(blockPos, player->getDimensionId()); if (!ev.call()) return 0; } IF_LISTENED_END(BlockInteractedEvent) - return original(this, pl, bp); + return original(this, player, blockPos); } /////////////////// BlockChanged /////////////////// // 没有这个符号 // 更换点位 TInstanceHook(void, "?onBlockChanged@Dimension@@UEAAXAEAVBlockSource@@AEBVBlockPos@@IAEBVBlock@@2HPEBUActorBlockSyncMessage@@@Z", - Dimension, BlockSource *bs, BlockPos* bp, int a4, Block* afterBlock, Block* beforeBlock, int a7, void* a8) { + Dimension, BlockSource *blockSource, BlockPos* blockPos, int layer, Block* afterBlock, Block* beforeBlock, char updateFlags, ActorBlockSyncMessage *syncMsg) { IF_LISTENED(BlockChangedEvent) { int dimId = this->getDimensionId(); BlockChangedEvent ev{}; - ev.mPreviousBlockInstance = BlockInstance::createBlockInstance(beforeBlock, *bp, dimId); - ev.mNewBlockInstance = BlockInstance::createBlockInstance(afterBlock, *bp, dimId); + ev.mPreviousBlockInstance = BlockInstance::createBlockInstance(beforeBlock, *blockPos, dimId); + ev.mNewBlockInstance = BlockInstance::createBlockInstance(afterBlock, *blockPos, dimId); if (!ev.call()) return; } IF_LISTENED_END(BlockChangedEvent) - return original(this, bs, bp, a4, afterBlock, beforeBlock, a7, a8); + return original(this, blockSource, blockPos, layer, afterBlock, beforeBlock, updateFlags, syncMsg); } /////////////////// BlockExploded /////////////////// @@ -1213,27 +946,27 @@ TClasslessInstanceHook(unsigned short, bool onFireSpread_OnPlace = false; TClasslessInstanceHook(void, "?onPlace@FireBlock@@UEBAXAEAVBlockSource@@AEBVBlockPos@@@Z", - BlockSource* bs, BlockPos* bp) { + BlockSource* blockSource, BlockPos* blockPos) { onFireSpread_OnPlace = true; - original(this, bs, bp); + original(this, blockSource, blockPos); onFireSpread_OnPlace = false; } TClasslessInstanceHook(bool, "?mayPlace@FireBlock@@UEBA_NAEAVBlockSource@@AEBVBlockPos@@@Z", - BlockSource* bs, BlockPos* bp) { - auto rtn = original(this, bs, bp); - if (!onFireSpread_OnPlace || !rtn) - return rtn; + BlockSource* blockSource, BlockPos* blockPos) { + auto result = original(this, blockSource, blockPos); + if (!onFireSpread_OnPlace || !result) + return result; IF_LISTENED(FireSpreadEvent) { FireSpreadEvent ev{}; - ev.mTarget = *bp; - ev.mDimensionId = bs->getDimensionId(); + ev.mTarget = *blockPos; + ev.mDimensionId = blockSource->getDimensionId(); if (!ev.call()) return false; } IF_LISTENED_END(FireSpreadEvent) - return rtn; + return result; } @@ -1287,10 +1020,10 @@ TClasslessInstanceHook(bool, "?mayPlace@FireBlock@@UEBA_NAEAVBlockSource@@AEBVBl /////////////////// RedStoneUpdate /////////////////// // 红石粉 TClasslessInstanceHook(void, "?onRedstoneUpdate@RedStoneWireBlock@@UEBAXAEAVBlockSource@@AEBVBlockPos@@H_N@Z", - BlockSource* bs, BlockPos* bp, int level, bool isActive) { + BlockSource* blockSource, BlockPos* blockPos, int level, bool isActive) { IF_LISTENED(RedStoneUpdateEvent) { RedStoneUpdateEvent ev{}; - ev.mBlockInstance = Level::getBlockInstance(bp, bs); + ev.mBlockInstance = Level::getBlockInstance(blockPos, blockSource); ev.mRedStonePower = level; ev.mIsActivated = level != 0; if (!ev.call()) @@ -1299,14 +1032,14 @@ TClasslessInstanceHook(void, "?onRedstoneUpdate@RedStoneWireBlock@@UEBAXAEAVBloc level = ev.mRedStonePower; } IF_LISTENED_END(RedStoneUpdateEvent) - return original(this, bs, bp, level, isActive); + return original(this, blockSource, blockPos, level, isActive); } // 红石火把 TClasslessInstanceHook(void, "?onRedstoneUpdate@RedstoneTorchBlock@@UEBAXAEAVBlockSource@@AEBVBlockPos@@H_N@Z", - BlockSource* bs, BlockPos* bp, int level, bool isActive) { + BlockSource* blockSource, BlockPos* blockPos, int level, bool isActive) { IF_LISTENED(RedStoneUpdateEvent) { RedStoneUpdateEvent ev{}; - ev.mBlockInstance = Level::getBlockInstance(bp, bs); + ev.mBlockInstance = Level::getBlockInstance(blockPos, blockSource); ev.mRedStonePower = level; ev.mIsActivated = level != 0; if (!ev.call()) @@ -1315,14 +1048,14 @@ TClasslessInstanceHook(void, "?onRedstoneUpdate@RedstoneTorchBlock@@UEBAXAEAVBlo level = ev.mRedStonePower; } IF_LISTENED_END(RedStoneUpdateEvent) - return original(this, bs, bp, level, isActive); + return original(this, blockSource, blockPos, level, isActive); } // 红石中继器 TClasslessInstanceHook(void, "?onRedstoneUpdate@DiodeBlock@@UEBAXAEAVBlockSource@@AEBVBlockPos@@H_N@Z", - BlockSource* bs, BlockPos* bp, int level, bool isActive) { + BlockSource* blockSource, BlockPos* blockPos, int level, bool isActive) { IF_LISTENED(RedStoneUpdateEvent) { RedStoneUpdateEvent ev{}; - ev.mBlockInstance = Level::getBlockInstance(bp, bs); + ev.mBlockInstance = Level::getBlockInstance(blockPos, blockSource); ev.mRedStonePower = level; ev.mIsActivated = level != 0; if (!ev.call()) @@ -1331,14 +1064,14 @@ TClasslessInstanceHook(void, "?onRedstoneUpdate@DiodeBlock@@UEBAXAEAVBlockSource level = ev.mRedStonePower; } IF_LISTENED_END(RedStoneUpdateEvent) - return original(this, bs, bp, level, isActive); + return original(this, blockSource, blockPos, level, isActive); } // 红石比较器 TClasslessInstanceHook(void, "?onRedstoneUpdate@ComparatorBlock@@UEBAXAEAVBlockSource@@AEBVBlockPos@@H_N@Z", - BlockSource* bs, BlockPos* bp, int level, bool isActive) { + BlockSource* blockSource, BlockPos* blockPos, int level, bool isActive) { IF_LISTENED(RedStoneUpdateEvent) { RedStoneUpdateEvent ev{}; - ev.mBlockInstance = Level::getBlockInstance(bp, bs); + ev.mBlockInstance = Level::getBlockInstance(blockPos, blockSource); ev.mRedStonePower = level; ev.mIsActivated = level != 0; if (!ev.call()) @@ -1347,74 +1080,74 @@ TClasslessInstanceHook(void, "?onRedstoneUpdate@ComparatorBlock@@UEBAXAEAVBlockS level = ev.mRedStonePower; } IF_LISTENED_END(RedStoneUpdateEvent) - return original(this, bs, bp, level, isActive); + return original(this, blockSource, blockPos, level, isActive); } /////////////////// HopperSearchItem /////////////////// // 没有这个符号 TClasslessInstanceHook(bool, "?_pullInItems@Hopper@@IEAA_NAEAVBlockSource@@AEAVContainer@@AEBVVec3@@@Z", - BlockSource* bs, void* container, Vec3* pos) { + BlockSource* blockSource, void* container, Vec3* vec3) { bool isMinecart = dAccess(this, 5); // IDA Hopper::Hopper 正确 IF_LISTENED(HopperSearchItemEvent) { HopperSearchItemEvent ev{}; if (isMinecart) { ev.isMinecart = true; - ev.mMinecartPos = *pos; + ev.mMinecartPos = *vec3; } else { ev.isMinecart = false; - ev.mHopperBlock = Level::getBlockInstance(pos->toBlockPos(), bs); + ev.mHopperBlock = Level::getBlockInstance(vec3->toBlockPos(), blockSource); } - ev.mDimensionId = bs->getDimensionId(); + ev.mDimensionId = blockSource->getDimensionId(); if (!ev.call()) return false; } IF_LISTENED_END(HopperSearchItemEvent) - return original(this, bs, container, pos); + return original(this, blockSource, container, vec3); } /////////////////// HopperPushOut /////////////////// TClasslessInstanceHook(bool, "?_pushOutItems@Hopper@@IEAA_NAEAVBlockSource@@AEAVContainer@@AEBVVec3@@H@Z", - BlockSource* bs, void* container, Vec3* pos, int a5) { + BlockSource* blockSource, void* container, Vec3* vec3, unsigned int attachedFace) { IF_LISTENED(HopperPushOutEvent) { HopperPushOutEvent ev{}; - ev.mPos = *pos; - ev.mDimensionId = bs->getDimensionId(); + ev.mPos = *vec3; + ev.mDimensionId = blockSource->getDimensionId(); if (!ev.call()) return false; } IF_LISTENED_END(HopperPushOutEvent) - return original(this, bs, container, pos, a5); + return original(this, blockSource, container, vec3, attachedFace); } /////////////////// PistonTryPushEvent & PistonPushEvent /////////////////// TInstanceHook(bool, "?_attachedBlockWalker@PistonBlockActor@@AEAA_NAEAVBlockSource@@AEBVBlockPos@@EE@Z", - PistonBlockActor, BlockSource* bs, BlockPos* bp, char a3, char a4) { + PistonBlockActor, BlockSource* blockSource, BlockPos* blockPos, char curBranchFacing, char pistonMoveFacing) { IF_LISTENED(PistonTryPushEvent) { PistonTryPushEvent ev{}; - ev.mTargetBlockInstance = Level::getBlockInstance(bp, bs); + ev.mTargetBlockInstance = Level::getBlockInstance(blockPos, blockSource); if (ev.mTargetBlockInstance.getBlock()->getTypeName() == "minecraft:air") - return original(this, bs, bp, a3, a4); + return original(this, blockSource, blockPos, curBranchFacing, pistonMoveFacing); - ev.mPistonBlockInstance = Level::getBlockInstance(this->getPosition(), bs); + ev.mPistonBlockInstance = Level::getBlockInstance(this->getPosition(), blockSource); if (!ev.call()) return false; } IF_LISTENED_END(PistonTryPushEvent) - bool res = original(this, bs, bp, a3, a4); + bool res = original(this, blockSource, blockPos, curBranchFacing, pistonMoveFacing); if (!res) return false; IF_LISTENED(PistonPushEvent) { PistonPushEvent ev{}; - ev.mTargetBlockInstance = Level::getBlockInstance(bp, bs); + ev.mTargetBlockInstance = Level::getBlockInstance(blockPos, blockSource); if (ev.mTargetBlockInstance.getBlock()->getTypeName() == "minecraft:air") return true; - ev.mPistonBlockInstance = Level::getBlockInstance(this->getPosition(), bs); + ev.mPistonBlockInstance = Level::getBlockInstance(this->getPosition(), blockSource); ev.call(); } @@ -1425,68 +1158,68 @@ TInstanceHook(bool, "?_attachedBlockWalker@PistonBlockActor@@AEAA_NAEAVBlockSour /////////////////// FarmLandDecay /////////////////// TClasslessInstanceHook(void, "?transformOnFall@FarmBlock@@UEBAXAEAVBlockSource@@AEBVBlockPos@@PEAVActor@@M@Z", - BlockSource* bs, BlockPos* bp, Actor* ac, float a5) { + BlockSource* blockSource, BlockPos* blockPos, Actor* actor, float fallDistance) { IF_LISTENED(FarmLandDecayEvent) { FarmLandDecayEvent ev{}; - ev.mBlockInstance = Level::getBlockInstance(bp, bs); - ev.mActor = ac; + ev.mBlockInstance = Level::getBlockInstance(blockPos, blockSource); + ev.mActor = actor; if (!ev.call()) return; } IF_LISTENED_END(FarmLandDecayEvent) - return original(this, bs, bp, ac, a5); + return original(this, blockSource, blockPos, actor, fallDistance); } /////////////////// PlayerUseFrameBlockEvent /////////////////// // 符号变更 TClasslessInstanceHook(bool, "?use@ItemFrameBlock@@UEBA_NAEAVPlayer@@AEBVBlockPos@@@Z", - Player* a2, BlockPos* a3) { + Player* player, BlockPos* blockPos) { IF_LISTENED(PlayerUseFrameBlockEvent) { PlayerUseFrameBlockEvent ev{}; ev.mType = PlayerUseFrameBlockEvent::Type::Use; - ev.mBlockInstance = Level::getBlockInstance(a3, a2->getDimensionId()); - ev.mPlayer = a2; + ev.mBlockInstance = Level::getBlockInstance(blockPos, player->getDimensionId()); + ev.mPlayer = player; if (!ev.call()) return false; } IF_LISTENED_END(PlayerUseFrameBlockEvent) - return original(this, a2, a3); + return original(this, player, blockPos); } TClasslessInstanceHook(bool, "?attack@ItemFrameBlock@@UEBA_NPEAVPlayer@@AEBVBlockPos@@@Z", - Player* a2, BlockPos* a3) { + Player* player, BlockPos* blockPos) { IF_LISTENED(PlayerUseFrameBlockEvent) { PlayerUseFrameBlockEvent ev{}; ev.mType = PlayerUseFrameBlockEvent::Type::Attack; - ev.mBlockInstance = Level::getBlockInstance(a3, a2->getDimensionId()); - ev.mPlayer = a2; + ev.mBlockInstance = Level::getBlockInstance(blockPos, player->getDimensionId()); + ev.mPlayer = player; if (!ev.call()) return false; } IF_LISTENED_END(PlayerUseFrameBlockEvent) - return original(this, a2, a3); + return original(this, player, blockPos); } /////////////////// LiquidSpreadEvent /////////////////// #include TInstanceHook(bool, "?_canSpreadTo@LiquidBlockDynamic@@AEBA_NAEAVBlockSource@@AEBVBlockPos@@1E@Z", - LiquidBlockDynamic, class BlockSource& bs, class BlockPos const& to, class BlockPos const& from, unsigned char unk) { - auto rtn = original(this, bs, to, from, unk); - if (!rtn) - return rtn; + LiquidBlockDynamic, class BlockSource& blockSource, class BlockPos const& to, class BlockPos const& from, unsigned char flowFromDirection) { + auto result = original(this, blockSource, to, from, flowFromDirection); + if (!result) + return result; IF_LISTENED(LiquidSpreadEvent) { LiquidSpreadEvent ev{}; ev.mBlockInstance = BlockInstance::createBlockInstance( - const_cast(&this->getRenderBlock()), from, bs.getDimensionId()); + const_cast(&this->getRenderBlock()), from, blockSource.getDimensionId()); ev.mTarget = to; - ev.mDimensionId = bs.getDimensionId(); + ev.mDimensionId = blockSource.getDimensionId(); if (!ev.call()) return false; } IF_LISTENED_END(LiquidSpreadEvent) - return rtn; + return result; } // THook(void, "?_trySpreadTo@LiquidBlockDynamic@@AEBAXAEAVBlockSource@@AEBVBlockPos@@H1E@Z", @@ -1522,9 +1255,9 @@ TInstanceHook(void*, "?die@ServerPlayer@@UEAAXAEBVActorDamageSource@@@Z", Server } IF_LISTENED_END(PlayerDieEvent) isDieDrop = true; - auto out = original(this, src); + auto result = original(this, src); isDieDrop = false; - return out; + return result; } #include @@ -1552,12 +1285,12 @@ TInstanceHook(void*, "?die@ServerPlayer@@UEAAXAEBVActorDamageSource@@@Z", Server // } TInstanceHook(bool, "?destroyBlock@GameMode@@UEAA_NAEBVBlockPos@@E@Z", - GameMode, BlockPos a3, unsigned __int8 a4) { + GameMode, BlockPos blockPos, char face) { IF_LISTENED(PlayerDestroyBlockEvent) { if (getPlayer()->isPlayer()) { PlayerDestroyBlockEvent ev{}; ev.mPlayer = getPlayer(); - auto bl = Level::getBlockInstance(a3, getPlayer()->getDimensionId()); + auto bl = Level::getBlockInstance(blockPos, getPlayer()->getDimensionId()); ev.mBlockInstance = bl; if (!ev.call()) { return false; @@ -1565,31 +1298,31 @@ TInstanceHook(bool, "?destroyBlock@GameMode@@UEAA_NAEBVBlockPos@@E@Z", } } IF_LISTENED_END(PlayerDestroyBlockEvent) - return original(this, a3, a4); + return original(this, blockPos, face); } /////////////////// PlayerUseItemOn /////////////////// TInstanceHook(bool, "?useItemOn@GameMode@@UEAA_NAEAVItemStack@@AEBVBlockPos@@EAEBVVec3@@PEBVBlock@@@Z", GameMode, - ItemStack& it, BlockPos bp, unsigned char side, Vec3* clickPos, void* a6_block) { + ItemStack* itemStack, BlockPos *blockPos, unsigned char side, Vec3* clickPos, Block* targetBlock) { IF_LISTENED(PlayerUseItemOnEvent) { PlayerUseItemOnEvent ev{}; ev.mPlayer = this->getPlayer(); - ev.mBlockInstance = Level::getBlockInstance(bp, ev.mPlayer->getDimensionId()); - ev.mItemStack = ⁢ + ev.mBlockInstance = Level::getBlockInstance(blockPos, ev.mPlayer->getDimensionId()); + ev.mItemStack = itemStack; ev.mFace = side; ev.mClickPos = *clickPos; if (!ev.call()) return false; } IF_LISTENED_END(PlayerUseItemOnEvent) - return original(this, it, bp, side, clickPos, a6_block); + return original(this, itemStack, blockPos, side, clickPos, targetBlock); } /////////////////// MobHurt /////////////////// TInstanceHook(bool, "?_hurt@Mob@@MEAA_NAEBVActorDamageSource@@H_N1@Z", - Mob, ActorDamageSource& src, int damage, bool unk1_1, bool unk2_0) { + Mob, ActorDamageSource& src, int damage, bool knock, bool ignite) { IF_LISTENED(MobHurtEvent) { if (this) { MobHurtEvent ev{}; @@ -1603,7 +1336,7 @@ TInstanceHook(bool, "?useItemOn@GameMode@@UEAA_NAEAVItemStack@@AEBVBlockPos@@EAE } } IF_LISTENED_END(MobHurtEvent) - return original(this, src, damage, unk1_1, unk2_0); + return original(this, src, damage, knock, ignite); } // 没有这个符号 // TInstanceHook(float, "?getDamageAfterResistanceEffect@Mob@@UEBAMAEBVActorDamageSource@@M@Z", Mob, ActorDamageSource* src, float damage) { @@ -1626,12 +1359,12 @@ TInstanceHook(bool, "?useItemOn@GameMode@@UEAA_NAEAVItemStack@@AEBVBlockPos@@EAE //////////////// PlayerUseItem & PlayerEat //////////////// // #include - TInstanceHook(bool, "?baseUseItem@GameMode@@QEAA_NAEAVItemStack@@@Z", GameMode, ItemStack& it) { - auto pl = this->getPlayer(); + TInstanceHook(bool, "?baseUseItem@GameMode@@QEAA_NAEAVItemStack@@@Z", GameMode, ItemStack& itemStack) { + auto player = this->getPlayer(); IF_LISTENED(PlayerUseItemEvent) { PlayerUseItemEvent ev{}; - ev.mPlayer = pl; - ev.mItemStack = ⁢ + ev.mPlayer = player; + ev.mItemStack = &itemStack; if (!ev.call()) return false; } @@ -1648,36 +1381,38 @@ TInstanceHook(bool, "?useItemOn@GameMode@@UEAA_NAEAVItemStack@@AEBVBlockPos@@EAE // } // } // IF_LISTENED_END(PlayerEatEvent) - return original(this, it); + return original(this, itemStack); } - THook(ItemStack*, "?use@BucketItem@@UEBAAEAVItemStack@@AEAV2@AEAVPlayer@@@Z", Item* _this, ItemStack* a1, Player* a2) { - if (_this->getFullItemName() == "minecraft:milk_bucket") { +#include +TInstanceHook(ItemStack*, "?use@BucketItem@@UEBAAEAVItemStack@@AEAV2@AEAVPlayer@@@Z", BucketItem, ItemStack* itemStack, Player* player) { + if (this->getFullItemName() == "minecraft:milk_bucket") { IF_LISTENED(PlayerEatEvent) { PlayerEatEvent ev{}; - ev.mPlayer = a2; - ev.mFoodItem = a1; + ev.mPlayer = player; + ev.mFoodItem = itemStack; if (!ev.call()) { - return a1; + return itemStack; } } IF_LISTENED_END(PlayerEatEvent) } - return original(_this, a1, a2); + return original(this, itemStack, player); } - THook(ItemStack*, "?use@PotionItem@@UEBAAEAVItemStack@@AEAV2@AEAVPlayer@@@Z", void* _this, ItemStack* a1, Player* a2) { +#include +TInstanceHook(ItemStack*, "?use@PotionItem@@UEBAAEAVItemStack@@AEAV2@AEAVPlayer@@@Z", PotionItem, ItemStack* itemStack, Player* player) { IF_LISTENED(PlayerEatEvent) { PlayerEatEvent ev{}; - ev.mPlayer = a2; - ev.mFoodItem = a1; + ev.mPlayer = player; + ev.mFoodItem = itemStack; if (!ev.call()) { - return a1; + return itemStack; } } IF_LISTENED_END(PlayerEatEvent) - return original(_this, a1, a2); + return original(this, itemStack, player); } /////////////////// MobDie /////////////////// @@ -1694,56 +1429,56 @@ TInstanceHook(bool, "?die@Mob@@UEAAXAEBVActorDamageSource@@@Z", Mob, ActorDamage IF_LISTENED_END(MobDieEvent) return original(this, ads); } - +#include /////////////////// Entity & Block Explosion /////////////////// -TClasslessInstanceHook(void, "?explode@Explosion@@QEAAXXZ") { +TInstanceHook(void, "?explode@Explosion@@QEAAXXZ",Explosion) { try { - auto acId = *(ActorUniqueID*)((QWORD*)this + 11); - auto actor = Global->getEntity(acId); - auto pos = *(Vec3*)(QWORD*)this; - auto radius = *((float*)this + 3); - auto bs = (BlockSource*)*((QWORD*)this + 12); - auto maxResistance = *((float*)this + 26); - auto genFire = (bool)*((BYTE*)this + 80); - auto canBreaking = (bool)*((BYTE*)this + 81); +// auto acId = *(ActorUniqueID*)((QWORD*)this + 11); +// auto actor = Global->getEntity(acId); +// auto vec3 = *(Vec3*)(QWORD*)this; +// auto radius = *((float*)this + 3); +// auto blockSource = (BlockSource*)*((QWORD*)this + 12); +// auto maxResistance = *((float*)this + 26); +// auto genFire = (bool)*((BYTE*)this + 80); +// auto canBreaking = (bool)*((BYTE*)this + 81); IF_LISTENED(EntityExplodeEvent) { - if (actor) { + if (this->mSource) { EntityExplodeEvent ev{}; - ev.mActor = actor; - ev.mBreaking = canBreaking; - ev.mFire = genFire; - ev.mMaxResistance = maxResistance; - ev.mPos = pos; - ev.mRadius = radius; - ev.mDimension = bs; + ev.mActor = this->mSource; + ev.mBreaking = this->mBreaking; + ev.mFire = this->mFire; + ev.mMaxResistance = this->mMaxResistance; + ev.mPos = this->mPos; + ev.mRadius = this->mRadius; + ev.mDimension = this->mRegion; if (!ev.call()) return; - *((float*)this + 3) = ev.mRadius; - *((float*)this + 26) = ev.mMaxResistance; - *((BYTE*)this + 80) = ev.mFire; - *((BYTE*)this + 81) = ev.mBreaking; + this->mRadius = ev.mRadius; + this->mMaxResistance = ev.mMaxResistance; + this->mFire = ev.mFire; + this->mBreaking = ev.mBreaking; } } IF_LISTENED_END(EntityExplodeEvent) IF_LISTENED(BlockExplodeEvent) { - if (!actor) { - BlockPos bp = pos.toBlockPos(); + if (!this->mSource) { + BlockPos blockPos = this->mPos.toBlockPos(); BlockExplodeEvent ev{}; - ev.mBlockInstance = Level::getBlockInstance(bp, bs); - ev.mBreaking = canBreaking; - ev.mFire = genFire; - ev.mMaxResistance = maxResistance; - ev.mRadius = radius; + ev.mBlockInstance = Level::getBlockInstance(blockPos, this->mRegion); + ev.mBreaking = this->mBreaking; + ev.mFire = this->mFire; + ev.mMaxResistance = this->mMaxResistance; + ev.mRadius = this->mRadius; if (!ev.call()) return; - *((float*)this + 3) = ev.mRadius; - *((float*)this + 26) = ev.mMaxResistance; - *((BYTE*)this + 80) = ev.mFire; - *((BYTE*)this + 81) = ev.mBreaking; + this->mRadius = ev.mRadius; + this->mMaxResistance = ev.mMaxResistance; + this->mFire = ev.mFire; + this->mBreaking = ev.mBreaking; } } IF_LISTENED_END(BlockExplodeEvent) @@ -1789,7 +1524,7 @@ TClasslessInstanceHook(void,"?newServerAiStep@WitherBoss@@UEAAXXZ"){ } THook(void, "?destroyBlocks@@YAXAEAVLevel@@AEBVAABB@@AEAVBlockSource@@H@Z", - Level* level, AABB* aabb, BlockSource* bs, int range) { + Level* level, AABB* aabb, BlockSource* blockSource, int range) { IF_LISTENED(WitherBossDestroyEvent) { WitherBossDestroyEvent ev{}; // ev.mWitherBoss = dAccess(level,-816); // WitherBoss::newServerAiStep Line515 @@ -1801,26 +1536,26 @@ THook(void, "?destroyBlocks@@YAXAEAVLevel@@AEBVAABB@@AEAVBlockSource@@H@Z", *aabb = ev.mDestroyRange; } IF_LISTENED_END(WitherBossDestroyEvent) - original(level, aabb, bs, range); + original(level, aabb, blockSource, range); } ////////////// EntityRide ////////////// // 没有这个符号 TInstanceHook(bool, "?canAddRider@Actor@@UEBA_NAEAV1@@Z", - Actor, Actor* a2) { - auto rtn = original(this, a2); - if (!rtn) + Actor, Actor* actor) { + auto result = original(this, actor); + if (!result) return false; IF_LISTENED(EntityRideEvent) { EntityRideEvent ev{}; - ev.mRider = a2; + ev.mRider = actor; ev.mVehicle = this; if (!ev.call()) return false; } IF_LISTENED_END(EntityRideEvent) - return rtn; + return result; } @@ -1934,22 +1669,22 @@ THook(void, "?destroyBlocks@@YAXAEAVLevel@@AEBVAABB@@AEAVBlockSource@@H@Z", ////////////// ArmorStandChange ////////////// TInstanceHook(bool, "?_trySwapItem@ArmorStand@@AEAA_NAEAVPlayer@@W4EquipmentSlot@@@Z", - ArmorStand, Player* a2, int a3) { + ArmorStand, Player* player, int slot) { IF_LISTENED(ArmorStandChangeEvent) { ArmorStandChangeEvent ev{}; ev.mArmorStand = this; - ev.mPlayer = a2; - ev.mSlot = a3; + ev.mPlayer = player; + ev.mSlot = slot; if (!ev.call()) return false; } IF_LISTENED_END(ArmorStandChangeEvent) - return original(this, a2, a3); + return original(this, player, slot); } ////////////////// EntityTransform ////////////////// TClasslessInstanceHook(void, "?maintainOldData@TransformationComponent@@QEAAXAEAVActor@@0AEBUTransformationDescription@@AEBUActorUniqueID@@AEBVLevel@@@Z", - Actor* beforeEntity, Actor* afterEntity, void* a4, ActorUniqueID* aid, Level* level) { + Actor* beforeEntity, Actor* afterEntity, void* transformation, ActorUniqueID* uniqueId, Level* level) { IF_LISTENED(EntityTransformEvent) { EntityTransformEvent ev{}; ActorUniqueID actorUniqueID = beforeEntity->getActorUniqueId(); @@ -1958,20 +1693,20 @@ TClasslessInstanceHook(void, "?maintainOldData@TransformationComponent@@QEAAXAEA ev.call(); } IF_LISTENED_END(EntityTransformEvent) - original(this, beforeEntity, afterEntity, a4, aid, level); + original(this, beforeEntity, afterEntity, transformation, uniqueId, level); } ////////////// PlayerScoreChangedEvent ////////////// TClasslessInstanceHook(void, "?onScoreChanged@ServerScoreboard@@UEAAXAEBUScoreboardId@@AEBVObjective@@@Z", - ScoreboardId* a1, Objective* a2) { + ScoreboardId* scoreboardId, Objective* objective) { IF_LISTENED(PlayerScoreChangedEvent) { - __int64 id = a1->id; + __int64 id = scoreboardId->id; Player* player = nullptr; - auto pls = Level::getAllPlayers(); - for (auto& pl : pls) { - if (Global->getScoreboardId(*pl).id == id) { - player = pl; + auto players = Level::getAllPlayers(); + for (auto& player : players) { + if (Global->getScoreboardId(*player).id == id) { + player = player; break; } } @@ -1979,15 +1714,15 @@ TClasslessInstanceHook(void, "?onScoreChanged@ServerScoreboard@@UEAAXAEBUScorebo if (player) { PlayerScoreChangedEvent ev{}; ev.mPlayer = player; - ev.mScore = a2->getPlayerScore(*a1).getCount(); - ev.mScoreboardId = a1; - ev.mObjective = a2; + ev.mScore = objective->getPlayerScore(*scoreboardId).getCount(); + ev.mScoreboardId = scoreboardId; + ev.mObjective = objective; ev.call(); } } IF_LISTENED_END(PlayerScoreChangedEvent) - return original(this, a1, a2); + return original(this, scoreboardId, objective); } @@ -2034,9 +1769,9 @@ TClasslessInstanceHook(void, "?execute@StopCommand@@UEBAXAEBVCommandOrigin@@AEAV ////////////// RegCmd ////////////// TInstanceHook(void, "?setup@ChangeSettingCommand@@SAXAEAVCommandRegistry@@@Z", - CommandRegistry, void* a1) { + CommandRegistry) { Global = this; - original(this, a1); + original(this); IF_LISTENED(RegCmdEvent) { RegCmdEvent ev{}; ev.mCommandRegistry = this; @@ -2065,29 +1800,29 @@ THook(std::ostream&, ////////////// PlayerDropItem ////////////// TInstanceHook(void*, "?handle@ComplexInventoryTransaction@@UEBA?AW4InventoryTransactionError@@AEAVPlayer@@_N@Z", - ComplexInventoryTransaction, Player* a2, int a3) { + ComplexInventoryTransaction, Player* player, bool isSenderAuthority) { if (this->type == ComplexInventoryTransaction::Type::NORMAL) { IF_LISTENED(PlayerDropItemEvent) { auto& InvTran = this->data; auto& action = InvTran.getActions(InventorySource(InventorySourceType::Container, ContainerID::Inventory)); if (action.size() == 1) { PlayerDropItemEvent ev{}; - auto& item = a2->getInventory().getItem(action[0].slot); + auto& item = player->getInventory().getItem(action[0].slot); ev.mItemStack = const_cast(&item); - ev.mPlayer = a2; + ev.mPlayer = player; if (!ev.call()) { - a2->sendInventory(1); + player->sendInventory(1); return nullptr; } isQDrop = true; - auto out = original(this, a2, a3); + auto result = original(this, player, isSenderAuthority); isQDrop = false; - return out; + return result; } } IF_LISTENED_END(PlayerDropItemEvent) } - return original(this, a2, a3); + return original(this, player, isSenderAuthority); } // 没有这个符号 @@ -2132,17 +1867,17 @@ TInstanceHook(int, "?startSleepInBed@Player@@UEAA?AW4BedSleepingResult@@AEBVBloc ////////////// MobSpawn ////////////// TInstanceHook(Mob*, "?spawnMob@Spawner@@QEAAPEAVMob@@AEAVBlockSource@@AEBUActorDefinitionIdentifier@@PEAVActor@@AEBVVec3@@_N44@Z", - Spawner, BlockSource* a2, ActorDefinitionIdentifier* a3, Actor* a4, Vec3& a5, bool a6, bool a7, bool a8) { + Spawner, BlockSource* blockSource, ActorDefinitionIdentifier* identifier, Actor* actor, Vec3& vec3, bool naturalSpawn, bool surface, bool fromSpawner) { IF_LISTENED(MobSpawnEvent) { MobSpawnEvent ev{}; - ev.mTypeName = a3->getCanonicalName(); - ev.mPos = a5; - ev.mDimensionId = a2->getDimensionId(); + ev.mTypeName = identifier->getCanonicalName(); + ev.mPos = vec3; + ev.mDimensionId = blockSource->getDimensionId(); if (!ev.call()) return nullptr; } IF_LISTENED_END(MobSpawnEvent) - return original(this, a2, a3, a4, a5, a6, a7, a8); + return original(this, blockSource, identifier, actor, vec3, naturalSpawn, surface, fromSpawner); } #include @@ -2154,8 +1889,8 @@ TClasslessInstanceHook(void, "?handle@?$PacketHandlerDispatcherInstance@VModalFo NetworkIdentifier* id, ServerNetworkHandler* handler, std::shared_ptr pPacket) { Packet* packet = pPacket.get(); ModalFormResponsePacket* mPacket = (ModalFormResponsePacket*)packet; - ServerPlayer* sp = handler->getServerPlayer(*id, 0); - if (sp) { + ServerPlayer* serverPlayer = handler->getServerPlayer(*id, 0); + if (serverPlayer) { string data; auto formId = mPacket->mFormId; if(!mPacket->mJSONResponse.empty()) @@ -2168,7 +1903,7 @@ TClasslessInstanceHook(void, "?handle@?$PacketHandlerDispatcherInstance@VModalFo IF_LISTENED(FormResponsePacketEvent) { FormResponsePacketEvent ev{}; - ev.mServerPlayer = sp; + ev.mServerPlayer = serverPlayer; ev.mFormId = formId; ev.mJsonData = data; @@ -2176,7 +1911,7 @@ TClasslessInstanceHook(void, "?handle@?$PacketHandlerDispatcherInstance@VModalFo return; } IF_LISTENED_END(FormResponsePacketEvent) - HandleFormPacket(sp, formId, data); + HandleFormPacket(serverPlayer, formId, data); } original(this, id, handler, pPacket); }