mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-12 07:48:16 -05:00
Dump SoundBank asset data files
This commit is contained in:
111
src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp
Normal file
111
src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
#include "AssetDumperSndBank.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include "Csv/CsvStream.h"
|
||||
#include "ObjContainer/SoundBank/SoundBank.h"
|
||||
|
||||
using namespace T6;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::unique_ptr<std::ostream> AssetDumperSndBank::OpenOutputFile(AssetDumpingContext& context, const std::string& outputFileName) const
|
||||
{
|
||||
fs::path assetPath(context.m_base_path);
|
||||
|
||||
fs::path assetName(outputFileName);
|
||||
auto firstPart = true;
|
||||
for(const auto& part : assetName)
|
||||
{
|
||||
if(firstPart)
|
||||
{
|
||||
firstPart = false;
|
||||
if(part.string() == "raw"
|
||||
|| part.string() == "devraw")
|
||||
continue;
|
||||
}
|
||||
|
||||
assetPath.append(part.string());
|
||||
}
|
||||
|
||||
auto assetDir(assetPath);
|
||||
assetDir.remove_filename();
|
||||
|
||||
create_directories(assetDir);
|
||||
|
||||
auto outputStream = std::make_unique<std::ofstream>(assetPath, std::ios_base::out | std::ios_base::binary);
|
||||
|
||||
if(outputStream->is_open())
|
||||
{
|
||||
return std::move(outputStream);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AssetDumperSndBank::DumpSndBank(AssetDumpingContext& context, const XAssetInfo<SndBank>* sndBankInfo)
|
||||
{
|
||||
const auto* sndBank = sndBankInfo->Asset();
|
||||
|
||||
// auto* streamAssetBank = SoundBank::Repository.GetContainerByName(SoundBank::GetFileNameForDefinition(true, sndBank->streamAssetBank.zone, sndBank->streamAssetBank.language));
|
||||
// SoundBank* loadedAssetBank = nullptr;
|
||||
// if (sndBank->runtimeAssetLoad && sndBank->loadAssetBank.zone)
|
||||
// loadedAssetBank = SoundBank::Repository.GetContainerByName(SoundBank::GetFileNameForDefinition(false, sndBank->loadAssetBank.zone, sndBank->loadAssetBank.language));
|
||||
|
||||
std::map<unsigned int, std::string> aliasMappings;
|
||||
for (auto i = 0u; i < sndBank->aliasCount; i++)
|
||||
{
|
||||
const auto& aliasList = sndBank->alias[i];
|
||||
for (auto j = 0; j < aliasList.count; j++)
|
||||
{
|
||||
const auto& alias = aliasList.head[j];
|
||||
if (alias.assetId && alias.assetFileName)
|
||||
aliasMappings[alias.assetId] = alias.assetFileName;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& [id, filename] : aliasMappings)
|
||||
{
|
||||
auto foundEntry = false;
|
||||
|
||||
for (const auto* soundBank : SoundBank::Repository)
|
||||
{
|
||||
auto soundFile = soundBank->GetEntryStream(id);
|
||||
if (soundFile.IsOpen())
|
||||
{
|
||||
auto outFile = OpenOutputFile(context, filename);
|
||||
if (!outFile)
|
||||
{
|
||||
std::cout << "Failed to open sound outputfile: \"" << filename << "\"" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
char buffer[2048];
|
||||
while (!soundFile.m_stream->eof())
|
||||
{
|
||||
soundFile.m_stream->read(buffer, sizeof(buffer));
|
||||
const auto readSize = soundFile.m_stream->gcount();
|
||||
outFile->write(buffer, readSize);
|
||||
}
|
||||
|
||||
foundEntry = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundEntry)
|
||||
{
|
||||
std::cout << "Could not find data for sound \"" << filename << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AssetDumperSndBank::DumpPool(AssetDumpingContext& context, AssetPool<SndBank>* pool)
|
||||
{
|
||||
for(const auto* assetInfo : *pool)
|
||||
{
|
||||
if (!assetInfo->m_name.empty() && assetInfo->m_name[0] == ',')
|
||||
continue;
|
||||
|
||||
DumpSndBank(context, assetInfo);
|
||||
}
|
||||
}
|
19
src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.h
Normal file
19
src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class AssetDumperSndBank final : public IAssetDumper<SndBank>
|
||||
{
|
||||
std::unique_ptr<std::ostream> OpenOutputFile(AssetDumpingContext& context, const std::string& outputFileName) const;
|
||||
void DumpSndBank(AssetDumpingContext& context, const XAssetInfo<SndBank>* sndBankInfo);
|
||||
|
||||
public:
|
||||
void DumpPool(AssetDumpingContext& context, AssetPool<SndBank>* pool) override;
|
||||
};
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
#include "AssetDumpers/AssetDumperFontIcon.h"
|
||||
#include "AssetDumpers/AssetDumperPhysConstraints.h"
|
||||
#include "AssetDumpers/AssetDumperPhysPreset.h"
|
||||
#include "AssetDumpers/AssetDumperSndBank.h"
|
||||
#include "AssetDumpers/AssetDumperTracer.h"
|
||||
#include "AssetDumpers/AssetDumperVehicle.h"
|
||||
#include "AssetDumpers/AssetDumperWeapon.h"
|
||||
@ -46,7 +47,7 @@ bool ZoneDumper::DumpZone(AssetDumpingContext& context) const
|
||||
// DUMP_ASSET_POOL(AssetDumperMaterial, m_material);
|
||||
// DUMP_ASSET_POOL(AssetDumperTechniqueSet, m_technique_set);
|
||||
DUMP_ASSET_POOL(AssetDumperGfxImage, m_image);
|
||||
// DUMP_ASSET_POOL(AssetDumperSndBank, m_sound_bank);
|
||||
DUMP_ASSET_POOL(AssetDumperSndBank, m_sound_bank);
|
||||
// DUMP_ASSET_POOL(AssetDumperSndPatch, m_sound_patch);
|
||||
// DUMP_ASSET_POOL(AssetDumperClipMap, m_clip_map);
|
||||
// DUMP_ASSET_POOL(AssetDumperComWorld, m_com_world);
|
||||
|
Reference in New Issue
Block a user