From a73afd9fe96c14960fdff9d724bcb05e871a55b4 Mon Sep 17 00:00:00 2001 From: Qiuzhizhe <42761326+quizhizhe@users.noreply.github.com> Date: Sat, 18 Mar 2023 06:35:08 -0700 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`PlayerDropItem`=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LiteLoader/include/llapi/Offset.h | 2 ++ LiteLoader/src/llapi/EventAPI.cpp | 45 ++++++++++++++++--------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/LiteLoader/include/llapi/Offset.h b/LiteLoader/include/llapi/Offset.h index d34afb9..9ba31fd 100644 --- a/LiteLoader/include/llapi/Offset.h +++ b/LiteLoader/include/llapi/Offset.h @@ -79,6 +79,8 @@ namespace ll{ constexpr uint64_t EVENTAPI_PlayerInteractEntity_2 = 0x70; // Hopper::Hopper constexpr uint64_t EVENTAPI_HopperSearchItem = 0x5; + // FillingContainer::FillingContainer a2 + constexpr uint64_t EVENTAPI_PlayerDropItem = 0xF8; // ->src/llapi/mc diff --git a/LiteLoader/src/llapi/EventAPI.cpp b/LiteLoader/src/llapi/EventAPI.cpp index b51125b..84e09b5 100644 --- a/LiteLoader/src/llapi/EventAPI.cpp +++ b/LiteLoader/src/llapi/EventAPI.cpp @@ -1825,28 +1825,29 @@ TInstanceHook(void*, "?handle@ComplexInventoryTransaction@@UEBA?AW4InventoryTran return original(this, player, isSenderAuthority); } -// 没有这个符号 -// TInstanceHook(void, "?dropSlot@Inventory@@QEAAXH_N00@Z", -// Container, int a2, char a3, char a4, bool a5) { -// auto pl = dAccess(this); -// if (pl->isPlayer()) { -// IF_LISTENED(PlayerDropItemEvent) { -// PlayerDropItemEvent ev{}; -// if (a2 >= 0) { -// auto& item = this->getItem(a2); -// if (!item.isNull()) { -// ev.mItemStack = const_cast(&item); -// ev.mPlayer = pl; -// } -// if (!ev.call()) { -// return; -// } -// } -// } -// IF_LISTENED_END(PlayerDropItemEvent) -// } -// return original(this, a2, a3, a4, a5); -// } +// 更换符号,逻辑大概一致,未清楚玩家丢物品是否调用 +#include + TInstanceHook(void, "?dropSlot@FillingContainer@@QEAAXH_N00@Z", + FillingContainer, signed int slot, char unk) { + auto player = dAccess(this); + if (player->isPlayer()) { + IF_LISTENED(PlayerDropItemEvent) { + PlayerDropItemEvent ev{}; + if (slot >= 0) { + auto& item = this->getItem(slot); + if (!item.isNull()) { + ev.mItemStack = const_cast(&item); + ev.mPlayer = player; + } + if (!ev.call()) { + return; + } + } + } + IF_LISTENED_END(PlayerDropItemEvent) + } + return original(this, slot, unk); + } ////////////// PlayerBedEnter ////////////// TInstanceHook(int, "?startSleepInBed@Player@@UEAA?AW4BedSleepingResult@@AEBVBlockPos@@@Z",