GetStatModifiersFixed

Tracking Issue: #313

Tags: compatibility

The base game provides a function

native function GetStatModifiers(ECharStatType Stat, out array<XComGameState_Effect> Mods, out array<float> ModValues, optional XComGameStateHistory GameStateHistoryObject);

that can be used to identify how much different effects contribute to the calculated stat total. For example, X2AbilityToHitCalc_StandardAim wants to show how many percentage points to-hit or to-crit different effects provide or diminish.

However, the function is subtly broken in the presence of multiplicative modifiers (MODOP_Multiplication or MODOP_PostMultiplication), where it doesn't return the correct contribution but instead simply returns MultiplicationMod * BaseStat. This makes multiplicative modifiers unusable for eStat_Offense and eStat_CritChance.

The Highlander function GetStatModifiersFixed wraps the broken function and fixes the numbers. Additionally, X2AbilityToHitCalc_StandardAim is changed to call this modified function.

Compatibility

Mods that override/replace X2AbilityToHitCalc_StandardAim:GetHitChance may undo the Highlander's changes and use the broken function. In particular, XModBase versions prior to 2.0.2 are known to undo this fix. It is recommended that mods using XModBase upgrade to 2.0.2, and otherwise affected mods check whether GetStatModifiersFixed exists and call it instead:

if (Function'XComGame.XComGameState_Unit.GetStatModifiersFixed' != none)
{
    // call GetStatModifiersFixed
}
else
{
    // call GetStatModifiers
}

Source code references