Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-09-2003, 03:05 AM
Yodason
Hill Giant
 
Join Date: Jan 2002
Posts: 205
Default Major bug fix

Code:
void Client::RepairInventory(){

	const Item_Struct* item = 0;

	int16 slotid = 0;

	for(int i=0;i<pp_containerinv_size;i++) {

		slotid = i;



		//Repair Main Inventory

		if(i<pp_inventory_size) {

			if(pp.inventory[slotid] == 0xFFFF) {

				//Nothing in slot, dont need to do anything

			}

			else {

				if(!(item = database.GetItem(pp.inventory[slotid]))) {

					//Item no longer exists, destroy it

					if(slotid == 0) {

						//Cursor

						pp.inventory[0] = 0xFFFF;

						memset(&pp.invitemproperties[0],0,sizeof(ItemProperties_Struct));



						for(int bag=0;bag<10;bag++) {

							int32 currentslot = 80+bag;

							memset(&pp.bagitemproperties[currentslot],0,sizeof(ItemProperties_Struct));

							pp.containerinv[currentslot] = 0xFFFF;

						}

					}

					else if(slotid >= 1 && slotid <= 21) {

						//Equipped Items

						pp.inventory[slotid] = 0xFFFF;

						memset(&pp.invitemproperties[slotid],0,sizeof(ItemProperties_Struct));

					}

					else if(slotid >= 22 && slotid <= 29) {

						//Main Inventory

						pp.inventory[slotid] = 0xFFFF;

						memset(&pp.invitemproperties[slotid],0,sizeof(ItemProperties_Struct));

									

						for(int bag=0;bag<10;bag++) {

							int32 currentslot = ((slotid-22)*10)+bag;

							memset(&pp.bagitemproperties[currentslot],0,sizeof(ItemProperties_Struct));

							pp.containerinv[currentslot] = 0xFFFF;

						}

					}



				}

				else {

					//Item exists, make sure it is ok

					if((item->IsGM() || !item->nosave) && admin < 10) {

						pp.inventory[0] = 0xFFFF;

						memset(&pp.invitemproperties[0],0,sizeof(ItemProperties_Struct));



						if(item->IsBag()) {

							if(slotid == 0) {

								for(int bag=0;bag<10;bag++){

									int32 currentslot = 80+bag;

									memset(&pp.bagitemproperties[currentslot],0,sizeof(ItemProperties_Struct));

									pp.containerinv[currentslot] = 0xFFFF;

								}

							}

							else if(slotid >= 22 && slotid <= 30) {

								for(int bag=0;bag<10;bag++){

									int32 currentslot = ((slotid-22)*10)+bag;

									memset(&pp.bagitemproperties[currentslot],0,sizeof(ItemProperties_Struct));

									pp.containerinv[currentslot] = 0xFFFF;

								}

							}

						}

						else {

							if(item->common.MaxCharges==255)

								pp.invitemproperties[slotid].charges = 255;

							else if(item->common.MaxCharges==0)

								pp.invitemproperties[slotid].charges = item->common.charges;



							memset(pp.invitemproperties[slotid].unknown01,0xFF,sizeof(int8)*2);

							memset(pp.invitemproperties[slotid].unknown02,0xFF,sizeof(int8)*6);

						}

					}

				}

			}

			//End of Repairing Main Inventory





			//Repair Container Inventory

			if(i<pp_containerinv_size) {

				if(pp.containerinv[slotid] == 0xFFFF) {

					//Nothing in slot, don't do anything

				}

				else {

					if(!(item = database.GetItem(pp.containerinv[slotid]))) {

						//Item no longer exists, destroy it

						pp.containerinv[slotid] = 0xFFFF;

						memset(&pp.bagitemproperties[slotid],0,sizeof(ItemProperties_Struct));

					}

					else {

						//Item exists, make sure it is ok

						if((item->IsGM() || !item->nosave) && admin < 10) {

							pp.containerinv[slotid] = 0xFFFF;

							memset(&pp.bagitemproperties[slotid],0,sizeof(ItemProperties_Struct));

						}

						else {

							if(item->common.MaxCharges==255)

								pp.bagitemproperties[slotid].charges = 255;

							else if(item->common.MaxCharges==0)

								pp.bagitemproperties[slotid].charges = item->common.charges;



							memset(pp.bagitemproperties[slotid].unknown01,0xFF,sizeof(int8)*2);

							memset(pp.bagitemproperties[slotid].unknown02,0xFF,sizeof(int8)*6);

						}



					}

				}

			}

		}

		//End of Repairing Container Inventory

		if(i<pp_bank_inv_size) {

			if(!(item = database.GetItem(pp.bank_inv[slotid]))){

				//Item no longer exists, destroy it

				pp.bank_inv[slotid] = 0xFFFF;

				memset(&pp.bankinvitemproperties[slotid],0,sizeof(ItemProperties_Struct));

			}

			else {

				//Item exists, make sure it is ok

				if((item->IsGM() || !item->nosave) && admin < 10) {

					pp.bank_inv[slotid] = 0xFFFF;

					memset(&pp.bankinvitemproperties[slotid],0,sizeof(ItemProperties_Struct));



					for(int bag=0;bag<10;bag++){

						int32 currentslot = bag+slotid;

						memcpy(&pp.bankbagitemproperties[currentslot],0,sizeof(ItemProperties_Struct));

						pp.bank_cont_inv[currentslot] = 0xFFFF;

					}

				}

				else {

					if(item->common.MaxCharges==255)

						pp.bankinvitemproperties[slotid].charges = 255;

					else if(item->common.MaxCharges==0)

						pp.bankinvitemproperties[slotid].charges = item->common.charges;



					memset(pp.bankinvitemproperties[slotid].unknown01,0xFF,sizeof(int8)*2);

					memset(pp.bankinvitemproperties[slotid].unknown02,0xFF,sizeof(int8)*6);

				}

			}

		}



		if(i<pp_bank_cont_inv_size) {

			if(!(item = database.GetItem(pp.bank_cont_inv[slotid]))){

				//Item no longer exists, destroy it

				pp.bank_cont_inv[slotid] = 0xFFFF;

				memset(&pp.bankbagitemproperties[slotid],0,sizeof(ItemProperties_Struct));

			}

			else {

				//Item exists, make sure it is ok

				if((item->IsGM() || !item->nosave) && admin < 10) {

					pp.bank_cont_inv[slotid] = 0xFFFF;

					memset(&pp.bankbagitemproperties[slotid],0,sizeof(ItemProperties_Struct));

				}

				else {

					if(item->common.MaxCharges==255)

						pp.bankbagitemproperties[slotid].charges = 255;

					else if(item->common.MaxCharges==0)

						pp.bankbagitemproperties[slotid].charges = item->common.charges;



					memset(pp.bankbagitemproperties[slotid].unknown01,0xFF,sizeof(int8)*2);

					memset(pp.bankbagitemproperties[slotid].unknown02,0xFF,sizeof(int8)*6);

				}

			}

		}

	}

}
This code fixes several memcpys to memsets so that the zone server no longer crashes when there is something wrong with inventory.
Reply With Quote
 


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 01:46 PM.


 

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