mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 20:04:13 +08:00
(RpgMaker): moved to Experimental project.
This commit is contained in:
parent
63e321ca62
commit
bb8d3dadb8
@ -269,9 +269,6 @@
|
|||||||
<Compile Include="RealLive\ImageG00Jpeg.cs" />
|
<Compile Include="RealLive\ImageG00Jpeg.cs" />
|
||||||
<Compile Include="ResourceSettings.cs" />
|
<Compile Include="ResourceSettings.cs" />
|
||||||
<Compile Include="Rits\ImageHBM.cs" />
|
<Compile Include="Rits\ImageHBM.cs" />
|
||||||
<Compile Include="RPGMaker\ArcRGSS.cs" />
|
|
||||||
<Compile Include="RPGMaker\AudioRPGMV.cs" />
|
|
||||||
<Compile Include="RPGMaker\ImageRPGMV.cs" />
|
|
||||||
<Compile Include="RPM\ArcZENOS.cs" />
|
<Compile Include="RPM\ArcZENOS.cs" />
|
||||||
<Compile Include="rUGP\AudioRHA.cs" />
|
<Compile Include="rUGP\AudioRHA.cs" />
|
||||||
<Compile Include="Lilim\ArcFGA.cs" />
|
<Compile Include="Lilim\ArcFGA.cs" />
|
||||||
|
@ -67,6 +67,7 @@
|
|||||||
<Reference Include="System.Data.SQLite">
|
<Reference Include="System.Data.SQLite">
|
||||||
<HintPath>..\packages\System.Data.SQLite.Core.1.0.106.0\lib\net46\System.Data.SQLite.dll</HintPath>
|
<HintPath>..\packages\System.Data.SQLite.Core.1.0.106.0\lib\net46\System.Data.SQLite.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="System.Web.Extensions" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
@ -79,6 +80,9 @@
|
|||||||
<Compile Include="CellWorks\ArcDB.cs" />
|
<Compile Include="CellWorks\ArcDB.cs" />
|
||||||
<Compile Include="Opus\AudioOPUS.cs" />
|
<Compile Include="Opus\AudioOPUS.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="RPGMaker\ArcRGSS.cs" />
|
||||||
|
<Compile Include="RPGMaker\AudioRPGMV.cs" />
|
||||||
|
<Compile Include="RPGMaker\ImageRPGMV.cs" />
|
||||||
<Compile Include="WebP\ImageWEBP.cs" />
|
<Compile Include="WebP\ImageWEBP.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -23,12 +23,7 @@
|
|||||||
// IN THE SOFTWARE.
|
// IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.ComponentModel.Composition;
|
using System.ComponentModel.Composition;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using GameRes.Utility;
|
|
||||||
using NVorbis;
|
|
||||||
|
|
||||||
namespace GameRes.Formats.RPGMaker
|
namespace GameRes.Formats.RPGMaker
|
||||||
{
|
{
|
||||||
@ -45,11 +40,17 @@ namespace GameRes.Formats.RPGMaker
|
|||||||
var header = file.ReadHeader (0x14);
|
var header = file.ReadHeader (0x14);
|
||||||
if (header[4] != 'V')
|
if (header[4] != 'V')
|
||||||
return null;
|
return null;
|
||||||
var key = RpgmvpFormat.DefaultKey;
|
var key = RpgmvDecryptor.LastKey ?? RpgmvDecryptor.FindKeyFor (file.Name);
|
||||||
|
if (null == key)
|
||||||
|
return null;
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
header[0x10+i] ^= key[i];
|
header[0x10+i] ^= key[i];
|
||||||
if (!header.AsciiEqual (0x10, "OggS"))
|
if (!header.AsciiEqual (0x10, "OggS"))
|
||||||
|
{
|
||||||
|
RpgmvDecryptor.LastKey = null;
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
RpgmvDecryptor.LastKey = key;
|
||||||
var ogg = RpgmvDecryptor.DecryptStream (file, key);
|
var ogg = RpgmvDecryptor.DecryptStream (file, key);
|
||||||
return OggAudio.Instance.TryOpen (ogg);
|
return OggAudio.Instance.TryOpen (ogg);
|
||||||
}
|
}
|
@ -23,9 +23,12 @@
|
|||||||
// IN THE SOFTWARE.
|
// IN THE SOFTWARE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.Composition;
|
using System.ComponentModel.Composition;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Media;
|
using System.Text;
|
||||||
|
using System.Web.Script.Serialization;
|
||||||
|
|
||||||
namespace GameRes.Formats.RPGMaker
|
namespace GameRes.Formats.RPGMaker
|
||||||
{
|
{
|
||||||
@ -41,20 +44,22 @@ namespace GameRes.Formats.RPGMaker
|
|||||||
public override string Description { get { return "RPG Maker engine image format"; } }
|
public override string Description { get { return "RPG Maker engine image format"; } }
|
||||||
public override uint Signature { get { return 0x4D475052; } } // 'RPGMV'
|
public override uint Signature { get { return 0x4D475052; } } // 'RPGMV'
|
||||||
|
|
||||||
internal static readonly byte[] DefaultKey = {
|
|
||||||
0x77, 0x4E, 0x46, 0x45, 0xFC, 0x43, 0x2F, 0x71, 0x47, 0x95, 0xA2, 0x43, 0xE5, 0x10, 0x13, 0xD8
|
|
||||||
};
|
|
||||||
|
|
||||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||||
{
|
{
|
||||||
var header = file.ReadHeader (0x14);
|
var header = file.ReadHeader (0x14);
|
||||||
if (header[4] != 'V')
|
if (header[4] != 'V')
|
||||||
return null;
|
return null;
|
||||||
var key = DefaultKey;
|
var key = RpgmvDecryptor.LastKey ?? RpgmvDecryptor.FindKeyFor (file.Name);
|
||||||
|
if (null == key)
|
||||||
|
return null;
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
header[0x10+i] ^= key[i];
|
header[0x10+i] ^= key[i];
|
||||||
if (!header.AsciiEqual (0x10, "\x89PNG"))
|
if (!header.AsciiEqual (0x10, "\x89PNG"))
|
||||||
|
{
|
||||||
|
RpgmvDecryptor.LastKey = null;
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
RpgmvDecryptor.LastKey = key;
|
||||||
using (var png = RpgmvDecryptor.DecryptStream (file, key, true))
|
using (var png = RpgmvDecryptor.DecryptStream (file, key, true))
|
||||||
{
|
{
|
||||||
var info = Png.ReadMetaData (png);
|
var info = Png.ReadMetaData (png);
|
||||||
@ -92,8 +97,66 @@ namespace GameRes.Formats.RPGMaker
|
|||||||
var header = input.ReadBytes (key.Length);
|
var header = input.ReadBytes (key.Length);
|
||||||
for (int i = 0; i < key.Length; ++i)
|
for (int i = 0; i < key.Length; ++i)
|
||||||
header[i] ^= key[i];
|
header[i] ^= key[i];
|
||||||
var result = new PrefixStream (header, new StreamRegion (input.AsStream, 0x20, leave_open));
|
var result = new PrefixStream (header, new StreamRegion (input.AsStream, input.Position, leave_open));
|
||||||
return new BinaryStream (result, input.Name);
|
return new BinaryStream (result, input.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static byte[] GetKeyFromString (string hex)
|
||||||
|
{
|
||||||
|
if ((hex.Length & 1) != 0)
|
||||||
|
throw new System.ArgumentException ("invalid key string");
|
||||||
|
var key = new byte[hex.Length/2];
|
||||||
|
for (int i = 0; i < key.Length; ++i)
|
||||||
|
{
|
||||||
|
key[i] = (byte)(HexToInt (hex[i * 2]) << 4 | HexToInt (hex[i * 2 + 1]));
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int HexToInt (char x)
|
||||||
|
{
|
||||||
|
if (char.IsDigit (x))
|
||||||
|
return x - '0';
|
||||||
|
else
|
||||||
|
return char.ToUpper (x) - 'A' + 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
static byte[] ParseSystemJson (string filename)
|
||||||
|
{
|
||||||
|
var json = File.ReadAllText (filename, Encoding.UTF8);
|
||||||
|
var serializer = new JavaScriptSerializer();
|
||||||
|
var sys = serializer.DeserializeObject (json) as IDictionary;
|
||||||
|
if (null == sys)
|
||||||
|
return null;
|
||||||
|
var key = sys["encryptionKey"] as string;
|
||||||
|
if (null == key)
|
||||||
|
return null;
|
||||||
|
return GetKeyFromString (key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] FindKeyFor (string filename)
|
||||||
|
{
|
||||||
|
foreach (var system_filename in FindSystemJson (filename))
|
||||||
|
{
|
||||||
|
if (File.Exists (system_filename))
|
||||||
|
return ParseSystemJson (system_filename);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static IEnumerable<string> FindSystemJson (string filename)
|
||||||
|
{
|
||||||
|
var dir_name = Path.GetDirectoryName (filename);
|
||||||
|
yield return Path.Combine (dir_name, @"..\..\data\System.json");
|
||||||
|
yield return Path.Combine (dir_name, @"..\..\..\www\data\System.json");
|
||||||
|
yield return Path.Combine (dir_name, @"..\data\System.json");
|
||||||
|
yield return Path.Combine (dir_name, @"data\System.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static readonly byte[] DefaultKey = {
|
||||||
|
0x77, 0x4E, 0x46, 0x45, 0xFC, 0x43, 0x2F, 0x71, 0x47, 0x95, 0xA2, 0x43, 0xE5, 0x10, 0x13, 0xD8
|
||||||
|
};
|
||||||
|
|
||||||
|
internal static byte[] LastKey = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user