forked from ScriptedEvents/ScriptedEventsReloaded
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSER.csproj
More file actions
266 lines (238 loc) · 10.7 KB
/
SER.csproj
File metadata and controls
266 lines (238 loc) · 10.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
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<RootNamespace>SER</RootNamespace>
<AssemblyName>SER</AssemblyName>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>preview</LangVersion>
<PlatformTarget>x64</PlatformTarget>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TRACE;HAVE_NULLABLE_ATTRIBUTES</DefineConstants>
<OutputPath>bin\Debug\</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE;HAVE_NULLABLE_ATTRIBUTES</DefineConstants>
<OutputPath>bin\Release\</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>$(SL_DEV_REFERENCES)\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>$(SL_DEV_REFERENCES)\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>$(SL_DEV_REFERENCES)\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="CommandSystem.Core">
<HintPath>$(SL_DEV_REFERENCES)\CommandSystem.Core.dll</HintPath>
<Private>true</Private>
</Reference>
<Reference Include="Mirror">
<HintPath>$(SL_DEV_REFERENCES)\Mirror.dll</HintPath>
</Reference>
<Reference Include="Pooling">
<HintPath>$(SL_DEV_REFERENCES)\Pooling.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(SL_DEV_REFERENCES)\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(SL_DEV_REFERENCES)\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>$(SL_DEV_REFERENCES)\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestModule">
<HintPath>$(SL_DEV_REFERENCES)\UnityEngine.UnityWebRequestModule.dll</HintPath>
</Reference>
</ItemGroup>
<!-- QoL moving the dll -->
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="$(TargetDir)SER.dll" DestinationFolder="$(LABAPI_PLUGINS)" />
<Copy SourceFiles="$(TargetDir)SER.dll" DestinationFolder="$(SL_DEV_REFERENCES)" />
</Target>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<Content Include=".gitignore" />
<Content Include="README.md" />
<None Include="THIRD_PARTY_LICENSES.txt" CopyToOutputDirectory="Always" />
</ItemGroup>
<!-- ignore warnings about mismatch between versions of core libs
and unreachable code because compiler is stupid -->
<PropertyGroup>
<NoWarn>$(NoWarn);MSB3277;CS0162</NoWarn>
</PropertyGroup>
<!-- nuget refs -->
<ItemGroup>
<PackageReference Include="AudioPlayerApi" Version="1.1.2" />
<PackageReference Include="ExMod.Exiled" Version="9.12.5" />
<PackageReference Include="NCalc" Version="1.3.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Northwood.LabAPI" Version="1.1.5" />
<PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Code\" />
<Folder Include="Code\MethodSystem\Methods\EXILED_custom_roleMethods\" />
</ItemGroup>
<!-- embedding dependencies into SER.dll -->
<Target Name="EmbedSelectedDependencies" AfterTargets="ResolveReferences">
<ItemGroup>
<EmbeddedResource Include="@(ReferenceCopyLocalPaths)"
Condition="'%(Extension)' == '.dll' and
(
'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'NCalc' or
'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'Newtonsoft.Json' or
'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'AudioPlayerApi' or
'%(Filename)' == 'NVorbis' or
'%(Filename)' == 'SharpCompress'
)" />
</ItemGroup>
</Target>
<!-- this checkes if the script examples are able to be compiled -->
<UsingTask TaskName="RunDllValidation" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<AssemblyPath ParameterType="System.String" Required="true" />
<ReferencePath ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Reflection" />
<Code Type="Fragment" Language="cs">
<![CDATA[
#nullable enable annotations
// 1. Resolver for SCP:SL Dependencies
ResolveEventHandler resolver = (sender, args) => {
try {
// Parse the requested assembly name
var nameObj = new AssemblyName(args.Name);
string fileName = nameObj.Name + ".dll";
// Look in the game references folder
string fullPath = Path.Combine(ReferencePath, fileName);
if (File.Exists(fullPath)) {
return Assembly.LoadFrom(fullPath);
}
}
catch (Exception e)
{
Log.LogError("Resolver Error: " + e.ToString());
}
return null;
};
try
{
AppDomain.CurrentDomain.AssemblyResolve += resolver;
if (!File.Exists(AssemblyPath)) {
Log.LogError("Target DLL not found: " + AssemblyPath);
return false;
}
// 3. Load the DLL
// LoadFrom allows dependencies to be resolved via the event handler
Assembly assembly = Assembly.LoadFrom(AssemblyPath);
{
// 4. Find the class (Namespace.ClassName)
Type? targetType = assembly.GetType("SER.Code.MethodSystem.MethodIndex");
if (targetType == null)
{
Log.LogError("Validation Error: Type 'SER.Code.MethodSystem.MethodIndex' not found.");
return false;
}
// 5. Find the method
MethodInfo? method = targetType.GetMethod(
"AddAllDefinedMethodsInAssembly",
BindingFlags.Public | BindingFlags.Static
);
if (method == null)
{
Log.LogError("Validation Error: Static method 'AddAllDefinedMethodsInAssembly()' not found.");
return false;
}
method.Invoke(null, new object[] { assembly });
Log.LogMessage(MessageImportance.High, ">>> Loaded methods.");
}
{
// 4. Find the class (Namespace.ClassName)
Type? targetType = assembly.GetType("SER.Code.Examples.Example");
if (targetType == null)
{
Log.LogError("Validation Error: Type 'SER.Code.Examples.Example' not found.");
return false;
}
// 5. Find the method
MethodInfo? method = targetType.GetMethod(
"Verify",
BindingFlags.Public | BindingFlags.Static
);
if (method == null)
{
Log.LogError("Validation Error: Static method 'Verify()' not found.");
return false;
}
Log.LogMessage(MessageImportance.High, ">>> Validating Scripts...");
// 6. Invoke
string result = (string)method.Invoke(null, null);
if (!string.IsNullOrEmpty(result))
{
Log.LogError("SCRIPT ERROR: " + result);
return false;
}
Log.LogMessage(MessageImportance.High, ">>> Validation Passed.");
return true;
}
}
catch (OperationCanceledException)
{
throw;
}
catch (ReflectionTypeLoadException re)
{
foreach (var loaderEx in re.LoaderExceptions)
{
Log.LogError("Loader Error: " + loaderEx.ToString());
}
return false;
}
catch (TargetInvocationException tie)
{
Log.LogError("Invocation Error: " +
(tie.InnerException != null ? tie.InnerException.ToString() : tie.ToString()));
return false;
}
catch (Exception ex)
{
Log.LogError("Task Error: " + ex.ToString());
return false;
}
finally {
// 7. Detach Resolver to keep build process clean
AppDomain.CurrentDomain.AssemblyResolve -= resolver;
}
#nullable disable annotations
]]>
</Code>
</Task>
</UsingTask>
<Target Name="RunValidation" AfterTargets="Build">
<RunDllValidation AssemblyPath="$(TargetPath)" ReferencePath="$(SL_DEV_REFERENCES)" />
</Target>
</Project>