Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2009, 09:16 PM
Congdar
Developer
 
Join Date: Jul 2007
Location: my own little world
Posts: 751
Default items disappearing after last charge is used - possible fix, test your items!

This is working for me using the Titanium client, but I read a post where KLS mentioned that the 0.6.2 client handles some things differently. Looking for testers!

\common\item.h existing:
Code:
	// Remove item from inventory
	void DeleteItem(sint16 slot_id, uint8 quantity=0);
\common\item.h change to:
Code:
	// Remove item from inventory
	bool DeleteItem(sint16 slot_id, uint8 quantity=0, bool isEquipment=false);

\common\Item.cpp replace method Inventory::DeleteItem(sint16 slot_id, uint8 quantity) with:
Code:
// Remove item from inventory (with memory delete)
bool Inventory::DeleteItem(sint16 slot_id, uint8 quantity, bool isEquipment)
{
	// Pop item out of inventory map (or queue)
	ItemInst* item_to_delete = PopItem(slot_id);
	
	// Determine if object should be fully deleted, or
	// just a quantity of charges of the item can be deleted
	if (item_to_delete && (quantity > 0)) {
		item_to_delete->SetCharges(item_to_delete->GetCharges() - quantity);
		if((item_to_delete->GetCharges() > 0) || isEquipment) {
			// Charges still exist!  Put back into inventory
			_PutItem(slot_id, item_to_delete);
			return false;
		}
	}
	
	// Item can now be destroyed
	safe_delete(item_to_delete);
	return true;
}



\zone\inventory.cpp replace method Client::DeleteItemInInventory(sint16 slot_id, sint8 quantity, bool client_update) with:
Code:
// Remove item from inventory
void Client::DeleteItemInInventory(sint16 slot_id, sint8 quantity, bool client_update) {
	#if (EQDEBUG >= 5)
		LogFile->write(EQEMuLog::Debug, "DeleteItemInInventory(%i, %i, %s)", slot_id, quantity, (client_update) ? "true":"false");
	#endif

	bool isDeleted = false;
	const Item_Struct* item = m_inv[slot_id]->GetItem();
	if(
		(m_inv[slot_id]->GetItem()->Click.Type == ET_Expendable) ||
		(m_inv[slot_id]->GetItem()->Click.Type == ET_ClickEffect) ||
		(m_inv[slot_id]->GetItem()->Click.Type == ET_ClickEffect2) ||
		(item->ItemType == ItemTypeFood) ||
		(item->ItemType == ItemTypeDrink) ||
		(item->ItemType == ItemTypeBandage) ||
		(item->ItemType == ItemTypeThrowing) ||
		(item->ItemType == ItemTypeThrowingv2) ||
		(item->ItemType == ItemTypeArrow) ||
		(item->ItemType == ItemTypeFishingBait) ||
		(item->ItemType == ItemTypeAlcohol) ||
		(item->ItemType == ItemTypePoison) ||
		(item->ItemType == ItemTypeStackable)
		) {
			isDeleted = m_inv.DeleteItem(slot_id, quantity);
	}
	else if(m_inv[slot_id]->GetItem()->Click.Type == ET_EquipClick) {
		isDeleted = m_inv.DeleteItem(slot_id, quantity, true);
	}

	const ItemInst* inst=NULL;
	if(slot_id==SLOT_CURSOR) {
		list<ItemInst*>::const_iterator s=m_inv.cursor_begin(),e=m_inv.cursor_end();
		database.SaveCursor(character_id, s, e);
	}
	else {
		// Save change to database
		inst = m_inv[slot_id];
		database.SaveInventory(character_id, inst, slot_id);
	}

	if(client_update) {
		EQApplicationPacket* outapp;
		if(inst) {
			if(!inst->IsStackable() && !isDeleted) 
				// Non stackable item with charges = Item with clicky spell effect ? Delete a charge.
				outapp = new EQApplicationPacket(OP_DeleteCharge, sizeof(MoveItem_Struct));
			else
				// Stackable, arrows, etc ? Delete one from the stack
				outapp = new EQApplicationPacket(OP_DeleteItem, sizeof(MoveItem_Struct));

			DeleteItem_Struct* delitem	= (DeleteItem_Struct*)outapp->pBuffer;
			delitem->from_slot			= slot_id;
			delitem->to_slot			= 0xFFFFFFFF;
			delitem->number_in_stack	= 0xFFFFFFFF;
			for(int loop=0;loop<quantity;loop++)
				QueuePacket(outapp);
			safe_delete(outapp);
		}
		else {
			outapp = new EQApplicationPacket(OP_MoveItem, sizeof(MoveItem_Struct));
			MoveItem_Struct* delitem	= (MoveItem_Struct*)outapp->pBuffer;
			delitem->from_slot			= slot_id;
			delitem->to_slot			= 0xFFFFFFFF;
			delitem->number_in_stack	= 0xFFFFFFFF;
			QueuePacket(outapp);
			safe_delete(outapp);
		}
	}
}
Reply With Quote
  #2  
