From 7f4d39f3dd6d5ea9bd7fdc9a8edcbae6104bd96a Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sun, 23 Sep 2018 23:34:21 -0500 Subject: [PATCH] Fixed issue where updating with a backup would fail to update the fackup and prevent IPA from loading --- IPA.Injector/Backups/BackupUnit.cs | 2 ++ IPA.Injector/Injector.cs | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/IPA.Injector/Backups/BackupUnit.cs b/IPA.Injector/Backups/BackupUnit.cs index ad7c6e5f..85b56c39 100644 --- a/IPA.Injector/Backups/BackupUnit.cs +++ b/IPA.Injector/Backups/BackupUnit.cs @@ -79,6 +79,8 @@ namespace IPA.Injector.Backups backupPath.Directory.Create(); if (file.Exists) { + if (File.Exists(backupPath.FullName)) + File.Delete(backupPath.FullName); file.CopyTo(backupPath.FullName); } else diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 1b3e2a73..09f91444 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -102,10 +102,22 @@ namespace IPA.Injector for (int i = 0; i < Math.Min(2, cctor.Body.Instructions.Count); i++) { var ins = cctor.Body.Instructions[i]; - if (i == 0 && (ins.OpCode != OpCodes.Call || ins.Operand != cbs)) + if (i == 0) { - ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs)); - modified = true; + if (ins.OpCode != OpCodes.Call) + { + ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs)); + modified = true; + } + else + { + var mref = ins.Operand as MethodReference; + if (mref.FullName != cbs.FullName) + { + ilp.Replace(ins, ilp.Create(OpCodes.Call, cbs)); + modified = true; + } + } } if (i == 1 && ins.OpCode != OpCodes.Ret) {