Pointer dereference bug fixes

This commit is contained in:
Jack Andersen 2017-03-10 08:00:40 -10:00
parent 2d093b6d80
commit d2e9290363
15 changed files with 187 additions and 209 deletions

6
.gitignore vendored
View File

@ -1,6 +0,0 @@
.directory
version.h
*.user
.DS_Store
*.autosave
docs/*

18
.gitmodules vendored
View File

@ -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

View File

@ -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}")

View File

@ -165,7 +165,7 @@ void PAKRouter<BRIDGETYPE>::build(std::vector<BRIDGETYPE>& 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<BRIDGETYPE>::build(std::vector<BRIDGETYPE>& 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<BRIDGETYPE>::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 ; count<sz ; ++w)
{
for (const auto& item : m_pak->m_firstEntries)
{
ResExtractor<BRIDGETYPE> extractor = BRIDGETYPE::LookupExtractor(*m_pak.get(), *item);
const auto* entryPtr = m_pak->lookupEntry(item);
ResExtractor<BRIDGETYPE> 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<BRIDGETYPE>::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<BRIDGETYPE>::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<BRIDGETYPE>::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);

View File

@ -167,8 +167,8 @@ private:
hecl::ProjectPath m_sharedCooked;
ThreadLocalPtr<const PAKType> m_pak;
ThreadLocalPtr<const nod::Node> m_node;
std::unordered_map<IDType, std::pair<size_t, EntryType*>> m_uniqueEntries;
std::unordered_map<IDType, std::pair<size_t, EntryType*>> m_sharedEntries;
std::unordered_map<IDType, std::pair<size_t, const EntryType*>> m_uniqueEntries;
std::unordered_map<IDType, std::pair<size_t, const EntryType*>> m_sharedEntries;
std::unordered_map<IDType, hecl::ProjectPath> m_overrideEntries;
std::unordered_map<IDType, RigPair> m_cmdlRigs;
std::unordered_map<IDType, std::pair<IDType, std::string>> m_cskrCinfToCharacter;

View File

@ -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<PAKBridge>& pakRouter,
std::unordered_map<UniqueID32, std::pair<UniqueID32, UniqueID32>>& addTo,
std::unordered_map<UniqueID32, std::pair<UniqueID32, std::string>>& cskrCinfToAncs) const
{
for (const std::pair<UniqueID32, PAK::Entry*>& entry : m_pak.m_idMap)
for (const std::pair<UniqueID32, PAK::Entry>& 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<PAKBridge>& 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<PAKBridge>& 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<PAKBridge>& pakRouter,
std::unordered_map<UniqueID32, zeus::CMatrix4f>& addTo,
std::unordered_map<UniqueID32, hecl::ProjectPath>& pathOverrides) const
{
for (const std::pair<UniqueID32, PAK::Entry*>& entry : m_pak.m_idMap)
for (const std::pair<UniqueID32, PAK::Entry>& 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"));

View File

@ -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<count ; ++e)
{
m_entries.emplace_back();
Entry& ent = m_entries.back();
ent.read(reader);
if (ent.compressed && m_useLzo)
ent.compressed = 2;
}
for (Entry& entry : m_entries)
{
auto search = m_idMap.find(entry.id);
if (search == m_idMap.end())
Entry entry;
entry.read(reader);
if (entry.compressed && m_useLzo)
entry.compressed = 2;
auto search = m_entries.find(entry.id);
if (search == m_entries.end())
{
m_firstEntries.push_back(&entry);
m_idMap[entry.id] = &entry;
m_firstEntries.push_back(entry.id);
m_entries[entry.id] = std::move(entry);
}
}
m_nameMap.clear();
m_nameMap.reserve(nameCount);
for (NameEntry& entry : m_nameEntries)
{
std::unordered_map<UniqueID32, Entry*>::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();
}
}
}

View File

@ -48,41 +48,13 @@ struct PAK : BigDNA
};
std::vector<NameEntry> m_nameEntries;
std::vector<Entry> m_entries;
std::vector<Entry*> m_firstEntries;
std::unordered_map<UniqueID32, Entry*> m_idMap;
std::unordered_map<std::string, Entry*> m_nameMap;
std::unordered_map<UniqueID32, Entry> m_entries;
std::vector<UniqueID32> m_firstEntries;
std::unordered_map<std::string, UniqueID32> m_nameMap;
const Entry* lookupEntry(const UniqueID32& id) const
{
std::unordered_map<UniqueID32, Entry*>::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<std::string, Entry*>::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;
};

View File

@ -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<PAKBridge>& pakRouter,
std::unordered_map<UniqueID32, std::pair<UniqueID32, UniqueID32>>& addTo,
std::unordered_map<UniqueID32, std::pair<UniqueID32, std::string>>& cskrCinfToAncs) const
{
for (const std::pair<UniqueID32, DNAMP1::PAK::Entry*>& entry : m_pak.m_idMap)
for (const std::pair<UniqueID32, DNAMP1::PAK::Entry>& 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<PAKBridge>& pakRouter,
std::unordered_map<UniqueID32, zeus::CMatrix4f>& addTo,
std::unordered_map<UniqueID32, hecl::ProjectPath>& pathOverrides) const
{
for (const std::pair<UniqueID32, DNAMP1::PAK::Entry*>& entry : m_pak.m_idMap)
for (const std::pair<UniqueID32, DNAMP1::PAK::Entry>& 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"));

View File

@ -42,8 +42,9 @@ PAKBridge::PAKBridge(hecl::Database::Project& project,
/* Append Level String */
std::set<hecl::SystemString, hecl::CaseInsensitiveCompare> 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<PAKBridge>& pakRouter,
std::unordered_map<UniqueID64, std::pair<UniqueID64, UniqueID64>>& addTo,
std::unordered_map<UniqueID64, std::pair<UniqueID64, std::string>>& cskrCinfToChar) const
{
for (const std::pair<UniqueID64, PAK::Entry*>& entry : m_pak.m_idMap)
for (const std::pair<UniqueID64, PAK::Entry>& 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<PAKBridge>& pakRouter,
std::unordered_map<UniqueID64, zeus::CMatrix4f>& addTo,
std::unordered_map<UniqueID64, hecl::ProjectPath>& pathOverrides) const
{
for (const std::pair<UniqueID64, PAK::Entry*>& entry : m_pak.m_idMap)
for (const std::pair<UniqueID64, PAK::Entry>& 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"));

View File

@ -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 ; e<count ; ++e)
{
m_entries.emplace_back();
m_entries.back().read(reader);
m_entries.back().offset += dataOffset;
}
for (Entry& entry : m_entries)
{
auto search = m_idMap.find(entry.id);
if (search == m_idMap.end())
Entry entry;
entry.read(reader);
entry.offset += dataOffset;
auto search = m_entries.find(entry.id);
if (search == m_entries.end())
{
m_firstEntries.push_back(&entry);
m_idMap[entry.id] = &entry;
m_firstEntries.push_back(entry.id);
m_entries[entry.id] = std::move(entry);
}
}
m_nameMap.clear();
m_nameMap.reserve(nameCount);
for (NameEntry& entry : m_nameEntries)
{
auto search = m_idMap.find(entry.id);
if (search != m_idMap.end())
{
m_nameMap[entry.name] = search->second;
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<atUint8[]> 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();
}
}
}

View File

@ -57,43 +57,15 @@ struct PAK : BigDNA
};
std::vector<NameEntry> m_nameEntries;
std::vector<Entry> m_entries;
std::vector<Entry*> m_firstEntries;
std::unordered_map<UniqueID64, Entry*> m_idMap;
std::unordered_map<std::string, Entry*> m_nameMap;
std::unordered_map<UniqueID64, Entry> m_entries;
std::vector<UniqueID64> m_firstEntries;
std::unordered_map<std::string, UniqueID64> m_nameMap;
DECL_EXPLICIT_DNA
inline const Entry* lookupEntry(const UniqueID64& id) const
{
std::unordered_map<UniqueID64, Entry*>::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<std::string, Entry*>::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;
};

View File

@ -1,6 +1,7 @@
#include "CMorphBall.hpp"
#include "CPlayer.hpp"
#include "CMorphBallShadow.hpp"
#include "Particle/CGenDescription.hpp"
namespace urde
{

2
hecl

@ -1 +1 @@
Subproject commit 406cff486a82467877dd99fbe01beefd5f0f27a6
Subproject commit c193e52b49ffa43b5cf5fe5d12994f6e273b0166

View File

@ -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")