This commit is contained in:
Jack Andersen 2017-07-13 19:14:36 -10:00
commit e23a61876e
4 changed files with 117 additions and 0 deletions

80
DataSpec/AssetNameMap.cpp Normal file
View File

@ -0,0 +1,80 @@
#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;
SAsset(athena::io::IStreamReader& in)
{
uint32_t nameLen = in.readUint32Big();
name = in.readString(nameLen);
uint32_t dirLen = in.readUint32Big();
directory = in.readString(dirLen);
type = in.readUint32Big();
}
};
static std::unordered_map<uint64_t, SAsset> g_AssetNameMap;
static bool g_AssetNameMapInit = false;
void LoadAssetMap(athena::io::MemoryReader ar)
{
if (!ar.hasError())
{
hecl::FourCC magic = ar.readUint32Big();
if (magic != FOURCC('AIDM'))
Log.report(logvisor::Error, _S("Unable to load asset map; Assets will not have proper filenames for most files."));
else
{
uint32_t assetCount = ar.readUint32Big();
for (uint32_t i = 0 ; i<assetCount ; ++i)
{
uint64_t id = ar.readUint64Big();
g_AssetNameMap[id] = SAsset(ar);
}
}
}
}
void InitAssetNameMap()
{
if (g_AssetNameMapInit)
return;
/* 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;
}
}
}

17
DataSpec/AssetNameMap.hpp Normal file
View File

@ -0,0 +1,17 @@
#ifndef _DATASPEC_ASSETNAMEMAP_HPP_
#define _DATASPEC_ASSETNAMEMAP_HPP_
#include <unordered_map>
#include <string>
#include "DNACommon/DNACommon.hpp"
namespace DataSpec
{
namespace AssetNameMap
{
void InitAssetNameMap();
const std::string* TranslateIdToName(const UniqueID32&);
const std::string* TranslateIdToName(const UniqueID64&);
}
}
#endif // _DATASPEC_ASSETNAMEMAP_HPP_

View File

@ -41,6 +41,20 @@ include(DNAMP3/CMakeLists.txt)
# Embed master shader script
bintoc(RetroMasterShader.c Blender/RetroMasterShader.py RETRO_MASTER_SHADER)
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap32.bin")
message(STATUS "Downloading 32bit ID map to '${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap32.bin'")
file(DOWNLOAD "https://www.dropbox.com/s/8rzkxstfap6hgi3/AssetNameMap32.dat"
${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap32.bin SHOW_PROGRESS)
endif()
bintoc(AssetNameMap32.c ${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap32.bin ASSET_NAME_MP32)
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap64.bin")
message(STATUS "Downloading 64bit ID map to '${CMAKE_CURRENT_BINARY_DIR}/DNAMP3/AssetNameMap64.bin'")
file(DOWNLOAD "https://www.dropbox.com/s/o1pp3ctu5dyhfwx/AssetNameMap64.dat"
${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap64.bin SHOW_PROGRESS)
endif()
bintoc(AssetNameMap64.c ${CMAKE_CURRENT_BINARY_DIR}/AssetNameMap64.bin ASSET_NAME_MP64)
# Each game's DataSpec implementation
add_library(RetroDataSpec
SpecBase.cpp
@ -55,4 +69,8 @@ add_library(RetroDataSpec
Blender/BlenderSupport.hpp
Blender/BlenderSupport.cpp
Blender/RetroMasterShader.py
AssetNameMap.hpp
AssetNameMap.cpp
AssetNameMap32.bin AssetNameMap32.c
AssetNameMap64.bin AssetNameMap64.c
RetroMasterShader.c)

View File

@ -8,6 +8,7 @@
#include "hecl/Blender/BlenderConnection.hpp"
#include "DNACommon/DNACommon.hpp"
#include "DNACommon/TXTR.hpp"
#include "AssetNameMap.hpp"
#include <time.h>
#include <png.h>
@ -38,6 +39,7 @@ SpecBase::SpecBase(const hecl::Database::DataSpecEntry* specEntry, hecl::Databas
: hecl::Database::IDataSpec(specEntry), m_project(project), m_pc(pc),
m_masterShader(project.getProjectWorkingPath(), ".hecl/RetroMasterShader.blend")
{
AssetNameMap::InitAssetNameMap();
DataSpec::UniqueIDBridge::setThreadProject(m_project);
}