forked from FabianTerhorst/coreclr-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMValueConst.Locked.NoRefs.cs
More file actions
252 lines (233 loc) · 9.14 KB
/
MValueConst.Locked.NoRefs.cs
File metadata and controls
252 lines (233 loc) · 9.14 KB
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
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.Core.CreateMValueBaseObject(out mValue, player);
}
}
public static void CreateLocked(IVehicle vehicle, out MValueConst mValue)
{
lock (vehicle)
{
if (!vehicle.Exists)
{
mValue = MValueConst.Nil;
return;
}
Alt.Core.CreateMValueBaseObject(out mValue, vehicle);
}
}
public static void CreateLocked(IBlip blip, out MValueConst mValue)
{
lock (blip)
{
if (!blip.Exists)
{
mValue = MValueConst.Nil;
return;
}
Alt.Core.CreateMValueBaseObject(out mValue, blip);
}
}
public static void CreateLocked(ICheckpoint checkpoint, out MValueConst mValue)
{
lock (checkpoint)
{
if (!checkpoint.Exists)
{
mValue = MValueConst.Nil;
return;
}
Alt.Core.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 ICheckpoint checkpoint:
CreateLocked(checkpoint, out mValue);
return;
case bool value:
Alt.Core.CreateMValueBool(out mValue, value);
return;
case int value:
Alt.Core.CreateMValueInt(out mValue, value);
return;
case uint value:
Alt.Core.CreateMValueUInt(out mValue, value);
return;
case long value:
Alt.Core.CreateMValueInt(out mValue, value);
return;
case ulong value:
Alt.Core.CreateMValueUInt(out mValue, value);
return;
case double value:
Alt.Core.CreateMValueDouble(out mValue, value);
return;
case float value:
Alt.Core.CreateMValueDouble(out mValue, value);
return;
case string value:
Alt.Core.CreateMValueString(out mValue, value);
return;
case MValueConst value:
mValue = value;
return;
case MValueConst[] value:
Alt.Core.CreateMValueList(out mValue, value, (ulong) value.Length);
return;
case Invoker value:
Alt.Core.CreateMValueFunction(out mValue, value.NativePointer);
return;
case MValueFunctionCallback value:
Alt.Core.CreateMValueFunction(out mValue, Alt.Core.Resource.CSharpResourceImpl.CreateInvoker(value));
return;
case Function function:
Alt.Core.CreateMValueFunction(out mValue,
Alt.Core.Resource.CSharpResourceImpl.CreateInvoker(function.Call));
return;
case byte[] byteArray:
Alt.Core.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)
{
Alt.Core.CreateMValue(out var elementMValue, value);
dictValues[i++] = elementMValue;
}
Alt.Core.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)
{
Alt.Core.CreateMValue(out var elementMValue, value);
listValues[i++] = elementMValue;
}
Alt.Core.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)
{
Alt.Core.CreateMValue(out var elementMValue, value);
dictValues[i++] = elementMValue;
}
Alt.Core.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.Core.CreateMValueVector3(out mValue, position);
return;
case Rotation rotation:
Alt.Core.CreateMValueVector3(out mValue, rotation);
return;
case Rgba rgba:
Alt.Core.CreateMValueRgba(out mValue, rgba);
return;
case short value:
Alt.Core.CreateMValueInt(out mValue, value);
return;
case ushort value:
Alt.Core.CreateMValueUInt(out mValue, value);
return;
case Vector3 position:
Alt.Core.CreateMValueVector3(out mValue, position);
return;
default:
Alt.Log("can't convert type:" + obj.GetType());
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;
}
}
}