Skip to content

Commit b187b9f

Browse files
Update cpp sdk
1 parent 8bb6de9 commit b187b9f

File tree

8 files changed

+250
-26
lines changed

8 files changed

+250
-26
lines changed

api/AltV.Net.Async/AltAsync.Player.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,6 @@ await AltVAsync.Schedule(() =>
156156
mValueArgs.Dispose();
157157
}
158158

159-
public static bool EmitLocked(this IPlayer player, string eventName, params object[] args)
160-
{
161-
var mValues = MValueLocked.CreateFromObjectsLocked(args);
162-
var mValueArgs = MValue.Create(mValues);
163-
var eventNamePtr = AltNative.StringUtils.StringToHGlobalUtf8(eventName);
164-
var successfully = true;
165-
lock (player)
166-
{
167-
if (player.Exists)
168-
{
169-
Alt.Server.TriggerClientEvent(player, eventNamePtr, ref mValueArgs);
170-
}
171-
else
172-
{
173-
successfully = false;
174-
}
175-
}
176-
177-
Marshal.FreeHGlobal(eventNamePtr);
178-
MValue.Dispose(mValues);
179-
mValueArgs.Dispose();
180-
return successfully;
181-
}
182-
183159
public static Task<ReadOnlyPlayer> CopyAsync(this IPlayer player) =>
184160
AltVAsync.Schedule(player.Copy);
185161
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
using AltV.Net.Data;
5+
using AltV.Net.Elements.Args;
6+
using AltV.Net.Elements.Entities;
7+
using AltV.Net.Native;
8+
9+
namespace AltV.Net.Async
10+
{
11+
public static partial class AltAsync
12+
{
13+
public static bool ExecuteLocked(this IPlayer player, Action action)
14+
{
15+
lock (player)
16+
{
17+
if (!player.Exists)
18+
{
19+
return false;
20+
}
21+
22+
action();
23+
return true;
24+
}
25+
}
26+
27+
public static bool ExecuteLocked<T>(this IPlayer player, Action<T> action, T param)
28+
{
29+
lock (player)
30+
{
31+
if (!player.Exists)
32+
{
33+
return false;
34+
}
35+
36+
action(param);
37+
return true;
38+
}
39+
}
40+
41+
public static bool ExecuteLocked<T1, T2, T3>(this IPlayer player, Action<T1, T2, T3> action, T1 param1,
42+
T2 param2, T3 param3)
43+
{
44+
lock (player)
45+
{
46+
if (!player.Exists)
47+
{
48+
return false;
49+
}
50+
51+
action(param1, param2, param3);
52+
return true;
53+
}
54+
}
55+
56+
public static bool SetPositionLocked(this IPlayer player, Position position)
57+
{
58+
lock (player)
59+
{
60+
if (!player.Exists)
61+
{
62+
return false;
63+
}
64+
65+
player.Position = position;
66+
return true;
67+
}
68+
}
69+
70+
public static bool GetPositionLocked(this IPlayer player, ref Position position)
71+
{
72+
lock (player)
73+
{
74+
if (!player.Exists)
75+
{
76+
return false;
77+
}
78+
79+
AltNative.Player.Player_GetPosition(player.NativePointer, ref position);
80+
return true;
81+
}
82+
}
83+
84+
public static bool EmitLocked(this IPlayer player, string eventName, params object[] args)
85+
{
86+
player.ExecuteLocked<float, float, float>(player.SetPosition, 1, 2, 3);
87+
88+
var mValues = MValueLocked.CreateFromObjectsLocked(args);
89+
var mValueArgs = MValue.Create(mValues);
90+
var eventNamePtr = AltNative.StringUtils.StringToHGlobalUtf8(eventName);
91+
var successfully = true;
92+
lock (player)
93+
{
94+
if (player.Exists)
95+
{
96+
Alt.Server.TriggerClientEvent(player, eventNamePtr, ref mValueArgs);
97+
}
98+
else
99+
{
100+
successfully = false;
101+
}
102+
}
103+
104+
Marshal.FreeHGlobal(eventNamePtr);
105+
MValue.Dispose(mValues);
106+
mValueArgs.Dispose();
107+
return successfully;
108+
}
109+
}
110+
}

