public static void WritePatch(Patch patch, IWriter writer) { var container = new ContainerWriter(writer); container.StartBlock("asmp", 0); WriteBlocks(patch, container, writer); container.EndBlock(); }
public static Patch LoadPatch(IReader reader, bool isAlteration) { Patch patch = new Patch(); SegmentChange change = new SegmentChange(0, 0, 0, 0, true); patch.Author = "Ascension/Alteration Patch"; patch.Description = "Ascension/Alteration Patch"; if (isAlteration) { //do shitty alteration stuff byte authorLength = reader.ReadByte(); patch.Author = reader.ReadAscii((int)authorLength); byte descLength = reader.ReadByte(); patch.Description = reader.ReadAscii((int)descLength); } //create ascension patch object and change segment while (!reader.EOF) { //get valuable info var segmentOffset = reader.ReadUInt32(); var segmentSize = reader.ReadInt32(); var segmentData = reader.ReadBlock(segmentSize); //Add change data change.DataChanges.Add(new DataChange(segmentOffset, segmentData)); } patch.SegmentChanges.Add(change); return patch; }
private static void ReadPatchInfo(IReader reader, byte version, Patch output) { // Version 0 (all versions) output.MapID = reader.ReadInt32(); output.MapInternalName = reader.ReadAscii(); output.Name = reader.ReadUTF16(); output.Description = reader.ReadUTF16(); output.Author = reader.ReadUTF16(); int screenshotLength = reader.ReadInt32(); if (screenshotLength > 0) output.Screenshot = reader.ReadBlock(screenshotLength); // Version 1 if (version >= 1) { output.MetaPokeBase = reader.ReadUInt32(); output.MetaChangesIndex = reader.ReadSByte(); } // Version 2 if (version >= 2) output.OutputName = reader.ReadAscii(); else output.OutputName = ""; }
private static Patch ReadBlocks(IReader reader, ContainerReader container) { var result = new Patch(); while (container.NextBlock()) { switch (container.BlockName) { case "titl": ReadPatchInfo(reader, container.BlockVersion, result); break; case "segm": ReadSegmentChanges(reader, result); break; case "blfc": ReadBlfInfo(reader, result); break; #region Deprecated case "meta": ReadMetaChanges(reader, result); break; case "locl": ReadLocaleChanges(reader, result); break; #endregion Deprecated } } return result; }
/// <summary> /// Builds a Patch by comparing two cache files. /// </summary> /// <param name="originalFile">The original cache file.</param> /// <param name="originalReader">The stream to use to read from the original cache file.</param> /// <param name="newFile">The modified cache file.</param> /// <param name="newReader">The stream to use to read from the modified cache file.</param> /// <param name="output">The Patch to store differences to.</param> public static void BuildPatch(ICacheFile originalFile, IReader originalReader, ICacheFile newFile, IReader newReader, Patch output) { output.MapInternalName = originalFile.InternalName; output.MetaPokeBase = newFile.MetaArea.BasePointer; var segmentChanges = SegmentComparer.CompareSegments(originalFile.Segments, originalReader, newFile.Segments, newReader); output.SegmentChanges.AddRange(segmentChanges); output.MetaChangesIndex = FindMetaChanges(segmentChanges, newFile); }
public static void WritePatch(Patch patch, IWriter writer) { var startPos = WriteBlockHeader(writer, AssemblyPatchMagic); writer.WriteByte(0); // No compression WriteBlocks(patch, writer); EndBlock(writer, startPos); }
private static void WriteBlocks(Patch patch, IWriter writer) { WritePatchInfo(patch, writer); WriteSegmentChanges(patch, writer); WriteBlfInfo(patch, writer); #region Deprecated WriteMetaChanges(patch, writer); WriteLocaleChanges(patch, writer); #endregion Deprecated }
/// <summary> /// Applies a patch to a cache file. /// </summary> /// <param name="patch">The patch to apply.</param> /// <param name="cacheFile">The cache file to apply the patch to. After the patch is applied, it may have to be reloaded.</param> /// <param name="stream">The stream to write changes to.</param> public static void ApplyPatch(Patch patch, ICacheFile cacheFile, IStream stream) { if (patch.MapInternalName != cacheFile.InternalName) throw new ArgumentException("The patch is for a different cache file. Expected \"" + patch.MapInternalName + "\" but got \"" + cacheFile.InternalName + "\"."); SegmentPatcher.PatchSegments(patch.SegmentChanges, stream); #region Deprecated DataPatcher.PatchData(patch.MetaChanges, (uint)-cacheFile.MetaArea.PointerMask, stream); if (patch.LanguageChanges.Count > 0) { LocalePatcher.WriteLanguageChanges(patch.LanguageChanges, cacheFile, stream); cacheFile.SaveChanges(stream); } #endregion }
private static void ReadBlfInfo(IReader reader, Patch output) { // Version 0 (all versions) var targetGame = (TargetGame) reader.ReadByte(); string mapInfoFileName = reader.ReadAscii(); uint mapInfoLength = reader.ReadUInt32(); byte[] mapInfo = reader.ReadBlock((int) mapInfoLength); short blfContainerCount = reader.ReadInt16(); output.CustomBlfContent = new BlfContent(mapInfoFileName, mapInfo, targetGame); for (int i = 0; i < blfContainerCount; i++) { string fileName = Path.GetFileName(reader.ReadAscii()); uint blfContainerLength = reader.ReadUInt32(); byte[] blfContainer = reader.ReadBlock((int) blfContainerLength); output.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(fileName, blfContainer)); } }
private static void WriteSegmentChanges(Patch patch, ContainerWriter container, IWriter writer) { if (patch.SegmentChanges.Count == 0) return; container.StartBlock("segm", 0); // Version 0 writer.WriteByte((byte) patch.SegmentChanges.Count); foreach (SegmentChange segment in patch.SegmentChanges) { writer.WriteUInt32(segment.OldOffset); writer.WriteInt32(segment.OldSize); writer.WriteUInt32(segment.NewOffset); writer.WriteInt32(segment.NewSize); writer.WriteByte(Convert.ToByte(segment.ResizeAtEnd)); WriteDataChanges(segment.DataChanges, writer); } container.EndBlock(); }
private static Patch ReadBlocks(IReader reader, uint startOffset, uint endOffset) { var result = new Patch(); var offset = startOffset; while (offset < endOffset) { reader.SeekTo(offset); var blockId = reader.ReadInt32(); var size = reader.ReadUInt32(); switch (blockId) { case AssemblyPatchBlockID.Titl: ReadPatchInfo(reader, result); break; case AssemblyPatchBlockID.Segm: ReadSegmentChanges(reader, result); break; case AssemblyPatchBlockID.Blfc: ReadBlfInfo(reader, result); break; #region Deprecated case AssemblyPatchBlockID.Meta: ReadMetaChanges(reader, result); break; case AssemblyPatchBlockID.Locl: ReadLocaleChanges(reader, result); break; #endregion Deprecated } // Skip to the next block offset += size; } return result; }
private static void ReadBlfInfo(IReader reader, Patch output) { // ReSharper disable UnusedVariable var version = reader.ReadByte(); // ReSharper restore UnusedVariable // Version 0 (all versions) var targetGame = (TargetGame)reader.ReadByte(); var mapInfoFileName = reader.ReadAscii(); var mapInfoLength = reader.ReadUInt32(); var mapInfo = reader.ReadBlock((int)mapInfoLength); var blfContainerCount = reader.ReadInt16(); output.CustomBlfContent = new BlfContent(mapInfoFileName, mapInfo, targetGame); for (var i = 0; i < blfContainerCount; i++) { var fileName = Path.GetFileName(reader.ReadAscii()); var blfContainerLength = reader.ReadUInt32(); var blfContainer = reader.ReadBlock((int)blfContainerLength); output.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(fileName, blfContainer)); } }
private static void WritePatchInfo(Patch patch, ContainerWriter container, IWriter writer) { container.StartBlock("titl", 2); // Version 2 // Write target map info writer.WriteInt32(patch.MapID); if (patch.MapInternalName != null) writer.WriteAscii(patch.MapInternalName); else writer.WriteByte(0); // Write patch info writer.WriteUTF16(patch.Name); writer.WriteUTF16(patch.Description); writer.WriteUTF16(patch.Author); // Write screenshot if (patch.Screenshot != null) { writer.WriteInt32(patch.Screenshot.Length); writer.WriteBlock(patch.Screenshot); } else { writer.WriteInt32(0); } // Write meta info writer.WriteUInt32(patch.MetaPokeBase); writer.WriteSByte((sbyte) patch.MetaChangesIndex); // Write output name if (patch.OutputName != null) writer.WriteAscii(patch.OutputName); else writer.WriteByte(0); container.EndBlock(); }
private static void WriteBlfInfo(Patch patch, IWriter writer) { if (patch.CustomBlfContent == null) return; var startPos = WriteBlockHeader(writer, AssemblyPatchBlockID.Blfc); writer.WriteByte(0); // Version 0 writer.WriteByte((byte)patch.CustomBlfContent.TargetGame); // Write mapinfo filename if (patch.CustomBlfContent.MapInfoFileName != null) writer.WriteAscii(patch.CustomBlfContent.MapInfoFileName); else writer.WriteByte(0); // Write mapinfo data if (patch.CustomBlfContent.MapInfo != null) { writer.WriteUInt32((uint)patch.CustomBlfContent.MapInfo.Length); writer.WriteBlock(patch.CustomBlfContent.MapInfo); } else { writer.WriteUInt32(0); } // Write BLF containers writer.WriteInt16((short)patch.CustomBlfContent.BlfContainerEntries.Count); foreach (var blfContainerEntry in patch.CustomBlfContent.BlfContainerEntries) { writer.WriteAscii(blfContainerEntry.FileName); writer.WriteUInt32((uint)blfContainerEntry.BlfContainer.Length); writer.WriteBlock(blfContainerEntry.BlfContainer); } EndBlock(writer, startPos); }
private static void WriteBlfInfo(Patch patch, ContainerWriter container, IWriter writer) { if (patch.CustomBlfContent == null) return; container.StartBlock("blfc", 0); // Version 0 writer.WriteByte((byte) patch.CustomBlfContent.TargetGame); // Write mapinfo filename if (patch.CustomBlfContent.MapInfoFileName != null) writer.WriteAscii(patch.CustomBlfContent.MapInfoFileName); else writer.WriteByte(0); // Write mapinfo data if (patch.CustomBlfContent.MapInfo != null) { writer.WriteUInt32((uint) patch.CustomBlfContent.MapInfo.Length); writer.WriteBlock(patch.CustomBlfContent.MapInfo); } else { writer.WriteUInt32(0); } // Write BLF containers writer.WriteInt16((short) patch.CustomBlfContent.BlfContainerEntries.Count); foreach (BlfContainerEntry blfContainerEntry in patch.CustomBlfContent.BlfContainerEntries) { writer.WriteAscii(blfContainerEntry.FileName); writer.WriteUInt32((uint) blfContainerEntry.BlfContainer.Length); writer.WriteBlock(blfContainerEntry.BlfContainer); } container.EndBlock(); }
private static void WriteLocaleChanges(Patch patch, ContainerWriter container, IWriter writer) { if (patch.LanguageChanges.Count == 0) return; container.StartBlock("locl", 0); // Version 0 // Write change data for each language writer.WriteByte((byte) patch.LanguageChanges.Count); foreach (LanguageChange language in patch.LanguageChanges) { writer.WriteByte(language.LanguageIndex); // Write the change data for each string in the language writer.WriteInt32(language.LocaleChanges.Count); foreach (LocaleChange change in language.LocaleChanges) { writer.WriteInt32(change.Index); writer.WriteUTF8(change.NewValue); } } container.EndBlock(); }
private static void WriteMetaChanges(Patch patch, ContainerWriter container, IWriter writer) { if (patch.MetaChanges.Count == 0) return; container.StartBlock("meta", 0); // Version 0 List<DataChange> fourByteChanges = patch.MetaChanges.Where(c => c.Data.Length == 4).ToList(); List<DataChange> otherChanges = patch.MetaChanges.Where(c => c.Data.Length != 4).ToList(); // Write 4-byte changes writer.WriteUInt32((uint) fourByteChanges.Count); foreach (DataChange change in fourByteChanges) { writer.WriteUInt32(change.Offset); writer.WriteBlock(change.Data); } // Write other changes writer.WriteUInt32((uint) otherChanges.Count); foreach (DataChange change in otherChanges) { writer.WriteUInt32(change.Offset); writer.WriteInt32(change.Data.Length); writer.WriteBlock(change.Data); } container.EndBlock(); }
private static void ReadMetaChanges(IReader reader, Patch output) { output.MetaChanges.AddRange(ReadDataChanges(reader)); }
private static void ReadPatchInfo(IReader reader, Patch output) { // ReSharper disable UnusedVariable var version = reader.ReadByte(); // ReSharper restore UnusedVariable // Version 0 (all versions) output.MapID = reader.ReadInt32(); output.MapInternalName = reader.ReadAscii(); output.Name = reader.ReadUTF16(); output.Description = reader.ReadUTF16(); output.Author = reader.ReadUTF16(); var screenshotLength = reader.ReadInt32(); if (screenshotLength > 0) output.Screenshot = reader.ReadBlock(screenshotLength); // Version 1 if (version == 1) { output.MetaPokeBase = reader.ReadUInt32(); output.MetaChangesIndex = reader.ReadSByte(); } }
private static void ReadSegmentChanges(IReader reader, Patch output) { // Version 0 (all versions) byte numChanges = reader.ReadByte(); for (int i = 0; i < numChanges; i++) { uint oldOffset = reader.ReadUInt32(); int oldSize = reader.ReadInt32(); uint newOffset = reader.ReadUInt32(); int newSize = reader.ReadInt32(); bool resizeAtEnd = Convert.ToBoolean(reader.ReadByte()); var segmentChange = new SegmentChange(oldOffset, oldSize, newOffset, newSize, resizeAtEnd); segmentChange.DataChanges.AddRange(ReadDataChanges(reader)); output.SegmentChanges.Add(segmentChange); } }
private static void WritePatchInfo(Patch patch, IWriter writer) { var startPos = WriteBlockHeader(writer, AssemblyPatchBlockID.Titl); writer.WriteByte(1); // Version 1 // Write target map info writer.WriteInt32(patch.MapID); if (patch.MapInternalName != null) writer.WriteAscii(patch.MapInternalName); else writer.WriteByte(0); // Write patch info writer.WriteUTF16(patch.Name); writer.WriteUTF16(patch.Description); writer.WriteUTF16(patch.Author); // Write screenshot if (patch.Screenshot != null) { writer.WriteInt32(patch.Screenshot.Length); writer.WriteBlock(patch.Screenshot); } else { writer.WriteInt32(0); } // Write meta info writer.WriteUInt32(patch.MetaPokeBase); writer.WriteSByte((sbyte)patch.MetaChangesIndex); EndBlock(writer, startPos); }
private static void WriteMetaChanges(Patch patch, IWriter writer) { if (patch.MetaChanges.Count == 0) return; var startPos = WriteBlockHeader(writer, AssemblyPatchBlockID.Meta); writer.WriteByte(0); // Version 0 var fourByteChanges = patch.MetaChanges.Where((c) => c.Data.Length == 4).ToList(); var otherChanges = patch.MetaChanges.Where((c) => c.Data.Length != 4).ToList(); // Write 4-byte changes writer.WriteUInt32((uint)fourByteChanges.Count); foreach (var change in fourByteChanges) { writer.WriteUInt32(change.Offset); writer.WriteBlock(change.Data); } // Write other changes writer.WriteUInt32((uint)otherChanges.Count); foreach (var change in otherChanges) { writer.WriteUInt32(change.Offset); writer.WriteInt32(change.Data.Length); writer.WriteBlock(change.Data); } EndBlock(writer, startPos); }
private static void ReadLocaleChanges(IReader reader, Patch output) { // Read language changes byte numLanguageChanges = reader.ReadByte(); for (byte i = 0; i < numLanguageChanges; i++) { byte languageIndex = reader.ReadByte(); var languageChange = new LanguageChange(languageIndex); // Read string changes int numStringChanges = reader.ReadInt32(); for (int j = 0; j < numStringChanges; j++) { int index = reader.ReadInt32(); string newValue = reader.ReadUTF8(); languageChange.LocaleChanges.Add(new LocaleChange(index, newValue)); } output.LanguageChanges.Add(languageChange); } }
// Meta Sorting private void LoadPatch(bool isAlteration) { try { using (var reader = new EndianReader(File.OpenRead(txtApplyPatchFile.Text), Endian.LittleEndian)) { string magic = reader.ReadAscii(4); reader.SeekTo(0); if (magic == "asmp") { // Load into UI reader.Endianness = Endian.BigEndian; currentPatch = AssemblyPatchLoader.LoadPatch(reader); txtApplyPatchAuthor.Text = currentPatch.Author; txtApplyPatchDesc.Text = currentPatch.Description; txtApplyPatchName.Text = currentPatch.Name; txtApplyPatchInternalName.Text = currentPatch.MapInternalName; //txtApplyPatchMapID.Text = currentPatch.MapID.ToString(CultureInfo.InvariantCulture); // Set Visibility PatchApplicationPatchExtra.Visibility = currentPatch.CustomBlfContent != null ? Visibility.Visible : Visibility.Collapsed; ApplyPatchControls.Visibility = Visibility.Visible; btnExtractInfo.IsEnabled = true; } else { currentPatch = OldPatchLoader.LoadPatch(reader, isAlteration); txtApplyPatchAuthor.Text = currentPatch.Author; txtApplyPatchDesc.Text = currentPatch.Description; txtApplyPatchName.Text = "Ascension/Alteration Patch"; txtApplyPatchInternalName.Text = "Ascension/Alteration Patch"; ApplyPatchControls.Visibility = Visibility.Visible; PatchApplicationPatchExtra.Visibility = Visibility.Collapsed; btnExtractInfo.IsEnabled = false; } } // Set Screenshot if (currentPatch.Screenshot == null) { // Set default var source = new Uri(@"/Assembly;component/Metro/Images/super_patcher.png", UriKind.Relative); imgApplyPreview.Source = new BitmapImage(source); } else { var image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(currentPatch.Screenshot); image.EndInit(); imgApplyPreview.Source = image; } } catch (Exception ex) { MetroException.Show(ex); } }
private static void ReadSegmentChanges(IReader reader, Patch output) { // ReSharper disable UnusedVariable var version = reader.ReadByte(); // ReSharper restore UnusedVariable // Version 0 (all versions) var numChanges = reader.ReadByte(); for (var i = 0; i < numChanges; i++) { var oldOffset = reader.ReadUInt32(); var oldSize = reader.ReadInt32(); var newOffset = reader.ReadUInt32(); var newSize = reader.ReadInt32(); var resizeAtEnd = Convert.ToBoolean(reader.ReadByte()); var segmentChange = new SegmentChange(oldOffset, oldSize, newOffset, newSize, resizeAtEnd); segmentChange.DataChanges.AddRange(ReadDataChanges(reader)); output.SegmentChanges.Add(segmentChange); } }
private static void ReadLocaleChanges(IReader reader, Patch output) { // ReSharper disable UnusedVariable var version = reader.ReadByte(); // ReSharper restore UnusedVariable // Read language changes var numLanguageChanges = reader.ReadByte(); for (byte i = 0; i < numLanguageChanges; i++) { var languageIndex = reader.ReadByte(); var languageChange = new LanguageChange(languageIndex); // Read string changes var numStringChanges = reader.ReadInt32(); for (var j = 0; j < numStringChanges; j++) { var index = reader.ReadInt32(); var newValue = reader.ReadUTF8(); languageChange.LocaleChanges.Add(new LocaleChange(index, newValue)); } output.LanguageChanges.Add(languageChange); } }
private static void WritePatchInfo(Patch patch, ContainerWriter container, IWriter writer) { container.StartBlock("titl", 3); // Version 2 // Write target map info writer.WriteInt32(patch.MapID); if (patch.MapInternalName != null) { writer.WriteAscii(patch.MapInternalName); } else { writer.WriteByte(0); } // Write patch info writer.WriteUTF16(patch.Name); writer.WriteUTF16(patch.Description); writer.WriteUTF16(patch.Author); // Write screenshot if (patch.Screenshot != null) { writer.WriteInt32(patch.Screenshot.Length); writer.WriteBlock(patch.Screenshot); } else { writer.WriteInt32(0); } // Write meta info writer.WriteInt64(patch.MetaPokeBase); writer.WriteSByte((sbyte)patch.MetaChangesIndex); // Write output name if (patch.OutputName != null) { writer.WriteAscii(patch.OutputName); } else { writer.WriteByte(0); } // PC? if (patch.PC) { writer.WriteByte(1); } else { writer.WriteByte(0); } // Write the build string if (patch.BuildString != null) { writer.WriteAscii(patch.BuildString); } else { writer.WriteByte(0); } container.EndBlock(); }
private static void WriteSegmentChanges(Patch patch, IWriter writer) { if (patch.SegmentChanges.Count == 0) return; var startPos = WriteBlockHeader(writer, AssemblyPatchBlockID.Segm); writer.WriteByte(0); // Version 0 writer.WriteByte((byte)patch.SegmentChanges.Count); foreach (var segment in patch.SegmentChanges) { writer.WriteUInt32(segment.OldOffset); writer.WriteInt32(segment.OldSize); writer.WriteUInt32(segment.NewOffset); writer.WriteInt32(segment.NewSize); writer.WriteByte(Convert.ToByte(segment.ResizeAtEnd)); WriteDataChanges(segment.DataChanges, writer); } EndBlock(writer, startPos); }
// Patch Creation private void btnCreatePatch_Click(object sender, RoutedEventArgs e) { try { // Check the user isn't completly retarded if (!CheckAllCreateMandatoryFields()) return; // Check the user isn't a skid if (!CheckAllCreateMetaFilesExists()) return; // Paths string cleanMapPath = txtCreatePatchUnModifiedMap.Text; string moddedMapPath = txtCreatePatchModifiedMap.Text; string outputPath = txtCreatePatchOutputPatch.Text; string previewImage = txtCreatePatchPreviewImage.Text; // Details string author = txtCreatePatchContentAuthor.Text; string desc = txtCreatePatchContentDescription.Text; string name = txtCreatePatchContentName.Text; string outputName = txtCreatePatchOutputName.Text; // Make dat patch var patch = new Patch { Author = author, Description = desc, Name = name, OutputName = outputName, Screenshot = String.IsNullOrEmpty(previewImage) ? null : File.ReadAllBytes(previewImage) }; EndianReader originalReader = null; EndianReader newReader = null; try { originalReader = new EndianReader(File.OpenRead(cleanMapPath), Endian.BigEndian); newReader = new EndianReader(File.OpenRead(moddedMapPath), Endian.BigEndian); ICacheFile originalFile = CacheFileLoader.LoadCacheFile(originalReader, App.AssemblyStorage.AssemblySettings.DefaultDatabase); ICacheFile newFile = CacheFileLoader.LoadCacheFile(newReader, App.AssemblyStorage.AssemblySettings.DefaultDatabase); if (cbCreatePatchHasCustomMeta.IsChecked != null && (bool) cbCreatePatchHasCustomMeta.IsChecked && cboxCreatePatchTargetGame.SelectedIndex < 4) { var targetGame = (TargetGame) cboxCreatePatchTargetGame.SelectedIndex; byte[] mapInfo = File.ReadAllBytes(txtCreatePatchMapInfo.Text); var mapInfoFileInfo = new FileInfo(txtCreatePatchMapInfo.Text); FileInfo blfFileInfo; patch.CustomBlfContent = new BlfContent(mapInfoFileInfo.FullName, mapInfo, targetGame); #region Blf Data if (PatchCreationBlfOption0.Visibility == Visibility.Visible) { blfFileInfo = new FileInfo(txtCreatePatchblf0.Text); patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name, File.ReadAllBytes(blfFileInfo.FullName))); } if (PatchCreationBlfOption1.Visibility == Visibility.Visible) { blfFileInfo = new FileInfo(txtCreatePatchblf1.Text); patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name, File.ReadAllBytes(blfFileInfo.FullName))); } if (PatchCreationBlfOption2.Visibility == Visibility.Visible) { blfFileInfo = new FileInfo(txtCreatePatchblf2.Text); patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name, File.ReadAllBytes(blfFileInfo.FullName))); } if (PatchCreationBlfOption3.Visibility == Visibility.Visible) { blfFileInfo = new FileInfo(txtCreatePatchblf3.Text); patch.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(blfFileInfo.Name, File.ReadAllBytes(blfFileInfo.FullName))); } #endregion } PatchBuilder.BuildPatch(originalFile, originalReader, newFile, newReader, patch); } finally { if (originalReader != null) originalReader.Close(); if (newReader != null) newReader.Close(); } IWriter output = new EndianWriter(File.Open(outputPath, FileMode.Create, FileAccess.Write), Endian.BigEndian); AssemblyPatchWriter.WritePatch(patch, output); output.Close(); MetroMessageBox.Show("Patch Created!", "Your patch has been created in the designated location. Happy sailing, modder!"); } catch (Exception ex) { MetroException.Show(ex); } }
private static void ReadMetaChanges(IReader reader, Patch output) { // ReSharper disable UnusedVariable var version = reader.ReadByte(); // ReSharper restore UnusedVariable output.MetaChanges.AddRange(ReadDataChanges(reader)); }
private void LoadPatchToPoke() { try { using (var reader = new EndianReader(File.OpenRead(txtPokePatchFile.Text), Endian.LittleEndian)) { string magic = reader.ReadAscii(4); reader.SeekTo(0); if (magic == "asmp") { // Load into UI reader.Endianness = Endian.BigEndian; currentPatchToPoke = AssemblyPatchLoader.LoadPatch(reader); txtPokePatchAuthor.Text = currentPatchToPoke.Author; txtPokePatchDesc.Text = currentPatchToPoke.Description; txtPokePatchName.Text = currentPatchToPoke.Name; txtPokePatchInternalName.Text = currentPatchToPoke.MapInternalName; //txtPokePatchMapID.Text = currentPatchToPoke.MapID.ToString(CultureInfo.InvariantCulture); // Set Visibility PokePatchControls.Visibility = Visibility.Visible; } else { MetroMessageBox.Show("You can't poke a patch from Alteration/Ascension. Convert it to a Assembly Patch first"); return; } } // Set Screenshot if (currentPatchToPoke.Screenshot == null) { // Set default var source = new Uri(@"/Assembly;component/Metro/Images/super_patcher.png", UriKind.Relative); imgPokePreview.Source = new BitmapImage(source); } else { var image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(currentPatchToPoke.Screenshot); image.EndInit(); imgPokePreview.Source = image; } } catch (Exception ex) { MetroException.Show(ex); } }
private static void WriteLocaleChanges(Patch patch, IWriter writer) { if (patch.LanguageChanges.Count == 0) return; var startPos = WriteBlockHeader(writer, AssemblyPatchBlockID.Locl); writer.WriteByte(0); // Version 0 // Write change data for each language writer.WriteByte((byte)patch.LanguageChanges.Count); foreach (var language in patch.LanguageChanges) { writer.WriteByte(language.LanguageIndex); // Write the change data for each string in the language writer.WriteInt32(language.LocaleChanges.Count); foreach (var change in language.LocaleChanges) { writer.WriteInt32(change.Index); writer.WriteUTF8(change.NewValue); } } EndBlock(writer, startPos); }