Old 01-10-2009, 06:55 PM
Congdar
Developer
 
Join Date: Jul 2007
Location: my own little world
Posts: 751
Default

This still needs some tweaking. Scribing spells is broke and it looks like trading is broke too, but hey... your items don't poof when you use the last charge! I've made a fix for the spell scribing and I'm working on the trading issue now.
Reply With Quote
  #3  
Old 01-10-2009, 07:33 PM
cavedude's Avatar
cavedude
The PEQ Dude
 
Join Date: Apr 2003
Location: -
Posts: 1,988
Default

Certain items don't deplete when used in tradeskills as well with this patch, one example is: http://lucy.allakhazam.com/item.html?id=27760 I also got a report that inventories didn't seem to be updating at all anymore.

Also, PEQ was getting this crash which is related to the above code:

Code:
#0  Client::DeleteItemInInventory(short, signed char, bool) (this=0x85915e0,
    slot_id=30, quantity=0 '\0', client_update=false) at Item.h:300
#1  0x080e271c in Client::OPMemorizeSpell(EQApplicationPacket const*) (
    this=0x85915e0, app=0x84a0440) at client_process.cpp:1097
#2  0x0819ab52 in Client::Handle_OP_MemorizeSpell(EQApplicationPacket const*) (
    this=0x0, app=0x0) at client_packet.cpp:3053
#3  0x08192570 in Client::HandlePacket(EQApplicationPacket const*) (
    this=0x85915e0, app=0x44112008) at client_packet.cpp:409
#4  0x080dfefd in Client::Process() (this=0x85915e0) at client_process.cpp:604
#5  0x080c2553 in EntityList::MobProcess() (this=0x82e2a20) at entity.cpp:462
#6  0x080eb9a4 in main (argc=0, argv=0xbfffef74) at net.cpp:494
Reply With Quote
  #4  
Old 01-10-2009, 08:37 PM
Congdar
Developer
 
Join Date: Jul 2007
Location: my own little world
Posts: 751
Default

Thanks for testing this. Your crash looks like the spellbook scribing I mentioned above and I'll take a look into the tradeskill consumption.
Reply With Quote
  #5  
Old 01-11-2009, 11:59 PM
Congdar
Developer
 
Join Date: Jul 2007
Location: my own little world
Posts: 751
Default

Try this new code out. I've fixed the Spinechill Silk combine and the Spellbook Scribe crash.
If somebody could list some thing to test or items that currently go away when the charges are used but aren't supposed to, that would be great.

Things I've tested with this new update:
Tradeskills:
Created Fish Rolls by combining 1 Fresh Fish and 1 Bat Wings. Stacked supplies correctly subtracted.
Created Spinechill Silk by combining 1 Spinechill Ichor Vial and 2 Spinechill Silk. Unstackable supplies correctly subtracted.

Worn items with charges:
Cleric/Paladin Shield - Aegis of Life 1 charge of Superior Healing. Charge used, Item not deleted.
Journeyman's Boots. Unlimited charges, not deleted.

Inventory items with charges:
Prayers of Life 5 charges of Word of Healing. Charges used, Item deleted.
Crystalized Pumice 5 charges of Nullify Magic. Charges used, Item deleted.
Stack of 10 Cloudy Potions. Stack decremented correctly and last one deleted.
5 Dose Cloudy Potion. Charges used, Item deleted.
Stack of Bandages. Took some damage and used Bind Wound skill. Bandages decremented correctly.

Spell Scribing:
Wizard memorized Gate spell. Spell scroll deleted, no crash.

Merchants:
Purchased stackable items
Purchased unstackable items
Sold stackable items
Sold unstackable items

Bots:
Trade with bots to give them equipment works.
#bot inventory remove used successfully

GM:
#si [itemid] worked.
#nukeitem [itemid] worked.

You will still need the item.h and Item.cpp changes from the first post.

