(ODN): recognize audio entries.

This commit is contained in:
morkt 2018-06-06 00:37:14 +04:00
parent 3dabada74e
commit c3dee20cba
10 changed files with 87 additions and 1 deletions

View File

@ -753,5 +753,17 @@ namespace GameRes.Formats.Properties {
this["PFSEncodingCP"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("44100")]
public uint ODNAudioSampleRate {
get {
return ((uint)(this["ODNAudioSampleRate"]));
}
set {
this["ODNAudioSampleRate"] = value;
}
}
}
}

View File

@ -185,5 +185,8 @@
<Setting Name="PFSEncodingCP" Type="System.Int32" Scope="User">
<Value Profile="(Default)">65001</Value>
</Setting>
<Setting Name="ODNAudioSampleRate" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">44100</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -606,6 +606,15 @@ namespace GameRes.Formats.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Default audio sampling rate.
/// </summary>
public static string ODNAudioSampleRate {
get {
return ResourceManager.GetString("ODNAudioSampleRate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Fix Ogg files checksums.
/// </summary>

View File

@ -501,4 +501,7 @@ Choose encryption scheme or enter a passphrase.</comment>
<data name="PFSEncodingCP" xml:space="preserve">
<value>Default file names encoding</value>
</data>
<data name="ODNAudioSampleRate" xml:space="preserve">
<value>Default audio sampling rate</value>
</data>
</root>

View File

@ -403,4 +403,8 @@
<value>Default file names encoding</value>
<comment>translation pending</comment>
</data>
<data name="ODNAudioSampleRate" xml:space="preserve">
<value>Default audio sampling rate</value>
<comment>translation pending</comment>
</data>
</root>

View File

@ -401,4 +401,7 @@ Choose encryption scheme or enter a passphrase.</value>
<data name="PFSEncodingCP" xml:space="preserve">
<value>Default file names encoding</value>
</data>
<data name="ODNAudioSampleRate" xml:space="preserve">
<value>Default audio sampling rate</value>
</data>
</root>

View File

@ -276,6 +276,9 @@
<value>Ключи шифрования
(требуются даже если содержимое не шифруется)</value>
</data>
<data name="ODNAudioSampleRate" xml:space="preserve">
<value>Частота дискретизации аудио</value>
</data>
<data name="OGGFixCrc" xml:space="preserve">
<value>Исправлять контрольные суммы в Ogg аудио файлах</value>
</data>

View File

@ -404,4 +404,8 @@
<value>Default file names encoding</value>
<comment>translation pending</comment>
</data>
<data name="ODNAudioSampleRate" xml:space="preserve">
<value>Default audio sampling rate</value>
<comment>translation pending</comment>
</data>
</root>

View File

@ -32,6 +32,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Media;
using GameRes.Formats.Strings;
using GameRes.Utility;
namespace GameRes.Formats.Valkyria
@ -55,7 +56,7 @@ namespace GameRes.Formats.Valkyria
}
[Export(typeof(ArchiveFormat))]
public class OdnOpener : ArchiveFormat
sealed public class OdnOpener : ArchiveFormat
{
public override string Tag { get { return "ODN"; } }
public override string Description { get { return "Valkyria resource archive"; } }
@ -63,6 +64,17 @@ namespace GameRes.Formats.Valkyria
public override bool IsHierarchic { get { return false; } }
public override bool CanWrite { get { return false; } }
public OdnOpener ()
{
Settings = new[] { AudioSampleRate };
}
FixedSetSetting AudioSampleRate = new FixedSetSetting (Properties.Settings.Default) {
Name = "ODNAudioSampleRate",
Text = arcStrings.ODNAudioSampleRate,
ValuesSet = new[] { 22050u, 44100u },
};
public override ArcFile TryOpen (ArcView file)
{
if (!file.Name.HasExtension (".odn"))
@ -92,6 +104,7 @@ namespace GameRes.Formats.Valkyria
internal static readonly Regex Image24NameRe = new Regex ("^(?:back|phii)");
internal static readonly Regex Image32NameRe = new Regex ("^(?:data|codn|cccc)");
internal static readonly Regex ScriptNameRe = new Regex ("^(?:scrp|menu|sysm)");
internal static readonly Regex AudioNameRe = new Regex ("^hime");
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
@ -102,6 +115,24 @@ namespace GameRes.Formats.Valkyria
Decrypt (data, data.Length, key);
return new BinMemoryStream (data);
}
if (AudioNameRe.IsMatch (entry.Name))
{
using (var wav = new MemoryStream (0x2C))
{
var format = new WaveFormat {
FormatTag = 1,
Channels = 1,
SamplesPerSecond = AudioSampleRate.Get<uint>(),
BlockAlign = 2,
BitsPerSample = 16,
};
format.SetBPS();
WaveAudio.WriteRiffHeader (wav, format, entry.Size);
var header = wav.ToArray();
var data = arc.File.CreateStream (entry.Offset, entry.Size);
return new PrefixStream (header, data);
}
}
var input = arc.File.CreateStream (entry.Offset, entry.Size);
if (0x5E6A6A42 == input.Signature)
{
@ -247,6 +278,11 @@ namespace GameRes.Formats.Valkyria
index_offset += 0x10;
if (m_entry_buf.AsciiEqual (0, "END_ffffffffffff"))
break;
else if (m_entry_buf.AsciiEqual (0, "HIME_END"))
{
index_offset += 8;
break;
}
var name = m_enc.GetString (m_entry_buf, 0, 8);
var offset = m_enc.GetString (m_entry_buf, 8, 8);
var entry = new Entry { Name = name, Offset = Convert.ToUInt32 (offset, 16) };
@ -254,6 +290,8 @@ namespace GameRes.Formats.Valkyria
}
foreach (var entry in m_dir)
entry.Offset += index_offset;
if (m_dir.Any() && m_dir[m_dir.Count-1].Offset == m_file.MaxOffset)
m_dir.RemoveAt (m_dir.Count-1);
}
void ReadV2 (uint record_size)
@ -321,6 +359,10 @@ namespace GameRes.Formats.Valkyria
{
entry.Type = "script";
}
else if (OdnOpener.AudioNameRe.IsMatch (entry.Name))
{
entry.Type = "audio";
}
else if (entry.Size > 4)
{
var signature = m_file.View.ReadUInt32 (entry.Offset);

View File

@ -187,6 +187,9 @@
<setting name="PFSEncodingCP" serializeAs="String">
<value>65001</value>
</setting>
<setting name="ODNAudioSampleRate" serializeAs="String">
<value>44100</value>
</setting>
</GameRes.Formats.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup>