Skip to content

[Bug]: PedProp.IsVariationValid doesn't actually test if the variation is valid but silently preload it into memoryย #1542

@kagikn

Description

@kagikn

๐Ÿ“ฆ What modules are you seeing the problem on?

ScriptHookVDotNet3.dll (v3 SDK/API)

๐Ÿ› ๏ธ SHVDN Version

Between fa83ade and 110abdd (including any stable versions between v3.0.0 and v3.6.0)

๐ŸŽฎ Game Version

Any game versions

๐Ÿ› Bug Description

PedProp.IsVariationValid doesn't actually test if the variation is valid but silently preload it into memory by calling the native NATIVE FUNC INT SET_PED_PRELOAD_PROP_DATA(PED_INDEX PedIndex, PED_PROP_POSITION Anchor, INT PropId, int TexId = 0) (if the variation is valid). Yes, the native was referenced as fa83ade73975b47243cdf3b71ddcc54a95b2b719 by the modding community at the time fa83ade was commited, but now we know the correct name by a leak of sch header files. Fortunately, the leak of the game's codebase reveals how SET_PED_PROP_INDEX tests the pre-conditions. We could fix the issue by testing the values of the anchor point, prop ID, and texture ID.

The defect of the method was reported by @ILaCHu (Discord: c0rsair1675), though I found out how it behaved incorrectly and how to reproduce the issue.

๐Ÿ”„ Steps To Reproduce

  1. Call PedProp.IsVariationValid on a Ped for more than 36 different variations
  2. The method will return false after preloading 36 different variations.

You can easily test with a Ped with "mp_f_freemode_01" or "mp_m_freemode_01". Example snippet;

// test this with a Ped with "mp_f_freemode_01" or "mp_m_freemode_01"!
bool PedProp_IsVariationValid_WorksForAllHeadPropDrawables(Ped ped)
{
    int headPropDrawableCount = Function.Call<int>(Hash.GET_NUMBER_OF_PED_PROP_DRAWABLE_VARIATIONS, _ped.Handle, (int)PedPropAnchorPoint.Head);
    for (int i = 0; i < headPropDrawableCount; i++)
    {
        if (!ped.Style[PedPropAnchorPoint.Head].IsVariationValid(i, 0))
        {
            return false;
        }
    }
    
    return true;
}

๐Ÿ“„ Link To Code Example

No response

โš ๏ธ Current Behavior

PedProp.IsVariationValid returns false after preloading 36 different variations on the ped, even if the variation is actually valid. Also the method silently preload the variation composed of the passed arguments if it's valid.

๐ŸŽฏ Expected Behavior

PedProp.IsVariationValid returns true if the variation is valid, without preloading the variation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: v3 APIArea: the v3 scripting APIbugThis is a bug (not for CI issues)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions