/// <summary> /// Loads and decompiles the FES screen script entry and returns the script as a string. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <returns>The decompiled script.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/> or <paramref name="kifintStream"/> is null. /// </exception> public static string DecompileScreen(this KifintEntry entry, KifintStream kifintStream) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream(kifintStream)) return(FesScreen.Decompile(stream, entry.FileName)); }
/// <summary> /// Loads and decompiles the CST scene script entry and returns the human readable script as a string. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <returns>The human readable script.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/> or <paramref name="kifintStream"/> is null. /// </exception> public static string HumanReadableScene(this KifintEntry entry, KifintStream kifintStream) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream(kifintStream)) return(CstScene.HumanReadable(stream, entry.FileName)); }
/// <summary> /// Loads and decompiles the FES screen script entry and outputs it to the specified stream. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <param name="outStream">The output stream to write the decompiled script to.</param> /// <param name="encoding">The output encoding, <see cref="CatUtils.ShiftJIS"/> if null.</param> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/> or <paramref name="outStream"/> is null. /// </exception> public static void DecompileScreenToStream(this KifintEntry entry, Stream outStream, Encoding encoding = null) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream()) FesScreen.DecompileToStream(stream, entry.FileName, outStream, encoding); }
/// <summary> /// Extracts the HG-X image information ONLY from open KIFINT archive stream and does not extract the actual /// images. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <returns>The extracted <see cref="HgxImage"/> information.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/> or <paramref name="kifintStream"/> is null. /// </exception> public static HgxImage ExtractHgx(this KifintEntry entry, KifintStream kifintStream) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream(kifintStream)) return(HgxImage.Extract(stream, entry.FileName)); }
/// <summary> /// Loads and decompiles the CST scene script entry and outputs it to the specified human readable stream. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <param name="outStream">The output stream to write the human readable script to.</param> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/> or <paramref name="outStream"/> is null. /// </exception> public static void HumanReadableSceneToStream(this KifintEntry entry, Stream outStream) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream()) CstScene.HumanReadableToStream(stream, entry.FileName, outStream); }
/// <summary> /// Extracts the FES screen script from the entry. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <returns>The extracted screen script.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/> is null. /// </exception> public static FesScreen ExtractScreen(this KifintEntry entry) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream()) return(FesScreen.Extract(stream, entry.FileName)); }
/// <summary> /// Extracts the HG-X image information from the KIFINT entry's open KIFINT archive stream and saves all /// images to the output <paramref name="outputDir"/>. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <param name="outputDir">The output directory to save the images to.</param> /// <param name="options">The options for manipulating the image during extraction.</param> /// <returns>The extracted <see cref="HgxImage"/> information.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/>, <paramref name="kifintStream"/>, or <paramref name="outputDir"/> is null. /// </exception> public static HgxImage ExtractHgxAndImages(this KifintEntry entry, KifintStream kifintStream, string outputDir, HgxOptions options) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream(kifintStream)) return(HgxImage.ExtractImages(stream, entry.FileName, outputDir, options)); }
/// <summary> /// Loads and decompiles the CST scene script entry and returns the script as a string. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <returns>The decompiled script.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/> is null. /// </exception> public static string DecompileScene(this KifintEntry entry) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream()) return(CstScene.Decompile(stream, entry.FileName)); }
/// <summary> /// Loads and decompiles the CST scene script entry and outputs it to the specified file. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <param name="outFile">The output file to write the decompiled script to.</param> /// <param name="encoding">The output encoding, <see cref="CatUtils.ShiftJIS"/> if null.</param> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/> or <paramref name="outFile"/> is null. /// </exception> public static void DecompileSceneToFile(this KifintEntry entry, string outFile, Encoding encoding = null) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream()) CstScene.DecompileToFile(stream, entry.FileName, outFile, encoding); }
/// <summary> /// Extracts the ZT package from the entry. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <returns>The extracted ZT package.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/> is null. /// </exception> public static ZtPackage ExtractZt(this KifintEntry entry) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream()) return(ZtPackage.Extract(stream, entry.FileName)); }
/// <summary> /// Extracts the ZT package from the open KIFINT archive stream and saves the contained files to the output /// directory. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <param name="outputDir">The output directory to save the package files to.</param> /// <returns>The extracted ZT package.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/>, <paramref name="kifintStream"/>, or <paramref name="outputDir"/> is null. /// </exception> public static ZtPackage ExtractZtAndFiles(this KifintEntry entry, KifintStream kifintStream, string outputDir) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream(kifintStream)) return(ZtPackage.ExtractFiles(stream, entry.FileName, outputDir)); }
/// <summary> /// Loads and decompiles the ANM animation script entry and outputs it to the specified file. /// </summary> /// <param name="entry">The entry to extract from.</param> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <param name="outFile">The output file to write the decompiled script to.</param> /// <param name="encoding">The output encoding, <see cref="CatUtils.ShiftJIS"/> if null.</param> /// /// <exception cref="ArgumentNullException"> /// <paramref name="entry"/>, <paramref name="kifintStream"/>, or <paramref name="outFile"/> is null. /// </exception> public static void DecompileAnimationToFile(this KifintEntry entry, KifintStream kifintStream, string outFile, Encoding encoding = null) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } using (var stream = entry.ExtractToStream(kifintStream)) AnmAnimation.DecompileToFile(stream, entry.FileName, outFile, encoding); }
/// <summary> /// Extracts the KIFINT entry to a fixed stream of <paramref name="kifintStream"/>. /// </summary> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <param name="entry">The KIFINT entry used to locate the file.</param> /// <param name="leaveOpen"> /// True if the KIFINT archive stream should be left open even after closing the returned stream. /// </param> /// <returns> /// A fixed stream containing the data of the decrypted entry. This stream must always be disposed of, because /// it's not guaranteed to be a fixed stream of <paramref name="kifintStream"/>. This is the case when the /// length is small enough for extracting bytes to be more efficient. /// </returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="kifintStream"/> or <paramref name="entry"/> is null. /// </exception> internal static Stream ExtractToStream(KifintStream kifintStream, KifintEntry entry, bool leaveOpen) { if (kifintStream == null) { throw new ArgumentNullException(nameof(kifintStream)); } if (entry == null) { throw new ArgumentNullException(nameof(entry)); } var kifint = entry.Kifint; // Smaller streams will be faster as reading a big chunk of data all at once. if (kifint.IsEncrypted && entry.Length < 131072 * 2) // Some arbitrary power of 2 cutoff length { try { return(new MemoryStream(ExtractToBytes(kifintStream, entry))); } finally { // We need to make sure the the stream is closed by us if we're not // relying on the fixed streams to close the KIFINT archive stream. if (!leaveOpen) { kifintStream.Close(); } } } kifintStream.Open(kifint); kifintStream.Position = entry.Offset; if (kifint.IsEncrypted) { return(new BlowfishInputStream(kifint.Blowfish, kifintStream, entry.Length, leaveOpen)); } return(new FixedStream(kifintStream, entry.Length, leaveOpen)); }
/// <summary> /// Extracts the KIFINT entry file from the the entry's KIFINT archive. /// </summary> /// <param name="kifintStream">The stream to the open KIFINT archive.</param> /// <param name="entry">The KIFINT entry used to locate the file.</param> /// <returns>A byte array containing the extracted KIFINT entry's file data.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="kifintStream"/> or <paramref name="entry"/> is null. /// </exception> internal static byte[] ExtractToBytes(KifintStream kifintStream, KifintEntry entry) { if (kifintStream == null) { throw new ArgumentNullException(nameof(kifintStream)); } if (entry == null) { throw new ArgumentNullException(nameof(entry)); } var kifint = entry.Kifint; kifintStream.Open(kifint); BinaryReader reader = new BinaryReader(kifintStream); kifintStream.Position = entry.Offset; byte[] buffer = reader.ReadBytes(entry.Length); if (kifint.IsEncrypted) { kifint.Blowfish.Decrypt(buffer, entry.Length & ~7); } return(buffer); }