From 1094ee0be0dccf84dfe0fc8afae4b16286775670 Mon Sep 17 00:00:00 2001 From: aszlig Date: Wed, 18 Jul 2018 11:49:56 +0200 Subject: 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 --- pkgs/games/build-support/monogame-patcher/src/patcher.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'pkgs/games') 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) { -- cgit 1.4.1