From d2e92903637d232c41695fdb5ec8d66debdd9e15 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 10 Mar 2017 08:00:40 -1000 Subject: [PATCH] Pointer dereference bug fixes --- .gitignore | 6 --- .gitmodules | 18 --------- CMakeLists.txt | 2 + DataSpec/DNACommon/PAK.cpp | 25 ++++++------ DataSpec/DNACommon/PAK.hpp | 4 +- DataSpec/DNAMP1/DNAMP1.cpp | 38 +++++++++--------- DataSpec/DNAMP1/PAK.cpp | 71 +++++++++++++++++++++------------ DataSpec/DNAMP1/PAK.hpp | 40 +++---------------- DataSpec/DNAMP2/DNAMP2.cpp | 42 ++++++++++---------- DataSpec/DNAMP3/DNAMP3.cpp | 30 +++++++------- DataSpec/DNAMP3/PAK.cpp | 76 ++++++++++++++++++++++++------------ DataSpec/DNAMP3/PAK.hpp | 40 +++---------------- Runtime/World/CMorphBall.cpp | 1 + hecl | 2 +- visigen/CMakeLists.txt | 1 + 15 files changed, 187 insertions(+), 209 deletions(-) delete mode 100644 .gitignore delete mode 100644 .gitmodules diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 2907a1935..000000000 --- a/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.directory -version.h -*.user -.DS_Store -*.autosave -docs/* diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index b4001e001..000000000 --- a/.gitmodules +++ /dev/null @@ -1,18 +0,0 @@ -[submodule "hecl"] - path = hecl - url = https://github.com/AxioDL/hecl.git -[submodule "specter"] - path = specter - url = https://github.com/AxioDL/specter.git -[submodule "nod"] - path = nod - url = https://github.com/AxioDL/nod.git -[submodule "amuse"] - path = amuse - url = https://github.com/AxioDL/amuse.git -[submodule "kabufuda"] - path = kabufuda - url = https://github.com/AxioDL/kabufuda.git -[submodule "jbus"] - path = jbus - url = https://github.com/AxioDL/jbus.git diff --git a/CMakeLists.txt b/CMakeLists.txt index de6c8f2d5..0d1af5c36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ if(MSVC) add_definitions(-DUNICODE=1 -D_UNICODE=1 -D__SSE__=1 -D_CRT_SECURE_NO_WARNINGS=1 -DD_SCL_SECURE_NO_WARNINGS=1 /IGNORE:4221 /wd4018 /wd4800 /wd4005 /wd4311 /wd4267 /wd4244 /wd4200 /wd4305 /wd4067 /wd4146 ${VS_DEFINES}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") + # Link-time Code Generation for Release builds set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy /MD") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") diff --git a/DataSpec/DNACommon/PAK.cpp b/DataSpec/DNACommon/PAK.cpp index 20768c9d3..0347a6ccf 100644 --- a/DataSpec/DNACommon/PAK.cpp +++ b/DataSpec/DNACommon/PAK.cpp @@ -165,7 +165,7 @@ void PAKRouter::build(std::vector& bridges, std::functio /* Add to global entry lookup */ const typename BRIDGETYPE::PAKType& pak = bridge.getPAK(); - for (const auto& entry : pak.m_idMap) + for (const auto& entry : pak.m_entries) { if (!pak.m_noShare) { @@ -176,13 +176,13 @@ void PAKRouter::build(std::vector& bridges, std::functio if (uSearch != m_uniqueEntries.end()) { m_uniqueEntries.erase(uSearch); - m_sharedEntries[entry.first] = std::make_pair(bridgeIdx, entry.second); + m_sharedEntries[entry.first] = std::make_pair(bridgeIdx, &entry.second); } else - m_uniqueEntries[entry.first] = std::make_pair(bridgeIdx, entry.second); + m_uniqueEntries[entry.first] = std::make_pair(bridgeIdx, &entry.second); } else - m_uniqueEntries[entry.first] = std::make_pair(bridgeIdx, entry.second); + m_uniqueEntries[entry.first] = std::make_pair(bridgeIdx, &entry.second); } /* Add RigPairs to global map */ @@ -518,24 +518,25 @@ bool PAKRouter::extractResources(const BRIDGETYPE& pakBridge, bool f { enterPAKBridge(pakBridge); size_t count = 0; - size_t sz = m_pak->m_idMap.size(); + size_t sz = m_pak->m_entries.size(); float fsz = sz; for (unsigned w=0 ; countm_firstEntries) { - ResExtractor extractor = BRIDGETYPE::LookupExtractor(*m_pak.get(), *item); + const auto* entryPtr = m_pak->lookupEntry(item); + ResExtractor extractor = BRIDGETYPE::LookupExtractor(*m_pak.get(), *entryPtr); if (extractor.weight != w) continue; - std::string bestName = getBestEntryName(*item, false); + std::string bestName = getBestEntryName(*entryPtr, false); hecl::SystemStringView bestNameView(bestName); float thisFac = ++count / fsz; progress(bestNameView.c_str(), thisFac); const nod::Node* node = m_node.get(); - hecl::ProjectPath working = getWorking(item, extractor); + hecl::ProjectPath working = getWorking(entryPtr, extractor); working.makeDirChain(false); hecl::ResourceLock resLk(working); if (!resLk) @@ -546,7 +547,7 @@ bool PAKRouter::extractResources(const BRIDGETYPE& pakBridge, bool f if (force || cooked.isNone()) { cooked.makeDirChain(false); - PAKEntryReadStream s = item->beginReadStream(*node); + PAKEntryReadStream s = entryPtr->beginReadStream(*node); FILE* fout = hecl::Fopen(cooked.getAbsolutePath().c_str(), _S("wb")); fwrite(s.data(), 1, s.length(), fout); fclose(fout); @@ -556,7 +557,7 @@ bool PAKRouter::extractResources(const BRIDGETYPE& pakBridge, bool f { if (force || !extractor.IsFullyExtracted(working)) { - PAKEntryReadStream s = item->beginReadStream(*node); + PAKEntryReadStream s = entryPtr->beginReadStream(*node); extractor.func_a(s, working); } } @@ -564,8 +565,8 @@ bool PAKRouter::extractResources(const BRIDGETYPE& pakBridge, bool f { if (force || !extractor.IsFullyExtracted(working)) { - PAKEntryReadStream s = item->beginReadStream(*node); - extractor.func_b(m_dataSpec, s, working, *this, *item, force, btok, + PAKEntryReadStream s = entryPtr->beginReadStream(*node); + extractor.func_b(m_dataSpec, s, working, *this, *entryPtr, force, btok, [&progress, thisFac](const hecl::SystemChar* update) { progress(update, thisFac); diff --git a/DataSpec/DNACommon/PAK.hpp b/DataSpec/DNACommon/PAK.hpp index ce1655ab2..02c8f13b0 100644 --- a/DataSpec/DNACommon/PAK.hpp +++ b/DataSpec/DNACommon/PAK.hpp @@ -167,8 +167,8 @@ private: hecl::ProjectPath m_sharedCooked; ThreadLocalPtr m_pak; ThreadLocalPtr m_node; - std::unordered_map> m_uniqueEntries; - std::unordered_map> m_sharedEntries; + std::unordered_map> m_uniqueEntries; + std::unordered_map> m_sharedEntries; std::unordered_map m_overrideEntries; std::unordered_map m_cmdlRigs; std::unordered_map> m_cskrCinfToCharacter; diff --git a/DataSpec/DNAMP1/DNAMP1.cpp b/DataSpec/DNAMP1/DNAMP1.cpp index 1bd0c95e2..38ddfd7d4 100644 --- a/DataSpec/DNAMP1/DNAMP1.cpp +++ b/DataSpec/DNAMP1/DNAMP1.cpp @@ -66,8 +66,9 @@ PAKBridge::PAKBridge(hecl::Database::Project& project, m_pak.read(rs); /* Append Level String */ - for (PAK::Entry& entry : m_pak.m_entries) + for (auto& ent : m_pak.m_entries) { + PAK::Entry& entry = ent.second; if (entry.type == FOURCC('MLVL')) { PAKEntryReadStream rs = entry.beginReadStream(m_node); @@ -100,8 +101,9 @@ static hecl::SystemString LayerName(const std::string& name) void PAKBridge::build() { /* First pass: build per-area/per-layer dependency map */ - for (const PAK::Entry& entry : m_pak.m_entries) + for (const auto& ent : m_pak.m_entries) { + const PAK::Entry& entry = ent.second; if (entry.type == FOURCC('MLVL')) { Level& level = m_levelDeps[entry.id]; @@ -207,9 +209,9 @@ void PAKBridge::build() } /* Second pass: cross-compare uniqueness */ - for (PAK::Entry& entry : m_pak.m_entries) + for (auto& entry : m_pak.m_entries) { - entry.unique.checkEntry(*this, entry); + entry.second.unique.checkEntry(*this, entry.second); } } @@ -217,18 +219,18 @@ void PAKBridge::addCMDLRigPairs(PAKRouter& pakRouter, std::unordered_map>& addTo, std::unordered_map>& cskrCinfToAncs) const { - for (const std::pair& entry : m_pak.m_idMap) + for (const std::pair& entry : m_pak.m_entries) { - if (entry.second->type == FOURCC('ANCS')) + if (entry.second.type == FOURCC('ANCS')) { - PAKEntryReadStream rs = entry.second->beginReadStream(m_node); + PAKEntryReadStream rs = entry.second.beginReadStream(m_node); ANCS ancs; ancs.read(rs); for (const ANCS::CharacterSet::CharacterInfo& ci : ancs.characterSet.characters) { addTo[ci.cmdl] = std::make_pair(ci.cskr, ci.cinf); - cskrCinfToAncs[ci.cskr] = std::make_pair(entry.second->id, hecl::Format("%s.CSKR", ci.name.c_str())); - cskrCinfToAncs[ci.cinf] = std::make_pair(entry.second->id, hecl::Format("CINF_%08X.CINF", ci.cinf.toUint32())); + cskrCinfToAncs[ci.cskr] = std::make_pair(entry.second.id, hecl::Format("%s.CSKR", ci.name.c_str())); + cskrCinfToAncs[ci.cinf] = std::make_pair(entry.second.id, hecl::Format("CINF_%08X.CINF", ci.cinf.toUint32())); PAK::Entry* cmdlEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cmdl); PAK::Entry* cskrEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cskr); PAK::Entry* cinfEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cinf); @@ -238,7 +240,7 @@ void PAKBridge::addCMDLRigPairs(PAKRouter& pakRouter, if (ci.cmdlOverlay && ci.cskrOverlay) { addTo[ci.cmdlOverlay] = std::make_pair(ci.cskrOverlay, ci.cinf); - cskrCinfToAncs[ci.cskrOverlay] = std::make_pair(entry.second->id, hecl::Format("%s.over.CSKR", ci.name.c_str())); + cskrCinfToAncs[ci.cskrOverlay] = std::make_pair(entry.second.id, hecl::Format("%s.over.CSKR", ci.name.c_str())); PAK::Entry* cmdlEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cmdlOverlay); PAK::Entry* cskrEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cskrOverlay); cmdlEnt->name = hecl::Format("ANCS_%08X_%s_overmodel", entry.first.toUint32(), ci.name.c_str()); @@ -251,18 +253,18 @@ void PAKBridge::addCMDLRigPairs(PAKRouter& pakRouter, { PAK::Entry* animEnt = (PAK::Entry*)m_pak.lookupEntry(ae.second.animId); animEnt->name = hecl::Format("ANCS_%08X_%s", entry.first.toUint32(), ae.second.name.c_str()); - cskrCinfToAncs[ae.second.animId] = std::make_pair(entry.second->id, hecl::Format("%s.ANIM", ae.second.name.c_str())); + cskrCinfToAncs[ae.second.animId] = std::make_pair(entry.second.id, hecl::Format("%s.ANIM", ae.second.name.c_str())); if (ae.second.evntId) { PAK::Entry* evntEnt = (PAK::Entry*)m_pak.lookupEntry(ae.second.evntId); evntEnt->name = hecl::Format("ANCS_%08X_%s_evnt", entry.first.toUint32(), ae.second.name.c_str()); - cskrCinfToAncs[ae.second.evntId] = std::make_pair(entry.second->id, hecl::Format("%s.evnt.yaml", ae.second.name.c_str())); + cskrCinfToAncs[ae.second.evntId] = std::make_pair(entry.second.id, hecl::Format("%s.evnt.yaml", ae.second.name.c_str())); } } } - else if (entry.second->type == FOURCC('MREA')) + else if (entry.second.type == FOURCC('MREA')) { - PAKEntryReadStream rs = entry.second->beginReadStream(m_node); + PAKEntryReadStream rs = entry.second.beginReadStream(m_node); MREA::AddCMDLRigPairs(rs, pakRouter, addTo); } } @@ -274,16 +276,16 @@ void PAKBridge::addMAPATransforms(PAKRouter& pakRouter, std::unordered_map& addTo, std::unordered_map& pathOverrides) const { - for (const std::pair& entry : m_pak.m_idMap) + for (const std::pair& entry : m_pak.m_entries) { - if (entry.second->type == FOURCC('MLVL')) + if (entry.second.type == FOURCC('MLVL')) { MLVL mlvl; { - PAKEntryReadStream rs = entry.second->beginReadStream(m_node); + PAKEntryReadStream rs = entry.second.beginReadStream(m_node); mlvl.read(rs); } - hecl::ProjectPath mlvlDirPath = pakRouter.getWorking(entry.second).getParentPath(); + hecl::ProjectPath mlvlDirPath = pakRouter.getWorking(&entry.second).getParentPath(); if (mlvl.worldNameId) pathOverrides[mlvl.worldNameId] = hecl::ProjectPath(mlvlDirPath, _S("!name.yaml")); diff --git a/DataSpec/DNAMP1/PAK.cpp b/DataSpec/DNAMP1/PAK.cpp index 14fdf47df..3e4c6e135 100644 --- a/DataSpec/DNAMP1/PAK.cpp +++ b/DataSpec/DNAMP1/PAK.cpp @@ -29,37 +29,25 @@ void PAK::read(athena::io::IStreamReader& reader) m_entries.reserve(count); m_firstEntries.clear(); m_firstEntries.reserve(count); - m_idMap.clear(); - m_idMap.reserve(count); for (atUint32 e=0 ; e::iterator found = m_idMap.find(entry.id); - if (found != m_idMap.end()) - { - m_nameMap[entry.name] = found->second; - found->second->name = entry.name; - } - } + m_nameMap[entry.name] = entry.id; } void PAK::write(athena::io::IStreamWriter& writer) const @@ -76,9 +64,9 @@ void PAK::write(athena::io::IStreamWriter& writer) const } writer.writeUint32Big(m_entries.size()); - for (const Entry& entry : m_entries) + for (const auto& entry : m_entries) { - Entry tmp = entry; + Entry tmp = entry.second; if (tmp.compressed) tmp.compressed = 1; tmp.write(writer); @@ -156,5 +144,40 @@ PAK::Entry::getBuffer(const nod::Node& pak, atUint64& szOut) const } } +const PAK::Entry* PAK::lookupEntry(const UniqueID32& id) const +{ + auto result = m_entries.find(id); + if (result != m_entries.end()) + return &result->second; + return nullptr; +} + +const PAK::Entry* PAK::lookupEntry(const std::string& name) const +{ + auto result = m_nameMap.find(name); + if (result != m_nameMap.end()) + { + auto result1 = m_entries.find(result->second); + if (result1 != m_entries.end()) + return &result1->second; + } + return nullptr; +} + +std::string PAK::bestEntryName(const Entry& entry, bool& named) const +{ + /* Prefer named entries first */ + for (const NameEntry& nentry : m_nameEntries) + if (nentry.id == entry.id) + { + named = true; + return nentry.name; + } + + /* Otherwise return ID format string */ + named = false; + return entry.type.toString() + '_' + entry.id.toString(); +} + } } diff --git a/DataSpec/DNAMP1/PAK.hpp b/DataSpec/DNAMP1/PAK.hpp index ea54e20cd..998060a7a 100644 --- a/DataSpec/DNAMP1/PAK.hpp +++ b/DataSpec/DNAMP1/PAK.hpp @@ -48,41 +48,13 @@ struct PAK : BigDNA }; std::vector m_nameEntries; - std::vector m_entries; - std::vector m_firstEntries; - std::unordered_map m_idMap; - std::unordered_map m_nameMap; + std::unordered_map m_entries; + std::vector m_firstEntries; + std::unordered_map m_nameMap; - const Entry* lookupEntry(const UniqueID32& id) const - { - std::unordered_map::const_iterator result = m_idMap.find(id); - if (result != m_idMap.end()) - return result->second; - return nullptr; - } - - const Entry* lookupEntry(const std::string& name) const - { - std::unordered_map::const_iterator result = m_nameMap.find(name); - if (result != m_nameMap.end()) - return result->second; - return nullptr; - } - - std::string bestEntryName(const Entry& entry, bool& named) const - { - /* Prefer named entries first */ - for (const NameEntry& nentry : m_nameEntries) - if (nentry.id == entry.id) - { - named = true; - return nentry.name; - } - - /* Otherwise return ID format string */ - named = false; - return entry.type.toString() + '_' + entry.id.toString(); - } + const Entry* lookupEntry(const UniqueID32& id) const; + const Entry* lookupEntry(const std::string& name) const; + std::string bestEntryName(const Entry& entry, bool& named) const; using IDType = UniqueID32; }; diff --git a/DataSpec/DNAMP2/DNAMP2.cpp b/DataSpec/DNAMP2/DNAMP2.cpp index 440882e50..5c30a943a 100644 --- a/DataSpec/DNAMP2/DNAMP2.cpp +++ b/DataSpec/DNAMP2/DNAMP2.cpp @@ -42,11 +42,12 @@ PAKBridge::PAKBridge(hecl::Database::Project& project, m_pak.read(rs); /* Append Level String */ - for (DNAMP1::PAK::Entry& entry : m_pak.m_entries) + for (const auto& entry : m_pak.m_entries) { - if (entry.type == FOURCC('MLVL')) + const DNAMP1::PAK::Entry& e = entry.second; + if (e.type == FOURCC('MLVL')) { - PAKEntryReadStream rs = entry.beginReadStream(m_node); + PAKEntryReadStream rs = e.beginReadStream(m_node); MLVL mlvl; mlvl.read(rs); const DNAMP1::PAK::Entry* nameEnt = m_pak.lookupEntry(mlvl.worldNameId); @@ -75,19 +76,20 @@ static hecl::SystemString LayerName(const std::string& name) void PAKBridge::build() { /* First pass: build per-area/per-layer dependency map */ - for (const DNAMP1::PAK::Entry& entry : m_pak.m_entries) + for (const auto& entry : m_pak.m_entries) { - if (entry.type == FOURCC('MLVL')) + const DNAMP1::PAK::Entry& e = entry.second; + if (e.type == FOURCC('MLVL')) { - Level& level = m_levelDeps[entry.id]; + Level& level = m_levelDeps[e.id]; MLVL mlvl; { - PAKEntryReadStream rs = entry.beginReadStream(m_node); + PAKEntryReadStream rs = e.beginReadStream(m_node); mlvl.read(rs); } bool named; - std::string bestName = m_pak.bestEntryName(entry, named); + std::string bestName = m_pak.bestEntryName(e, named); level.name = hecl::SystemStringView(bestName).sys_str(); level.areas.reserve(mlvl.areaCount); unsigned layerIdx = 0; @@ -163,9 +165,9 @@ void PAKBridge::build() } /* Second pass: cross-compare uniqueness */ - for (DNAMP1::PAK::Entry& entry : m_pak.m_entries) + for (auto& entry : m_pak.m_entries) { - entry.unique.checkEntry(*this, entry); + entry.second.unique.checkEntry(*this, entry.second); } } @@ -173,22 +175,22 @@ void PAKBridge::addCMDLRigPairs(PAKRouter& pakRouter, std::unordered_map>& addTo, std::unordered_map>& cskrCinfToAncs) const { - for (const std::pair& entry : m_pak.m_idMap) + for (const std::pair& entry : m_pak.m_entries) { - if (entry.second->type == FOURCC('ANCS')) + if (entry.second.type == FOURCC('ANCS')) { - PAKEntryReadStream rs = entry.second->beginReadStream(m_node); + PAKEntryReadStream rs = entry.second.beginReadStream(m_node); ANCS ancs; ancs.read(rs); for (const ANCS::CharacterSet::CharacterInfo& ci : ancs.characterSet.characters) { addTo[ci.cmdl] = std::make_pair(ci.cskr, ci.cinf); - cskrCinfToAncs[ci.cskr] = std::make_pair(entry.second->id, hecl::Format("%s.CSKR", ci.name.c_str())); - cskrCinfToAncs[ci.cinf] = std::make_pair(entry.second->id, hecl::Format("CINF_%08X.CINF", ci.cinf.toUint32())); + cskrCinfToAncs[ci.cskr] = std::make_pair(entry.second.id, hecl::Format("%s.CSKR", ci.name.c_str())); + cskrCinfToAncs[ci.cinf] = std::make_pair(entry.second.id, hecl::Format("CINF_%08X.CINF", ci.cinf.toUint32())); if (ci.cmdlOverlay) { addTo[ci.cmdlOverlay] = std::make_pair(ci.cskrOverlay, ci.cinf); - cskrCinfToAncs[ci.cskrOverlay] = std::make_pair(entry.second->id, hecl::Format("%s.over.CSKR", ci.name.c_str())); + cskrCinfToAncs[ci.cskrOverlay] = std::make_pair(entry.second.id, hecl::Format("%s.over.CSKR", ci.name.c_str())); } } } @@ -201,16 +203,16 @@ void PAKBridge::addMAPATransforms(PAKRouter& pakRouter, std::unordered_map& addTo, std::unordered_map& pathOverrides) const { - for (const std::pair& entry : m_pak.m_idMap) + for (const std::pair& entry : m_pak.m_entries) { - if (entry.second->type == FOURCC('MLVL')) + if (entry.second.type == FOURCC('MLVL')) { MLVL mlvl; { - PAKEntryReadStream rs = entry.second->beginReadStream(m_node); + PAKEntryReadStream rs = entry.second.beginReadStream(m_node); mlvl.read(rs); } - hecl::ProjectPath mlvlDirPath = pakRouter.getWorking(entry.second).getParentPath(); + hecl::ProjectPath mlvlDirPath = pakRouter.getWorking(&entry.second).getParentPath(); if (mlvl.worldNameId) pathOverrides[mlvl.worldNameId] = hecl::ProjectPath(mlvlDirPath, _S("!name.yaml")); diff --git a/DataSpec/DNAMP3/DNAMP3.cpp b/DataSpec/DNAMP3/DNAMP3.cpp index 073e6f5f0..3ea7364ab 100644 --- a/DataSpec/DNAMP3/DNAMP3.cpp +++ b/DataSpec/DNAMP3/DNAMP3.cpp @@ -42,8 +42,9 @@ PAKBridge::PAKBridge(hecl::Database::Project& project, /* Append Level String */ std::set uniq; - for (PAK::Entry& entry : m_pak.m_entries) + for (auto& ent : m_pak.m_entries) { + PAK::Entry& entry = ent.second; if (entry.type == FOURCC('MLVL')) { PAKEntryReadStream rs = entry.beginReadStream(m_node); @@ -81,8 +82,9 @@ static hecl::SystemString LayerName(const std::string& name) void PAKBridge::build() { /* First pass: build per-area/per-layer dependency map */ - for (const PAK::Entry& entry : m_pak.m_entries) + for (const auto& ent : m_pak.m_entries) { + const PAK::Entry& entry = ent.second; if (entry.type == FOURCC('MLVL')) { Level& level = m_levelDeps[entry.id]; @@ -173,9 +175,9 @@ void PAKBridge::build() } /* Second pass: cross-compare uniqueness */ - for (PAK::Entry& entry : m_pak.m_entries) + for (auto& entry : m_pak.m_entries) { - entry.unique.checkEntry(*this, entry); + entry.second.unique.checkEntry(*this, entry.second); } } @@ -183,21 +185,21 @@ void PAKBridge::addCMDLRigPairs(PAKRouter& pakRouter, std::unordered_map>& addTo, std::unordered_map>& cskrCinfToChar) const { - for (const std::pair& entry : m_pak.m_idMap) + for (const std::pair& entry : m_pak.m_entries) { - if (entry.second->type == FOURCC('CHAR')) + if (entry.second.type == FOURCC('CHAR')) { - PAKEntryReadStream rs = entry.second->beginReadStream(m_node); + PAKEntryReadStream rs = entry.second.beginReadStream(m_node); CHAR aChar; aChar.read(rs); const CHAR::CharacterInfo& ci = aChar.characterInfo; addTo[ci.cmdl] = std::make_pair(ci.cskr, ci.cinf); - cskrCinfToChar[ci.cskr] = std::make_pair(entry.second->id, hecl::Format("%s.CSKR", ci.name.c_str())); - cskrCinfToChar[ci.cinf] = std::make_pair(entry.second->id, hecl::Format("CINF_%" PRIX64 ".CINF", ci.cinf.toUint64())); + cskrCinfToChar[ci.cskr] = std::make_pair(entry.second.id, hecl::Format("%s.CSKR", ci.name.c_str())); + cskrCinfToChar[ci.cinf] = std::make_pair(entry.second.id, hecl::Format("CINF_%" PRIX64 ".CINF", ci.cinf.toUint64())); for (const CHAR::CharacterInfo::Overlay& overlay : ci.overlays) { addTo[overlay.cmdl] = std::make_pair(overlay.cskr, ci.cinf); - cskrCinfToChar[overlay.cskr] = std::make_pair(entry.second->id, + cskrCinfToChar[overlay.cskr] = std::make_pair(entry.second.id, hecl::Format("%s.%s.CSKR", ci.name.c_str(), overlay.type.toString().c_str())); } } @@ -210,16 +212,16 @@ void PAKBridge::addMAPATransforms(PAKRouter& pakRouter, std::unordered_map& addTo, std::unordered_map& pathOverrides) const { - for (const std::pair& entry : m_pak.m_idMap) + for (const std::pair& entry : m_pak.m_entries) { - if (entry.second->type == FOURCC('MLVL')) + if (entry.second.type == FOURCC('MLVL')) { MLVL mlvl; { - PAKEntryReadStream rs = entry.second->beginReadStream(m_node); + PAKEntryReadStream rs = entry.second.beginReadStream(m_node); mlvl.read(rs); } - hecl::ProjectPath mlvlDirPath = pakRouter.getWorking(entry.second).getParentPath(); + hecl::ProjectPath mlvlDirPath = pakRouter.getWorking(&entry.second).getParentPath(); if (mlvl.worldNameId) pathOverrides[mlvl.worldNameId] = hecl::ProjectPath(mlvlDirPath, _S("!name.yaml")); diff --git a/DataSpec/DNAMP3/PAK.cpp b/DataSpec/DNAMP3/PAK.cpp index 1e9e120a7..8779d7169 100644 --- a/DataSpec/DNAMP3/PAK.cpp +++ b/DataSpec/DNAMP3/PAK.cpp @@ -37,35 +37,24 @@ void PAK::read(athena::io::IStreamReader& reader) m_entries.reserve(count); m_firstEntries.clear(); m_firstEntries.reserve(count); - m_idMap.clear(); - m_idMap.reserve(count); for (atUint32 e=0 ; esecond; - search->second->name = entry.name; - } - } + m_nameMap[entry.name] = entry.id; } void PAK::write(athena::io::IStreamWriter& writer) const { @@ -88,8 +77,8 @@ void PAK::write(athena::io::IStreamWriter& writer) const DNAFourCC("DATA").write(writer); atUint32 dataSz = 0; - for (const Entry& entry : m_entries) - dataSz += (entry.size + 63) & ~63; + for (const auto& entry : m_entries) + dataSz += (entry.second.size + 63) & ~63; atUint32 dataPad = ((dataSz + 63) & ~63) - dataSz; dataSz += dataPad; writer.writeUint32Big(dataSz); @@ -101,9 +90,9 @@ void PAK::write(athena::io::IStreamWriter& writer) const writer.seek(strgPad, athena::Current); writer.writeUint32Big((atUint32)m_entries.size()); - for (const Entry& entry : m_entries) + for (const auto& entry : m_entries) { - Entry copy = entry; + Entry copy = entry.second; copy.offset -= dataOffset; copy.write(writer); } @@ -129,8 +118,8 @@ size_t PAK::binarySize(size_t __isz) const __isz += strgPad; __isz += 4; - for (const Entry& entry : m_entries) - __isz = entry.binarySize(__isz); + for (const auto& entry : m_entries) + __isz = entry.second.binarySize(__isz); __isz += rshdPad; return __isz; @@ -215,5 +204,40 @@ std::unique_ptr PAK::Entry::getBuffer(const nod::Node& pak, atUint64& } } +const PAK::Entry* PAK::lookupEntry(const UniqueID64& id) const +{ + auto result = m_entries.find(id); + if (result != m_entries.end()) + return &result->second; + return nullptr; +} + +const PAK::Entry* PAK::lookupEntry(const std::string& name) const +{ + auto result = m_nameMap.find(name); + if (result != m_nameMap.end()) + { + auto result1 = m_entries.find(result->second); + if (result1 != m_entries.end()) + return &result1->second; + } + return nullptr; +} + +std::string PAK::bestEntryName(const Entry& entry, bool& named) const +{ + /* Prefer named entries first */ + for (const NameEntry& nentry : m_nameEntries) + if (nentry.id == entry.id) + { + named = true; + return nentry.name; + } + + /* Otherwise return ID format string */ + named = false; + return entry.type.toString() + '_' + entry.id.toString(); +} + } } diff --git a/DataSpec/DNAMP3/PAK.hpp b/DataSpec/DNAMP3/PAK.hpp index 45eb1dbd4..1ee1e718d 100644 --- a/DataSpec/DNAMP3/PAK.hpp +++ b/DataSpec/DNAMP3/PAK.hpp @@ -57,43 +57,15 @@ struct PAK : BigDNA }; std::vector m_nameEntries; - std::vector m_entries; - std::vector m_firstEntries; - std::unordered_map m_idMap; - std::unordered_map m_nameMap; + std::unordered_map m_entries; + std::vector m_firstEntries; + std::unordered_map m_nameMap; DECL_EXPLICIT_DNA - inline const Entry* lookupEntry(const UniqueID64& id) const - { - std::unordered_map::const_iterator result = m_idMap.find(id); - if (result != m_idMap.end()) - return result->second; - return nullptr; - } - - inline const Entry* lookupEntry(const std::string& name) const - { - std::unordered_map::const_iterator result = m_nameMap.find(name); - if (result != m_nameMap.end()) - return result->second; - return nullptr; - } - - inline std::string bestEntryName(const Entry& entry, bool& named) const - { - /* Prefer named entries first */ - for (const NameEntry& nentry : m_nameEntries) - if (nentry.id == entry.id) - { - named = true; - return nentry.name; - } - - /* Otherwise return ID format string */ - named = false; - return entry.type.toString() + '_' + entry.id.toString(); - } + const Entry* lookupEntry(const UniqueID64& id) const; + const Entry* lookupEntry(const std::string& name) const; + std::string bestEntryName(const Entry& entry, bool& named) const; typedef UniqueID64 IDType; }; diff --git a/Runtime/World/CMorphBall.cpp b/Runtime/World/CMorphBall.cpp index 94f422f85..5ca4b0fa9 100644 --- a/Runtime/World/CMorphBall.cpp +++ b/Runtime/World/CMorphBall.cpp @@ -1,6 +1,7 @@ #include "CMorphBall.hpp" #include "CPlayer.hpp" #include "CMorphBallShadow.hpp" +#include "Particle/CGenDescription.hpp" namespace urde { diff --git a/hecl b/hecl index 406cff486..c193e52b4 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 406cff486a82467877dd99fbe01beefd5f0f27a6 +Subproject commit c193e52b49ffa43b5cf5fe5d12994f6e273b0166 diff --git a/visigen/CMakeLists.txt b/visigen/CMakeLists.txt index a4cb15d95..909f08ead 100644 --- a/visigen/CMakeLists.txt +++ b/visigen/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.0) project(visigen) if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}\ -std=c++14 -Wno-multichar -fno-exceptions -Wno-narrowing -Wno-nullability-completeness -Werror=return-type")