From db15679ec1785bdeef70c698251b551182ae3c15 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Fri, 12 Jun 2026 15:45:31 +0300 Subject: [PATCH] Add missing Iter->Exists() checks --- Strategic/Assignments.cpp | 2 +- Tactical/Interface Enhanced.cpp | 4 ++-- Tactical/Items.cpp | 24 ++++++++++++------------ Tactical/Soldier Control.cpp | 2 +- Tactical/Weapons.cpp | 10 +++++----- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Strategic/Assignments.cpp b/Strategic/Assignments.cpp index 9dbb5cfc..5867c470 100644 --- a/Strategic/Assignments.cpp +++ b/Strategic/Assignments.cpp @@ -4948,7 +4948,7 @@ static void CollectRepairableItems(SOLDIERTYPE* pRepairSoldier, SOLDIERTYPE* pSo // Check for attachments (are there stackable items that can take attachments though?) UINT8 attachmentIndex = 0; for (attachmentList::const_iterator iter = (*pObj)[stackIndex]->attachments.begin(); iter != (*pObj)[stackIndex]->attachments.end(); ++iter, ++attachmentIndex) { - if (IsItemRepairable(pRepairSoldier, iter->usItem, (*iter)[attachmentIndex]->data.objectStatus, (*iter)[attachmentIndex]->data.sRepairThreshold )) { + if ( iter->exists() && IsItemRepairable(pRepairSoldier, iter->usItem, (*iter)[attachmentIndex]->data.objectStatus, (*iter)[attachmentIndex]->data.sRepairThreshold )) { // Send the main item, not the attachment RepairItem item(pObj, pSoldier, (INVENTORY_SLOT) pocketIndex); itemsToFix.push(item); diff --git a/Tactical/Interface Enhanced.cpp b/Tactical/Interface Enhanced.cpp index 7a7cbfdc..a773924d 100644 --- a/Tactical/Interface Enhanced.cpp +++ b/Tactical/Interface Enhanced.cpp @@ -10073,7 +10073,7 @@ void DrawArmorValues( OBJECTTYPE * gpItemDescObject ) UINT16 iFinalProtectionValue = iProtectionValue; for (attachmentList::iterator iter = (*gpItemDescObject)[0]->attachments.begin(); iter != (*gpItemDescObject)[0]->attachments.end(); ++iter) { - if (Item[ iter->usItem ].usItemClass == IC_ARMOUR) + if ( iter->exists() && Item[ iter->usItem ].usItemClass == IC_ARMOUR) { iFinalProtectionValue += Armour[Item[iter->usItem].ubClassIndex].ubProtection; } @@ -10099,7 +10099,7 @@ void DrawArmorValues( OBJECTTYPE * gpItemDescObject ) UINT16 iComparedFinalProtectionValue = iComparedProtectionValue; for (attachmentList::iterator iter = (*gpComparedItemDescObject)[0]->attachments.begin(); iter != (*gpComparedItemDescObject)[0]->attachments.end(); ++iter) { - if (Item[ iter->usItem ].usItemClass == IC_ARMOUR) + if ( iter->exists() && Item[ iter->usItem ].usItemClass == IC_ARMOUR) { iComparedFinalProtectionValue += Armour[Item[iter->usItem].ubClassIndex].ubProtection; } diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 82151081..6967be53 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -2162,7 +2162,7 @@ BOOLEAN ItemHasAttachments( OBJECTTYPE * pObj, SOLDIERTYPE * pSoldier, UINT8 ite { for(attachmentList::iterator att = (*pObj)[iter]->attachments.begin(); att != (*pObj)[iter]->attachments.end(); ++att) { - if ( att->usItem != 0 && !ItemIsHiddenAttachment(att->usItem) ) + if ( att->exists() && att->usItem != 0 && !ItemIsHiddenAttachment(att->usItem) ) { attachmentHidden = FALSE; break; @@ -2178,7 +2178,7 @@ BOOLEAN ItemHasAttachments( OBJECTTYPE * pObj, SOLDIERTYPE * pSoldier, UINT8 ite { for(attachmentList::iterator att = (*pObj)[iter]->attachments.begin(); att != (*pObj)[iter]->attachments.end(); ++att) { - if ( att->usItem != 0 && !ItemIsHiddenAttachment(att->usItem) ) + if ( att->exists() && att->usItem != 0 && !ItemIsHiddenAttachment(att->usItem) ) { attachmentHidden = FALSE; break; @@ -5658,7 +5658,7 @@ BOOLEAN OBJECTTYPE::AttachObjectNAS( SOLDIERTYPE * pSoldier, OBJECTTYPE * pAttac //Madd: if the attaching/merging item had any attachments on it, then try to move them to the first result for (attachmentList::iterator iter = (*pAttachment)[0]->attachments.begin(); iter != (*pAttachment)[0]->attachments.end();) { - if( ValidItemAttachmentSlot(this, iter->usItem, TRUE, FALSE, subObject )){ + if( iter->exists() && ValidItemAttachmentSlot(this, iter->usItem, TRUE, FALSE, subObject )){ //This seems to be rather valid. Can't be 100% sure though. OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... CreateItem(iter->usItem, (*iter)[0]->data.objectStatus, &tempAttachment); @@ -5995,7 +5995,7 @@ void RemoveProhibitedAttachments(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 //Start by trying to re-attach inseperable items. They take precedence over items that can normally be removed for (attachmentList::iterator iter = tempAttachList.begin(); iter != tempAttachList.end();) { - if(Item[iter->usItem].inseparable && ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, 0, -1, 0, NULL, usAttachmentSlotIndexVector)){ + if( iter->exists() && Item[iter->usItem].inseparable && ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, 0, -1, 0, NULL, usAttachmentSlotIndexVector)){ //This seems to be rather valid. Can't be 100% sure though. if(pObj->AttachObject(NULL, &(*iter), FALSE, 0, -1, FALSE, usAttachmentSlotIndexVector)){ //Ok now we can be sure, lets remove this object so we don't try to drop it later. @@ -6009,7 +6009,7 @@ void RemoveProhibitedAttachments(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 } //Try to attach all the other attachments that didn't fit their current slot. for (attachmentList::iterator iter = tempAttachList.begin(); iter != tempAttachList.end();) { - if(ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, 0, -1, 0, NULL, usAttachmentSlotIndexVector)){ + if( iter->exists() && ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, 0, -1, 0, NULL, usAttachmentSlotIndexVector)){ //This seems to be rather valid. Can't be 100% sure though. if(pObj->AttachObject(NULL, &(*iter), FALSE, 0, -1, FALSE, usAttachmentSlotIndexVector)){ //Ok now we can be sure, lets remove this object so we don't try to drop it later. @@ -6185,7 +6185,7 @@ attachmentList ReInitMergedItem(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 //First re-attach any slot-changing attachments. for (attachmentList::iterator iter = tempSlotChangingAttachList.begin(); iter != tempSlotChangingAttachList.end();) { - if( ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, ubStatusIndex )){ + if( iter->exists() && ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, ubStatusIndex )){ //This seems to be rather valid. Can't be 100% sure though. OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... CreateItem(iter->usItem, (*iter)[0]->data.objectStatus, &tempAttachment); @@ -6202,7 +6202,7 @@ attachmentList ReInitMergedItem(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 //Time to re-attach the other attachments, if we can. I am the king of copy pasta. for (attachmentList::iterator iter = tempAttachList.begin(); iter != tempAttachList.end();) { - if( ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, ubStatusIndex)){ + if( iter->exists() && ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, ubStatusIndex)){ //This seems to be rather valid. Can't be 100% sure though. OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... CreateItem(iter->usItem, (*iter)[0]->data.objectStatus, &tempAttachment); @@ -6219,7 +6219,7 @@ attachmentList ReInitMergedItem(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 //drop all items we couldn't re-attach. for (attachmentList::iterator iter = tempSlotChangingAttachList.begin(); iter != tempSlotChangingAttachList.end(); ++iter) { - if ( Item[iter->usItem].inseparable != 1) + if ( iter->exists() && Item[iter->usItem].inseparable != 1) {//WarmSteel - Couldn't re-attach this item, try to drop it. if (pSoldier) { OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... @@ -6237,7 +6237,7 @@ attachmentList ReInitMergedItem(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 } //and the rest too for (attachmentList::iterator iter = tempAttachList.begin(); iter != tempAttachList.end(); ++iter) { - if ( Item[iter->usItem].inseparable != 1) + if ( iter->exists() && Item[iter->usItem].inseparable != 1) {//WarmSteel - Couldn't re-attach this item, try to drop it. if (pSoldier) { OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... @@ -13223,7 +13223,7 @@ INT16 GetMinRangeForAimBonus( SOLDIERTYPE* pSoldier, OBJECTTYPE * pObj ) attachmentList::iterator iterend = (*pObj)[0]->attachments.end(); for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != iterend; ++iter) { - if ( !gGameExternalOptions.fScopeModes || !IsAttachmentClass(iter->usItem, AC_SCOPE|AC_SIGHT|AC_IRONSIGHT ) ) + if ( !gGameExternalOptions.fScopeModes || (iter->exists() && !IsAttachmentClass(iter->usItem, AC_SCOPE|AC_SIGHT|AC_IRONSIGHT )) ) bonus += Item[iter->usItem].minrangeforaimbonus; } } @@ -15180,7 +15180,7 @@ BOOLEAN OBJECTTYPE::TransformObject( SOLDIERTYPE * pSoldier, UINT8 ubStatusIndex // I am the prince of copy pasta ;) for (attachmentList::iterator iter = unattachableList.begin(); iter != unattachableList.end();) { - if( ValidItemAttachmentSlot(&gTempObject, iter->usItem, TRUE, FALSE, ubStatusIndex )) + if( iter->exists() && ValidItemAttachmentSlot(&gTempObject, iter->usItem, TRUE, FALSE, ubStatusIndex )) { //This seems to be rather valid. Can't be 100% sure though. OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... @@ -15868,7 +15868,7 @@ INT32 GetPercentRangeBonus( OBJECTTYPE * pObj ) bonus = ( bonus * ( 100 + Item[(*pObj)[0]->data.gun.usGunAmmoItem].percentrangebonus ) ) / 100; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if ( !ItemIsDuckbill(iter->usItem) || (ItemIsDuckbill(iter->usItem) && (*pObj)[0]->data.gun.ubGunAmmoType == AMMO_BUCKSHOT )) + if ( iter->exists() && !ItemIsDuckbill(iter->usItem) || (ItemIsDuckbill(iter->usItem) && (*pObj)[0]->data.gun.ubGunAmmoType == AMMO_BUCKSHOT )) bonus = ( bonus * ( 100 + BonusReduce( Item[iter->usItem].percentrangebonus, (*iter)[0]->data.objectStatus ) ) ) / 100; } } diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index 777d03fe..697b6ed1 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -14668,7 +14668,7 @@ void SOLDIERTYPE::SoldierInventoryCoolDown( void ) attachmentList::iterator iterend = (*pObj)[0]->attachments.end( ); for ( attachmentList::iterator iter = (*pObj)[0]->attachments.begin( ); iter != iterend; ++iter ) { - if ( Item[iter->usItem].usFlashLightRange ) + if ( iter->exists() && Item[iter->usItem].usFlashLightRange ) flashlightfound = TRUE; } } diff --git a/Tactical/Weapons.cpp b/Tactical/Weapons.cpp index 79731524..47ff557a 100644 --- a/Tactical/Weapons.cpp +++ b/Tactical/Weapons.cpp @@ -1062,7 +1062,7 @@ INT32 EffectiveArmourLBE( OBJECTTYPE * pObj ) iValue = 0; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) + if ( iter->exists() && Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) { INT32 iValue2; @@ -1088,7 +1088,7 @@ INT32 ExplosiveEffectiveArmourLBE( OBJECTTYPE * pObj ) iValue = 0; for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) + if ( iter->exists() && Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) { INT32 iValue2; @@ -2560,7 +2560,7 @@ BOOLEAN UseGunNCTH( SOLDIERTYPE *pSoldier , INT32 sTargetGridNo ) { for (attachmentList::iterator iter = (*pObjAttHand)[0]->attachments.begin(); iter != (*pObjAttHand)[0]->attachments.end(); ++iter) { - if (ItemHasHiddenMuzzleFlash(iter->usItem)) + if ( iter->exists() && ItemHasHiddenMuzzleFlash(iter->usItem)) { OBJECTTYPE* pA= &(*iter); if ( (*pA)[0]->data.objectStatus >=USABLE) @@ -3346,7 +3346,7 @@ BOOLEAN UseGun( SOLDIERTYPE *pSoldier , INT32 sTargetGridNo ) { for (attachmentList::iterator iter = (*pObjUsed)[0]->attachments.begin(); iter != (*pObjUsed)[0]->attachments.end(); ++iter) { - if (ItemHasHiddenMuzzleFlash(iter->usItem)) + if ( iter->exists() && ItemHasHiddenMuzzleFlash(iter->usItem)) { OBJECTTYPE* pA= &(*iter); if ( (*pA)[0]->data.objectStatus >=USABLE) @@ -7993,7 +7993,7 @@ INT32 TotalArmourProtection( SOLDIERTYPE * pTarget, UINT8 ubHitLocation, INT32 i if (iSlot == VESTPOS && pVestPack->exists() == true) { for (attachmentList::iterator iter = (*pVestPack)[0]->attachments.begin(); iter != (*pVestPack)[0]->attachments.end(); ++iter) { - if (Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) + if ( iter->exists() && Item[iter->usItem].usItemClass == IC_ARMOUR && (*iter)[0]->data.objectStatus > 0 ) { INT32 protection = ArmourProtection( pTarget, Item[iter->usItem].ubClassIndex, &((*iter)[0]->data.objectStatus), iImpact, ubAmmoType, &plateHit );