private bool ReplaceAllPatterns(Patcher.MainPattern pt) { if (!pt.Ptrn.ReplaceImmediately || this._isDisposed) { return(false); } int num = 0; long[] arg_3E_0 = pt.StreamPosition; Patcher.Pattern.UniversalByte[] replaceBytes = pt.Ptrn.ReplaceBytes; byte[] array = new byte[pt.Ptrn.SearchBytes.Length]; long[] array2 = arg_3E_0; for (int i = 0; i < array2.Length; i++) { long position = array2[i]; if (this._isDisposed) { return(false); } bool flag = false; this._fs.Position = position; this._fs.Read(array, 0, array.Length); for (int j = 0; j < array.Length; j++) { if (replaceBytes[j].Act > Patcher.Pattern.UniversalByte.Action.Skip && array[j] != replaceBytes[j].B) { array[j] = replaceBytes[j].B; flag = true; } } if (flag) { this._fs.Position = position; this._fs.Write(array, 0, array.Length); num++; } } return(true); }
public bool Patch() { if (this.Patterns == null) { NLogger.Error("ArgumentNullException: patterns."); return(false); } List <Patcher.Pattern> arg_39_0 = this.Patterns; Predicate <Patcher.Pattern> arg_39_1; arg_39_1 = Patcher.PatcherData.PatcherDataPredicate; if (arg_39_1 == null) { Patcher.PatcherData.PatcherDataPredicate = new Predicate <Patcher.Pattern>(Patcher.PatcherData.Instance.Patch); arg_39_1 = Patcher.PatcherData.PatcherDataPredicate; } arg_39_0.RemoveAll(arg_39_1); if (this.Patterns.Count == 0) { NLogger.Error("Collection is empty: patterns."); return(false); } uint num = 0u; uint num2 = 0u; bool flag = false; try { this._fs = this.CreateStream(this.FileName); foreach (Patcher.Pattern current in this.Patterns) { Patcher.MainPattern pt = this.FindAllPatterns(current); if (pt.SuccessfullyFound > 0) { if (this.ReplaceAllPatterns(pt)) { flag = true; } if (pt.Success) { num2 += 1u; } else { num2 += 1u; num += 1u; } } else { num += 1u; } } } catch (Exception ex) { if (this._fs != null) { this._fs.Dispose(); this._fs = null; } NLogger.Error(string.Format("{0}: {1}", ex.GetType(), ex.Message)); return(false); } if (this._fs != null) { this._fs.Close(); this._fs = null; } if (flag) { if (num > 0u && num2 > 0u) { NLogger.Debug(this._succesMessages[2]); this.CurrentState = new Patcher.PatcherState(flag, num2, num, this._succesMessages[2]); return(true); } if (num == 0u && num2 > 0u) { NLogger.Debug(this._succesMessages[1]); this.CurrentState = new Patcher.PatcherState(flag, num2, num, this._succesMessages[1]); return(true); } this.CurrentState = new Patcher.PatcherState(flag, num2, num, this._succesMessages[0]); NLogger.Debug(this._succesMessages[0]); } else { if (num > 0u && num2 > 0u) { this.CurrentState = new Patcher.PatcherState(flag, num2, num, this._succesMessages[4]); NLogger.Debug(this._succesMessages[4]); return(true); } if (num == 0u && num2 > 0u) { this.CurrentState = new Patcher.PatcherState(flag, num2, num, this._succesMessages[3]); NLogger.Debug(this._succesMessages[3]); return(true); } this.CurrentState = new Patcher.PatcherState(flag, num2, num, this._succesMessages[0]); NLogger.Debug(this._succesMessages[0]); } return(false); }