Add more code
This commit is contained in:
parent
29bf9fabed
commit
a4e56b8675
|
@ -100,7 +100,7 @@ namespace CXML
|
|||
IntIDTable = Tools.ByteToStream(GetIntIDTable());
|
||||
StringTable = Tools.ByteToStream(GetStringTable());
|
||||
CharTable = Tools.ByteToStream(GetCharTable());
|
||||
HashIDTable = Tools.ByteToStream(GetStyleIDTable());
|
||||
HashIDTable = Tools.ByteToStream(GetHashIDTable());
|
||||
IntArrayTable = Tools.ByteToStream(GetIntArrayTable());
|
||||
FloatArrayTable = Tools.ByteToStream(GetFloatArrayTable());
|
||||
FileTable = Tools.ByteToStream(GetFileTable());
|
||||
|
@ -195,12 +195,12 @@ namespace CXML
|
|||
return Tools.ReadIntAt(InfoFile, 0x2C);
|
||||
}
|
||||
|
||||
public static int GetStyleIDTableOffset()
|
||||
public static int GetHashIDTableOffset()
|
||||
{
|
||||
return Tools.ReadIntAt(InfoFile, 0x30);
|
||||
}
|
||||
|
||||
public static int GetStyleIDTableSize()
|
||||
public static int GetHashIDTableSize()
|
||||
{
|
||||
return Tools.ReadIntAt(InfoFile, 0x34);
|
||||
}
|
||||
|
@ -285,14 +285,14 @@ namespace CXML
|
|||
return CharTable;
|
||||
}
|
||||
|
||||
public static byte[] GetStyleIDTable()
|
||||
public static byte[] GetHashIDTable()
|
||||
{
|
||||
int StyleIDTableOffset = GetStyleIDTableOffset();
|
||||
int StyleIDTableSize = GetStyleIDTableSize();
|
||||
InfoFile.Seek(StyleIDTableOffset, SeekOrigin.Begin);
|
||||
byte[] StyleIDTable = new byte[StyleIDTableSize];
|
||||
InfoFile.Read(StyleIDTable, 0x00, StyleIDTableSize);
|
||||
return StyleIDTable;
|
||||
int HashIDTableOffset = GetHashIDTableOffset();
|
||||
int HashIDTableSize = GetHashIDTableSize();
|
||||
InfoFile.Seek(HashIDTableOffset, SeekOrigin.Begin);
|
||||
byte[] HashIDTable = new byte[HashIDTableSize];
|
||||
InfoFile.Read(HashIDTable, 0x00, HashIDTableSize);
|
||||
return HashIDTable;
|
||||
}
|
||||
|
||||
public static byte[] GetIntArrayTable()
|
||||
|
@ -427,7 +427,7 @@ namespace CXML
|
|||
break;
|
||||
case AttributeType.TYPE_FLOAT:
|
||||
float FloatValue = bTreeTable.ReadSingle();
|
||||
AttributeValue = FloatValue;
|
||||
AttributeValue = FloatValue.ToString()+"f";
|
||||
TreeTable.Seek(4, SeekOrigin.Current);
|
||||
break;
|
||||
case AttributeType.TYPE_STRING:
|
||||
|
@ -483,7 +483,7 @@ namespace CXML
|
|||
for(int i = 0; i < FloatArraySize; i++)
|
||||
{
|
||||
FloatValue = bFloatArrayTable.ReadSingle();
|
||||
StrList.Add(FloatValue.ToString());
|
||||
StrList.Add(FloatValue.ToString()+"f");
|
||||
}
|
||||
string[] StrArray = StrList.ToArray();
|
||||
AttributeValue = String.Join(", ", StrArray);
|
||||
|
@ -491,33 +491,29 @@ namespace CXML
|
|||
case AttributeType.TYPE_FILE:
|
||||
int FilePtr = bTreeTable.ReadInt32();
|
||||
int FileSz = bTreeTable.ReadInt32();
|
||||
|
||||
String FileName = "";
|
||||
|
||||
|
||||
Byte[] FileData = new Byte[FileSz];
|
||||
FileTable.Seek(FilePtr, SeekOrigin.Begin);
|
||||
FileTable.Read(FileData, 0, FileSz);
|
||||
string FileHash = Tools.GenerateHash(FileData);
|
||||
|
||||
int count = 0;
|
||||
string CounterStr = count.ToString();
|
||||
do
|
||||
String Extension = Tools.GetFileExtension(FileData);
|
||||
String FileName = Path.Combine(FileDir, ElementName, FileHash + Extension);
|
||||
if(!File.Exists(FileName))
|
||||
{
|
||||
String Extension = Tools.GetFileExtension(FileData);
|
||||
CounterStr = count.ToString();
|
||||
if (count == 0)
|
||||
CounterStr = "";
|
||||
FileName = Path.Combine(FileDir , ElementName , AttributeName + CounterStr + Extension);
|
||||
count++;
|
||||
Console.WriteLine("Writing: " + FileName);
|
||||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(FileName)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
|
||||
|
||||
File.WriteAllBytes(FileName, FileData);
|
||||
ProcessFile(FileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("File allready extracted \n(theres a VERY low chance that it acturally is a different file that has the same hash.)");
|
||||
}
|
||||
while (File.Exists(FileName));
|
||||
|
||||
Console.WriteLine("Writing: " + FileName);
|
||||
|
||||
if (!Directory.Exists(Path.GetDirectoryName(FileName)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
|
||||
|
||||
File.WriteAllBytes(FileName, FileData);
|
||||
ProcessFile(FileName);
|
||||
|
||||
AttributeValue = FileName;
|
||||
break;
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace CXMLCli
|
|||
if ((ArgsFull.Contains("-sit") || ArgsFull.Contains("--dump-style-id")) /*kept for backwards comp*/ || (ArgsFull.Contains("-hit") || ArgsFull.Contains("--dump-hash-id")))
|
||||
{
|
||||
Console.WriteLine("Dumping hash ID table.");
|
||||
File.WriteAllBytes("hash-id-table.bin", CXML.CXMLParser.GetStyleIDTable());
|
||||
File.WriteAllBytes("hash-id-table.bin", CXML.CXMLParser.GetHashIDTable());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -203,6 +204,14 @@ namespace General
|
|||
return i;
|
||||
}
|
||||
|
||||
public static String GenerateHash(byte[] Data)
|
||||
{
|
||||
SHA1 sha = SHA1.Create();
|
||||
byte[] ShaBytes = sha.ComputeHash(Data);
|
||||
int Hash = BitConverter.ToInt32(ShaBytes, 0);
|
||||
return Hash.ToString("X8");
|
||||
}
|
||||
|
||||
public static String ReadString(Stream ms, int limit = -1)
|
||||
{
|
||||
int i = 0xFF;
|
||||
|
|
Loading…
Reference in New Issue