/// <summary> /// Gets the patch infos for each <see cref="Patch"/> /// </summary> /// <param name="ipkStream">The IPK file stream</param> /// <returns>The patch infos</returns> protected IEnumerable <PatchInfo> GetPatchInfos(Stream ipkStream) { // Deserialize the IPK file var ipk = BinarySerializableHelpers.ReadFromStream <UbiArtIpkData>(ipkStream, UbiArtSettings.GetDefaultSettings(UbiArtGame.RaymanLegends, Platform.PC), RCPServices.App.GetBinarySerializerLogger()); // Enumerate every patch foreach (var patchGroup in GetPatches.GroupBy(x => x.FileName)) { // Get the file var file = ipk.Files.FindItem(x => x.Path.FileName == patchGroup.Key); // Make sure we found the file if (file == null) { throw new Exception("Patch file not found"); } // Make sure it's not compressed if (file.IsCompressed) { throw new Exception("The configuration file is compressed and can not be edited"); } // Get the offsets foreach (Patch patch in patchGroup) { // Get the offset of the byte in the file to change yield return(new PatchInfo(patch, (long)(ipk.BaseOffset + file.Offsets.First() + (uint)patch.FileOffset))); } } }
/// <summary> /// Gets the patch infos for each <see cref="Patch"/> /// </summary> /// <param name="ipkStream">The IPK file stream</param> /// <param name="name">The IPK name</param> /// <returns>The patch infos</returns> protected IEnumerable <PatchInfo> GetPatchInfos(Stream ipkStream, string name) { // Deserialize the IPK file using RCPContext context = new(String.Empty); UbiArtSettings settings = new(Game.RaymanLegends, Platform.PC); context.AddSettings(settings); BundleFile ipk = context.ReadStreamData <BundleFile>(ipkStream, name: name, endian: settings.GetEndian, leaveOpen: true); // Enumerate every patch foreach (var patchGroup in GetPatches.GroupBy(x => x.FileName)) { // Get the file BundleFile_FileEntry?file = ipk.FilePack.Files.FirstOrDefault(x => x.Path.FileName == patchGroup.Key); // Make sure we found the file if (file == null) { throw new Exception("Patch file not found"); } // Make sure it's not compressed if (file.IsCompressed) { throw new Exception("The configuration file is compressed and can not be edited"); } // Make sure the file size matches if (file.FileSize != patchGroup.First().FileSize) { throw new Exception($"File size for {file.Path} doesn't match the expected size"); } // Get the offsets foreach (Patch patch in patchGroup) { // Get the offset of the byte in the file to change yield return(new PatchInfo(patch, (long)(ipk.BootHeader.BaseOffset + file.Offsets.First() + (uint)patch.FileOffset))); } } }