@ -65,7 +65,7 @@ namespace Hack.Xenosaga.Process
br . ReadUInt32 ( ) ;
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
// Extracting text from pointers
foreach ( Pointers pt in tblPt . ListPointers )
foreach ( Pointers pt in tblPt . ListPointers )
@ -188,9 +188,108 @@ namespace Hack.Xenosaga.Process
#endregion
#endregion
#region evtitem.dat
public static bool extractEvtitem ( string filename , Encoding encode )
{
int numBloc = 0 ;
int sizeBloc = 1 2 8 ;
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 = 1 2 8 ;
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
#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 ) ;
Encoding encode = new UTF8Encoding ( false ) ;
@ -200,18 +299,13 @@ namespace Hack.Xenosaga.Process
jc . load ( br ) ;
jc . load ( br ) ;
//using (StreamWriter sw = new StreamWriter("ST0210_constantes.txt"))
//{
// jc.writeConstants(sw);
//}
Dictionary < int , byte [ ] > dictBytes = jc . getConstantsBytes ( ) ;
Dictionary < int , byte [ ] > dictBytes = jc . getConstantsBytes ( ) ;
if ( dictBytes . Count > 0 )
if ( dictBytes . Count > 0 )
{
{
using ( StreamWriter sw = new StreamWriter ( Variables . dirExtract + nameFile + ".txt" , false , encode ) )
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 )
foreach ( KeyValuePair < int , byte [ ] > bytes in dictBytes )
{
{
@ -235,6 +329,10 @@ namespace Hack.Xenosaga.Process
evtClass evtFile = new evtClass ( pathName ) ;
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 . dirExtract ) ;
Directory . CreateDirectory ( Variables . dirInsert ) ;
Directory . CreateDirectory ( Variables . dirInsert ) ;
@ -245,7 +343,7 @@ namespace Hack.Xenosaga.Process
ms . Write ( file . file , 0 , ( int ) file . fileLength ) ;
ms . Write ( file . file , 0 , ( int ) file . fileLength ) ;
ms . Position = 0 ;
ms . Position = 0 ;
decompilEvt ( file . name , ms ) ;
decompilEvt ( file . name , ms , nameTable ) ;
}
}
}
}
@ -264,13 +362,17 @@ namespace Hack.Xenosaga.Process
{
{
try
try
{
{
Trace . WriteLine ( string . Format ( "Insert {0} : " , pathName ) ) ;
Trace . Write ( string . Format ( "Insert {0} : " , pathName ) ) ;
using ( BinaryReader br = new BinaryReader ( File . Open ( pathName , FileMode . Open ) ) )
using ( BinaryReader br = new BinaryReader ( File . Open ( pathName , FileMode . Open ) ) )
{
{
evtClass origEvt = new evtClass ( br ) ;
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 ( ) )
using ( MemoryStream destEvt = new MemoryStream ( ) )
{
{
@ -323,9 +425,14 @@ namespace Hack.Xenosaga.Process
foreach ( KeyValuePair < int , byte [ ] > bytes in dictBytes )
foreach ( KeyValuePair < int , byte [ ] > bytes in dictBytes )
{
{
pt = string . Format ( "{0:X4}" , bytes . Key ) ;
pt = string . Format ( "{0:X4}" , bytes . Key ) ;
if ( dictBytes . ContainsKey ( Convert . ToInt32 ( pt , 1 6 ) ) & & list [ pt ] ! = null )
if ( dictBytes . ContainsKey ( Convert . ToInt32 ( pt , 1 6 ) ) & & list [ pt ] ! = null )
{
if ( list [ pt ] . Length > = 2 5 5 )
throw new Exception ( "Line too long (254 characters max)!" ) ;
jc . setConstantsBytes ( bytes . Key , list [ pt ] ) ;
jc . setConstantsBytes ( bytes . Key , list [ pt ] ) ;
}
}
}
}
}
@ -340,7 +447,7 @@ namespace Hack.Xenosaga.Process
destEvt . Write ( classFile . file , 0 , ( int ) classFile . fileLength ) ;
destEvt . Write ( classFile . file , 0 , ( int ) classFile . fileLength ) ;
}
}
Functions . Padding ( destEvt ) ;
destEvt . Padding ( ) ;
}
}
long posName = destEvt . Position ;
long posName = destEvt . Position ;
@ -401,6 +508,9 @@ namespace Hack.Xenosaga.Process
if ( Path . GetFileName ( pathName ) = = "card.dat" )
if ( Path . GetFileName ( pathName ) = = "card.dat" )
result = extractCard ( pathName , encode ) ;
result = extractCard ( pathName , encode ) ;
if ( Path . GetFileName ( pathName ) = = "evtitem.dat" )
result = extractEvtitem ( pathName , encode ) ;
if ( Path . GetExtension ( pathName ) = = ".evt" )
if ( Path . GetExtension ( pathName ) = = ".evt" )
result = extractEvt ( pathName , encode ) ;
result = extractEvt ( pathName , encode ) ;
}
}
@ -415,6 +525,8 @@ namespace Hack.Xenosaga.Process
{
{
if ( Path . GetFileName ( file ) = = "card.dat" )
if ( Path . GetFileName ( file ) = = "card.dat" )
result = extractCard ( file . ToLower ( ) , encode ) ;
result = extractCard ( file . ToLower ( ) , encode ) ;
else if ( Path . GetFileName ( file ) = = "evtitem.dat" )
result = extractEvtitem ( file . ToLower ( ) , encode ) ;
else if ( Path . GetExtension ( file ) = = ".evt" )
else if ( Path . GetExtension ( file ) = = ".evt" )
result = extractEvt ( file . ToLower ( ) , encode ) ;
result = extractEvt ( file . ToLower ( ) , encode ) ;
}
}
@ -429,10 +541,13 @@ namespace Hack.Xenosaga.Process
if ( File . Exists ( pathName ) )
if ( File . Exists ( pathName ) )
{
{
if ( Path . GetFileName ( pathName ) = = "card.dat" )
if ( Path . GetFileName ( pathName ) . ToLower ( ) = = "card.dat" )
result = insertCard ( pathName , encode ) ;
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 ) ;
result = insertEvt ( pathName , encode ) ;
}
}
else if ( Directory . Exists ( pathName ) )
else if ( Directory . Exists ( pathName ) )
@ -444,9 +559,11 @@ namespace Hack.Xenosaga.Process
foreach ( string file in listFiles )
foreach ( string file in listFiles )
{
{
if ( Path . GetFileName ( file ) = = "card.dat" )
if ( Path . GetFileName ( file ) . ToLower ( ) = = "card.dat" )
result = insertCard ( file . ToLower ( ) , encode ) ;
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 ) ;
result = insertEvt ( file . ToLower ( ) , encode ) ;
}
}
}
}