api/AltV.Net/Elements/Entities/IVehicle.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public interface IVehicle : IEntity
7272
byte DirtLevel { get; set; }
7373

7474
Rgba NeonColor { get; set; }
75+
76+
string AppearanceData { get; set; }
7577

7678
byte GetMod(byte category);
7779

@@ -96,6 +98,8 @@ public interface IVehicle : IEntity
9698
bool IsHandbrakeActive { get; }
9799

98100
byte HeadlightColor { get; set; }
101+
102+
uint RadioStation { get; set; }
99103

100104
bool SirenActive { get; set; }
101105

@@ -190,6 +194,10 @@ public interface IVehicle : IEntity
190194
void SetBumperDamageLevel(byte bumperId, byte damageLevel);
191195

192196
string DamageData { get; set; }
197+
198+
bool ManualEngineControl { get; set; }
199+
200+
string ScriptData { get; set; }
193201

194202
void Remove();
195203

api/AltV.Net/Elements/Entities/Vehicle.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,22 @@ public Rgba NeonColor
426426
}
427427
}
428428

429+
public string AppearanceData
430+
{
431+
get
432+
{
433+
CheckIfEntityExists();
434+
var ptr = IntPtr.Zero;
435+
AltNative.Vehicle.Vehicle_GetAppearanceDataBase64(NativePointer, ref ptr);
436+
return Marshal.PtrToStringAnsi(ptr);
437+
}
438+
set
439+
{
440+
CheckIfEntityExists();
441+
AltNative.Vehicle.Vehicle_LoadAppearanceDataFromBase64(NativePointer, value);
442+
}
443+
}
444+
429445
public bool EngineOn
430446
{
431447
get
@@ -463,6 +479,20 @@ public byte HeadlightColor
463479
}
464480
}
465481

482+
public uint RadioStation
483+
{
484+
get
485+
{
486+
CheckIfEntityExists();
487+
return AltNative.Vehicle.Vehicle_GetRadioStationIndex(NativePointer);
488+
}
489+
set
490+
{
491+
CheckIfEntityExists();
492+
AltNative.Vehicle.Vehicle_SetRadioStationIndex(NativePointer, value);
493+
}
494+
}
495+
466496
public bool SirenActive
467497
{
468498
get
@@ -819,7 +849,38 @@ public string DamageData
819849
}
820850
}
821851

822-
public Vehicle(uint model, Position position, Rotation rotation): this(Alt.Module.Server.CreateVehicleEntity(out var id, model, position, rotation), id)
852+
public bool ManualEngineControl
853+
{
854+
get
855+
{
856+
CheckIfEntityExists();
857+
return AltNative.Vehicle.Vehicle_IsManualEngineControl(NativePointer);
858+
}
859+
set
860+
{
861+
CheckIfEntityExists();
862+
AltNative.Vehicle.Vehicle_SetManualEngineControl(NativePointer, value);
863+
}
864+
}
865+
866+
public string ScriptData
867+
{
868+
get
869+
{
870+
CheckIfEntityExists();
871+
var ptr = IntPtr.Zero;
872+
AltNative.Vehicle.Vehicle_GetScriptDataBase64(NativePointer, ref ptr);
873+
return Marshal.PtrToStringAnsi(ptr);
874+
}
875+
set
876+
{
877+
CheckIfEntityExists();
878+
AltNative.Vehicle.Vehicle_LoadScriptDataFromBase64(NativePointer, value);
879+
}
880+
}
881+
882+
public Vehicle(uint model, Position position, Rotation rotation) : this(
883+
Alt.Module.Server.CreateVehicleEntity(out var id, model, position, rotation), id)
823884
{
824885
Alt.Module.VehiclePool.Add(this);
825886
}

