|
@@ -20,7 +20,7 @@ LOTRO_DAT::Subfile::Subfile() {
|
|
|
|
|
|
LOTRO_DAT::Subfile::Subfile(DatFile *dat, long long unknown0, long long unknown1, long long file_id, long long file_offset, long long size1,
|
|
|
long long timestamp, long long version, long long size2) :
|
|
|
- dat_(dat), unknown0_(unknown0), unknown1_(unknown1), file_id_(file_id), file_offset_(file_offset + 8),
|
|
|
+ dat_(dat), unknown0_(unknown0), unknown1_(unknown1), file_id_(file_id), file_offset_(file_offset),
|
|
|
size1_(size1), timestamp_(timestamp), version_(version), size2_(size2) {
|
|
|
|
|
|
if (size1_ > MAXSIZE)
|
|
@@ -75,7 +75,7 @@ LOTRO_DAT::EXTENSION LOTRO_DAT::Subfile::GetExtension() const {
|
|
|
|
|
|
BinaryData header(64);
|
|
|
try {
|
|
|
- dat_->ReadData(header, 64, (unsigned) file_offset_);
|
|
|
+ dat_->ReadData(header, 64, (unsigned) file_offset_ + 8);
|
|
|
} catch (DatException &e) {
|
|
|
if (e.type() == READ_EXCEPTION) {
|
|
|
std::string err =
|
|
@@ -136,7 +136,8 @@ std::string LOTRO_DAT::Subfile::ExtensionToString(LOTRO_DAT::EXTENSION ext) cons
|
|
|
|
|
|
bool LOTRO_DAT::Subfile::ExportFile(const char *filename, Database *db) const {
|
|
|
try {
|
|
|
- BinaryData data;
|
|
|
+ BinaryData data;
|
|
|
+
|
|
|
switch (ext_)
|
|
|
{
|
|
|
case LOTRO_DAT::TXT:
|
|
@@ -158,7 +159,8 @@ bool LOTRO_DAT::Subfile::ExportFile(const char *filename, Database *db) const {
|
|
|
}
|
|
|
|
|
|
if (db == nullptr) {
|
|
|
- return data.WriteToFile(std::string(filename) + std::string(ExtensionToString(ext_)));
|
|
|
+ std::string s = std::string(filename) + std::string(ExtensionToString(ext_));
|
|
|
+ return data.WriteToFile(s);
|
|
|
} else {
|
|
|
db->PushBinaryFile(file_id_, data);
|
|
|
return true;
|
|
@@ -175,15 +177,31 @@ bool LOTRO_DAT::Subfile::ExportFileAsTXT(const char *filename, Database *db) con
|
|
|
throw DatException("ExportAsTXT function is not implemented yet", EXPORT_EXCEPTION);
|
|
|
}
|
|
|
|
|
|
+LOTRO_DAT::BinaryData LOTRO_DAT::Subfile::GetFileData() const {
|
|
|
+ BinaryData data((unsigned)size1());
|
|
|
+ if (size2() >= size1() + 8) {
|
|
|
+ dat_->ReadData(data, size1(), file_offset() + 8);
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ long long first_block_size = size2() - 8 - 4;
|
|
|
+
|
|
|
+ dat_->ReadData(data, first_block_size, file_offset() + 8);
|
|
|
+
|
|
|
+ BinaryData newFragmentOffset(4);
|
|
|
+ dat_->ReadData(newFragmentOffset, 4, file_offset() + size2() - 4);
|
|
|
+ long long part_offset = newFragmentOffset.ToNumber<4>(0);
|
|
|
+
|
|
|
+ dat_->ReadData(data, size1() - first_block_size, part_offset, first_block_size);
|
|
|
+ return data;
|
|
|
+}
|
|
|
+
|
|
|
const LOTRO_DAT::BinaryData LOTRO_DAT::Subfile::PrepareAsJPG() const {
|
|
|
- BinaryData data((unsigned) size1_ - 24);
|
|
|
- dat_->ReadData(data, (unsigned) size1_ - 24, (unsigned) file_offset_ + 24);
|
|
|
- return data;
|
|
|
+ return GetFileData().CutData(24);
|
|
|
}
|
|
|
|
|
|
const LOTRO_DAT::BinaryData LOTRO_DAT::Subfile::PrepareAsDDS() const {
|
|
|
- BinaryData data((unsigned) size1_);
|
|
|
- dat_->ReadData(data, (unsigned) size1_, file_offset_);
|
|
|
+ BinaryData data = GetFileData();
|
|
|
if (compressed_)
|
|
|
data.DecompressData(4);
|
|
|
|
|
@@ -291,9 +309,7 @@ const LOTRO_DAT::BinaryData LOTRO_DAT::Subfile::PrepareAsDDS() const {
|
|
|
}
|
|
|
|
|
|
const LOTRO_DAT::BinaryData LOTRO_DAT::Subfile::PrepareAsOGG() const {
|
|
|
- BinaryData data((unsigned) size1_ - 8);
|
|
|
- dat_->ReadData(data, (unsigned) size1_ - 8, (unsigned) file_offset_ + 8);
|
|
|
- return data;
|
|
|
+ return GetFileData().CutData(8);
|
|
|
}
|
|
|
|
|
|
const LOTRO_DAT::BinaryData LOTRO_DAT::Subfile::PrepareAsFont() const {
|
|
@@ -301,9 +317,7 @@ const LOTRO_DAT::BinaryData LOTRO_DAT::Subfile::PrepareAsFont() const {
|
|
|
}
|
|
|
|
|
|
const LOTRO_DAT::BinaryData LOTRO_DAT::Subfile::PrepareAsWAV() const {
|
|
|
- BinaryData data((unsigned) size1_ - 8);
|
|
|
- dat_->ReadData(data, (unsigned) size1_ - 8, (unsigned) file_offset_ + 8);
|
|
|
- return data;
|
|
|
+ return GetFileData().CutData(8);
|
|
|
}
|
|
|
|
|
|
const LOTRO_DAT::BinaryData LOTRO_DAT::Subfile::PrepareAsUnk() const {
|