diff --git a/Reactor.OxygenFilter.MSBuild/AssemblyResolver.cs b/Reactor.OxygenFilter.MSBuild/AssemblyResolver.cs new file mode 100644 index 0000000..7e8adf2 --- /dev/null +++ b/Reactor.OxygenFilter.MSBuild/AssemblyResolver.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using Mono.Cecil; + +namespace Reactor.OxygenFilter.MSBuild +{ + public class AssemblyResolver : DefaultAssemblyResolver + { + protected override AssemblyDefinition SearchDirectory(AssemblyNameReference name, IEnumerable directories, ReaderParameters parameters) + { + if (name.Name == "netstandard") + return null; + + return base.SearchDirectory(name, directories, parameters); + } + } +} diff --git a/Reactor.OxygenFilter.MSBuild/Deobfuscate.cs b/Reactor.OxygenFilter.MSBuild/Deobfuscate.cs index e5cab7b..12c0e44 100644 --- a/Reactor.OxygenFilter.MSBuild/Deobfuscate.cs +++ b/Reactor.OxygenFilter.MSBuild/Deobfuscate.cs @@ -33,12 +33,21 @@ public override bool Execute() var mappings = JsonConvert.DeserializeObject(Context.MappingsJson); - var resolver = new DefaultAssemblyResolver(); + var resolver = new AssemblyResolver(); resolver.AddSearchDirectory(Path.Combine(Context.MappedPath, "references")); resolver.AddSearchDirectory(Path.Combine(AmongUs, "BepInEx", "core")); resolver.AddSearchDirectory(Path.Combine(AmongUs, "BepInEx", "plugins")); resolver.AddSearchDirectory(Path.Combine(AmongUs, "BepInEx", "unhollowed")); + var readerParameters = new ReaderParameters { AssemblyResolver = resolver }; + + // quick fix for reactor plugin having different file name than assembly name + resolver.ResolveFailure += (_, reference) => + { + var files = Directory.GetFiles(Path.Combine(AmongUs, "BepInEx", "plugins"), $"{reference.Name}-*.dll"); + return files.Length == 1 ? AssemblyDefinition.ReadAssembly(files.Single(), readerParameters) : null; + }; + var deobfuscated = new List(); foreach (var input in Input) @@ -58,7 +67,7 @@ public override bool Execute() using var stream = File.Open(input, FileMode.Open, FileAccess.Read, FileShare.Read); - using var moduleDefinition = ModuleDefinition.ReadModule(stream, new ReaderParameters { AssemblyResolver = resolver }); + using var moduleDefinition = ModuleDefinition.ReadModule(stream, readerParameters); var toDeobfuscate = new Dictionary(); foreach (var type in moduleDefinition.GetTypeReferences()) diff --git a/Reactor.OxygenFilter.MSBuild/Reactor.OxygenFilter.MSBuild.csproj b/Reactor.OxygenFilter.MSBuild/Reactor.OxygenFilter.MSBuild.csproj index 5b87c9b..050133b 100644 --- a/Reactor.OxygenFilter.MSBuild/Reactor.OxygenFilter.MSBuild.csproj +++ b/Reactor.OxygenFilter.MSBuild/Reactor.OxygenFilter.MSBuild.csproj @@ -4,7 +4,7 @@ latest true - 0.2.7 + 0.2.8 git https://github.com/NuclearPowered/Reactor.OxygenFilter LGPL-3.0-or-later diff --git a/Reactor.OxygenFilter.MSBuild/Reobfuscate.cs b/Reactor.OxygenFilter.MSBuild/Reobfuscate.cs index aa0fc74..9b97178 100644 --- a/Reactor.OxygenFilter.MSBuild/Reobfuscate.cs +++ b/Reactor.OxygenFilter.MSBuild/Reobfuscate.cs @@ -31,7 +31,7 @@ private static string GetObfuscated(ICustomAttributeProvider cap) public override bool Execute() { using var stream = File.Open(Input, FileMode.Open, FileAccess.ReadWrite); - var resolver = new DefaultAssemblyResolver(); + var resolver = new AssemblyResolver(); var obfuscatedAssembly = AssemblyDefinition.ReadAssembly(Path.Combine(AmongUs, "BepInEx", "unhollowed", "Assembly-CSharp.dll")); @@ -41,7 +41,7 @@ public override bool Execute() { foreach (var referencedAssembly in referencedAssemblies) { - if (referencedAssembly.Name.FullName == reference.FullName) + if (referencedAssembly.Name.Name == reference.Name) { return referencedAssembly; }