Skip to content

Commit 7676ebb

Browse files
Security improvements
1 parent 68a9cc1 commit 7676ebb

File tree

4 files changed

+74
-74
lines changed

4 files changed

+74
-74
lines changed

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

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@ namespace AltV.Net.Async
1111
{
1212
public static partial class AltAsync
1313
{
14-
public static async Task<IVehicle> CreateVehicle(uint model, Position pos, Rotation rot)
15-
{
16-
ushort id = default;
17-
var vehiclePtr = await AltVAsync.Schedule(() =>
18-
AltNative.Server.Server_CreateVehicle(((Server) Alt.Server).NativePointer, model, pos, rot,
19-
ref id));
20-
Alt.Module.VehiclePool.Create(vehiclePtr, id, out var vehicle);
21-
return vehicle;
22-
}
14+
public static Task<IVehicle> CreateVehicle(uint model, Position pos, Rotation rot) => AltVAsync.Schedule(() =>
15+
Alt.Module.Server.CreateVehicle(model, pos, rot));
2316

2417
public static Task<IVehicle> CreateVehicle(VehicleModel model, Position pos, Rotation rot) =>
2518
CreateVehicle((uint) model, pos, rot);
@@ -36,14 +29,8 @@ public static IVehicleBuilder CreateVehicleBuilder(VehicleModel model, Position
3629
public static IVehicleBuilder CreateVehicleBuilder(string model, Position pos, Rotation rot) =>
3730
new VehicleBuilder(Alt.Hash(model), pos, rot);
3831

39-
public static async Task<IPlayer> GetDriverAsync(this IVehicle vehicle)
40-
{
41-
var entityPointer =
42-
await AltVAsync.Schedule(() =>
43-
!vehicle.Exists ? IntPtr.Zero : AltNative.Vehicle.Vehicle_GetDriver(vehicle.NativePointer));
44-
if (entityPointer == IntPtr.Zero) return null;
45-
return Alt.Module.PlayerPool.GetOrCreate(entityPointer, out var player) ? player : null;
46-
}
32+
public static Task<IPlayer> GetDriverAsync(this IVehicle vehicle) => AltVAsync.Schedule(() =>
33+
!vehicle.Exists ? null : vehicle.Driver);
4734

4835
public static Task<byte> GetModKitAsync(this IVehicle vehicle) =>
4936
AltVAsync.Schedule(() => vehicle.ModKit);
@@ -235,22 +222,22 @@ public static Task<bool> IsRoofOpenAsync(this IVehicle vehicle) =>
235222

236223
public static Task SetRoofOpenAsync(this IVehicle vehicle, bool roofOpen) =>
237224
AltVAsync.Schedule(() => vehicle.RoofOpened = roofOpen);
238-
225+
239226
public static Task<byte> GetDoorStateAsync(this IVehicle vehicle, byte doorId) =>
240227
AltVAsync.Schedule(() => vehicle.GetDoorState(doorId));
241-
228+
242229
public static Task SetDoorStateAsync(this IVehicle vehicle, byte doorId, byte state) =>
243230
AltVAsync.Schedule(() => vehicle.SetDoorState(doorId, state));
244-
231+
245232
public static Task<VehicleDoorState> GetDoorStateAsync(this IVehicle vehicle, VehicleDoor door) =>
246233
AltVAsync.Schedule(() => vehicle.GetDoorState(door));
247-
234+
248235
public static Task SetDoorStateAsync(this IVehicle vehicle, VehicleDoor door, VehicleDoorState state) =>
249236
AltVAsync.Schedule(() => vehicle.SetDoorState(door, state));
250-
237+
251238
public static Task<bool> IsWindowOpenedAsync(this IVehicle vehicle, byte windowId) =>
252239
AltVAsync.Schedule(() => vehicle.IsWindowOpened(windowId));
253-
240+
254241
public static Task SetWindowOpenedAsync(this IVehicle vehicle, byte windowId, bool state) =>
255242
AltVAsync.Schedule(() => vehicle.SetWindowOpened(windowId, state));
256243

@@ -286,19 +273,19 @@ public static Task<bool> IsFlamethrowerActiveAsync(this IVehicle vehicle) =>
286273

287274
public static Task<bool> HasArmoredWindowsAsync(this IVehicle vehicle) =>
288275
AltVAsync.Schedule(() => vehicle.HasArmoredWindows);
289-
276+
290277
public static Task SetSpecialLightDamaged(this IVehicle vehicle, byte specialLightId, bool isDamaged) =>
291278
AltVAsync.Schedule(() => vehicle.SetSpecialLightDamaged(specialLightId, isDamaged));
292-
279+
293280
public static Task<bool> IsSpecialLightDamaged(this IVehicle vehicle, byte specialLightId) =>
294281
AltVAsync.Schedule(() => vehicle.IsSpecialLightDamaged(specialLightId));
295-
282+
296283
public static Task SetWindowDamaged(this IVehicle vehicle, byte windowId, bool isDamaged) =>
297284
AltVAsync.Schedule(() => vehicle.SetWindowDamaged(windowId, isDamaged));
298-
285+
299286
public static Task<bool> IsWindowDamaged(this IVehicle vehicle, byte windowId) =>
300287
AltVAsync.Schedule(() => vehicle.IsWindowDamaged(windowId));
301-
288+
302289
// TODO: Add: SetLightDamaged, IsLightDamaged, SetPartBulletHoles, GetPartBulletHoles, SetPartDamageLevel, GetPartDamageLevel
303290
// TODO: GetArmoredWindowHealth, SetArmoredWindowHealth, GetArmoredWindowShootCount, SetArmoredWindowShootCount
304291
// TODO: GetBumperDamageLevel, SetBumperDamageLevel
@@ -341,31 +328,31 @@ public static Task<Tuple<bool, bool, bool, bool>> GetNeonActiveAsync(this IVehic
341328
public static Task
342329
SetNeonActiveAsync(this IVehicle vehicle, bool left, bool right, bool front, bool back) =>
343330
AltVAsync.Schedule(() => vehicle.SetNeonActive(left, right, front, back));
344-
331+
345332
public static Task<string> GetAppearanceDataAsync(this IVehicle vehicle) =>
346333
AltVAsync.Schedule(() => vehicle.AppearanceData);
347334

348335
public static Task SetAppearanceDataAsync(this IVehicle vehicle, string text) =>
349336
AltVAsync.Schedule(() => vehicle.AppearanceData = text);
350-
337+
351338
public static Task<uint> GetRadioStationAsync(this IVehicle vehicle) =>
352339
AltVAsync.Schedule(() => vehicle.RadioStation);
353340

354341
public static Task SetRadioStationAsync(this IVehicle vehicle, uint radioStation) =>
355342
AltVAsync.Schedule(() => vehicle.RadioStation = radioStation);
356-
343+
357344
public static Task<bool> GetManualEngineControlAsync(this IVehicle vehicle) =>
358345
AltVAsync.Schedule(() => vehicle.ManualEngineControl);
359346

360347
public static Task SetManualEngineControlAsync(this IVehicle vehicle, bool state) =>
361348
AltVAsync.Schedule(() => vehicle.ManualEngineControl = state);
362-
349+
363350
public static Task<string> GetScriptDataAsync(this IVehicle vehicle) =>
364351
AltVAsync.Schedule(() => vehicle.ScriptData);
365352

366353
public static Task SetScriptDataAsync(this IVehicle vehicle, string text) =>
367354
AltVAsync.Schedule(() => vehicle.ScriptData = text);
368-
355+
369356
public static Task RemoveAsync(this IVehicle vehicle) => AltVAsync.Schedule(vehicle.Remove);
370357
}
371358
}

api/AltV.Net.Example/SampleResource.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public override void OnStart()
2828
var convertibleObject = new ConvertibleObject();
2929
Alt.Emit("convertible_test", convertibleObject);
3030

31-
Alt.CreateColShapeCircle(new Position(0, 0, 0), 1);
32-
33-
Alt.OnColShape += (shape, entity, state) => { };
34-
3531
Alt.On<string>("test", s => { Alt.Log("test=" + s); });
3632
Alt.OnServer("test", args => { Alt.Log("args=" + args[0]); });
3733
Alt.Emit("test", "bla");
@@ -58,6 +54,15 @@ public override void OnStart()
5854
async args => { await AltAsync.Do(() => Alt.Log("bla with no args:" + args.Length)); });
5955
Alt.Emit("bla");
6056

57+
var blip = Alt.CreateBlip(BlipType.Area, Position.Zero);
58+
blip.Color = 1;
59+
60+
var checkpoint = Alt.CreateCheckpoint(CheckpointType.Cyclinder, Position.Zero, 1f, 1f, Rgba.Zero);
61+
Alt.Log(checkpoint.Color.ToString());
62+
63+
var voiceChannel = Alt.CreateVoiceChannel(true, 10f);
64+
Alt.Log(voiceChannel.MaxDistance.ToString());
65+
6166
var vehicle = Alt.CreateVehicle(VehicleModel.Apc, new Position(1, 2, 3), new Rotation(1, 2, 3));
6267
Alt.Log(vehicle.Position.ToString());
6368
vehicle.PrimaryColor = 7;
@@ -248,22 +253,37 @@ async delegate(string s, string s1, long i1, string[] arg3, object[] arg4, IMyVe
248253
catch (BaseObjectRemovedException baseObjectRemovedException)
249254
{
250255
}
251-
256+
252257
Alt.RegisterEvents(this);
253-
258+
254259
Alt.Emit("bla2", "bla");
255-
260+
256261
AltAsync.RegisterEvents(this);
257-
262+
258263
Alt.Emit("asyncBla3", "bla");
264+
Alt.OnColShape += (shape, entity, state) =>
265+
{
266+
Console.WriteLine("collision shape test:" + shape + " " + shape.GetData("bla", out int id1) + " " + id1);
267+
Console.WriteLine(" " + shape + " " + shape.GetMetaData("bla", out long id2) + " " + id2 + " " + entity + " " + state);
268+
};
269+
270+
var colShapeCylinder = Alt.CreateColShapeCylinder(new Position(1337, 1337, 1337), 10, 10);
271+
colShapeCylinder.SetMetaData("bla", 1);
272+
colShapeCylinder.SetData("bla", (int) 2);
273+
274+
var colShapeCircle = Alt.CreateColShapeCircle(new Position(1337, 1337, 1337), 10);
275+
colShapeCircle.SetMetaData("bla", 3);
276+
colShapeCircle.SetData("bla", (int) 4);
277+
278+
Alt.CreateVehicle(VehicleModel.Adder, new Position(1337, 1337, 1337), Rotation.Zero);
259279
}
260-
280+
261281
[Event("bla2")]
262282
public void MyServerEventHandler2(string myString)
263283
{
264284
Alt.Log(myString);
265285
}
266-
286+
267287
[AsyncEvent]
268288
public void asyncBla3(string myString)
269289
{

api/AltV.Net.NetworkingEntity/EntityStreamer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using System;
21
using AltV.Net.NetworkingEntity.Elements.Entities;
32
using Entity;
43
using Google.Protobuf;
5-
using net.vieapps.Components.Utility;
64

75
namespace AltV.Net.NetworkingEntity
86
{

api/AltV.Net/Server.cs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -221,74 +221,69 @@ public void TriggerClientEvent(IPlayer player, string eventName, params object[]
221221
public IVehicle CreateVehicle(uint model, Position pos, Rotation rotation)
222222
{
223223
ushort id = default;
224-
vehiclePool.Create(AltNative.Server.Server_CreateVehicle(NativePointer, model, pos, rotation, ref id), id,
225-
out var vehicle);
226-
return vehicle;
224+
var ptr = AltNative.Server.Server_CreateVehicle(NativePointer, model, pos, rotation, ref id);
225+
return vehiclePool.Get(ptr, out var vehicle) ? vehicle : null;
227226
}
228227

229228
public ICheckpoint CreateCheckpoint(IPlayer player, byte type, Position pos, float radius, float height,
230229
Rgba color)
231230
{
232-
checkpointPool.Create(AltNative.Server.Server_CreateCheckpoint(NativePointer,
231+
var ptr = AltNative.Server.Server_CreateCheckpoint(NativePointer,
233232
player?.NativePointer ?? IntPtr.Zero,
234-
type, pos, radius, height, color), out var checkpoint);
235-
return checkpoint;
233+
type, pos, radius, height, color);
234+
return checkpointPool.Get(ptr, out var checkpoint) ? checkpoint : null;
236235
}
237236

238237
public IBlip CreateBlip(IPlayer player, byte type, Position pos)
239238
{
240-
blipPool.Create(AltNative.Server.Server_CreateBlip(NativePointer, player?.NativePointer ?? IntPtr.Zero,
241-
type, pos), out var blip);
242-
return blip;
239+
var ptr = AltNative.Server.Server_CreateBlip(NativePointer, player?.NativePointer ?? IntPtr.Zero,
240+
type, pos);
241+
return blipPool.Get(ptr, out var blip) ? blip : null;
243242
}
244243

245244
public IBlip CreateBlip(IPlayer player, byte type, IEntity entityAttach)
246245
{
247-
blipPool.Create(AltNative.Server.Server_CreateBlipAttached(NativePointer,
246+
var ptr = AltNative.Server.Server_CreateBlipAttached(NativePointer,
248247
player?.NativePointer ?? IntPtr.Zero,
249-
type, entityAttach.NativePointer), out var blip);
250-
return blip;
248+
type, entityAttach.NativePointer);
249+
return blipPool.Get(ptr, out var blip) ? blip : null;
251250
}
252251

253252
public IVoiceChannel CreateVoiceChannel(bool spatial, float maxDistance)
254253
{
255-
voiceChannelPool.Create(AltNative.Server.Server_CreateVoiceChannel(NativePointer,
256-
spatial, maxDistance), out var voiceChannel);
257-
return voiceChannel;
254+
var ptr = AltNative.Server.Server_CreateVoiceChannel(NativePointer,
255+
spatial, maxDistance);
256+
return voiceChannelPool.Get(ptr, out var voiceChannel) ? voiceChannel : null;
258257
}
259258

260259
public IColShape CreateColShapeCylinder(Position pos, float radius, float height)
261260
{
262-
colShapePool.Create(AltNative.Server.Server_CreateColShapeCylinder(NativePointer, pos, radius, height),
263-
out var colShape);
264-
return colShape;
261+
var ptr = AltNative.Server.Server_CreateColShapeCylinder(NativePointer, pos, radius, height);
262+
return colShapePool.Get(ptr, out var colShape) ? colShape : null;
265263
}
266264

267265
public IColShape CreateColShapeSphere(Position pos, float radius)
268266
{
269-
colShapePool.Create(AltNative.Server.Server_CreateColShapeSphere(NativePointer, pos, radius),
270-
out var colShape);
271-
return colShape;
267+
var ptr = AltNative.Server.Server_CreateColShapeSphere(NativePointer, pos, radius);
268+
return colShapePool.Get(ptr, out var colShape) ? colShape : null;
272269
}
273270

274271
public IColShape CreateColShapeCircle(Position pos, float radius)
275272
{
276-
colShapePool.Create(AltNative.Server.Server_CreateColShapeCircle(NativePointer, pos, radius),
277-
out var colShape);
278-
return colShape;
273+
var ptr = AltNative.Server.Server_CreateColShapeCircle(NativePointer, pos, radius);
274+
return colShapePool.Get(ptr, out var colShape) ? colShape : null;
279275
}
280276

281277
public IColShape CreateColShapeCube(Position pos, Position pos2)
282278
{
283-
colShapePool.Create(AltNative.Server.Server_CreateColShapeCube(NativePointer, pos, pos2), out var colShape);
284-
return colShape;
279+
var ptr = AltNative.Server.Server_CreateColShapeCube(NativePointer, pos, pos2);
280+
return colShapePool.Get(ptr, out var colShape) ? colShape : null;
285281
}
286282

287283
public IColShape CreateColShapeRectangle(Position pos, Position pos2)
288284
{
289-
colShapePool.Create(AltNative.Server.Server_CreateColShapeRectangle(NativePointer, pos, pos2),
290-
out var colShape);
291-
return colShape;
285+
var ptr = AltNative.Server.Server_CreateColShapeRectangle(NativePointer, pos, pos2);
286+
return colShapePool.Get(ptr, out var colShape) ? colShape : null;
292287
}
293288

294289
public void RemoveBlip(IBlip blip)

0 commit comments

Comments
 (0)