Skip to content

Commit c64eb86

Browse files
Merge pull request #22 from Lordfirespeed/main
Move netcode patched attribute to the mainmodule
2 parents 08b21f2 + 795cb8b commit c64eb86

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

NetcodePatcher.MSBuild/NetcodePatcher.MSBuild.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<NoPackageAnalysis>true</NoPackageAnalysis>
1313
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1414
</PropertyGroup>
15-
15+
1616
<!-- Development dependencies -->
1717
<ItemGroup>
18-
18+
1919
</ItemGroup>
2020

2121
<!-- Runtime dependencies -->
@@ -51,8 +51,9 @@
5151
<TaskDependencies Include="bin\$(Configuration)\*\UnityEngine.CoreModule.dll"/>
5252
<TaskDependencies Include="bin\$(Configuration)\*\SeriLog*.dll"/>
5353
<TaskDependencies Include="bin\$(Configuration)\*\System.Diagnostics*.dll"/>
54+
<TaskDependencies Include="bin\$(Configuration)\*\Microsoft.DiaSymReader*.dll"/>
5455
</ItemGroup>
55-
56+
5657
<ItemGroup>
5758
<_PackageFiles Include="@(TaskDependencies)">
5859
<PackagePath>lib/</PackagePath>
@@ -61,4 +62,4 @@
6162
</_PackageFiles>
6263
</ItemGroup>
6364
</Target>
64-
</Project>
65+
</Project>

NetcodePatcher/CodeGen/ApplyPatchedAttributeILPP.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,17 @@ public override bool WillProcess(ICompiledAssembly compiledAssembly)
6262
)
6363
);
6464
attr_AttributeUsage.ConstructorArguments.Add(
65-
new CustomAttributeArgument(assemblyDefinition.MainModule.ImportReference(typeof(AttributeTargets)), 1)
65+
new CustomAttributeArgument(assemblyDefinition.MainModule.ImportReference(typeof(AttributeTargets)), 2)
6666
);
6767
cls_NetcodePatchedAttribute.CustomAttributes.Add(attr_AttributeUsage);
6868

6969
// Method : NetcodePatchedAttribute.ctor
7070
var ctor_NetcodePatchedAttribute = new MethodDefinition(
7171
".ctor",
72-
MethodAttributes.Assembly | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName |
73-
MethodAttributes.HideBySig, assemblyDefinition.MainModule.TypeSystem.Void
72+
MethodAttributes.Public | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName | MethodAttributes.HideBySig,
73+
assemblyDefinition.MainModule.TypeSystem.Void
7474
);
7575
cls_NetcodePatchedAttribute.Methods.Add(ctor_NetcodePatchedAttribute);
76-
ctor_NetcodePatchedAttribute.Body.InitLocals = true;
7776
var il_ctor_NetcodePatchedAttribute = ctor_NetcodePatchedAttribute.Body.GetILProcessor();
7877
il_ctor_NetcodePatchedAttribute.Emit(OpCodes.Ldarg_0);
7978
il_ctor_NetcodePatchedAttribute.Emit(
@@ -88,7 +87,7 @@ public override bool WillProcess(ICompiledAssembly compiledAssembly)
8887
var attribute = new CustomAttribute(
8988
assemblyDefinition.MainModule.ImportReference(TypeHelpers.DefaultCtorFor(cls_NetcodePatchedAttribute))
9089
);
91-
assemblyDefinition.CustomAttributes.Add(attribute);
90+
assemblyDefinition.MainModule.CustomAttributes.Add(attribute);
9291

9392
// write
9493
var pe = new MemoryStream();

NetcodePatcher/CodeGen/NetcodeILPPApplicator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static bool HasNetcodePatchedAttribute(ICompiledAssembly assembly)
3636
var assemblyDefinition = CodeGenHelpers.AssemblyDefinitionFor(assembly, out _);
3737
if (assemblyDefinition is null) return false;
3838

39-
return assemblyDefinition.CustomAttributes.Any(
39+
return assemblyDefinition.MainModule.CustomAttributes.Any(
4040
attribute => attribute.Constructor.DeclaringType.FullName.EndsWith(
4141
$".{ApplyPatchedAttributeILPP.AttributeNamespaceSuffix}.{ApplyPatchedAttributeILPP.AttributeName}")
4242
);

0 commit comments

Comments
 (0)