Skip to content

Commit

Permalink
Improve archive version detection
Browse files Browse the repository at this point in the history
 * Improve archive version detection to match the file extension
   instead of whole name. This helps decrypting games that have a
   renamed archive, for example Pokemon Uranium with a renamed archive
   "Uranium.rgssad".

   This is not a best solution as the archive version can be also detected by reading
   archive header and this is  already used in a codebase when reading from the
   archive starts. Maybe this could be later improved by refactoring.
 * Improve error reporting so that undetected RPG Maker version detection
   is told to user.
 * CLI: Add error reporting when input file is not found
  • Loading branch information
uuksu committed Jul 1, 2023
1 parent 21c071d commit c17071b
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 269 deletions.
14 changes: 11 additions & 3 deletions RPGMakerDecrypter.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ static void Main(string[] args)
Environment.Exit(1);
}

RPGMakerVersion version = RGSSAD.GetVersion(_commandLineOptions.InputPath);
if(!File.Exists(_commandLineOptions.InputPath))
{
Console.WriteLine($"RGSSAD file not found in path '{_commandLineOptions.InputPath}'");
Environment.Exit(1);
}

RPGMakerVersion version = RGSSAD.GetRPGMakerVersion(_commandLineOptions.InputPath);

if (version == RPGMakerVersion.Invalid)
if (version == RPGMakerVersion.Unknown)
{
Console.WriteLine("Invalid input file.");
Console.WriteLine("Unable to determinite RGSSAD RPG Maker version. " +
"Please rename RGSSAD file with a extension corresponding to version: " +
"XP: .rgssad, VX: .rgss2a, VX Ace: .rgss3a");
Environment.Exit(1);
}

Expand Down
4 changes: 4 additions & 0 deletions RPGMakerDecrypter.Decrypter/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class Constants
public const string RpgMakerVxArchiveName = "Game.rgss2a";
public const string RpgMakerVxAceArchiveName = "Game.rgss3a";

public static string RpgMakerXpArchiveExtension = RpgMakerXpArchiveName.Split('.').Last();
public static string RpgMakerVxArchiveExtension = RpgMakerVxArchiveName.Split('.').Last();
public static string RpgMakerVxAceArchiveExtension = RpgMakerVxAceArchiveName.Split('.').Last();

public const string RpgMakerXpProjectFileContent = "RPGXP 1.02";
public const string RpgMakerVxProjectFileContent = "RPGVX 1.02";
public const string RpgMakerVxAceProjectFileContent = "RPGVXAce 1.00";
Expand Down
25 changes: 15 additions & 10 deletions RPGMakerDecrypter.Decrypter/RGSSAD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,26 @@ public void Dispose()
/// Gets the RPG Maker version based on RGASSD file extension.
/// </summary>
/// <param name="inputPath">Path to RGSSAD file</param>
public static RPGMakerVersion GetVersion(string inputPath)
public static RPGMakerVersion GetRPGMakerVersion(string inputPath)
{
FileInfo fi = new FileInfo(inputPath);

switch (fi.Name)
if(fi.Extension.EndsWith(Constants.RpgMakerXpArchiveExtension))
{
case Constants.RpgMakerXpArchiveName:
return RPGMakerVersion.Xp;
case Constants.RpgMakerVxArchiveName:
return RPGMakerVersion.Vx;
case Constants.RpgMakerVxAceArchiveName:
return RPGMakerVersion.VxAce;
default:
return RPGMakerVersion.Invalid;
return RPGMakerVersion.Xp;
}

if (fi.Extension.EndsWith(Constants.RpgMakerVxArchiveExtension))
{
return RPGMakerVersion.Vx;
}

if (fi.Extension.EndsWith(Constants.RpgMakerVxAceArchiveExtension))
{
return RPGMakerVersion.VxAce;
}

return RPGMakerVersion.Unknown;
}
}
}
2 changes: 1 addition & 1 deletion RPGMakerDecrypter.Decrypter/RPGMakerVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public enum RPGMakerVersion
{
Invalid,
Unknown,
Xp,
Vx,
VxAce
Expand Down
384 changes: 195 additions & 189 deletions RPGMakerDecrypter.Gui/MainForm.Designer.cs

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions RPGMakerDecrypter.Gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ private void openRGSSADToolStripMenuItem_Click(object sender, EventArgs e)

string inputFilePath = openFileDialog.FileName;

currentArchiveVersion = RGSSAD.GetVersion(inputFilePath);
currentArchiveVersion = RGSSAD.GetRPGMakerVersion(inputFilePath);

if (currentArchiveVersion == RPGMakerVersion.Invalid)
if (currentArchiveVersion == RPGMakerVersion.Unknown)
{
MessageBox.Show("Invalid input file.", "Invalid input file", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(
"Unable to determinite RGSSAD RPG Maker version. " +
"Please rename RGSSAD file with a extension corresponding to version: " +
"XP: .rgssad, VX: .rgss2a, VX Ace: .rgss3a",
"Unknown RGSSAD file", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

Expand Down Expand Up @@ -109,7 +113,7 @@ private void Reset()
SetClickableElementsEnabled(false);
extractFileButton.Enabled = false;

currentArchiveVersion = RPGMakerVersion.Invalid;
currentArchiveVersion = RPGMakerVersion.Unknown;

currentArchive?.Dispose();
}
Expand Down Expand Up @@ -191,7 +195,7 @@ private void extractFileButton_Click(object sender, EventArgs e)
}

FileInfo fileInfo = new FileInfo(saveFileDialog.FileName);

try
{
currentArchive.ExtractFile(archivedFile, fileInfo.DirectoryName, true, false);
Expand Down
62 changes: 1 addition & 61 deletions RPGMakerDecrypter.Gui/MainForm.resx
Original file line number Diff line number Diff line change
@@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down

0 comments on commit c17071b

Please sign in to comment.