2011-09-27 05:19:01 +02:00
|
|
|
|
/* This file is part of Sharpii.
|
2013-02-16 07:55:46 +01:00
|
|
|
|
* Copyright (C) 2013 Person66
|
2011-09-27 05:19:01 +02:00
|
|
|
|
*
|
|
|
|
|
* Sharpii is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* Sharpii is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2011-11-02 02:02:11 +01:00
|
|
|
|
* along with Sharpii. If not, see <http://www.gnu.org/licenses/>.
|
2011-09-27 05:19:01 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using libWiiSharp;
|
|
|
|
|
|
|
|
|
|
namespace Sharpii
|
|
|
|
|
{
|
|
|
|
|
partial class TPL_Stuff
|
|
|
|
|
{
|
|
|
|
|
public static void TPL(string[] args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Length < 4)
|
|
|
|
|
{
|
|
|
|
|
TPL_help();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//********************* To TPL *********************
|
|
|
|
|
if (args[1] == "-to")
|
|
|
|
|
{
|
|
|
|
|
To(args);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//********************* From TPL *********************
|
|
|
|
|
if (args[1] == "-from")
|
|
|
|
|
{
|
|
|
|
|
From(args);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//If tuser gets here, they entered something wrong
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("ERROR: The argument {0} is invalid", args[1]);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void From(string[] args)
|
|
|
|
|
{
|
|
|
|
|
string input = args[2];
|
|
|
|
|
string output = args[3];
|
|
|
|
|
|
|
|
|
|
//Check if file exists
|
|
|
|
|
if (File.Exists(input) == false)
|
|
|
|
|
{
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("ERROR: Unable to open file: {0}", input);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Run main part, and check for exceptions
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//Load tpl
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Loading file...");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
TPL tplfile = libWiiSharp.TPL.Load(input);
|
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Done!\n");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
//save image
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Extracting texture...");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
tplfile.ExtractTexture(output);
|
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Done!\n");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 1)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Operation completed succesfully!");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("An unknown error occured, please try again");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void To(string[] args)
|
|
|
|
|
{
|
|
|
|
|
//Setting up variables
|
|
|
|
|
string input = args[2];
|
|
|
|
|
string output = args[3];
|
|
|
|
|
string tplFormat = "RGB565";
|
|
|
|
|
|
|
|
|
|
//Check if file exists
|
|
|
|
|
if (File.Exists(input) == false)
|
|
|
|
|
{
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("ERROR: Unable to open file: {0}", input);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Check for arguments
|
|
|
|
|
for (int i = 1; i < args.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
switch (args[i].ToUpper())
|
|
|
|
|
{
|
|
|
|
|
case "-FORMAT":
|
|
|
|
|
if (i + 1 >= args.Length)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("ERROR: No format set");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
tplFormat = args[i + 1];
|
|
|
|
|
break;
|
|
|
|
|
case "-F":
|
|
|
|
|
if (i + 1 >= args.Length)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("ERROR: No format set");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
tplFormat = args[i + 1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Check if valid format was entered
|
|
|
|
|
if (tplFormat != "I4" & tplFormat != "I8" & tplFormat != "IA4" & tplFormat != "IA8" & tplFormat != "RGB565" & tplFormat != "RGB5A3" & tplFormat != "RGBA8")
|
|
|
|
|
{
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("ERROR: Unknown format type: {0}", tplFormat);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Run main part, and check for exceptions
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//Set format
|
|
|
|
|
TPL_TextureFormat format = TPL_TextureFormat.RGB565;
|
|
|
|
|
if (tplFormat == "I4")
|
|
|
|
|
format = TPL_TextureFormat.I4;
|
|
|
|
|
if (tplFormat == "I8")
|
|
|
|
|
format = TPL_TextureFormat.I8;
|
|
|
|
|
if (tplFormat == "IA4")
|
|
|
|
|
format = TPL_TextureFormat.IA4;
|
|
|
|
|
if (tplFormat == "IA8")
|
|
|
|
|
format = TPL_TextureFormat.IA8;
|
|
|
|
|
if (tplFormat == "RGB565")
|
|
|
|
|
format = TPL_TextureFormat.RGB565;
|
|
|
|
|
if (tplFormat == "RGB5A3")
|
|
|
|
|
format = TPL_TextureFormat.RGB5A3;
|
|
|
|
|
if (tplFormat == "RGBA8")
|
|
|
|
|
format = TPL_TextureFormat.RGBA8;
|
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Format set to: {0}", tplFormat);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
//Make tpl
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Creating tpl file...");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
TPL tplfile = libWiiSharp.TPL.FromImage(input, format);
|
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Done!\n");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
//save
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Saving tpl file...");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
if (output.Substring(output.Length - 4, 4).ToUpper() != ".TPL")
|
|
|
|
|
output = output + ".tpl";
|
|
|
|
|
|
|
|
|
|
tplfile.Save(output);
|
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 2)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.Write("Done!\n");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
|
|
|
|
|
if (Quiet.quiet > 1)
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("Operation completed succesfully!");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("An unknown error occured, please try again");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("ERROR DETAILS: {0}", ex.Message);
|
2011-09-27 05:19:01 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void TPL_help()
|
|
|
|
|
{
|
2011-11-08 05:59:31 +01:00
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("Sharpii {0} - TPL - A tool by person66, using libWiiSharp.dll by leathl", Version.version);
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" Usage:");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" Sharpii.exe TPL [-to | -from] input output [arguments]");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" Arguments:");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" -to Convert image to tpl");
|
|
|
|
|
Console.WriteLine(" -from Create image from tpl");
|
|
|
|
|
Console.WriteLine(" input The input file/folder");
|
|
|
|
|
Console.WriteLine(" output The output file/folder");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" Arguments for Converting to TPL:");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" -format | -f The format of the tpl. Possible values are:");
|
|
|
|
|
Console.WriteLine(" RGBA8 (High Quality with Alpha)");
|
|
|
|
|
Console.WriteLine(" RGB565 (Medium Quality without Alpha)");
|
|
|
|
|
Console.WriteLine(" RGB5A3 (Low Quality with Alpha)");
|
|
|
|
|
Console.WriteLine(" IA8 (High quality B/W with Alpha)");
|
|
|
|
|
Console.WriteLine(" IA4 (Low Quality B/W with Alpha)");
|
|
|
|
|
Console.WriteLine(" I8 (High Quality B/W without Alpha)");
|
|
|
|
|
Console.WriteLine(" I4 (Low Quality B/W without Alpha)");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" Notes:");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.WriteLine(" If no format is specified when converting to TPL, RGB565 is used.");
|
|
|
|
|
Console.WriteLine(" When converting to an image, the image format is chosen based on the extension");
|
2011-09-27 05:19:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|