diff --git a/DataSpec/DNACommon/PAK.hpp b/DataSpec/DNACommon/PAK.hpp index 943f1eaf0..e603e2c4e 100644 --- a/DataSpec/DNACommon/PAK.hpp +++ b/DataSpec/DNACommon/PAK.hpp @@ -59,35 +59,132 @@ struct UniqueResult UNIQUE_LEVEL, UNIQUE_AREA, UNIQUE_LAYER - } type = UNIQUE_NOTFOUND; - const HECL::SystemString* levelName = nullptr; - const HECL::SystemString* areaName = nullptr; - const HECL::SystemString* layerName = nullptr; + } m_type = UNIQUE_NOTFOUND; + const HECL::SystemString* m_levelName = nullptr; + const HECL::SystemString* m_areaName = nullptr; + const HECL::SystemString* m_layerName = nullptr; UniqueResult() = default; - UniqueResult(Type tp) : type(tp) {} + UniqueResult(Type tp) : m_type(tp) {} + + template + void checkEntry(const PAKBRIDGE& pakBridge, const typename PAKBRIDGE::PAKType::Entry& entry) + { + UniqueResult::Type resultType = UniqueResult::UNIQUE_NOTFOUND; + bool foundOneLayer = false; + const HECL::SystemString* levelName = nullptr; + typename PAKBRIDGE::PAKType::IDType levelId; + typename PAKBRIDGE::PAKType::IDType areaId; + unsigned layerIdx; + for (const auto& lpair : pakBridge.m_levelDeps) + { + if (entry.id == lpair.first) + { + levelName = &lpair.second.name; + resultType = UniqueResult::UNIQUE_LEVEL; + break; + } + + for (const auto& pair : lpair.second.areas) + { + unsigned l=0; + for (const auto& layer : pair.second.layers) + { + if (layer.resources.find(entry.id) != layer.resources.end()) + { + if (foundOneLayer) + { + if (areaId == pair.first) + { + resultType = UniqueResult::UNIQUE_AREA; + } + else if (levelId == lpair.first) + { + resultType = UniqueResult::UNIQUE_LEVEL; + break; + } + else + { + m_type = UniqueResult::UNIQUE_PAK; + return; + } + continue; + } + else + resultType = UniqueResult::UNIQUE_LAYER; + levelName = &lpair.second.name; + levelId = lpair.first; + areaId = pair.first; + layerIdx = l; + foundOneLayer = true; + } + ++l; + } + if (pair.second.resources.find(entry.id) != pair.second.resources.end()) + { + if (foundOneLayer) + { + if (areaId == pair.first) + { + resultType = UniqueResult::UNIQUE_AREA; + } + else if (levelId == lpair.first) + { + resultType = UniqueResult::UNIQUE_LEVEL; + break; + } + else + { + m_type = UniqueResult::UNIQUE_PAK; + return; + } + continue; + } + else + resultType = UniqueResult::UNIQUE_AREA; + levelName = &lpair.second.name; + levelId = lpair.first; + areaId = pair.first; + foundOneLayer = true; + } + } + } + m_type = resultType; + m_levelName = levelName; + if (resultType == UniqueResult::UNIQUE_LAYER || resultType == UniqueResult::UNIQUE_AREA) + { + const typename PAKBRIDGE::Level::Area& area = pakBridge.m_levelDeps.at(levelId).areas.at(areaId); + m_areaName = &area.name; + if (resultType == UniqueResult::UNIQUE_LAYER) + { + const typename PAKBRIDGE::Level::Area::Layer& layer = area.layers[layerIdx]; + m_layerName = &layer.name; + } + } + } + HECL::ProjectPath uniquePath(const HECL::ProjectPath& pakPath) const { - if (type == UNIQUE_PAK) + if (m_type == UNIQUE_PAK) return pakPath; HECL::ProjectPath levelDir; - if (levelName) - levelDir.assign(pakPath, *levelName); + if (m_levelName) + levelDir.assign(pakPath, *m_levelName); else levelDir = pakPath; levelDir.makeDir(); - if (type == UNIQUE_AREA) + if (m_type == UNIQUE_AREA) { - HECL::ProjectPath areaDir(levelDir, *areaName); + HECL::ProjectPath areaDir(levelDir, *m_areaName); areaDir.makeDir(); return areaDir; } - else if (type == UNIQUE_LAYER) + else if (m_type == UNIQUE_LAYER) { - HECL::ProjectPath areaDir(levelDir, *areaName); + HECL::ProjectPath areaDir(levelDir, *m_areaName); areaDir.makeDir(); - HECL::ProjectPath layerDir(areaDir, *layerName); + HECL::ProjectPath layerDir(areaDir, *m_layerName); layerDir.makeDir(); return layerDir; } diff --git a/DataSpec/DNAMP1/DNAMP1.cpp b/DataSpec/DNAMP1/DNAMP1.cpp index 215c06abb..02a013067 100644 --- a/DataSpec/DNAMP1/DNAMP1.cpp +++ b/DataSpec/DNAMP1/DNAMP1.cpp @@ -52,98 +52,6 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar } } -UniqueResult PAKBridge::uniqueCheck(const PAK::Entry& entry) -{ - UniqueResult::Type result = UniqueResult::UNIQUE_NOTFOUND; - bool foundOneLayer = false; - const HECL::SystemString* levelName = nullptr; - UniqueID32 levelId; - UniqueID32 areaId; - unsigned layerIdx; - for (const auto& lpair : m_levelDeps) - { - levelName = &lpair.second.name; - if (entry.id == lpair.first) - { - result = UniqueResult::UNIQUE_LEVEL; - break; - } - - for (const auto& pair : lpair.second.areas) - { - unsigned l=0; - for (const auto& layer : pair.second.layers) - { - if (layer.resources.find(entry.id) != layer.resources.end()) - { - if (foundOneLayer) - { - if (areaId == pair.first) - { - result = UniqueResult::UNIQUE_AREA; - } - else if (levelId == lpair.first) - { - result = UniqueResult::UNIQUE_LEVEL; - break; - } - else - { - return {UniqueResult::UNIQUE_PAK}; - } - continue; - } - else - result = UniqueResult::UNIQUE_LAYER; - levelId = lpair.first; - areaId = pair.first; - layerIdx = l; - foundOneLayer = true; - } - ++l; - } - if (pair.second.resources.find(entry.id) != pair.second.resources.end()) - { - if (foundOneLayer) - { - if (areaId == pair.first) - { - result = UniqueResult::UNIQUE_AREA; - } - else if (levelId == lpair.first) - { - result = UniqueResult::UNIQUE_LEVEL; - break; - } - else - { - return {UniqueResult::UNIQUE_PAK}; - } - continue; - } - else - result = UniqueResult::UNIQUE_AREA; - levelId = lpair.first; - areaId = pair.first; - foundOneLayer = true; - } - } - } - UniqueResult retval = {result}; - retval.levelName = levelName; - if (result == UniqueResult::UNIQUE_LAYER || result == UniqueResult::UNIQUE_AREA) - { - const PAKBridge::Level::Area& area = m_levelDeps[levelId].areas[areaId]; - retval.areaName = &area.name; - if (result == UniqueResult::UNIQUE_LAYER) - { - const PAKBridge::Level::Area::Layer& layer = area.layers[layerIdx]; - retval.layerName = &layer.name; - } - } - return retval; -} - static HECL::SystemString LayerName(const std::string& name) { #if HECL_UCS2 @@ -265,7 +173,7 @@ void PAKBridge::build() /* Second pass: cross-compare uniqueness */ for (PAK::Entry& entry : m_pak.m_entries) { - entry.unique = uniqueCheck(entry); + entry.unique.checkEntry(*this, entry); } } diff --git a/DataSpec/DNAMP1/DNAMP1.hpp b/DataSpec/DNAMP1/DNAMP1.hpp index b87f78f7c..7f698f97a 100644 --- a/DataSpec/DNAMP1/DNAMP1.hpp +++ b/DataSpec/DNAMP1/DNAMP1.hpp @@ -17,7 +17,6 @@ class PAKBridge HECL::Database::Project& m_project; const NOD::DiscBase::IPartition::Node& m_node; PAK m_pak; - UniqueResult uniqueCheck(const PAK::Entry& entry); public: struct Level { diff --git a/DataSpec/DNAMP2/DNAMP2.cpp b/DataSpec/DNAMP2/DNAMP2.cpp index bf924b210..94682a3e6 100644 --- a/DataSpec/DNAMP2/DNAMP2.cpp +++ b/DataSpec/DNAMP2/DNAMP2.cpp @@ -50,98 +50,6 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar } } -UniqueResult PAKBridge::uniqueCheck(const DNAMP1::PAK::Entry& entry) -{ - UniqueResult::Type result = UniqueResult::UNIQUE_NOTFOUND; - bool foundOneLayer = false; - const HECL::SystemString* levelName = nullptr; - UniqueID32 levelId; - UniqueID32 areaId; - unsigned layerIdx; - for (const auto& lpair : m_levelDeps) - { - levelName = &lpair.second.name; - if (entry.id == lpair.first) - { - result = UniqueResult::UNIQUE_LEVEL; - break; - } - - for (const auto& pair : lpair.second.areas) - { - unsigned l=0; - for (const auto& layer : pair.second.layers) - { - if (layer.resources.find(entry.id) != layer.resources.end()) - { - if (foundOneLayer) - { - if (areaId == pair.first) - { - result = UniqueResult::UNIQUE_AREA; - } - else if (levelId == lpair.first) - { - result = UniqueResult::UNIQUE_LEVEL; - break; - } - else - { - return {UniqueResult::UNIQUE_PAK}; - } - continue; - } - else - result = UniqueResult::UNIQUE_LAYER; - levelId = lpair.first; - areaId = pair.first; - layerIdx = l; - foundOneLayer = true; - } - ++l; - } - if (pair.second.resources.find(entry.id) != pair.second.resources.end()) - { - if (foundOneLayer) - { - if (areaId == pair.first) - { - result = UniqueResult::UNIQUE_AREA; - } - else if (levelId == lpair.first) - { - result = UniqueResult::UNIQUE_LEVEL; - break; - } - else - { - return {UniqueResult::UNIQUE_PAK}; - } - continue; - } - else - result = UniqueResult::UNIQUE_AREA; - levelId = lpair.first; - areaId = pair.first; - foundOneLayer = true; - } - } - } - UniqueResult retval = {result}; - retval.levelName = levelName; - if (result == UniqueResult::UNIQUE_LAYER || result == UniqueResult::UNIQUE_AREA) - { - const PAKBridge::Level::Area& area = m_levelDeps[levelId].areas[areaId]; - retval.areaName = &area.name; - if (result == UniqueResult::UNIQUE_LAYER) - { - const PAKBridge::Level::Area::Layer& layer = area.layers[layerIdx]; - retval.layerName = &layer.name; - } - } - return retval; -} - static HECL::SystemString LayerName(const std::string& name) { #if HECL_UCS2 @@ -271,7 +179,7 @@ void PAKBridge::build() /* Second pass: cross-compare uniqueness */ for (DNAMP1::PAK::Entry& entry : m_pak.m_entries) { - entry.unique = uniqueCheck(entry); + entry.unique.checkEntry(*this, entry); } } diff --git a/DataSpec/DNAMP2/DNAMP2.hpp b/DataSpec/DNAMP2/DNAMP2.hpp index 8b7cab86c..cb5357db8 100644 --- a/DataSpec/DNAMP2/DNAMP2.hpp +++ b/DataSpec/DNAMP2/DNAMP2.hpp @@ -17,7 +17,6 @@ class PAKBridge HECL::Database::Project& m_project; const NOD::DiscBase::IPartition::Node& m_node; DNAMP1::PAK m_pak; - UniqueResult uniqueCheck(const DNAMP1::PAK::Entry& entry); public: struct Level { diff --git a/DataSpec/DNAMP3/DNAMP3.cpp b/DataSpec/DNAMP3/DNAMP3.cpp index 6d1545265..3cd8fa7ee 100644 --- a/DataSpec/DNAMP3/DNAMP3.cpp +++ b/DataSpec/DNAMP3/DNAMP3.cpp @@ -59,98 +59,6 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar } } -UniqueResult PAKBridge::uniqueCheck(const PAK::Entry& entry) -{ - UniqueResult::Type result = UniqueResult::UNIQUE_NOTFOUND; - bool foundOneLayer = false; - const HECL::SystemString* levelName = nullptr; - UniqueID64 levelId; - UniqueID64 areaId; - unsigned layerIdx; - for (const auto& lpair : m_levelDeps) - { - levelName = &lpair.second.name; - if (entry.id == lpair.first) - { - result = UniqueResult::UNIQUE_LEVEL; - break; - } - - for (const auto& pair : lpair.second.areas) - { - unsigned l=0; - for (const auto& layer : pair.second.layers) - { - if (layer.resources.find(entry.id) != layer.resources.end()) - { - if (foundOneLayer) - { - if (areaId == pair.first) - { - result = UniqueResult::UNIQUE_AREA; - } - else if (levelId == lpair.first) - { - result = UniqueResult::UNIQUE_LEVEL; - break; - } - else - { - return {UniqueResult::UNIQUE_PAK}; - } - continue; - } - else - result = UniqueResult::UNIQUE_LAYER; - levelId = lpair.first; - areaId = pair.first; - layerIdx = l; - foundOneLayer = true; - } - ++l; - } - if (pair.second.resources.find(entry.id) != pair.second.resources.end()) - { - if (foundOneLayer) - { - if (areaId == pair.first) - { - result = UniqueResult::UNIQUE_AREA; - } - else if (levelId == lpair.first) - { - result = UniqueResult::UNIQUE_LEVEL; - break; - } - else - { - return {UniqueResult::UNIQUE_PAK}; - } - continue; - } - else - result = UniqueResult::UNIQUE_AREA; - levelId = lpair.first; - areaId = pair.first; - foundOneLayer = true; - } - } - } - UniqueResult retval = {result}; - retval.levelName = levelName; - if (result == UniqueResult::UNIQUE_LAYER || result == UniqueResult::UNIQUE_AREA) - { - const PAKBridge::Level::Area& area = m_levelDeps[levelId].areas[areaId]; - retval.areaName = &area.name; - if (result == UniqueResult::UNIQUE_LAYER) - { - const PAKBridge::Level::Area::Layer& layer = area.layers[layerIdx]; - retval.layerName = &layer.name; - } - } - return retval; -} - static HECL::SystemString LayerName(const std::string& name) { #if HECL_UCS2 @@ -285,7 +193,7 @@ void PAKBridge::build() /* Second pass: cross-compare uniqueness */ for (PAK::Entry& entry : m_pak.m_entries) { - entry.unique = uniqueCheck(entry); + entry.unique.checkEntry(*this, entry); } } diff --git a/DataSpec/DNAMP3/DNAMP3.hpp b/DataSpec/DNAMP3/DNAMP3.hpp index 06d84448c..34a43769b 100644 --- a/DataSpec/DNAMP3/DNAMP3.hpp +++ b/DataSpec/DNAMP3/DNAMP3.hpp @@ -17,7 +17,6 @@ class PAKBridge HECL::Database::Project& m_project; const NOD::DiscBase::IPartition::Node& m_node; PAK m_pak; - UniqueResult uniqueCheck(const PAK::Entry& entry); public: struct Level { diff --git a/DataSpec/DNAMP3/MREA.cpp b/DataSpec/DNAMP3/MREA.cpp index 10b2b503e..8919435f7 100644 --- a/DataSpec/DNAMP3/MREA.cpp +++ b/DataSpec/DNAMP3/MREA.cpp @@ -332,7 +332,6 @@ bool MREA::ExtractLayerDeps(PAKEntryReadStream& rs, PAKBridge::Level::Area& area DEPS deps; deps.read(drs); - printf("%d\n", deps.depLayerCount); unsigned r=0; for (unsigned l=1 ; l