diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 6ba86b06..965b6bcf 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -133,6 +133,9 @@ + + WidgetNPK.xaml + @@ -593,6 +596,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ArcFormats/NitroPlus/ArcNPK.cs b/ArcFormats/NitroPlus/ArcNPK.cs index e3a06f82..4b035826 100644 --- a/ArcFormats/NitroPlus/ArcNPK.cs +++ b/ArcFormats/NitroPlus/ArcNPK.cs @@ -28,8 +28,9 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using System.IO; using System.IO.Compression; -using System.Linq; using System.Security.Cryptography; +using GameRes.Formats.Properties; +using GameRes.Formats.Strings; namespace GameRes.Formats.NitroPlus { @@ -47,6 +48,11 @@ namespace GameRes.Formats.NitroPlus public bool IsCompressed { get { return Size < UnpackedSize; } } } + public class Npk2Options : ResourceOptions + { + public byte[] Key; + } + internal class NpkArchive : ArcFile { public readonly Aes Encryption; @@ -141,8 +147,14 @@ namespace GameRes.Formats.NitroPlus entry.UnpackedSize = index.ReadUInt32(); index.Read (name_buffer, 0, 0x20); // skip int segment_count = index.ReadInt32(); - if (segment_count <= 0) + if (segment_count < 0) return null; + if (0 == segment_count) + { + entry.Offset = 0; + dir.Add (entry); + continue; + } entry.Segments.Capacity = segment_count; uint packed_size = 0; bool is_packed = false; @@ -169,6 +181,8 @@ namespace GameRes.Formats.NitroPlus public override Stream OpenEntry (ArcFile arc, Entry entry) { + if (0 == entry.Size) + return Stream.Null; var narc = arc as NpkArchive; var nent = entry as NpkEntry; if (null == narc || null == nent) @@ -183,11 +197,28 @@ namespace GameRes.Formats.NitroPlus return new NpkStream (narc, nent); } + public override ResourceOptions GetDefaultOptions () + { + return new Npk2Options { Key = GetKey (Settings.Default.NPKScheme) }; + } + + public override object GetAccessWidget () + { + return new GUI.WidgetNPK(); + } + byte[] QueryEncryption () { - if (0 == KnownKeys.Count) - return null; - return KnownKeys.Values.First(); + var options = Query (arcStrings.ArcEncryptedNotice); + return options.Key; + } + + byte[] GetKey (string title) + { + byte[] key; + if (KnownKeys.TryGetValue (title, out key)) + return key; + return key; } } diff --git a/ArcFormats/NitroPlus/WidgetNPK.xaml b/ArcFormats/NitroPlus/WidgetNPK.xaml new file mode 100644 index 00000000..a2f9554f --- /dev/null +++ b/ArcFormats/NitroPlus/WidgetNPK.xaml @@ -0,0 +1,9 @@ + + + diff --git a/ArcFormats/NitroPlus/WidgetNPK.xaml.cs b/ArcFormats/NitroPlus/WidgetNPK.xaml.cs new file mode 100644 index 00000000..ba9a249d --- /dev/null +++ b/ArcFormats/NitroPlus/WidgetNPK.xaml.cs @@ -0,0 +1,18 @@ +using System.Windows.Controls; +using System.Linq; +using GameRes.Formats.NitroPlus; + +namespace GameRes.Formats.GUI +{ + /// + /// Interaction logic for WidgetNPK.xaml + /// + public partial class WidgetNPK : Grid + { + public WidgetNPK () + { + InitializeComponent(); + Scheme.ItemsSource = NpkOpener.KnownKeys.Keys.OrderBy (x => x); + } + } +} diff --git a/ArcFormats/Properties/Settings.Designer.cs b/ArcFormats/Properties/Settings.Designer.cs index b820742d..5dc31d96 100644 --- a/ArcFormats/Properties/Settings.Designer.cs +++ b/ArcFormats/Properties/Settings.Designer.cs @@ -585,5 +585,17 @@ namespace GameRes.Formats.Properties { this["BELLTitle"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string NPKScheme { + get { + return ((string)(this["NPKScheme"])); + } + set { + this["NPKScheme"] = value; + } + } } } diff --git a/ArcFormats/Properties/Settings.settings b/ArcFormats/Properties/Settings.settings index 16dc5afc..a881c3cd 100644 --- a/ArcFormats/Properties/Settings.settings +++ b/ArcFormats/Properties/Settings.settings @@ -143,5 +143,8 @@ + + + \ No newline at end of file diff --git a/ArcFormats/app.config b/ArcFormats/app.config index fe5f6783..f8cdb6fc 100644 --- a/ArcFormats/app.config +++ b/ArcFormats/app.config @@ -145,6 +145,9 @@ + + +