Skip to content

Commit

Permalink
Fix common and palette values
Browse files Browse the repository at this point in the history
  • Loading branch information
Deamon87 committed Feb 12, 2024
1 parent 8c06020 commit 1f463eb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion fileReaders/WDC2/DB2Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void DB2Base::process(HFileContent db2File, const std::string &fileName) {
bytesRead = 0;

readValue(header);
if (header->magic != 'WDC2') return;
if (header->magic != '2CDW') return;

readValues(section_headers, header->section_count);
readValues(fields, header->total_field_count);
Expand Down
13 changes: 8 additions & 5 deletions fileReaders/WDC3/DB2Ver3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,14 @@ DB2Ver3::WDC3Record::WDC3Record(std::shared_ptr<DB2Ver3 const> db2Class, int rec
db2Class(db2Class), recordId(recordId), recordIndex(recordIndex),
recordPointer(recordPointer), sectionIndex(sectionIndex)
{
if (!db2Class->getWDCHeader()->flags.hasNonInlineId) {
auto result = getField(db2Class->getWDCHeader()->id_index, 0, 0);
this->recordId = result[0].v32s;
}

}

static inline void fixPaletteValue(WDC3::DB2Ver3::WDCFieldValue &value, int externalElemSizeBytes) {
static inline void fixPaletteOrCommonValue(WDC3::DB2Ver3::WDCFieldValue &value, int externalElemSizeBytes) {
if (externalElemSizeBytes > 0 && externalElemSizeBytes < 4) {
uint32_t mask = (1 << (externalElemSizeBytes*8)) - 1;
value.v32 = value.v32 & mask;
Expand Down Expand Up @@ -462,6 +466,7 @@ std::vector<WDC3::DB2Ver3::WDCFieldValue> DB2Ver3::WDC3Record::getField(int fiel
auto it = db2Class->commonDataHashMap[fieldIndex].find(recordId);
if (it != db2Class->commonDataHashMap[fieldIndex].end()) {
fieldValue.v32 = it->second;
fixPaletteOrCommonValue(fieldValue, externalElemSizeBytes);
}
}
break;
Expand All @@ -487,19 +492,17 @@ std::vector<WDC3::DB2Ver3::WDCFieldValue> DB2Ver3::WDC3Record::getField(int fiel

auto &fieldValue = result.emplace_back();
fieldValue.v32 = db2Class->palleteDataArray[fieldIndex][properPalleteIndex];;
fixPaletteValue(fieldValue, externalElemSizeBytes);
fixPaletteOrCommonValue(fieldValue, externalElemSizeBytes);
}
} else {
int properPalleteIndex = palleteIndex;
assert(properPalleteIndex < db2Class->palleteDataArray[fieldIndex].size());

auto &fieldValue = result.emplace_back();
fieldValue.v32 = db2Class->palleteDataArray[fieldIndex][properPalleteIndex];
fixPaletteValue(fieldValue, externalElemSizeBytes);
fixPaletteOrCommonValue(fieldValue, externalElemSizeBytes);
}



break;
}
}
Expand Down
8 changes: 7 additions & 1 deletion fileReaders/WDC3/DB2Ver3.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,16 @@ namespace WDC3 {

const field_storage_info * const getFieldInfo(uint32_t fieldIndex) const;

const auto* const getWDCHeader() {
const auto* const getWDCHeader() const {
return this->headerContent;
}

bool isFieldId(int fieldIndex) const {
return (this->getWDCHeader()->id_index == fieldIndex) && !this->getWDCHeader()->flags.hasNonInlineId;
}



union WDCFieldValue {
uint64_t v64;
int64_t v64s;
Expand Down
7 changes: 5 additions & 2 deletions importers/CImporterClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../fileReaders/WDC3/DB2Ver3.h"
#include "WDC3/WDC3Importer.h"
#include "../fileReaders/WDC4/DB2Ver4.h"
#include "../fileReaders/WDC5/DB2Ver5.h"

#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -39,13 +40,15 @@ void CImporterClass::addTable(std::string &tableName,
}

const uint32_t fileIdent = *(uint32_t *)vec->data();
if (fileIdent == 'WDC2') {
if (fileIdent == '2CDW') {
WDC2::DB2Base db2Base;
db2Base.process(vec, db2File);
} else if (fileIdent == '3CDW' || fileIdent == '4CDW' || fileIdent == '5CDW') {
std::shared_ptr<WDC3::DB2Ver3> db2Base = nullptr;

if (*(uint32_t *)vec->data() == '4CDW') {
if (*(uint32_t *)vec->data() == '5CDW') {
db2Base = std::make_shared<WDC5::DB2Ver5>();
} else if (*(uint32_t *)vec->data() == '4CDW') {
db2Base = std::make_shared<WDC4::DB2Ver4>();
} else {
db2Base = std::make_shared<WDC3::DB2Ver3>();
Expand Down
10 changes: 5 additions & 5 deletions importers/WDC3/WDC3Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ WDC3Importer::generateFieldsFromDB2Columns(std::shared_ptr<WDC3::DB2Ver3> db2Bas
} else {
std::string columnName = "field_" + std::to_string(i);
bool isId = false;
if (i == db2Base->getWDCHeader()->id_index && !db2Base->getWDCHeader()->flags.hasNonInlineId) {
if (db2Base->isFieldId(i)) {
columnName = "id";
isId = true;
}
Expand Down Expand Up @@ -328,15 +328,15 @@ bool WDC3Importer::readWDC3Record(const int recordIndex,
case FieldType::INT: {
if (dbdBuildColumnDef->bitSize == 64) {
if (dbdBuildColumnDef->isSigned) {
fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v64);
} else {
fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v64s);
} else {
fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v64);
}
} else {
if (dbdBuildColumnDef->isSigned) {
fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v32);
} else {
fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v32s);
} else {
fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v32);
}
}
break;
Expand Down

0 comments on commit 1f463eb

Please sign in to comment.