mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 13:45:34 +08:00
implemented Flying Shine resource archive.
This commit is contained in:
parent
37d9461304
commit
d1bde19bb3
@ -61,6 +61,7 @@
|
||||
<Compile Include="ArcMajiro.cs" />
|
||||
<Compile Include="ArcNPA.cs" />
|
||||
<Compile Include="ArcNSA.cs" />
|
||||
<Compile Include="ArcPD.cs" />
|
||||
<Compile Include="ArcSteinsGate.cs" />
|
||||
<Compile Include="ArcXFL.cs" />
|
||||
<Compile Include="ArcXP3.cs" />
|
||||
@ -72,6 +73,9 @@
|
||||
<Compile Include="CreateONSWidget.xaml.cs">
|
||||
<DependentUpon>CreateONSWidget.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="CreatePDWidget.xaml.cs">
|
||||
<DependentUpon>CreatePDWidget.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="CreateSGWidget.xaml.cs">
|
||||
<DependentUpon>CreateSGWidget.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@ -139,6 +143,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="CreatePDWidget.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="CreateSGWidget.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
221
ArcFormats/ArcPD.cs
Normal file
221
ArcFormats/ArcPD.cs
Normal file
@ -0,0 +1,221 @@
|
||||
//! \file ArcPD.cs
|
||||
//! \date Thu Aug 14 19:10:02 2014
|
||||
//! \brief PD archive format implementation.
|
||||
//
|
||||
// Copyright (C) 2014 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
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GameRes.Formats.Properties;
|
||||
using GameRes.Formats.Strings;
|
||||
|
||||
namespace GameRes.Formats.Fs
|
||||
{
|
||||
internal class PackPlusArchive : ArcFile
|
||||
{
|
||||
public PackPlusArchive (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir)
|
||||
: base (arc, impl, dir)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class PdOptions : ResourceOptions
|
||||
{
|
||||
public bool ScrambleContents { get; set; }
|
||||
}
|
||||
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class PdOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "PD"; } }
|
||||
public override string Description { get { return arcStrings.PDDescription; } }
|
||||
public override uint Signature { get { return 0x6b636150; } } // Pack
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanCreate { get { return true; } }
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
uint version = file.View.ReadUInt32 (4);
|
||||
if (0x796c6e4f != version && 0x73756c50 != version) // 'Only' || 'Plus'
|
||||
return null;
|
||||
uint count = file.View.ReadUInt32 (0x40);
|
||||
if (count > 0x0fffff || count * 0x90 >= file.MaxOffset)
|
||||
return null;
|
||||
bool encrypted = 0x73756c50 == version;
|
||||
long cur_offset = 0x48;
|
||||
var dir = new List<Entry> ((int)count);
|
||||
for (uint i = 0; i < count; ++i)
|
||||
{
|
||||
string name = file.View.ReadString (cur_offset, 0x80);
|
||||
var entry = FormatCatalog.Instance.CreateEntry (name);
|
||||
entry.Offset = file.View.ReadInt64 (cur_offset+0x80);
|
||||
entry.Size = file.View.ReadUInt32 (cur_offset+0x88);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
if (Path.GetExtension (name).Equals (".dsf", System.StringComparison.OrdinalIgnoreCase))
|
||||
entry.Type = "script";
|
||||
dir.Add (entry);
|
||||
cur_offset += 0x90;
|
||||
}
|
||||
return encrypted ? new PackPlusArchive (file, this, dir) : new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
{
|
||||
Stream input = arc.File.CreateStream (entry.Offset, entry.Size);
|
||||
if (arc is PackPlusArchive)
|
||||
{
|
||||
MemoryStream buffer;
|
||||
using (input)
|
||||
{
|
||||
buffer = new MemoryStream ((int)entry.Size);
|
||||
input.CopyTo (buffer);
|
||||
}
|
||||
var data = buffer.GetBuffer();
|
||||
for (uint i = 0; i < entry.Size; ++i)
|
||||
data[i] = (byte)~data[i];
|
||||
buffer.Position = 0;
|
||||
input = buffer;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public override ResourceOptions GetDefaultOptions ()
|
||||
{
|
||||
return new PdOptions { ScrambleContents = Settings.Default.PDScrambleContents };
|
||||
}
|
||||
|
||||
public override object GetCreationWidget ()
|
||||
{
|
||||
return new GUI.CreatePDWidget();
|
||||
}
|
||||
|
||||
public override void Create (Stream output, IEnumerable<Entry> list, ResourceOptions options,
|
||||
EntryCallback callback)
|
||||
{
|
||||
int file_count = list.Count();
|
||||
if (file_count > 0x4000)
|
||||
throw new InvalidFormatException (arcStrings.MsgTooManyFiles);
|
||||
if (null != callback)
|
||||
callback (file_count+2, null, null);
|
||||
int callback_count = 0;
|
||||
var pd_options = GetOptions<PdOptions> (options);
|
||||
|
||||
using (var writer = new BinaryWriter (output, Encoding.ASCII, true))
|
||||
{
|
||||
writer.Write (Signature);
|
||||
if (pd_options.ScrambleContents)
|
||||
writer.Write ((uint)0x73756c50);
|
||||
else
|
||||
writer.Write ((uint)0x796c6e4f);
|
||||
output.Seek (0x38, SeekOrigin.Current);
|
||||
writer.Write (file_count);
|
||||
writer.Write ((int)0);
|
||||
long dir_offset = output.Position;
|
||||
|
||||
if (null != callback)
|
||||
callback (callback_count++, null, arcStrings.MsgWritingIndex);
|
||||
|
||||
var encoding = Encodings.cp932.WithFatalFallback();
|
||||
byte[] name_buf = new byte[0x80];
|
||||
int previous_size = 0;
|
||||
|
||||
// first, write names only
|
||||
foreach (var entry in list)
|
||||
{
|
||||
string name = Path.GetFileName (entry.Name);
|
||||
try
|
||||
{
|
||||
int size = encoding.GetBytes (name, 0, name.Length, name_buf, 0);
|
||||
for (int i = size; i < previous_size; ++i)
|
||||
name_buf[i] = 0;
|
||||
previous_size = size;
|
||||
}
|
||||
catch (EncoderFallbackException X)
|
||||
{
|
||||
throw new InvalidFileName (entry.Name, arcStrings.MsgIllegalCharacters, X);
|
||||
}
|
||||
catch (ArgumentException X)
|
||||
{
|
||||
throw new InvalidFileName (entry.Name, arcStrings.MsgFileNameTooLong, X);
|
||||
}
|
||||
writer.Write (name_buf);
|
||||
writer.BaseStream.Seek (16, SeekOrigin.Current);
|
||||
}
|
||||
|
||||
// now, write files and remember offset/sizes
|
||||
long current_offset = 0x240000 + dir_offset;
|
||||
output.Seek (current_offset, SeekOrigin.Begin);
|
||||
foreach (var entry in list)
|
||||
{
|
||||
if (null != callback)
|
||||
callback (callback_count++, entry, arcStrings.MsgAddingFile);
|
||||
|
||||
entry.Offset = current_offset;
|
||||
using (var input = File.OpenRead (entry.Name))
|
||||
{
|
||||
var size = input.Length;
|
||||
if (size > uint.MaxValue)
|
||||
throw new FileSizeException();
|
||||
current_offset += size;
|
||||
entry.Size = (uint)size;
|
||||
if (pd_options.ScrambleContents)
|
||||
CopyScrambled (input, output);
|
||||
else
|
||||
input.CopyTo (output);
|
||||
}
|
||||
}
|
||||
|
||||
if (null != callback)
|
||||
callback (callback_count++, null, arcStrings.MsgUpdatingIndex);
|
||||
|
||||
// at last, go back to directory and write offset/sizes
|
||||
dir_offset += 0x80;
|
||||
foreach (var entry in list)
|
||||
{
|
||||
writer.BaseStream.Position = dir_offset;
|
||||
writer.Write (entry.Offset);
|
||||
writer.Write ((long)entry.Size);
|
||||
dir_offset += 0x90;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CopyScrambled (Stream input, Stream output)
|
||||
{
|
||||
byte[] buffer = new byte[81920];
|
||||
for (;;)
|
||||
{
|
||||
int read = input.Read (buffer, 0, buffer.Length);
|
||||
if (0 == read)
|
||||
break;
|
||||
for (int i = 0; i < read; ++i)
|
||||
buffer[i] = (byte)~buffer[i];
|
||||
output.Write (buffer, 0, read);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
ArcFormats/CreatePDWidget.xaml
Normal file
8
ArcFormats/CreatePDWidget.xaml
Normal file
@ -0,0 +1,8 @@
|
||||
<Grid x:Class="GameRes.Formats.GUI.CreatePDWidget"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:GameRes.Formats.Strings"
|
||||
xmlns:p="clr-namespace:GameRes.Formats.Properties">
|
||||
<CheckBox Name="ScrambleContents" Content="{x:Static s:arcStrings.PDScrambleContents}" Margin="5"
|
||||
IsChecked="{Binding Source={x:Static p:Settings.Default}, Path=PDScrambleContents, Mode=TwoWay}"/>
|
||||
</Grid>
|
15
ArcFormats/CreatePDWidget.xaml.cs
Normal file
15
ArcFormats/CreatePDWidget.xaml.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace GameRes.Formats.GUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CreatePDWidget.xaml
|
||||
/// </summary>
|
||||
public partial class CreatePDWidget : Grid
|
||||
{
|
||||
public CreatePDWidget ()
|
||||
{
|
||||
InitializeComponent ();
|
||||
}
|
||||
}
|
||||
}
|
12
ArcFormats/Properties/Settings.Designer.cs
generated
12
ArcFormats/Properties/Settings.Designer.cs
generated
@ -165,5 +165,17 @@ namespace GameRes.Formats.Properties {
|
||||
this["AMIUseBaseArchive"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("False")]
|
||||
public bool PDScrambleContents {
|
||||
get {
|
||||
return ((bool)(this["PDScrambleContents"]));
|
||||
}
|
||||
set {
|
||||
this["PDScrambleContents"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,5 +38,8 @@
|
||||
<Setting Name="AMIUseBaseArchive" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
<Setting Name="PDScrambleContents" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
27
ArcFormats/Strings/arcStrings.Designer.cs
generated
27
ArcFormats/Strings/arcStrings.Designer.cs
generated
@ -261,6 +261,15 @@ namespace GameRes.Formats.Strings {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Number of files exceedes archive limit..
|
||||
/// </summary>
|
||||
public static string MsgTooManyFiles {
|
||||
get {
|
||||
return ResourceManager.GetString("MsgTooManyFiles", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Updating index....
|
||||
/// </summary>
|
||||
@ -333,6 +342,24 @@ namespace GameRes.Formats.Strings {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Flying Shine resource archive.
|
||||
/// </summary>
|
||||
public static string PDDescription {
|
||||
get {
|
||||
return ResourceManager.GetString("PDDescription", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Scramble contents.
|
||||
/// </summary>
|
||||
public static string PDScrambleContents {
|
||||
get {
|
||||
return ResourceManager.GetString("PDScrambleContents", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Amaterasu Translations Muv-Luv script file.
|
||||
/// </summary>
|
||||
|
@ -186,6 +186,9 @@ predefined encryption scheme.</value>
|
||||
<data name="MsgInvalidImageFormat" xml:space="preserve">
|
||||
<value>{0}: image format not recognized.</value>
|
||||
</data>
|
||||
<data name="MsgTooManyFiles" xml:space="preserve">
|
||||
<value>Number of files exceedes archive limit.</value>
|
||||
</data>
|
||||
<data name="MsgUpdatingIndex" xml:space="preserve">
|
||||
<value>Updating index...</value>
|
||||
</data>
|
||||
@ -210,6 +213,12 @@ predefined encryption scheme.</value>
|
||||
<data name="ONSCompressionNone" xml:space="preserve">
|
||||
<value>None</value>
|
||||
</data>
|
||||
<data name="PDDescription" xml:space="preserve">
|
||||
<value>Flying Shine resource archive</value>
|
||||
</data>
|
||||
<data name="PDScrambleContents" xml:space="preserve">
|
||||
<value>Scramble contents</value>
|
||||
</data>
|
||||
<data name="SCRDescription" xml:space="preserve">
|
||||
<value>Amaterasu Translations Muv-Luv script file</value>
|
||||
</data>
|
||||
|
@ -171,6 +171,9 @@
|
||||
<data name="MsgInvalidImageFormat" xml:space="preserve">
|
||||
<value>{0}: не удалось распознать формат изображения.</value>
|
||||
</data>
|
||||
<data name="MsgTooManyFiles" xml:space="preserve">
|
||||
<value>Количество файлов превышает ограничения архива.</value>
|
||||
</data>
|
||||
<data name="MsgUpdatingIndex" xml:space="preserve">
|
||||
<value>Обновляется оглавление...</value>
|
||||
</data>
|
||||
@ -186,6 +189,9 @@
|
||||
<data name="ONSCompressionNone" xml:space="preserve">
|
||||
<value>Без компрессии</value>
|
||||
</data>
|
||||
<data name="PDScrambleContents" xml:space="preserve">
|
||||
<value>Шифровать содержимое</value>
|
||||
</data>
|
||||
<data name="SGLabelEncoding" xml:space="preserve">
|
||||
<value>Кодировка имён файлов</value>
|
||||
</data>
|
||||
|
@ -11,7 +11,7 @@
|
||||
<value>NotEncrypted</value>
|
||||
</setting>
|
||||
<setting name="XP3Scheme" serializeAs="String">
|
||||
<value/>
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="YPFKey" serializeAs="String">
|
||||
<value>4294967295</value>
|
||||
@ -35,11 +35,14 @@
|
||||
<value>None</value>
|
||||
</setting>
|
||||
<setting name="AMIBaseArchive" serializeAs="String">
|
||||
<value/>
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="AMIUseBaseArchive" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
<setting name="PDScrambleContents" serializeAs="String">
|
||||
<value>False</value>
|
||||
</setting>
|
||||
</GameRes.Formats.Properties.Settings>
|
||||
</userSettings>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user