Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EventParameterInfo.cs
Go to the documentation of this file.
2
3internal struct EventParameterInfo
4{
5 internal string ParameterName;
6
8
10
11 internal void SetInfo(string name, Type type, TraceLoggingTypeInfo typeInfo = null)
12 {
13 ParameterName = name;
15 TypeInfo = typeInfo;
16 }
17
18 internal unsafe bool GenerateMetadata(byte* pMetadataBlob, ref uint offset, uint blobSize)
19 {
20 TypeCode typeCodeExtended = GetTypeCodeExtended(ParameterType);
21 if (typeCodeExtended == TypeCode.Object)
22 {
23 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, 1u);
24 if (!(TypeInfo is InvokeTypeInfo { properties: var properties }))
25 {
26 return false;
27 }
28 if (properties != null)
29 {
30 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)properties.Length);
31 PropertyAnalysis[] array = properties;
32 foreach (PropertyAnalysis property in array)
33 {
34 if (!GenerateMetadataForProperty(property, pMetadataBlob, ref offset, blobSize))
35 {
36 return false;
37 }
38 }
39 }
40 else
41 {
42 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, 0u);
43 }
44 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, '\0');
45 }
46 else
47 {
48 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)typeCodeExtended);
49 fixed (char* src = ParameterName)
50 {
51 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (byte*)src, (uint)((ParameterName.Length + 1) * 2));
52 }
53 }
54 return true;
55 }
56
57 private unsafe static bool GenerateMetadataForProperty(PropertyAnalysis property, byte* pMetadataBlob, ref uint offset, uint blobSize)
58 {
59 if (property.typeInfo is InvokeTypeInfo invokeTypeInfo)
60 {
61 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, 1u);
62 PropertyAnalysis[] properties = invokeTypeInfo.properties;
63 if (properties != null)
64 {
65 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)properties.Length);
66 PropertyAnalysis[] array = properties;
67 foreach (PropertyAnalysis property2 in array)
68 {
69 if (!GenerateMetadataForProperty(property2, pMetadataBlob, ref offset, blobSize))
70 {
71 return false;
72 }
73 }
74 }
75 else
76 {
77 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, 0u);
78 }
79 fixed (char* src = property.name)
80 {
81 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (byte*)src, (uint)((property.name.Length + 1) * 2));
82 }
83 }
84 else
85 {
86 TypeCode typeCodeExtended = GetTypeCodeExtended(property.typeInfo.DataType);
87 if (typeCodeExtended == TypeCode.Object)
88 {
89 return false;
90 }
91 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)typeCodeExtended);
92 fixed (char* src2 = property.name)
93 {
94 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (byte*)src2, (uint)((property.name.Length + 1) * 2));
95 }
96 }
97 return true;
98 }
99
100 internal unsafe bool GenerateMetadataV2(byte* pMetadataBlob, ref uint offset, uint blobSize)
101 {
102 if (TypeInfo == null)
103 {
104 return false;
105 }
106 return GenerateMetadataForNamedTypeV2(ParameterName, TypeInfo, pMetadataBlob, ref offset, blobSize);
107 }
108
109 private unsafe static bool GenerateMetadataForNamedTypeV2(string name, TraceLoggingTypeInfo typeInfo, byte* pMetadataBlob, ref uint offset, uint blobSize)
110 {
111 if (!GetMetadataLengthForNamedTypeV2(name, typeInfo, out var size))
112 {
113 return false;
114 }
115 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, size);
116 fixed (char* src = name)
117 {
118 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (byte*)src, (uint)((name.Length + 1) * 2));
119 }
120 return GenerateMetadataForTypeV2(typeInfo, pMetadataBlob, ref offset, blobSize);
121 }
122
123 private unsafe static bool GenerateMetadataForTypeV2(TraceLoggingTypeInfo typeInfo, byte* pMetadataBlob, ref uint offset, uint blobSize)
124 {
125 if (typeInfo is InvokeTypeInfo invokeTypeInfo)
126 {
127 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, 1u);
128 PropertyAnalysis[] properties = invokeTypeInfo.properties;
129 if (properties != null)
130 {
131 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)properties.Length);
132 PropertyAnalysis[] array = properties;
133 foreach (PropertyAnalysis propertyAnalysis in array)
134 {
135 if (!GenerateMetadataForNamedTypeV2(propertyAnalysis.name, propertyAnalysis.typeInfo, pMetadataBlob, ref offset, blobSize))
136 {
137 return false;
138 }
139 }
140 }
141 else
142 {
143 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, 0u);
144 }
145 }
146 else if (typeInfo is EnumerableTypeInfo enumerableTypeInfo)
147 {
148 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, 19);
149 GenerateMetadataForTypeV2(enumerableTypeInfo.ElementInfo, pMetadataBlob, ref offset, blobSize);
150 }
151 else if (typeInfo is ScalarArrayTypeInfo scalarArrayTypeInfo)
152 {
153 if (!scalarArrayTypeInfo.DataType.HasElementType)
154 {
155 return false;
156 }
157 if (!GetTypeInfoFromType(scalarArrayTypeInfo.DataType.GetElementType(), out var typeInfo2))
158 {
159 return false;
160 }
161 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, 19);
162 GenerateMetadataForTypeV2(typeInfo2, pMetadataBlob, ref offset, blobSize);
163 }
164 else
165 {
166 TypeCode typeCodeExtended = GetTypeCodeExtended(typeInfo.DataType);
167 if (typeCodeExtended == TypeCode.Object)
168 {
169 return false;
170 }
171 EventPipeMetadataGenerator.WriteToBuffer(pMetadataBlob, blobSize, ref offset, (uint)typeCodeExtended);
172 }
173 return true;
174 }
175
176 internal static bool GetTypeInfoFromType(Type type, out TraceLoggingTypeInfo typeInfo)
177 {
178 if (type == typeof(bool))
179 {
180 typeInfo = ScalarTypeInfo.Boolean();
181 return true;
182 }
183 if (type == typeof(byte))
184 {
185 typeInfo = ScalarTypeInfo.Byte();
186 return true;
187 }
188 if (type == typeof(sbyte))
189 {
190 typeInfo = ScalarTypeInfo.SByte();
191 return true;
192 }
193 if (type == typeof(char))
194 {
195 typeInfo = ScalarTypeInfo.Char();
196 return true;
197 }
198 if (type == typeof(short))
199 {
200 typeInfo = ScalarTypeInfo.Int16();
201 return true;
202 }
203 if (type == typeof(ushort))
204 {
205 typeInfo = ScalarTypeInfo.UInt16();
206 return true;
207 }
208 if (type == typeof(int))
209 {
210 typeInfo = ScalarTypeInfo.Int32();
211 return true;
212 }
213 if (type == typeof(uint))
214 {
215 typeInfo = ScalarTypeInfo.UInt32();
216 return true;
217 }
218 if (type == typeof(long))
219 {
220 typeInfo = ScalarTypeInfo.Int64();
221 return true;
222 }
223 if (type == typeof(ulong))
224 {
225 typeInfo = ScalarTypeInfo.UInt64();
226 return true;
227 }
228 if (type == typeof(IntPtr))
229 {
230 typeInfo = ScalarTypeInfo.IntPtr();
231 return true;
232 }
233 if (type == typeof(UIntPtr))
234 {
235 typeInfo = ScalarTypeInfo.UIntPtr();
236 return true;
237 }
238 if (type == typeof(float))
239 {
240 typeInfo = ScalarTypeInfo.Single();
241 return true;
242 }
243 if (type == typeof(double))
244 {
245 typeInfo = ScalarTypeInfo.Double();
246 return true;
247 }
248 if (type == typeof(Guid))
249 {
250 typeInfo = ScalarTypeInfo.Guid();
251 return true;
252 }
253 typeInfo = null;
254 return false;
255 }
256
257 internal bool GetMetadataLength(out uint size)
258 {
259 size = 0u;
260 TypeCode typeCodeExtended = GetTypeCodeExtended(ParameterType);
261 if (typeCodeExtended == TypeCode.Object)
262 {
263 if (!(TypeInfo is InvokeTypeInfo invokeTypeInfo))
264 {
265 return false;
266 }
267 size += 8u;
268 PropertyAnalysis[] properties = invokeTypeInfo.properties;
269 if (properties != null)
270 {
271 PropertyAnalysis[] array = properties;
272 foreach (PropertyAnalysis property in array)
273 {
274 size += GetMetadataLengthForProperty(property);
275 }
276 }
277 size += 2u;
278 }
279 else
280 {
281 size += (uint)(4 + (ParameterName.Length + 1) * 2);
282 }
283 return true;
284 }
285
286 private static uint GetMetadataLengthForProperty(PropertyAnalysis property)
287 {
288 uint num = 0u;
289 if (property.typeInfo is InvokeTypeInfo invokeTypeInfo)
290 {
291 num += 8;
292 PropertyAnalysis[] properties = invokeTypeInfo.properties;
293 if (properties != null)
294 {
295 PropertyAnalysis[] array = properties;
296 foreach (PropertyAnalysis property2 in array)
297 {
298 num += GetMetadataLengthForProperty(property2);
299 }
300 }
301 return num + (uint)((property.name.Length + 1) * 2);
302 }
303 return num + (uint)(4 + (property.name.Length + 1) * 2);
304 }
305
306 private static TypeCode GetTypeCodeExtended(Type parameterType)
307 {
308 if (parameterType == typeof(Guid))
309 {
310 return (TypeCode)17;
311 }
312 if (parameterType == typeof(IntPtr))
313 {
314 _ = IntPtr.Size;
315 return TypeCode.Int64;
316 }
317 if (parameterType == typeof(UIntPtr))
318 {
319 _ = UIntPtr.Size;
320 return TypeCode.UInt64;
321 }
322 return Type.GetTypeCode(parameterType);
323 }
324
325 internal bool GetMetadataLengthV2(out uint size)
326 {
328 }
329
330 private static bool GetMetadataLengthForTypeV2(TraceLoggingTypeInfo typeInfo, out uint size)
331 {
332 size = 0u;
333 if (typeInfo == null)
334 {
335 return false;
336 }
337 if (typeInfo is InvokeTypeInfo invokeTypeInfo)
338 {
339 size += 8u;
340 PropertyAnalysis[] properties = invokeTypeInfo.properties;
341 if (properties != null)
342 {
343 PropertyAnalysis[] array = properties;
344 foreach (PropertyAnalysis propertyAnalysis in array)
345 {
346 if (!GetMetadataLengthForNamedTypeV2(propertyAnalysis.name, propertyAnalysis.typeInfo, out var size2))
347 {
348 return false;
349 }
350 size += size2;
351 }
352 }
353 }
354 else if (typeInfo is EnumerableTypeInfo enumerableTypeInfo)
355 {
356 size += 4u;
357 if (!GetMetadataLengthForTypeV2(enumerableTypeInfo.ElementInfo, out var size3))
358 {
359 return false;
360 }
361 size += size3;
362 }
363 else if (typeInfo is ScalarArrayTypeInfo scalarArrayTypeInfo)
364 {
365 if (!scalarArrayTypeInfo.DataType.HasElementType || !GetTypeInfoFromType(scalarArrayTypeInfo.DataType.GetElementType(), out var typeInfo2))
366 {
367 return false;
368 }
369 size += 4u;
370 if (!GetMetadataLengthForTypeV2(typeInfo2, out var size4))
371 {
372 return false;
373 }
374 size += size4;
375 }
376 else
377 {
378 size += 4u;
379 }
380 return true;
381 }
382
383 private static bool GetMetadataLengthForNamedTypeV2(string name, TraceLoggingTypeInfo typeInfo, out uint size)
384 {
385 size = (uint)(4 + (name.Length + 1) * 2);
386 if (!GetMetadataLengthForTypeV2(typeInfo, out var size2))
387 {
388 return false;
389 }
390 size += size2;
391 return true;
392 }
393}
static unsafe void WriteToBuffer(byte *buffer, uint bufferLength, ref uint offset, byte *src, uint srcLength)
static TraceLoggingTypeInfo UInt32()
static TraceLoggingTypeInfo Char()
static TraceLoggingTypeInfo Int32()
static TraceLoggingTypeInfo Guid()
static TraceLoggingTypeInfo Single()
static TraceLoggingTypeInfo UInt64()
static TraceLoggingTypeInfo UInt16()
static TraceLoggingTypeInfo UIntPtr()
static TraceLoggingTypeInfo SByte()
static TraceLoggingTypeInfo Boolean()
static TraceLoggingTypeInfo Int64()
static TraceLoggingTypeInfo Int16()
static TraceLoggingTypeInfo Byte()
static TraceLoggingTypeInfo Double()
static TraceLoggingTypeInfo IntPtr()
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
TypeCode
Definition TypeCode.cs:4
void SetInfo(string name, Type type, TraceLoggingTypeInfo typeInfo=null)
static uint GetMetadataLengthForProperty(PropertyAnalysis property)
static unsafe bool GenerateMetadataForProperty(PropertyAnalysis property, byte *pMetadataBlob, ref uint offset, uint blobSize)
static TypeCode GetTypeCodeExtended(Type parameterType)
static unsafe bool GenerateMetadataForNamedTypeV2(string name, TraceLoggingTypeInfo typeInfo, byte *pMetadataBlob, ref uint offset, uint blobSize)
static bool GetMetadataLengthForTypeV2(TraceLoggingTypeInfo typeInfo, out uint size)
static unsafe bool GenerateMetadataForTypeV2(TraceLoggingTypeInfo typeInfo, byte *pMetadataBlob, ref uint offset, uint blobSize)
static bool GetTypeInfoFromType(Type type, out TraceLoggingTypeInfo typeInfo)
unsafe bool GenerateMetadata(byte *pMetadataBlob, ref uint offset, uint blobSize)
unsafe bool GenerateMetadataV2(byte *pMetadataBlob, ref uint offset, uint blobSize)
static bool GetMetadataLengthForNamedTypeV2(string name, TraceLoggingTypeInfo typeInfo, out uint size)
static int Size
Definition IntPtr.cs:21
static int Size
Definition UIntPtr.cs:22