Skip to content

Commit

Permalink
feat(game/five): add ped prop collection natives
Browse files Browse the repository at this point in the history
  • Loading branch information
william-des committed Jan 10, 2025
1 parent 7cc7add commit 77c9445
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
57 changes: 57 additions & 0 deletions code/components/extra-natives-five/src/PedCollectionsNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,63 @@ static HookFunction hookFunction([]()
return;
}

context.SetResult<const char*>(GetCollectionName(variationInfo));
});
fx::ScriptEngine::RegisterNativeHandler("GET_PED_PROP_COLLECTION_LOCAL_INDEX", [](fx::ScriptContext& context)
{
uint32_t pedId = context.GetArgument<uint32_t>(0);
int anchorPoint = context.GetArgument<int>(1);
auto variationInfoCollection = GetPedVariationInfoCollection(pedId);
if (!variationInfoCollection)
{
context.SetResult<int>(-1);
return;
}

fx::ScriptContextBuffer newContext;
newContext.Push(pedId);
newContext.Push(anchorPoint);
// Call GET_PED_PROP_INDEX to get global prop index.
fx::ScriptEngine::CallNativeHandler(0x898CC20EA75BACD8, newContext);
int globalPropIndex = newContext.GetResult<int>();
if(globalPropIndex < 0)
{
context.SetResult<int>(-1);
return;
}

context.SetResult<int>(g_GetDlcPropIdx(variationInfoCollection, anchorPoint, globalPropIndex));
});
fx::ScriptEngine::RegisterNativeHandler("GET_PED_PROP_COLLECTION_NAME", [](fx::ScriptContext& context)
{
uint32_t pedId = context.GetArgument<uint32_t>(0);
int anchorPoint = context.GetArgument<int>(1);
auto variationInfoCollection = GetPedVariationInfoCollection(pedId);
if (!variationInfoCollection)
{
context.SetResult<const char*>(nullptr);
return;
}

fx::ScriptContextBuffer newContext;
newContext.Push(pedId);
newContext.Push(anchorPoint);
// Call GET_PED_PROP_INDEX to get global prop index.
fx::ScriptEngine::CallNativeHandler(0x898CC20EA75BACD8, newContext);
int globalPropIndex = newContext.GetResult<int>();
if(globalPropIndex < 0)
{
context.SetResult<const char*>(nullptr);
return;
}

auto variationInfo = g_GetVariationInfoFromPropIdx(variationInfoCollection, anchorPoint, globalPropIndex);
if (!variationInfo)
{
context.SetResult<const char*>(nullptr);
return;
}

context.SetResult<const char*>(GetCollectionName(variationInfo));
});
});
19 changes: 19 additions & 0 deletions ext/native-decls/GetPedPropCollectionLocalIndex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
ns: CFX
apiset: client
game: gta5
---
## GET_PED_PROP_COLLECTION_LOCAL_INDEX

```c
int GET_PED_PROP_COLLECTION_LOCAL_INDEX(Ped ped, int anchorPoint);
```

An analogue to [GET_PED_PROP_INDEX](#_0x898CC20EA75BACD8) that returns collection local prop index (inside [GET_PED_PROP_COLLECTION_NAME](#_0x6B5653E4) collection) instead of the global prop index.

## Parameters
* **ped**: The target ped
* **anchorPoint**: One of the anchor points from [SET_PED_PROP_INDEX](#_0x93376B65A266EB5F)

## Return value
Local drawable index of the drawable that is currently used in the given ped and component, or -1 if the ped does not have a prop at the specified anchor point
21 changes: 21 additions & 0 deletions ext/native-decls/GetPedPropCollectionName
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
ns: CFX
apiset: client
game: gta5
---
## GET_PED_PROP_COLLECTION_NAME

```c
char* GET_PED_PROP_COLLECTION_NAME(Ped ped, int anchorPoint);
```

An analogue to [GET_PED_PROP_INDEX](#_0x898CC20EA75BACD8) that returns collection name instead of the global drawable index.

Should be used together with [GET_PED_PROP_COLLECTION_LOCAL_INDEX](#_0xCD420AD1).

## Parameters
* **ped**: The target ped
* **anchorPoint**: One of the anchor points from [SET_PED_PROP_INDEX](#_0x93376B65A266EB5F)

## Return value
Collection name to which the current prop used in the given ped and anchor point belongs to. Returns null if Ped is not found, does not have a prop at the specified anchor point, or if the index is out of bounds.

0 comments on commit 77c9445

Please sign in to comment.