Skip to content

Commit

Permalink
Updated GSPalConv!
Browse files Browse the repository at this point in the history
Autodetects Gens savestates (just give it the file and no other
parameters) and has a better generation of output filenames.
  • Loading branch information
Techokami committed Sep 3, 2016
1 parent 5415308 commit 4aafab9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions GSPalConv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ static void Main(string[] args)
//Arguments stuff
if (args.Length == 0)
{
System.Console.WriteLine("Genesis Standard Palette Converter - converts 0BGR palette data into RRGGBB data, perfect for YY-CHR!");
System.Console.WriteLine("Usage: GSPalConv <filename> [output = out.pal] [offset = 0 (give a hex value without a prefix)] [lines = 1]");
System.Console.WriteLine("Genesis Standard Palette Converter: converts 0BGR palette data into RRGGBB data \n Perfect for YY-CHR! \n Gens/Genecyst/Dgen savestate autodetection included.");
System.Console.WriteLine("Usage: GSPalConv <filename> [offset = 0 (give a hex value without a prefix)] [lines = 1] [output = filename.pal]");
return;
}

Expand All @@ -24,6 +24,7 @@ static void Main(string[] args)
int offset;
int lines;
bool test = false;
bool endian = false;
byte red;
byte green;
byte blue;
Expand All @@ -34,17 +35,18 @@ static void Main(string[] args)
infile = args[0];

//Output file
if (args.Length >= 2)
if (args.Length >= 4)
{
outfile = args[1];
outfile = args[3];
}
else
{
outfile = "out.pal";
string[] words = args[0].Split('.');
outfile = words[0] + ".pal";
}

//Palette data offset (why do some games put this data in different places? Default is for working with disassembly files)
if (args.Length >= 3)
if (args.Length >= 2)
{
offset = Int32.Parse(args[2], System.Globalization.NumberStyles.HexNumber);
}
Expand All @@ -53,8 +55,8 @@ static void Main(string[] args)
offset = 0;
}

//Make sure this last argument is a number...
if (args.Length >= 4)
//Make sure this argument is a number...
if (args.Length >= 3)
{
test = int.TryParse(args[3], out lines);
}
Expand Down Expand Up @@ -93,6 +95,24 @@ static void Main(string[] args)
return;
}

//If we weren't given any other parameters aside from filename, let's check to see if this is a savestate.
if(args.Length == 1)
{
//At the start of the file, there is a three-char magic: GST
char[] magic = br.ReadChars(3);
string magics = new string(magic);
if (magics == "GST")
{
Console.WriteLine("Detected savestate format: " + magics);
lines = 4;
offset = Int32.Parse("112", System.Globalization.NumberStyles.HexNumber);
endian = true;
}
//Please be kind! Rewind.
br.BaseStream.Seek(0, SeekOrigin.Begin);
}


br.ReadBytes(offset);

//create the output file
Expand All @@ -109,9 +129,19 @@ static void Main(string[] args)
//The main event!
for (int i = 0; i < (lines * 16); i++)
{
color1 = br.ReadByte();
color2 = br.ReadByte();
// Genesis pallete entries are words - 0B GR
if (!endian)
{
// Genesis pallete entries are words - 0B GR
color1 = br.ReadByte();
color2 = br.ReadByte();
}
else
{
//But GST files store them as GR 0B. ENDIANS!!!
color2 = br.ReadByte();
color1 = br.ReadByte();
}

red = Convert.ToByte(17 * (color2 % 16));
green = Convert.ToByte(17 * Math.Floor(color2 / 16f));
blue = Convert.ToByte(17 * (color1 % 16));
Expand Down
Binary file modified GSPalConv.exe
Binary file not shown.

0 comments on commit 4aafab9

Please sign in to comment.