This is the spell scribing fix:
\zone\client_process.cpp void Client::OPMemorizeSpell(const EQApplicationPacket* app)
Replace the case statement for memSpellScribing:
Code:
		case memSpellScribing:	{	// scribing spell to book
			ItemInst* inst = m_inv.PopItem(SLOT_CURSOR);
			
			if(inst && inst->IsType(ItemClassCommon))
			{
				const Item_Struct* item = inst->GetItem();
				
				if(item && item->Scroll.Effect == (sint32)(memspell->spell_id))
				{
					ScribeSpell(memspell->spell_id, memspell->slot);

					// Destroy scroll on cursor
					EQApplicationPacket* outapp = new EQApplicationPacket(OP_MoveItem, sizeof(MoveItem_Struct));
					MoveItem_Struct* spellmoveitem = (MoveItem_Struct*) outapp->pBuffer;
					spellmoveitem->from_slot = SLOT_CURSOR;
					spellmoveitem->to_slot = SLOT_INVALID;
					spellmoveitem->number_in_stack = 0;
					QueuePacket(outapp);
					safe_delete(outapp);

					DeleteItemInInventory(SLOT_CURSOR);
					
				}
				else 
					Message(0,"Scribing spell: inst exists but item does not or spell ids do not match.");
			}
			else
				Message(0,"Scribing a spell without an inst on your cursor?");
			break;

			}
with
Code:
		case memSpellScribing:	{	// scribing spell to book
			const ItemInst* inst = m_inv[SLOT_CURSOR];

			if(inst && inst->IsType(ItemClassCommon))
			{
				const Item_Struct* item = inst->GetItem();
				
				if(item && item->Scroll.Effect == (sint32)(memspell->spell_id))
				{
					ScribeSpell(memspell->spell_id, memspell->slot);
					DeleteItemInInventory(SLOT_CURSOR, 1, true);
				}
				else 
					Message(0,"Scribing spell: inst exists but item does not or spell ids do not match.");
			}
			else
				Message(0,"Scribing a spell without an inst on your cursor?");
			break;
		}
Here's a complete replacement again for the method \zone\inventory.cpp Client::DeleteItemInInventory(sint16 slot_id, sint8 quantity, bool client_update)
Code:
// Remove item from inventory
void Client::DeleteItemInInventory(sint16 slot_id, sint8 quantity, bool client_update) {
	#if (EQDEBUG >= 5)
		LogFile->write(EQEMuLog::Debug, "DeleteItemInInventory(%i, %i, %s)", slot_id, quantity, (client_update) ? "true":"false");
	#endif

	if(!m_inv[slot_id]) {
		return;
	}

	bool isDeleted = false;
	if(m_inv[slot_id]->GetItem()->Click.Type == ET_EquipClick) {
		isDeleted = m_inv.DeleteItem(slot_id, quantity, true);
	}
	else {
		isDeleted = m_inv.DeleteItem(slot_id, quantity);
	}

	const ItemInst* inst=NULL;
	if(slot_id==SLOT_CURSOR) {
		list<ItemInst*>::const_iterator s=m_inv.cursor_begin(),e=m_inv.cursor_end();
		database.SaveCursor(character_id, s, e);
	}
	else {
		// Save change to database
		inst = m_inv[slot_id];
		database.SaveInventory(character_id, inst, slot_id);
	}

	if(client_update) {
		EQApplicationPacket* outapp;
		if(inst) {
			if(!inst->IsStackable() && !isDeleted) 
				// Non stackable item with charges = Item with clicky spell effect ? Delete a charge.
				outapp = new EQApplicationPacket(OP_DeleteCharge, sizeof(MoveItem_Struct));
			else
				// Stackable, arrows, etc ? Delete one from the stack
				outapp = new EQApplicationPacket(OP_DeleteItem, sizeof(MoveItem_Struct));

			DeleteItem_Struct* delitem	= (DeleteItem_Struct*)outapp->pBuffer;
			delitem->from_slot		= slot_id;
			delitem->to_slot		= 0xFFFFFFFF;
			delitem->number_in_stack	= 0xFFFFFFFF;
			for(int loop=0;loop<quantity;loop++)
				QueuePacket(outapp);
			safe_delete(outapp);
		}
		else {
			outapp = new EQApplicationPacket(OP_MoveItem, sizeof(MoveItem_Struct));
			MoveItem_Struct* delitem	= (MoveItem_Struct*)outapp->pBuffer;
			delitem->from_slot		= slot_id;
			delitem->to_slot		= 0xFFFFFFFF;
			delitem->number_in_stack	= 0xFFFFFFFF;
			QueuePacket(outapp);
			safe_delete(outapp);
		}
	}
}
Reply With Quote
  #6  
Old 01-13-2009, 12:01 PM
cavedude's Avatar
cavedude
The PEQ Dude
 
Join Date: Apr 2003
Location: -
Posts: 1,988
Default

Found a new problem with the above code. Permanent items with charges do not delete off of player corpses. They remain on the player, AND also appear on the corpse. The charges of the items that remain on the player do seem to be depleted, as even unlimited items say the item is out of charges when used. Deleting those items, and looting the ones of their corpse works fine.

Edit: I should mention this bug only effects those who enable player corpses with items!

Last edited by cavedude; 01-13-2009 at 08:12 PM..
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 07:35 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3