api/AltV.Net/Native/AltV.Vehicle.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ internal static extern void Vehicle_SetNeonActive(IntPtr vehiclePointer, bool le
202202

203203
[DllImport(DllName, CharSet = CharSet.Ansi, CallingConvention = NativeCallingConvention)]
204204
internal static extern void Vehicle_SetNeonColor(IntPtr vehiclePointer, Rgba color);
205+
206+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
207+
internal static extern void Vehicle_GetAppearanceDataBase64(IntPtr vehiclePointer, ref IntPtr text);
208+
209+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
210+
internal static extern void Vehicle_LoadAppearanceDataFromBase64(IntPtr vehiclePointer, string base64);
205211

206212
[DllImport(DllName, CharSet = CharSet.Ansi, CallingConvention = NativeCallingConvention)]
207213
internal static extern bool Vehicle_IsEngineOn(IntPtr vehiclePointer);
@@ -217,6 +223,12 @@ internal static extern void Vehicle_SetNeonActive(IntPtr vehiclePointer, bool le
217223

218224
[DllImport(DllName, CharSet = CharSet.Ansi, CallingConvention = NativeCallingConvention)]
219225
internal static extern void Vehicle_SetHeadlightColor(IntPtr vehiclePointer, byte color);
226+
227+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
228+
internal static extern uint Vehicle_GetRadioStationIndex(IntPtr vehiclePointer);
229+
230+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
231+
internal static extern void Vehicle_SetRadioStationIndex(IntPtr vehiclePointer, uint stationIndex);
220232

221233
[DllImport(DllName, CharSet = CharSet.Ansi, CallingConvention = NativeCallingConvention)]
222234
internal static extern bool Vehicle_IsSirenActive(IntPtr vehiclePointer);
@@ -378,6 +390,18 @@ internal static extern void Vehicle_SetBumperDamageLevel(IntPtr vehiclePointer,
378390

379391
[DllImport(DllName, CharSet = CharSet.Ansi, CallingConvention = NativeCallingConvention)]
380392
internal static extern void Vehicle_LoadDamageDataFromBase64(IntPtr vehiclePointer, string base64);
393+
394+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
395+
internal static extern bool Vehicle_IsManualEngineControl(IntPtr vehiclePointer);
396+
397+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
398+
internal static extern void Vehicle_SetManualEngineControl(IntPtr vehiclePointer, bool state);
399+
400+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
401+
internal static extern void Vehicle_GetScriptDataBase64(IntPtr vehiclePointer, ref IntPtr text);
402+
403+
[DllImport(DllName, CallingConvention = NativeCallingConvention)]
404+
internal static extern void Vehicle_LoadScriptDataFromBase64(IntPtr vehiclePointer, string base64);
381405
}
382406
}
383407
}

runtime/src/altv-c-api/vehicle.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ void Vehicle_SetNeonColor(alt::IVehicle* vehicle, alt::RGBA color) {
274274
return vehicle->SetNeonColor(color);
275275
}
276276

277+
void Vehicle_GetAppearanceDataBase64(alt::IVehicle* vehicle, const char*&base64) {
278+
base64 = vehicle->GetAppearanceDataBase64().CStr();
279+
}
280+
281+
void Vehicle_LoadAppearanceDataFromBase64(alt::IVehicle* vehicle, const char* base64) {
282+
vehicle->LoadAppearanceDataFromBase64(base64);
283+
}
284+
277285
bool Vehicle_IsEngineOn(alt::IVehicle* vehicle) {
278286
return vehicle->IsEngineOn();
279287
}
@@ -294,6 +302,14 @@ void Vehicle_SetHeadlightColor(alt::IVehicle* vehicle, uint8_t color) {
294302
vehicle->SetHeadlightColor(color);
295303
}
296304

