// This file is part of ClassicAPI. // // ClassicAPI is free software: you can redistribute it and/or modify it under the terms // of the GNU Lesser General Public License as published by the Free Software Foundation, either // version 3 of the License, or (at your option) any later version. // // ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License along with // ClassicAPI. If not, see . #include "Game.h" #include "Offsets.h" #include "item/Location.h" #include namespace Item::Bound { static bool ItemIsSoulbound(const uint8_t *item) { auto *descriptor = *reinterpret_cast( item + Offsets::OFF_ITEM_DESCRIPTOR); if (descriptor == nullptr) return false; const uint32_t flags = *reinterpret_cast( descriptor + Offsets::OFF_DESCRIPTOR_FLAGS); return (flags & Offsets::ITEM_FLAG_SOULBOUND) != 0; } static int __fastcall Script_IsBound(void *L) { if (!Item::Location::IsLocationArg(L, 1)) { Game::Lua::Error(L, "Usage: C_Item.IsBound(itemLocation)"); return 0; } const uint8_t *item = Item::Location::Resolve(L, 1); const bool bound = (item != nullptr) && ItemIsSoulbound(item); Game::Lua::PushBoolean(L, bound ? 1 : 0); return 1; } static void RegisterLuaFunctions() { Game::Lua::RegisterTableFunction("C_Item", "IsBound", &Script_IsBound); } static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions}; } // namespace Item::Bound