2017-07-13 11:39:52 +00:00
|
|
|
#include "AssetNameMap.hpp"
|
|
|
|
#include "athena/MemoryReader.hpp"
|
|
|
|
|
|
|
|
extern "C" uint8_t ASSET_NAME_MP32[];
|
|
|
|
extern "C" uint32_t ASSET_NAME_MP32_SZ;
|
|
|
|
extern "C" uint8_t ASSET_NAME_MP64[];
|
|
|
|
extern "C" uint32_t ASSET_NAME_MP64_SZ;
|
|
|
|
|
|
|
|
namespace DataSpec
|
|
|
|
{
|
|
|
|
namespace AssetNameMap
|
|
|
|
{
|
|
|
|
logvisor::Module Log("AssetNameMap");
|
|
|
|
|
|
|
|
struct SAsset
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::string directory;
|
|
|
|
hecl::FourCC type;
|
|
|
|
SAsset() = default;
|
2017-07-23 09:21:18 +00:00
|
|
|
SAsset(const hecl::FourCC& typeIn, athena::io::IStreamReader& in)
|
|
|
|
: type(typeIn)
|
2017-07-13 11:39:52 +00:00
|
|
|
{
|
|
|
|
uint32_t nameLen = in.readUint32Big();
|
|
|
|
name = in.readString(nameLen);
|
|
|
|
uint32_t dirLen = in.readUint32Big();
|
|
|
|
directory = in.readString(dirLen);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::unordered_map<uint64_t, SAsset> g_AssetNameMap;
|
|
|
|
static bool g_AssetNameMapInit = false;
|
|
|
|
|
2017-07-23 09:21:18 +00:00
|
|
|
void LoadAssetMap(athena::io::MemoryReader& ar)
|
2017-07-13 11:39:52 +00:00
|
|
|
{
|
|
|
|
if (!ar.hasError())
|
|
|
|
{
|
2017-07-23 09:21:18 +00:00
|
|
|
hecl::FourCC magic;
|
|
|
|
if (ar.length() >= 4)
|
|
|
|
ar.readBytesToBuf(&magic, 4);
|
2017-07-13 11:39:52 +00:00
|
|
|
if (magic != FOURCC('AIDM'))
|
2017-07-23 09:21:18 +00:00
|
|
|
Log.report(logvisor::Warning, _S("Unable to load asset map; Assets will not have proper filenames for most files."));
|
2017-07-13 11:39:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
uint32_t assetCount = ar.readUint32Big();
|
2017-07-23 09:21:18 +00:00
|
|
|
g_AssetNameMap.reserve(assetCount);
|
2017-07-13 11:39:52 +00:00
|
|
|
for (uint32_t i = 0 ; i<assetCount ; ++i)
|
|
|
|
{
|
2017-07-23 09:21:18 +00:00
|
|
|
hecl::FourCC type;
|
|
|
|
ar.readBytesToBuf(&type, 4);
|
2017-07-13 11:39:52 +00:00
|
|
|
uint64_t id = ar.readUint64Big();
|
2017-07-23 09:21:18 +00:00
|
|
|
g_AssetNameMap[id] = SAsset(type, ar);
|
2017-07-13 11:39:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitAssetNameMap()
|
|
|
|
{
|
|
|
|
if (g_AssetNameMapInit)
|
|
|
|
return;
|
|
|
|
|
2017-07-23 09:21:18 +00:00
|
|
|
Log.report(logvisor::Info, "Initializing asset name database...");
|
|
|
|
|
2017-07-13 11:39:52 +00:00
|
|
|
/* First load the 32bit map for MP1/2 */
|
|
|
|
{
|
|
|
|
athena::io::MemoryReader ar(ASSET_NAME_MP32, ASSET_NAME_MP32_SZ);
|
|
|
|
LoadAssetMap(ar);
|
|
|
|
}
|
|
|
|
/* Now load the 64bit map for MP3 */
|
|
|
|
{
|
|
|
|
athena::io::MemoryReader ar(ASSET_NAME_MP64, ASSET_NAME_MP64_SZ);
|
|
|
|
LoadAssetMap(ar);
|
|
|
|
}
|
|
|
|
g_AssetNameMapInit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string* TranslateIdToName(const UniqueID32& id)
|
|
|
|
{
|
|
|
|
if (g_AssetNameMap.find(id.toUint64()) == g_AssetNameMap.end())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &g_AssetNameMap[id.toUint64()].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|