Browse Source

Add methods to extract/insert script from evtitem.dat

master
BahaBulle 8 years ago
parent
commit
1b591b8e7b
1 changed files with 127 additions and 15 deletions
  1. +127
    -15
      Hack.Xenosaga/Process/Scripts.cs

+ 127
- 15
Hack.Xenosaga/Process/Scripts.cs View File

@ -65,7 +65,7 @@ namespace Hack.Xenosaga.Process
br.ReadUInt32();
}
using (StreamWriter sw = new StreamWriter(Variables.dirExtract + filename + ".txt", false, encode))
using (StreamWriter sw = new StreamWriter(Variables.dirExtract + Path.GetFileName(filename) + ".txt", false, encode))
{
// Extracting text from pointers
foreach (Pointers pt in tblPt.ListPointers)
@ -188,9 +188,108 @@ namespace Hack.Xenosaga.Process
#endregion
#region evtitem.dat
public static bool extractEvtitem(string filename, Encoding encode)
{
int numBloc = 0;
int sizeBloc = 128;
long pos = 0;
try
{
Trace.Write("Extract evtitem.dat : ");
Directory.CreateDirectory(Variables.dirExtract);
Directory.CreateDirectory(Variables.dirInsert);
using (BinaryReader br = new BinaryReader(File.Open(filename, FileMode.Open)))
{
Table tbl = new Table(encode);
tbl.Load(Variables.tblEvtItem);
using (StreamWriter sw = new StreamWriter(Variables.dirExtract + Path.GetFileName(filename) + ".txt", false, encode))
{
while (br.PeekChar() != 0)
{
sw.Write(string.Format("[{0:d4}]\n", numBloc));
// Read object name
sw.Write(tbl.BytesToString(br));
// Read object description
sw.Write(tbl.BytesToString(br));
pos += sizeBloc;
numBloc++;
br.BaseStream.Position = pos;
}
}
}
Trace.WriteLine("OK");
}
catch (Exception ex)
{
Trace.WriteLine(string.Format("ERROR : {0}", ex.Message));
return false;
}
return true;
}
private static bool insertEvtitem(string filename, Encoding encode)
{
string name = Path.GetFileName(filename);
int sizeBloc = 128;
try
{
Trace.Write("Insert evtitem.dat : ");
using (BinaryReader brOriginalDatFile = new BinaryReader(File.Open(filename, FileMode.Open)))
using (MemoryStream ms = new MemoryStream())
{
cTblPointers tblPt = new cTblPointers();
Table tbl = loadTable(Variables.tblEvtItem, encode);
Dictionary<string, byte[]> bytes = tbl.StringToBytesArray(Variables.dirInsert + name + ".txt", new Regex(@"\[(.{4})\]\n"));
foreach (KeyValuePair<string, byte[]> b in bytes)
{
if (b.Value.Length > sizeBloc)
throw new Exception(string.Format("Bloc [{0}] too long : {1}/{2}!", b.Key, b.Value.Length, sizeBloc));
ms.Write(b.Value, 0, b.Value.Length);
ms.Padding(sizeBloc);
}
Directory.CreateDirectory(Variables.dirPack);
using (FileStream fs = new FileStream(Variables.dirPack + name, FileMode.Create))
{
ms.Position = 0;
ms.CopyTo(fs);
}
}
Trace.WriteLine("OK");
return true;
}
catch (Exception ex)
{
Trace.WriteLine(string.Format("ERROR : {0}", ex.Message));
return false;
}
}
#endregion
#region *.evt
private static bool decompilEvt(string nameFile, MemoryStream ms)
private static bool decompilEvt(string nameFile, MemoryStream ms, string nameTable)
{
Encoding encode = new UTF8Encoding(false);
@ -200,18 +299,13 @@ namespace Hack.Xenosaga.Process
jc.load(br);
//using (StreamWriter sw = new StreamWriter("ST0210_constantes.txt"))
//{
// jc.writeConstants(sw);
//}
Dictionary<int, byte[]> dictBytes = jc.getConstantsBytes();
if (dictBytes.Count > 0)
{
using (StreamWriter sw = new StreamWriter(Variables.dirExtract + nameFile + ".txt", false, encode))
{
Table tbl = loadTable(Variables.tblEvt, Encoding.Default);
Table tbl = loadTable(nameTable, Encoding.Default);
foreach (KeyValuePair<int, byte[]> bytes in dictBytes)
{
@ -235,6 +329,10 @@ namespace Hack.Xenosaga.Process
evtClass evtFile = new evtClass(pathName);
string nameTable = Variables.tblEvtBox;
if (Path.GetFileName(pathName).Substring(0, 3).ToUpper() == "SCE")
nameTable = Variables.tblEvtVideo;
Directory.CreateDirectory(Variables.dirExtract);
Directory.CreateDirectory(Variables.dirInsert);
@ -245,7 +343,7 @@ namespace Hack.Xenosaga.Process
ms.Write(file.file, 0, (int)file.fileLength);
ms.Position = 0;
decompilEvt(file.name, ms);
decompilEvt(file.name, ms, nameTable);
}
}
@ -270,7 +368,11 @@ namespace Hack.Xenosaga.Process
{
evtClass origEvt = new evtClass(br);
Table tbl = loadTable(Variables.tblEvt, Encoding.Default);
Table tbl;
if (Path.GetFileName(pathName).Substring(0, 3).ToUpper() == "SCE")
tbl = loadTable(Variables.tblEvtVideo, Encoding.Default);
else
tbl = loadTable(Variables.tblEvtBox, Encoding.Default);
using (MemoryStream destEvt = new MemoryStream())
{
@ -345,7 +447,7 @@ namespace Hack.Xenosaga.Process
destEvt.Write(classFile.file, 0, (int)classFile.fileLength);
}
Functions.Padding(destEvt);
destEvt.Padding();
}
long posName = destEvt.Position;
@ -406,6 +508,9 @@ namespace Hack.Xenosaga.Process
if (Path.GetFileName(pathName) == "card.dat")
result = extractCard(pathName, encode);
if (Path.GetFileName(pathName) == "evtitem.dat")
result = extractEvtitem(pathName, encode);
if (Path.GetExtension(pathName) == ".evt")
result = extractEvt(pathName, encode);
}
@ -420,6 +525,8 @@ namespace Hack.Xenosaga.Process
{
if (Path.GetFileName(file) == "card.dat")
result = extractCard(file.ToLower(), encode);
else if (Path.GetFileName(file) == "evtitem.dat")
result = extractEvtitem(file.ToLower(), encode);
else if (Path.GetExtension(file) == ".evt")
result = extractEvt(file.ToLower(), encode);
}
@ -434,10 +541,13 @@ namespace Hack.Xenosaga.Process
if (File.Exists(pathName))
{
if (Path.GetFileName(pathName) == "card.dat")
if (Path.GetFileName(pathName).ToLower() == "card.dat")
result = insertCard(pathName, encode);
if (Path.GetExtension(pathName) == ".evt")
if (Path.GetFileName(pathName).ToLower() == "evtitem.dat")
result = insertEvtitem(pathName, encode);
if (Path.GetExtension(pathName).ToLower() == ".evt")
result = insertEvt(pathName, encode);
}
else if (Directory.Exists(pathName))
@ -449,9 +559,11 @@ namespace Hack.Xenosaga.Process
foreach (string file in listFiles)
{
if (Path.GetFileName(file) == "card.dat")
if (Path.GetFileName(file).ToLower() == "card.dat")
result = insertCard(file.ToLower(), encode);
else if (Path.GetExtension(file) == ".evt")
else if (Path.GetFileName(file).ToLower() == "evtitem.dat")
result = insertEvtitem(file.ToLower(), encode);
else if (Path.GetExtension(file).ToLower() == ".evt")
result = insertEvt(file.ToLower(), encode);
}
}


Loading…
Cancel
Save