(StuduiJikkenshitsu): moved to ArcFormats project.

added encryption scheme query.
This commit is contained in:
morkt 2018-12-23 14:30:01 +04:00
parent c18672f1d4
commit 761ec768b1
10 changed files with 104 additions and 14 deletions

View File

@ -306,6 +306,12 @@
<Compile Include="Slg\ImageTIM.cs" />
<Compile Include="Speed\ArcARC.cs" />
<Compile Include="Stack\ArcGPK.cs" />
<Compile Include="StudioJikkenshitsu\ImageDAT.cs" />
<Compile Include="StudioJikkenshitsu\ImageGRD.cs" />
<Compile Include="StudioJikkenshitsu\SjTransform.cs" />
<Compile Include="StudioJikkenshitsu\WidgetSJDAT.xaml.cs">
<DependentUpon>WidgetSJDAT.xaml</DependentUpon>
</Compile>
<Compile Include="StudioSakura\ArcDAT.cs" />
<Compile Include="Silky\ImageGRD.cs" />
<Compile Include="Slg\ArcSPD.cs" />
@ -575,6 +581,7 @@
<DependentUpon>WidgetTactics.xaml</DependentUpon>
</Compile>
<Compile Include="Tail\ArcCAF.cs" />
<Compile Include="Tail\ArcPKG.cs" />
<Compile Include="Tail\ImageCFP.cs" />
<Compile Include="Tamamo\ArcPCK.cs" />
<Compile Include="Tamamo\WidgetPCK.xaml.cs">
@ -1094,6 +1101,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="StudioJikkenshitsu\WidgetSJDAT.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Tactics\WidgetTactics.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -789,5 +789,17 @@ namespace GameRes.Formats.Properties {
this["LEAFTitle"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string SJDatTitle {
get {
return ((string)(this["SJDatTitle"]));
}
set {
this["SJDatTitle"] = value;
}
}
}
}

View File

@ -194,5 +194,8 @@
<Setting Name="LEAFTitle" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SJDatTitle" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View File

