forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssemblyValidation.cs
More file actions
300 lines (270 loc) · 9.7 KB
/
AssemblyValidation.cs
File metadata and controls
300 lines (270 loc) · 9.7 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using UnityEngine;
internal class AssemblyValidation
{
private static Dictionary<RuntimePlatform, List<System.Type>> _rulesByPlatform;
[CompilerGenerated]
private static Func<IValidationRule, bool> <>f__am$cache0;
[CompilerGenerated]
private static Func<object, System.Type> <>f__am$cache1;
[CompilerGenerated]
private static Func<AssemblyValidationRule, int> <>f__am$cache2;
[CompilerGenerated]
private static Func<System.Type, bool> <>f__mg$cache0;
internal static int CompareValidationRulesByPriority(System.Type a, System.Type b, RuntimePlatform platform)
{
int num = PriorityFor(a, platform);
int num2 = PriorityFor(b, platform);
if (num == num2)
{
return 0;
}
return ((num >= num2) ? 1 : -1);
}
private static ConstructorInfo ConstructorFor(System.Type type, IEnumerable<object> options)
{
if (<>f__am$cache1 == null)
{
<>f__am$cache1 = o => o.GetType();
}
System.Type[] types = Enumerable.Select<object, System.Type>(options, <>f__am$cache1).ToArray<System.Type>();
return type.GetConstructor(types);
}
private static IValidationRule CreateValidationRuleWithOptions(System.Type type, params object[] options)
{
List<object> list = new List<object>(options);
while (true)
{
object[] objArray = list.ToArray();
ConstructorInfo info = ConstructorFor(type, objArray);
if (info != null)
{
return (IValidationRule) info.Invoke(objArray);
}
if (list.Count == 0)
{
return null;
}
list.RemoveAt(list.Count - 1);
}
}
private static bool IsValidationRule(System.Type type) =>
ValidationRuleAttributesFor(type).Any<AssemblyValidationRule>();
private static int PriorityFor(System.Type type, RuntimePlatform platform)
{
<PriorityFor>c__AnonStorey3 storey = new <PriorityFor>c__AnonStorey3 {
platform = platform
};
if (<>f__am$cache2 == null)
{
<>f__am$cache2 = attr => attr.Priority;
}
return Enumerable.Select<AssemblyValidationRule, int>(Enumerable.Where<AssemblyValidationRule>(ValidationRuleAttributesFor(type), new Func<AssemblyValidationRule, bool>(storey.<>m__0)), <>f__am$cache2).FirstOrDefault<int>();
}
internal static void RegisterValidationRule(System.Type type)
{
foreach (AssemblyValidationRule rule in ValidationRuleAttributesFor(type))
{
RegisterValidationRuleForPlatform(rule.Platform, type);
}
}
internal static void RegisterValidationRuleForPlatform(RuntimePlatform platform, System.Type type)
{
<RegisterValidationRuleForPlatform>c__AnonStorey2 storey = new <RegisterValidationRuleForPlatform>c__AnonStorey2 {
platform = platform
};
if (!_rulesByPlatform.ContainsKey(storey.platform))
{
_rulesByPlatform[storey.platform] = new List<System.Type>();
}
if (_rulesByPlatform[storey.platform].IndexOf(type) == -1)
{
_rulesByPlatform[storey.platform].Add(type);
}
_rulesByPlatform[storey.platform].Sort(new Comparison<System.Type>(storey.<>m__0));
}
public static ValidationResult Validate(RuntimePlatform platform, IEnumerable<string> userAssemblies, params object[] options)
{
string[] strArray;
WarmUpRulesCache();
string[] textArray1 = userAssemblies as string[];
if (textArray1 != null)
{
strArray = textArray1;
}
else
{
strArray = userAssemblies.ToArray<string>();
}
if (strArray.Length != 0)
{
foreach (IValidationRule rule in ValidationRulesFor(platform, options))
{
ValidationResult result = rule.Validate(strArray, options);
if (!result.Success)
{
return result;
}
}
}
return new ValidationResult { Success = true };
}
private static IEnumerable<AssemblyValidationRule> ValidationRuleAttributesFor(System.Type type) =>
type.GetCustomAttributes(true).OfType<AssemblyValidationRule>();
private static IEnumerable<IValidationRule> ValidationRulesFor(RuntimePlatform platform, params object[] options)
{
<ValidationRulesFor>c__AnonStorey1 storey = new <ValidationRulesFor>c__AnonStorey1 {
options = options
};
if (<>f__am$cache0 == null)
{
<>f__am$cache0 = v => v != null;
}
return Enumerable.Where<IValidationRule>(Enumerable.Select<System.Type, IValidationRule>(ValidationRuleTypesFor(platform), new Func<System.Type, IValidationRule>(storey.<>m__0)), <>f__am$cache0);
}
[DebuggerHidden]
private static IEnumerable<System.Type> ValidationRuleTypesFor(RuntimePlatform platform) =>
new <ValidationRuleTypesFor>c__Iterator0 {
platform = platform,
$PC = -2
};
private static void WarmUpRulesCache()
{
if (_rulesByPlatform == null)
{
_rulesByPlatform = new Dictionary<RuntimePlatform, List<System.Type>>();
Assembly assembly = typeof(AssemblyValidation).Assembly;
if (<>f__mg$cache0 == null)
{
<>f__mg$cache0 = new Func<System.Type, bool>(AssemblyValidation.IsValidationRule);
}
foreach (System.Type type in Enumerable.Where<System.Type>(assembly.GetTypes(), <>f__mg$cache0))
{
RegisterValidationRule(type);
}
}
}
[CompilerGenerated]
private sealed class <PriorityFor>c__AnonStorey3
{
internal RuntimePlatform platform;
internal bool <>m__0(AssemblyValidationRule attr) =>
(attr.Platform == this.platform);
}
[CompilerGenerated]
private sealed class <RegisterValidationRuleForPlatform>c__AnonStorey2
{
internal RuntimePlatform platform;
internal int <>m__0(System.Type a, System.Type b) =>
AssemblyValidation.CompareValidationRulesByPriority(a, b, this.platform);
}
[CompilerGenerated]
private sealed class <ValidationRulesFor>c__AnonStorey1
{
internal object[] options;
internal IValidationRule <>m__0(System.Type t) =>
AssemblyValidation.CreateValidationRuleWithOptions(t, this.options);
}
[CompilerGenerated]
private sealed class <ValidationRuleTypesFor>c__Iterator0 : IEnumerable, IEnumerable<System.Type>, IEnumerator, IDisposable, IEnumerator<System.Type>
{
internal System.Type $current;
internal bool $disposing;
internal List<System.Type>.Enumerator $locvar0;
internal int $PC;
internal System.Type <validationType>__0;
internal RuntimePlatform platform;
[DebuggerHidden]
public void Dispose()
{
uint num = (uint) this.$PC;
this.$disposing = true;
this.$PC = -1;
switch (num)
{
case 1:
try
{
}
finally
{
this.$locvar0.Dispose();
}
break;
}
}
public bool MoveNext()
{
uint num = (uint) this.$PC;
this.$PC = -1;
bool flag = false;
switch (num)
{
case 0:
if (AssemblyValidation._rulesByPlatform.ContainsKey(this.platform))
{
this.$locvar0 = AssemblyValidation._rulesByPlatform[this.platform].GetEnumerator();
num = 0xfffffffd;
break;
}
goto Label_00D3;
case 1:
break;
default:
goto Label_00D3;
}
try
{
while (this.$locvar0.MoveNext())
{
this.<validationType>__0 = this.$locvar0.Current;
this.$current = this.<validationType>__0;
if (!this.$disposing)
{
this.$PC = 1;
}
flag = true;
return true;
}
}
finally
{
if (!flag)
{
}
this.$locvar0.Dispose();
}
this.$PC = -1;
Label_00D3:
return false;
}
[DebuggerHidden]
public void Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<System.Type> IEnumerable<System.Type>.GetEnumerator()
{
if (Interlocked.CompareExchange(ref this.$PC, 0, -2) == -2)
{
return this;
}
return new AssemblyValidation.<ValidationRuleTypesFor>c__Iterator0 { platform = this.platform };
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator() =>
this.System.Collections.Generic.IEnumerable<System.Type>.GetEnumerator();
System.Type IEnumerator<System.Type>.Current =>
this.$current;
object IEnumerator.Current =>
this.$current;
}
}