diff --git a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp index 9460e36ae3..64a9a902cc 100644 --- a/code/components/extra-natives-five/src/VehicleExtraNatives.cpp +++ b/code/components/extra-natives-five/src/VehicleExtraNatives.cpp @@ -261,6 +261,7 @@ static int VisualHeightSetOffset = 0x07C; static int LightMultiplierGetOffset; static int VehiclePitchBiasOffset; static int VehicleRollBiasOffset; +static int VehicleFlagsOffset; // TODO: Wheel class. static int WheelYRotOffset = 0x008; @@ -621,6 +622,11 @@ static HookFunction initFunction([]() VehicleRollBiasOffset = VehiclePitchBiasOffset - 4; } + { + auto location = hook::get_pattern("48 85 C0 74 3C 8B 80 ? ? ? ? C1 E8 0F"); + VehicleFlagsOffset = *(uint32_t*)(location + 7); + } + { std::initializer_list list = { { "44 38 ? ? ? ? 02 74 ? F3 0F 10 1D", 13 }, @@ -1155,6 +1161,20 @@ static HookFunction initFunction([]() } }); + fx::ScriptEngine::RegisterNativeHandler("GET_VEHICLE_HAS_FLAG", [](fx::ScriptContext& context) + { + int flagIndex = context.GetArgument(1); + + if (flagIndex < 0 || flagIndex >= (32 * 7)) return; + + if (fwEntity* vehicle = getAndCheckVehicle(context, "GET_VEHICLE_HAS_FLAG")) + { + auto addr = *reinterpret_cast((unsigned char *)vehicle + 0x020); + auto target_block = *(uint32_t*)(addr + VehicleFlagsOffset + sizeof(uint32_t) * (flagIndex / 32)); + context.SetResult((target_block & (1 << (flagIndex & 31))) != 0); + } + }); + fx::ScriptEngine::RegisterNativeHandler("IS_VEHICLE_WANTED", std::bind(readVehicleMemoryBit<&IsWantedOffset, 3>, _1, "IS_VEHICLE_WANTED")); fx::ScriptEngine::RegisterNativeHandler("IS_VEHICLE_PREVIOUSLY_OWNED_BY_PLAYER", std::bind(readVehicleMemoryBit<&PreviouslyOwnedByPlayerOffset, 1>, _1, "IS_VEHICLE_PREVIOUSLY_OWNED_BY_PLAYER")); diff --git a/ext/native-decls/GetVehicleHasFlag.md b/ext/native-decls/GetVehicleHasFlag.md new file mode 100644 index 0000000000..e93886ed88 --- /dev/null +++ b/ext/native-decls/GetVehicleHasFlag.md @@ -0,0 +1,21 @@ +--- +ns: CFX +apiset: client +--- +## GET_VEHICLE_HAS_FLAG + +```c +bool GET_VEHICLE_HAS_FLAG(Vehicle vehicle, int flagIndex); +``` + +Get vehicle.meta flag by index. Useful examples include FLAG_LAW_ENFORCEMENT (31), FLAG_RICH_CAR (36), FLAG_IS_ELECTRIC (43), FLAG_IS_OFFROAD_VEHICLE (48). + +Complete list of flags: https://gtamods.com/wiki/Vehicles.meta#flags +Compilation of all vehicles' metadata files (including their flags): https://forum.cfx.re/t/vehicle-meta-files-last-dlc/5142301 + +## Parameters +* **vehicle**: The vehicle to obtain data for. +* **flagIndex**: Flag index (0-203) + +## Return value +A boolean for whether the flag is set. \ No newline at end of file