Fix floats when compiling

This commit is contained in:
Li 2022-06-20 01:20:50 +12:00
parent 0aa6de7b9c
commit 486fe98cca
5 changed files with 278 additions and 259 deletions

View File

@ -17,7 +17,7 @@ namespace CXMLDecompiler
String XMLFilename = "";
String MagicNumber = "";
Endainness FileEndainness;
Endianness FileEndainness;
bool ps3;
Tools tools;
@ -46,9 +46,9 @@ namespace CXMLDecompiler
Version = Int32.Parse(GetTypingInformation("VERSION").Replace("0x", ""), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture);
// Determine filetype.
FileEndainness = (Endainness)Enum.Parse(typeof(Endainness), GetTypingInformation("ENDAINESS"));
FileEndainness = (Endianness)Enum.Parse(typeof(Endianness), GetTypingInformation("ENDAINESS"));
ps3 = GetTypingInformation("PS3") == "true";
tools = new Tools((FileEndainness == Endainness.BIG_ENDAIN));
tools = new Tools((FileEndainness == Endianness.BIG_ENDIAN));
InfoFile = File.Open(CxmlFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
InfoFile.SetLength(0);
@ -362,7 +362,7 @@ namespace CXMLDecompiler
Console.WriteLine("Int - Value: " + intWrite.ToString());
break;
case AttributeType.TYPE_FLOAT:
float FloatValue = Single.Parse(attribute.Value.Substring(0, attribute.Value.Length - 1), CultureInfo.InvariantCulture);
float FloatValue = Single.Parse(attribute.Value.Replace("f", ""), CultureInfo.InvariantCulture);
tools.WriteSingle(WorkRam, FloatValue);
tools.WriteInt32(WorkRam, 0x00);
Console.WriteLine("Float - Value: " + FloatValue.ToString());

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<StartArguments>sample\sample.xml sample2.cxml --compile</StartArguments>
<StartArguments>PvrResource.cxml -ps3 -le -f -d</StartArguments>
<StartWorkingDirectory>C:\Users\User\Documents\git\cxml-decompiler\CXMLCli\bin\x64\Debug</StartWorkingDirectory>
</PropertyGroup>
</Project>

View File

@ -74,7 +74,7 @@ namespace CXMLDecompiler
CXML.Version FileVersion;
public Endainness FileEndainness = Endainness.LITTLE_ENDAIN;
public Endianness FileEndainness = Endianness.LITTLE_ENDIAN;
List<LoopbackHandler> FileList = new List<LoopbackHandler>();
@ -84,7 +84,7 @@ namespace CXMLDecompiler
public bool ProcessFiles = false;
public bool WaitExit = false;
public bool NoRecursive = false;
public void Init(string path, bool CheckMagic = true, bool forcePs3 = false, Endainness forceEndainness = Endainness.UNCHANGED)
public void Init(string path, bool CheckMagic = true, bool forcePs3 = false, Endianness forceEndainness = Endianness.UNCHANGED)
{
InfoFile = File.Open(path, FileMode.Open, FileAccess.Read);
bool MagicValid = _checkMagicNumber();
@ -101,20 +101,20 @@ namespace CXMLDecompiler
if (FileVersion == CXML.Version.PS3)
{
ps3 = true;
FileEndainness = Endainness.BIG_ENDAIN;
FileEndainness = Endianness.BIG_ENDIAN;
}
else
{
FileEndainness = Endainness.LITTLE_ENDAIN;
FileEndainness = Endianness.LITTLE_ENDIAN;
}
if (forcePs3)
ps3 = true;
if (forceEndainness != Endainness.UNCHANGED)
if (forceEndainness != Endianness.UNCHANGED)
FileEndainness = forceEndainness;
tools = new Tools(FileEndainness == Endainness.BIG_ENDAIN);
tools = new Tools(FileEndainness == Endianness.BIG_ENDIAN);
TreeTable = Tools.ByteToStream(GetTreeTable());
StringTable = Tools.ByteToStream(GetStringTable());
@ -416,11 +416,11 @@ namespace CXMLDecompiler
Align(InfoFile, 0x10);
}
public void DecompileCXML(String CXMLFile, bool force = false)
public void DecompileCXML(String CXMLFile)
{
if (!IsInitalized)
Init(CXMLFile,force);
Init(CXMLFile);
if (Directory.Exists(MainDir))
@ -683,7 +683,7 @@ namespace CXMLDecompiler
Console.WriteLine("Int - Value: " + AttributeValue.ToString() + " sz:" + sz);
break;
case AttributeType.TYPE_FLOAT:
float FloatValue = tools.ReadSingle(TreeTable);
Double FloatValue = (Double)tools.ReadSingle(TreeTable);
string FloatStr = FloatValue.ToString("G9", CultureInfo.InvariantCulture);
if (!FloatStr.Contains("."))
FloatStr += ".0";
@ -749,7 +749,7 @@ namespace CXMLDecompiler
for(int i = 0; i < FloatArraySize; i++)
{
FloatValue = tools.ReadSingle(FloatArrayTable);
FloatValue = (Double)tools.ReadSingle(FloatArrayTable);
FloatStr = FloatValue.ToString("G9", CultureInfo.InvariantCulture);
if (!FloatStr.Contains("."))
FloatStr += ".0";

View File

@ -66,8 +66,8 @@ namespace CXMLCli
Console.WriteLine("\t-iat --dump-int-array Dump int array table.");
Console.WriteLine("\t-fat --dump-float-array Dump float array table.");
Console.WriteLine("\t-ft --dump-file Dump file table.");
Console.WriteLine("\t-le --little-endain De/Encode ints as Little Endain");
Console.WriteLine("\t-be --big-endain De/Encode ints as Big Endain");
Console.WriteLine("\t-le --little-endian Decode ints as Little Endian");
Console.WriteLine("\t-be --big-endian Decode ints as Big Endian");
Console.WriteLine("\t-ps3 --playstation-3 Use the old CXML Format used back on PS3.");
Console.WriteLine("\t-p --process-files Process Extracted Files");
Console.WriteLine("\t-nr --no-recursive Do not recursively decompile .RCS to XML");
@ -82,40 +82,63 @@ namespace CXMLCli
}
String ArgsFull = String.Join(" ", args);
String path = args[0];
String ProcessFilePath = args[0];
bool ForcePs3 = false;
Endianness FileEndianness = Endianness.UNCHANGED;
if (args.Length == 1)
{
ArgsFull += " -d -p -w";
}
if (HasArg(ArgsFull, "-le") || HasArg(ArgsFull, "--little-endian"))
{
FileEndianness = Endianness.LITTLE_ENDIAN;
}
if (HasArg(ArgsFull, "-be") || HasArg(ArgsFull, "--big-endian"))
{
FileEndianness = Endianness.LITTLE_ENDIAN;
}
if (HasArg(ArgsFull, "-ps3") || HasArg(ArgsFull, "--playstation-3"))
{
ForcePs3 = true;
}
if (HasArg(ArgsFull, "-iv") || HasArg(ArgsFull, "--is-vag"))
{
byte[] WaveData = VAG.VAGAudio.Vag2Wav(path);
string FileName = Path.GetFileNameWithoutExtension(path) + "-" + VAG.VAGAudio.GetFilename(path) + ".wav";
byte[] WaveData = VAG.VAGAudio.Vag2Wav(ProcessFilePath);
string FileName = Path.GetFileNameWithoutExtension(ProcessFilePath) + "-" + VAG.VAGAudio.GetFilename(ProcessFilePath) + ".wav";
Console.WriteLine("Writing "+FileName);
File.WriteAllBytes(FileName, WaveData);
return 0;
}
if (HasArg(ArgsFull, "-f") || HasArg(ArgsFull, "--force"))
{
Check = false;
}
if (HasArg(ArgsFull, "-dc") || HasArg(ArgsFull, "--decompress"))
{
Console.WriteLine("Decompressing " + path);
Byte[] FileData = File.ReadAllBytes(path);
Console.WriteLine("Decompressing " + ProcessFilePath);
Byte[] FileData = File.ReadAllBytes(ProcessFilePath);
Byte[] DecompressedData = ZlibStream.UncompressBuffer(FileData);
string Extension = Tools.GetFileExtension(DecompressedData);
string OutPath = Path.ChangeExtension(path, Extension);
string OutPath = Path.ChangeExtension(ProcessFilePath, Extension);
File.WriteAllBytes(OutPath, DecompressedData);
return 0;
}
if (HasArg(ArgsFull, "-cc") || HasArg(ArgsFull, "--compress"))
{
Console.WriteLine("Compressing " + path);
Byte[] FileData = File.ReadAllBytes(path);
Console.WriteLine("Compressing " + ProcessFilePath);
Byte[] FileData = File.ReadAllBytes(ProcessFilePath);
Byte[] CompressedData = ZlibStream.CompressBuffer(FileData);
string Extension = Tools.GetFileExtension(CompressedData);
string OutPath = Path.ChangeExtension(path, Extension);
string OutPath = Path.ChangeExtension(ProcessFilePath, Extension);
File.WriteAllBytes(OutPath, CompressedData);
return 0;
}
@ -123,15 +146,11 @@ namespace CXMLCli
CXMLReader cxmlParser = new CXMLReader();
if(!HasArg(ArgsFull, "-c") && !HasArg(ArgsFull, "--compile"))
{
Console.WriteLine("Initalizing: " + path);
cxmlParser.Init(path, Check);
Console.WriteLine("Initalizing: " + ProcessFilePath);
cxmlParser.Init(ProcessFilePath, Check, ForcePs3, FileEndianness);
}
if (HasArg(ArgsFull, "-f") || HasArg(ArgsFull, "--force"))
{
Check = false;
}
if (HasArg(ArgsFull, "-dt") || HasArg(ArgsFull, "--dump-tables"))
{
@ -215,20 +234,20 @@ namespace CXMLCli
if (HasArg(ArgsFull, "-d") || HasArg(ArgsFull, "--decompile") && !HasArg(ArgsFull, "-dt"))
{
Console.WriteLine("Decompiling.");
cxmlParser.DecompileCXML(path, Check);
cxmlParser.DecompileCXML(ProcessFilePath);
Console.WriteLine("\n\nDECOMPILATION COMPLETE!");
if(cxmlParser.WaitExit)
Console.ReadKey();
}
else if (HasArg(ArgsFull, "-c") || HasArg(ArgsFull, "--compile"))
{
Console.WriteLine("Compiling: " + path);
Console.WriteLine("Compiling: " + ProcessFilePath);
CXMLBuilder builder = new CXMLBuilder();
if (HasArg(ArgsFull, "-h") || HasArg(ArgsFull, "----hash-string"))
builder.HashStrings = true;
builder.Init(path, args[1]);
builder.BuildCXML(path, args[1]);
builder.Init(ProcessFilePath, args[1]);
builder.BuildCXML(ProcessFilePath, args[1]);
Console.WriteLine("\n\nCOMPILATION COMPLETE!");
if (cxmlParser.WaitExit)
Console.ReadKey();

View File

@ -7,10 +7,10 @@ using System.Text;
namespace General
{
enum Endainness
enum Endianness
{
LITTLE_ENDAIN,
BIG_ENDAIN,
LITTLE_ENDIAN,
BIG_ENDIAN,
UNCHANGED
};