305+
uint32_t Vehicle_GetRadioStationIndex(alt::IVehicle* vehicle) {
306+
return vehicle->GetRadioStationIndex();
307+
}
308+
309+
void Vehicle_SetRadioStationIndex(alt::IVehicle* vehicle, uint32_t stationIndex) {
310+
vehicle->SetRadioStationIndex(stationIndex);
311+
}
312+
297313
bool Vehicle_IsSirenActive(alt::IVehicle* vehicle) {
298314
return vehicle->IsSirenActive();
299315
}
@@ -501,3 +517,19 @@ void Vehicle_GetDamageDataBase64(alt::IVehicle* vehicle, const char*&text) {
501517
void Vehicle_LoadDamageDataFromBase64(alt::IVehicle* vehicle, const char* base64) {
502518
vehicle->LoadDamageDataFromBase64(base64);
503519
}
520+
521+
void Vehicle_SetManualEngineControl(alt::IVehicle* vehicle, bool state) {
522+
vehicle->SetManualEngineControl(state);
523+
}
524+
525+
bool Vehicle_IsManualEngineControl(alt::IVehicle* vehicle) {
526+
return vehicle->IsManualEngineControl();
527+
}
528+
529+
void Vehicle_GetScriptDataBase64(alt::IVehicle* vehicle, const char*&base64) {
530+
base64 = vehicle->GetScriptDataBase64().CStr();
531+
}
532+
533+
void Vehicle_LoadScriptDataFromBase64(alt::IVehicle* vehicle, const char* base64) {
534+
vehicle->LoadScriptDataFromBase64(base64);
535+
}

runtime/src/altv-c-api/vehicle.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ EXPORT void Vehicle_SetNeonActive(alt::IVehicle* vehicle, bool left, bool right,
8484
EXPORT void Vehicle_GetNeonColor(alt::IVehicle* vehicle, rgba_t &neonColor);
8585
EXPORT void Vehicle_SetNeonColor(alt::IVehicle* vehicle, alt::RGBA color);
8686

87+
EXPORT void Vehicle_GetAppearanceDataBase64(alt::IVehicle* vehicle, const char*&base64);
88+
EXPORT void Vehicle_LoadAppearanceDataFromBase64(alt::IVehicle* vehicle, const char* base64);
89+
8790
EXPORT bool Vehicle_IsEngineOn(alt::IVehicle* vehicle);
8891
EXPORT void Vehicle_SetEngineOn(alt::IVehicle* vehicle, bool state);
8992

@@ -92,6 +95,9 @@ EXPORT bool Vehicle_IsHandbrakeActive(alt::IVehicle* vehicle);
9295
EXPORT uint8_t Vehicle_GetHeadlightColor(alt::IVehicle* vehicle);
9396
EXPORT void Vehicle_SetHeadlightColor(alt::IVehicle* vehicle, uint8_t color);
9497

98+
EXPORT uint32_t Vehicle_GetRadioStationIndex(alt::IVehicle* vehicle);
99+
EXPORT void Vehicle_SetRadioStationIndex(alt::IVehicle* vehicle, uint32_t stationIndex);
100+
95101
EXPORT bool Vehicle_IsSirenActive(alt::IVehicle* vehicle);
96102
EXPORT void Vehicle_SetSirenActive(alt::IVehicle* vehicle, bool state);
97103

@@ -167,6 +173,13 @@ EXPORT void Vehicle_SetBumperDamageLevel(alt::IVehicle* vehicle, uint8_t bumperI
167173
EXPORT void Vehicle_GetDamageDataBase64(alt::IVehicle* vehicle, const char*&text);
168174
EXPORT void Vehicle_LoadDamageDataFromBase64(alt::IVehicle* vehicle, const char* base64);
169175

176+
//vehicle script data
177+
EXPORT void Vehicle_SetManualEngineControl(alt::IVehicle* vehicle, bool state);
178+
EXPORT bool Vehicle_IsManualEngineControl(alt::IVehicle* vehicle);
179+
180+
EXPORT void Vehicle_GetScriptDataBase64(alt::IVehicle* vehicle, const char*&base64);
181+
EXPORT void Vehicle_LoadScriptDataFromBase64(alt::IVehicle* vehicle, const char* base64);
182+
170183
#ifdef __cplusplus
171184
}
172185
#endif

runtime/thirdparty/altv-cpp-api

0 commit comments

Comments
 (0)