Overload of countermeasures

A Forum dedicated to the Suggestion, Creation and Editing of XWA Dynamic Link Library Files

Moderator: JeremyaFr

Post Reply

Overload of countermeasures

User avatar
Phoenix Leader
Rebel Alliance
Posts: 437
Joined: Wed Aug 08, 2018 2:20 pm

Post by Phoenix Leader » Fri Feb 08, 2019 1:20 pm

Hello,
I experienced an issue with countermeasures.
While I'm preparing my craft to re-fly a mission in the flight simulator, I can select 2 types of countermeasures: chaff or flare.
They come in 2 different quantities: for example 1 X-Wing can load 10 chaff or 7 flares.
However, when I come back to the hangar to reload, the amount of countermeasures gets restored to 10 for the X-Wing, even if I chose flare.
I mean after reloading 1 X-Wing can load 10 chaff or 10 flares.

Also tried with other crafts in different missions and always got the same result.
Initial load: X chaff or Y flares (Y<X)
Re-load: X chaff or X flares

Did anyone experience anything similar?

User avatar
Phoenix Leader
Rebel Alliance
Posts: 437
Joined: Wed Aug 08, 2018 2:20 pm

Post by Phoenix Leader » Fri Feb 08, 2019 1:55 pm

I forgot to write 1 important thing: the overload of flares after reloading happens both in v2.02 and with XWACP v1.5 installed.
I use GOG v18061 X-Wing Alliance installation.

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Fri Feb 08, 2019 3:41 pm

Hello,
I think the problem is situated in function L00460650.

The code that load countermesures looks like that:

Code: Select all

// load countermeasures
if( s_pXwaCurrentCraft->CounterMeasuresType != CounterMeasureType_None )
{
    s_pXwaCurrentCraft->CounterMeasuresCount = s_ExeCraftTable[esp18].CounterMeasuresCount;

    if( s_pXwaCurrentCraft->CounterMeasuresType == CounterMeasureType_Flare )
    {
        s_pXwaCurrentCraft->CounterMeasuresCount = XwaMulWordPercent( s_pXwaCurrentCraft->CounterMeasuresCount, 0xAAAC ); // 66.67%
    }
}

The code that reloads countermeasures looks like that:

Code: Select all

// reload countermeasures
if( ebx->CounterMeasuresType != CounterMeasureType_None )
{
    byte cl = ebx->CounterMeasuresCount;
    byte al = s_ExeCraftTable[esp18].CounterMeasuresCount;

    if( cl != al )
    {
        ebx->CounterMeasuresCount = al;

        esp28 = 0x01;
    }
}
As you can see, the 66.67% is not applied when the countermeasures are reloaded.

User avatar
Phoenix Leader
Rebel Alliance
Posts: 437
Joined: Wed Aug 08, 2018 2:20 pm

Post by Phoenix Leader » Fri Feb 08, 2019 11:27 pm

Amazing job! The lack of that 66% is surely what causes the problem.
Ehm, any chances this will be fixed in a future release?

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Sat Feb 09, 2019 2:11 pm

Here is a hook that fixes the countermeasures count:
xwa_hook_countermeasures.zip
Last edited by JeremyaFr on Sat Feb 09, 2019 8:19 pm, edited 1 time in total.

User avatar
Phoenix Leader
Rebel Alliance
Posts: 437
Joined: Wed Aug 08, 2018 2:20 pm

Post by Phoenix Leader » Sat Feb 09, 2019 8:00 pm

Works great! You are the best, Jeremy.
Would be great to see this hook in the future releases.

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Sat Feb 09, 2019 8:20 pm

UPDATE
I've uploaded this hook to GitHub and OneDrive.

User avatar
Phoenix Leader
Rebel Alliance
Posts: 437
Joined: Wed Aug 08, 2018 2:20 pm

Post by Phoenix Leader » Sat Feb 09, 2019 8:49 pm

Thanks again.

Post Reply