protected virtual void PrintSaveSlotChecksumValidation(SramFileSoE currFile, SramFileSoE compFile) { ConsolePrinter.PrintSectionHeader(); ConsolePrinter.PrintColoredLine(ConsoleColor.DarkYellow, $@"{Resources.EnumChecksum}:"); OnPrintSaveSlotChecksumValidation(Res.EnumCurrentFile, currFile); OnPrintSaveSlotChecksumValidation(Res.EnumComparisonFile, compFile); }
protected virtual void OnPrintSaveSlotChecksumValidation(string name, IMultiSegmentFile file) { ConsolePrinter.PrintColored(ConsoleColor.Gray, $@"{name}:".PadRight(15)); ConsolePrinter.PrintColored(ConsoleColor.DarkYellow, $@" {Res.CompSlot} (1-{file.MaxIndex + 1})"); ConsolePrinter.PrintColored(ConsoleColor.White, @" [ "); for (var i = 0; i <= file.MaxIndex; i++) { if (i > 0) { ConsolePrinter.PrintColored(ConsoleColor.White, @" | "); } var isValid = file.IsValid(i); ConsolePrinter.PrintColored(isValid ? ConsoleColor.DarkGreen : ConsoleColor.Red, isValid ? Resources.Valid : Resources.Invalid); } ConsolePrinter.PrintColoredLine(ConsoleColor.White, @" ]"); }
/// <inheritdoc cref="SramComparerBase{TSramFile,TSaveSlot}"/> protected override int OnCompareSram(SramFileSoE currFile, SramFileSoE compFile, IOptions options) { var optionCurrSlotIndex = options.CurrentFileSaveSlot - 1; var optionCompSlotIndex = options.ComparisonFileSaveSlot - 1; if (optionCompSlotIndex > -1) { if (optionCurrSlotIndex == -1 || optionCurrSlotIndex == optionCompSlotIndex) { optionCompSlotIndex = -1; } } var optionFlags = (ComparisonFlagsSoE)options.ComparisonFlags; if (optionFlags.HasFlag(ComparisonFlagsSoE.ChecksumStatus)) { PrintSaveSlotChecksumValidation(currFile, compFile); } ConsolePrinter.PrintLine(); var slotComparisonMode = optionCompSlotIndex > -1 && optionCurrSlotIndex > -1 ? Res.StatusDifferentSaveSlotComparisonTemplate.InsertArgs(options.CurrentFileSaveSlot, options.ComparisonFileSaveSlot) : optionCurrSlotIndex > -1 ? string.Format(Res.StatusSingleSaveSlotComparisonTemplate, options.CurrentFileSaveSlot) : Res.StatusAllSaveSlotsComparison; ConsolePrinter.PrintColoredLine(ConsoleColor.Yellow, slotComparisonMode); ConsolePrinter.PrintLine(); var allDiffBytes = 0; #region Preparation for additional save slot value display StringBuilder checksums = new(), timestamps = new(); checksums.AppendLine($"{Resources.EnumChecksum} (2 {Res.Bytes} | {Resources.CompChangesAtEveryInSaveSlotSave}):"); timestamps.AppendLine($"{nameof(Sizes.ScriptedEventTimer)} ({Sizes.ScriptedEventTimer} {Res.Bytes}):"); #endregion #region Slot comparison // Single slot cimparison if (optionCurrSlotIndex > -1 && optionCompSlotIndex > -1) { allDiffBytes = CompareSaveSlots(optionCurrSlotIndex, optionCompSlotIndex); } else #region Slot loop { for (var slotIndex = 0; slotIndex < 4; slotIndex++) { if (optionCurrSlotIndex > -1 && optionCurrSlotIndex != slotIndex) { continue; } allDiffBytes = CompareSaveSlots(slotIndex); } } #endregion #endregion #region Non slot comparison if (options.ComparisonFlags.HasFlag(ComparisonFlagsSoE.NonSlotComparison)) { var nonSaveSlotUnknownDiffBytes = CompareValue(nameof(currFile.Struct.Unknown19), 0, currFile.Struct.Unknown19, compFile.Struct.Unknown19, false); if (nonSaveSlotUnknownDiffBytes > 0) { ConsolePrinter.PrintLine(); ConsolePrinter.PrintColoredLine(ConsoleColor.Magenta, " ".Repeat(2) + $@"[ {Res.CompSectionNonSaveSlotUnknowns} ]"); ConsolePrinter.ResetColor(); nonSaveSlotUnknownDiffBytes = CompareValue(nameof(currFile.Struct.Unknown19), SramOffsets.Unknown19, currFile.Struct.Unknown19, compFile.Struct.Unknown19, true); ConsolePrinter.PrintLine(); ConsolePrinter.PrintColoredLine(nonSaveSlotUnknownDiffBytes > 0 ? ConsoleColor.Green : ConsoleColor.White, " ".Repeat(4) + Res.StatusNonSaveSlotUnknownsBytesTemplate.InsertArgs(nonSaveSlotUnknownDiffBytes)); ConsolePrinter.ResetColor(); allDiffBytes += nonSaveSlotUnknownDiffBytes; } } #endregion #region Display of comparison summary ConsolePrinter.PrintLine(); const int borderLength = 50; var color = allDiffBytes > 0 ? ConsoleColor.Yellow : ConsoleColor.Green; ConsolePrinter.PrintColoredLine(color, "=".Repeat(borderLength)); ConsolePrinter.PrintColoredLine(color, allDiffBytes > 0 ? @$ "== {Res.StatusSramChangedBytesTemplate.InsertArgs(allDiffBytes)} ".PadRight(borderLength, '=') : @$ "== {Res.StatusNoSramBytesChanged} =".PadRight(borderLength, '=')); ConsolePrinter.PrintColoredLine(color, "=".Repeat(borderLength)); ConsolePrinter.ResetColor(); #endregion #region Display of additional save slot values if (optionFlags != default) { ConsolePrinter.PrintLine(); if (optionFlags.HasFlag(ComparisonFlagsSoE.ChecksumIfDifferent)) { ConsolePrinter.PrintColoredLine(ConsoleColor.Cyan, FormatAdditionalValues(nameof(checksums), checksums)); } if (optionFlags.HasFlag(ComparisonFlagsSoE.ScriptedEventTimerIfDifferent)) { ConsolePrinter.PrintColoredLine(ConsoleColor.Cyan, FormatAdditionalValues(nameof(timestamps), timestamps)); } } #endregion return(allDiffBytes); int CompareSaveSlots(int currSlotIndex, int compSlotIndex = -1) { if (compSlotIndex == -1) { compSlotIndex = currSlotIndex; } var currSlot = currFile.GetSegment(currSlotIndex); var currSlotBytes = currFile.GetSegmentBytes(currSlotIndex); var compSlot = compFile.GetSegment(compSlotIndex); var compSlotBytes = compFile.GetSegmentBytes(compSlotIndex); var currSlotId = currSlotIndex + 1; var compSlotId = compSlotIndex + 1; var slotIdString = currSlotId.ToString(); if (currSlotId != compSlotId) { slotIdString += $" ({Resources.CompComparedWithOtherSaveSlotTemplate.InsertArgs(compSlotId)})"; } #region Additional save slot value display const int padding = 25; var currSlotName = $"{$"({Res.EnumCurrentFile})".PadRight(padding)} {Res.CompSlot} {currSlotId}"; var currSlotNameString = $"{" ".Repeat(2)}{currSlotName}"; if (optionFlags.HasFlag(ComparisonFlagsSoE.Checksum) || compSlot.Checksum != currSlot.Checksum) { checksums.AppendLine($"{currSlotNameString}: {currSlot.Checksum.PadLeft()}"); } if (optionFlags.HasFlag(ComparisonFlagsSoE.ScriptedEventTimer) || compSlot.Data.EquippedStuff_Moneys_Levels.ScriptedEventTimer != currSlot.Data.EquippedStuff_Moneys_Levels.ScriptedEventTimer) { timestamps.AppendLine($"{currSlotNameString}: {currSlot.Data.EquippedStuff_Moneys_Levels.ScriptedEventTimer.PadLeft()}"); } #endregion if (compSlotBytes.SequenceEqual(currSlotBytes)) { return(allDiffBytes); } #region Additional save slot value display var compSlotName = $"{$"({Res.EnumComparisonFile})".PadRight(padding)} {Res.CompSlot} {compSlotId}"; var compSlotNameString = $"{" ".Repeat(2)}{compSlotName}"; checksums.AppendLine($"{compSlotNameString}: {compSlot.Checksum.PadLeft()}"); timestamps.AppendLine($"{compSlotNameString}: {compSlot.Data.EquippedStuff_Moneys_Levels.ScriptedEventTimer.PadLeft()}"); #endregion ConsolePrinter.PrintColoredLine(ConsoleColor.Yellow, $@"[ {Res.CompSlot} {slotIdString} ]"); ConsolePrinter.ResetColor(); ConsolePrinter.PrintLine(); ConsolePrinter.PrintColoredLine(ConsoleColor.Magenta, " ".Repeat(2) + $@"[ {Res.CompUnknownAreasOnly} ]"); ConsolePrinter.ResetColor(); var slotDiffBytes = OnCompareSaveSlot(currSlot, compSlot, options); if (slotDiffBytes > 0) { ConsolePrinter.PrintLine(); ConsolePrinter.PrintColoredLine(ConsoleColor.Green, " ".Repeat(4) + Res.StatusUnknownsChangedBytesTemplate.InsertArgs(slotDiffBytes)); ConsolePrinter.ResetColor(); } if (optionFlags.HasFlag(ComparisonFlagsSoE.SlotByteComparison)) { #region Slot byte by byte comparison ConsoleHelper.EnsureMinConsoleWidth(ComparisonMinConsoleWidth); var fieldName = $"{nameof(compFile.Struct.SaveSlots)}[{currSlotIndex}]"; var bufferOffset = SramOffsets.FirstSaveSlot + currSlotId * SramSizes.SaveSlot; var slotBufferDiffBytes = CompareValue(fieldName, bufferOffset, currSlotBytes, compSlotBytes, false); if (slotBufferDiffBytes > slotDiffBytes) { ConsolePrinter.PrintLine(); ConsolePrinter.PrintColoredLine(ConsoleColor.Magenta, $@"{" ".Repeat(2)}[ {Res.CompSectionSaveSlotChangedTemplate} ]".InsertArgs(currSlotIndex)); // ReSharper disable once RedundantArgumentDefaultValue CompareValue(fieldName, bufferOffset, currSlotBytes, compSlotBytes, true, offset => typeof(SaveSlotDataSoE).GetFieldNameByOffset(offset), isUnknown: false); ConsolePrinter.PrintLine(); ConsolePrinter.PrintColoredLine(slotDiffBytes > 0 ? ConsoleColor.Green : ConsoleColor.White, " ".Repeat(4) + Res.StatusSaveSlotChangedResultTemplate.InsertArgs(slotIdString, slotBufferDiffBytes)); ConsolePrinter.ResetColor(); } allDiffBytes += slotBufferDiffBytes; #endregion } else { allDiffBytes += slotDiffBytes; } return(allDiffBytes); } }