From 4fdd111da650ca43ff268f74b9ce82b22c00f611 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sun, 2 Sep 2018 02:15:15 -0500 Subject: [PATCH] Updated patcher to optionally update reference instead of replacing it and hoping for the best (which wasn't working) Fix for #2 --- IPA/Patcher/Patcher.cs | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/IPA/Patcher/Patcher.cs b/IPA/Patcher/Patcher.cs index 7f8b25f5..a8ea3911 100644 --- a/IPA/Patcher/Patcher.cs +++ b/IPA/Patcher/Patcher.cs @@ -62,10 +62,11 @@ namespace IPA.Patcher public void Patch(Version v) { // First, let's add the reference - var nameReference = new AssemblyNameReference("IPA.Injector", Program.Version); + var nameReference = new AssemblyNameReference("IPA.Injector", v); var injectorPath = Path.Combine(_File.DirectoryName, "IPA.Injector.dll"); var injector = ModuleDefinition.ReadModule(injectorPath); + bool hasIPAInjector = false; for (int i = 0; i < _Module.AssemblyReferences.Count; i++) { if (_Module.AssemblyReferences[i].Name == "IllusionInjector") @@ -73,26 +74,37 @@ namespace IPA.Patcher if (_Module.AssemblyReferences[i].Name == "IllusionPlugin") _Module.AssemblyReferences.RemoveAt(i--); if (_Module.AssemblyReferences[i].Name == "IPA.Injector") - _Module.AssemblyReferences.RemoveAt(i--); + { + hasIPAInjector = true; + _Module.AssemblyReferences[i].Version = v; + } } - _Module.AssemblyReferences.Add(nameReference); - - int patched = 0; - foreach(var type in FindEntryTypes()) + if (!hasIPAInjector) { - if(PatchType(type, injector)) + _Module.AssemblyReferences.Add(nameReference); + + int patched = 0; + foreach (var type in FindEntryTypes()) + { + if (PatchType(type, injector)) + { + patched++; + } + } + + if (patched > 0) + { + _Module.Write(_File.FullName); + } + else { - patched++; + throw new Exception("Could not find any entry type!"); } } - - if(patched > 0) + else { _Module.Write(_File.FullName); - } else - { - throw new Exception("Could not find any entry type!"); } }