From cf243359e3b0a607a74cbc2cf7c7eb268a46b945 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 17 Jul 2018 08:14:25 +0200 Subject: monogame-patcher: Fix assembly search directory By default the assemblies are searched in the current working directory, but when patching an assembly in some other directory than the current the patcher will fail to resolve assemblies residing beneath the target file. So we just add the directory of the target file to the search path. I also moved all of the assemblies in the test to be in a subdir so we can verify that this indeed works and we won't regress in the future. Signed-off-by: aszlig --- .../build-support/monogame-patcher/src/patcher.cs | 6 +++++- .../build-support/monogame-patcher/src/test.sh | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'pkgs/games/build-support') diff --git a/pkgs/games/build-support/monogame-patcher/src/patcher.cs b/pkgs/games/build-support/monogame-patcher/src/patcher.cs index b35e44d6..6aeaa324 100644 --- a/pkgs/games/build-support/monogame-patcher/src/patcher.cs +++ b/pkgs/games/build-support/monogame-patcher/src/patcher.cs @@ -21,8 +21,12 @@ class Command { this.outfile = options.outputFile; this.infile = options.inputFile; + var resolver = new DefaultAssemblyResolver(); + resolver.AddSearchDirectory(Path.GetDirectoryName(this.infile)); + var rp = new ReaderParameters { - ReadWrite = this.infile == this.outfile + ReadWrite = this.infile == this.outfile, + AssemblyResolver = resolver }; this.module = ModuleDefinition.ReadModule(this.infile, rp); } diff --git a/pkgs/games/build-support/monogame-patcher/src/test.sh b/pkgs/games/build-support/monogame-patcher/src/test.sh index 9c51cd7e..b19457d4 100644 --- a/pkgs/games/build-support/monogame-patcher/src/test.sh +++ b/pkgs/games/build-support/monogame-patcher/src/test.sh @@ -51,30 +51,31 @@ class test1 { } EOF -mcs a.cs -target:library -out:a.dll -mcs b.cs -target:library -out:b.dll +mkdir subdir +mcs a.cs -target:library -out:subdir/a.dll +mcs b.cs -target:library -out:subdir/b.dll -mcs test1.cs -r:a -r:b -out:test1.exe -mcs test2.cs -r:a -r:b -out:test2.exe +mcs test1.cs -r:subdir/a -r:subdir/b -out:subdir/test1.exe +mcs test2.cs -r:subdir/a -r:subdir/b -out:subdir/test2.exe -! "$out/bin/monogame-patcher" replace-call -i test1.exe \ +! "$out/bin/monogame-patcher" replace-call -i subdir/test1.exe \ "System.String a::replaceMe(System.String)" \ "System.String b::notfound(System.String)" \ test1 2> /dev/null -"$out/bin/monogame-patcher" replace-call -i test1.exe \ +"$out/bin/monogame-patcher" replace-call -i subdir/test1.exe \ "System.String a::replaceMe(System.String)" \ "System.String b::replacement(System.String)" \ test1 -test "$(mono test1.exe)" = "bar called: xxx" +test "$(mono subdir/test1.exe)" = "bar called: xxx" echo foo > write_test.txt -test "$(mono test2.exe)" = "can write" +test "$(mono subdir/test2.exe)" = "can write" -"$out/bin/monogame-patcher" fix-filestreams -i b.dll b +"$out/bin/monogame-patcher" fix-filestreams -i subdir/b.dll b -test "$(mono test2.exe)" = "can not write" +test "$(mono subdir/test2.exe)" = "can not write" "$out/bin/monogame-patcher" --help 2>&1 | grep -q fix-filestreams -- cgit 1.4.1