Skip to content

Commit eb9d838

Browse files
committed
feat(game/five): add ped prop collection natives
1 parent 7cc7add commit eb9d838

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

code/components/extra-natives-five/src/PedCollectionsNatives.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ static HookFunction hookFunction([]()
403403
// Call GET_PED_DRAWABLE_VARIATION to get global drawable index.
404404
fx::ScriptEngine::CallNativeHandler(0x67F3780DD425D4FC, newContext);
405405
int globalDrawableIndex = newContext.GetResult<int>();
406+
if(globalDrawableIndex < 0)
407+
{
408+
context.SetResult<int>(-1);
409+
return;
410+
}
411+
406412
context.SetResult<int>(g_GetDlcDrawableIdx(variationInfoCollection, componentId, globalDrawableIndex));
407413
});
408414
fx::ScriptEngine::RegisterNativeHandler("GET_PED_DRAWABLE_VARIATION_COLLECTION_NAME", [](fx::ScriptContext& context)
@@ -422,13 +428,76 @@ static HookFunction hookFunction([]()
422428
// Call GET_PED_DRAWABLE_VARIATION to get global drawable index.
423429
fx::ScriptEngine::CallNativeHandler(0x67F3780DD425D4FC, newContext);
424430
int globalDrawableIndex = newContext.GetResult<int>();
431+
if(globalDrawableIndex < 0)
432+
{
433+
context.SetResult<const char*>(nullptr);
434+
return;
435+
}
436+
425437
auto variationInfo = g_GetVariationInfoFromDrawableIdx(variationInfoCollection, componentId, globalDrawableIndex);
426438
if (!variationInfo)
427439
{
428440
context.SetResult<const char*>(nullptr);
429441
return;
430442
}
431443

444+
context.SetResult<const char*>(GetCollectionName(variationInfo));
445+
});
446+
fx::ScriptEngine::RegisterNativeHandler("GET_PED_PROP_COLLECTION_LOCAL_INDEX", [](fx::ScriptContext& context)
447+
{
448+
uint32_t pedId = context.GetArgument<uint32_t>(0);
449+
int anchorPoint = context.GetArgument<int>(1);
450+
auto variationInfoCollection = GetPedVariationInfoCollection(pedId);
451+
if (!variationInfoCollection)
452+
{
453+
context.SetResult<int>(-1);
454+
return;
455+
}
456+
457+
fx::ScriptContextBuffer newContext;
458+
newContext.Push(pedId);
459+
newContext.Push(anchorPoint);
460+
// Call GET_PED_PROP_INDEX to get global prop index.
461+
fx::ScriptEngine::CallNativeHandler(0x898CC20EA75BACD8, newContext);
462+
int globalPropIndex = newContext.GetResult<int>();
463+
if(globalPropIndex < 0)
464+
{
465+
context.SetResult<int>(-1);
466+
return;
467+
}
468+
469+
context.SetResult<int>(g_GetDlcPropIdx(variationInfoCollection, anchorPoint, globalPropIndex));
470+
});
471+
fx::ScriptEngine::RegisterNativeHandler("GET_PED_PROP_COLLECTION_NAME", [](fx::ScriptContext& context)
472+
{
473+
uint32_t pedId = context.GetArgument<uint32_t>(0);
474+
int anchorPoint = context.GetArgument<int>(1);
475+
auto variationInfoCollection = GetPedVariationInfoCollection(pedId);
476+
if (!variationInfoCollection)
477+
{
478+
context.SetResult<const char*>(nullptr);
479+
return;
480+
}
481+
482+
fx::ScriptContextBuffer newContext;
483+
newContext.Push(pedId);
484+
newContext.Push(anchorPoint);
485+
// Call GET_PED_PROP_INDEX to get global prop index.
486+
fx::ScriptEngine::CallNativeHandler(0x898CC20EA75BACD8, newContext);
487+
int globalPropIndex = newContext.GetResult<int>();
488+
if(globalPropIndex < 0)
489+
{
490+
context.SetResult<const char*>(nullptr);
491+
return;
492+
}
493+
494+
auto variationInfo = g_GetVariationInfoFromPropIdx(variationInfoCollection, anchorPoint, globalPropIndex);
495+
if (!variationInfo)
496+
{
497+
context.SetResult<const char*>(nullptr);
498+
return;
499+
}
500+
432501
context.SetResult<const char*>(GetCollectionName(variationInfo));
433502
});
434503
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
ns: CFX
3+
apiset: client
4+
game: gta5
5+
---
6+
## GET_PED_PROP_COLLECTION_LOCAL_INDEX
7+
8+
```c
9+
int GET_PED_PROP_COLLECTION_LOCAL_INDEX(Ped ped, int anchorPoint);
10+
```
11+
12+
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.
13+
14+
## Parameters
15+
* **ped**: The target ped
16+
* **anchorPoint**: One of the anchor points from [SET_PED_PROP_INDEX](#_0x93376B65A266EB5F)
17+
18+
## Return value
19+
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
ns: CFX
3+
apiset: client
4+
game: gta5
5+
---
6+
## GET_PED_PROP_COLLECTION_NAME
7+
8+
```c
9+
char* GET_PED_PROP_COLLECTION_NAME(Ped ped, int anchorPoint);
10+
```
11+
12+
An analogue to [GET_PED_PROP_INDEX](#_0x898CC20EA75BACD8) that returns collection name instead of the global drawable index.
13+
14+
Should be used together with [GET_PED_PROP_COLLECTION_LOCAL_INDEX](#_0xCD420AD1).
15+
16+
## Parameters
17+
* **ped**: The target ped
18+
* **anchorPoint**: One of the anchor points from [SET_PED_PROP_INDEX](#_0x93376B65A266EB5F)
19+
20+
## Return value
21+
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 commit comments

Comments
 (0)