|
@@ -17,40 +17,26 @@
|
|
#include "Subfiles/UnknownSubfile.h"
|
|
#include "Subfiles/UnknownSubfile.h"
|
|
|
|
|
|
namespace LOTRO_DAT {
|
|
namespace LOTRO_DAT {
|
|
- std::set<long long> SubDirectory::visited_subdirectories_ = std::set<long long>();
|
|
|
|
|
|
+ std::unordered_set<long long> SubDirectory::visited_subdirectories_ = std::unordered_set<long long>();
|
|
|
|
+ std::unordered_set<long long> SubDirectory::visited_subfiles_ = std::unordered_set<long long>();
|
|
|
|
+ std::set<std::shared_ptr<SubDirectory>, SubDirectory::SubDirectoryOffsetComp> SubDirectory::subdir_init_queue_
|
|
|
|
+ = std::set<std::shared_ptr<SubDirectory>, SubDirectory::SubDirectoryOffsetComp>();
|
|
|
|
+ std::set<std::shared_ptr<SubDirectory>, SubDirectory::SubDirectoryOffsetComp> SubDirectory::subfile_init_queue_
|
|
|
|
+ = std::set<std::shared_ptr<SubDirectory>, SubDirectory::SubDirectoryOffsetComp>();
|
|
|
|
|
|
- SubDirectory::SubDirectory() {
|
|
|
|
- offset_ = 0;
|
|
|
|
- }
|
|
|
|
|
|
|
|
SubDirectory::~SubDirectory() {
|
|
SubDirectory::~SubDirectory() {
|
|
subfiles_.clear();
|
|
subfiles_.clear();
|
|
subdirs_.clear();
|
|
subdirs_.clear();
|
|
}
|
|
}
|
|
|
|
|
|
- SubDirectory::SubDirectory(long long offset, DatFile *dat, long long max_subdirs) :
|
|
|
|
|
|
+ SubDirectory::SubDirectory(long long offset, DatFile &dat, long long max_subdirs) :
|
|
dat_(dat), offset_(offset), max_subdirs_(max_subdirs) {
|
|
dat_(dat), offset_(offset), max_subdirs_(max_subdirs) {
|
|
- LOG(DEBUG) << "Initialising " << offset_ << " SubDirectory";
|
|
|
|
- LOG(DEBUG) << "Processing SubDirectories";
|
|
|
|
-
|
|
|
|
- if (!MakeSubDirectories()) {
|
|
|
|
- subfiles_.clear();
|
|
|
|
- subdirs_.clear();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- LOG(DEBUG) << "Processing SubFiles";
|
|
|
|
- if (!MakeSubFiles()) {
|
|
|
|
- subfiles_.clear();
|
|
|
|
- subdirs_.clear();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- LOG(DEBUG) << "SubDirectory " << offset_ << " initialized successfully";
|
|
|
|
}
|
|
}
|
|
|
|
|
|
bool SubDirectory::MakeSubDirectories() {
|
|
bool SubDirectory::MakeSubDirectories() {
|
|
BinaryData data(1024);
|
|
BinaryData data(1024);
|
|
- dat_->ReadData(data, 63 * 8, offset_);
|
|
|
|
|
|
+ dat_.ReadData(data, 63 * 8, offset_);
|
|
|
|
|
|
if (data.Empty()) {
|
|
if (data.Empty()) {
|
|
LOG(ERROR) << "(READ ERROR) Incorrect directory at offset " << offset_;
|
|
LOG(ERROR) << "(READ ERROR) Incorrect directory at offset " << offset_;
|
|
@@ -74,18 +60,20 @@ namespace LOTRO_DAT {
|
|
|
|
|
|
SubDirectory *subdir = new SubDirectory(data.ToNumber<4>(i + 4), dat_);
|
|
SubDirectory *subdir = new SubDirectory(data.ToNumber<4>(i + 4), dat_);
|
|
|
|
|
|
- if (subdir->subfiles_.empty() && subdir->subdirs_.empty()) {
|
|
|
|
- LOG(WARNING) << "Sub-subdirectory is empty or made empty... Dictionary offset = " << offset_ + i << "; Passing others";
|
|
|
|
- break;
|
|
|
|
- } else
|
|
|
|
|
|
+ //if (subdir->subfiles_.empty() && subdir->subdirs_.empty()) {
|
|
|
|
+ // LOG(WARNING) << "Sub-subdirectory is empty or made empty... Dictionary offset = " << offset_ + i << "; Passing others";
|
|
|
|
+ // break;
|
|
|
|
+ //} else {
|
|
subdirs_.push_back(subdir);
|
|
subdirs_.push_back(subdir);
|
|
|
|
+ subdir_init_queue_.insert(subdir);
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
bool SubDirectory::MakeSubFiles() {
|
|
bool SubDirectory::MakeSubFiles() {
|
|
BinaryData data = BinaryData(4);
|
|
BinaryData data = BinaryData(4);
|
|
- dat_->ReadData(data, 4, offset_ + 63 * 8);
|
|
|
|
|
|
+ dat_.ReadData(data, 4, offset_ + 63 * 8);
|
|
|
|
|
|
if (data.Empty()) {
|
|
if (data.Empty()) {
|
|
LOG(ERROR) << "(READ ERROR) Incorrect directory at offset " << offset_;
|
|
LOG(ERROR) << "(READ ERROR) Incorrect directory at offset " << offset_;
|
|
@@ -98,9 +86,12 @@ namespace LOTRO_DAT {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ subfiles_.resize(unsigned(subfiles_number), nullptr);
|
|
|
|
+ BinaryData headers(32 * unsigned(subfiles_number));
|
|
|
|
+ dat_.ReadData(headers, 32 * subfiles_number, offset_ + 63 * 8 + 4);
|
|
|
|
+
|
|
for (int i = 0; i < subfiles_number; i++) {
|
|
for (int i = 0; i < subfiles_number; i++) {
|
|
- BinaryData header(32);
|
|
|
|
- dat_->ReadData(header, 32, offset_ + 63 * 8 + 4 + 32 * i);
|
|
|
|
|
|
+ BinaryData header = headers.CutData(32 * i, 32 * (i + 1));
|
|
|
|
|
|
if (header.Empty()) {
|
|
if (header.Empty()) {
|
|
LOG(ERROR) << "(READ ERROR) Incorrect directory (unable to read subfile data) at offset " << offset_;
|
|
LOG(ERROR) << "(READ ERROR) Incorrect directory (unable to read subfile data) at offset " << offset_;
|
|
@@ -110,7 +101,12 @@ namespace LOTRO_DAT {
|
|
if (header.ToNumber<4>(20) == 0 || header.ToNumber<4>(28) != 0)
|
|
if (header.ToNumber<4>(20) == 0 || header.ToNumber<4>(28) != 0)
|
|
continue;
|
|
continue;
|
|
|
|
|
|
- Subfile *subfile = MakeSubfile(
|
|
|
|
|
|
+ if (visited_subfiles_.count(header.ToNumber<4>(4))) {
|
|
|
|
+ LOG(ERROR) << "Found duplicate file with id " << header.ToNumber<4>(4);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ subfiles_[i] = MakeSubfile(
|
|
offset_ + 63 * 8 + 4 + 32 * i,
|
|
offset_ + 63 * 8 + 4 + 32 * i,
|
|
header.ToNumber<4>(0), // unknown1
|
|
header.ToNumber<4>(0), // unknown1
|
|
header.ToNumber<4>(4), // file_id
|
|
header.ToNumber<4>(4), // file_id
|
|
@@ -122,32 +118,35 @@ namespace LOTRO_DAT {
|
|
header.ToNumber<4>(28) // unknown2 - must be zero??
|
|
header.ToNumber<4>(28) // unknown2 - must be zero??
|
|
);
|
|
);
|
|
|
|
|
|
-// if (dat_->CorrectSubfile(subfile)) {
|
|
|
|
- subfiles_.emplace_back(subfile);
|
|
|
|
-// } else {
|
|
|
|
-// LOG(WARNING) << "Incorrect Subfile in directory at offset " << offset_ + 63 * 8 + 4 + 32 * i << " (id = " << subfile->file_id() << ");";
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
|
|
+ if (dat_.CorrectSubfile(subfiles_[i])) {
|
|
|
|
+ visited_subfiles_.insert(subfiles_[i]->file_id());
|
|
|
|
+ } else {
|
|
|
|
+ LOG(WARNING) << "Incorrect Subfile in directory at offset " << offset_ + 63 * 8 + 4 + 32 * i << " (id = " << subfiles_[i]->file_id() << ");";
|
|
|
|
+ delete subfiles_[i];
|
|
|
|
+ subfiles_[i] = nullptr;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- void SubDirectory::MakeDictionary(std::map<long long, Subfile *> &dict) {
|
|
|
|
- for (Subfile *i : subfiles_) {
|
|
|
|
- if (dict.count(i->file_id() != 0)) {
|
|
|
|
- LOG(WARNING) << "Found multiple instances of file " << i->file_id() << " at dictionary offset "
|
|
|
|
- << i->dictionary_offset() << ". Base offset = " << dict[i->file_id()]->dictionary_offset();
|
|
|
|
- if (!dat_->CorrectSubfile(i) || dat_->CorrectSubfile(dict[i->file_id_]))
|
|
|
|
|
|
+ void SubDirectory::MakeDictionary(std::map<long long, std::shared_ptr<Subfile> > &dict) {
|
|
|
|
+ for (const std::shared_ptr<Subfile> &file: subfiles_) {
|
|
|
|
+ if (dict.count(file->file_id() != 0)) {
|
|
|
|
+ LOG(WARNING) << "Found multiple instances of file " << file->file_id() << " at dictionary offset "
|
|
|
|
+ << file->dictionary_offset() << ". Base offset = " << dict[file->file_id()]->dictionary_offset();
|
|
|
|
+ if (!dat_.CorrectSubfile(file) || dat_.CorrectSubfile(dict[file->file_id_]))
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- dict[i->file_id()] = i;
|
|
|
|
|
|
+ dict[file->file_id()] = file;
|
|
}
|
|
}
|
|
|
|
|
|
- for (SubDirectory *i : subdirs_)
|
|
|
|
- i->MakeDictionary(dict);
|
|
|
|
|
|
+ for (const auto &dir : subdirs_) {
|
|
|
|
+ dir->MakeDictionary(dict);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- Subfile *SubDirectory::MakeSubfile(long long dictionary_offset, long long unknown1, long long file_id,
|
|
|
|
|
|
+ std::shared_ptr<Subfile> SubDirectory::MakeSubfile(long long dictionary_offset, long long unknown1, long long file_id,
|
|
long long file_offset, long long file_size, long long timestamp,
|
|
long long file_offset, long long file_size, long long timestamp,
|
|
long long version, long long block_size, long long unknown2) {
|
|
long long version, long long block_size, long long unknown2) {
|
|
|
|
|
|
@@ -155,22 +154,22 @@ namespace LOTRO_DAT {
|
|
|
|
|
|
switch (type) {
|
|
switch (type) {
|
|
case TEXT:
|
|
case TEXT:
|
|
- return dynamic_cast<Subfile *>(new TextSubfile(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
|
|
|
|
+ return std::dynamic_pointer_cast<Subfile>(std::make_shared<TextSubfile>(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
case JPG:
|
|
case JPG:
|
|
- return dynamic_cast<Subfile *>(new JpgSubfile(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
|
|
|
|
+ return std::dynamic_pointer_cast<Subfile>(std::make_shared<JpgSubfile>(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
case DDS:
|
|
case DDS:
|
|
- return dynamic_cast<Subfile *>(new DdsSubfile(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
|
|
|
|
+ return std::dynamic_pointer_cast<Subfile>(std::make_shared<DdsSubfile>(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
case WAV:
|
|
case WAV:
|
|
- return dynamic_cast<Subfile *>(new WavSubfile(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
|
|
|
|
+ return std::dynamic_pointer_cast<Subfile>(std::make_shared<WavSubfile>(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
case OGG:
|
|
case OGG:
|
|
- return dynamic_cast<Subfile *>(new OggSubfile(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
|
|
|
|
+ return std::dynamic_pointer_cast<Subfile>(std::make_shared<OggSubfile>(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
case FONT:
|
|
case FONT:
|
|
- return dynamic_cast<Subfile *>(new FontSubfile(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
|
|
|
|
+ return std::dynamic_pointer_cast<Subfile>(std::make_shared<FontSubfile>(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
case UNKNOWN:
|
|
case UNKNOWN:
|
|
- return dynamic_cast<Subfile *>(new UnknownSubfile(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
|
|
|
|
+ return std::dynamic_pointer_cast<Subfile>(std::make_shared<UnknownSubfile>(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
}
|
|
}
|
|
LOG(ERROR) << "Incorrect file type..";
|
|
LOG(ERROR) << "Incorrect file type..";
|
|
- return dynamic_cast<Subfile *>(new UnknownSubfile(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
|
|
|
|
+ return std::dynamic_pointer_cast<Subfile>(std::make_shared<UnknownSubfile>(dat_, dictionary_offset, unknown1, file_id, file_offset, file_size, timestamp, version, block_size, unknown2));
|
|
}
|
|
}
|
|
|
|
|
|
FILE_TYPE SubDirectory::GetSubfileType(long long file_id, long long file_offset) const {
|
|
FILE_TYPE SubDirectory::GetSubfileType(long long file_id, long long file_offset) const {
|
|
@@ -183,7 +182,7 @@ namespace LOTRO_DAT {
|
|
return FONT;
|
|
return FONT;
|
|
|
|
|
|
BinaryData header(64);
|
|
BinaryData header(64);
|
|
- dat_->ReadData(header, 64, (unsigned) file_offset + 8);
|
|
|
|
|
|
+ dat_.ReadData(header, 64, (unsigned) file_offset + 8);
|
|
|
|
|
|
if (header.Empty()) {
|
|
if (header.Empty()) {
|
|
LOG(ERROR) << "Unable to read file header. file_id = " << file_id << ", offset = " << offset_;
|
|
LOG(ERROR) << "Unable to read file header. file_id = " << file_id << ", offset = " << offset_;
|