add support for reading PS3 Theme Files .p3t
This commit is contained in:
parent
486fe98cca
commit
3a5e794736
|
@ -351,21 +351,17 @@ namespace CXMLDecompiler
|
||||||
Console.WriteLine("AttributeType: " + Type.ToString());
|
Console.WriteLine("AttributeType: " + Type.ToString());
|
||||||
switch (Type)
|
switch (Type)
|
||||||
{
|
{
|
||||||
case AttributeType.TYPE_NONE:
|
|
||||||
Console.WriteLine("UNSUPPORTED TYPE @ " + TreeTable.Position);
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case AttributeType.TYPE_INT:
|
case AttributeType.TYPE_INT:
|
||||||
int intWrite = Int32.Parse(attribute.Value, CultureInfo.InvariantCulture);
|
int intWrite = Int32.Parse(attribute.Value, CultureInfo.InvariantCulture);
|
||||||
tools.WriteInt32(WorkRam, intWrite);
|
tools.WriteInt32(WorkRam, intWrite);
|
||||||
tools.WriteInt32(WorkRam, 0x00);
|
tools.WriteInt32(WorkRam, 0x00);
|
||||||
Console.WriteLine("Int - Value: " + intWrite.ToString());
|
Console.WriteLine("Int: " + intWrite.ToString());
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_FLOAT:
|
case AttributeType.TYPE_FLOAT:
|
||||||
float FloatValue = Single.Parse(attribute.Value.Replace("f", ""), CultureInfo.InvariantCulture);
|
float FloatValue = Single.Parse(attribute.Value.Replace("f", ""), CultureInfo.InvariantCulture);
|
||||||
tools.WriteSingle(WorkRam, FloatValue);
|
tools.WriteSingle(WorkRam, FloatValue);
|
||||||
tools.WriteInt32(WorkRam, 0x00);
|
tools.WriteInt32(WorkRam, 0x00);
|
||||||
Console.WriteLine("Float - Value: " + FloatValue.ToString());
|
Console.WriteLine("Float: " + FloatValue.ToString());
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_STRING:
|
case AttributeType.TYPE_STRING:
|
||||||
int StringOffset = AddGetStringTable(attribute.Value);
|
int StringOffset = AddGetStringTable(attribute.Value);
|
||||||
|
@ -391,7 +387,7 @@ namespace CXMLDecompiler
|
||||||
int HashTableSize = 4;
|
int HashTableSize = 4;
|
||||||
tools.WriteInt32(WorkRam, HashTableOffset);
|
tools.WriteInt32(WorkRam, HashTableOffset);
|
||||||
tools.WriteInt32(WorkRam, HashTableSize);
|
tools.WriteInt32(WorkRam, HashTableSize);
|
||||||
Console.WriteLine("Hash ID Offset:" + HashTableOffset.ToString() + " size: " + HashTableSize);
|
Console.WriteLine("Hash Offset:" + HashTableOffset.ToString() + " size: " + HashTableSize);
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_INTEGER_ARRAY:
|
case AttributeType.TYPE_INTEGER_ARRAY:
|
||||||
string[] arr = attribute.Value.Replace("[", "").Replace("]", "").Replace(" ", "").Split(',');
|
string[] arr = attribute.Value.Replace("[", "").Replace("]", "").Replace(" ", "").Split(',');
|
||||||
|
@ -432,38 +428,39 @@ namespace CXMLDecompiler
|
||||||
int IdTableOffset = AddGetIdTable(attribute.Value, Convert.ToInt32(TreeTable.Position));
|
int IdTableOffset = AddGetIdTable(attribute.Value, Convert.ToInt32(TreeTable.Position));
|
||||||
tools.WriteInt32(WorkRam, IdTableOffset);
|
tools.WriteInt32(WorkRam, IdTableOffset);
|
||||||
tools.WriteInt32(WorkRam, 0x00);
|
tools.WriteInt32(WorkRam, 0x00);
|
||||||
Console.WriteLine("String Loopback: " + ElementName + " " + TreeTable.Position.ToString("X") + " (" + TreeTable.Position.ToString("X") + ")");
|
Console.WriteLine("ID Ref: " + ElementName + " " + TreeTable.Position.ToString("X") + " (" + TreeTable.Position.ToString("X") + ")");
|
||||||
Console.WriteLine("Loopback ID String: " + IdTableOffset + " sz: 0");
|
Console.WriteLine("ID Ref Offset: " + IdTableOffset + " sz: 0");
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_ID:
|
case AttributeType.TYPE_ID:
|
||||||
IdTableOffset = AddGetIdTable(attribute.Value, -1);
|
IdTableOffset = AddGetIdTable(attribute.Value, -1);
|
||||||
tools.WriteInt32(WorkRam, IdTableOffset);
|
tools.WriteInt32(WorkRam, IdTableOffset);
|
||||||
tools.WriteInt32(WorkRam, 0x00);
|
tools.WriteInt32(WorkRam, 0x00);
|
||||||
Console.WriteLine("ID String: " + IdTableOffset + " sz: 0");
|
Console.WriteLine("ID : " + IdTableOffset + " sz: 0");
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_ID_HASH_REF:
|
case AttributeType.TYPE_ID_HASH_REF:
|
||||||
int hash = Int32.Parse(attribute.Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
int hash = Int32.Parse(attribute.Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
if (HashStrings)
|
if (HashStrings)
|
||||||
hash = Int32.Parse(Tools.GenerateShortHash(Encoding.UTF8.GetBytes(attribute.Value)), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
hash = Int32.Parse(Tools.GenerateShortHash(Encoding.UTF8.GetBytes(attribute.Value)), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
int IntIdTableOffset = AddGetHashIdTable(hash, Convert.ToInt32(TreeTable.Position));
|
int HashIdTableOffset = AddGetHashIdTable(hash, Convert.ToInt32(TreeTable.Position));
|
||||||
tools.WriteInt32(WorkRam, IntIdTableOffset);
|
tools.WriteInt32(WorkRam, HashIdTableOffset);
|
||||||
tools.WriteInt32(WorkRam, 0x00);
|
tools.WriteInt32(WorkRam, 0x00);
|
||||||
Console.WriteLine("Int Loopback: " + ElementName + " " + TreeTable.Position.ToString("X") + " (" + TreeTable.Position.ToString("X") + ")");
|
Console.WriteLine("Hash ID Ref: " + ElementName + " " + TreeTable.Position.ToString("X") + " (" + TreeTable.Position.ToString("X") + ")");
|
||||||
Console.WriteLine("Loopback ID Int: " + IntIdTableOffset + " sz: 0");
|
Console.WriteLine("Hash ID REF offset: " + HashIdTableOffset + " sz: 0");
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_ID_HASH:
|
case AttributeType.TYPE_ID_HASH:
|
||||||
hash = Int32.Parse(attribute.Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
hash = Int32.Parse(attribute.Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
if (HashStrings)
|
if (HashStrings)
|
||||||
hash = Int32.Parse(Tools.GenerateShortHash(Encoding.UTF8.GetBytes(attribute.Value)), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
hash = Int32.Parse(Tools.GenerateShortHash(Encoding.UTF8.GetBytes(attribute.Value)), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||||
IntIdTableOffset = AddGetHashIdTable(hash, -1);
|
HashIdTableOffset = AddGetHashIdTable(hash, -1);
|
||||||
|
|
||||||
tools.WriteInt32(WorkRam, IntIdTableOffset);
|
tools.WriteInt32(WorkRam, HashIdTableOffset);
|
||||||
tools.WriteInt32(WorkRam, 0x00);
|
tools.WriteInt32(WorkRam, 0x00);
|
||||||
Console.WriteLine("Int Id: " + IntIdTableOffset + " sz: 0");
|
Console.WriteLine("Hash ID: " + HashIdTableOffset + " sz: 0");
|
||||||
|
break;
|
||||||
|
case AttributeType.TYPE_NONE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("UNKNOWN TYPE @ " + TreeTable.Position);
|
throw new NotImplementedException("UNKNOWN TYPE @ " + TreeTable.Position);
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Console.WriteLine(attribute.Name + "=" + attribute.Value);
|
Console.WriteLine(attribute.Name + "=" + attribute.Value);
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||||
<StartArguments>PvrResource.cxml -ps3 -le -f -d</StartArguments>
|
<StartArguments>PvrResource.cxml -ps3 -le -f -d</StartArguments>
|
||||||
<StartWorkingDirectory>C:\Users\User\Documents\git\cxml-decompiler\CXMLCli\bin\x64\Debug</StartWorkingDirectory>
|
<StartWorkingDirectory>C:\Users\Li\Documents\git\cxml-decompiler\CXMLCli\bin\x64\Debug</StartWorkingDirectory>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -32,6 +32,10 @@ namespace CXMLDecompiler
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (Magic.StartsWith("P3TF")) // ps3 theme file
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else if (Magic.StartsWith("CXML")) // cxml.py default
|
else if (Magic.StartsWith("CXML")) // cxml.py default
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -679,6 +683,7 @@ namespace CXMLDecompiler
|
||||||
{
|
{
|
||||||
case AttributeType.TYPE_INT:
|
case AttributeType.TYPE_INT:
|
||||||
AttributeValue = tools.ReadInt32(TreeTable);
|
AttributeValue = tools.ReadInt32(TreeTable);
|
||||||
|
|
||||||
int sz = tools.ReadInt32(TreeTable);
|
int sz = tools.ReadInt32(TreeTable);
|
||||||
Console.WriteLine("Int - Value: " + AttributeValue.ToString() + " sz:" + sz);
|
Console.WriteLine("Int - Value: " + AttributeValue.ToString() + " sz:" + sz);
|
||||||
break;
|
break;
|
||||||
|
|
662
CXMLCli/Tools.cs
662
CXMLCli/Tools.cs
|
@ -1,69 +1,69 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace General
|
namespace General
|
||||||
{
|
{
|
||||||
enum Endianness
|
enum Endianness
|
||||||
{
|
{
|
||||||
LITTLE_ENDIAN,
|
LITTLE_ENDIAN,
|
||||||
BIG_ENDIAN,
|
BIG_ENDIAN,
|
||||||
UNCHANGED
|
UNCHANGED
|
||||||
};
|
};
|
||||||
|
|
||||||
class Tools
|
class Tools
|
||||||
{
|
{
|
||||||
public Tools(bool bigEndain)
|
public Tools(bool bigEndain)
|
||||||
{
|
{
|
||||||
BigEndain = bigEndain;
|
BigEndain = bigEndain;
|
||||||
}
|
}
|
||||||
public bool BigEndain = false;
|
public bool BigEndain = false;
|
||||||
|
|
||||||
public static byte[] bmp = Encoding.ASCII.GetBytes("BM"); // BMP
|
public static byte[] bmp = Encoding.ASCII.GetBytes("BM"); // BMP
|
||||||
public static byte[] gif = Encoding.ASCII.GetBytes("GIF"); // GIF
|
public static byte[] gif = Encoding.ASCII.GetBytes("GIF"); // GIF
|
||||||
public static byte[] png = new byte[] { 137, 80, 78, 71 }; // PNG
|
public static byte[] png = new byte[] { 137, 80, 78, 71 }; // PNG
|
||||||
public static byte[] tiff = new byte[] { 73, 73, 42 }; // TIFF
|
public static byte[] tiff = new byte[] { 73, 73, 42 }; // TIFF
|
||||||
public static byte[] tiff2 = new byte[] { 77, 77, 42 }; // TIFF
|
public static byte[] tiff2 = new byte[] { 77, 77, 42 }; // TIFF
|
||||||
public static byte[] jpeg = new byte[] { 255, 216, 255 }; // jpeg
|
public static byte[] jpeg = new byte[] { 255, 216, 255 }; // jpeg
|
||||||
public static Random rng = new Random(Guid.NewGuid().GetHashCode());
|
public static Random rng = new Random(Guid.NewGuid().GetHashCode());
|
||||||
|
|
||||||
public static void WriteStringToStream(Stream s, String str)
|
public static void WriteStringToStream(Stream s, String str)
|
||||||
{
|
{
|
||||||
Byte[] bytes = Encoding.UTF8.GetBytes(str);
|
Byte[] bytes = Encoding.UTF8.GetBytes(str);
|
||||||
s.Write(bytes, 0x00, bytes.Length);
|
s.Write(bytes, 0x00, bytes.Length);
|
||||||
}
|
}
|
||||||
public static void WriteUtf16StringToStream(Stream s, String str)
|
public static void WriteUtf16StringToStream(Stream s, String str)
|
||||||
{
|
{
|
||||||
Byte[] bytes = Encoding.Unicode.GetBytes(str);
|
Byte[] bytes = Encoding.Unicode.GetBytes(str);
|
||||||
s.Write(bytes, 0x00, bytes.Length);
|
s.Write(bytes, 0x00, bytes.Length);
|
||||||
}
|
}
|
||||||
public static MemoryStream ByteToStream(byte[] Array)
|
public static MemoryStream ByteToStream(byte[] Array)
|
||||||
{
|
{
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new MemoryStream();
|
||||||
ms.Write(Array, 0x00, Array.Length);
|
ms.Write(Array, 0x00, Array.Length);
|
||||||
ms.Seek(0, SeekOrigin.Begin);
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
return ms;
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] StreamToByte(Stream stream)
|
public static byte[] StreamToByte(Stream stream)
|
||||||
{
|
{
|
||||||
int StreamLen = (int)stream.Length;
|
int StreamLen = (int)stream.Length;
|
||||||
byte[] Bytes = new byte[StreamLen];
|
byte[] Bytes = new byte[StreamLen];
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
stream.Read(Bytes, 0x00, StreamLen);
|
stream.Read(Bytes, 0x00, StreamLen);
|
||||||
return Bytes;
|
return Bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GenerateReplacePattern()
|
public static string GenerateReplacePattern()
|
||||||
{
|
{
|
||||||
byte[] RandomNumber = new byte[0x20];
|
byte[] RandomNumber = new byte[0x20];
|
||||||
rng.NextBytes(RandomNumber);
|
rng.NextBytes(RandomNumber);
|
||||||
return "{{" + BitConverter.ToString(RandomNumber).Replace("-", "") + "}}";
|
return "{{" + BitConverter.ToString(RandomNumber).Replace("-", "") + "}}";
|
||||||
}
|
}
|
||||||
public static string GetFileExtension(byte[] Bytes)
|
public static string GetFileExtension(byte[] Bytes)
|
||||||
{
|
{
|
||||||
if (bmp.SequenceEqual(Bytes.Take(bmp.Length)))
|
if (bmp.SequenceEqual(Bytes.Take(bmp.Length)))
|
||||||
{
|
{
|
||||||
|
@ -88,296 +88,296 @@ namespace General
|
||||||
else if (jpeg.SequenceEqual(Bytes.Take(jpeg.Length)))
|
else if (jpeg.SequenceEqual(Bytes.Take(jpeg.Length)))
|
||||||
{
|
{
|
||||||
return ".jpg";
|
return ".jpg";
|
||||||
}
|
}
|
||||||
else if (IsZlib(Bytes))
|
else if (IsZlib(Bytes))
|
||||||
{
|
{
|
||||||
return ".z";
|
return ".z";
|
||||||
}
|
}
|
||||||
else if (IsRcf(Bytes))
|
else if (IsRcf(Bytes))
|
||||||
{
|
{
|
||||||
return ".rcs";
|
return ".rcs";
|
||||||
}
|
}
|
||||||
else if (IsDDS(Bytes))
|
else if (IsDDS(Bytes))
|
||||||
{
|
{
|
||||||
return ".dds";
|
return ".dds";
|
||||||
}
|
}
|
||||||
else if (IsVAG(Bytes))
|
else if (IsVAG(Bytes))
|
||||||
{
|
{
|
||||||
return ".vag";
|
return ".vag";
|
||||||
}
|
}
|
||||||
else if (IsGim(Bytes))
|
else if (IsGim(Bytes))
|
||||||
{
|
{
|
||||||
return ".gim";
|
return ".gim";
|
||||||
}
|
}
|
||||||
else if (!HasBinaryContent(Encoding.UTF8.GetString(Bytes)))
|
else if (!HasBinaryContent(Encoding.UTF8.GetString(Bytes)))
|
||||||
{
|
{
|
||||||
return ".txt";
|
return ".txt";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ".bin";
|
return ".bin";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsVAG(byte[] Bytes)
|
|
||||||
{
|
|
||||||
MemoryStream Data = ByteToStream(Bytes);
|
|
||||||
String header = ReadString(Data, 4);
|
|
||||||
if (header.StartsWith("VAG"))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsDDS(byte[] Bytes)
|
|
||||||
{
|
|
||||||
MemoryStream Data = ByteToStream(Bytes);
|
|
||||||
String header = ReadString(Data, 4);
|
|
||||||
if (header.StartsWith("DDS"))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static bool IsRcf(byte[] Bytes)
|
|
||||||
{
|
|
||||||
MemoryStream Data = ByteToStream(Bytes);
|
|
||||||
String header = ReadString(Data, 5);
|
|
||||||
if (header.StartsWith("RCSF"))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsGim(byte[] Bytes)
|
|
||||||
{
|
|
||||||
MemoryStream Data = ByteToStream(Bytes);
|
|
||||||
String header = ReadString(Data, 4);
|
|
||||||
if (header.StartsWith("MIG"))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsZlib(byte[] Bytes)
|
|
||||||
{
|
|
||||||
if (Bytes[0] == 0x78)
|
|
||||||
{
|
|
||||||
if (Bytes[1] == 0x01)
|
|
||||||
return true;
|
|
||||||
if (Bytes[1] == 0x9C)
|
|
||||||
return true;
|
|
||||||
if (Bytes[1] == 0xDA)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Bitmap GetBitmap(byte[] BitmapBytes)
|
|
||||||
{
|
|
||||||
MemoryStream ms = ByteToStream(BitmapBytes);
|
|
||||||
Bitmap bmp = new Bitmap(ms);
|
|
||||||
ms.Dispose();
|
|
||||||
return bmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String ReadStringAt(Stream ms, int location)
|
|
||||||
{
|
|
||||||
long ogPos = ms.Position;
|
|
||||||
ms.Seek(location, SeekOrigin.Begin);
|
|
||||||
String str = ReadString(ms);
|
|
||||||
ms.Seek(ogPos, SeekOrigin.Begin);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int ReadLittleEndainIntAt(Stream ms, int location)
|
|
||||||
{
|
|
||||||
long ogPos = ms.Position;
|
|
||||||
ms.Seek(location, SeekOrigin.Begin);
|
|
||||||
int i = ReadLittleEndainInt(ms);
|
|
||||||
ms.Seek(ogPos, SeekOrigin.Begin);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ReadIntAt(Stream ms, int location)
|
|
||||||
{
|
|
||||||
long ogPos = ms.Position;
|
|
||||||
ms.Seek(location, SeekOrigin.Begin);
|
|
||||||
int i = ReadInt32(ms);
|
|
||||||
ms.Seek(ogPos, SeekOrigin.Begin);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
public static bool HasBinaryContent(string content)
|
|
||||||
{
|
|
||||||
return content.Any(ch => char.IsControl(ch) && ch != '\r' && ch != '\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsVAG(byte[] Bytes)
|
||||||
public void WriteInt32(Stream ms, int val)
|
|
||||||
{
|
|
||||||
if (BigEndain)
|
|
||||||
WriteBigEndainInt(ms, val);
|
|
||||||
else
|
|
||||||
WriteLittleEndainInt(ms, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteSingle(Stream ms, Single val)
|
|
||||||
{
|
|
||||||
if (BigEndain)
|
|
||||||
WriteBigEndainSingle(ms, val);
|
|
||||||
else
|
|
||||||
WriteLittleEndainSingle(ms, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ReadInt32(Stream ms)
|
|
||||||
{
|
|
||||||
if (BigEndain)
|
|
||||||
return ReadBigEndainInt(ms);
|
|
||||||
else
|
|
||||||
return ReadLittleEndainInt(ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Single ReadSingle(Stream ms)
|
|
||||||
{
|
|
||||||
if (BigEndain)
|
|
||||||
return ReadBigEndainSingle(ms);
|
|
||||||
else
|
|
||||||
return ReadLittleEndainSingle(ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int ReadBigEndainIntAt(Stream ms, int location)
|
|
||||||
{
|
|
||||||
long ogPos = ms.Position;
|
|
||||||
ms.Seek(location, SeekOrigin.Begin);
|
|
||||||
int i = ReadBigEndainInt(ms);
|
|
||||||
ms.Seek(ogPos, SeekOrigin.Begin);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
public static Single ReadBigEndainSingle(Stream ms)
|
|
||||||
{
|
|
||||||
byte[] SingleBytes = new byte[4];
|
|
||||||
ms.Read(SingleBytes, 0x00, 4);
|
|
||||||
SingleBytes = SingleBytes.Reverse().ToArray();
|
|
||||||
Single val = BitConverter.ToSingle(SingleBytes, 0x00);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
public static Single ReadLittleEndainSingle(Stream ms)
|
|
||||||
{
|
|
||||||
byte[] SingleBytes = new byte[4];
|
|
||||||
ms.Read(SingleBytes, 0x00, 4);
|
|
||||||
SingleBytes = SingleBytes.ToArray();
|
|
||||||
Single val = BitConverter.ToSingle(SingleBytes, 0x00);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
public static void WriteLittleEndainSingle(Stream ms, Single val)
|
|
||||||
{
|
{
|
||||||
byte[] SingleBytes = BitConverter.GetBytes(val);
|
MemoryStream Data = ByteToStream(Bytes);
|
||||||
ms.Write(SingleBytes, 0x00, SingleBytes.Length);
|
String header = ReadString(Data, 4);
|
||||||
}
|
if (header.StartsWith("VAG"))
|
||||||
public static void WriteBigEndainSingle(Stream ms, Single val)
|
{
|
||||||
{
|
return true;
|
||||||
byte[] SingleBytes = BitConverter.GetBytes(val);
|
}
|
||||||
SingleBytes = SingleBytes.Reverse().ToArray();
|
else
|
||||||
ms.Write(SingleBytes, 0x00, SingleBytes.Length);
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WriteLittleEndainInt(Stream ms, int val)
|
public static bool IsDDS(byte[] Bytes)
|
||||||
{
|
{
|
||||||
byte[] IntBytes = BitConverter.GetBytes(val);
|
MemoryStream Data = ByteToStream(Bytes);
|
||||||
ms.Write(IntBytes, 0x00, IntBytes.Length);
|
String header = ReadString(Data, 4);
|
||||||
}
|
if (header.StartsWith("DDS"))
|
||||||
public static void WriteBigEndainInt(Stream ms, int val)
|
{
|
||||||
{
|
return true;
|
||||||
byte[] IntBytes = BitConverter.GetBytes(val);
|
}
|
||||||
IntBytes = IntBytes.Reverse().ToArray();
|
else
|
||||||
ms.Write(IntBytes, 0x00, IntBytes.Length);
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int ReadLittleEndainInt(Stream ms)
|
|
||||||
|
public static bool IsRcf(byte[] Bytes)
|
||||||
{
|
{
|
||||||
byte[] IntBytes = new byte[4];
|
MemoryStream Data = ByteToStream(Bytes);
|
||||||
ms.Read(IntBytes, 0x00, 4);
|
String header = ReadString(Data, 5);
|
||||||
IntBytes = IntBytes.ToArray();
|
if (header.StartsWith("RCSF"))
|
||||||
int i = BitConverter.ToInt32(IntBytes, 0x00);
|
{
|
||||||
return i;
|
return true;
|
||||||
}
|
}
|
||||||
public static int ReadBigEndainInt(Stream ms)
|
else
|
||||||
{
|
{
|
||||||
byte[] IntBytes = new byte[4];
|
return false;
|
||||||
ms.Read(IntBytes, 0x00, 4);
|
}
|
||||||
IntBytes = IntBytes.Reverse().ToArray();
|
}
|
||||||
int i = BitConverter.ToInt32(IntBytes, 0x00);
|
|
||||||
return i;
|
public static bool IsGim(byte[] Bytes)
|
||||||
}
|
{
|
||||||
public static String GetRootFolder(string path)
|
MemoryStream Data = ByteToStream(Bytes);
|
||||||
{
|
String header = ReadString(Data, 4);
|
||||||
while (true)
|
if (header.StartsWith("MIG") || header.EndsWith("GIM"))
|
||||||
{
|
{
|
||||||
string temp = Path.GetDirectoryName(path);
|
return true;
|
||||||
if (String.IsNullOrEmpty(temp))
|
}
|
||||||
break;
|
else
|
||||||
path = temp;
|
{
|
||||||
}
|
return false;
|
||||||
return path;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String GenerateHash(byte[] Data)
|
public static bool IsZlib(byte[] Bytes)
|
||||||
{
|
{
|
||||||
SHA1 sha = SHA1.Create();
|
if (Bytes[0] == 0x78)
|
||||||
byte[] ShaBytes = sha.ComputeHash(Data);
|
{
|
||||||
return BitConverter.ToString(ShaBytes).Replace("-", "").ToUpper();
|
if (Bytes[1] == 0x01)
|
||||||
}
|
return true;
|
||||||
|
if (Bytes[1] == 0x9C)
|
||||||
public static string GenerateShortHash(byte[] Data)
|
return true;
|
||||||
{
|
if (Bytes[1] == 0xDA)
|
||||||
SHA1 sha = SHA1.Create();
|
return true;
|
||||||
byte[] ShaBytes = sha.ComputeHash(Data);
|
}
|
||||||
return BitConverter.ToInt32(ShaBytes, 0).ToString("X8");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String ReadString(Stream ms, int limit = -1)
|
|
||||||
{
|
|
||||||
int i = 0xFF;
|
public static Bitmap GetBitmap(byte[] BitmapBytes)
|
||||||
int counter = 0;
|
{
|
||||||
|
MemoryStream ms = ByteToStream(BitmapBytes);
|
||||||
MemoryStream StringStream = new MemoryStream();
|
Bitmap bmp = new Bitmap(ms);
|
||||||
|
ms.Dispose();
|
||||||
do
|
return bmp;
|
||||||
{
|
}
|
||||||
i = ms.ReadByte();
|
|
||||||
if (i == 0 || counter == limit)
|
public static String ReadStringAt(Stream ms, int location)
|
||||||
break;
|
{
|
||||||
StringStream.WriteByte((byte)i);
|
long ogPos = ms.Position;
|
||||||
counter += 1;
|
ms.Seek(location, SeekOrigin.Begin);
|
||||||
}
|
String str = ReadString(ms);
|
||||||
while (true);
|
ms.Seek(ogPos, SeekOrigin.Begin);
|
||||||
|
return str;
|
||||||
byte[] StringData = StringStream.ToArray();
|
}
|
||||||
|
|
||||||
String str = Encoding.UTF8.GetString(StringData);
|
public static int ReadLittleEndainIntAt(Stream ms, int location)
|
||||||
|
{
|
||||||
return str;
|
long ogPos = ms.Position;
|
||||||
|
ms.Seek(location, SeekOrigin.Begin);
|
||||||
}
|
int i = ReadLittleEndainInt(ms);
|
||||||
}
|
ms.Seek(ogPos, SeekOrigin.Begin);
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int ReadIntAt(Stream ms, int location)
|
||||||
|
{
|
||||||
|
long ogPos = ms.Position;
|
||||||
|
ms.Seek(location, SeekOrigin.Begin);
|
||||||
|
int i = ReadInt32(ms);
|
||||||
|
ms.Seek(ogPos, SeekOrigin.Begin);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
public static bool HasBinaryContent(string content)
|
||||||
|
{
|
||||||
|
return content.Any(ch => char.IsControl(ch) && ch != '\r' && ch != '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void WriteInt32(Stream ms, int val)
|
||||||
|
{
|
||||||
|
if (BigEndain)
|
||||||
|
WriteBigEndainInt(ms, val);
|
||||||
|
else
|
||||||
|
WriteLittleEndainInt(ms, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteSingle(Stream ms, Single val)
|
||||||
|
{
|
||||||
|
if (BigEndain)
|
||||||
|
WriteBigEndainSingle(ms, val);
|
||||||
|
else
|
||||||
|
WriteLittleEndainSingle(ms, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ReadInt32(Stream ms)
|
||||||
|
{
|
||||||
|
if (BigEndain)
|
||||||
|
return ReadBigEndainInt(ms);
|
||||||
|
else
|
||||||
|
return ReadLittleEndainInt(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Single ReadSingle(Stream ms)
|
||||||
|
{
|
||||||
|
if (BigEndain)
|
||||||
|
return ReadBigEndainSingle(ms);
|
||||||
|
else
|
||||||
|
return ReadLittleEndainSingle(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int ReadBigEndainIntAt(Stream ms, int location)
|
||||||
|
{
|
||||||
|
long ogPos = ms.Position;
|
||||||
|
ms.Seek(location, SeekOrigin.Begin);
|
||||||
|
int i = ReadBigEndainInt(ms);
|
||||||
|
ms.Seek(ogPos, SeekOrigin.Begin);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
public static Single ReadBigEndainSingle(Stream ms)
|
||||||
|
{
|
||||||
|
byte[] SingleBytes = new byte[4];
|
||||||
|
ms.Read(SingleBytes, 0x00, 4);
|
||||||
|
SingleBytes = SingleBytes.Reverse().ToArray();
|
||||||
|
Single val = BitConverter.ToSingle(SingleBytes, 0x00);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
public static Single ReadLittleEndainSingle(Stream ms)
|
||||||
|
{
|
||||||
|
byte[] SingleBytes = new byte[4];
|
||||||
|
ms.Read(SingleBytes, 0x00, 4);
|
||||||
|
SingleBytes = SingleBytes.ToArray();
|
||||||
|
Single val = BitConverter.ToSingle(SingleBytes, 0x00);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
public static void WriteLittleEndainSingle(Stream ms, Single val)
|
||||||
|
{
|
||||||
|
byte[] SingleBytes = BitConverter.GetBytes(val);
|
||||||
|
ms.Write(SingleBytes, 0x00, SingleBytes.Length);
|
||||||
|
}
|
||||||
|
public static void WriteBigEndainSingle(Stream ms, Single val)
|
||||||
|
{
|
||||||
|
byte[] SingleBytes = BitConverter.GetBytes(val);
|
||||||
|
SingleBytes = SingleBytes.Reverse().ToArray();
|
||||||
|
ms.Write(SingleBytes, 0x00, SingleBytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteLittleEndainInt(Stream ms, int val)
|
||||||
|
{
|
||||||
|
byte[] IntBytes = BitConverter.GetBytes(val);
|
||||||
|
ms.Write(IntBytes, 0x00, IntBytes.Length);
|
||||||
|
}
|
||||||
|
public static void WriteBigEndainInt(Stream ms, int val)
|
||||||
|
{
|
||||||
|
byte[] IntBytes = BitConverter.GetBytes(val);
|
||||||
|
IntBytes = IntBytes.Reverse().ToArray();
|
||||||
|
ms.Write(IntBytes, 0x00, IntBytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int ReadLittleEndainInt(Stream ms)
|
||||||
|
{
|
||||||
|
byte[] IntBytes = new byte[4];
|
||||||
|
ms.Read(IntBytes, 0x00, 4);
|
||||||
|
IntBytes = IntBytes.ToArray();
|
||||||
|
int i = BitConverter.ToInt32(IntBytes, 0x00);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
public static int ReadBigEndainInt(Stream ms)
|
||||||
|
{
|
||||||
|
byte[] IntBytes = new byte[4];
|
||||||
|
ms.Read(IntBytes, 0x00, 4);
|
||||||
|
IntBytes = IntBytes.Reverse().ToArray();
|
||||||
|
int i = BitConverter.ToInt32(IntBytes, 0x00);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
public static String GetRootFolder(string path)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
string temp = Path.GetDirectoryName(path);
|
||||||
|
if (String.IsNullOrEmpty(temp))
|
||||||
|
break;
|
||||||
|
path = temp;
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GenerateHash(byte[] Data)
|
||||||
|
{
|
||||||
|
SHA1 sha = SHA1.Create();
|
||||||
|
byte[] ShaBytes = sha.ComputeHash(Data);
|
||||||
|
return BitConverter.ToString(ShaBytes).Replace("-", "").ToUpper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GenerateShortHash(byte[] Data)
|
||||||
|
{
|
||||||
|
SHA1 sha = SHA1.Create();
|
||||||
|
byte[] ShaBytes = sha.ComputeHash(Data);
|
||||||
|
return BitConverter.ToInt32(ShaBytes, 0).ToString("X8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String ReadString(Stream ms, int limit = -1)
|
||||||
|
{
|
||||||
|
int i = 0xFF;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
MemoryStream StringStream = new MemoryStream();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
i = ms.ReadByte();
|
||||||
|
if (i == 0 || counter == limit)
|
||||||
|
break;
|
||||||
|
StringStream.WriteByte((byte)i);
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
while (true);
|
||||||
|
|
||||||
|
byte[] StringData = StringStream.ToArray();
|
||||||
|
|
||||||
|
String str = Encoding.UTF8.GetString(StringData);
|
||||||
|
|
||||||
|
return str;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue