diff --git a/src/ObjWriting/Dumping/AbstractAssetDumper.h b/src/ObjWriting/Dumping/AbstractAssetDumper.h index 6f001640..a18b5e6f 100644 --- a/src/ObjWriting/Dumping/AbstractAssetDumper.h +++ b/src/ObjWriting/Dumping/AbstractAssetDumper.h @@ -2,10 +2,6 @@ #include "IAssetDumper.h" -#include -#include -#include - template class AbstractAssetDumper : public IAssetDumper { @@ -15,77 +11,19 @@ protected: return true; } - virtual bool CanDumpAsRaw() - { - return false; - } - - virtual bool CanDumpAsGdtEntry() - { - return false; - } - - virtual std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) - { - return asset->m_name; - } - - virtual void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) - { - - } - - virtual GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) - { - return GdtEntry(); - } + virtual void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) = 0; public: void DumpPool(AssetDumpingContext& context, AssetPool* pool) override { - if(context.m_gdt && CanDumpAsGdtEntry()) + for (auto assetInfo : *pool) { - for (auto assetInfo : *pool) + if (assetInfo->m_name[0] == ',' || !ShouldDump(assetInfo)) { - if (assetInfo->m_name[0] == ',' - || !ShouldDump(assetInfo)) - { - continue; - } - - auto entry = DumpGdtEntry(context, assetInfo); - context.m_gdt->WriteEntry(entry); + continue; } - } - else if(CanDumpAsRaw()) - { - for (auto assetInfo : *pool) - { - if (assetInfo->m_name[0] == ',' - || !ShouldDump(assetInfo)) - { - continue; - } - std::filesystem::path assetFilePath(context.m_base_path); - assetFilePath.append(GetFileNameForAsset(context.m_zone, assetInfo)); - - auto assetFileFolder(assetFilePath); - assetFileFolder.replace_filename(""); - create_directories(assetFileFolder); - - std::ofstream file(assetFilePath, std::fstream::out | std::fstream::binary); - if (file.is_open()) - { - DumpRaw(context, assetInfo, file); - - file.close(); - } - else - { - std::cout << "Failed to open file '" << assetFilePath.string() << "' to dump asset '" << assetInfo->m_name.c_str() << "'\n"; - } - } + DumpAsset(context, assetInfo); } } }; diff --git a/src/ObjWriting/Dumping/AssetDumpingContext.cpp b/src/ObjWriting/Dumping/AssetDumpingContext.cpp index 723ffcbb..9d6bfd1c 100644 --- a/src/ObjWriting/Dumping/AssetDumpingContext.cpp +++ b/src/ObjWriting/Dumping/AssetDumpingContext.cpp @@ -1,6 +1,29 @@ #include "AssetDumpingContext.h" +#include +#include + AssetDumpingContext::AssetDumpingContext() : m_zone(nullptr) { } + +std::unique_ptr AssetDumpingContext::OpenAssetFile(const std::string& fileName) const +{ + std::filesystem::path assetFilePath(m_base_path); + assetFilePath.append(fileName); + + auto assetFileFolder(assetFilePath); + assetFileFolder.replace_filename(""); + create_directories(assetFileFolder); + + auto file = std::make_unique(assetFilePath, std::fstream::out | std::fstream::binary); + + if (!file->is_open()) + { + std::cout << "Failed to open file '" << assetFilePath.string() << "' to dump asset '" << fileName << "'\n"; + return nullptr; + } + + return std::move(file); +} diff --git a/src/ObjWriting/Dumping/AssetDumpingContext.h b/src/ObjWriting/Dumping/AssetDumpingContext.h index 27c5bd48..f1218446 100644 --- a/src/ObjWriting/Dumping/AssetDumpingContext.h +++ b/src/ObjWriting/Dumping/AssetDumpingContext.h @@ -1,7 +1,10 @@ #pragma once #include +#include +#include +#include "Utils/ClassUtils.h" #include "Obj/Gdt/GdtStream.h" #include "Zone/Zone.h" @@ -13,4 +16,6 @@ public: std::unique_ptr m_gdt; AssetDumpingContext(); + + _NODISCARD std::unique_ptr OpenAssetFile(const std::string& fileName) const; }; diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperGfxImage.cpp b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperGfxImage.cpp index 359f1203..2fc3b470 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperGfxImage.cpp +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperGfxImage.cpp @@ -31,12 +31,7 @@ bool AssetDumperGfxImage::ShouldDump(XAssetInfo* asset) return image->cardMemory.platform[0] > 0; } -bool AssetDumperGfxImage::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperGfxImage::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) +std::string AssetDumperGfxImage::GetAssetFileName(XAssetInfo* asset) const { std::string cleanAssetName = asset->m_name; for (auto& c : cleanAssetName) @@ -55,8 +50,14 @@ std::string AssetDumperGfxImage::GetFileNameForAsset(Zone* zone, XAssetInfoGetFileExtension(); } -void AssetDumperGfxImage::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* image = asset->Asset(); + const auto assetFile = context.OpenAssetFile(GetAssetFileName(asset)); + + if (!assetFile) + return; + + auto& stream = *assetFile; m_writer->DumpImage(stream, image->texture.texture); } diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperGfxImage.h b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperGfxImage.h index af62f01c..0c42f400 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperGfxImage.h +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperGfxImage.h @@ -12,11 +12,11 @@ namespace IW3 { std::unique_ptr m_writer; + std::string GetAssetFileName(XAssetInfo* asset) const; + protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; public: AssetDumperGfxImage(); diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLoadedSound.cpp b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLoadedSound.cpp index b0e33cab..52c00d83 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLoadedSound.cpp +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLoadedSound.cpp @@ -9,16 +9,6 @@ bool AssetDumperLoadedSound::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperLoadedSound::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperLoadedSound::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "sound/" + asset->m_name; -} - void AssetDumperLoadedSound::DumpWavPcm(AssetDumpingContext& context, const LoadedSound* asset, std::ostream& stream) { const auto riffMasterChunkSize = sizeof(WAV_CHUNK_ID_RIFF) @@ -60,9 +50,15 @@ void AssetDumperLoadedSound::DumpWavPcm(AssetDumpingContext& context, const Load stream.write(asset->sound.data, asset->sound.info.data_len); } -void AssetDumperLoadedSound::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperLoadedSound::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* loadedSound = asset->Asset(); + const auto assetFile = context.OpenAssetFile("sound/" + asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; switch (static_cast(loadedSound->sound.info.format)) { case WavFormat::PCM: diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLoadedSound.h b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLoadedSound.h index 5e36aaaf..91ed3f7e 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLoadedSound.h +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLoadedSound.h @@ -8,10 +8,9 @@ namespace IW3 class AssetDumperLoadedSound final : public AbstractAssetDumper { static void DumpWavPcm(AssetDumpingContext& context, const LoadedSound* asset, std::ostream& stream); + protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLocalizeEntry.cpp b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLocalizeEntry.cpp index d6ccf34d..65c951d7 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLocalizeEntry.cpp +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperLocalizeEntry.cpp @@ -1,13 +1,11 @@ #include "AssetDumperLocalizeEntry.h" -#include -#include +#include #include "Localize/LocalizeCommon.h" #include "Dumping/Localize/StringFileDumper.h" using namespace IW3; -namespace fs = std::filesystem; void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool* pool) { @@ -15,20 +13,14 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< return; const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language); - fs::path stringsPath(context.m_base_path); - stringsPath.append(language); - stringsPath.append("localizedstrings"); - create_directories(stringsPath); + std::ostringstream ss; + ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str"; + const auto assetFile = context.OpenAssetFile(ss.str()); - auto stringFilePath(stringsPath); - stringFilePath.append(context.m_zone->m_name + ".str"); - - std::ofstream stringFile(stringFilePath, std::fstream::out | std::ofstream::binary); - - if (stringFile.is_open()) + if (assetFile) { - StringFileDumper stringFileDumper(context.m_zone, stringFile); + StringFileDumper stringFileDumper(context.m_zone, *assetFile); stringFileDumper.SetLanguageName(language); @@ -43,8 +35,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< } stringFileDumper.Finalize(); - - stringFile.close(); } else { diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperMapEnts.cpp b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperMapEnts.cpp index db019471..9e9cd441 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperMapEnts.cpp +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperMapEnts.cpp @@ -7,18 +7,14 @@ bool AssetDumperMapEnts::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperMapEnts::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperMapEnts::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name + ".ents"; -} - -void AssetDumperMapEnts::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperMapEnts::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* mapEnts = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name + ".ents"); + + if (!assetFile) + return; + + auto& stream = *assetFile; stream.write(mapEnts->entityString, mapEnts->numEntityChars); } diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperMapEnts.h b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperMapEnts.h index 8c38c37a..36da6a8e 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperMapEnts.h +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperMapEnts.h @@ -9,8 +9,6 @@ namespace IW3 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperRawFile.cpp b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperRawFile.cpp index 12a35ae0..bd9b7ecd 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperRawFile.cpp +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperRawFile.cpp @@ -7,18 +7,14 @@ bool AssetDumperRawFile::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperRawFile::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperRawFile::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperRawFile::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* rawFile = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; stream.write(rawFile->buffer, rawFile->len); } diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperRawFile.h b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperRawFile.h index 537bfe68..7c79a423 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperRawFile.h +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperRawFile.h @@ -9,8 +9,6 @@ namespace IW3 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperStringTable.cpp b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperStringTable.cpp index 1b12b56f..26c8d514 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperStringTable.cpp +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperStringTable.cpp @@ -9,20 +9,15 @@ bool AssetDumperStringTable::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperStringTable::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperStringTable::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperStringTable::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperStringTable::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* stringTable = asset->Asset(); - CsvOutputStream csv(stream); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + CsvOutputStream csv(*assetFile); for (auto row = 0; row < stringTable->rowCount; row++) { diff --git a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperStringTable.h b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperStringTable.h index 4dd9c69e..d4cb9299 100644 --- a/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperStringTable.h +++ b/src/ObjWriting/Game/IW3/AssetDumpers/AssetDumperStringTable.h @@ -9,9 +9,6 @@ namespace IW3 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperAddonMapEnts.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperAddonMapEnts.cpp index 4e64366a..58c745c5 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperAddonMapEnts.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperAddonMapEnts.cpp @@ -10,18 +10,15 @@ bool AssetDumperAddonMapEnts::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperAddonMapEnts::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperAddonMapEnts::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperAddonMapEnts::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperAddonMapEnts::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* addonMapEnts = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; + stream.write(addonMapEnts->entityString, std::max(addonMapEnts->numEntityChars - 1, 0)); } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperAddonMapEnts.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperAddonMapEnts.h index b6cc6729..94da070e 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperAddonMapEnts.h +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperAddonMapEnts.h @@ -9,8 +9,6 @@ namespace IW4 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperGfxImage.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperGfxImage.cpp index b5ce9d19..916eaca2 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperGfxImage.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperGfxImage.cpp @@ -31,12 +31,7 @@ bool AssetDumperGfxImage::ShouldDump(XAssetInfo* asset) return image->cardMemory.platform[0] > 0; } -bool AssetDumperGfxImage::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperGfxImage::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) +std::string AssetDumperGfxImage::GetAssetFileName(XAssetInfo* asset) const { std::string cleanAssetName = asset->m_name; for (auto& c : cleanAssetName) @@ -55,8 +50,14 @@ std::string AssetDumperGfxImage::GetFileNameForAsset(Zone* zone, XAssetInfoGetFileExtension(); } -void AssetDumperGfxImage::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* image = asset->Asset(); + const auto assetFile = context.OpenAssetFile(GetAssetFileName(asset)); + + if (!assetFile) + return; + + auto& stream = *assetFile; m_writer->DumpImage(stream, image->texture.texture); } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperGfxImage.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperGfxImage.h index 1bd2019a..5d04301d 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperGfxImage.h +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperGfxImage.h @@ -12,11 +12,11 @@ namespace IW4 { std::unique_ptr m_writer; + std::string GetAssetFileName(XAssetInfo* asset) const; + protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; public: AssetDumperGfxImage(); diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLoadedSound.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLoadedSound.cpp index 80f5097e..f7c97209 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLoadedSound.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLoadedSound.cpp @@ -9,16 +9,6 @@ bool AssetDumperLoadedSound::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperLoadedSound::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperLoadedSound::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "sound/" + asset->m_name; -} - void AssetDumperLoadedSound::DumpWavPcm(AssetDumpingContext& context, const LoadedSound* asset, std::ostream& stream) { const auto riffMasterChunkSize = sizeof(WAV_CHUNK_ID_RIFF) @@ -60,9 +50,15 @@ void AssetDumperLoadedSound::DumpWavPcm(AssetDumpingContext& context, const Load stream.write(asset->sound.data, asset->sound.info.data_len); } -void AssetDumperLoadedSound::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperLoadedSound::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* loadedSound = asset->Asset(); + const auto assetFile = context.OpenAssetFile("sound/" + asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; switch (static_cast(loadedSound->sound.info.format)) { case WavFormat::PCM: diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLoadedSound.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLoadedSound.h index 7f614889..915d5402 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLoadedSound.h +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLoadedSound.h @@ -10,8 +10,6 @@ namespace IW4 static void DumpWavPcm(AssetDumpingContext& context, const LoadedSound* asset, std::ostream& stream); protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLocalizeEntry.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLocalizeEntry.cpp index af3e26c3..91dca90c 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLocalizeEntry.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperLocalizeEntry.cpp @@ -1,13 +1,11 @@ #include "AssetDumperLocalizeEntry.h" -#include -#include +#include #include "Localize/LocalizeCommon.h" #include "Dumping/Localize/StringFileDumper.h" using namespace IW4; -namespace fs = std::filesystem; void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool* pool) { @@ -15,20 +13,14 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< return; const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language); - fs::path stringsPath(context.m_base_path); - stringsPath.append(language); - stringsPath.append("localizedstrings"); - create_directories(stringsPath); + std::ostringstream ss; + ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str"; + const auto assetFile = context.OpenAssetFile(ss.str()); - auto stringFilePath(stringsPath); - stringFilePath.append(context.m_zone->m_name + ".str"); - - std::ofstream stringFile(stringFilePath, std::fstream::out | std::ofstream::binary); - - if (stringFile.is_open()) + if (assetFile) { - StringFileDumper stringFileDumper(context.m_zone, stringFile); + StringFileDumper stringFileDumper(context.m_zone, *assetFile); stringFileDumper.SetLanguageName(language); @@ -43,8 +35,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< } stringFileDumper.Finalize(); - - stringFile.close(); } else { diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperRawFile.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperRawFile.cpp index e1acba04..507d2cfa 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperRawFile.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperRawFile.cpp @@ -10,19 +10,15 @@ bool AssetDumperRawFile::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperRawFile::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperRawFile::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperRawFile::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* rawFile = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; if (rawFile->compressedLen > 0) { z_stream_s zs{}; diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperRawFile.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperRawFile.h index ffc6a713..66a2c000 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperRawFile.h +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperRawFile.h @@ -9,8 +9,6 @@ namespace IW4 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperStringTable.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperStringTable.cpp index a81504a9..cadfd739 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperStringTable.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperStringTable.cpp @@ -9,20 +9,15 @@ bool AssetDumperStringTable::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperStringTable::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperStringTable::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperStringTable::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperStringTable::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* stringTable = asset->Asset(); - CsvOutputStream csv(stream); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + CsvOutputStream csv(*assetFile); for (auto row = 0; row < stringTable->rowCount; row++) { diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperStringTable.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperStringTable.h index a717bc18..0194b747 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperStringTable.h +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperStringTable.h @@ -9,9 +9,6 @@ namespace IW4 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVehicle.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVehicle.cpp index fe59e8b5..26f79a80 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVehicle.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVehicle.cpp @@ -11,149 +11,149 @@ using namespace IW4; cspField_t AssetDumperVehicle::vehicle_fields[] { - { "type", offsetof(VehicleDef, type), VFT_TYPE }, - { "useHintString", offsetof(VehicleDef, useHintString), CSPFT_STRING }, - { "health", offsetof(VehicleDef, health), CSPFT_INT }, - { "quadBarrel", offsetof(VehicleDef, quadBarrel), CSPFT_QBOOLEAN }, - { "texureScrollScale", offsetof(VehicleDef, texScrollScale), CSPFT_FLOAT }, - { "topSpeed", offsetof(VehicleDef, topSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "accel", offsetof(VehicleDef, accel), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "rotRate", offsetof(VehicleDef, rotRate), CSPFT_FLOAT }, - { "rotAccel", offsetof(VehicleDef, rotAccel), CSPFT_FLOAT }, - { "maxBodyPitch", offsetof(VehicleDef, maxBodyPitch), CSPFT_FLOAT }, - { "maxBodyRoll", offsetof(VehicleDef, maxBodyRoll), CSPFT_FLOAT }, - { "fakeBodyAccelPitch", offsetof(VehicleDef, fakeBodyAccelPitch), CSPFT_FLOAT }, - { "fakeBodyAccelRoll", offsetof(VehicleDef, fakeBodyAccelRoll), CSPFT_FLOAT }, - { "fakeBodyVelPitch", offsetof(VehicleDef, fakeBodyVelPitch), CSPFT_FLOAT }, - { "fakeBodyVelRoll", offsetof(VehicleDef, fakeBodyVelRoll), CSPFT_FLOAT }, - { "fakeBodySideVelPitch", offsetof(VehicleDef, fakeBodySideVelPitch), CSPFT_FLOAT }, - { "fakeBodyPitchStrength", offsetof(VehicleDef, fakeBodyPitchStrength), CSPFT_FLOAT }, - { "fakeBodyRollStrength", offsetof(VehicleDef, fakeBodyRollStrength), CSPFT_FLOAT }, - { "fakeBodyPitchDampening", offsetof(VehicleDef, fakeBodyPitchDampening), CSPFT_FLOAT }, - { "fakeBodyRollDampening", offsetof(VehicleDef, fakeBodyRollDampening), CSPFT_FLOAT }, - { "fakeBodyBoatRockingAmplitude", offsetof(VehicleDef, fakeBodyBoatRockingAmplitude), CSPFT_FLOAT }, - { "fakeBodyBoatRockingPeriod", offsetof(VehicleDef, fakeBodyBoatRockingPeriod), CSPFT_FLOAT }, - { "fakeBodyBoatRockingRotationPeriod", offsetof(VehicleDef, fakeBodyBoatRockingRotationPeriod), CSPFT_FLOAT }, - { "fakeBodyBoatRockingFadeoutSpeed", offsetof(VehicleDef, fakeBodyBoatRockingFadeoutSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "boatBouncingMinForce", offsetof(VehicleDef, boatBouncingMinForce), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "boatBouncingMaxForce", offsetof(VehicleDef, boatBouncingMaxForce), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "boatBouncingRate", offsetof(VehicleDef, boatBouncingRate), CSPFT_FLOAT }, - { "boatBouncingFadeinSpeed", offsetof(VehicleDef, boatBouncingFadeinSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "boatBouncingFadeoutSteeringAngle", offsetof(VehicleDef, boatBouncingFadeoutSteeringAngle), CSPFT_FLOAT }, - { "collisionDamage", offsetof(VehicleDef, collisionDamage), CSPFT_FLOAT }, - { "collisionSpeed", offsetof(VehicleDef, collisionSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "killcamZDist", offsetof(VehicleDef, killcamOffset[0]), CSPFT_FLOAT }, - { "killcamBackDist", offsetof(VehicleDef, killcamOffset[1]), CSPFT_FLOAT }, - { "killcamUpDist", offsetof(VehicleDef, killcamOffset[2]), CSPFT_FLOAT }, - { "playerProtected", offsetof(VehicleDef, playerProtected), CSPFT_QBOOLEAN }, - { "bulletDamage", offsetof(VehicleDef, bulletDamage), CSPFT_QBOOLEAN }, - { "armorPiercingDamage", offsetof(VehicleDef, armorPiercingDamage), CSPFT_QBOOLEAN }, - { "grenadeDamage", offsetof(VehicleDef, grenadeDamage), CSPFT_QBOOLEAN }, - { "projectileDamage", offsetof(VehicleDef, projectileDamage), CSPFT_QBOOLEAN }, - { "projectileSplashDamage", offsetof(VehicleDef, projectileSplashDamage), CSPFT_QBOOLEAN }, - { "heavyExplosiveDamage", offsetof(VehicleDef, heavyExplosiveDamage), CSPFT_QBOOLEAN }, - { "physicsEnabled", offsetof(VehicleDef, vehPhysDef.physicsEnabled), CSPFT_QBOOLEAN }, - { "physicsPreset", offsetof(VehicleDef, vehPhysDef.physPresetName), CSPFT_STRING }, - { "accelerationGraph", offsetof(VehicleDef, vehPhysDef.accelGraphName), CSPFT_STRING }, - { "steeringAxle", offsetof(VehicleDef, vehPhysDef.steeringAxle), VFT_AXLE_STEERING }, - { "powerAxle", offsetof(VehicleDef, vehPhysDef.powerAxle), VFT_AXLE_POWER }, - { "brakingAxle", offsetof(VehicleDef, vehPhysDef.brakingAxle), VFT_AXLE_BRAKING }, - { "reverseSpeed", offsetof(VehicleDef, vehPhysDef.reverseSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "maxVelocity", offsetof(VehicleDef, vehPhysDef.maxVelocity), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "maxPitch", offsetof(VehicleDef, vehPhysDef.maxPitch), CSPFT_FLOAT }, - { "maxRoll", offsetof(VehicleDef, vehPhysDef.maxRoll), CSPFT_FLOAT }, - { "suspensionTravelRear", offsetof(VehicleDef, vehPhysDef.suspensionTravelRear), CSPFT_FLOAT }, - { "suspensionStrengthFront", offsetof(VehicleDef, vehPhysDef.suspensionStrengthFront), CSPFT_FLOAT }, - { "suspensionDampingFront", offsetof(VehicleDef, vehPhysDef.suspensionDampingFront), CSPFT_FLOAT }, - { "suspensionStrengthRear", offsetof(VehicleDef, vehPhysDef.suspensionStrengthRear), CSPFT_FLOAT }, - { "suspensionDampingRear", offsetof(VehicleDef, vehPhysDef.suspensionDampingRear), CSPFT_FLOAT }, - { "frictionBraking", offsetof(VehicleDef, vehPhysDef.frictionBraking), CSPFT_FLOAT }, - { "frictionCoasting", offsetof(VehicleDef, vehPhysDef.frictionCoasting), CSPFT_FLOAT }, - { "frictionTopSpeed", offsetof(VehicleDef, vehPhysDef.frictionTopSpeed), CSPFT_FLOAT }, - { "frictionSide", offsetof(VehicleDef, vehPhysDef.frictionSide), CSPFT_FLOAT }, - { "frictionSideRear", offsetof(VehicleDef, vehPhysDef.frictionSideRear), CSPFT_FLOAT }, - { "velocityDependentSlip", offsetof(VehicleDef, vehPhysDef.velocityDependentSlip), CSPFT_FLOAT }, - { "rollStability", offsetof(VehicleDef, vehPhysDef.rollStability), CSPFT_FLOAT }, - { "rollResistance", offsetof(VehicleDef, vehPhysDef.rollResistance), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "pitchResistance", offsetof(VehicleDef, vehPhysDef.pitchResistance), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "yawResistance", offsetof(VehicleDef, vehPhysDef.yawResistance), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "uprightStrengthPitch", offsetof(VehicleDef, vehPhysDef.uprightStrengthPitch), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "uprightStrengthRoll", offsetof(VehicleDef, vehPhysDef.uprightStrengthRoll), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "targetAirPitch", offsetof(VehicleDef, vehPhysDef.targetAirPitch), CSPFT_FLOAT }, - { "airYawTorque", offsetof(VehicleDef, vehPhysDef.airYawTorque), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "airPitchTorque", offsetof(VehicleDef, vehPhysDef.airPitchTorque), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "minimumMomentumForCollision", offsetof(VehicleDef, vehPhysDef.minimumMomentumForCollision), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "collisionLaunchForceScale", offsetof(VehicleDef, vehPhysDef.collisionLaunchForceScale), CSPFT_FLOAT }, - { "wreckedMassScale", offsetof(VehicleDef, vehPhysDef.wreckedMassScale), CSPFT_FLOAT }, - { "wreckedBodyFriction", offsetof(VehicleDef, vehPhysDef.wreckedBodyFriction), CSPFT_FLOAT }, - { "minimumJoltForNotify", offsetof(VehicleDef, vehPhysDef.minimumJoltForNotify), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "slipThresholdFront", offsetof(VehicleDef, vehPhysDef.slipThresholdFront), CSPFT_FLOAT }, - { "slipThresholdRear", offsetof(VehicleDef, vehPhysDef.slipThresholdRear), CSPFT_FLOAT }, - { "slipFricScaleFront", offsetof(VehicleDef, vehPhysDef.slipFricScaleFront), CSPFT_FLOAT }, - { "slipFricScaleRear", offsetof(VehicleDef, vehPhysDef.slipFricScaleRear), CSPFT_FLOAT }, - { "slipFricRateFront", offsetof(VehicleDef, vehPhysDef.slipFricRateFront), CSPFT_FLOAT }, - { "slipFricRateRear", offsetof(VehicleDef, vehPhysDef.slipFricRateRear), CSPFT_FLOAT }, - { "slipYawTorque", offsetof(VehicleDef, vehPhysDef.slipYawTorque), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "boostDuration", offsetof(VehicleDef, boostDuration), CSPFT_FLOAT }, - { "boostRechargeTime", offsetof(VehicleDef, boostRechargeTime), CSPFT_FLOAT }, - { "boostAcceleration", offsetof(VehicleDef, boostAcceleration), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "suspensionTravel", offsetof(VehicleDef, suspensionTravel), CSPFT_FLOAT }, - { "maxSteeringAngle", offsetof(VehicleDef, maxSteeringAngle), CSPFT_FLOAT }, - { "steeringLerp", offsetof(VehicleDef, steeringLerp), CSPFT_FLOAT }, - { "minSteeringScale", offsetof(VehicleDef, minSteeringScale), CSPFT_FLOAT }, - { "minSteeringSpeed", offsetof(VehicleDef, minSteeringSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "camLookEnabled", offsetof(VehicleDef, camLookEnabled), CSPFT_QBOOLEAN }, - { "camLerp", offsetof(VehicleDef, camLerp), CSPFT_FLOAT }, - { "camPitchInfluence", offsetof(VehicleDef, camPitchInfluence), CSPFT_FLOAT }, - { "camRollInfluence", offsetof(VehicleDef, camRollInfluence), CSPFT_FLOAT }, - { "camFovIncrease", offsetof(VehicleDef, camFovIncrease), CSPFT_FLOAT }, - { "camFovOffset", offsetof(VehicleDef, camFovOffset), CSPFT_FLOAT }, - { "camFovSpeed", offsetof(VehicleDef, camFovSpeed), CSPFT_FLOAT }, - { "turretWeaponName", offsetof(VehicleDef, turretWeaponName), CSPFT_STRING }, - { "turretHorizSpanLeft", offsetof(VehicleDef, turretHorizSpanLeft), CSPFT_FLOAT }, - { "turretHorizSpanRight", offsetof(VehicleDef, turretHorizSpanRight), CSPFT_FLOAT }, - { "turretVertSpanUp", offsetof(VehicleDef, turretVertSpanUp), CSPFT_FLOAT }, - { "turretVertSpanDown", offsetof(VehicleDef, turretVertSpanDown), CSPFT_FLOAT }, - { "turretRotRate", offsetof(VehicleDef, turretRotRate), CSPFT_FLOAT }, - { "turretSpinSnd", offsetof(VehicleDef, turretSpinSnd), CSPFT_SOUND }, - { "turretStopSnd", offsetof(VehicleDef, turretStopSnd), CSPFT_SOUND }, - { "trophyEnabled", offsetof(VehicleDef, trophyEnabled), CSPFT_QBOOLEAN }, - { "trophyRadius", offsetof(VehicleDef, trophyRadius), CSPFT_FLOAT }, - { "trophyInactiveRadius", offsetof(VehicleDef, trophyInactiveRadius), CSPFT_FLOAT }, - { "trophyAmmoCount", offsetof(VehicleDef, trophyAmmoCount), CSPFT_INT }, - { "trophyReloadTime", offsetof(VehicleDef, trophyReloadTime), CSPFT_FLOAT }, - { "trophyTags", offsetof(VehicleDef, trophyTags), VFT_TROPHY_TAGS }, - { "compassFriendlyIcon", offsetof(VehicleDef, compassFriendlyIcon), CSPFT_MATERIAL }, - { "compassEnemyIcon", offsetof(VehicleDef, compassEnemyIcon), CSPFT_MATERIAL }, - { "compassIconWidth", offsetof(VehicleDef, compassIconWidth), CSPFT_INT }, - { "compassIconHeight", offsetof(VehicleDef, compassIconHeight), CSPFT_INT }, - { "lowIdleSnd", offsetof(VehicleDef, idleLowSnd), CSPFT_SOUND }, - { "highIdleSnd", offsetof(VehicleDef, idleHighSnd), CSPFT_SOUND }, - { "lowEngineSnd", offsetof(VehicleDef, engineLowSnd), CSPFT_SOUND }, - { "highEngineSnd", offsetof(VehicleDef, engineHighSnd), CSPFT_SOUND }, - { "engineSndSpeed", offsetof(VehicleDef, engineSndSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "engineStartUpSnd", offsetof(VehicleDef, engineStartUpSnd), CSPFT_SOUND }, - { "engineStartUpLength", offsetof(VehicleDef, engineStartUpLength), CSPFT_MILLISECONDS }, - { "engineShutdownSnd", offsetof(VehicleDef, engineShutdownSnd), CSPFT_SOUND }, - { "engineIdleSnd", offsetof(VehicleDef, engineIdleSnd), CSPFT_SOUND }, - { "engineSustainSnd", offsetof(VehicleDef, engineSustainSnd), CSPFT_SOUND }, - { "engineRampUpSnd", offsetof(VehicleDef, engineRampUpSnd), CSPFT_SOUND }, - { "engineRampUpLength", offsetof(VehicleDef, engineRampUpLength), CSPFT_MILLISECONDS }, - { "engineRampDownSnd", offsetof(VehicleDef, engineRampDownSnd), CSPFT_SOUND }, - { "engineRampDownLength", offsetof(VehicleDef, engineRampDownLength), CSPFT_MILLISECONDS }, - { "suspensionSoftSnd", offsetof(VehicleDef, suspensionSoftSnd), CSPFT_SOUND }, - { "suspensionSoftCompression", offsetof(VehicleDef, suspensionSoftCompression), CSPFT_FLOAT }, - { "suspensionHardSnd", offsetof(VehicleDef, suspensionHardSnd), CSPFT_SOUND }, - { "suspensionHardCompression", offsetof(VehicleDef, suspensionHardCompression), CSPFT_FLOAT }, - { "collisionSnd", offsetof(VehicleDef, collisionSnd), CSPFT_SOUND }, - { "collisionBlendSpeed", offsetof(VehicleDef, collisionBlendSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "speedSnd", offsetof(VehicleDef, speedSnd), CSPFT_SOUND }, - { "speedSndBlendSpeed", offsetof(VehicleDef, speedSndBlendSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "surfaceSndPrefix", offsetof(VehicleDef, surfaceSndPrefix), CSPFT_STRING }, - { "surfaceSndBlendSpeed", offsetof(VehicleDef, surfaceSndBlendSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "slideVolume", offsetof(VehicleDef, slideVolume), CSPFT_FLOAT }, - { "slideBlendSpeed", offsetof(VehicleDef, slideBlendSpeed), CSPFT_MPH_TO_INCHES_PER_SEC }, - { "inAirPitch", offsetof(VehicleDef, inAirPitch), CSPFT_FLOAT }, + {"type", offsetof(VehicleDef, type), VFT_TYPE}, + {"useHintString", offsetof(VehicleDef, useHintString), CSPFT_STRING}, + {"health", offsetof(VehicleDef, health), CSPFT_INT}, + {"quadBarrel", offsetof(VehicleDef, quadBarrel), CSPFT_QBOOLEAN}, + {"texureScrollScale", offsetof(VehicleDef, texScrollScale), CSPFT_FLOAT}, + {"topSpeed", offsetof(VehicleDef, topSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"accel", offsetof(VehicleDef, accel), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"rotRate", offsetof(VehicleDef, rotRate), CSPFT_FLOAT}, + {"rotAccel", offsetof(VehicleDef, rotAccel), CSPFT_FLOAT}, + {"maxBodyPitch", offsetof(VehicleDef, maxBodyPitch), CSPFT_FLOAT}, + {"maxBodyRoll", offsetof(VehicleDef, maxBodyRoll), CSPFT_FLOAT}, + {"fakeBodyAccelPitch", offsetof(VehicleDef, fakeBodyAccelPitch), CSPFT_FLOAT}, + {"fakeBodyAccelRoll", offsetof(VehicleDef, fakeBodyAccelRoll), CSPFT_FLOAT}, + {"fakeBodyVelPitch", offsetof(VehicleDef, fakeBodyVelPitch), CSPFT_FLOAT}, + {"fakeBodyVelRoll", offsetof(VehicleDef, fakeBodyVelRoll), CSPFT_FLOAT}, + {"fakeBodySideVelPitch", offsetof(VehicleDef, fakeBodySideVelPitch), CSPFT_FLOAT}, + {"fakeBodyPitchStrength", offsetof(VehicleDef, fakeBodyPitchStrength), CSPFT_FLOAT}, + {"fakeBodyRollStrength", offsetof(VehicleDef, fakeBodyRollStrength), CSPFT_FLOAT}, + {"fakeBodyPitchDampening", offsetof(VehicleDef, fakeBodyPitchDampening), CSPFT_FLOAT}, + {"fakeBodyRollDampening", offsetof(VehicleDef, fakeBodyRollDampening), CSPFT_FLOAT}, + {"fakeBodyBoatRockingAmplitude", offsetof(VehicleDef, fakeBodyBoatRockingAmplitude), CSPFT_FLOAT}, + {"fakeBodyBoatRockingPeriod", offsetof(VehicleDef, fakeBodyBoatRockingPeriod), CSPFT_FLOAT}, + {"fakeBodyBoatRockingRotationPeriod", offsetof(VehicleDef, fakeBodyBoatRockingRotationPeriod), CSPFT_FLOAT}, + {"fakeBodyBoatRockingFadeoutSpeed", offsetof(VehicleDef, fakeBodyBoatRockingFadeoutSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"boatBouncingMinForce", offsetof(VehicleDef, boatBouncingMinForce), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"boatBouncingMaxForce", offsetof(VehicleDef, boatBouncingMaxForce), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"boatBouncingRate", offsetof(VehicleDef, boatBouncingRate), CSPFT_FLOAT}, + {"boatBouncingFadeinSpeed", offsetof(VehicleDef, boatBouncingFadeinSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"boatBouncingFadeoutSteeringAngle", offsetof(VehicleDef, boatBouncingFadeoutSteeringAngle), CSPFT_FLOAT}, + {"collisionDamage", offsetof(VehicleDef, collisionDamage), CSPFT_FLOAT}, + {"collisionSpeed", offsetof(VehicleDef, collisionSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"killcamZDist", offsetof(VehicleDef, killcamOffset[0]), CSPFT_FLOAT}, + {"killcamBackDist", offsetof(VehicleDef, killcamOffset[1]), CSPFT_FLOAT}, + {"killcamUpDist", offsetof(VehicleDef, killcamOffset[2]), CSPFT_FLOAT}, + {"playerProtected", offsetof(VehicleDef, playerProtected), CSPFT_QBOOLEAN}, + {"bulletDamage", offsetof(VehicleDef, bulletDamage), CSPFT_QBOOLEAN}, + {"armorPiercingDamage", offsetof(VehicleDef, armorPiercingDamage), CSPFT_QBOOLEAN}, + {"grenadeDamage", offsetof(VehicleDef, grenadeDamage), CSPFT_QBOOLEAN}, + {"projectileDamage", offsetof(VehicleDef, projectileDamage), CSPFT_QBOOLEAN}, + {"projectileSplashDamage", offsetof(VehicleDef, projectileSplashDamage), CSPFT_QBOOLEAN}, + {"heavyExplosiveDamage", offsetof(VehicleDef, heavyExplosiveDamage), CSPFT_QBOOLEAN}, + {"physicsEnabled", offsetof(VehicleDef, vehPhysDef.physicsEnabled), CSPFT_QBOOLEAN}, + {"physicsPreset", offsetof(VehicleDef, vehPhysDef.physPresetName), CSPFT_STRING}, + {"accelerationGraph", offsetof(VehicleDef, vehPhysDef.accelGraphName), CSPFT_STRING}, + {"steeringAxle", offsetof(VehicleDef, vehPhysDef.steeringAxle), VFT_AXLE_STEERING}, + {"powerAxle", offsetof(VehicleDef, vehPhysDef.powerAxle), VFT_AXLE_POWER}, + {"brakingAxle", offsetof(VehicleDef, vehPhysDef.brakingAxle), VFT_AXLE_BRAKING}, + {"reverseSpeed", offsetof(VehicleDef, vehPhysDef.reverseSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"maxVelocity", offsetof(VehicleDef, vehPhysDef.maxVelocity), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"maxPitch", offsetof(VehicleDef, vehPhysDef.maxPitch), CSPFT_FLOAT}, + {"maxRoll", offsetof(VehicleDef, vehPhysDef.maxRoll), CSPFT_FLOAT}, + {"suspensionTravelRear", offsetof(VehicleDef, vehPhysDef.suspensionTravelRear), CSPFT_FLOAT}, + {"suspensionStrengthFront", offsetof(VehicleDef, vehPhysDef.suspensionStrengthFront), CSPFT_FLOAT}, + {"suspensionDampingFront", offsetof(VehicleDef, vehPhysDef.suspensionDampingFront), CSPFT_FLOAT}, + {"suspensionStrengthRear", offsetof(VehicleDef, vehPhysDef.suspensionStrengthRear), CSPFT_FLOAT}, + {"suspensionDampingRear", offsetof(VehicleDef, vehPhysDef.suspensionDampingRear), CSPFT_FLOAT}, + {"frictionBraking", offsetof(VehicleDef, vehPhysDef.frictionBraking), CSPFT_FLOAT}, + {"frictionCoasting", offsetof(VehicleDef, vehPhysDef.frictionCoasting), CSPFT_FLOAT}, + {"frictionTopSpeed", offsetof(VehicleDef, vehPhysDef.frictionTopSpeed), CSPFT_FLOAT}, + {"frictionSide", offsetof(VehicleDef, vehPhysDef.frictionSide), CSPFT_FLOAT}, + {"frictionSideRear", offsetof(VehicleDef, vehPhysDef.frictionSideRear), CSPFT_FLOAT}, + {"velocityDependentSlip", offsetof(VehicleDef, vehPhysDef.velocityDependentSlip), CSPFT_FLOAT}, + {"rollStability", offsetof(VehicleDef, vehPhysDef.rollStability), CSPFT_FLOAT}, + {"rollResistance", offsetof(VehicleDef, vehPhysDef.rollResistance), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"pitchResistance", offsetof(VehicleDef, vehPhysDef.pitchResistance), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"yawResistance", offsetof(VehicleDef, vehPhysDef.yawResistance), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"uprightStrengthPitch", offsetof(VehicleDef, vehPhysDef.uprightStrengthPitch), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"uprightStrengthRoll", offsetof(VehicleDef, vehPhysDef.uprightStrengthRoll), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"targetAirPitch", offsetof(VehicleDef, vehPhysDef.targetAirPitch), CSPFT_FLOAT}, + {"airYawTorque", offsetof(VehicleDef, vehPhysDef.airYawTorque), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"airPitchTorque", offsetof(VehicleDef, vehPhysDef.airPitchTorque), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"minimumMomentumForCollision", offsetof(VehicleDef, vehPhysDef.minimumMomentumForCollision), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"collisionLaunchForceScale", offsetof(VehicleDef, vehPhysDef.collisionLaunchForceScale), CSPFT_FLOAT}, + {"wreckedMassScale", offsetof(VehicleDef, vehPhysDef.wreckedMassScale), CSPFT_FLOAT}, + {"wreckedBodyFriction", offsetof(VehicleDef, vehPhysDef.wreckedBodyFriction), CSPFT_FLOAT}, + {"minimumJoltForNotify", offsetof(VehicleDef, vehPhysDef.minimumJoltForNotify), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"slipThresholdFront", offsetof(VehicleDef, vehPhysDef.slipThresholdFront), CSPFT_FLOAT}, + {"slipThresholdRear", offsetof(VehicleDef, vehPhysDef.slipThresholdRear), CSPFT_FLOAT}, + {"slipFricScaleFront", offsetof(VehicleDef, vehPhysDef.slipFricScaleFront), CSPFT_FLOAT}, + {"slipFricScaleRear", offsetof(VehicleDef, vehPhysDef.slipFricScaleRear), CSPFT_FLOAT}, + {"slipFricRateFront", offsetof(VehicleDef, vehPhysDef.slipFricRateFront), CSPFT_FLOAT}, + {"slipFricRateRear", offsetof(VehicleDef, vehPhysDef.slipFricRateRear), CSPFT_FLOAT}, + {"slipYawTorque", offsetof(VehicleDef, vehPhysDef.slipYawTorque), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"boostDuration", offsetof(VehicleDef, boostDuration), CSPFT_FLOAT}, + {"boostRechargeTime", offsetof(VehicleDef, boostRechargeTime), CSPFT_FLOAT}, + {"boostAcceleration", offsetof(VehicleDef, boostAcceleration), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"suspensionTravel", offsetof(VehicleDef, suspensionTravel), CSPFT_FLOAT}, + {"maxSteeringAngle", offsetof(VehicleDef, maxSteeringAngle), CSPFT_FLOAT}, + {"steeringLerp", offsetof(VehicleDef, steeringLerp), CSPFT_FLOAT}, + {"minSteeringScale", offsetof(VehicleDef, minSteeringScale), CSPFT_FLOAT}, + {"minSteeringSpeed", offsetof(VehicleDef, minSteeringSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"camLookEnabled", offsetof(VehicleDef, camLookEnabled), CSPFT_QBOOLEAN}, + {"camLerp", offsetof(VehicleDef, camLerp), CSPFT_FLOAT}, + {"camPitchInfluence", offsetof(VehicleDef, camPitchInfluence), CSPFT_FLOAT}, + {"camRollInfluence", offsetof(VehicleDef, camRollInfluence), CSPFT_FLOAT}, + {"camFovIncrease", offsetof(VehicleDef, camFovIncrease), CSPFT_FLOAT}, + {"camFovOffset", offsetof(VehicleDef, camFovOffset), CSPFT_FLOAT}, + {"camFovSpeed", offsetof(VehicleDef, camFovSpeed), CSPFT_FLOAT}, + {"turretWeaponName", offsetof(VehicleDef, turretWeaponName), CSPFT_STRING}, + {"turretHorizSpanLeft", offsetof(VehicleDef, turretHorizSpanLeft), CSPFT_FLOAT}, + {"turretHorizSpanRight", offsetof(VehicleDef, turretHorizSpanRight), CSPFT_FLOAT}, + {"turretVertSpanUp", offsetof(VehicleDef, turretVertSpanUp), CSPFT_FLOAT}, + {"turretVertSpanDown", offsetof(VehicleDef, turretVertSpanDown), CSPFT_FLOAT}, + {"turretRotRate", offsetof(VehicleDef, turretRotRate), CSPFT_FLOAT}, + {"turretSpinSnd", offsetof(VehicleDef, turretSpinSnd), CSPFT_SOUND}, + {"turretStopSnd", offsetof(VehicleDef, turretStopSnd), CSPFT_SOUND}, + {"trophyEnabled", offsetof(VehicleDef, trophyEnabled), CSPFT_QBOOLEAN}, + {"trophyRadius", offsetof(VehicleDef, trophyRadius), CSPFT_FLOAT}, + {"trophyInactiveRadius", offsetof(VehicleDef, trophyInactiveRadius), CSPFT_FLOAT}, + {"trophyAmmoCount", offsetof(VehicleDef, trophyAmmoCount), CSPFT_INT}, + {"trophyReloadTime", offsetof(VehicleDef, trophyReloadTime), CSPFT_FLOAT}, + {"trophyTags", offsetof(VehicleDef, trophyTags), VFT_TROPHY_TAGS}, + {"compassFriendlyIcon", offsetof(VehicleDef, compassFriendlyIcon), CSPFT_MATERIAL}, + {"compassEnemyIcon", offsetof(VehicleDef, compassEnemyIcon), CSPFT_MATERIAL}, + {"compassIconWidth", offsetof(VehicleDef, compassIconWidth), CSPFT_INT}, + {"compassIconHeight", offsetof(VehicleDef, compassIconHeight), CSPFT_INT}, + {"lowIdleSnd", offsetof(VehicleDef, idleLowSnd), CSPFT_SOUND}, + {"highIdleSnd", offsetof(VehicleDef, idleHighSnd), CSPFT_SOUND}, + {"lowEngineSnd", offsetof(VehicleDef, engineLowSnd), CSPFT_SOUND}, + {"highEngineSnd", offsetof(VehicleDef, engineHighSnd), CSPFT_SOUND}, + {"engineSndSpeed", offsetof(VehicleDef, engineSndSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"engineStartUpSnd", offsetof(VehicleDef, engineStartUpSnd), CSPFT_SOUND}, + {"engineStartUpLength", offsetof(VehicleDef, engineStartUpLength), CSPFT_MILLISECONDS}, + {"engineShutdownSnd", offsetof(VehicleDef, engineShutdownSnd), CSPFT_SOUND}, + {"engineIdleSnd", offsetof(VehicleDef, engineIdleSnd), CSPFT_SOUND}, + {"engineSustainSnd", offsetof(VehicleDef, engineSustainSnd), CSPFT_SOUND}, + {"engineRampUpSnd", offsetof(VehicleDef, engineRampUpSnd), CSPFT_SOUND}, + {"engineRampUpLength", offsetof(VehicleDef, engineRampUpLength), CSPFT_MILLISECONDS}, + {"engineRampDownSnd", offsetof(VehicleDef, engineRampDownSnd), CSPFT_SOUND}, + {"engineRampDownLength", offsetof(VehicleDef, engineRampDownLength), CSPFT_MILLISECONDS}, + {"suspensionSoftSnd", offsetof(VehicleDef, suspensionSoftSnd), CSPFT_SOUND}, + {"suspensionSoftCompression", offsetof(VehicleDef, suspensionSoftCompression), CSPFT_FLOAT}, + {"suspensionHardSnd", offsetof(VehicleDef, suspensionHardSnd), CSPFT_SOUND}, + {"suspensionHardCompression", offsetof(VehicleDef, suspensionHardCompression), CSPFT_FLOAT}, + {"collisionSnd", offsetof(VehicleDef, collisionSnd), CSPFT_SOUND}, + {"collisionBlendSpeed", offsetof(VehicleDef, collisionBlendSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"speedSnd", offsetof(VehicleDef, speedSnd), CSPFT_SOUND}, + {"speedSndBlendSpeed", offsetof(VehicleDef, speedSndBlendSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"surfaceSndPrefix", offsetof(VehicleDef, surfaceSndPrefix), CSPFT_STRING}, + {"surfaceSndBlendSpeed", offsetof(VehicleDef, surfaceSndBlendSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"slideVolume", offsetof(VehicleDef, slideVolume), CSPFT_FLOAT}, + {"slideBlendSpeed", offsetof(VehicleDef, slideBlendSpeed), CSPFT_MPH_TO_INCHES_PER_SEC}, + {"inAirPitch", offsetof(VehicleDef, inAirPitch), CSPFT_FLOAT}, }; namespace IW4 @@ -176,28 +176,28 @@ namespace IW4 break; case VFT_TROPHY_TAGS: - { - const auto* trophyTags = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - std::stringstream ss; - bool first = true; - - for (auto i = 0u; i < std::extent::value; i++) { - const auto& str = m_get_scr_string(trophyTags[i]); - if (!str.empty()) + const auto* trophyTags = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); + std::stringstream ss; + bool first = true; + + for (auto i = 0u; i < std::extent::value; i++) { - if (!first) - ss << "\n"; - else - first = false; + const auto& str = m_get_scr_string(trophyTags[i]); + if (!str.empty()) + { + if (!first) + ss << "\n"; + else + first = false; - ss << str; + ss << str; + } } - } - m_info_string.SetValueForKey(std::string(field.szName), ss.str()); - break; - } + m_info_string.SetValueForKey(std::string(field.szName), ss.str()); + break; + } case VFT_NUM: default: @@ -217,13 +217,13 @@ namespace IW4 InfoString AssetDumperVehicle::CreateInfoString(XAssetInfo* asset) { InfoStringFromVehicleConverter converter(asset->Asset(), vehicle_fields, std::extent::value, [asset](const scr_string_t scrStr) -> std::string - { - assert(scrStr < asset->m_zone->m_script_strings.Count()); - if (scrStr >= asset->m_zone->m_script_strings.Count()) - return ""; + { + assert(scrStr < asset->m_zone->m_script_strings.Count()); + if (scrStr >= asset->m_zone->m_script_strings.Count()) + return ""; - return asset->m_zone->m_script_strings[scrStr]; - }); + return asset->m_zone->m_script_strings[scrStr]; + }); return converter.Convert(); } @@ -233,33 +233,26 @@ bool AssetDumperVehicle::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperVehicle::CanDumpAsRaw() +void AssetDumperVehicle::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, GDF_NAME); + infoString.ToGdtProperties(FILE_TYPE_STR, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("vehicles/" + asset->m_name); -bool AssetDumperVehicle::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperVehicle::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "vehicles/" + asset->m_name; -} - -GdtEntry AssetDumperVehicle::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, GDF_NAME); - infoString.ToGdtProperties(FILE_TYPE_STR, gdtEntry); - - return gdtEntry; -} - -void AssetDumperVehicle::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(FILE_TYPE_STR); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(FILE_TYPE_STR); + stream.write(stringValue.c_str(), stringValue.size()); + } } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVehicle.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVehicle.h index b1a2c514..da793375 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVehicle.h +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperVehicle.h @@ -16,11 +16,6 @@ namespace IW4 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.cpp index 4eb7e40f..de8a6404 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.cpp @@ -1013,33 +1013,26 @@ bool AssetDumperWeapon::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperWeapon::CanDumpAsRaw() +void AssetDumperWeapon::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, GDF_NAME); + infoString.ToGdtProperties(FILE_TYPE_STR, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("weapons/" + asset->m_name); -bool AssetDumperWeapon::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperWeapon::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "weapons/" + asset->m_name; -} - -GdtEntry AssetDumperWeapon::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, GDF_NAME); - infoString.ToGdtProperties(FILE_TYPE_STR, gdtEntry); - - return gdtEntry; -} - -void AssetDumperWeapon::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(FILE_TYPE_STR); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(FILE_TYPE_STR); + stream.write(stringValue.c_str(), stringValue.size()); + } } diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.h b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.h index 450c2961..fbe8d408 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.h +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperWeapon.h @@ -17,11 +17,6 @@ namespace IW4 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperAddonMapEnts.cpp b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperAddonMapEnts.cpp index 1f8fd668..547881cf 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperAddonMapEnts.cpp +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperAddonMapEnts.cpp @@ -10,18 +10,14 @@ bool AssetDumperAddonMapEnts::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperAddonMapEnts::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperAddonMapEnts::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperAddonMapEnts::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperAddonMapEnts::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* addonMapEnts = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; stream.write(addonMapEnts->entityString, std::max(addonMapEnts->numEntityChars - 1, 0)); } diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperAddonMapEnts.h b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperAddonMapEnts.h index 4d3880f8..47a6098e 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperAddonMapEnts.h +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperAddonMapEnts.h @@ -9,8 +9,6 @@ namespace IW5 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperGfxImage.cpp b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperGfxImage.cpp index ad09f43c..6c00be0a 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperGfxImage.cpp +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperGfxImage.cpp @@ -31,12 +31,7 @@ bool AssetDumperGfxImage::ShouldDump(XAssetInfo* asset) return image->cardMemory.platform[0] > 0; } -bool AssetDumperGfxImage::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperGfxImage::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) +std::string AssetDumperGfxImage::GetAssetFileName(XAssetInfo* asset) const { std::string cleanAssetName = asset->m_name; for (auto& c : cleanAssetName) @@ -55,8 +50,14 @@ std::string AssetDumperGfxImage::GetFileNameForAsset(Zone* zone, XAssetInfoGetFileExtension(); } -void AssetDumperGfxImage::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* image = asset->Asset(); + const auto assetFile = context.OpenAssetFile(GetAssetFileName(asset)); + + if (!assetFile) + return; + + auto& stream = *assetFile; m_writer->DumpImage(stream, image->texture.texture); } diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperGfxImage.h b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperGfxImage.h index 7c903bb5..64a9267c 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperGfxImage.h +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperGfxImage.h @@ -12,11 +12,11 @@ namespace IW5 { std::unique_ptr m_writer; + std::string GetAssetFileName(XAssetInfo* asset) const; + protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; public: AssetDumperGfxImage(); diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLoadedSound.cpp b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLoadedSound.cpp index 32f3e388..392d22ea 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLoadedSound.cpp +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLoadedSound.cpp @@ -9,16 +9,6 @@ bool AssetDumperLoadedSound::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperLoadedSound::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperLoadedSound::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "sound/" + asset->m_name; -} - void AssetDumperLoadedSound::DumpWavPcm(AssetDumpingContext& context, const LoadedSound* asset, std::ostream& stream) { const auto riffMasterChunkSize = sizeof(WAV_CHUNK_ID_RIFF) @@ -60,9 +50,15 @@ void AssetDumperLoadedSound::DumpWavPcm(AssetDumpingContext& context, const Load stream.write(asset->sound.data, asset->sound.info.data_len); } -void AssetDumperLoadedSound::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperLoadedSound::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* loadedSound = asset->Asset(); + const auto assetFile = context.OpenAssetFile("sound/" + asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; switch (static_cast(loadedSound->sound.info.format)) { case WavFormat::PCM: diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLoadedSound.h b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLoadedSound.h index de3cf038..d60e6088 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLoadedSound.h +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLoadedSound.h @@ -8,10 +8,9 @@ namespace IW5 class AssetDumperLoadedSound final : public AbstractAssetDumper { static void DumpWavPcm(AssetDumpingContext& context, const LoadedSound* asset, std::ostream& stream); + protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLocalizeEntry.cpp b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLocalizeEntry.cpp index 865d251c..fae5d7ed 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLocalizeEntry.cpp +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperLocalizeEntry.cpp @@ -1,13 +1,11 @@ #include "AssetDumperLocalizeEntry.h" -#include -#include +#include #include "Localize/LocalizeCommon.h" #include "Dumping/Localize/StringFileDumper.h" using namespace IW5; -namespace fs = std::filesystem; void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool* pool) { @@ -15,20 +13,14 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< return; const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language); - fs::path stringsPath(context.m_base_path); - stringsPath.append(language); - stringsPath.append("localizedstrings"); - create_directories(stringsPath); + std::ostringstream ss; + ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str"; + const auto assetFile = context.OpenAssetFile(ss.str()); - auto stringFilePath(stringsPath); - stringFilePath.append(context.m_zone->m_name + ".str"); - - std::ofstream stringFile(stringFilePath, std::fstream::out | std::ofstream::binary); - - if (stringFile.is_open()) + if (assetFile) { - StringFileDumper stringFileDumper(context.m_zone, stringFile); + StringFileDumper stringFileDumper(context.m_zone, *assetFile); stringFileDumper.SetLanguageName(language); @@ -43,8 +35,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< } stringFileDumper.Finalize(); - - stringFile.close(); } else { diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.cpp b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.cpp index 2435ec66..47ef898b 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.cpp +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.cpp @@ -10,12 +10,7 @@ bool AssetDumperRawFile::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperRawFile::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperRawFile::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) +std::string AssetDumperRawFile::GetAssetFileName(XAssetInfo* asset) { std::string cleanAssetName = asset->m_name; for (auto& c : cleanAssetName) @@ -34,9 +29,15 @@ std::string AssetDumperRawFile::GetFileNameForAsset(Zone* zone, XAssetInfo* asset, std::ostream& stream) +void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* rawFile = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; if (rawFile->compressedLen <= 0) return; diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.h b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.h index 6388ae6b..b1c87b88 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.h +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.h @@ -7,10 +7,10 @@ namespace IW5 { class AssetDumperRawFile final : public AbstractAssetDumper { + static std::string GetAssetFileName(XAssetInfo* asset); + protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperStringTable.cpp b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperStringTable.cpp index 199f545a..0502816d 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperStringTable.cpp +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperStringTable.cpp @@ -9,20 +9,15 @@ bool AssetDumperStringTable::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperStringTable::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperStringTable::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperStringTable::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperStringTable::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* stringTable = asset->Asset(); - CsvOutputStream csv(stream); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + CsvOutputStream csv(*assetFile); for (auto row = 0; row < stringTable->rowCount; row++) { diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperStringTable.h b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperStringTable.h index faaee6c2..bdc480fa 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperStringTable.h +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperStringTable.h @@ -9,9 +9,6 @@ namespace IW5 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperGfxImage.cpp b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperGfxImage.cpp index 65a75f38..745784d1 100644 --- a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperGfxImage.cpp +++ b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperGfxImage.cpp @@ -31,18 +31,33 @@ bool AssetDumperGfxImage::ShouldDump(XAssetInfo* asset) return image->loadedSize > 0; } -bool AssetDumperGfxImage::CanDumpAsRaw() +std::string AssetDumperGfxImage::GetAssetFileName(XAssetInfo* asset) const { - return true; + std::string cleanAssetName = asset->m_name; + for (auto& c : cleanAssetName) + { + switch (c) + { + case '*': + c = '_'; + break; + + default: + break; + } + } + + return "images/" + cleanAssetName + m_writer->GetFileExtension(); } -std::string AssetDumperGfxImage::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "images/" + asset->m_name + m_writer->GetFileExtension(); -} - -void AssetDumperGfxImage::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* image = asset->Asset(); + const auto assetFile = context.OpenAssetFile(GetAssetFileName(asset)); + + if (!assetFile) + return; + + auto& stream = *assetFile; m_writer->DumpImage(stream, image->texture.texture); } diff --git a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperGfxImage.h b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperGfxImage.h index e201838c..4bbe63a8 100644 --- a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperGfxImage.h +++ b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperGfxImage.h @@ -12,11 +12,11 @@ namespace T5 { std::unique_ptr m_writer; + std::string GetAssetFileName(XAssetInfo* asset) const; + protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; public: AssetDumperGfxImage(); diff --git a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperLocalizeEntry.cpp b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperLocalizeEntry.cpp index fb620b9c..fc3f052c 100644 --- a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperLocalizeEntry.cpp +++ b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperLocalizeEntry.cpp @@ -1,13 +1,11 @@ #include "AssetDumperLocalizeEntry.h" -#include -#include +#include #include "Localize/LocalizeCommon.h" #include "Dumping/Localize/StringFileDumper.h" using namespace T5; -namespace fs = std::filesystem; void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool* pool) { @@ -15,20 +13,14 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< return; const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language); - fs::path stringsPath(context.m_base_path); - stringsPath.append(language); - stringsPath.append("localizedstrings"); - create_directories(stringsPath); + std::ostringstream ss; + ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str"; + const auto assetFile = context.OpenAssetFile(ss.str()); - auto stringFilePath(stringsPath); - stringFilePath.append(context.m_zone->m_name + ".str"); - - std::ofstream stringFile(stringFilePath, std::fstream::out | std::ofstream::binary); - - if (stringFile.is_open()) + if (assetFile) { - StringFileDumper stringFileDumper(context.m_zone, stringFile); + StringFileDumper stringFileDumper(context.m_zone, *assetFile); stringFileDumper.SetLanguageName(language); @@ -43,8 +35,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< } stringFileDumper.Finalize(); - - stringFile.close(); } else { diff --git a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperRawFile.cpp b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperRawFile.cpp index d51f4a3a..0c1d883e 100644 --- a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperRawFile.cpp +++ b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperRawFile.cpp @@ -91,24 +91,19 @@ bool AssetDumperRawFile::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperRawFile::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperRawFile::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperRawFile::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* rawFile = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + if (!assetFile) + return; + + auto& stream = *assetFile; const fs::path rawFilePath(rawFile->name); const auto extension = rawFilePath.extension().string(); - if(extension == ".gsc" || extension == ".csc") + if (extension == ".gsc" || extension == ".csc") { DumpGsc(context, asset, stream); } diff --git a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperRawFile.h b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperRawFile.h index bffcf9e6..de3e8ddc 100644 --- a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperRawFile.h +++ b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperRawFile.h @@ -9,13 +9,10 @@ namespace T5 { constexpr static size_t GSC_MAX_SIZE = 0xC000000; - void DumpGsc(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream); + static void DumpGsc(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream); protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperStringTable.cpp b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperStringTable.cpp index dad03712..ba164c80 100644 --- a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperStringTable.cpp +++ b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperStringTable.cpp @@ -9,20 +9,15 @@ bool AssetDumperStringTable::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperStringTable::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperStringTable::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperStringTable::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperStringTable::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* stringTable = asset->Asset(); - CsvOutputStream csv(stream); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + CsvOutputStream csv(*assetFile); for (auto row = 0; row < stringTable->rowCount; row++) { diff --git a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperStringTable.h b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperStringTable.h index b6e9a43e..cbbd86ea 100644 --- a/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperStringTable.h +++ b/src/ObjWriting/Game/T5/AssetDumpers/AssetDumperStringTable.h @@ -9,9 +9,6 @@ namespace T5 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperFontIcon.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperFontIcon.cpp index ea7ef376..e0750d74 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperFontIcon.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperFontIcon.cpp @@ -260,18 +260,13 @@ bool AssetDumperFontIcon::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperFontIcon::CanDumpAsRaw() +void AssetDumperFontIcon::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + const auto assetFile = context.OpenAssetFile(asset->m_name); -std::string AssetDumperFontIcon::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} + if (!assetFile) + return; -void AssetDumperFontIcon::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - AssetDumperFontIconInternal dumper(stream); + AssetDumperFontIconInternal dumper(*assetFile); dumper.DumpFontIcon(asset->Asset()); } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperFontIcon.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperFontIcon.h index 05deaa99..23f1d54f 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperFontIcon.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperFontIcon.h @@ -9,9 +9,6 @@ namespace T6 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperGfxImage.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperGfxImage.cpp index 50e6d18b..a205c05d 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperGfxImage.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperGfxImage.cpp @@ -31,12 +31,7 @@ bool AssetDumperGfxImage::ShouldDump(XAssetInfo* asset) return image->loadedSize > 0; } -bool AssetDumperGfxImage::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperGfxImage::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) +std::string AssetDumperGfxImage::GetAssetFileName(XAssetInfo* asset) const { std::string cleanAssetName = asset->m_name; for (auto& c : cleanAssetName) @@ -55,8 +50,14 @@ std::string AssetDumperGfxImage::GetFileNameForAsset(Zone* zone, XAssetInfoGetFileExtension(); } -void AssetDumperGfxImage::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* image = asset->Asset(); + const auto assetFile = context.OpenAssetFile(GetAssetFileName(asset)); + + if (!assetFile) + return; + + auto& stream = *assetFile; m_writer->DumpImage(stream, image->texture.texture); } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperGfxImage.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperGfxImage.h index b7458595..456dd84b 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperGfxImage.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperGfxImage.h @@ -12,11 +12,11 @@ namespace T6 { std::unique_ptr m_writer; + std::string GetAssetFileName(XAssetInfo* asset) const; + protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; public: AssetDumperGfxImage(); diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperLocalizeEntry.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperLocalizeEntry.cpp index 369a9dce..127e244d 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperLocalizeEntry.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperLocalizeEntry.cpp @@ -1,13 +1,11 @@ #include "AssetDumperLocalizeEntry.h" -#include -#include +#include #include "Localize/LocalizeCommon.h" #include "Dumping/Localize/StringFileDumper.h" using namespace T6; -namespace fs = std::filesystem; void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool* pool) { @@ -15,20 +13,14 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< return; const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language); - fs::path stringsPath(context.m_base_path); - stringsPath.append(language); - stringsPath.append("localizedstrings"); - create_directories(stringsPath); + std::ostringstream ss; + ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str"; + const auto assetFile = context.OpenAssetFile(ss.str()); - auto stringFilePath(stringsPath); - stringFilePath.append(context.m_zone->m_name + ".str"); - - std::ofstream stringFile(stringFilePath, std::fstream::out | std::ofstream::binary); - - if(stringFile.is_open()) + if (assetFile) { - StringFileDumper stringFileDumper(context.m_zone, stringFile); + StringFileDumper stringFileDumper(context.m_zone, *assetFile); stringFileDumper.SetLanguageName(language); @@ -43,8 +35,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool< } stringFileDumper.Finalize(); - - stringFile.close(); } else { diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.cpp index 3e959664..7568ef9e 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.cpp @@ -58,33 +58,26 @@ bool AssetDumperPhysConstraints::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperPhysConstraints::CanDumpAsRaw() +void AssetDumperPhysConstraints::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_PHYS_CONSTRAINTS); + infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("physconstraints/" + asset->m_name); -bool AssetDumperPhysConstraints::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperPhysConstraints::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "physconstraints/" + asset->m_name; -} - -GdtEntry AssetDumperPhysConstraints::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_PHYS_CONSTRAINTS); - infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, gdtEntry); - - return gdtEntry; -} - -void AssetDumperPhysConstraints::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS); + stream.write(stringValue.c_str(), stringValue.size()); + } } \ No newline at end of file diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.h index 8b299cc0..e94bfdd9 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysConstraints.h @@ -12,11 +12,6 @@ namespace T6 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.cpp index f47b6e52..2db9c7ab 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.cpp @@ -78,33 +78,26 @@ bool AssetDumperPhysPreset::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperPhysPreset::CanDumpAsRaw() +void AssetDumperPhysPreset::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_PHYS_PRESET); + infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("physic/" + asset->m_name); -bool AssetDumperPhysPreset::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperPhysPreset::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "physic/" + asset->m_name; -} - -GdtEntry AssetDumperPhysPreset::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_PHYS_PRESET); - infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, gdtEntry); - - return gdtEntry; -} - -void AssetDumperPhysPreset::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET); + stream.write(stringValue.c_str(), stringValue.size()); + } } \ No newline at end of file diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.h index dcd7ce9f..3dcb9445 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperPhysPreset.h @@ -13,11 +13,6 @@ namespace T6 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperQdb.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperQdb.cpp index 129f5d8c..d847be17 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperQdb.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperQdb.cpp @@ -7,18 +7,14 @@ bool AssetDumperQdb::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperQdb::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperQdb::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperQdb::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperQdb::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* qdb = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; stream.write(qdb->buffer, qdb->len); } \ No newline at end of file diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperQdb.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperQdb.h index 2e6387da..7d253a4f 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperQdb.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperQdb.h @@ -9,9 +9,6 @@ namespace T6 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.cpp index 4a9af1fb..5c5b2357 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.cpp @@ -7,18 +7,14 @@ bool AssetDumperRawFile::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperRawFile::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperRawFile::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperRawFile::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* rawFile = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; stream.write(rawFile->buffer, rawFile->len); } \ No newline at end of file diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.h index 82ccd7b7..8916419d 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperRawFile.h @@ -9,9 +9,6 @@ namespace T6 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperScriptParseTree.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperScriptParseTree.cpp index b9e4db57..dc87009d 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperScriptParseTree.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperScriptParseTree.cpp @@ -7,18 +7,14 @@ bool AssetDumperScriptParseTree::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperScriptParseTree::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperScriptParseTree::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperScriptParseTree::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperScriptParseTree::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* scriptParseTree = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; stream.write(scriptParseTree->buffer, scriptParseTree->len); } \ No newline at end of file diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperScriptParseTree.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperScriptParseTree.h index ffb333b4..396100b0 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperScriptParseTree.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperScriptParseTree.h @@ -9,9 +9,6 @@ namespace T6 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSlug.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSlug.cpp index 0d2d94e8..0be7b081 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSlug.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSlug.cpp @@ -7,18 +7,14 @@ bool AssetDumperSlug::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperSlug::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperSlug::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperSlug::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperSlug::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* slug = asset->Asset(); + const auto assetFile = context.OpenAssetFile(asset->m_name); + + if (!assetFile) + return; + + auto& stream = *assetFile; stream.write(slug->buffer, slug->len); } \ No newline at end of file diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSlug.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSlug.h index 4dc62ef0..f84fa993 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSlug.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSlug.h @@ -9,9 +9,6 @@ namespace T6 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp index fa6706c4..af3a4170 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp @@ -1,5 +1,6 @@ #include "AssetDumperSndBank.h" +#include #include #include diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperStringTable.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperStringTable.cpp index 34aa9e7f..1116559b 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperStringTable.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperStringTable.cpp @@ -9,24 +9,19 @@ bool AssetDumperStringTable::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperStringTable::CanDumpAsRaw() -{ - return true; -} - -std::string AssetDumperStringTable::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return asset->m_name; -} - -void AssetDumperStringTable::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) +void AssetDumperStringTable::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { const auto* stringTable = asset->Asset(); - CsvOutputStream csv(stream); + const auto assetFile = context.OpenAssetFile(asset->m_name); - for(auto row = 0; row < stringTable->rowCount; row++) + if (!assetFile) + return; + + CsvOutputStream csv(*assetFile); + + for (auto row = 0; row < stringTable->rowCount; row++) { - for(auto column = 0; column < stringTable->columnCount; column++) + for (auto column = 0; column < stringTable->columnCount; column++) { const auto* cell = &stringTable->values[column + row * stringTable->columnCount]; csv.WriteColumn(cell->string); diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperStringTable.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperStringTable.h index 4efd369c..d175e812 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperStringTable.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperStringTable.h @@ -9,9 +9,6 @@ namespace T6 { protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.cpp index 64b16054..ccafb90c 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.cpp @@ -57,33 +57,26 @@ bool AssetDumperTracer::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperTracer::CanDumpAsRaw() +void AssetDumperTracer::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_TRACER); + infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_TRACER, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("tracer/" + asset->m_name); -bool AssetDumperTracer::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperTracer::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "tracer/" + asset->m_name; -} - -GdtEntry AssetDumperTracer::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_TRACER); - infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_TRACER, gdtEntry); - - return gdtEntry; -} - -void AssetDumperTracer::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_TRACER); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_TRACER); + stream.write(stringValue.c_str(), stringValue.size()); + } } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.h index a1b009b4..36f6e7b6 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperTracer.h @@ -12,11 +12,6 @@ namespace T6 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.cpp index 5905b64c..c998bce9 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.cpp @@ -107,33 +107,26 @@ bool AssetDumperVehicle::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperVehicle::CanDumpAsRaw() +void AssetDumperVehicle::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_VEHICLE); + infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_VEHICLE, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("vehicles/" + asset->m_name); -bool AssetDumperVehicle::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperVehicle::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "vehicles/" + asset->m_name; -} - -GdtEntry AssetDumperVehicle::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_VEHICLE); - infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_VEHICLE, gdtEntry); - - return gdtEntry; -} - -void AssetDumperVehicle::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_VEHICLE); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_VEHICLE); + stream.write(stringValue.c_str(), stringValue.size()); + } } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.h index 4c584677..499181e4 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperVehicle.h @@ -12,11 +12,6 @@ namespace T6 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.cpp index f96e8523..0870e33a 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.cpp @@ -417,33 +417,26 @@ bool AssetDumperWeapon::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperWeapon::CanDumpAsRaw() +void AssetDumperWeapon::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_WEAPON); + infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("weapons/" + asset->m_name); -bool AssetDumperWeapon::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperWeapon::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "weapons/" + asset->m_name; -} - -GdtEntry AssetDumperWeapon::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_WEAPON); - infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON, gdtEntry); - - return gdtEntry; -} - -void AssetDumperWeapon::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_WEAPON); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_WEAPON); + stream.write(stringValue.c_str(), stringValue.size()); + } } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.h index 47bad5c1..1e89f189 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeapon.h @@ -13,11 +13,6 @@ namespace T6 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.cpp index 4e797314..adb665e8 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.cpp @@ -63,33 +63,26 @@ bool AssetDumperWeaponAttachment::ShouldDump(XAssetInfo* asset return true; } -bool AssetDumperWeaponAttachment::CanDumpAsRaw() +void AssetDumperWeaponAttachment::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT); + infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("attachment/" + asset->m_name); -bool AssetDumperWeaponAttachment::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperWeaponAttachment::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "attachment/" + asset->m_name; -} - -GdtEntry AssetDumperWeaponAttachment::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT); - infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT, gdtEntry); - - return gdtEntry; -} - -void AssetDumperWeaponAttachment::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT); + stream.write(stringValue.c_str(), stringValue.size()); + } } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.h index 2e610ef5..25158627 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachment.h @@ -12,11 +12,6 @@ namespace T6 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.cpp index 4bc0a4c9..85e62da5 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.cpp @@ -131,33 +131,26 @@ bool AssetDumperWeaponAttachmentUnique::ShouldDump(XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT_UNIQUE); + infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("attachmentunique/" + asset->m_name); -bool AssetDumperWeaponAttachmentUnique::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperWeaponAttachmentUnique::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "attachmentunique/" + asset->m_name; -} - -GdtEntry AssetDumperWeaponAttachmentUnique::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT_UNIQUE); - infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE, gdtEntry); - - return gdtEntry; -} - -void AssetDumperWeaponAttachmentUnique::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE); + stream.write(stringValue.c_str(), stringValue.size()); + } } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.h index a21f62d9..39d4f7d9 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperWeaponAttachmentUnique.h @@ -13,11 +13,6 @@ namespace T6 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.cpp index f7aa9f72..c9cb00fa 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.cpp @@ -46,33 +46,26 @@ bool AssetDumperZBarrier::ShouldDump(XAssetInfo* asset) return true; } -bool AssetDumperZBarrier::CanDumpAsRaw() +void AssetDumperZBarrier::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) { - return true; -} + // Only dump raw when no gdt available + if (context.m_gdt) + { + const auto infoString = CreateInfoString(asset); + GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_ZBARRIER); + infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, gdtEntry); + context.m_gdt->WriteEntry(gdtEntry); + } + else + { + const auto assetFile = context.OpenAssetFile("zbarrier/" + asset->m_name); -bool AssetDumperZBarrier::CanDumpAsGdtEntry() -{ - return true; -} + if (!assetFile) + return; -std::string AssetDumperZBarrier::GetFileNameForAsset(Zone* zone, XAssetInfo* asset) -{ - return "zbarrier/" + asset->m_name; -} - -GdtEntry AssetDumperZBarrier::DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto infoString = CreateInfoString(asset); - GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_ZBARRIER); - infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, gdtEntry); - - return gdtEntry; -} - -void AssetDumperZBarrier::DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) -{ - const auto infoString = CreateInfoString(asset); - const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_ZBARRIER); - stream.write(stringValue.c_str(), stringValue.size()); + auto& stream = *assetFile; + const auto infoString = CreateInfoString(asset); + const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_ZBARRIER); + stream.write(stringValue.c_str(), stringValue.size()); + } } diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.h b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.h index e52b8c0a..8dd46e54 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.h +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperZBarrier.h @@ -12,11 +12,6 @@ namespace T6 protected: bool ShouldDump(XAssetInfo* asset) override; - bool CanDumpAsRaw() override; - bool CanDumpAsGdtEntry() override; - - std::string GetFileNameForAsset(Zone* zone, XAssetInfo* asset) override; - GdtEntry DumpGdtEntry(AssetDumpingContext& context, XAssetInfo* asset) override; - void DumpRaw(AssetDumpingContext& context, XAssetInfo* asset, std::ostream& stream) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; }