Skip to content

Commit 843b404

Browse files
Cleanup mock pointer and mock id
1 parent 66f45c7 commit 843b404

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

api/AltV.Net.Mock/MockAltV.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public MockAltV(string entryPoint)
3838

3939
public IPlayer ConnectPlayer(string playerName, string reason, Action<IPlayer> intercept = null)
4040
{
41-
var ptr = MockEntities.GetNextPtr();
42-
Alt.Module.PlayerPool.Create(ptr, MockEntities.Id, out var player);
41+
var ptr = MockEntities.GetNextPtr(out var entityId);
42+
Alt.Module.PlayerPool.Create(ptr, entityId, out var player);
4343
player.Name = playerName;
4444
intercept?.Invoke(player);
4545
Alt.Module.OnPlayerConnect(ptr, player.Id, reason);

api/AltV.Net.Mock/MockEntities.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
using System;
2-
using System.Collections.Generic;
3-
using AltV.Net.Elements.Entities;
42

53
namespace AltV.Net.Mock
64
{
7-
public class MockEntities
5+
public static class MockEntities
86
{
9-
public static IntPtr Ptr = IntPtr.Zero;
7+
private static IntPtr _ptr = IntPtr.Zero;
108

11-
public static ushort Id = 0;
9+
private static ushort _id = 0;
1210

13-
public static IntPtr GetNextPtr()
11+
public static IntPtr GetNextPtr(out ushort id)
1412
{
15-
Ptr += 1;
16-
Id++;
17-
return Ptr;
13+
_ptr += 1;
14+
id = ++_id;
15+
return _ptr;
16+
}
17+
18+
public static IntPtr GetNextPtrNoId()
19+
{
20+
_ptr += 1;
21+
return _ptr;
1822
}
1923
}
2024
}

api/AltV.Net.Mock/MockServer.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,31 +183,31 @@ public void TriggerClientEvent(IPlayer player, IntPtr eventNamePtr, ref MValue a
183183

184184
public IVehicle CreateVehicle(uint model, Position pos, Rotation rotation)
185185
{
186-
var ptr = MockEntities.GetNextPtr();
187-
vehiclePool.Create(ptr, MockEntities.Id, out var vehicle);
186+
var ptr = MockEntities.GetNextPtr(out var entityId);
187+
vehiclePool.Create(ptr, entityId, out var vehicle);
188188
vehicle.Position = pos;
189189
if (vehicle is MockVehicle mockVehicle)
190190
{
191191
mockVehicle.Position = pos;
192192
mockVehicle.Rotation = rotation;
193193
mockVehicle.Model = model;
194194
}
195-
Alt.Module.OnCreateVehicle(ptr, MockEntities.Id);
195+
Alt.Module.OnCreateVehicle(ptr, entityId);
196196
return vehicle;
197197
}
198198

199199
public IntPtr CreateVehicleEntity(out ushort id, uint model, Position pos, Rotation rotation)
200200
{
201-
var ptr = MockEntities.GetNextPtr();
202-
id = MockEntities.Id;
203-
Alt.Module.OnCreateVehicle(ptr, id);
201+
var ptr = MockEntities.GetNextPtr(out var entityId);
202+
id = entityId;
203+
Alt.Module.OnCreateVehicle(ptr, entityId);
204204
return ptr;
205205
}
206206

207207
public ICheckpoint CreateCheckpoint(IPlayer player, byte type, Position pos, float radius, float height,
208208
Rgba color)
209209
{
210-
var ptr = MockEntities.GetNextPtr();
210+
var ptr = MockEntities.GetNextPtrNoId();
211211
checkpointPool.Create(ptr, out var checkpoint);
212212
if (checkpoint is MockCheckpoint mockCheckpoint)
213213
{
@@ -223,7 +223,7 @@ public ICheckpoint CreateCheckpoint(IPlayer player, byte type, Position pos, flo
223223

224224
public IBlip CreateBlip(IPlayer player, byte type, Position pos)
225225
{
226-
var ptr = MockEntities.GetNextPtr();
226+
var ptr = MockEntities.GetNextPtrNoId();
227227
blipPool.Create(ptr, out var blip);
228228
if (blip is MockBlip mockBlip)
229229
{
@@ -236,7 +236,7 @@ public IBlip CreateBlip(IPlayer player, byte type, Position pos)
236236

237237
public IBlip CreateBlip(IPlayer player, byte type, IEntity entityAttach)
238238
{
239-
var ptr = MockEntities.GetNextPtr();
239+
var ptr = MockEntities.GetNextPtrNoId();
240240
blipPool.Create(ptr, out var blip);
241241
if (blip is MockBlip mockBlip)
242242
{
@@ -250,7 +250,7 @@ public IBlip CreateBlip(IPlayer player, byte type, IEntity entityAttach)
250250

251251
public IVoiceChannel CreateVoiceChannel(bool spatial, float maxDistance)
252252
{
253-
var ptr = MockEntities.GetNextPtr();
253+
var ptr = MockEntities.GetNextPtrNoId();
254254
voiceChannelPool.Create(ptr, out var voiceChannel);
255255
if (voiceChannel is MockVoiceChannel mockVoiceChannel)
256256
{

0 commit comments

Comments
 (0)