mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 17:44:56 +00:00
All cooked resources extracting; decompression bug-fixes
This commit is contained in:
@@ -11,7 +11,7 @@ namespace DNAMP2
|
||||
LogVisor::LogModule Log("Retro::DNAMP2");
|
||||
|
||||
PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPartition::Node& node)
|
||||
: m_project(project), m_node(node)
|
||||
: m_project(project), m_node(node), m_pak(true)
|
||||
{
|
||||
NOD::AthenaPartReadStream rs(node.beginReadStream());
|
||||
m_pak.read(rs);
|
||||
@@ -35,7 +35,7 @@ std::string PAKBridge::getLevelString() const
|
||||
mlvlName.read(rs);
|
||||
if (retval.size())
|
||||
retval += _S(", ");
|
||||
retval += mlvlName.getSystemString(ENGL, 0);
|
||||
retval += mlvlName.getUTF8(ENGL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,20 +45,35 @@ std::string PAKBridge::getLevelString() const
|
||||
ResExtractor PAKBridge::LookupExtractor(const DNAMP1::PAK::Entry& entry)
|
||||
{
|
||||
if (entry.type == Retro::STRG)
|
||||
return {STRG::Extract<STRG>, ".strg"};
|
||||
return {STRG::Extract<STRG>, ".as"};
|
||||
return {};
|
||||
}
|
||||
|
||||
bool PAKBridge::extractResources(const HECL::ProjectPath& dirOut)
|
||||
bool PAKBridge::extractResources(const HECL::ProjectPath& workingOut,
|
||||
const HECL::ProjectPath& cookedOut,
|
||||
bool force)
|
||||
{
|
||||
for (const std::pair<UniqueID32, DNAMP1::PAK::Entry*>& item : m_pak.m_idMap)
|
||||
{
|
||||
PAKEntryReadStream s;
|
||||
ResExtractor extractor = LookupExtractor(*item.second);
|
||||
if (extractor.func)
|
||||
{
|
||||
PAKEntryReadStream strgIn = item.second->beginReadStream(m_node);
|
||||
HECL::ProjectPath resPath(dirOut, m_pak.bestEntryName(*item.second) + extractor.fileExt);
|
||||
extractor.func(strgIn, resPath);
|
||||
HECL::ProjectPath workPath(workingOut, m_pak.bestEntryName(*item.second) + extractor.fileExt);
|
||||
if (force || workPath.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
s = item.second->beginReadStream(m_node);
|
||||
extractor.func(s, workPath);
|
||||
}
|
||||
}
|
||||
HECL::ProjectPath cookPath(cookedOut, m_pak.bestEntryName(*item.second));
|
||||
if (force || cookPath.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
if (!s)
|
||||
s = item.second->beginReadStream(m_node);
|
||||
FILE* fout = HECL::Fopen(cookPath.getAbsolutePath().c_str(), _S("wb"));
|
||||
fwrite(s.data(), 1, s.length(), fout);
|
||||
fclose(fout);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -17,14 +17,14 @@ class PAKBridge
|
||||
HECL::Database::Project& m_project;
|
||||
const NOD::DiscBase::IPartition::Node& m_node;
|
||||
DNAMP1::PAK m_pak;
|
||||
|
||||
static ResExtractor LookupExtractor(const DNAMP1::PAK::Entry& entry);
|
||||
|
||||
public:
|
||||
PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPartition::Node& node);
|
||||
const std::string& getName() const {return m_node.getName();}
|
||||
std::string getLevelString() const;
|
||||
bool extractResources(const HECL::ProjectPath& dirOut);
|
||||
bool extractResources(const HECL::ProjectPath& dirOut,
|
||||
const HECL::ProjectPath& cookedOut,
|
||||
bool force);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -44,8 +44,13 @@ void STRG::_read(Athena::io::IStreamReader& reader)
|
||||
reader.seek(strCount * 4);
|
||||
for (atUint32 s=0 ; s<strCount ; ++s)
|
||||
strs.emplace_back(reader.readWString());
|
||||
langs.emplace(std::make_pair(lang, strs));
|
||||
langs.emplace_back(lang, strs);
|
||||
}
|
||||
|
||||
langMap.clear();
|
||||
langMap.reserve(langCount);
|
||||
for (std::pair<FourCC, std::vector<std::wstring>>& item : langs)
|
||||
langMap.emplace(item.first, &item.second);
|
||||
}
|
||||
|
||||
void STRG::read(Athena::io::IStreamReader& reader)
|
||||
@@ -140,6 +145,35 @@ bool STRG::readAngelScript(const AngelScript::asIScriptModule& in)
|
||||
|
||||
void STRG::writeAngelScript(std::ofstream& out) const
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> wconv;
|
||||
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
|
||||
{
|
||||
out << "STRG::Language " << lang.first.toString() << "({";
|
||||
bool comma = false;
|
||||
unsigned idx = 0;
|
||||
for (const std::wstring& str : lang.second)
|
||||
{
|
||||
if (comma)
|
||||
out << ",";
|
||||
out << "\n/* " << idx++ << " */ \"";
|
||||
out << wconv.to_bytes(str);
|
||||
out << "\"";
|
||||
comma = true;
|
||||
}
|
||||
out << "\n});\n";
|
||||
}
|
||||
|
||||
out << "STRG::Names NAMES({";
|
||||
bool comma = false;
|
||||
for (const std::pair<std::string, int32_t>& name : names)
|
||||
{
|
||||
if (comma)
|
||||
out << ",";
|
||||
out << "\n ";
|
||||
comma = true;
|
||||
out << "{\"" << name.first << "\", " << name.second << "}";
|
||||
}
|
||||
out << "\n});\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ struct STRG : ISTRG, BigDNA
|
||||
{
|
||||
DECL_EXPLICIT_DNA
|
||||
void _read(Athena::io::IStreamReader& reader);
|
||||
std::unordered_map<FourCC, std::vector<std::wstring>> langs;
|
||||
std::vector<std::pair<FourCC, std::vector<std::wstring>>> langs;
|
||||
std::unordered_map<FourCC, std::vector<std::wstring>*> langMap;
|
||||
std::map<std::string, int32_t> names;
|
||||
|
||||
inline int32_t lookupIdx(const std::string& name) const
|
||||
@@ -38,26 +39,26 @@ struct STRG : ISTRG, BigDNA
|
||||
}
|
||||
inline std::string getUTF8(const FourCC& lang, size_t idx) const
|
||||
{
|
||||
auto search = langs.find(lang);
|
||||
if (search != langs.end())
|
||||
return HECL::WideToUTF8(search->second.at(idx));
|
||||
auto search = langMap.find(lang);
|
||||
if (search != langMap.end())
|
||||
return HECL::WideToUTF8(search->second->at(idx));
|
||||
return std::string();
|
||||
}
|
||||
inline std::wstring getUTF16(const FourCC& lang, size_t idx) const
|
||||
{
|
||||
auto search = langs.find(lang);
|
||||
if (search != langs.end())
|
||||
return search->second.at(idx);
|
||||
auto search = langMap.find(lang);
|
||||
if (search != langMap.end())
|
||||
return search->second->at(idx);
|
||||
return std::wstring();
|
||||
}
|
||||
inline HECL::SystemString getSystemString(const FourCC& lang, size_t idx) const
|
||||
{
|
||||
auto search = langs.find(lang);
|
||||
if (search != langs.end())
|
||||
auto search = langMap.find(lang);
|
||||
if (search != langMap.end())
|
||||
#if HECL_UCS2
|
||||
return search->second.at(idx);
|
||||
return search->second->at(idx);
|
||||
#else
|
||||
return HECL::WideToUTF8(search->second.at(idx));
|
||||
return HECL::WideToUTF8(search->second->at(idx));
|
||||
#endif
|
||||
return std::string();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user