-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
MValueConst.Locked.NoRefs.cs
276 lines (254 loc) · 9.91 KB
/
MValueConst.Locked.NoRefs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using AltV.Net.Data;
using AltV.Net.Elements.Args;
using AltV.Net.Elements.Entities;
using AltV.Net.Native;
namespace AltV.Net.Async;
public static class MValueConstLockedNoRefs
{
public static void CreateLocked(IPlayer player, out MValueConst mValue)
{
lock (player)
{
if (!player.Exists)
{
mValue = MValueConst.Nil;
return;
}
Alt.CoreImpl.CreateMValueBaseObject(out mValue, player);
}
}
public static void CreateLocked(IVehicle vehicle, out MValueConst mValue)
{
lock (vehicle)
{
if (!vehicle.Exists)
{
mValue = MValueConst.Nil;
return;
}
Alt.CoreImpl.CreateMValueBaseObject(out mValue, vehicle);
}
}
public static void CreateLocked(IBlip blip, out MValueConst mValue)
{
lock (blip)
{
if (!blip.Exists)
{
mValue = MValueConst.Nil;
return;
}
Alt.CoreImpl.CreateMValueBaseObject(out mValue, blip);
}
}
public static void CreateLocked(IPed ped, out MValueConst mValue)
{
lock (ped)
{
if (!ped.Exists)
{
mValue = MValueConst.Nil;
return;
}
Alt.CoreImpl.CreateMValueBaseObject(out mValue, ped);
}
}
public static void CreateLocked(ICheckpoint checkpoint, out MValueConst mValue)
{
lock (checkpoint)
{
if (!checkpoint.Exists)
{
mValue = MValueConst.Nil;
return;
}
Alt.CoreImpl.CreateMValueBaseObject(out mValue, checkpoint);
}
}
public static void CreateFromObjectLocked(object obj, out MValueConst mValue)
{
if (obj == null)
{
mValue = MValueConst.Nil;
return;
}
int i;
string[] dictKeys;
MValueConst[] dictValues;
MValueWriter2 writer;
switch (obj)
{
case IPlayer player:
CreateLocked(player, out mValue);
return;
case IVehicle vehicle:
CreateLocked(vehicle, out mValue);
return;
case IBlip blip:
CreateLocked(blip, out mValue);
return;
case IPed ped:
CreateLocked(ped, out mValue);
return;
case ICheckpoint checkpoint:
CreateLocked(checkpoint, out mValue);
return;
case bool value:
Alt.CoreImpl.CreateMValueBool(out mValue, value);
return;
case int value:
Alt.CoreImpl.CreateMValueInt(out mValue, value);
return;
case uint value:
Alt.CoreImpl.CreateMValueUInt(out mValue, value);
return;
case long value:
Alt.CoreImpl.CreateMValueInt(out mValue, value);
return;
case ulong value:
Alt.CoreImpl.CreateMValueUInt(out mValue, value);
return;
case double value:
Alt.CoreImpl.CreateMValueDouble(out mValue, value);
return;
case float value:
Alt.CoreImpl.CreateMValueDouble(out mValue, value);
return;
case string value:
Alt.CoreImpl.CreateMValueString(out mValue, value);
return;
case MValueConst value:
mValue = value;
return;
case MValueConst[] value:
Alt.CoreImpl.CreateMValueList(out mValue, value, (ulong) value.Length);
return;
case Invoker value:
Alt.CoreImpl.CreateMValueFunction(out mValue, value.NativePointer);
return;
case MValueFunctionCallback value:
Alt.CoreImpl.CreateMValueFunction(out mValue, Alt.CoreImpl.Resource.CSharpResourceImpl.CreateInvoker(value));
return;
case Function function:
Alt.CoreImpl.CreateMValueFunction(out mValue,
Alt.CoreImpl.Resource.CSharpResourceImpl.CreateInvoker(function.Call));
return;
case byte[] byteArray:
Alt.CoreImpl.CreateMValueByteArray(out mValue, byteArray);
break;
case IDictionary dictionary:
dictKeys = new string[dictionary.Count];
dictValues = new MValueConst[dictionary.Count];
i = 0;
foreach (var key in dictionary.Keys)
{
if (key is string stringKey)
{
dictKeys[i++] = stringKey;
}
else
{
mValue = MValueConst.Nil;
return;
}
}
i = 0;
foreach (var value in dictionary.Values)
{
CreateFromObjectLocked(value, out var elementMValue);
dictValues[i++] = elementMValue;
}
Alt.CoreImpl.CreateMValueDict(out mValue, dictKeys, dictValues, (ulong) dictionary.Count);
for (int j = 0, dictLength = dictionary.Count; j < dictLength; j++)
{
dictValues[j].Dispose();
}
return;
case ICollection collection:
var length = (ulong) collection.Count;
var listValues = new MValueConst[length];
i = 0;
foreach (var value in collection)
{
CreateFromObjectLocked(value, out var elementMValue);
listValues[i++] = elementMValue;
}
Alt.CoreImpl.CreateMValueList(out mValue, listValues, length);
for (ulong j = 0; j < length; j++)
{
listValues[j].Dispose();
}
return;
case IDictionary<string, object> dictionary:
dictKeys = new string[dictionary.Count];
dictValues = new MValueConst[dictionary.Count];
i = 0;
foreach (var key in dictionary.Keys)
{
dictKeys[i++] = key;
}
i = 0;
foreach (var value in dictionary.Values)
{
CreateFromObjectLocked(value, out var elementMValue);
dictValues[i++] = elementMValue;
}
Alt.CoreImpl.CreateMValueDict(out mValue, dictKeys, dictValues, (ulong) dictionary.Count);
for (int j = 0, dictLength = dictValues.Length; j < dictLength; j++)
{
dictValues[j].Dispose();
}
return;
case IWritable writable:
writer = Alt.CreateMValueWriter();
writable.OnWrite(writer);
writer.ToMValue(out mValue);
return;
case IMValueConvertible convertible:
writer = Alt.CreateMValueWriter();
convertible.GetAdapter().ToMValue(obj, writer);
writer.ToMValue(out mValue);
return;
case Position position:
Alt.CoreImpl.CreateMValueVector3(out mValue, position);
return;
case Rotation rotation:
Alt.CoreImpl.CreateMValueVector3(out mValue, rotation);
return;
case Rgba rgba:
Alt.CoreImpl.CreateMValueRgba(out mValue, rgba);
return;
case short value:
Alt.CoreImpl.CreateMValueInt(out mValue, value);
return;
case ushort value:
Alt.CoreImpl.CreateMValueUInt(out mValue, value);
return;
case Vector3 position:
Alt.CoreImpl.CreateMValueVector3(out mValue, position);
return;
default:
var type = obj?.GetType();
if (type != null && Alt.IsMValueConvertible(obj.GetType()))
{
Alt.ToMValue(obj, type, out mValue);
return;
}
Alt.LogInfo("can't convert type:" + type);
mValue = MValueConst.Nil;
return;
}
}
internal static void CreateFromObjectsLocked(object[] objects, MValueConst[] mValues)
{
var length = objects.Length;
for (var i = 0; i < length; i++)
{
CreateFromObjectLocked(objects[i], out var mValueElement);
mValues[i] = mValueElement;
}
}
}