@ -29,8 +29,10 @@ using System.ComponentModel.Composition;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using GameRes.Formats.Strings;
// [010719][Studio Jikkenshitsu] Shin Gekka Bijin ~Hitori Shizuka
// [030606][Studio Jikkenshitsu] Bias {biAs+}
// [031212][Studio Jikkenshitsu] Jam n' Limit
namespace GameRes.Formats.Jikkenshitsu
@ -50,6 +52,11 @@ namespace GameRes.Formats.Jikkenshitsu
public IDictionary<string, byte[]> KnownSchemes;
}
internal class SjOptions : ResourceOptions
{
public byte[] Key;
}
[Export(typeof(ImageFormat))]
public class SpDatFormat : ImageFormat
{
@ -63,11 +70,7 @@ namespace GameRes.Formats.Jikkenshitsu
Signatures = new uint[] { 0x010003, 0x010007, 0x01000B, 0x010046, 0 };
}
// Futanari Clinic Karte #1
// static readonly byte[] DefaultKey = { 10, 0, 5, 10, 11, 0, 9, 0, 1, 13, 5, 2, 3, 5, 6, 4 };
// Jam n' Limit
static readonly byte[] DefaultKey = { 12, 5, 0, 8, 5, 1, 2, 10, 4, 8, 2, 3, 9, 6, 0, 1 };
byte[] DefaultKey = null;
public override ImageMetaData ReadMetaData (IBinaryStream file)
{
@ -77,14 +80,24 @@ namespace GameRes.Formats.Jikkenshitsu
int flags = header.ToUInt16 (0);
if ((flags & ~0xFF) != 0)
return null;
return new SpMetaData {
var info = new SpMetaData {
Width = header.ToUInt16 (0x16),
Height = header.ToUInt16 (0x18),
BPP = 8,
Flags = flags,
Colors = header.ToUInt16 (0x1E),
Key = DefaultKey,
};
if (info.IsEncrypted)
{
if (null == DefaultKey)
{
DefaultKey = QueryKey (file.Name);
if (null == DefaultKey)
return null;
}
info.Key = DefaultKey;
}
return info;
}
public override ImageData Read (IBinaryStream file, ImageMetaData info)
@ -106,6 +119,30 @@ namespace GameRes.Formats.Jikkenshitsu
get { return DefaultScheme; }
set { DefaultScheme = (SjSchemeMap)value; }
}
public override ResourceOptions GetDefaultOptions ()
{
return new SjOptions { Key = GetKey (Properties.Settings.Default.SJDatTitle) };
}
public override object GetAccessWidget ()
{
return new GUI.WidgetSJDAT (DefaultScheme.KnownSchemes.Keys);
}
byte[] QueryKey (string filename)
{
var options = Query<SjOptions> (arcStrings.ArcImageEncrypted);
return options.Key;
}
byte[] GetKey (string title)
{
byte[] key = null;
if (!string.IsNullOrEmpty (title))
DefaultScheme.KnownSchemes.TryGetValue (title, out key);
return key;
}
}
internal class SpReader
@ -124,7 +161,7 @@ namespace GameRes.Formats.Jikkenshitsu
m_input = input;
m_info = info;
m_output = new byte[info.Width * info.Height];
m_stride = (int)info.Width;
m_stride = info.iWidth;
}
public byte[] Unpack ()
@ -210,8 +247,8 @@ namespace GameRes.Formats.Jikkenshitsu
byte[] ConvertToRgbA (byte[] alpha)
{
m_stride = (int)m_info.Width * 4;
var pixels = new byte[m_stride * (int)m_info.Height];
m_stride = m_info.iWidth * 4;
var pixels = new byte[m_stride * m_info.iHeight];
var colors = Palette.Colors;
int dst = 0;
for (int src = 0; src < m_output.Length; ++src)

View File

@ -51,7 +51,7 @@ namespace GameRes.Formats.Jikkenshitsu
public override uint Signature { get { return 0x20445247; } } // 'GRD '
// Giin Oyako
static readonly byte[] DefaultKey = { 0xF, 0, 1, 2, 8, 5, 0xA, 0xB, 5, 9, 0xE, 0xD, 1, 8, 0, 6 };
static readonly byte[] DefaultKey = { 15, 0, 1, 2, 8, 5, 10, 11, 5, 9, 14, 13, 1, 8, 0, 6 };
public override ImageMetaData ReadMetaData (IBinaryStream file)
{

View File

@ -0,0 +1,9 @@
<StackPanel x:Class="GameRes.Formats.GUI.WidgetSJDAT"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="clr-namespace:GameRes.Formats.Properties"
MaxWidth="250" Orientation="Vertical">
<ComboBox Name="Title"
SelectedValue="{Binding Source={x:Static p:Settings.Default}, Path=SJDatTitle, Mode=TwoWay}"
Width="200" HorizontalAlignment="Left"/>
</StackPanel>

View File

@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
namespace GameRes.Formats.GUI
{
/// <summary>
/// Interaction logic for WidgetSJDAT.xaml
/// </summary>
public partial class WidgetSJDAT : StackPanel
{
public WidgetSJDAT (IEnumerable<string> known_schemes)
{
InitializeComponent ();
this.Title.ItemsSource = known_schemes.OrderBy (x => x);
}
}
}

View File

@ -196,6 +196,9 @@
<setting name="LEAFTitle" serializeAs="String">
<value />
</setting>
<setting name="SJDatTitle" serializeAs="String">
<value />
</setting>
</GameRes.Formats.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup>

View File

@ -139,9 +139,6 @@
<Compile Include="Rune\ArcYK.cs" />
<Compile Include="Sarang\ImageABC.cs" />
<Compile Include="Sogna\ArcSGS.cs" />
<Compile Include="StudioJikkenshitsu\ImageDAT.cs" />
<Compile Include="StudioJikkenshitsu\ImageGRD.cs" />
<Compile Include="StudioJikkenshitsu\SjTransform.cs" />
<Compile Include="Tako\ArcMPK.cs" />
<Compile Include="Tetratech\ArcBND.cs" />
<Compile Include="Tigerman\ArcCHR.cs" />