From e23e473333151848dabcaa195a8de0f9bbea1221 Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Sun, 25 Apr 2021 12:26:58 +0000 Subject: [PATCH] Exploit fix: don't allow "apply item to others" cursor to reveal position of invisible enemy. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8976 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Handle Items.cpp | 19 +++++----------- Tactical/Handle UI.cpp | 33 +++++++-------------------- Tactical/UI Cursors.cpp | 47 +++++++++++++-------------------------- 3 files changed, 29 insertions(+), 70 deletions(-) diff --git a/Tactical/Handle Items.cpp b/Tactical/Handle Items.cpp index b5320836..d6209dd9 100644 --- a/Tactical/Handle Items.cpp +++ b/Tactical/Handle Items.cpp @@ -257,7 +257,6 @@ INT32 HandleItem( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel, UINT16 usHa UINT16 usRaiseGunCost = 0; UINT16 usTurningCost = 0; - // Remove any previous actions pSoldier->aiData.ubPendingAction = NO_PENDING_ACTION; @@ -300,12 +299,6 @@ INT32 HandleItem( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel, UINT16 usHa gTacticalStatus.ubAttackBusyCount = 0; } -// if ( pTargetSoldier ) -// { -// pTargetSoldier->bBeingAttackedCount = 0; -// } - - // Check our soldier's life for unconscious! if ( pSoldier->stats.bLife < OKLIFE ) { @@ -1476,8 +1469,11 @@ INT32 HandleItem( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel, UINT16 usHa } } + UINT8 ubPerson = WhoIsThere2(usMapPos, pSoldier->pathing.bLevel); + // Flugente: apply misc items to other soldiers - if ( ItemCanBeAppliedToOthers( usHandItem ) ) + // sevenfm: check that target soldier is visible + if (ItemCanBeAppliedToOthers(usHandItem) && ubPerson != NOBODY && MercPtrs[ubPerson] && MercPtrs[ubPerson]->bVisible != 0) { // ATE: AI CANNOT GO THROUGH HERE! BOOLEAN fHadToUseCursorPos = FALSE; @@ -1499,12 +1495,7 @@ INT32 HandleItem( SOLDIERTYPE *pSoldier, INT32 sGridNo, INT8 bLevel, UINT16 usHa sAPCost = GetAPsToApplyItem( pSoldier, sActionGridNo ); sAPCost += PlotPath( pSoldier, sActionGridNo, NO_COPYROUTE, FALSE, TEMPORARY, (UINT16)pSoldier->usUIMovementMode, NOT_STEALTH, FORWARD, pSoldier->bActionPoints); - // if we are at the action gridno, the item is a bomb, but nobody is at the gridno, do not apply and do not return - we will plant the bomb instead (handlded later in this function) - if ( Item[ usHandItem ].usItemClass == IC_BOMB && WhoIsThere2( usMapPos, pSoldier->pathing.bLevel ) == NOBODY ) - { - ; - } - else if ( EnoughPoints( pSoldier, sAPCost, 0, fFromUI ) ) + if ( EnoughPoints( pSoldier, sAPCost, 0, fFromUI ) ) { // OK, set UI SetUIBusy( pSoldier->ubID ); diff --git a/Tactical/Handle UI.cpp b/Tactical/Handle UI.cpp index 0c604de2..c662ceb2 100644 --- a/Tactical/Handle UI.cpp +++ b/Tactical/Handle UI.cpp @@ -680,13 +680,13 @@ UINT32 HandleTacticalUI( void ) } // Look for soldier full - if ( FindSoldier( usMapPos, &gusUIFullTargetID, &guiUIFullTargetFlags, ( FINDSOLDIERSAMELEVEL( gsInterfaceLevel ) ) ) ) + if (FindSoldier(usMapPos, &gusUIFullTargetID, &guiUIFullTargetFlags, (FINDSOLDIERSAMELEVEL(gsInterfaceLevel)))) { gfUIFullTargetFound = TRUE; } // Look for soldier selective - if ( FindSoldier( usMapPos, &gusUISelectiveTargetID, &guiUISelectiveTargetFlags, FINDSOLDIERSELECTIVESAMELEVEL( gsInterfaceLevel ) ) ) + if (FindSoldier(usMapPos, &gusUISelectiveTargetID, &guiUISelectiveTargetFlags, FINDSOLDIERSELECTIVESAMELEVEL(gsInterfaceLevel))) { gfUISelectiveTargetFound = TRUE; } @@ -4766,11 +4766,11 @@ INT16 APsToTurnAround(SOLDIERTYPE *pSoldier, INT16 sAdjustedGridNo) BOOLEAN UIMouseOnValidAttackLocation( SOLDIERTYPE *pSoldier ) { - UINT16 usInHand; - BOOLEAN fGuyHere = FALSE; - SOLDIERTYPE *pTSoldier; - UINT8 ubItemCursor; - INT32 usMapPos; + UINT16 usInHand; + BOOLEAN fGuyHere = FALSE; + SOLDIERTYPE *pTSoldier; + UINT8 ubItemCursor; + INT32 usMapPos; if ( !GetMouseMapPos( &usMapPos ) ) { @@ -4788,7 +4788,6 @@ BOOLEAN UIMouseOnValidAttackLocation( SOLDIERTYPE *pSoldier ) return( FALSE ); } - if ( ubItemCursor == WIRECUTCURS ) { if ( IsCuttableWireFenceAtGridNo( usMapPos ) && pSoldier->pathing.bLevel == 0 ) @@ -4964,7 +4963,7 @@ BOOLEAN UIMouseOnValidAttackLocation( SOLDIERTYPE *pSoldier ) } // SEE IF THERE IS SOMEBODY HERE - if ( gfUIFullTargetFound && ubItemCursor != KNIFECURS ) + if ( gfUIFullTargetFound && ubItemCursor != KNIFECURS ) { fGuyHere = TRUE; @@ -4979,14 +4978,6 @@ BOOLEAN UIMouseOnValidAttackLocation( SOLDIERTYPE *pSoldier ) return( FALSE ); } - //if ( Item[ usInHand ].usItemClass == IC_BLADE && usInHand != THROWING_KNIFE ) - //{ - // if ( !fGuyHere ) - // { - // return( FALSE ); - // } - //} - if ( Item[ usInHand ].usItemClass == IC_PUNCH ) { if ( !fGuyHere ) @@ -4995,14 +4986,6 @@ BOOLEAN UIMouseOnValidAttackLocation( SOLDIERTYPE *pSoldier ) } } - //if ( Item[ usInHand ].usItemClass == IC_BLADE ) - //{ - // if ( !fGuyHere ) - // { - // return( FALSE ); - // } - //} - if ( Item[ usInHand ].usItemClass == IC_MEDKIT ) { if ( !fGuyHere ) diff --git a/Tactical/UI Cursors.cpp b/Tactical/UI Cursors.cpp index 3eb3b3ac..2c327fd2 100644 --- a/Tactical/UI Cursors.cpp +++ b/Tactical/UI Cursors.cpp @@ -254,26 +254,6 @@ UINT8 GetProperItemCursor( UINT8 ubSoldierID, UINT16 ubItemIndex, INT32 usMapPos { ubCursorID = HandleNonActivatedTossCursor( pSoldier, sTargetGridNo, fRecalc, uiCursorFlags, ubItemCursor ); } - -#if 0 - if ( gCurrentUIMode == ACTION_MODE && ubItemCursor == TRAJECTORYCURS && ( gTacticalStatus.uiFlags & INCOMBAT ) ) - { - // Alrighty, let's change the cursor! - if ( fRecalc && gfUIFullTargetFound ) - { - // ATE: Check for ammo - if ( IsValidTargetMerc( (UINT8)gusUIFullTargetID ) && EnoughAmmo( pSoldier, FALSE, HANDPOS ) ) - { - // IF it's an ememy, goto confirm action mode - if ( ( guiUIFullTargetFlags & ENEMY_MERC ) && ( guiUIFullTargetFlags & VISIBLE_MERC ) && !( guiUIFullTargetFlags & DEAD_MERC ) && !gfCannotGetThrough ) - { - guiPendingOverrideEvent = A_CHANGE_TO_CONFIM_ACTION; - } - - } - } - } -#endif break; case BOMBCURS: @@ -2337,22 +2317,22 @@ UINT8 HandleHandcuffCursor( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT32 uiCurso return( HANDCUFF_RED_UICURSOR ); } -UINT8 HandleApplyItemCursor( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT32 uiCursorFlags ) +UINT8 HandleApplyItemCursor(SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT32 uiCursorFlags) { // DRAW PATH TO GUY - HandleUIMovementCursor( pSoldier, uiCursorFlags, sGridNo, MOVEUI_TARGET_APPLYITEM ); - - if ( ItemCanBeAppliedToOthers( (&(pSoldier->inv[HANDPOS]))->usItem ) ) + HandleUIMovementCursor(pSoldier, uiCursorFlags, sGridNo, MOVEUI_TARGET_APPLYITEM); + + if (ItemCanBeAppliedToOthers((&(pSoldier->inv[HANDPOS]))->usItem)) { // is there a person here? - UINT8 usSoldierIndex = WhoIsThere2( sGridNo, pSoldier->pathing.bLevel ); - if ( usSoldierIndex != NOBODY ) + UINT8 ubPerson = WhoIsThere2(sGridNo, pSoldier->pathing.bLevel); + if (ubPerson != NOBODY && MercPtrs[ubPerson] && MercPtrs[ubPerson]->bVisible >= 0) { - return( APPLYITEM_GREY_UICURSOR ); + return(APPLYITEM_GREY_UICURSOR); } } - return( APPLYITEM_RED_UICURSOR ); + return(APPLYITEM_RED_UICURSOR); } UINT8 HandleHackCursor( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT32 uiCursorFlags ) @@ -2952,7 +2932,7 @@ UINT8 GetActionModeCursor( SOLDIERTYPE *pSoldier ) } // Flugente: apply misc items to other soldiers - // exception: not for medical items (medkists can have drug effects that are applied during bandaging) + // exception: not for medical items (medkits can have drug effects that are applied during bandaging) if ( ubCursor != AIDCURS && ItemCanBeAppliedToOthers( usInHand ) ) { // if item is a bomb, only allow apply if hovering over a soldier (otherwise we cannot mine anymore) @@ -2962,12 +2942,17 @@ UINT8 GetActionModeCursor( SOLDIERTYPE *pSoldier ) if ( GetMouseMapPos( &usMapPos ) ) { // is there a person here? - if ( WhoIsThere2( usMapPos, pSoldier->pathing.bLevel ) != NOBODY ) - ubCursor = APPLYITEMCURS; + UINT8 ubPerson = WhoIsThere2(usMapPos, pSoldier->pathing.bLevel); + if (ubPerson != NOBODY && MercPtrs[ubPerson] && MercPtrs[ubPerson]->bVisible >= 0) + { + ubCursor = APPLYITEMCURS; + } } } else + { ubCursor = APPLYITEMCURS; + } } // WANNE.WATER: Allow shooting if we are on a "water" tile, but on level > 0