diff --git a/ArcFormats/AnimeGameSystem/ArcDAT.cs b/ArcFormats/AnimeGameSystem/ArcDAT.cs index af562c05..5d6397e6 100644 --- a/ArcFormats/AnimeGameSystem/ArcDAT.cs +++ b/ArcFormats/AnimeGameSystem/ArcDAT.cs @@ -2,7 +2,7 @@ //! \date Thu Nov 05 04:40:35 2015 //! \brief AnimeGameSystem resource archive. // -// Copyright (C) 2015 by morkt +// Copyright (C) 2015-2016 by morkt // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to @@ -27,6 +27,8 @@ using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.IO; +using GameRes.Formats.Properties; +using GameRes.Formats.Strings; using GameRes.Utility; namespace GameRes.Formats.Ags @@ -67,7 +69,102 @@ namespace GameRes.Formats.Ags dir.Add (entry); index_offset += 0x18; } + var arc_name = Path.GetFileName (file.Name); + if (EncryptedArchives.Contains (arc_name)) + { + var options = Query (arcStrings.AGSMightBeEncrypted); + EncryptionKey key; + if (options.Scheme.FileMap.TryGetValue (arc_name, out key)) + return new DatArchive (file, this, dir, key); + } return new ArcFile (file, this, dir); } + + public override Stream OpenEntry (ArcFile arc, Entry entry) + { + var earc = arc as DatArchive; + if (null == earc) + return base.OpenEntry (arc, entry); + var data = arc.File.View.ReadBytes (entry.Offset, entry.Size); + byte key = earc.Key.Initial; + for (int i = 0; i < data.Length; ++i) + { + data[i] ^= key; + key += earc.Key.Increment; + } + return new MemoryStream (data); + } + + public static readonly EncryptionScheme DefaultScheme = new EncryptionScheme { + FileMap = new Dictionary() + }; + + public override ResourceOptions GetDefaultOptions () + { + return new AgsOptions { Scheme = GetScheme (Settings.Default.AGSTitle) }; + } + + public override object GetAccessWidget () + { + return new GUI.WidgetAGS(); + } + + public static EncryptionScheme GetScheme (string title) + { + EncryptionScheme scheme; + if (string.IsNullOrEmpty (title) || !KnownSchemes.TryGetValue (title, out scheme)) + scheme = DefaultScheme; + return scheme; + } + + public static Dictionary KnownSchemes = new Dictionary(); + static HashSet EncryptedArchives = new HashSet(); + + public override ResourceScheme Scheme + { + get { return new AgsScheme { KnownSchemes = KnownSchemes, EncryptedArchives = EncryptedArchives }; } + set + { + var ags = (AgsScheme)value; + KnownSchemes = ags.KnownSchemes; + EncryptedArchives = ags.EncryptedArchives; + } + } + } + + internal class DatArchive : ArcFile + { + public EncryptionKey Key; + + public DatArchive (ArcView arc, ArchiveFormat impl, ICollection dir, EncryptionKey key) + : base (arc, impl, dir) + { + Key = key; + } + } + + internal class AgsOptions : ResourceOptions + { + public EncryptionScheme Scheme; + } + + [Serializable] + public struct EncryptionKey + { + public byte Initial; + public byte Increment; + } + + [Serializable] + public class EncryptionScheme + { + public Dictionary FileMap; + } + + [Serializable] + public class AgsScheme : ResourceScheme + { + public Dictionary KnownSchemes; + public HashSet EncryptedArchives; } } diff --git a/ArcFormats/AnimeGameSystem/WidgetAGS.xaml b/ArcFormats/AnimeGameSystem/WidgetAGS.xaml new file mode 100644 index 00000000..e8599cf2 --- /dev/null +++ b/ArcFormats/AnimeGameSystem/WidgetAGS.xaml @@ -0,0 +1,7 @@ + + + diff --git a/ArcFormats/AnimeGameSystem/WidgetAGS.xaml.cs b/ArcFormats/AnimeGameSystem/WidgetAGS.xaml.cs new file mode 100644 index 00000000..b01aecc9 --- /dev/null +++ b/ArcFormats/AnimeGameSystem/WidgetAGS.xaml.cs @@ -0,0 +1,22 @@ +using System.Linq; +using System.Windows.Controls; +using GameRes.Formats.Ags; +using GameRes.Formats.Strings; + +namespace GameRes.Formats.GUI +{ + /// + /// Interaction logic for WidgetAGS.xaml + /// + public partial class WidgetAGS : StackPanel + { + public WidgetAGS() + { + InitializeComponent(); + var keys = new string[] { arcStrings.ArcNoEncryption }; + Scheme.ItemsSource = keys.Concat (DatOpener.KnownSchemes.Keys.OrderBy (x => x)); + if (-1 == Scheme.SelectedIndex) + Scheme.SelectedIndex = 0; + } + } +} diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 161bf0da..dc2833d2 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -67,6 +67,9 @@ + + WidgetAGS.xaml + @@ -495,6 +498,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ArcFormats/Properties/Settings.Designer.cs b/ArcFormats/Properties/Settings.Designer.cs index 374e085c..20d22d5b 100644 --- a/ArcFormats/Properties/Settings.Designer.cs +++ b/ArcFormats/Properties/Settings.Designer.cs @@ -513,5 +513,17 @@ namespace GameRes.Formats.Properties { this["AZScriptScheme"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string AGSTitle { + get { + return ((string)(this["AGSTitle"])); + } + set { + this["AGSTitle"] = value; + } + } } } diff --git a/ArcFormats/Properties/Settings.settings b/ArcFormats/Properties/Settings.settings index a4bf7820..7dd944dd 100644 --- a/ArcFormats/Properties/Settings.settings +++ b/ArcFormats/Properties/Settings.settings @@ -125,5 +125,8 @@ + + + \ No newline at end of file diff --git a/ArcFormats/Strings/arcStrings.Designer.cs b/ArcFormats/Strings/arcStrings.Designer.cs index 7fa42da5..9e366265 100644 --- a/ArcFormats/Strings/arcStrings.Designer.cs +++ b/ArcFormats/Strings/arcStrings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34209 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -60,6 +60,16 @@ namespace GameRes.Formats.Strings { } } + /// + /// Looks up a localized string similar to Archive contents might be encrypted, + ///choose appropriate encryption scheme.. + /// + public static string AGSMightBeEncrypted { + get { + return ResourceManager.GetString("AGSMightBeEncrypted", resourceCulture); + } + } + /// /// Looks up a localized string similar to Base archive. /// diff --git a/ArcFormats/Strings/arcStrings.ko-KR.resx b/ArcFormats/Strings/arcStrings.ko-KR.resx index f045b63c..c163f8e7 100644 --- a/ArcFormats/Strings/arcStrings.ko-KR.resx +++ b/ArcFormats/Strings/arcStrings.ko-KR.resx @@ -372,4 +372,9 @@ Try to guess translation pending + + Archive contents might be encrypted, +choose appropriate encryption scheme. + translation pending + \ No newline at end of file diff --git a/ArcFormats/Strings/arcStrings.resx b/ArcFormats/Strings/arcStrings.resx index be6da685..f7e4df92 100644 --- a/ArcFormats/Strings/arcStrings.resx +++ b/ArcFormats/Strings/arcStrings.resx @@ -367,4 +367,8 @@ Choose appropriate encryption scheme. Try to guess + + Archive contents might be encrypted, +choose appropriate encryption scheme. + \ No newline at end of file diff --git a/ArcFormats/Strings/arcStrings.ru-RU.resx b/ArcFormats/Strings/arcStrings.ru-RU.resx index e6d367b0..a30709f2 100644 --- a/ArcFormats/Strings/arcStrings.ru-RU.resx +++ b/ArcFormats/Strings/arcStrings.ru-RU.resx @@ -117,6 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Содержимое архива может быть зашифровано, +выберите подходящий способ шифрования. + Базовый архив diff --git a/ArcFormats/Strings/arcStrings.zh-Hans.resx b/ArcFormats/Strings/arcStrings.zh-Hans.resx index 679e1b67..0af35ec5 100644 --- a/ArcFormats/Strings/arcStrings.zh-Hans.resx +++ b/ArcFormats/Strings/arcStrings.zh-Hans.resx @@ -367,4 +367,9 @@ 尝试猜测 + + Archive contents might be encrypted, +choose appropriate encryption scheme. + translation pending + \ No newline at end of file diff --git a/ArcFormats/app.config b/ArcFormats/app.config index f3cb6ae3..02fbcabf 100644 --- a/ArcFormats/app.config +++ b/ArcFormats/app.config @@ -127,6 +127,9 @@ + + +