• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

eluna api: GetIcon() ruturn itemIcon

Ayase

Enthusiast
eluna api, return item icon

src\server\game\DataStores\DBCfmt.h
Code:
---- //char const ItemDisplayTemplateEntryfmt[] = "nxxxxxxxxxxixxxxxxxxxxx";
++++  char const ItemDisplayTemplateEntryfmt[] = "nxxxxsxxxxxxxxxxxxxxxxxxx";

src\server\game\DataStores\DBCStores.cpp

Code:
---- //DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently
++++ DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt);

src/server/game/DataStores/DBCStores.h
Code:
---- //extern DBCStorage <ItemDisplayInfoEntry>      sItemDisplayInfoStore; -- not used currently
++++ extern DBCStorage <ItemDisplayInfoEntry>         sItemDisplayInfoStore;

src/server/game/DataStores/DBCStructure.h
Code:
    uint32      ID;                                         // 0        m_ID
                                                            // 1        m_modelName[2]
                                                            // 2        m_modelTexture[2]
---                                                            // 3        m_inventoryIcon
+++    char*       inventoryIcon;                  // 3        m_inventoryIcon
                                                            // 4        m_geosetGroup[3]
                                                            // 5        m_flags
                                                            // 6        m_spellVisualID

src\LuaEngine\GlobalMethods.h
Code:
int GetIcon(lua_State* L)
	{
		 Item* item = Eluna::CHECKOBJ<Item>(L, 1, false);
		const ItemDisplayInfoEntry* dispInfo;
        if (!item)
        {
			uint32 entry = Eluna::CHECKVAL<uint32 >(L, 1);
			const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
                        if (temp)
			      dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID);
        }
		else
			dispInfo = sItemDisplayInfoStore.LookupEntry(item->GetTemplate()->DisplayInfoID);


		std::ostringstream iconText;
		
		float w = Eluna::CHECKVAL<float >(L, 2);
		float h = Eluna::CHECKVAL<float >(L, 3);
		float x = Eluna::CHECKVAL<float >(L, 4,0);
		float y = Eluna::CHECKVAL<float >(L, 5,0);

		iconText << "|TInterface";
		if (dispInfo)
		{
			iconText << "/ICONS/" << dispInfo->inventoryIcon;
		}
		else
		{
			iconText << "/InventoryItems/WoWUnknownItem01";
		}
		iconText << ":" << w << ":" << h << ":" << x << ":" << y << "|t";
		Eluna::Push(L, iconText.str());
		return 1;
	}

src\LuaEngine\ItemMethods.h
Code:
	int GetIcon(lua_State* L, Item* item)
	{
		std::ostringstream iconText;
		float w = Eluna::CHECKVAL<float >(L, 2);
		float h = Eluna::CHECKVAL<float >(L, 3);
		float x = Eluna::CHECKVAL<float >(L, 4,0);
		float y = Eluna::CHECKVAL<float >(L, 5,0);

		const ItemDisplayInfoEntry* dispInfo = sItemDisplayInfoStore.LookupEntry(item->GetTemplate()->DisplayInfoID);

		iconText << "|TInterface";
		if (dispInfo)
		{
			iconText << "/ICONS/" << dispInfo->inventoryIcon;
		}
		else
		{
			iconText << "/InventoryItems/WoWUnknownItem01";
		}
		iconText << ":" << w << ":" << h << ":" << x << ":" << y << "|t";
		Eluna::Push(L, iconText.str());
		return 1;
	}


src\LuaEngine\LuaFunctions.cpp
Code:
void RegisterGlobals(lua_State* L)
{
    // Getters
++++    lua_register(L, "GetIcon", &LuaGlobalFunctions::GetIcon);                                               //GetIcon(entry/item,high,width,x,y)

Code:
ElunaRegister<Item> ItemMethods[] =
{
    // Getters
++++    { "GetIcon", &LuaItem::GetIcon },                             // :GetIcon(high,width,x,y)



use:

item:GetIcon(40,40,0,0)
or
GetIcon(item,40,40)
or
GetIcon(123456,40,40,-1,10)



Thanks~ :argh::argh:
 
Last edited:

Rochet2

Moderator / Eluna Dev

Rochet2

Moderator / Eluna Dev
Possible crash;
const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID);
if entry is invalid and temp will be nullptr and accessing temp.
 

Ayase

Enthusiast
Code:
	Item* item = Eluna::CHECKOBJ<Item>(L, 1, false);
		const ItemDisplayInfoEntry* dispInfo = NULL;
		if (!item)
		{
			uint32 entry = Eluna::CHECKVAL<uint32 >(L, 1);
			const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
++			if (temp)
				dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID);
		}
		else
			dispInfo = sItemDisplayInfoStore.LookupEntry(item->GetTemplate()->DisplayInfoID);


Add a judgment.

0_0
 

Rochet2

Moderator / Eluna Dev
Code:
	Item* item = Eluna::CHECKOBJ<Item>(L, 1, false);
		[COLOR="#FF0000"]const ItemDisplayInfoEntry* dispInfo = NULL;[/COLOR]
		if (!item)
		{
			uint32 entry = Eluna::CHECKVAL<uint32 >(L, 1);
			const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry);
++			if (temp)
				dispInfo = sItemDisplayInfoStore.LookupEntry(temp->DisplayInfoID);
		}
		else
			dispInfo = sItemDisplayInfoStore.LookupEntry(item->GetTemplate()->DisplayInfoID);


Add a judgment.

0_0

you should also add that red part to the script in main post :)
Because atm its not there and dispInfo will be undefined causing undefined behavior when an entry with no item template is given.
 
Top