2017-03-06 17:30:50 -08:00
using System.IO ;
2017-03-12 20:21:34 -05:00
using log4net ;
2017-03-06 17:30:50 -08:00
namespace ACE.DatLoader
{
2018-01-23 04:02:39 -06:00
public static class DatManager
2017-03-06 17:30:50 -08:00
{
2017-03-16 22:39:29 -04:00
private static readonly ILog log = LogManager . GetLogger ( System . Reflection . MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
2017-03-06 17:30:50 -08:00
private static string datFile ;
2017-03-15 08:12:21 -04:00
2017-03-06 17:30:50 -08:00
private static int count ;
2020-05-23 10:23:45 -07:00
// End of retail Iteration versions.
private static int ITERATION_CELL = 982 ;
private static int ITERATION_PORTAL = 2072 ;
private static int ITERATION_HIRES = 497 ;
private static int ITERATION_LANGUAGE = 994 ;
2018-02-09 06:46:49 -06:00
public static CellDatDatabase CellDat { get ; private set ; }
2017-03-15 08:12:21 -04:00
2018-02-09 06:46:49 -06:00
public static PortalDatDatabase PortalDat { get ; private set ; }
2018-12-02 13:46:01 -06:00
public static DatDatabase HighResDat { get ; private set ; }
2019-02-07 16:39:30 -05:00
public static LanguageDatDatabase LanguageDat { get ; private set ; }
2017-06-20 12:17:22 -05:00
2018-11-22 01:33:17 -05:00
public static void Initialize ( string datFileDirectory , bool keepOpen = false , bool loadCell = true )
2017-03-06 17:30:50 -08:00
{
2018-02-03 17:54:07 -06:00
var datDir = Path . GetFullPath ( Path . Combine ( datFileDirectory ) ) ;
2018-01-23 04:02:39 -06:00
2018-11-22 01:33:17 -05:00
if ( loadCell )
2017-03-06 17:30:50 -08:00
{
2018-11-22 01:33:17 -05:00
try
{
datFile = Path . Combine ( datDir , "client_cell_1.dat" ) ;
CellDat = new CellDatDatabase ( datFile , keepOpen ) ;
count = CellDat . AllFiles . Count ;
2020-05-23 10:23:45 -07:00
log . Info ( $"Successfully opened {datFile} file, containing {count} records, iteration {CellDat.Iteration}" ) ;
if ( CellDat . Iteration ! = ITERATION_CELL )
log . Warn ( $"{datFile} iteration does not match expected end-of-retail version of {ITERATION_CELL}." ) ;
2018-11-22 01:33:17 -05:00
}
catch ( FileNotFoundException ex )
{
2019-08-30 19:25:35 -05:00
log . Error ( $"An exception occured while attempting to open {datFile} file! This needs to be corrected in order for Landblocks to load!" ) ;
log . Error ( $"Exception: {ex.Message}" ) ;
2018-11-22 01:33:17 -05:00
}
2017-03-06 17:30:50 -08:00
}
try
{
2017-04-04 12:44:57 -04:00
datFile = Path . Combine ( datDir , "client_portal.dat" ) ;
2018-11-20 07:45:09 -06:00
PortalDat = new PortalDatDatabase ( datFile , keepOpen ) ;
2019-04-28 01:30:45 -04:00
PortalDat . SkillTable . AddRetiredSkills ( ) ;
2018-02-09 06:46:49 -06:00
count = PortalDat . AllFiles . Count ;
2020-05-23 10:23:45 -07:00
log . Info ( $"Successfully opened {datFile} file, containing {count} records, iteration {PortalDat.Iteration}" ) ;
if ( PortalDat . Iteration ! = ITERATION_PORTAL )
log . Warn ( $"{datFile} iteration does not match expected end-of-retail version of {ITERATION_PORTAL}." ) ;
2017-03-06 17:30:50 -08:00
}
catch ( FileNotFoundException ex )
{
2019-08-30 19:25:35 -05:00
log . Error ( $"An exception occured while attempting to open {datFile} file!\n\n *** Please check your 'DatFilesDirectory' setting in the config.js file. ***\n *** ACE will not run properly without this properly configured! ***\n" ) ;
log . Error ( $"Exception: {ex.Message}" ) ;
2017-03-06 17:30:50 -08:00
}
2018-07-05 05:50:42 -07:00
2018-07-05 13:09:20 -07:00
// Load the client_highres.dat file. This is not required for ACE operation, so no exception needs to be generated.
datFile = Path . Combine ( datDir , "client_highres.dat" ) ;
if ( File . Exists ( datFile ) )
2018-11-22 01:33:17 -05:00
{
2018-12-02 13:46:01 -06:00
HighResDat = new DatDatabase ( datFile , keepOpen ) ;
2018-07-05 05:50:42 -07:00
count = HighResDat . AllFiles . Count ;
2020-05-23 10:23:45 -07:00
log . Info ( $"Successfully opened {datFile} file, containing {count} records, iteration {HighResDat.Iteration}" ) ;
if ( HighResDat . Iteration ! = ITERATION_HIRES )
log . Warn ( $"{datFile} iteration does not match expected end-of-retail version of {ITERATION_HIRES}." ) ;
2018-07-05 05:50:42 -07:00
}
2019-02-07 16:39:30 -05:00
try
2018-07-05 05:50:42 -07:00
{
2019-02-07 16:39:30 -05:00
datFile = Path . Combine ( datDir , "client_local_English.dat" ) ;
LanguageDat = new LanguageDatDatabase ( datFile , keepOpen ) ;
2018-07-05 05:50:42 -07:00
count = LanguageDat . AllFiles . Count ;
2020-05-23 10:23:45 -07:00
log . Info ( $"Successfully opened {datFile} file, containing {count} records, iteration {LanguageDat.Iteration}" ) ;
if ( LanguageDat . Iteration ! = ITERATION_LANGUAGE )
log . Warn ( $"{datFile} iteration does not match expected end-of-retail version of {ITERATION_LANGUAGE}." ) ;
2018-07-05 05:50:42 -07:00
}
2019-02-07 16:39:30 -05:00
catch ( FileNotFoundException ex )
{
2019-08-30 19:25:35 -05:00
log . Error ( $"An exception occured while attempting to open {datFile} file!\n\n *** Please check your 'DatFilesDirectory' setting in the config.json file. ***\n *** ACE will not run properly without this properly configured! ***\n" ) ;
log . Error ( $"Exception: {ex.Message}" ) ;
2019-02-07 16:39:30 -05:00
}
2017-03-06 17:30:50 -08:00
}
}
}