about summary refs log tree commit diff
path: root/pkgs/games/build-support
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-07-18 11:49:56 +0200
committeraszlig <aszlig@nix.build>2018-07-19 06:35:27 +0200
commit1094ee0be0dccf84dfe0fc8afae4b16286775670 (patch)
treee304a78470aa97a8951ad4766739e76c61aeac06 /pkgs/games/build-support
parentec65da1fbc93bd4fcdbdf20cb41c085ece53473c (diff)
monogame-patcher: Raise exception on no-op
We really want to make sure that things were actually patched, so just
silently skipping everything is not an option.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/games/build-support')
-rw-r--r--pkgs/games/build-support/monogame-patcher/src/patcher.cs11
1 files changed, 10 insertions, 1 deletions
diff --git a/pkgs/games/build-support/monogame-patcher/src/patcher.cs b/pkgs/games/build-support/monogame-patcher/src/patcher.cs
index 961a6b7e..8e4f8ddd 100644
--- a/pkgs/games/build-support/monogame-patcher/src/patcher.cs
+++ b/pkgs/games/build-support/monogame-patcher/src/patcher.cs
@@ -108,6 +108,7 @@ class ReplaceCall : Command {
     private string search;
     private MethodReference replace;
     private ModuleDefinition targetModule;
+    private bool patch_done;
 
     public ReplaceCall(ReplaceCallCmd options) : base(options) {
         if (options.assemblyFile != null)
@@ -119,9 +120,15 @@ class ReplaceCall : Command {
         var filtered = this.module.Types
             .Where(p => options.typesToPatch.Contains(p.Name));
 
+        this.patch_done = false;
         foreach (var toPatch in filtered)
             patch_type(toPatch);
 
+        if (!this.patch_done) {
+            var types = string.Join(", ", options.typesToPatch);
+            throw new Exception($"Unable to find {this.search} in {types}.");
+        }
+
         this.save();
     }
 
@@ -139,8 +146,10 @@ class ReplaceCall : Command {
             .Where(i => i.OpCode == OpCodes.Call)
             .Where(i => i.Operand.ToString() == this.search);
 
-        foreach (Instruction i in found.ToList())
+        foreach (Instruction i in found.ToList()) {
             il.Replace(i, il.Create(OpCodes.Call, this.replace));
+            this.patch_done = true;
+        }
     }
 
     private void patch_type(TypeDefinition td) {