2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 22:27:41 +00:00

initial MLVL and STRG trilogy integration

This commit is contained in:
Jack Andersen
2015-07-12 20:29:12 -10:00
parent abb9d4c000
commit 7876d4c209
26 changed files with 1333 additions and 126 deletions

View File

@@ -1,3 +1,5 @@
make_dnalist(liblist
MLVL)
add_library(DNAMP2 ${liblist})
MLVL
STRG)
add_library(DNAMP2 ${liblist}
STRG.cpp)

View File

@@ -1,3 +1,6 @@
#ifndef __DNAMP2_MLVL_HPP__
#define __DNAMP2_MLVL_HPP__
#include "../DNACommon/DNACommon.hpp"
namespace Retro
@@ -8,7 +11,7 @@ namespace DNAMP2
struct MLVL : BigDNA
{
DECL_DNA
FourCC magic;
Value<atUint32> magic;
Value<atUint32> version;
UniqueID32 worldNameId;
UniqueID32 darkWorldNameId;
@@ -35,7 +38,7 @@ struct MLVL : BigDNA
{
DECL_DNA
UniqueID32 id;
HECL::FourCC type;
FourCC type;
};
Vector<Dependency, DNA_COUNT(depCount)> deps;
@@ -53,7 +56,7 @@ struct MLVL : BigDNA
Value<atUint32> areaIdx;
Value<atUint32> dockIdx;
};
HECL::FourCC type;
FourCC type;
Vector<Endpoint, DNA_COUNT(endpointCount)> endpoints;
Value<atUint32> planeVertCount;
@@ -66,7 +69,6 @@ struct MLVL : BigDNA
Value<atUint32> relOffsetCount;
Vector<atUint32, DNA_COUNT(relOffsetCount)> relOffsets;
Value<atUint32> unk1;
String<-1> internalAreaName;
};
@@ -92,3 +94,5 @@ struct MLVL : BigDNA
}
}
#endif // __DNAMP2_MLVL_HPP__

138
DataSpec/DNAMP2/STRG.cpp Normal file
View File

@@ -0,0 +1,138 @@
#include "STRG.hpp"
#include "../Logging.hpp"
namespace Retro
{
namespace DNAMP2
{
void STRG::_read(Athena::io::IStreamReader& reader)
{
atUint32 langCount = reader.readUint32();
atUint32 strCount = reader.readUint32();
std::vector<FourCC> readLangs;
readLangs.reserve(langCount);
for (atUint32 l=0 ; l<langCount ; ++l)
{
FourCC lang;
lang.read(reader);
readLangs.emplace_back(lang);
reader.seek(8);
}
atUint32 nameCount = reader.readUint32();
atUint32 nameTableSz = reader.readUint32();
std::unique_ptr<uint8_t[]> nameTableBuf(new uint8_t[nameTableSz]);
reader.readUBytesToBuf(nameTableBuf.get(), nameTableSz);
struct NameIdxEntry
{
atUint32 nameOff;
atUint32 strIdx;
}* nameIndex = (NameIdxEntry*)nameTableBuf.get();
for (atUint32 n=0 ; n<nameCount ; ++n)
{
const char* name = (char*)(nameTableBuf.get() + HECL::SBig(nameIndex[n].nameOff));
names[name] = HECL::SBig(nameIndex[n].strIdx);
}
langs.clear();
langs.reserve(langCount);
for (FourCC& lang : readLangs)
{
std::vector<std::wstring> strs;
reader.seek(strCount * 4);
for (atUint32 s=0 ; s<strCount ; ++s)
strs.emplace_back(reader.readWString());
langs.emplace(std::make_pair(lang, strs));
}
}
void STRG::read(Athena::io::IStreamReader& reader)
{
reader.setEndian(Athena::BigEndian);
atUint32 magic = reader.readUint32();
if (magic != 0x87654321)
LogModule.report(LogVisor::Error, "invalid STRG magic");
atUint32 version = reader.readUint32();
if (version != 1)
LogModule.report(LogVisor::Error, "invalid STRG version");
_read(reader);
}
void STRG::write(Athena::io::IStreamWriter& writer) const
{
writer.setEndian(Athena::BigEndian);
writer.writeUint32(0x87654321);
writer.writeUint32(1);
writer.writeUint32(langs.size());
atUint32 strCount = STRG::count();
writer.writeUint32(strCount);
atUint32 offset = 0;
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
{
lang.first.write(writer);
writer.writeUint32(offset);
offset += strCount * 4 + 4;
atUint32 langStrCount = lang.second.size();
atUint32 tableSz = strCount * 4;
for (atUint32 s=0 ; s<strCount ; ++s)
{
atUint32 chCount = lang.second[s].size();
if (s < langStrCount)
{
offset += chCount * 2 + 1;
tableSz += chCount * 2 + 1;
}
else
{
offset += 1;
tableSz += 1;
}
}
writer.writeUint32(tableSz);
}
atUint32 nameTableSz = names.size() * 8;
for (const std::pair<std::string, int32_t>& name : names)
nameTableSz += name.first.size() + 1;
writer.writeUint32(names.size());
writer.writeUint32(nameTableSz);
offset = names.size() * 8;
for (const std::pair<std::string, int32_t>& name : names)
{
writer.writeUint32(offset);
writer.writeInt32(name.second);
offset += name.first.size() + 1;
}
for (const std::pair<std::string, int32_t>& name : names)
writer.writeString(name.first);
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
{
offset = strCount * 4;
atUint32 langStrCount = lang.second.size();
for (atUint32 s=0 ; s<strCount ; ++s)
{
writer.writeUint32(offset);
if (s < langStrCount)
offset += lang.second[s].size() * 2 + 1;
else
offset += 1;
}
for (atUint32 s=0 ; s<strCount ; ++s)
{
if (s < langStrCount)
writer.writeWString(lang.second[s]);
else
writer.writeUByte(0);
}
}
}
}
}

69
DataSpec/DNAMP2/STRG.hpp Normal file
View File

@@ -0,0 +1,69 @@
#ifndef __DNAMP2_STRG_HPP__
#define __DNAMP2_STRG_HPP__
#include <unordered_map>
#include "../DNACommon/DNACommon.hpp"
#include "../DNACommon/STRG.hpp"
namespace Retro
{
namespace DNAMP2
{
struct STRG : ISTRG, BigDNA
{
DECL_EXPLICIT_DNA
void _read(Athena::io::IStreamReader& reader);
std::unordered_map<FourCC, std::vector<std::wstring>> langs;
std::map<std::string, int32_t> names;
inline int32_t lookupIdx(const std::string& name) const
{
auto search = names.find(name);
if (search == names.end())
return -1;
return search->second;
}
inline size_t count() const
{
size_t retval = 0;
for (auto item : langs)
{
size_t sz = item.second.size();
if (sz > retval)
retval = sz;
}
return retval;
}
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));
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);
return std::wstring();
}
inline HECL::SystemString getSystemString(const FourCC& lang, size_t idx) const
{
auto search = langs.find(lang);
if (search != langs.end())
#if HECL_UCS2
return search->second.at(idx);
#else
return HECL::WideToUTF8(search->second.at(idx));
#endif
return std::string();
}
};
}
}
#endif // __DNAMP2_STRG_HPP__