From 3551d0c0ebcae486da5738ff4c1b9f4c80f00b35 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 29 Nov 2016 19:32:46 +0100 Subject: [PATCH] [ZoneBuilder] Add LoadedSound interface --- src/Components/Modules/AssetHandler.cpp | 1 + src/Components/Modules/AssetHandler.hpp | 1 + .../Modules/AssetInterfaces/ILoadedSound.cpp | 45 +++++++++++++++++++ .../Modules/AssetInterfaces/ILoadedSound.hpp | 10 +++++ src/Components/Modules/ZoneBuilder.cpp | 3 ++ src/Game/Structs.hpp | 17 ++++++- 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/Components/Modules/AssetInterfaces/ILoadedSound.cpp create mode 100644 src/Components/Modules/AssetInterfaces/ILoadedSound.hpp diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index 61e7c326..28327893 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -393,6 +393,7 @@ namespace Components AssetHandler::RegisterInterface(new Assets::IPhysPreset()); AssetHandler::RegisterInterface(new Assets::IXAnimParts()); AssetHandler::RegisterInterface(new Assets::IFxEffectDef()); + AssetHandler::RegisterInterface(new Assets::ILoadedSound()); AssetHandler::RegisterInterface(new Assets::IPhysCollmap()); AssetHandler::RegisterInterface(new Assets::IStringTable()); //AssetHandler::RegisterInterface(new Assets::IXModelSurfs()); diff --git a/src/Components/Modules/AssetHandler.hpp b/src/Components/Modules/AssetHandler.hpp index de41dfd9..117e25f0 100644 --- a/src/Components/Modules/AssetHandler.hpp +++ b/src/Components/Modules/AssetHandler.hpp @@ -77,6 +77,7 @@ namespace Components #include "AssetInterfaces\IPhysPreset.hpp" #include "AssetInterfaces\IXAnimParts.hpp" #include "AssetInterfaces\IFxEffectDef.hpp" +#include "AssetInterfaces\ILoadedSound.hpp" #include "AssetInterfaces\IPhysCollmap.hpp" #include "AssetInterfaces\IStringTable.hpp" #include "AssetInterfaces\IXModelSurfs.hpp" diff --git a/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp b/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp new file mode 100644 index 00000000..561dcfdf --- /dev/null +++ b/src/Components/Modules/AssetInterfaces/ILoadedSound.cpp @@ -0,0 +1,45 @@ +#include + +namespace Assets +{ + void ILoadedSound::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) + { + AssertSize(Game::LoadedSound, 44); + + Utils::Stream* buffer = builder->getBuffer(); + Game::LoadedSound* asset = header.sound; + Game::LoadedSound* dest = buffer->dest(); + buffer->save(asset); + + buffer->pushBlock(Game::XFILE_BLOCK_VIRTUAL); + + if (asset->name) + { + buffer->saveString(builder->getAssetName(this->getType(), asset->name)); + Utils::Stream::ClearPointer(&dest->name); + } + + { + buffer->pushBlock(Game::XFILE_BLOCK_TEMP); + + if (asset->mssSound.data) + { + if (builder->hasPointer(asset->mssSound.data)) + { + dest->mssSound.data = builder->getPointer(asset->mssSound.data); + } + else + { + builder->storePointer(asset->mssSound.data); + + buffer->saveArray(asset->mssSound.data, asset->mssSound.size); + Utils::Stream::ClearPointer(&dest->mssSound.data); + } + } + + buffer->popBlock(); + } + + buffer->popBlock(); + } +} diff --git a/src/Components/Modules/AssetInterfaces/ILoadedSound.hpp b/src/Components/Modules/AssetInterfaces/ILoadedSound.hpp new file mode 100644 index 00000000..fd5dd0e6 --- /dev/null +++ b/src/Components/Modules/AssetInterfaces/ILoadedSound.hpp @@ -0,0 +1,10 @@ +namespace Assets +{ + class ILoadedSound : public Components::AssetHandler::IAsset + { + public: + virtual Game::XAssetType getType() override { return Game::XAssetType::ASSET_TYPE_LOADED_SOUND; }; + + virtual void save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override; + }; +} diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index a3efe22d..6627320d 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -514,6 +514,9 @@ namespace Components // Don't create default assets Utils::Hook::Set(0x407BAA, 0xEB); + // Don't load sounds + Utils::Hook::Set(0x334D41, 0xC3); + // Don't display errors when assets are missing (we might manually build those) Utils::Hook::Nop(0x5BB3F2, 5); Utils::Hook::Nop(0x5BB422, 5); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index cc0f88b7..b24ad71e 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -1215,14 +1215,26 @@ namespace Game char * compressedData; }; -#pragma pack(push, 4) struct SndCurve { const char *filename; unsigned __int16 knotCount; vec2_t knots[16]; }; -#pragma pack(pop) + + struct MssSound + { + char unknown1[8]; + int size; + char unknown2[22]; + char *data; // size = soundSize + }; + + struct LoadedSound + { + const char *name; + MssSound mssSound; + }; struct FontEntry { @@ -2898,6 +2910,7 @@ namespace Game VehicleDef* vehicle; GfxWorld* gfxMap; SndCurve* sndCurve; + LoadedSound* sound; }; struct XAsset