public void Patch(FileInfo fileInfo) { if (FileInUse(fileInfo.Path)) { Console.WriteLine($"Version: {fileInfo.Version} - IOException (Slack running?)"); return; } if (AlreadyPatched(fileInfo.Path)) { Console.WriteLine($"Version: {fileInfo.Version} - Already patched"); return; } using (var reader = new BinaryReader(new FileStream(fileInfo.Path, FileMode.Open, FileAccess.Read))) { using (var writer = new BinaryWriter(new FileStream($"{fileInfo.Path}{PatchSuffix}", FileMode.Create))) { BinaryUtility.Replace(reader, writer, new List <Tuple <byte[], byte[]> >() { Tuple.Create(OriginalOpCode, PatchedOpCode), }); } } File.Replace($"{fileInfo.Path}{PatchSuffix}", fileInfo.Path, $"{fileInfo.Path}{BackupSuffix}"); Console.WriteLine($"Version: {fileInfo.Version} - Patched successfully"); }