diff --git a/libzhl/functions/EntityPlayer.zhl b/libzhl/functions/EntityPlayer.zhl index ea6611816..6eebf0bcf 100644 --- a/libzhl/functions/EntityPlayer.zhl +++ b/libzhl/functions/EntityPlayer.zhl @@ -460,6 +460,9 @@ __thiscall bool Entity_Player::IsEntityValidTarget(Entity * entity); "568bf15780be????????0075??8b86": __thiscall bool Entity_Player::IsInvisible(); +"558bec568bf1e8????????8b45??8b4d": +__thiscall void Entity_Player::QueueItem(ItemConfig_Item* itemConfig, int charge, bool touched, bool golden, int varData); + "558bec83e4f8515356578bf98b87": __thiscall bool Entity_Player::IsFootstepFrame(int eFoot); diff --git a/repentogon/LuaInterfaces/CustomCallbacks.cpp b/repentogon/LuaInterfaces/CustomCallbacks.cpp index 0782639d7..c63a73fd8 100644 --- a/repentogon/LuaInterfaces/CustomCallbacks.cpp +++ b/repentogon/LuaInterfaces/CustomCallbacks.cpp @@ -5126,3 +5126,64 @@ HOOK_METHOD(Room, SpawnGreedModeWave, (bool unusedBool) -> void) { .call(1); } } +//MC_PRE_QUEUE_ITEM (1490) +HOOK_METHOD(Entity_Player, QueueItem, (ItemConfig_Item* itemConfig, int charge, bool touched, bool golden, int varData) -> void) { + const int callbackid = 1490; + ItemConfig_Item itemCopy; + + if (CallbackState.test(callbackid - 1000)) { + lua_State* L = g_LuaEngine->_state; + lua::LuaStackProtector protector(L); + + lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key); + + lua::LuaResults result = lua::LuaCaller(L).push(callbackid) + .pushnil() + .push(itemConfig, lua::Metatables::ITEM) + .push(charge) + .push(touched) + .push(golden) + .push(varData) + .call(1); + + if (!result) { + if (lua_istable(L, -1)) { + lua_pushnil(L); + while (lua_next(L, -2) != 0) { + if (lua_isstring(L, -2) && lua_isuserdata(L, -1)) { + const std::string key = lua_tostring(L, -2); + if (key == "ItemConfig") { + auto* retItem = lua::UserdataToData(lua_touserdata(L, -1)); + if (retItem) { + itemConfig = retItem; + } + } + } + else if (lua_isstring(L, -2) && lua_isinteger(L, -1)) { + const std::string key = lua_tostring(L, -2); + if (key == "Charge") { + charge = (int)lua_tointeger(L, -1); + } + else if (key == "VarData") { + varData = (int)lua_tointeger(L, -1); + } + } + else if (lua_isstring(L, -2) && lua_isboolean(L, -1)) { + const std::string key = lua_tostring(L, -2); + if (key == "Golden") { + golden = lua_toboolean(L, -1); + } + else if (key == "Touched") { + touched = lua_toboolean(L, -1); + } + } + + lua_pop(L, 1); + } + } + } + } + + super(itemConfig, charge, touched, golden, varData); +} + diff --git a/repentogon/resources/scripts/enums_ex.lua b/repentogon/resources/scripts/enums_ex.lua index d6ba5bcc6..4e78f356a 100644 --- a/repentogon/resources/scripts/enums_ex.lua +++ b/repentogon/resources/scripts/enums_ex.lua @@ -348,6 +348,7 @@ ModCallbacks.MC_PRE_ENTITY_SET_COLOR = 1486 ModCallbacks.MC_POST_ENTITY_SET_COLOR = 1487 ModCallbacks.MC_POST_START_AMBUSH_WAVE = 1488 ModCallbacks.MC_POST_START_GREED_WAVE = 1489 +ModCallbacks.MC_PRE_QUEUE_ITEM = 1490 AddHealthType = { NONE = 0,