From 0546572ecf809b5e0cfe2827f9ba3b7ce170a599 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sun, 3 Aug 2025 13:12:50 +0200 Subject: [PATCH] refactor: streamline weapon dumping --- src/ObjCommon/Weapon/AttachmentCommon.cpp | 16 + src/ObjCommon/Weapon/AttachmentCommon.h | 9 + .../Weapon/AttachmentUniqueCommon.cpp | 11 + src/ObjCommon/Weapon/AttachmentUniqueCommon.h | 8 + src/ObjCommon/Weapon/CamoCommon.cpp | 11 + src/ObjCommon/Weapon/CamoCommon.h | 8 + src/ObjCommon/Weapon/WeaponCommon.cpp | 11 + src/ObjCommon/Weapon/WeaponCommon.h | 8 + src/ObjLoading/Game/T6/ObjLoaderT6.cpp | 28 +- ...chmentT6.cpp => AttachmentGdtLoaderT6.cpp} | 12 +- .../Game/T6/Weapon/AttachmentGdtLoaderT6.h | 14 + ...6.cpp => AttachmentInfoStringLoaderT6.cpp} | 47 +- ...entT6.h => AttachmentInfoStringLoaderT6.h} | 8 +- ...chmentT6.cpp => AttachmentRawLoaderT6.cpp} | 16 +- .../Game/T6/Weapon/AttachmentRawLoaderT6.h | 13 + ...T6.cpp => AttachmentUniqueGdtLoaderT6.cpp} | 13 +- .../T6/Weapon/AttachmentUniqueGdtLoaderT6.h | 14 + ...=> AttachmentUniqueInfoStringLoaderT6.cpp} | 147 +++---- ...h => AttachmentUniqueInfoStringLoaderT6.h} | 12 +- ...T6.cpp => AttachmentUniqueRawLoaderT6.cpp} | 22 +- ...iqueT6.h => AttachmentUniqueRawLoaderT6.h} | 6 +- ...nCamoLoaderT6.cpp => CamoJsonLoaderT6.cpp} | 55 ++- ...oaderWeaponCamoT6.h => CamoJsonLoaderT6.h} | 6 +- .../Game/T6/Weapon/GdtLoaderAttachmentT6.h | 14 - .../T6/Weapon/GdtLoaderAttachmentUniqueT6.h | 15 - .../Game/T6/Weapon/JsonWeaponCamoLoaderT6.h | 14 - .../Game/T6/Weapon/LoaderWeaponCamoT6.cpp | 55 --- .../Game/T6/Weapon/RawLoaderAttachmentT6.h | 13 - .../Game/T6/Weapon/RawLoaderWeaponT6.h | 13 - ...aderWeaponT6.cpp => WeaponGdtLoaderT6.cpp} | 12 +- ...dtLoaderWeaponT6.h => WeaponGdtLoaderT6.h} | 6 +- ...ponT6.cpp => WeaponInfoStringLoaderT6.cpp} | 60 +-- ...rWeaponT6.h => WeaponInfoStringLoaderT6.h} | 8 +- ...aderWeaponT6.cpp => WeaponRawLoaderT6.cpp} | 22 +- .../Game/T6/Weapon/WeaponRawLoaderT6.h | 13 + src/ObjWriting/Game/IW3/ObjWriterIW3.cpp | 1 - .../Game/IW3/Weapon/AssetDumperWeapon.cpp | 0 .../Game/IW3/Weapon/AssetDumperWeapon.h | 0 src/ObjWriting/Game/IW4/ObjWriterIW4.cpp | 4 +- .../Game/IW4/Weapon/AssetDumperWeapon.h | 19 - ...etDumperWeapon.cpp => WeaponDumperIW4.cpp} | 370 ++++++++-------- .../Game/IW4/Weapon/WeaponDumperIW4.h | 15 + src/ObjWriting/Game/IW5/ObjWriterIW5.cpp | 8 +- .../Game/IW5/Weapon/AssetDumperWeapon.h | 19 - .../Weapon/AssetDumperWeaponAttachment.cpp | 22 - ...Writer.cpp => AttachmentJsonDumperIW5.cpp} | 28 +- ...Attachment.h => AttachmentJsonDumperIW5.h} | 6 +- .../IW5/Weapon/JsonWeaponAttachmentWriter.h | 11 - ...etDumperWeapon.cpp => WeaponDumperIW5.cpp} | 402 +++++++++--------- .../Game/IW5/Weapon/WeaponDumperIW5.h | 15 + src/ObjWriting/Game/T5/ObjWriterT5.cpp | 1 - .../Game/T5/Weapon/AssetDumperWeapon.cpp | 0 .../Game/T5/Weapon/AssetDumperWeapon.h | 0 src/ObjWriting/Game/T6/ObjWriterT6.cpp | 16 +- .../Game/T6/Weapon/AssetDumperWeapon.h | 19 - .../T6/Weapon/AssetDumperWeaponAttachment.cpp | 94 ---- .../AssetDumperWeaponAttachmentUnique.cpp | 158 ------- .../AssetDumperWeaponAttachmentUnique.h | 18 - .../Game/T6/Weapon/AssetDumperWeaponCamo.cpp | 23 - .../Game/T6/Weapon/AttachmentDumperT6.cpp | 99 +++++ ...eaponAttachment.h => AttachmentDumperT6.h} | 8 +- .../T6/Weapon/AttachmentUniqueDumperT6.cpp | 163 +++++++ .../Game/T6/Weapon/AttachmentUniqueDumperT6.h | 15 + ...ponCamoWriter.cpp => CamoJsonDumperT6.cpp} | 29 +- ...tDumperWeaponCamo.h => CamoJsonDumperT6.h} | 6 +- .../Game/T6/Weapon/JsonWeaponCamoWriter.h | 11 - ...setDumperWeapon.cpp => WeaponDumperT6.cpp} | 395 ++++++++--------- .../Game/T6/Weapon/WeaponDumperT6.h | 14 + 68 files changed, 1380 insertions(+), 1349 deletions(-) create mode 100644 src/ObjCommon/Weapon/AttachmentCommon.cpp create mode 100644 src/ObjCommon/Weapon/AttachmentCommon.h create mode 100644 src/ObjCommon/Weapon/AttachmentUniqueCommon.cpp create mode 100644 src/ObjCommon/Weapon/AttachmentUniqueCommon.h create mode 100644 src/ObjCommon/Weapon/CamoCommon.cpp create mode 100644 src/ObjCommon/Weapon/CamoCommon.h create mode 100644 src/ObjCommon/Weapon/WeaponCommon.cpp create mode 100644 src/ObjCommon/Weapon/WeaponCommon.h rename src/ObjLoading/Game/T6/Weapon/{GdtLoaderAttachmentT6.cpp => AttachmentGdtLoaderT6.cpp} (80%) create mode 100644 src/ObjLoading/Game/T6/Weapon/AttachmentGdtLoaderT6.h rename src/ObjLoading/Game/T6/Weapon/{InfoStringLoaderAttachmentT6.cpp => AttachmentInfoStringLoaderT6.cpp} (76%) rename src/ObjLoading/Game/T6/Weapon/{InfoStringLoaderAttachmentT6.h => AttachmentInfoStringLoaderT6.h} (70%) rename src/ObjLoading/Game/T6/Weapon/{RawLoaderAttachmentT6.cpp => AttachmentRawLoaderT6.cpp} (74%) create mode 100644 src/ObjLoading/Game/T6/Weapon/AttachmentRawLoaderT6.h rename src/ObjLoading/Game/T6/Weapon/{GdtLoaderAttachmentUniqueT6.cpp => AttachmentUniqueGdtLoaderT6.cpp} (78%) create mode 100644 src/ObjLoading/Game/T6/Weapon/AttachmentUniqueGdtLoaderT6.h rename src/ObjLoading/Game/T6/Weapon/{InfoStringLoaderAttachmentUniqueT6.cpp => AttachmentUniqueInfoStringLoaderT6.cpp} (64%) rename src/ObjLoading/Game/T6/Weapon/{InfoStringLoaderAttachmentUniqueT6.h => AttachmentUniqueInfoStringLoaderT6.h} (59%) rename src/ObjLoading/Game/T6/Weapon/{RawLoaderAttachmentUniqueT6.cpp => AttachmentUniqueRawLoaderT6.cpp} (63%) rename src/ObjLoading/Game/T6/Weapon/{RawLoaderAttachmentUniqueT6.h => AttachmentUniqueRawLoaderT6.h} (61%) rename src/ObjLoading/Game/T6/Weapon/{JsonWeaponCamoLoaderT6.cpp => CamoJsonLoaderT6.cpp} (84%) rename src/ObjLoading/Game/T6/Weapon/{LoaderWeaponCamoT6.h => CamoJsonLoaderT6.h} (50%) delete mode 100644 src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.h delete mode 100644 src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.h delete mode 100644 src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.h delete mode 100644 src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.cpp delete mode 100644 src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.h delete mode 100644 src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.h rename src/ObjLoading/Game/T6/Weapon/{GdtLoaderWeaponT6.cpp => WeaponGdtLoaderT6.cpp} (80%) rename src/ObjLoading/Game/T6/Weapon/{GdtLoaderWeaponT6.h => WeaponGdtLoaderT6.h} (50%) rename src/ObjLoading/Game/T6/Weapon/{InfoStringLoaderWeaponT6.cpp => WeaponInfoStringLoaderT6.cpp} (94%) rename src/ObjLoading/Game/T6/Weapon/{InfoStringLoaderWeaponT6.h => WeaponInfoStringLoaderT6.h} (71%) rename src/ObjLoading/Game/T6/Weapon/{RawLoaderWeaponT6.cpp => WeaponRawLoaderT6.cpp} (63%) create mode 100644 src/ObjLoading/Game/T6/Weapon/WeaponRawLoaderT6.h delete mode 100644 src/ObjWriting/Game/IW3/Weapon/AssetDumperWeapon.cpp delete mode 100644 src/ObjWriting/Game/IW3/Weapon/AssetDumperWeapon.h delete mode 100644 src/ObjWriting/Game/IW4/Weapon/AssetDumperWeapon.h rename src/ObjWriting/Game/IW4/Weapon/{AssetDumperWeapon.cpp => WeaponDumperIW4.cpp} (50%) create mode 100644 src/ObjWriting/Game/IW4/Weapon/WeaponDumperIW4.h delete mode 100644 src/ObjWriting/Game/IW5/Weapon/AssetDumperWeapon.h delete mode 100644 src/ObjWriting/Game/IW5/Weapon/AssetDumperWeaponAttachment.cpp rename src/ObjWriting/Game/IW5/Weapon/{JsonWeaponAttachmentWriter.cpp => AttachmentJsonDumperIW5.cpp} (96%) rename src/ObjWriting/Game/IW5/Weapon/{AssetDumperWeaponAttachment.h => AttachmentJsonDumperIW5.h} (68%) delete mode 100644 src/ObjWriting/Game/IW5/Weapon/JsonWeaponAttachmentWriter.h rename src/ObjWriting/Game/IW5/Weapon/{AssetDumperWeapon.cpp => WeaponDumperIW5.cpp} (67%) create mode 100644 src/ObjWriting/Game/IW5/Weapon/WeaponDumperIW5.h delete mode 100644 src/ObjWriting/Game/T5/Weapon/AssetDumperWeapon.cpp delete mode 100644 src/ObjWriting/Game/T5/Weapon/AssetDumperWeapon.h delete mode 100644 src/ObjWriting/Game/T6/Weapon/AssetDumperWeapon.h delete mode 100644 src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachment.cpp delete mode 100644 src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachmentUnique.cpp delete mode 100644 src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachmentUnique.h delete mode 100644 src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponCamo.cpp create mode 100644 src/ObjWriting/Game/T6/Weapon/AttachmentDumperT6.cpp rename src/ObjWriting/Game/T6/Weapon/{AssetDumperWeaponAttachment.h => AttachmentDumperT6.h} (60%) create mode 100644 src/ObjWriting/Game/T6/Weapon/AttachmentUniqueDumperT6.cpp create mode 100644 src/ObjWriting/Game/T6/Weapon/AttachmentUniqueDumperT6.h rename src/ObjWriting/Game/T6/Weapon/{JsonWeaponCamoWriter.cpp => CamoJsonDumperT6.cpp} (86%) rename src/ObjWriting/Game/T6/Weapon/{AssetDumperWeaponCamo.h => CamoJsonDumperT6.h} (70%) delete mode 100644 src/ObjWriting/Game/T6/Weapon/JsonWeaponCamoWriter.h rename src/ObjWriting/Game/T6/Weapon/{AssetDumperWeapon.cpp => WeaponDumperT6.cpp} (53%) create mode 100644 src/ObjWriting/Game/T6/Weapon/WeaponDumperT6.h diff --git a/src/ObjCommon/Weapon/AttachmentCommon.cpp b/src/ObjCommon/Weapon/AttachmentCommon.cpp new file mode 100644 index 00000000..1fd354b3 --- /dev/null +++ b/src/ObjCommon/Weapon/AttachmentCommon.cpp @@ -0,0 +1,16 @@ +#include "AttachmentCommon.h" + +#include + +namespace attachment +{ + std::string GetInfoStringFileNameForAssetName(const std::string& assetName) + { + return std::format("attachment/{}", assetName); + } + + std::string GetJsonFileNameForAssetName(const std::string& assetName) + { + return std::format("attachment/{}.json", assetName); + } +} // namespace attachment diff --git a/src/ObjCommon/Weapon/AttachmentCommon.h b/src/ObjCommon/Weapon/AttachmentCommon.h new file mode 100644 index 00000000..e9566b4f --- /dev/null +++ b/src/ObjCommon/Weapon/AttachmentCommon.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace attachment +{ + std::string GetInfoStringFileNameForAssetName(const std::string& assetName); + std::string GetJsonFileNameForAssetName(const std::string& assetName); +} // namespace attachment diff --git a/src/ObjCommon/Weapon/AttachmentUniqueCommon.cpp b/src/ObjCommon/Weapon/AttachmentUniqueCommon.cpp new file mode 100644 index 00000000..a1b520e3 --- /dev/null +++ b/src/ObjCommon/Weapon/AttachmentUniqueCommon.cpp @@ -0,0 +1,11 @@ +#include "AttachmentUniqueCommon.h" + +#include + +namespace attachment_unique +{ + std::string GetFileNameForAssetName(const std::string& assetName) + { + return std::format("attachmentunique/{}", assetName); + } +} // namespace attachment_unique diff --git a/src/ObjCommon/Weapon/AttachmentUniqueCommon.h b/src/ObjCommon/Weapon/AttachmentUniqueCommon.h new file mode 100644 index 00000000..dcc9accc --- /dev/null +++ b/src/ObjCommon/Weapon/AttachmentUniqueCommon.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace attachment_unique +{ + std::string GetFileNameForAssetName(const std::string& assetName); +} diff --git a/src/ObjCommon/Weapon/CamoCommon.cpp b/src/ObjCommon/Weapon/CamoCommon.cpp new file mode 100644 index 00000000..293794eb --- /dev/null +++ b/src/ObjCommon/Weapon/CamoCommon.cpp @@ -0,0 +1,11 @@ +#include "WeaponCommon.h" + +#include + +namespace camo +{ + std::string GetJsonFileNameForAssetName(const std::string& assetName) + { + return std::format("camo/{}.json", assetName); + } +} // namespace camo diff --git a/src/ObjCommon/Weapon/CamoCommon.h b/src/ObjCommon/Weapon/CamoCommon.h new file mode 100644 index 00000000..b0450767 --- /dev/null +++ b/src/ObjCommon/Weapon/CamoCommon.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace camo +{ + std::string GetJsonFileNameForAssetName(const std::string& assetName); +} diff --git a/src/ObjCommon/Weapon/WeaponCommon.cpp b/src/ObjCommon/Weapon/WeaponCommon.cpp new file mode 100644 index 00000000..704a388c --- /dev/null +++ b/src/ObjCommon/Weapon/WeaponCommon.cpp @@ -0,0 +1,11 @@ +#include "WeaponCommon.h" + +#include + +namespace weapon +{ + std::string GetFileNameForAssetName(const std::string& assetName) + { + return std::format("weapons/{}", assetName); + } +} // namespace weapon diff --git a/src/ObjCommon/Weapon/WeaponCommon.h b/src/ObjCommon/Weapon/WeaponCommon.h new file mode 100644 index 00000000..1d1a350a --- /dev/null +++ b/src/ObjCommon/Weapon/WeaponCommon.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace weapon +{ + std::string GetFileNameForAssetName(const std::string& assetName); +} diff --git a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp index 7ebfbc3b..7232c923 100644 --- a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp @@ -32,13 +32,13 @@ #include "Tracer/RawLoaderTracerT6.h" #include "Vehicle/GdtLoaderVehicleT6.h" #include "Vehicle/RawLoaderVehicleT6.h" -#include "Weapon/GdtLoaderAttachmentT6.h" -#include "Weapon/GdtLoaderAttachmentUniqueT6.h" -#include "Weapon/GdtLoaderWeaponT6.h" -#include "Weapon/LoaderWeaponCamoT6.h" -#include "Weapon/RawLoaderAttachmentT6.h" -#include "Weapon/RawLoaderAttachmentUniqueT6.h" -#include "Weapon/RawLoaderWeaponT6.h" +#include "Weapon/AttachmentGdtLoaderT6.h" +#include "Weapon/AttachmentRawLoaderT6.h" +#include "Weapon/AttachmentUniqueGdtLoaderT6.h" +#include "Weapon/AttachmentUniqueRawLoaderT6.h" +#include "Weapon/CamoJsonLoaderT6.h" +#include "Weapon/WeaponGdtLoaderT6.h" +#include "Weapon/WeaponRawLoaderT6.h" #include "ZBarrier/GdtLoaderZBarrierT6.h" #include "ZBarrier/RawLoaderZBarrierT6.h" @@ -418,13 +418,13 @@ namespace T6 // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); collection.AddAssetCreator(CreateLocalizeLoader(memory, searchPath, zone)); - collection.AddAssetCreator(CreateRawWeaponLoader(memory, searchPath, zone)); - collection.AddAssetCreator(CreateGdtWeaponLoader(memory, searchPath, gdt, zone)); - collection.AddAssetCreator(CreateRawAttachmentLoader(memory, searchPath, zone)); - collection.AddAssetCreator(CreateGdtAttachmentLoader(memory, searchPath, gdt, zone)); - collection.AddAssetCreator(CreateRawAttachmentUniqueLoader(memory, searchPath, zone)); - collection.AddAssetCreator(CreateGdtAttachmentUniqueLoader(memory, searchPath, gdt, zone)); - collection.AddAssetCreator(CreateWeaponCamoLoader(memory, searchPath)); + collection.AddAssetCreator(weapon::CreateRawLoader(memory, searchPath, zone)); + collection.AddAssetCreator(weapon::CreateGdtLoader(memory, searchPath, gdt, zone)); + collection.AddAssetCreator(attachment::CreateRawLoader(memory, searchPath, zone)); + collection.AddAssetCreator(attachment::CreateGdtLoader(memory, searchPath, gdt, zone)); + collection.AddAssetCreator(attachment_unique::CreateRawLoader(memory, searchPath, zone)); + collection.AddAssetCreator(attachment_unique::CreateGdtLoader(memory, searchPath, gdt, zone)); + collection.AddAssetCreator(camo::CreateJsonLoader(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); // collection.AddAssetCreator(std::make_unique(memory)); diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.cpp b/src/ObjLoading/Game/T6/Weapon/AttachmentGdtLoaderT6.cpp similarity index 80% rename from src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.cpp rename to src/ObjLoading/Game/T6/Weapon/AttachmentGdtLoaderT6.cpp index ceecfd7f..0357b7d8 100644 --- a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentGdtLoaderT6.cpp @@ -1,9 +1,9 @@ -#include "GdtLoaderAttachmentT6.h" +#include "AttachmentGdtLoaderT6.h" +#include "AttachmentInfoStringLoaderT6.h" #include "Game/T6/ObjConstantsT6.h" #include "Game/T6/T6.h" #include "InfoString/InfoString.h" -#include "InfoStringLoaderAttachmentT6.h" #include #include @@ -40,14 +40,14 @@ namespace private: IGdtQueryable& m_gdt; - InfoStringLoaderAttachment m_info_string_loader; + T6::attachment::InfoStringLoader m_info_string_loader; }; } // namespace -namespace T6 +namespace T6::attachment { - std::unique_ptr> CreateGdtAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + std::unique_ptr> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) { return std::make_unique(memory, searchPath, gdt, zone); } -} // namespace T6 +} // namespace T6::attachment diff --git a/src/ObjLoading/Game/T6/Weapon/AttachmentGdtLoaderT6.h b/src/ObjLoading/Game/T6/Weapon/AttachmentGdtLoaderT6.h new file mode 100644 index 00000000..799507bf --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentGdtLoaderT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6::attachment +{ + std::unique_ptr> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6::attachment diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.cpp b/src/ObjLoading/Game/T6/Weapon/AttachmentInfoStringLoaderT6.cpp similarity index 76% rename from src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.cpp rename to src/ObjLoading/Game/T6/Weapon/AttachmentInfoStringLoaderT6.cpp index 83f71735..721a4b81 100644 --- a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentInfoStringLoaderT6.cpp @@ -1,4 +1,4 @@ -#include "InfoStringLoaderAttachmentT6.h" +#include "AttachmentInfoStringLoaderT6.h" #include "Game/T6/InfoString/InfoStringToStructConverter.h" #include "Game/T6/T6.h" @@ -93,29 +93,32 @@ namespace } } // namespace -InfoStringLoaderAttachment::InfoStringLoaderAttachment(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) - : m_memory(memory), - m_search_path(searchPath), - m_zone(zone) +namespace T6::attachment { -} - -AssetCreationResult InfoStringLoaderAttachment::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) -{ - auto* attachment = m_memory.Alloc(); - attachment->szInternalName = m_memory.Dup(assetName.c_str()); - - AssetRegistration registration(assetName, attachment); - - InfoStringToAttachmentConverter converter( - infoString, *attachment, m_zone.m_script_strings, m_memory, context, registration, attachment_fields, std::extent_v); - if (!converter.Convert()) + InfoStringLoader::InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) { - std::cerr << std::format("Failed to parse attachment: \"{}\"\n", assetName); - return AssetCreationResult::Failure(); } - CalculateAttachmentFields(*attachment); + AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) + { + auto* attachment = m_memory.Alloc(); + attachment->szInternalName = m_memory.Dup(assetName.c_str()); - return AssetCreationResult::Success(context.AddAsset(std::move(registration))); -} + AssetRegistration registration(assetName, attachment); + + InfoStringToAttachmentConverter converter( + infoString, *attachment, m_zone.m_script_strings, m_memory, context, registration, attachment_fields, std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse attachment: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + CalculateAttachmentFields(*attachment); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } +} // namespace T6::attachment diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.h b/src/ObjLoading/Game/T6/Weapon/AttachmentInfoStringLoaderT6.h similarity index 70% rename from src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.h rename to src/ObjLoading/Game/T6/Weapon/AttachmentInfoStringLoaderT6.h index fc6d020d..c9dd12d7 100644 --- a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentT6.h +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentInfoStringLoaderT6.h @@ -4,12 +4,12 @@ #include "Asset/AssetCreationResult.h" #include "InfoString/InfoString.h" -namespace T6 +namespace T6::attachment { - class InfoStringLoaderAttachment + class InfoStringLoader { public: - InfoStringLoaderAttachment(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); @@ -18,4 +18,4 @@ namespace T6 ISearchPath& m_search_path; Zone& m_zone; }; -} // namespace T6 +} // namespace T6::attachment diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.cpp b/src/ObjLoading/Game/T6/Weapon/AttachmentRawLoaderT6.cpp similarity index 74% rename from src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.cpp rename to src/ObjLoading/Game/T6/Weapon/AttachmentRawLoaderT6.cpp index bf318b2d..c2158ba2 100644 --- a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentRawLoaderT6.cpp @@ -1,15 +1,17 @@ -#include "RawLoaderAttachmentT6.h" +#include "AttachmentRawLoaderT6.h" +#include "AttachmentInfoStringLoaderT6.h" #include "Game/T6/ObjConstantsT6.h" #include "Game/T6/T6.h" #include "InfoString/InfoString.h" -#include "InfoStringLoaderAttachmentT6.h" +#include "Weapon/AttachmentCommon.h" #include #include #include using namespace T6; +using namespace ::attachment; namespace { @@ -24,7 +26,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto fileName = std::format("attachment/{}", assetName); + const auto fileName = GetInfoStringFileNameForAssetName(assetName); const auto file = m_search_path.Open(fileName); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -41,14 +43,14 @@ namespace private: ISearchPath& m_search_path; - InfoStringLoaderAttachment m_info_string_loader; + T6::attachment::InfoStringLoader m_info_string_loader; }; } // namespace -namespace T6 +namespace T6::attachment { - std::unique_ptr> CreateRawAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + std::unique_ptr> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) { return std::make_unique(memory, searchPath, zone); } -} // namespace T6 +} // namespace T6::attachment diff --git a/src/ObjLoading/Game/T6/Weapon/AttachmentRawLoaderT6.h b/src/ObjLoading/Game/T6/Weapon/AttachmentRawLoaderT6.h new file mode 100644 index 00000000..5726e166 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentRawLoaderT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6::attachment +{ + std::unique_ptr> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6::attachment diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.cpp b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueGdtLoaderT6.cpp similarity index 78% rename from src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.cpp rename to src/ObjLoading/Game/T6/Weapon/AttachmentUniqueGdtLoaderT6.cpp index ab53d947..b79492ff 100644 --- a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueGdtLoaderT6.cpp @@ -1,9 +1,9 @@ -#include "GdtLoaderAttachmentUniqueT6.h" +#include "AttachmentUniqueGdtLoaderT6.h" +#include "AttachmentUniqueInfoStringLoaderT6.h" #include "Game/T6/ObjConstantsT6.h" #include "Game/T6/T6.h" #include "InfoString/InfoString.h" -#include "InfoStringLoaderAttachmentUniqueT6.h" #include #include @@ -40,15 +40,14 @@ namespace private: IGdtQueryable& m_gdt; - InfoStringLoaderAttachmentUnique m_info_string_loader; + T6::attachment_unique::InfoStringLoader m_info_string_loader; }; } // namespace -namespace T6 +namespace T6::attachment_unique { - std::unique_ptr> - CreateGdtAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + std::unique_ptr> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) { return std::make_unique(memory, searchPath, gdt, zone); } -} // namespace T6 +} // namespace T6::attachment_unique diff --git a/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueGdtLoaderT6.h b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueGdtLoaderT6.h new file mode 100644 index 00000000..b7065166 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueGdtLoaderT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "Gdt/IGdtQueryable.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6::attachment_unique +{ + std::unique_ptr> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6::attachment_unique diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.cpp b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueInfoStringLoaderT6.cpp similarity index 64% rename from src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.cpp rename to src/ObjLoading/Game/T6/Weapon/AttachmentUniqueInfoStringLoaderT6.cpp index 98a17081..02429b3f 100644 --- a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueInfoStringLoaderT6.cpp @@ -1,4 +1,4 @@ -#include "InfoStringLoaderAttachmentUniqueT6.h" +#include "AttachmentUniqueInfoStringLoaderT6.h" #include "Game/T6/InfoString/InfoStringToStructConverter.h" #include "Game/T6/T6.h" @@ -141,7 +141,7 @@ namespace { // combinedAttachmentTypeMask std::vector attachmentsFromName; - if (!InfoStringLoaderAttachmentUnique::ExtractAttachmentsFromAssetName(assetName, attachmentsFromName)) + if (!T6::attachment_unique::ExtractAttachmentsFromAssetName(assetName, attachmentsFromName)) { std::cerr << std::format("Failed to determine attachments from attachment unique name \"{}\"\n", assetName); return false; @@ -159,86 +159,89 @@ namespace } } // namespace -bool InfoStringLoaderAttachmentUnique::ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector& attachmentList) +namespace T6::attachment_unique { - std::vector parts; - - auto attachCount = 1u; - auto partStart = 0u; - for (auto ci = 0u; ci < assetName.size(); ci++) + bool ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector& attachmentList) { - if (assetName[ci] == '_') + std::vector parts; + + auto attachCount = 1u; + auto partStart = 0u; + for (auto ci = 0u; ci < assetName.size(); ci++) { - parts.emplace_back(assetName, partStart, ci - partStart); - partStart = ci + 1; - } - else if (assetName[ci] == '+') - { - attachCount++; - parts.emplace_back(assetName, partStart, ci - partStart); - partStart = ci + 1; - } - } - - if (partStart < assetName.size()) - parts.emplace_back(assetName, partStart, assetName.size() - partStart); - - for (auto attachPartOffset = parts.size() - attachCount; attachPartOffset < parts.size(); attachPartOffset++) - { - auto& specifiedAttachName = parts[attachPartOffset]; - - for (auto& c : specifiedAttachName) - c = static_cast(tolower(c)); - - auto foundAttachment = false; - for (auto attachIndex = 0u; attachIndex < std::extent_v; attachIndex++) - { - if (specifiedAttachName == szAttachmentTypeNames[attachIndex]) + if (assetName[ci] == '_') { - attachmentList.push_back(static_cast(attachIndex)); - foundAttachment = true; - break; + parts.emplace_back(assetName, partStart, ci - partStart); + partStart = ci + 1; + } + else if (assetName[ci] == '+') + { + attachCount++; + parts.emplace_back(assetName, partStart, ci - partStart); + partStart = ci + 1; } } - if (!foundAttachment) - return false; + if (partStart < assetName.size()) + parts.emplace_back(assetName, partStart, assetName.size() - partStart); + + for (auto attachPartOffset = parts.size() - attachCount; attachPartOffset < parts.size(); attachPartOffset++) + { + auto& specifiedAttachName = parts[attachPartOffset]; + + for (auto& c : specifiedAttachName) + c = static_cast(tolower(c)); + + auto foundAttachment = false; + for (auto attachIndex = 0u; attachIndex < std::extent_v; attachIndex++) + { + if (specifiedAttachName == szAttachmentTypeNames[attachIndex]) + { + attachmentList.push_back(static_cast(attachIndex)); + foundAttachment = true; + break; + } + } + + if (!foundAttachment) + return false; + } + + return true; } - return true; -} - -InfoStringLoaderAttachmentUnique::InfoStringLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) - : m_memory(memory), - m_search_path(searchPath), - m_zone(zone) -{ -} - -AssetCreationResult InfoStringLoaderAttachmentUnique::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) -{ - auto* attachmentUniqueFull = m_memory.Alloc(); - attachmentUniqueFull->attachment.szInternalName = m_memory.Dup(assetName.c_str()); - - LinkAttachmentUniqueFullSubStructs(*attachmentUniqueFull); - - AssetRegistration registration(assetName, &attachmentUniqueFull->attachment); - - InfoStringToAttachmentUniqueConverter converter(infoString, - *attachmentUniqueFull, - m_zone.m_script_strings, - m_memory, - context, - registration, - attachment_unique_fields, - std::extent_v); - if (!converter.Convert()) + InfoStringLoader::InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) { - std::cerr << std::format("Failed to parse attachment unique: \"{}\"\n", assetName); - return AssetCreationResult::Failure(); } - CalculateAttachmentUniqueFields(assetName, *attachmentUniqueFull); + AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) + { + auto* attachmentUniqueFull = m_memory.Alloc(); + attachmentUniqueFull->attachment.szInternalName = m_memory.Dup(assetName.c_str()); - return AssetCreationResult::Success(context.AddAsset(std::move(registration))); -} + LinkAttachmentUniqueFullSubStructs(*attachmentUniqueFull); + + AssetRegistration registration(assetName, &attachmentUniqueFull->attachment); + + InfoStringToAttachmentUniqueConverter converter(infoString, + *attachmentUniqueFull, + m_zone.m_script_strings, + m_memory, + context, + registration, + attachment_unique_fields, + std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse attachment unique: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + CalculateAttachmentUniqueFields(assetName, *attachmentUniqueFull); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } +} // namespace T6::attachment_unique diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.h b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueInfoStringLoaderT6.h similarity index 59% rename from src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.h rename to src/ObjLoading/Game/T6/Weapon/AttachmentUniqueInfoStringLoaderT6.h index 3ff89621..5c50650b 100644 --- a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderAttachmentUniqueT6.h +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueInfoStringLoaderT6.h @@ -7,20 +7,20 @@ #include -namespace T6 +namespace T6::attachment_unique { - class InfoStringLoaderAttachmentUnique + bool ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector& attachmentList); + + class InfoStringLoader { public: - InfoStringLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); - static bool ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector& attachmentList); - private: MemoryManager& m_memory; ISearchPath& m_search_path; Zone& m_zone; }; -} // namespace T6 +} // namespace T6::attachment_unique diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.cpp b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueRawLoaderT6.cpp similarity index 63% rename from src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.cpp rename to src/ObjLoading/Game/T6/Weapon/AttachmentUniqueRawLoaderT6.cpp index f3af0c30..4023168f 100644 --- a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueRawLoaderT6.cpp @@ -1,22 +1,24 @@ -#include "RawLoaderAttachmentUniqueT6.h" +#include "AttachmentUniqueRawLoaderT6.h" +#include "AttachmentUniqueInfoStringLoaderT6.h" #include "Game/T6/ObjConstantsT6.h" #include "Game/T6/T6.h" #include "InfoString/InfoString.h" -#include "InfoStringLoaderAttachmentUniqueT6.h" +#include "Weapon/AttachmentUniqueCommon.h" #include #include #include using namespace T6; +using namespace ::attachment_unique; namespace { - class RawLoaderAttachmentUnique final : public AssetCreator + class RawLoader final : public AssetCreator { public: - RawLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + RawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) : m_search_path(searchPath), m_info_string_loader(memory, searchPath, zone) { @@ -24,7 +26,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto fileName = std::format("attachmentunique/{}", assetName); + const auto fileName = GetFileNameForAssetName(assetName); const auto file = m_search_path.Open(fileName); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -41,14 +43,14 @@ namespace private: ISearchPath& m_search_path; - InfoStringLoaderAttachmentUnique m_info_string_loader; + T6::attachment_unique::InfoStringLoader m_info_string_loader; }; } // namespace -namespace T6 +namespace T6::attachment_unique { - std::unique_ptr> CreateRawAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + std::unique_ptr> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) { - return std::make_unique(memory, searchPath, zone); + return std::make_unique(memory, searchPath, zone); } -} // namespace T6 +} // namespace T6::attachment_unique diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.h b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueRawLoaderT6.h similarity index 61% rename from src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.h rename to src/ObjLoading/Game/T6/Weapon/AttachmentUniqueRawLoaderT6.h index 47b66237..afdf3584 100644 --- a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentUniqueT6.h +++ b/src/ObjLoading/Game/T6/Weapon/AttachmentUniqueRawLoaderT6.h @@ -7,7 +7,7 @@ #include -namespace T6 +namespace T6::attachment_unique { - std::unique_ptr> CreateRawAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); -} // namespace T6 + std::unique_ptr> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6::attachment_unique diff --git a/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp b/src/ObjLoading/Game/T6/Weapon/CamoJsonLoaderT6.cpp similarity index 84% rename from src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp rename to src/ObjLoading/Game/T6/Weapon/CamoJsonLoaderT6.cpp index 75bbe247..65a57723 100644 --- a/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/CamoJsonLoaderT6.cpp @@ -1,14 +1,18 @@ -#include "JsonWeaponCamoLoaderT6.h" +#include "CamoJsonLoaderT6.h" -#include "Game/T6/CommonT6.h" #include "Game/T6/Json/JsonWeaponCamo.h" +#include "Game/T6/T6.h" +#include "Pool/GlobalAssetPool.h" +#include "Weapon/CamoCommon.h" +#include #include #include #include using namespace nlohmann; using namespace T6; +using namespace ::camo; namespace { @@ -55,7 +59,7 @@ namespace private: static void PrintError(const WeaponCamo& weaponCamo, const std::string& message) { - std::cerr << "Cannot load weapon camo \"" << weaponCamo.name << "\": " << message << "\n"; + std::cerr << std::format("Cannot load weapon camo \"{}\": {}\n", weaponCamo.name, message); } bool CreateWeaponCamoSetFromJson(const JsonWeaponCamoSet& jWeaponCamoSet, WeaponCamoSet& weaponCamoSet, const WeaponCamo& weaponCamo) const @@ -237,15 +241,46 @@ namespace AssetCreationContext& m_context; AssetRegistration& m_registration; }; + + class WeaponCamoLoader final : public AssetCreator + { + public: + WeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override + { + const auto file = m_search_path.Open(GetJsonFileNameForAssetName(assetName)); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + + auto* weaponCamo = m_memory.Alloc(); + weaponCamo->name = m_memory.Dup(assetName.c_str()); + + AssetRegistration registration(assetName, weaponCamo); + const JsonLoader loader(*file.m_stream, m_memory, context, registration); + if (!loader.Load(*weaponCamo)) + { + std::cerr << std::format("Failed to load weapon camo \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; } // namespace -namespace T6 +namespace T6::camo { - bool LoadWeaponCamoAsJson( - std::istream& stream, WeaponCamo& weaponCamo, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration) + std::unique_ptr> CreateJsonLoader(MemoryManager& memory, ISearchPath& searchPath) { - const JsonLoader loader(stream, memory, context, registration); - - return loader.Load(weaponCamo); + return std::make_unique(memory, searchPath); } -} // namespace T6 +} // namespace T6::camo diff --git a/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.h b/src/ObjLoading/Game/T6/Weapon/CamoJsonLoaderT6.h similarity index 50% rename from src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.h rename to src/ObjLoading/Game/T6/Weapon/CamoJsonLoaderT6.h index b5270fba..3b5f7f7f 100644 --- a/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.h +++ b/src/ObjLoading/Game/T6/Weapon/CamoJsonLoaderT6.h @@ -7,7 +7,7 @@ #include -namespace T6 +namespace T6::camo { - std::unique_ptr> CreateWeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath); -} // namespace T6 + std::unique_ptr> CreateJsonLoader(MemoryManager& memory, ISearchPath& searchPath); +} // namespace T6::camo diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.h b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.h deleted file mode 100644 index 6455b204..00000000 --- a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentT6.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "Asset/IAssetCreator.h" -#include "Game/T6/T6.h" -#include "Gdt/IGdtQueryable.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" - -#include - -namespace T6 -{ - std::unique_ptr> CreateGdtAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.h b/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.h deleted file mode 100644 index 3e39221d..00000000 --- a/src/ObjLoading/Game/T6/Weapon/GdtLoaderAttachmentUniqueT6.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "Asset/IAssetCreator.h" -#include "Game/T6/T6.h" -#include "Gdt/IGdtQueryable.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" - -#include - -namespace T6 -{ - std::unique_ptr> - CreateGdtAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.h b/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.h deleted file mode 100644 index 6f5aea17..00000000 --- a/src/ObjLoading/Game/T6/Weapon/JsonWeaponCamoLoaderT6.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "Asset/AssetCreationContext.h" -#include "Asset/AssetRegistration.h" -#include "Game/T6/T6.h" -#include "Utils/MemoryManager.h" - -#include - -namespace T6 -{ - bool LoadWeaponCamoAsJson( - std::istream& stream, WeaponCamo& weaponCamo, MemoryManager& memory, AssetCreationContext& context, AssetRegistration& registration); -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.cpp b/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.cpp deleted file mode 100644 index c3409ac8..00000000 --- a/src/ObjLoading/Game/T6/Weapon/LoaderWeaponCamoT6.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "LoaderWeaponCamoT6.h" - -#include "Game/T6/T6.h" -#include "JsonWeaponCamoLoaderT6.h" -#include "Pool/GlobalAssetPool.h" - -#include -#include -#include - -using namespace T6; - -namespace -{ - class WeaponCamoLoader final : public AssetCreator - { - public: - WeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath) - : m_memory(memory), - m_search_path(searchPath) - { - } - - AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override - { - const auto file = m_search_path.Open(std::format("camo/{}.json", assetName)); - if (!file.IsOpen()) - return AssetCreationResult::NoAction(); - - auto* weaponCamo = m_memory.Alloc(); - weaponCamo->name = m_memory.Dup(assetName.c_str()); - - AssetRegistration registration(assetName, weaponCamo); - if (!LoadWeaponCamoAsJson(*file.m_stream, *weaponCamo, m_memory, context, registration)) - { - std::cerr << std::format("Failed to load weapon camo \"{}\"\n", assetName); - return AssetCreationResult::Failure(); - } - - return AssetCreationResult::Success(context.AddAsset(std::move(registration))); - } - - private: - MemoryManager& m_memory; - ISearchPath& m_search_path; - }; -} // namespace - -namespace T6 -{ - std::unique_ptr> CreateWeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath) - { - return std::make_unique(memory, searchPath); - } -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.h b/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.h deleted file mode 100644 index d83631d1..00000000 --- a/src/ObjLoading/Game/T6/Weapon/RawLoaderAttachmentT6.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Asset/IAssetCreator.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" - -#include - -namespace T6 -{ - std::unique_ptr> CreateRawAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.h b/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.h deleted file mode 100644 index 8eedbb71..00000000 --- a/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Asset/IAssetCreator.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" - -#include - -namespace T6 -{ - std::unique_ptr> CreateRawWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); -} // namespace T6 diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.cpp b/src/ObjLoading/Game/T6/Weapon/WeaponGdtLoaderT6.cpp similarity index 80% rename from src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.cpp rename to src/ObjLoading/Game/T6/Weapon/WeaponGdtLoaderT6.cpp index 702213dd..9caabce5 100644 --- a/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/WeaponGdtLoaderT6.cpp @@ -1,9 +1,9 @@ -#include "GdtLoaderWeaponT6.h" +#include "WeaponGdtLoaderT6.h" #include "Game/T6/ObjConstantsT6.h" #include "Game/T6/T6.h" #include "InfoString/InfoString.h" -#include "InfoStringLoaderWeaponT6.h" +#include "WeaponInfoStringLoaderT6.h" #include #include @@ -40,14 +40,14 @@ namespace private: IGdtQueryable& m_gdt; - InfoStringLoaderWeapon m_info_string_loader; + T6::weapon::InfoStringLoader m_info_string_loader; }; } // namespace -namespace T6 +namespace T6::weapon { - std::unique_ptr> CreateGdtWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) + std::unique_ptr> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone) { return std::make_unique(memory, searchPath, gdt, zone); } -} // namespace T6 +} // namespace T6::weapon diff --git a/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.h b/src/ObjLoading/Game/T6/Weapon/WeaponGdtLoaderT6.h similarity index 50% rename from src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.h rename to src/ObjLoading/Game/T6/Weapon/WeaponGdtLoaderT6.h index fdb1882b..34670907 100644 --- a/src/ObjLoading/Game/T6/Weapon/GdtLoaderWeaponT6.h +++ b/src/ObjLoading/Game/T6/Weapon/WeaponGdtLoaderT6.h @@ -8,7 +8,7 @@ #include -namespace T6 +namespace T6::weapon { - std::unique_ptr> CreateGdtWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); -} // namespace T6 + std::unique_ptr> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone); +} // namespace T6::weapon diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.cpp b/src/ObjLoading/Game/T6/Weapon/WeaponInfoStringLoaderT6.cpp similarity index 94% rename from src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.cpp rename to src/ObjLoading/Game/T6/Weapon/WeaponInfoStringLoaderT6.cpp index 6d97ceab..d5cefc6f 100644 --- a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/WeaponInfoStringLoaderT6.cpp @@ -1,10 +1,10 @@ -#include "InfoStringLoaderWeaponT6.h" +#include "WeaponInfoStringLoaderT6.h" +#include "AttachmentUniqueInfoStringLoaderT6.h" #include "Game/T6/InfoString/InfoStringToStructConverter.h" #include "Game/T6/T6.h" #include "Game/T6/Weapon/WeaponFields.h" #include "Game/T6/Weapon/WeaponStrings.h" -#include "InfoStringLoaderAttachmentUniqueT6.h" #include "Weapon/AccuracyGraphLoader.h" #include @@ -568,8 +568,7 @@ namespace && weapon.attachmentUniques[attachmentUniqueIndex]->attachmentType != attachmentUnique.attachmentType) { std::vector attachments; - if (InfoStringLoaderAttachmentUnique::ExtractAttachmentsFromAssetName(weapon.attachmentUniques[attachmentUniqueIndex]->szInternalName, - attachments) + if (T6::attachment_unique::ExtractAttachmentsFromAssetName(weapon.attachmentUniques[attachmentUniqueIndex]->szInternalName, attachments) && attachments.front() == attachmentUnique.attachmentType) { if (lastSibling == nullptr) @@ -600,34 +599,37 @@ namespace } } // namespace -InfoStringLoaderWeapon::InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) - : m_memory(memory), - m_search_path(searchPath), - m_zone(zone) +namespace T6::weapon { -} - -AssetCreationResult InfoStringLoaderWeapon::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) -{ - auto* weaponFullDef = m_memory.Alloc(); - weaponFullDef->weapVariantDef.szInternalName = m_memory.Dup(assetName.c_str()); - - LinkWeaponFullDefSubStructs(*weaponFullDef); - - AssetRegistration registration(assetName, &weaponFullDef->weapVariantDef); - - InfoStringToWeaponConverter converter( - infoString, *weaponFullDef, m_zone.m_script_strings, m_memory, context, registration, weapon_fields, std::extent_v); - if (!converter.Convert()) + InfoStringLoader::InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + : m_memory(memory), + m_search_path(searchPath), + m_zone(zone) { - std::cerr << std::format("Failed to parse weapon: \"{}\"\n", assetName); - return AssetCreationResult::Failure(); } - CalculateWeaponFields(*weaponFullDef); - CalculateAttachmentFields(*weaponFullDef); + AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context) + { + auto* weaponFullDef = m_memory.Alloc(); + weaponFullDef->weapVariantDef.szInternalName = m_memory.Dup(assetName.c_str()); - LoadAccuracyGraphs(*weaponFullDef, m_memory, m_search_path, context); + LinkWeaponFullDefSubStructs(*weaponFullDef); - return AssetCreationResult::Success(context.AddAsset(std::move(registration))); -} + AssetRegistration registration(assetName, &weaponFullDef->weapVariantDef); + + InfoStringToWeaponConverter converter( + infoString, *weaponFullDef, m_zone.m_script_strings, m_memory, context, registration, weapon_fields, std::extent_v); + if (!converter.Convert()) + { + std::cerr << std::format("Failed to parse weapon: \"{}\"\n", assetName); + return AssetCreationResult::Failure(); + } + + CalculateWeaponFields(*weaponFullDef); + CalculateAttachmentFields(*weaponFullDef); + + LoadAccuracyGraphs(*weaponFullDef, m_memory, m_search_path, context); + + return AssetCreationResult::Success(context.AddAsset(std::move(registration))); + } +} // namespace T6::weapon diff --git a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.h b/src/ObjLoading/Game/T6/Weapon/WeaponInfoStringLoaderT6.h similarity index 71% rename from src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.h rename to src/ObjLoading/Game/T6/Weapon/WeaponInfoStringLoaderT6.h index f745963a..7ba8a410 100644 --- a/src/ObjLoading/Game/T6/Weapon/InfoStringLoaderWeaponT6.h +++ b/src/ObjLoading/Game/T6/Weapon/WeaponInfoStringLoaderT6.h @@ -4,12 +4,12 @@ #include "Asset/AssetCreationResult.h" #include "InfoString/InfoString.h" -namespace T6 +namespace T6::weapon { - class InfoStringLoaderWeapon + class InfoStringLoader { public: - InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); + InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context); @@ -18,4 +18,4 @@ namespace T6 ISearchPath& m_search_path; Zone& m_zone; }; -} // namespace T6 +} // namespace T6::weapon diff --git a/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.cpp b/src/ObjLoading/Game/T6/Weapon/WeaponRawLoaderT6.cpp similarity index 63% rename from src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.cpp rename to src/ObjLoading/Game/T6/Weapon/WeaponRawLoaderT6.cpp index 36cbcd48..09304559 100644 --- a/src/ObjLoading/Game/T6/Weapon/RawLoaderWeaponT6.cpp +++ b/src/ObjLoading/Game/T6/Weapon/WeaponRawLoaderT6.cpp @@ -1,22 +1,24 @@ -#include "RawLoaderWeaponT6.h" +#include "WeaponRawLoaderT6.h" #include "Game/T6/ObjConstantsT6.h" #include "Game/T6/T6.h" #include "InfoString/InfoString.h" -#include "InfoStringLoaderWeaponT6.h" +#include "Weapon/WeaponCommon.h" +#include "WeaponInfoStringLoaderT6.h" #include #include #include using namespace T6; +using namespace ::weapon; namespace { - class RawLoaderWeapon final : public AssetCreator + class RawLoader final : public AssetCreator { public: - RawLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + RawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) : m_search_path(searchPath), m_info_string_loader(memory, searchPath, zone) { @@ -24,7 +26,7 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { - const auto fileName = std::format("weapons/{}", assetName); + const auto fileName = GetFileNameForAssetName(assetName); const auto file = m_search_path.Open(fileName); if (!file.IsOpen()) return AssetCreationResult::NoAction(); @@ -41,14 +43,14 @@ namespace private: ISearchPath& m_search_path; - InfoStringLoaderWeapon m_info_string_loader; + T6::weapon::InfoStringLoader m_info_string_loader; }; } // namespace -namespace T6 +namespace T6::weapon { - std::unique_ptr> CreateRawWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) + std::unique_ptr> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone) { - return std::make_unique(memory, searchPath, zone); + return std::make_unique(memory, searchPath, zone); } -} // namespace T6 +} // namespace T6::weapon diff --git a/src/ObjLoading/Game/T6/Weapon/WeaponRawLoaderT6.h b/src/ObjLoading/Game/T6/Weapon/WeaponRawLoaderT6.h new file mode 100644 index 00000000..e02ce562 --- /dev/null +++ b/src/ObjLoading/Game/T6/Weapon/WeaponRawLoaderT6.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Game/T6/T6.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace T6::weapon +{ + std::unique_ptr> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone); +} // namespace T6::weapon diff --git a/src/ObjWriting/Game/IW3/ObjWriterIW3.cpp b/src/ObjWriting/Game/IW3/ObjWriterIW3.cpp index 8a7ce5e0..8e840474 100644 --- a/src/ObjWriting/Game/IW3/ObjWriterIW3.cpp +++ b/src/ObjWriting/Game/IW3/ObjWriterIW3.cpp @@ -10,7 +10,6 @@ #include "RawFile/RawFileDumperIW3.h" #include "Sound/LoadedSoundDumperIW3.h" #include "StringTable/StringTableDumperIW3.h" -#include "Weapon/AssetDumperWeapon.h" using namespace IW3; diff --git a/src/ObjWriting/Game/IW3/Weapon/AssetDumperWeapon.cpp b/src/ObjWriting/Game/IW3/Weapon/AssetDumperWeapon.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ObjWriting/Game/IW3/Weapon/AssetDumperWeapon.h b/src/ObjWriting/Game/IW3/Weapon/AssetDumperWeapon.h deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp index 3723fbe2..4ab99c42 100644 --- a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp +++ b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp @@ -24,7 +24,7 @@ #include "Techset/TechsetDumperIW4.h" #include "Tracer/TracerDumperIW4.h" #include "Vehicle/VehicleDumperIW4.h" -#include "Weapon/AssetDumperWeapon.h" +#include "Weapon/WeaponDumperIW4.h" using namespace IW4; @@ -66,7 +66,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const DUMP_ASSET_POOL(AssetDumperMenuList, m_menu_list, ASSET_TYPE_MENULIST) DUMP_ASSET_POOL(AssetDumperMenuDef, m_menu_def, ASSET_TYPE_MENU) DUMP_ASSET_POOL(localize::Dumper, m_localize, ASSET_TYPE_LOCALIZE_ENTRY) - DUMP_ASSET_POOL(AssetDumperWeapon, m_weapon, ASSET_TYPE_WEAPON) + DUMP_ASSET_POOL(weapon::Dumper, m_weapon, ASSET_TYPE_WEAPON) // DUMP_ASSET_POOL(AssetDumperSndDriverGlobals, m_snd_driver_globals, ASSET_TYPE_SNDDRIVER_GLOBALS) // DUMP_ASSET_POOL(AssetDumperFxEffectDef, m_fx, ASSET_TYPE_FX) // DUMP_ASSET_POOL(AssetDumperFxImpactTable, m_fx_impact_table, ASSET_TYPE_IMPACT_FX) diff --git a/src/ObjWriting/Game/IW4/Weapon/AssetDumperWeapon.h b/src/ObjWriting/Game/IW4/Weapon/AssetDumperWeapon.h deleted file mode 100644 index 3abade7f..00000000 --- a/src/ObjWriting/Game/IW4/Weapon/AssetDumperWeapon.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "Dumping/AbstractAssetDumper.h" -#include "Game/IW4/IW4.h" -#include "InfoString/InfoString.h" - -namespace IW4 -{ - class AssetDumperWeapon final : public AbstractAssetDumper - { - static void CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef); - static InfoString CreateInfoString(XAssetInfo* asset); - static void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset); - - protected: - bool ShouldDump(XAssetInfo* asset) override; - void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; - }; -} // namespace IW4 diff --git a/src/ObjWriting/Game/IW4/Weapon/AssetDumperWeapon.cpp b/src/ObjWriting/Game/IW4/Weapon/WeaponDumperIW4.cpp similarity index 50% rename from src/ObjWriting/Game/IW4/Weapon/AssetDumperWeapon.cpp rename to src/ObjWriting/Game/IW4/Weapon/WeaponDumperIW4.cpp index 0d388e3c..7fce3396 100644 --- a/src/ObjWriting/Game/IW4/Weapon/AssetDumperWeapon.cpp +++ b/src/ObjWriting/Game/IW4/Weapon/WeaponDumperIW4.cpp @@ -1,4 +1,4 @@ -#include "AssetDumperWeapon.h" +#include "WeaponDumperIW4.h" #include "Game/IW4/CommonIW4.h" #include "Game/IW4/InfoString/EnumStrings.h" @@ -6,6 +6,7 @@ #include "Game/IW4/ObjConstantsIW4.h" #include "Game/IW4/Weapon/WeaponFields.h" #include "Weapon/AccuracyGraphWriter.h" +#include "Weapon/WeaponCommon.h" #include #include @@ -13,8 +14,9 @@ #include using namespace IW4; +using namespace ::weapon; -namespace IW4 +namespace { class InfoStringFromWeaponConverter final : public InfoStringFromStructConverter { @@ -237,195 +239,201 @@ namespace IW4 return graph; } -} // namespace IW4 -void AssetDumperWeapon::CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef) -{ - fullDef->weapCompleteDef = *weapon; - - if (weapon->weapDef) + void CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef) { - fullDef->weapDef = *weapon->weapDef; - fullDef->weapCompleteDef.weapDef = &fullDef->weapDef; + fullDef->weapCompleteDef = *weapon; + + if (weapon->weapDef) + { + fullDef->weapDef = *weapon->weapDef; + fullDef->weapCompleteDef.weapDef = &fullDef->weapDef; + } + + if (weapon->hideTags) + { + assert(sizeof(WeaponFullDef::hideTags) >= sizeof(scr_string_t) * std::extent_v); + memcpy(fullDef->hideTags, weapon->hideTags, sizeof(scr_string_t) * std::extent_v); + fullDef->weapCompleteDef.hideTags = fullDef->hideTags; + } + + if (weapon->szXAnims) + { + assert(sizeof(WeaponFullDef::szXAnims) >= sizeof(void*) * NUM_WEAP_ANIMS); + memcpy(fullDef->szXAnims, weapon->szXAnims, sizeof(void*) * NUM_WEAP_ANIMS); + fullDef->weapCompleteDef.szXAnims = fullDef->szXAnims; + } + + if (fullDef->weapDef.gunXModel) + { + assert(sizeof(WeaponFullDef::gunXModel) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->gunXModel, fullDef->weapDef.gunXModel, sizeof(void*) * std::extent_v); + fullDef->weapDef.gunXModel = fullDef->gunXModel; + } + + if (fullDef->weapDef.szXAnimsRightHanded) + { + assert(sizeof(WeaponFullDef::szXAnimsRightHanded) >= sizeof(void*) * NUM_WEAP_ANIMS); + memcpy(fullDef->szXAnimsRightHanded, fullDef->weapDef.szXAnimsRightHanded, sizeof(void*) * NUM_WEAP_ANIMS); + fullDef->weapDef.szXAnimsRightHanded = fullDef->szXAnimsRightHanded; + } + + if (fullDef->weapDef.szXAnimsLeftHanded) + { + assert(sizeof(WeaponFullDef::szXAnimsLeftHanded) >= sizeof(void*) * NUM_WEAP_ANIMS); + memcpy(fullDef->szXAnimsLeftHanded, fullDef->weapDef.szXAnimsLeftHanded, sizeof(void*) * NUM_WEAP_ANIMS); + fullDef->weapDef.szXAnimsLeftHanded = fullDef->szXAnimsLeftHanded; + } + + if (fullDef->weapDef.notetrackSoundMapKeys) + { + assert(sizeof(WeaponFullDef::notetrackSoundMapKeys) >= sizeof(scr_string_t) * std::extent_v); + memcpy(fullDef->notetrackSoundMapKeys, + fullDef->weapDef.notetrackSoundMapKeys, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackSoundMapKeys = fullDef->notetrackSoundMapKeys; + } + + if (fullDef->weapDef.notetrackSoundMapValues) + { + assert(sizeof(WeaponFullDef::notetrackSoundMapValues) >= sizeof(scr_string_t) * std::extent_v); + memcpy(fullDef->notetrackSoundMapValues, + fullDef->weapDef.notetrackSoundMapValues, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackSoundMapValues = fullDef->notetrackSoundMapValues; + } + + if (fullDef->weapDef.notetrackRumbleMapKeys) + { + assert(sizeof(WeaponFullDef::notetrackRumbleMapKeys) >= sizeof(scr_string_t) * std::extent_v); + memcpy(fullDef->notetrackRumbleMapKeys, + fullDef->weapDef.notetrackRumbleMapKeys, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackRumbleMapKeys = fullDef->notetrackRumbleMapKeys; + } + + if (fullDef->weapDef.notetrackRumbleMapValues) + { + assert(sizeof(WeaponFullDef::notetrackRumbleMapValues) >= sizeof(scr_string_t) * std::extent_v); + memcpy(fullDef->notetrackRumbleMapValues, + fullDef->weapDef.notetrackRumbleMapValues, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackRumbleMapValues = fullDef->notetrackRumbleMapValues; + } + + if (fullDef->weapDef.worldModel) + { + assert(sizeof(WeaponFullDef::worldModel) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->worldModel, fullDef->weapDef.worldModel, sizeof(void*) * std::extent_v); + fullDef->weapDef.worldModel = fullDef->worldModel; + } + + if (fullDef->weapDef.parallelBounce) + { + assert(sizeof(WeaponFullDef::parallelBounce) >= sizeof(float) * std::extent_v); + memcpy(fullDef->parallelBounce, fullDef->weapDef.parallelBounce, sizeof(float) * std::extent_v); + fullDef->weapDef.parallelBounce = fullDef->parallelBounce; + } + + if (fullDef->weapDef.perpendicularBounce) + { + assert(sizeof(WeaponFullDef::perpendicularBounce) >= sizeof(float) * std::extent_v); + memcpy(fullDef->perpendicularBounce, + fullDef->weapDef.perpendicularBounce, + sizeof(float) * std::extent_v); + fullDef->weapDef.perpendicularBounce = fullDef->perpendicularBounce; + } + + if (fullDef->weapDef.locationDamageMultipliers) + { + assert(sizeof(WeaponFullDef::locationDamageMultipliers) >= sizeof(float) * std::extent_v); + memcpy(fullDef->locationDamageMultipliers, + fullDef->weapDef.locationDamageMultipliers, + sizeof(float) * std::extent_v); + fullDef->weapDef.locationDamageMultipliers = fullDef->locationDamageMultipliers; + } } - if (weapon->hideTags) + InfoString CreateInfoString(XAssetInfo* asset) { - assert(sizeof(WeaponFullDef::hideTags) >= sizeof(scr_string_t) * std::extent_v); - memcpy(fullDef->hideTags, weapon->hideTags, sizeof(scr_string_t) * std::extent_v); - fullDef->weapCompleteDef.hideTags = fullDef->hideTags; + const auto fullDef = std::make_unique(); + memset(fullDef.get(), 0, sizeof(WeaponFullDef)); + CopyToFullDef(asset->Asset(), fullDef.get()); + + InfoStringFromWeaponConverter converter(fullDef.get(), + weapon_fields, + std::extent_v, + [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 ""; + + return asset->m_zone->m_script_strings[scrStr]; + }); + + return converter.Convert(); } - if (weapon->szXAnims) + void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset) { - assert(sizeof(WeaponFullDef::szXAnims) >= sizeof(void*) * NUM_WEAP_ANIMS); - memcpy(fullDef->szXAnims, weapon->szXAnims, sizeof(void*) * NUM_WEAP_ANIMS); - fullDef->weapCompleteDef.szXAnims = fullDef->szXAnims; - } + auto* accuracyGraphWriter = context.GetZoneAssetDumperState(); + const auto weapon = asset->Asset(); + const auto* weapDef = weapon->weapDef; - if (fullDef->weapDef.gunXModel) - { - assert(sizeof(WeaponFullDef::gunXModel) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->gunXModel, fullDef->weapDef.gunXModel, sizeof(void*) * std::extent_v); - fullDef->weapDef.gunXModel = fullDef->gunXModel; - } - - if (fullDef->weapDef.szXAnimsRightHanded) - { - assert(sizeof(WeaponFullDef::szXAnimsRightHanded) >= sizeof(void*) * NUM_WEAP_ANIMS); - memcpy(fullDef->szXAnimsRightHanded, fullDef->weapDef.szXAnimsRightHanded, sizeof(void*) * NUM_WEAP_ANIMS); - fullDef->weapDef.szXAnimsRightHanded = fullDef->szXAnimsRightHanded; - } - - if (fullDef->weapDef.szXAnimsLeftHanded) - { - assert(sizeof(WeaponFullDef::szXAnimsLeftHanded) >= sizeof(void*) * NUM_WEAP_ANIMS); - memcpy(fullDef->szXAnimsLeftHanded, fullDef->weapDef.szXAnimsLeftHanded, sizeof(void*) * NUM_WEAP_ANIMS); - fullDef->weapDef.szXAnimsLeftHanded = fullDef->szXAnimsLeftHanded; - } - - if (fullDef->weapDef.notetrackSoundMapKeys) - { - assert(sizeof(WeaponFullDef::notetrackSoundMapKeys) >= sizeof(scr_string_t) * std::extent_v); - memcpy(fullDef->notetrackSoundMapKeys, - fullDef->weapDef.notetrackSoundMapKeys, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackSoundMapKeys = fullDef->notetrackSoundMapKeys; - } - - if (fullDef->weapDef.notetrackSoundMapValues) - { - assert(sizeof(WeaponFullDef::notetrackSoundMapValues) >= sizeof(scr_string_t) * std::extent_v); - memcpy(fullDef->notetrackSoundMapValues, - fullDef->weapDef.notetrackSoundMapValues, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackSoundMapValues = fullDef->notetrackSoundMapValues; - } - - if (fullDef->weapDef.notetrackRumbleMapKeys) - { - assert(sizeof(WeaponFullDef::notetrackRumbleMapKeys) >= sizeof(scr_string_t) * std::extent_v); - memcpy(fullDef->notetrackRumbleMapKeys, - fullDef->weapDef.notetrackRumbleMapKeys, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackRumbleMapKeys = fullDef->notetrackRumbleMapKeys; - } - - if (fullDef->weapDef.notetrackRumbleMapValues) - { - assert(sizeof(WeaponFullDef::notetrackRumbleMapValues) >= sizeof(scr_string_t) * std::extent_v); - memcpy(fullDef->notetrackRumbleMapValues, - fullDef->weapDef.notetrackRumbleMapValues, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackRumbleMapValues = fullDef->notetrackRumbleMapValues; - } - - if (fullDef->weapDef.worldModel) - { - assert(sizeof(WeaponFullDef::worldModel) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->worldModel, fullDef->weapDef.worldModel, sizeof(void*) * std::extent_v); - fullDef->weapDef.worldModel = fullDef->worldModel; - } - - if (fullDef->weapDef.parallelBounce) - { - assert(sizeof(WeaponFullDef::parallelBounce) >= sizeof(float) * std::extent_v); - memcpy(fullDef->parallelBounce, fullDef->weapDef.parallelBounce, sizeof(float) * std::extent_v); - fullDef->weapDef.parallelBounce = fullDef->parallelBounce; - } - - if (fullDef->weapDef.perpendicularBounce) - { - assert(sizeof(WeaponFullDef::perpendicularBounce) >= sizeof(float) * std::extent_v); - memcpy(fullDef->perpendicularBounce, fullDef->weapDef.perpendicularBounce, sizeof(float) * std::extent_v); - fullDef->weapDef.perpendicularBounce = fullDef->perpendicularBounce; - } - - if (fullDef->weapDef.locationDamageMultipliers) - { - assert(sizeof(WeaponFullDef::locationDamageMultipliers) >= sizeof(float) * std::extent_v); - memcpy(fullDef->locationDamageMultipliers, - fullDef->weapDef.locationDamageMultipliers, - sizeof(float) * std::extent_v); - fullDef->weapDef.locationDamageMultipliers = fullDef->locationDamageMultipliers; - } -} - -InfoString AssetDumperWeapon::CreateInfoString(XAssetInfo* asset) -{ - const auto fullDef = std::make_unique(); - memset(fullDef.get(), 0, sizeof(WeaponFullDef)); - CopyToFullDef(asset->Asset(), fullDef.get()); - - InfoStringFromWeaponConverter converter(fullDef.get(), - weapon_fields, - std::extent_v, - [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 ""; - - return asset->m_zone->m_script_strings[scrStr]; - }); - - return converter.Convert(); -} - -void AssetDumperWeapon::DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset) -{ - auto* accuracyGraphWriter = context.GetZoneAssetDumperState(); - const auto weapon = asset->Asset(); - const auto* weapDef = weapon->weapDef; - - if (!weapDef) - return; - - if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots - && accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName)) - { - AccuracyGraphWriter::DumpAiVsAiGraph( - context, - ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName, weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount)); - } - - if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots - && accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName)) - { - AccuracyGraphWriter::DumpAiVsPlayerGraph(context, - ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName, - weapDef->originalAiVsPlayerAccuracyGraphKnots, - weapDef->originalAiVsPlayerAccuracyGraphKnotCount)); - } -} - -bool AssetDumperWeapon::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperWeapon::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - // 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); - - if (!assetFile) + if (!weapDef) return; - 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()); + if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots + && accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName)) + { + AccuracyGraphWriter::DumpAiVsAiGraph(context, + ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName, + weapDef->originalAiVsAiAccuracyGraphKnots, + weapDef->originalAiVsAiAccuracyGraphKnotCount)); + } + + if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots + && accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName)) + { + AccuracyGraphWriter::DumpAiVsPlayerGraph(context, + ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName, + weapDef->originalAiVsPlayerAccuracyGraphKnots, + weapDef->originalAiVsPlayerAccuracyGraphKnotCount)); + } + } +} // namespace + +namespace IW4::weapon +{ + bool Dumper::ShouldDump(XAssetInfo* asset) + { + return true; } - DumpAccuracyGraphs(context, asset); -} + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + // 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(GetFileNameForAssetName(asset->m_name)); + + if (!assetFile) + return; + + 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()); + } + + DumpAccuracyGraphs(context, asset); + } +} // namespace IW4::weapon diff --git a/src/ObjWriting/Game/IW4/Weapon/WeaponDumperIW4.h b/src/ObjWriting/Game/IW4/Weapon/WeaponDumperIW4.h new file mode 100644 index 00000000..0beff65e --- /dev/null +++ b/src/ObjWriting/Game/IW4/Weapon/WeaponDumperIW4.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/IW4/IW4.h" +#include "InfoString/InfoString.h" + +namespace IW4::weapon +{ + class Dumper final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} // namespace IW4::weapon diff --git a/src/ObjWriting/Game/IW5/ObjWriterIW5.cpp b/src/ObjWriting/Game/IW5/ObjWriterIW5.cpp index 43ce039f..8ed1bf82 100644 --- a/src/ObjWriting/Game/IW5/ObjWriterIW5.cpp +++ b/src/ObjWriting/Game/IW5/ObjWriterIW5.cpp @@ -14,8 +14,8 @@ #include "Script/ScriptDumperIW5.h" #include "Sound/LoadedSoundDumperIW5.h" #include "StringTable/StringTableDumperIW5.h" -#include "Weapon/AssetDumperWeapon.h" -#include "Weapon/AssetDumperWeaponAttachment.h" +#include "Weapon/AttachmentJsonDumperIW5.h" +#include "Weapon/WeaponDumperIW5.h" using namespace IW5; @@ -56,8 +56,8 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const DUMP_ASSET_POOL(AssetDumperMenuList, m_menu_list, ASSET_TYPE_MENULIST) DUMP_ASSET_POOL(AssetDumperMenuDef, m_menu_def, ASSET_TYPE_MENU) DUMP_ASSET_POOL(localize::Dumper, m_localize, ASSET_TYPE_LOCALIZE_ENTRY) - DUMP_ASSET_POOL(AssetDumperWeaponAttachment, m_attachment, ASSET_TYPE_ATTACHMENT) - DUMP_ASSET_POOL(AssetDumperWeapon, m_weapon, ASSET_TYPE_WEAPON) + DUMP_ASSET_POOL(attachment::JsonDumper, m_attachment, ASSET_TYPE_ATTACHMENT) + DUMP_ASSET_POOL(weapon::Dumper, m_weapon, ASSET_TYPE_WEAPON) // DUMP_ASSET_POOL(AssetDumperFxEffectDef, m_fx, ASSET_TYPE_FX) // DUMP_ASSET_POOL(AssetDumperFxImpactTable, m_fx_impact_table, ASSET_TYPE_IMPACT_FX) // DUMP_ASSET_POOL(AssetDumperSurfaceFxTable, m_surface_fx_table, ASSET_TYPE_SURFACE_FX) diff --git a/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeapon.h b/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeapon.h deleted file mode 100644 index d13b00a5..00000000 --- a/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeapon.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "Dumping/AbstractAssetDumper.h" -#include "Game/IW5/IW5.h" -#include "InfoString/InfoString.h" - -namespace IW5 -{ - class AssetDumperWeapon final : public AbstractAssetDumper - { - static void CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef); - static InfoString CreateInfoString(XAssetInfo* asset); - static void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset); - - protected: - bool ShouldDump(XAssetInfo* asset) override; - void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; - }; -} // namespace IW5 diff --git a/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeaponAttachment.cpp b/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeaponAttachment.cpp deleted file mode 100644 index d63e1649..00000000 --- a/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeaponAttachment.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "AssetDumperWeaponAttachment.h" - -#include "Game/IW5/Weapon/JsonWeaponAttachmentWriter.h" - -#include - -using namespace IW5; - -bool AssetDumperWeaponAttachment::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperWeaponAttachment::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto assetFile = context.OpenAssetFile(std::format("attachment/{}.json", asset->m_name)); - - if (!assetFile) - return; - - DumpWeaponAttachmentAsJson(*assetFile, asset->Asset(), context); -} diff --git a/src/ObjWriting/Game/IW5/Weapon/JsonWeaponAttachmentWriter.cpp b/src/ObjWriting/Game/IW5/Weapon/AttachmentJsonDumperIW5.cpp similarity index 96% rename from src/ObjWriting/Game/IW5/Weapon/JsonWeaponAttachmentWriter.cpp rename to src/ObjWriting/Game/IW5/Weapon/AttachmentJsonDumperIW5.cpp index 69f50071..763e96fe 100644 --- a/src/ObjWriting/Game/IW5/Weapon/JsonWeaponAttachmentWriter.cpp +++ b/src/ObjWriting/Game/IW5/Weapon/AttachmentJsonDumperIW5.cpp @@ -1,20 +1,22 @@ -#include "JsonWeaponAttachmentWriter.h" +#include "AttachmentJsonDumperIW5.h" #include "Game/IW5/CommonIW5.h" #include "Game/IW5/Weapon/JsonWeaponAttachment.h" +#include "Weapon/AttachmentCommon.h" #include #include using namespace nlohmann; using namespace IW5; +using namespace ::attachment; namespace { - class JsonDumper + class JsonDumperImpl { public: - JsonDumper(AssetDumpingContext& context, std::ostream& stream) + JsonDumperImpl(AssetDumpingContext& context, std::ostream& stream) : m_stream(stream) { } @@ -392,11 +394,21 @@ namespace }; } // namespace -namespace IW5 +namespace IW5::attachment { - void DumpWeaponAttachmentAsJson(std::ostream& stream, const WeaponAttachment* attachment, AssetDumpingContext& context) + bool JsonDumper::ShouldDump(XAssetInfo* asset) { - const JsonDumper dumper(context, stream); - dumper.Dump(attachment); + return true; } -} // namespace IW5 + + void JsonDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + const auto assetFile = context.OpenAssetFile(GetJsonFileNameForAssetName(asset->m_name)); + + if (!assetFile) + return; + + const JsonDumperImpl dumper(context, *assetFile); + dumper.Dump(asset->Asset()); + } +} // namespace IW5::attachment diff --git a/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeaponAttachment.h b/src/ObjWriting/Game/IW5/Weapon/AttachmentJsonDumperIW5.h similarity index 68% rename from src/ObjWriting/Game/IW5/Weapon/AssetDumperWeaponAttachment.h rename to src/ObjWriting/Game/IW5/Weapon/AttachmentJsonDumperIW5.h index 11f32004..26547be9 100644 --- a/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeaponAttachment.h +++ b/src/ObjWriting/Game/IW5/Weapon/AttachmentJsonDumperIW5.h @@ -3,12 +3,12 @@ #include "Dumping/AbstractAssetDumper.h" #include "Game/IW5/IW5.h" -namespace IW5 +namespace IW5::attachment { - class AssetDumperWeaponAttachment final : public AbstractAssetDumper + class JsonDumper final : public AbstractAssetDumper { protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; -} // namespace IW5 +} // namespace IW5::attachment diff --git a/src/ObjWriting/Game/IW5/Weapon/JsonWeaponAttachmentWriter.h b/src/ObjWriting/Game/IW5/Weapon/JsonWeaponAttachmentWriter.h deleted file mode 100644 index dc0a84c2..00000000 --- a/src/ObjWriting/Game/IW5/Weapon/JsonWeaponAttachmentWriter.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "Dumping/AssetDumpingContext.h" -#include "Game/IW5/IW5.h" - -#include - -namespace IW5 -{ - void DumpWeaponAttachmentAsJson(std::ostream& stream, const WeaponAttachment* attachment, AssetDumpingContext& context); -} // namespace IW5 diff --git a/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeapon.cpp b/src/ObjWriting/Game/IW5/Weapon/WeaponDumperIW5.cpp similarity index 67% rename from src/ObjWriting/Game/IW5/Weapon/AssetDumperWeapon.cpp rename to src/ObjWriting/Game/IW5/Weapon/WeaponDumperIW5.cpp index 83e4cc93..adc4b899 100644 --- a/src/ObjWriting/Game/IW5/Weapon/AssetDumperWeapon.cpp +++ b/src/ObjWriting/Game/IW5/Weapon/WeaponDumperIW5.cpp @@ -1,10 +1,11 @@ -#include "AssetDumperWeapon.h" +#include "WeaponDumperIW5.h" #include "Game/IW5/CommonIW5.h" #include "Game/IW5/InfoString/InfoStringFromStructConverter.h" #include "Game/IW5/ObjConstantsIW5.h" #include "Game/IW5/Weapon/WeaponFields.h" #include "Weapon/AccuracyGraphWriter.h" +#include "Weapon/WeaponCommon.h" #include #include @@ -14,8 +15,9 @@ #include using namespace IW5; +using namespace ::weapon; -namespace IW5 +namespace { class InfoStringFromWeaponConverter final : public InfoStringFromStructConverter { @@ -551,211 +553,217 @@ namespace IW5 return graph; } -} // namespace IW5 -void AssetDumperWeapon::CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef) -{ - fullDef->weapCompleteDef = *weapon; - - if (weapon->weapDef) + void CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFullDef* fullDef) { - fullDef->weapDef = *weapon->weapDef; - fullDef->weapCompleteDef.weapDef = &fullDef->weapDef; + fullDef->weapCompleteDef = *weapon; + + if (weapon->weapDef) + { + fullDef->weapDef = *weapon->weapDef; + fullDef->weapCompleteDef.weapDef = &fullDef->weapDef; + } + + if (weapon->hideTags) + { + memcpy(fullDef->hideTags, weapon->hideTags, sizeof(scr_string_t) * std::extent_v); + fullDef->weapCompleteDef.hideTags = fullDef->hideTags; + } + + if (weapon->szXAnims) + { + static_assert(std::extent_v == WEAP_ANIM_COUNT); + memcpy(fullDef->szXAnims, weapon->szXAnims, sizeof(void*) * WEAP_ANIM_COUNT); + fullDef->weapCompleteDef.szXAnims = fullDef->szXAnims; + } + + if (fullDef->weapDef.gunXModel) + { + memcpy(fullDef->gunXModel, fullDef->weapDef.gunXModel, sizeof(void*) * std::extent_v); + fullDef->weapDef.gunXModel = fullDef->gunXModel; + } + + if (fullDef->weapDef.szXAnimsRightHanded) + { + static_assert(std::extent_v == WEAP_ANIM_COUNT); + memcpy(fullDef->szXAnimsRightHanded, fullDef->weapDef.szXAnimsRightHanded, sizeof(void*) * WEAP_ANIM_COUNT); + fullDef->weapDef.szXAnimsRightHanded = fullDef->szXAnimsRightHanded; + } + + if (fullDef->weapDef.szXAnimsLeftHanded) + { + static_assert(std::extent_v == WEAP_ANIM_COUNT); + memcpy(fullDef->szXAnimsLeftHanded, fullDef->weapDef.szXAnimsLeftHanded, sizeof(void*) * WEAP_ANIM_COUNT); + fullDef->weapDef.szXAnimsLeftHanded = fullDef->szXAnimsLeftHanded; + } + + if (fullDef->weapDef.notetrackSoundMapKeys) + { + memcpy(fullDef->notetrackSoundMapKeys, + fullDef->weapDef.notetrackSoundMapKeys, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackSoundMapKeys = fullDef->notetrackSoundMapKeys; + } + + if (fullDef->weapDef.notetrackSoundMapValues) + { + memcpy(fullDef->notetrackSoundMapValues, + fullDef->weapDef.notetrackSoundMapValues, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackSoundMapValues = fullDef->notetrackSoundMapValues; + } + + if (fullDef->weapDef.notetrackRumbleMapKeys) + { + memcpy(fullDef->notetrackRumbleMapKeys, + fullDef->weapDef.notetrackRumbleMapKeys, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackRumbleMapKeys = fullDef->notetrackRumbleMapKeys; + } + + if (fullDef->weapDef.notetrackRumbleMapValues) + { + memcpy(fullDef->notetrackRumbleMapValues, + fullDef->weapDef.notetrackRumbleMapValues, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackRumbleMapValues = fullDef->notetrackRumbleMapValues; + } + + if (fullDef->weapDef.worldModel) + { + memcpy(fullDef->worldModel, fullDef->weapDef.worldModel, sizeof(void*) * std::extent_v); + fullDef->weapDef.worldModel = fullDef->worldModel; + } + + if (fullDef->weapDef.parallelBounce) + { + static_assert(std::extent_v == SURF_TYPE_COUNT); + assert(sizeof(WeaponFullDef::parallelBounce) >= sizeof(float) * std::extent_v); + memcpy(fullDef->parallelBounce, fullDef->weapDef.parallelBounce, sizeof(float) * std::extent_v); + fullDef->weapDef.parallelBounce = fullDef->parallelBounce; + } + + if (fullDef->weapDef.perpendicularBounce) + { + static_assert(std::extent_v == SURF_TYPE_COUNT); + assert(sizeof(WeaponFullDef::perpendicularBounce) >= sizeof(float) * std::extent_v); + memcpy(fullDef->perpendicularBounce, + fullDef->weapDef.perpendicularBounce, + sizeof(float) * std::extent_v); + fullDef->weapDef.perpendicularBounce = fullDef->perpendicularBounce; + } + + if (fullDef->weapDef.locationDamageMultipliers) + { + static_assert(std::extent_v == HITLOC_COUNT); + assert(sizeof(WeaponFullDef::locationDamageMultipliers) >= sizeof(float) * std::extent_v); + memcpy(fullDef->locationDamageMultipliers, + fullDef->weapDef.locationDamageMultipliers, + sizeof(float) * std::extent_v); + fullDef->weapDef.locationDamageMultipliers = fullDef->locationDamageMultipliers; + } + + if (fullDef->weapCompleteDef.scopes) + { + memcpy(fullDef->scopes, fullDef->weapCompleteDef.scopes, sizeof(void*) * std::extent_v); + fullDef->weapCompleteDef.scopes = fullDef->scopes; + } + + if (fullDef->weapCompleteDef.underBarrels) + { + memcpy(fullDef->underBarrels, fullDef->weapCompleteDef.underBarrels, sizeof(void*) * std::extent_v); + fullDef->weapCompleteDef.underBarrels = fullDef->underBarrels; + } + + if (fullDef->weapCompleteDef.others) + { + memcpy(fullDef->others, fullDef->weapCompleteDef.others, sizeof(void*) * std::extent_v); + fullDef->weapCompleteDef.others = fullDef->others; + } } - if (weapon->hideTags) + InfoString CreateInfoString(XAssetInfo* asset) { - memcpy(fullDef->hideTags, weapon->hideTags, sizeof(scr_string_t) * std::extent_v); - fullDef->weapCompleteDef.hideTags = fullDef->hideTags; + const auto fullDef = std::make_unique(); + memset(fullDef.get(), 0, sizeof(WeaponFullDef)); + CopyToFullDef(asset->Asset(), fullDef.get()); + + InfoStringFromWeaponConverter converter(fullDef.get(), + weapon_fields, + std::extent_v, + [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 ""; + + return asset->m_zone->m_script_strings[scrStr]; + }); + + return converter.Convert(); } - if (weapon->szXAnims) + void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset) { - static_assert(std::extent_v == WEAP_ANIM_COUNT); - memcpy(fullDef->szXAnims, weapon->szXAnims, sizeof(void*) * WEAP_ANIM_COUNT); - fullDef->weapCompleteDef.szXAnims = fullDef->szXAnims; - } + auto* accuracyGraphWriter = context.GetZoneAssetDumperState(); + const auto weapon = asset->Asset(); + const auto* weapDef = weapon->weapDef; - if (fullDef->weapDef.gunXModel) - { - memcpy(fullDef->gunXModel, fullDef->weapDef.gunXModel, sizeof(void*) * std::extent_v); - fullDef->weapDef.gunXModel = fullDef->gunXModel; - } - - if (fullDef->weapDef.szXAnimsRightHanded) - { - static_assert(std::extent_v == WEAP_ANIM_COUNT); - memcpy(fullDef->szXAnimsRightHanded, fullDef->weapDef.szXAnimsRightHanded, sizeof(void*) * WEAP_ANIM_COUNT); - fullDef->weapDef.szXAnimsRightHanded = fullDef->szXAnimsRightHanded; - } - - if (fullDef->weapDef.szXAnimsLeftHanded) - { - static_assert(std::extent_v == WEAP_ANIM_COUNT); - memcpy(fullDef->szXAnimsLeftHanded, fullDef->weapDef.szXAnimsLeftHanded, sizeof(void*) * WEAP_ANIM_COUNT); - fullDef->weapDef.szXAnimsLeftHanded = fullDef->szXAnimsLeftHanded; - } - - if (fullDef->weapDef.notetrackSoundMapKeys) - { - memcpy(fullDef->notetrackSoundMapKeys, - fullDef->weapDef.notetrackSoundMapKeys, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackSoundMapKeys = fullDef->notetrackSoundMapKeys; - } - - if (fullDef->weapDef.notetrackSoundMapValues) - { - memcpy(fullDef->notetrackSoundMapValues, - fullDef->weapDef.notetrackSoundMapValues, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackSoundMapValues = fullDef->notetrackSoundMapValues; - } - - if (fullDef->weapDef.notetrackRumbleMapKeys) - { - memcpy(fullDef->notetrackRumbleMapKeys, - fullDef->weapDef.notetrackRumbleMapKeys, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackRumbleMapKeys = fullDef->notetrackRumbleMapKeys; - } - - if (fullDef->weapDef.notetrackRumbleMapValues) - { - memcpy(fullDef->notetrackRumbleMapValues, - fullDef->weapDef.notetrackRumbleMapValues, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackRumbleMapValues = fullDef->notetrackRumbleMapValues; - } - - if (fullDef->weapDef.worldModel) - { - memcpy(fullDef->worldModel, fullDef->weapDef.worldModel, sizeof(void*) * std::extent_v); - fullDef->weapDef.worldModel = fullDef->worldModel; - } - - if (fullDef->weapDef.parallelBounce) - { - static_assert(std::extent_v == SURF_TYPE_COUNT); - assert(sizeof(WeaponFullDef::parallelBounce) >= sizeof(float) * std::extent_v); - memcpy(fullDef->parallelBounce, fullDef->weapDef.parallelBounce, sizeof(float) * std::extent_v); - fullDef->weapDef.parallelBounce = fullDef->parallelBounce; - } - - if (fullDef->weapDef.perpendicularBounce) - { - static_assert(std::extent_v == SURF_TYPE_COUNT); - assert(sizeof(WeaponFullDef::perpendicularBounce) >= sizeof(float) * std::extent_v); - memcpy(fullDef->perpendicularBounce, fullDef->weapDef.perpendicularBounce, sizeof(float) * std::extent_v); - fullDef->weapDef.perpendicularBounce = fullDef->perpendicularBounce; - } - - if (fullDef->weapDef.locationDamageMultipliers) - { - static_assert(std::extent_v == HITLOC_COUNT); - assert(sizeof(WeaponFullDef::locationDamageMultipliers) >= sizeof(float) * std::extent_v); - memcpy(fullDef->locationDamageMultipliers, - fullDef->weapDef.locationDamageMultipliers, - sizeof(float) * std::extent_v); - fullDef->weapDef.locationDamageMultipliers = fullDef->locationDamageMultipliers; - } - - if (fullDef->weapCompleteDef.scopes) - { - memcpy(fullDef->scopes, fullDef->weapCompleteDef.scopes, sizeof(void*) * std::extent_v); - fullDef->weapCompleteDef.scopes = fullDef->scopes; - } - - if (fullDef->weapCompleteDef.underBarrels) - { - memcpy(fullDef->underBarrels, fullDef->weapCompleteDef.underBarrels, sizeof(void*) * std::extent_v); - fullDef->weapCompleteDef.underBarrels = fullDef->underBarrels; - } - - if (fullDef->weapCompleteDef.others) - { - memcpy(fullDef->others, fullDef->weapCompleteDef.others, sizeof(void*) * std::extent_v); - fullDef->weapCompleteDef.others = fullDef->others; - } -} - -InfoString AssetDumperWeapon::CreateInfoString(XAssetInfo* asset) -{ - const auto fullDef = std::make_unique(); - memset(fullDef.get(), 0, sizeof(WeaponFullDef)); - CopyToFullDef(asset->Asset(), fullDef.get()); - - InfoStringFromWeaponConverter converter(fullDef.get(), - weapon_fields, - std::extent_v, - [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 ""; - - return asset->m_zone->m_script_strings[scrStr]; - }); - - return converter.Convert(); -} - -void AssetDumperWeapon::DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset) -{ - auto* accuracyGraphWriter = context.GetZoneAssetDumperState(); - const auto weapon = asset->Asset(); - const auto* weapDef = weapon->weapDef; - - if (!weapDef) - return; - - if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots - && accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName)) - { - AccuracyGraphWriter::DumpAiVsAiGraph( - context, - ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName, weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount)); - } - - if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots - && accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName)) - { - AccuracyGraphWriter::DumpAiVsPlayerGraph(context, - ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName, - weapDef->originalAiVsPlayerAccuracyGraphKnots, - weapDef->originalAiVsPlayerAccuracyGraphKnotCount)); - } -} - -bool AssetDumperWeapon::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperWeapon::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - // TODO: only dump infostring fields when non-default - - // 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); - - if (!assetFile) + if (!weapDef) return; - 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()); + if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots + && accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName)) + { + AccuracyGraphWriter::DumpAiVsAiGraph(context, + ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName, + weapDef->originalAiVsAiAccuracyGraphKnots, + weapDef->originalAiVsAiAccuracyGraphKnotCount)); + } + + if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots + && accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName)) + { + AccuracyGraphWriter::DumpAiVsPlayerGraph(context, + ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName, + weapDef->originalAiVsPlayerAccuracyGraphKnots, + weapDef->originalAiVsPlayerAccuracyGraphKnotCount)); + } + } +} // namespace + +namespace IW5::weapon +{ + bool Dumper::ShouldDump(XAssetInfo* asset) + { + return true; } - DumpAccuracyGraphs(context, asset); -} + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + // TODO: only dump infostring fields when non-default + + // 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(GetFileNameForAssetName(asset->m_name)); + + if (!assetFile) + return; + + 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()); + } + + DumpAccuracyGraphs(context, asset); + } +} // namespace IW5::weapon diff --git a/src/ObjWriting/Game/IW5/Weapon/WeaponDumperIW5.h b/src/ObjWriting/Game/IW5/Weapon/WeaponDumperIW5.h new file mode 100644 index 00000000..4a33e035 --- /dev/null +++ b/src/ObjWriting/Game/IW5/Weapon/WeaponDumperIW5.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/IW5/IW5.h" +#include "InfoString/InfoString.h" + +namespace IW5::weapon +{ + class Dumper final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} // namespace IW5::weapon diff --git a/src/ObjWriting/Game/T5/ObjWriterT5.cpp b/src/ObjWriting/Game/T5/ObjWriterT5.cpp index 55466d5d..5d1ff986 100644 --- a/src/ObjWriting/Game/T5/ObjWriterT5.cpp +++ b/src/ObjWriting/Game/T5/ObjWriterT5.cpp @@ -8,7 +8,6 @@ #include "ObjWriting.h" #include "RawFile/RawFileDumperT5.h" #include "StringTable/StringTableDumperT5.h" -#include "Weapon/AssetDumperWeapon.h" using namespace T5; diff --git a/src/ObjWriting/Game/T5/Weapon/AssetDumperWeapon.cpp b/src/ObjWriting/Game/T5/Weapon/AssetDumperWeapon.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ObjWriting/Game/T5/Weapon/AssetDumperWeapon.h b/src/ObjWriting/Game/T5/Weapon/AssetDumperWeapon.h deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ObjWriting/Game/T6/ObjWriterT6.cpp b/src/ObjWriting/Game/T6/ObjWriterT6.cpp index 93cfea5a..f198725b 100644 --- a/src/ObjWriting/Game/T6/ObjWriterT6.cpp +++ b/src/ObjWriting/Game/T6/ObjWriterT6.cpp @@ -21,10 +21,10 @@ #include "Techset/TechsetDumperT6.h" #include "Tracer/TracerDumperT6.h" #include "Vehicle/VehicleDumperT6.h" -#include "Weapon/AssetDumperWeapon.h" -#include "Weapon/AssetDumperWeaponAttachment.h" -#include "Weapon/AssetDumperWeaponAttachmentUnique.h" -#include "Weapon/AssetDumperWeaponCamo.h" +#include "Weapon/AttachmentDumperT6.h" +#include "Weapon/AttachmentUniqueDumperT6.h" +#include "Weapon/CamoJsonDumperT6.h" +#include "Weapon/WeaponDumperT6.h" #include "ZBarrier/ZBarrierDumperT6.h" using namespace T6; @@ -68,10 +68,10 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const // DUMP_ASSET_POOL(AssetDumperMenuList, m_menu_list, ASSET_TYPE_MENULIST) // DUMP_ASSET_POOL(AssetDumperMenuDef, m_menu_def, ASSET_TYPE_MENU) DUMP_ASSET_POOL(localize::Dumper, m_localize, ASSET_TYPE_LOCALIZE_ENTRY) - DUMP_ASSET_POOL(AssetDumperWeapon, m_weapon, ASSET_TYPE_WEAPON) - DUMP_ASSET_POOL(AssetDumperWeaponAttachment, m_attachment, ASSET_TYPE_ATTACHMENT) - DUMP_ASSET_POOL(AssetDumperWeaponAttachmentUnique, m_attachment_unique, ASSET_TYPE_ATTACHMENT_UNIQUE) - DUMP_ASSET_POOL(AssetDumperWeaponCamo, m_camo, ASSET_TYPE_WEAPON_CAMO) + DUMP_ASSET_POOL(weapon::Dumper, m_weapon, ASSET_TYPE_WEAPON) + DUMP_ASSET_POOL(attachment::Dumper, m_attachment, ASSET_TYPE_ATTACHMENT) + DUMP_ASSET_POOL(attachment_unique::Dumper, m_attachment_unique, ASSET_TYPE_ATTACHMENT_UNIQUE) + DUMP_ASSET_POOL(camo::JsonDumper, m_camo, ASSET_TYPE_WEAPON_CAMO) DUMP_ASSET_POOL(sound::SndDriverGlobalsDumper, m_snd_driver_globals, ASSET_TYPE_SNDDRIVER_GLOBALS) // DUMP_ASSET_POOL(AssetDumperFxEffectDef, m_fx, ASSET_TYPE_FX) // DUMP_ASSET_POOL(AssetDumperFxImpactTable, m_fx_impact_table, ASSET_TYPE_IMPACT_FX) diff --git a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeapon.h b/src/ObjWriting/Game/T6/Weapon/AssetDumperWeapon.h deleted file mode 100644 index d8f9d746..00000000 --- a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeapon.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "Dumping/AbstractAssetDumper.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" - -namespace T6 -{ - class AssetDumperWeapon final : public AbstractAssetDumper - { - static void CopyToFullDef(const WeaponVariantDef* weapon, WeaponFullDef* fullDef); - static InfoString CreateInfoString(XAssetInfo* asset); - static void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset); - - protected: - bool ShouldDump(XAssetInfo* asset) override; - void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; - }; -} // namespace T6 diff --git a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachment.cpp b/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachment.cpp deleted file mode 100644 index 0c7fd032..00000000 --- a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachment.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "AssetDumperWeaponAttachment.h" - -#include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/Weapon/AttachmentFields.h" -#include "Game/T6/Weapon/WeaponStrings.h" - -#include -#include - -using namespace T6; - -namespace T6 -{ - class InfoStringFromAttachmentConverter final : public InfoStringFromStructConverter - { - protected: - void FillFromExtensionField(const cspField_t& field) override - { - switch (static_cast(field.iFieldType)) - { - case AFT_ATTACHMENTTYPE: - FillFromEnumInt(std::string(field.szName), field.iOffset, szAttachmentTypeNames, std::extent_v); - break; - - case AFT_PENETRATE_TYPE: - FillFromEnumInt(std::string(field.szName), field.iOffset, penetrateTypeNames, std::extent_v); - break; - - case AFT_FIRETYPE: - FillFromEnumInt(std::string(field.szName), field.iOffset, szWeapFireTypeNames, std::extent_v); - break; - - default: - break; - } - } - - public: - InfoStringFromAttachmentConverter(const WeaponAttachment* structure, - const cspField_t* fields, - const size_t fieldCount, - std::function scriptStringValueCallback) - : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) - { - } - }; -} // namespace T6 - -InfoString AssetDumperWeaponAttachment::CreateInfoString(XAssetInfo* asset) -{ - InfoStringFromAttachmentConverter converter(asset->Asset(), - attachment_fields, - std::extent_v, - [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 ""; - - return asset->m_zone->m_script_strings[scrStr]; - }); - - return converter.Convert(); -} - -bool AssetDumperWeaponAttachment::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperWeaponAttachment::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - // 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); - - if (!assetFile) - return; - - 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/Weapon/AssetDumperWeaponAttachmentUnique.cpp b/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachmentUnique.cpp deleted file mode 100644 index 6730771a..00000000 --- a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachmentUnique.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include "AssetDumperWeaponAttachmentUnique.h" - -#include "Game/T6/InfoString/InfoStringFromStructConverter.h" -#include "Game/T6/ObjConstantsT6.h" -#include "Game/T6/Weapon/AttachmentUniqueFields.h" -#include "Game/T6/Weapon/WeaponStrings.h" - -#include -#include -#include -#include - -using namespace T6; - -namespace T6 -{ - class InfoStringFromWeaponAttachmentUniqueConverter final : public InfoStringFromStructConverter - { - protected: - void FillFromExtensionField(const cspField_t& field) override - { - switch (static_cast(field.iFieldType)) - { - case AUFT_ATTACHMENTTYPE: - FillFromEnumInt(std::string(field.szName), field.iOffset, szAttachmentTypeNames, std::extent_v); - break; - - case AUFT_HIDETAGS: - { - const auto* hideTags = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - std::stringstream ss; - auto first = true; - - for (auto i = 0u; i < std::extent_v; i++) - { - const auto& str = m_get_scr_string(hideTags[i]); - if (!str.empty()) - { - if (!first) - ss << "\n"; - else - first = false; - - ss << str; - } - } - - m_info_string.SetValueForKey(std::string(field.szName), ss.str()); - break; - } - - case AUFT_OVERLAYRETICLE: - FillFromEnumInt(std::string(field.szName), field.iOffset, szWeapOverlayReticleNames, std::extent_v); - break; - - case AUFT_CAMO: - { - const auto* camo = *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - - if (camo) - m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(camo->name))); - else - m_info_string.SetValueForKey(std::string(field.szName), ""); - break; - } - - default: - assert(false); - break; - } - } - - public: - InfoStringFromWeaponAttachmentUniqueConverter(const WeaponAttachmentUniqueFull* structure, - const cspField_t* fields, - const size_t fieldCount, - std::function scriptStringValueCallback) - : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) - { - } - }; -} // namespace T6 - -void AssetDumperWeaponAttachmentUnique::CopyToFullDef(const WeaponAttachmentUnique* attachment, WeaponAttachmentUniqueFull* fullDef) -{ - fullDef->attachment = *attachment; - - if (attachment->szXAnims) - { - assert(sizeof(WeaponAttachmentUniqueFull::szXAnims) >= sizeof(void*) * NUM_WEAP_ANIMS); - memcpy(fullDef->szXAnims, attachment->szXAnims, sizeof(void*) * NUM_WEAP_ANIMS); - fullDef->attachment.szXAnims = fullDef->szXAnims; - } - - if (attachment->hideTags) - { - assert(sizeof(WeaponAttachmentUniqueFull::hideTags) >= sizeof(scr_string_t) * std::extent_v); - memcpy(fullDef->hideTags, attachment->hideTags, sizeof(scr_string_t) * std::extent_v); - fullDef->attachment.hideTags = fullDef->hideTags; - } - - if (attachment->locationDamageMultipliers) - { - assert(sizeof(WeaponAttachmentUniqueFull::locationDamageMultipliers) >= sizeof(float) * HITLOC_COUNT); - memcpy(fullDef->locationDamageMultipliers, attachment->locationDamageMultipliers, sizeof(float) * HITLOC_COUNT); - fullDef->attachment.locationDamageMultipliers = fullDef->locationDamageMultipliers; - } -} - -InfoString AssetDumperWeaponAttachmentUnique::CreateInfoString(XAssetInfo* asset) -{ - const auto fullDef = std::make_unique(); - memset(fullDef.get(), 0, sizeof(WeaponAttachmentUniqueFull)); - CopyToFullDef(asset->Asset(), fullDef.get()); - - InfoStringFromWeaponAttachmentUniqueConverter converter(fullDef.get(), - attachment_unique_fields, - std::extent_v, - [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 ""; - - return asset->m_zone->m_script_strings[scrStr]; - }); - - return converter.Convert(); -} - -bool AssetDumperWeaponAttachmentUnique::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperWeaponAttachmentUnique::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - // 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); - - if (!assetFile) - return; - - 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/Weapon/AssetDumperWeaponAttachmentUnique.h b/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachmentUnique.h deleted file mode 100644 index 4d6a9c41..00000000 --- a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachmentUnique.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "Dumping/AbstractAssetDumper.h" -#include "Game/T6/T6.h" -#include "InfoString/InfoString.h" - -namespace T6 -{ - class AssetDumperWeaponAttachmentUnique final : public AbstractAssetDumper - { - static void CopyToFullDef(const WeaponAttachmentUnique* attachment, WeaponAttachmentUniqueFull* fullDef); - static InfoString CreateInfoString(XAssetInfo* asset); - - protected: - bool ShouldDump(XAssetInfo* asset) override; - void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; - }; -} // namespace T6 diff --git a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponCamo.cpp b/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponCamo.cpp deleted file mode 100644 index 4e485235..00000000 --- a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponCamo.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "AssetDumperWeaponCamo.h" - -#include "JsonWeaponCamoWriter.h" - -#include - -using namespace T6; - -bool AssetDumperWeaponCamo::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperWeaponCamo::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto fileName = std::format("camo/{}.json", asset->m_name); - const auto assetFile = context.OpenAssetFile(fileName); - - if (!assetFile) - return; - - DumpWeaponCamoAsJson(*assetFile, asset->Asset()); -} diff --git a/src/ObjWriting/Game/T6/Weapon/AttachmentDumperT6.cpp b/src/ObjWriting/Game/T6/Weapon/AttachmentDumperT6.cpp new file mode 100644 index 00000000..ff521c15 --- /dev/null +++ b/src/ObjWriting/Game/T6/Weapon/AttachmentDumperT6.cpp @@ -0,0 +1,99 @@ +#include "AttachmentDumperT6.h" + +#include "Game/T6/InfoString/InfoStringFromStructConverter.h" +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/Weapon/AttachmentFields.h" +#include "Game/T6/Weapon/WeaponStrings.h" +#include "Weapon/AttachmentCommon.h" + +#include +#include + +using namespace T6; +using namespace ::attachment; + +namespace +{ + class InfoStringFromAttachmentConverter final : public InfoStringFromStructConverter + { + protected: + void FillFromExtensionField(const cspField_t& field) override + { + switch (static_cast(field.iFieldType)) + { + case AFT_ATTACHMENTTYPE: + FillFromEnumInt(std::string(field.szName), field.iOffset, szAttachmentTypeNames, std::extent_v); + break; + + case AFT_PENETRATE_TYPE: + FillFromEnumInt(std::string(field.szName), field.iOffset, penetrateTypeNames, std::extent_v); + break; + + case AFT_FIRETYPE: + FillFromEnumInt(std::string(field.szName), field.iOffset, szWeapFireTypeNames, std::extent_v); + break; + + default: + break; + } + } + + public: + InfoStringFromAttachmentConverter(const WeaponAttachment* structure, + const cspField_t* fields, + const size_t fieldCount, + std::function scriptStringValueCallback) + : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) + { + } + }; + + InfoString CreateInfoString(XAssetInfo* asset) + { + InfoStringFromAttachmentConverter converter(asset->Asset(), + attachment_fields, + std::extent_v, + [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 ""; + + return asset->m_zone->m_script_strings[scrStr]; + }); + + return converter.Convert(); + } +} // namespace + +namespace T6::attachment +{ + bool Dumper::ShouldDump(XAssetInfo* asset) + { + return true; + } + + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + // 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(GetInfoStringFileNameForAssetName(asset->m_name)); + + if (!assetFile) + return; + + 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()); + } + } +} // namespace T6::attachment diff --git a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachment.h b/src/ObjWriting/Game/T6/Weapon/AttachmentDumperT6.h similarity index 60% rename from src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachment.h rename to src/ObjWriting/Game/T6/Weapon/AttachmentDumperT6.h index cde27cf5..2f386ccc 100644 --- a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponAttachment.h +++ b/src/ObjWriting/Game/T6/Weapon/AttachmentDumperT6.h @@ -4,14 +4,12 @@ #include "Game/T6/T6.h" #include "InfoString/InfoString.h" -namespace T6 +namespace T6::attachment { - class AssetDumperWeaponAttachment final : public AbstractAssetDumper + class Dumper final : public AbstractAssetDumper { - static InfoString CreateInfoString(XAssetInfo* asset); - protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; -} // namespace T6 +} // namespace T6::attachment diff --git a/src/ObjWriting/Game/T6/Weapon/AttachmentUniqueDumperT6.cpp b/src/ObjWriting/Game/T6/Weapon/AttachmentUniqueDumperT6.cpp new file mode 100644 index 00000000..88e4c054 --- /dev/null +++ b/src/ObjWriting/Game/T6/Weapon/AttachmentUniqueDumperT6.cpp @@ -0,0 +1,163 @@ +#include "AttachmentUniqueDumperT6.h" + +#include "Game/T6/InfoString/InfoStringFromStructConverter.h" +#include "Game/T6/ObjConstantsT6.h" +#include "Game/T6/Weapon/AttachmentUniqueFields.h" +#include "Game/T6/Weapon/WeaponStrings.h" +#include "Weapon/AttachmentUniqueCommon.h" + +#include +#include +#include +#include + +using namespace T6; +using namespace ::attachment_unique; + +namespace +{ + class InfoStringFromWeaponAttachmentUniqueConverter final : public InfoStringFromStructConverter + { + protected: + void FillFromExtensionField(const cspField_t& field) override + { + switch (static_cast(field.iFieldType)) + { + case AUFT_ATTACHMENTTYPE: + FillFromEnumInt(std::string(field.szName), field.iOffset, szAttachmentTypeNames, std::extent_v); + break; + + case AUFT_HIDETAGS: + { + const auto* hideTags = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); + std::stringstream ss; + auto first = true; + + for (auto i = 0u; i < std::extent_v; i++) + { + const auto& str = m_get_scr_string(hideTags[i]); + if (!str.empty()) + { + if (!first) + ss << "\n"; + else + first = false; + + ss << str; + } + } + + m_info_string.SetValueForKey(std::string(field.szName), ss.str()); + break; + } + + case AUFT_OVERLAYRETICLE: + FillFromEnumInt(std::string(field.szName), field.iOffset, szWeapOverlayReticleNames, std::extent_v); + break; + + case AUFT_CAMO: + { + const auto* camo = *reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); + + if (camo) + m_info_string.SetValueForKey(std::string(field.szName), std::string(AssetName(camo->name))); + else + m_info_string.SetValueForKey(std::string(field.szName), ""); + break; + } + + default: + assert(false); + break; + } + } + + public: + InfoStringFromWeaponAttachmentUniqueConverter(const WeaponAttachmentUniqueFull* structure, + const cspField_t* fields, + const size_t fieldCount, + std::function scriptStringValueCallback) + : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) + { + } + }; + + void CopyToFullDef(const WeaponAttachmentUnique* attachment, WeaponAttachmentUniqueFull* fullDef) + { + fullDef->attachment = *attachment; + + if (attachment->szXAnims) + { + assert(sizeof(WeaponAttachmentUniqueFull::szXAnims) >= sizeof(void*) * NUM_WEAP_ANIMS); + memcpy(fullDef->szXAnims, attachment->szXAnims, sizeof(void*) * NUM_WEAP_ANIMS); + fullDef->attachment.szXAnims = fullDef->szXAnims; + } + + if (attachment->hideTags) + { + assert(sizeof(WeaponAttachmentUniqueFull::hideTags) >= sizeof(scr_string_t) * std::extent_v); + memcpy(fullDef->hideTags, attachment->hideTags, sizeof(scr_string_t) * std::extent_v); + fullDef->attachment.hideTags = fullDef->hideTags; + } + + if (attachment->locationDamageMultipliers) + { + assert(sizeof(WeaponAttachmentUniqueFull::locationDamageMultipliers) >= sizeof(float) * HITLOC_COUNT); + memcpy(fullDef->locationDamageMultipliers, attachment->locationDamageMultipliers, sizeof(float) * HITLOC_COUNT); + fullDef->attachment.locationDamageMultipliers = fullDef->locationDamageMultipliers; + } + } + + InfoString CreateInfoString(XAssetInfo* asset) + { + const auto fullDef = std::make_unique(); + memset(fullDef.get(), 0, sizeof(WeaponAttachmentUniqueFull)); + CopyToFullDef(asset->Asset(), fullDef.get()); + + InfoStringFromWeaponAttachmentUniqueConverter converter(fullDef.get(), + attachment_unique_fields, + std::extent_v, + [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 ""; + + return asset->m_zone->m_script_strings[scrStr]; + }); + + return converter.Convert(); + } +} // namespace + +namespace T6::attachment_unique +{ + bool Dumper::ShouldDump(XAssetInfo* asset) + { + return true; + } + + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + // 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(GetFileNameForAssetName(asset->m_name)); + + if (!assetFile) + return; + + 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()); + } + } +} // namespace T6::attachment_unique diff --git a/src/ObjWriting/Game/T6/Weapon/AttachmentUniqueDumperT6.h b/src/ObjWriting/Game/T6/Weapon/AttachmentUniqueDumperT6.h new file mode 100644 index 00000000..e84fcb74 --- /dev/null +++ b/src/ObjWriting/Game/T6/Weapon/AttachmentUniqueDumperT6.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/T6/T6.h" +#include "InfoString/InfoString.h" + +namespace T6::attachment_unique +{ + class Dumper final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} // namespace T6::attachment_unique diff --git a/src/ObjWriting/Game/T6/Weapon/JsonWeaponCamoWriter.cpp b/src/ObjWriting/Game/T6/Weapon/CamoJsonDumperT6.cpp similarity index 86% rename from src/ObjWriting/Game/T6/Weapon/JsonWeaponCamoWriter.cpp rename to src/ObjWriting/Game/T6/Weapon/CamoJsonDumperT6.cpp index 3438dae8..958470c7 100644 --- a/src/ObjWriting/Game/T6/Weapon/JsonWeaponCamoWriter.cpp +++ b/src/ObjWriting/Game/T6/Weapon/CamoJsonDumperT6.cpp @@ -1,20 +1,22 @@ -#include "JsonWeaponCamoWriter.h" +#include "CamoJsonDumperT6.h" #include "Game/T6/CommonT6.h" #include "Game/T6/Json/JsonWeaponCamo.h" +#include "Weapon/CamoCommon.h" #include #include using namespace nlohmann; using namespace T6; +using namespace ::camo; namespace { - class JsonDumper + class JsonDumperImpl { public: - explicit JsonDumper(std::ostream& stream) + explicit JsonDumperImpl(std::ostream& stream) : m_stream(stream) { } @@ -101,11 +103,22 @@ namespace }; } // namespace -namespace T6 +namespace T6::camo { - void DumpWeaponCamoAsJson(std::ostream& stream, const WeaponCamo* weaponCamo) + bool JsonDumper::ShouldDump(XAssetInfo* asset) { - const JsonDumper dumper(stream); - dumper.Dump(weaponCamo); + return true; } -} // namespace T6 + + void JsonDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + const auto fileName = GetJsonFileNameForAssetName(asset->m_name); + const auto assetFile = context.OpenAssetFile(fileName); + + if (!assetFile) + return; + + const JsonDumperImpl dumper(*assetFile); + dumper.Dump(asset->Asset()); + } +} // namespace T6::camo diff --git a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponCamo.h b/src/ObjWriting/Game/T6/Weapon/CamoJsonDumperT6.h similarity index 70% rename from src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponCamo.h rename to src/ObjWriting/Game/T6/Weapon/CamoJsonDumperT6.h index 36b2df92..e7c316e0 100644 --- a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeaponCamo.h +++ b/src/ObjWriting/Game/T6/Weapon/CamoJsonDumperT6.h @@ -3,12 +3,12 @@ #include "Dumping/AbstractAssetDumper.h" #include "Game/T6/T6.h" -namespace T6 +namespace T6::camo { - class AssetDumperWeaponCamo final : public AbstractAssetDumper + class JsonDumper final : public AbstractAssetDumper { protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; -} // namespace T6 +} // namespace T6::camo diff --git a/src/ObjWriting/Game/T6/Weapon/JsonWeaponCamoWriter.h b/src/ObjWriting/Game/T6/Weapon/JsonWeaponCamoWriter.h deleted file mode 100644 index 0da45568..00000000 --- a/src/ObjWriting/Game/T6/Weapon/JsonWeaponCamoWriter.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "Dumping/AssetDumpingContext.h" -#include "Game/T6/T6.h" - -#include - -namespace T6 -{ - void DumpWeaponCamoAsJson(std::ostream& stream, const WeaponCamo* weaponCamo); -} // namespace T6 diff --git a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeapon.cpp b/src/ObjWriting/Game/T6/Weapon/WeaponDumperT6.cpp similarity index 53% rename from src/ObjWriting/Game/T6/Weapon/AssetDumperWeapon.cpp rename to src/ObjWriting/Game/T6/Weapon/WeaponDumperT6.cpp index 24223dc4..96ad8700 100644 --- a/src/ObjWriting/Game/T6/Weapon/AssetDumperWeapon.cpp +++ b/src/ObjWriting/Game/T6/Weapon/WeaponDumperT6.cpp @@ -1,10 +1,12 @@ -#include "AssetDumperWeapon.h" +#include "WeaponDumperT6.h" #include "Game/T6/InfoString/InfoStringFromStructConverter.h" #include "Game/T6/ObjConstantsT6.h" #include "Game/T6/Weapon/WeaponFields.h" #include "Game/T6/Weapon/WeaponStrings.h" +#include "InfoString/InfoString.h" #include "Weapon/AccuracyGraphWriter.h" +#include "Weapon/WeaponCommon.h" #include #include @@ -12,8 +14,9 @@ #include using namespace T6; +using namespace ::weapon; -namespace T6 +namespace { class InfoStringFromWeaponConverter final : public InfoStringFromStructConverter { @@ -281,208 +284,212 @@ namespace T6 return graph; } -} // namespace T6 -void AssetDumperWeapon::CopyToFullDef(const WeaponVariantDef* weapon, WeaponFullDef* fullDef) -{ - fullDef->weapVariantDef = *weapon; - - if (weapon->weapDef) + void CopyToFullDef(const WeaponVariantDef* weapon, WeaponFullDef* fullDef) { - fullDef->weapDef = *weapon->weapDef; - fullDef->weapVariantDef.weapDef = &fullDef->weapDef; + fullDef->weapVariantDef = *weapon; + + if (weapon->weapDef) + { + fullDef->weapDef = *weapon->weapDef; + fullDef->weapVariantDef.weapDef = &fullDef->weapDef; + } + + if (weapon->attachments) + { + assert(sizeof(WeaponFullDef::attachments) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->attachments, weapon->attachments, sizeof(void*) * std::extent_v); + fullDef->weapVariantDef.attachments = fullDef->attachments; + } + + if (weapon->attachmentUniques) + { + assert(sizeof(WeaponFullDef::attachmentUniques) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->attachmentUniques, weapon->attachmentUniques, sizeof(void*) * std::extent_v); + fullDef->weapVariantDef.attachmentUniques = fullDef->attachmentUniques; + } + + if (fullDef->weapDef.gunXModel) + { + assert(sizeof(WeaponFullDef::gunXModel) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->gunXModel, fullDef->weapDef.gunXModel, sizeof(void*) * std::extent_v); + fullDef->weapDef.gunXModel = fullDef->gunXModel; + } + + if (weapon->szXAnims) + { + assert(sizeof(WeaponFullDef::szXAnims) >= sizeof(void*) * NUM_WEAP_ANIMS); + memcpy(fullDef->szXAnims, weapon->szXAnims, sizeof(void*) * NUM_WEAP_ANIMS); + fullDef->weapVariantDef.szXAnims = fullDef->szXAnims; + } + + if (weapon->hideTags) + { + assert(sizeof(WeaponFullDef::hideTags) >= sizeof(scr_string_t) * std::extent_v); + memcpy(fullDef->hideTags, weapon->hideTags, sizeof(scr_string_t) * std::extent_v); + fullDef->weapVariantDef.hideTags = fullDef->hideTags; + } + + if (fullDef->weapDef.notetrackSoundMapKeys) + { + assert(sizeof(WeaponFullDef::notetrackSoundMapKeys) >= sizeof(scr_string_t) * std::extent_v); + memcpy(fullDef->notetrackSoundMapKeys, + fullDef->weapDef.notetrackSoundMapKeys, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackSoundMapKeys = fullDef->notetrackSoundMapKeys; + } + + if (fullDef->weapDef.notetrackSoundMapValues) + { + assert(sizeof(WeaponFullDef::notetrackSoundMapValues) >= sizeof(scr_string_t) * std::extent_v); + memcpy(fullDef->notetrackSoundMapValues, + fullDef->weapDef.notetrackSoundMapValues, + sizeof(scr_string_t) * std::extent_v); + fullDef->weapDef.notetrackSoundMapValues = fullDef->notetrackSoundMapValues; + } + + if (fullDef->weapDef.worldModel) + { + assert(sizeof(WeaponFullDef::worldModel) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->worldModel, fullDef->weapDef.worldModel, sizeof(void*) * std::extent_v); + fullDef->weapDef.worldModel = fullDef->worldModel; + } + + if (weapon->attachViewModel) + { + assert(sizeof(WeaponFullDef::attachViewModel) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->attachViewModel, weapon->attachViewModel, sizeof(void*) * std::extent_v); + fullDef->weapVariantDef.attachViewModel = fullDef->attachViewModel; + } + + if (weapon->attachWorldModel) + { + assert(sizeof(WeaponFullDef::attachWorldModel) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->attachWorldModel, weapon->attachWorldModel, sizeof(void*) * std::extent_v); + fullDef->weapVariantDef.attachWorldModel = fullDef->attachWorldModel; + } + + if (weapon->attachViewModelTag) + { + assert(sizeof(WeaponFullDef::attachViewModelTag) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->attachViewModelTag, weapon->attachViewModelTag, sizeof(void*) * std::extent_v); + fullDef->weapVariantDef.attachViewModelTag = fullDef->attachViewModelTag; + } + + if (weapon->attachWorldModelTag) + { + assert(sizeof(WeaponFullDef::attachWorldModelTag) >= sizeof(void*) * std::extent_v); + memcpy(fullDef->attachWorldModelTag, weapon->attachWorldModelTag, sizeof(void*) * std::extent_v); + fullDef->weapVariantDef.attachWorldModelTag = fullDef->attachWorldModelTag; + } + + if (fullDef->weapDef.parallelBounce) + { + assert(sizeof(WeaponFullDef::parallelBounce) >= sizeof(float) * SURF_TYPE_NUM); + memcpy(fullDef->parallelBounce, fullDef->weapDef.parallelBounce, sizeof(float) * SURF_TYPE_NUM); + fullDef->weapDef.parallelBounce = fullDef->parallelBounce; + } + + if (fullDef->weapDef.perpendicularBounce) + { + assert(sizeof(WeaponFullDef::perpendicularBounce) >= sizeof(float) * SURF_TYPE_NUM); + memcpy(fullDef->perpendicularBounce, fullDef->weapDef.perpendicularBounce, sizeof(float) * SURF_TYPE_NUM); + fullDef->weapDef.perpendicularBounce = fullDef->perpendicularBounce; + } + + if (fullDef->weapDef.locationDamageMultipliers) + { + assert(sizeof(WeaponFullDef::locationDamageMultipliers) >= sizeof(float) * HITLOC_COUNT); + memcpy(fullDef->locationDamageMultipliers, fullDef->weapDef.locationDamageMultipliers, sizeof(float) * HITLOC_COUNT); + fullDef->weapDef.locationDamageMultipliers = fullDef->locationDamageMultipliers; + } + + if (fullDef->weapDef.weaponCamo && fullDef->weapDef.weaponCamo->name) + { + strncpy(fullDef->weaponCamo, fullDef->weapDef.weaponCamo->name, std::extent_v); + } } - if (weapon->attachments) + InfoString CreateInfoString(XAssetInfo* asset) { - assert(sizeof(WeaponFullDef::attachments) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->attachments, weapon->attachments, sizeof(void*) * std::extent_v); - fullDef->weapVariantDef.attachments = fullDef->attachments; + const auto fullDef = std::make_unique(); + memset(fullDef.get(), 0, sizeof(WeaponFullDef)); + CopyToFullDef(asset->Asset(), fullDef.get()); + + InfoStringFromWeaponConverter converter(fullDef.get(), + weapon_fields, + std::extent_v, + [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 ""; + + return asset->m_zone->m_script_strings[scrStr]; + }); + + return converter.Convert(); } - if (weapon->attachmentUniques) + void DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset) { - assert(sizeof(WeaponFullDef::attachmentUniques) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->attachmentUniques, weapon->attachmentUniques, sizeof(void*) * std::extent_v); - fullDef->weapVariantDef.attachmentUniques = fullDef->attachmentUniques; - } + auto* accuracyGraphWriter = context.GetZoneAssetDumperState(); + const auto weapon = asset->Asset(); + const auto* weapDef = weapon->weapDef; - if (fullDef->weapDef.gunXModel) - { - assert(sizeof(WeaponFullDef::gunXModel) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->gunXModel, fullDef->weapDef.gunXModel, sizeof(void*) * std::extent_v); - fullDef->weapDef.gunXModel = fullDef->gunXModel; - } - - if (weapon->szXAnims) - { - assert(sizeof(WeaponFullDef::szXAnims) >= sizeof(void*) * NUM_WEAP_ANIMS); - memcpy(fullDef->szXAnims, weapon->szXAnims, sizeof(void*) * NUM_WEAP_ANIMS); - fullDef->weapVariantDef.szXAnims = fullDef->szXAnims; - } - - if (weapon->hideTags) - { - assert(sizeof(WeaponFullDef::hideTags) >= sizeof(scr_string_t) * std::extent_v); - memcpy(fullDef->hideTags, weapon->hideTags, sizeof(scr_string_t) * std::extent_v); - fullDef->weapVariantDef.hideTags = fullDef->hideTags; - } - - if (fullDef->weapDef.notetrackSoundMapKeys) - { - assert(sizeof(WeaponFullDef::notetrackSoundMapKeys) >= sizeof(scr_string_t) * std::extent_v); - memcpy(fullDef->notetrackSoundMapKeys, - fullDef->weapDef.notetrackSoundMapKeys, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackSoundMapKeys = fullDef->notetrackSoundMapKeys; - } - - if (fullDef->weapDef.notetrackSoundMapValues) - { - assert(sizeof(WeaponFullDef::notetrackSoundMapValues) >= sizeof(scr_string_t) * std::extent_v); - memcpy(fullDef->notetrackSoundMapValues, - fullDef->weapDef.notetrackSoundMapValues, - sizeof(scr_string_t) * std::extent_v); - fullDef->weapDef.notetrackSoundMapValues = fullDef->notetrackSoundMapValues; - } - - if (fullDef->weapDef.worldModel) - { - assert(sizeof(WeaponFullDef::worldModel) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->worldModel, fullDef->weapDef.worldModel, sizeof(void*) * std::extent_v); - fullDef->weapDef.worldModel = fullDef->worldModel; - } - - if (weapon->attachViewModel) - { - assert(sizeof(WeaponFullDef::attachViewModel) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->attachViewModel, weapon->attachViewModel, sizeof(void*) * std::extent_v); - fullDef->weapVariantDef.attachViewModel = fullDef->attachViewModel; - } - - if (weapon->attachWorldModel) - { - assert(sizeof(WeaponFullDef::attachWorldModel) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->attachWorldModel, weapon->attachWorldModel, sizeof(void*) * std::extent_v); - fullDef->weapVariantDef.attachWorldModel = fullDef->attachWorldModel; - } - - if (weapon->attachViewModelTag) - { - assert(sizeof(WeaponFullDef::attachViewModelTag) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->attachViewModelTag, weapon->attachViewModelTag, sizeof(void*) * std::extent_v); - fullDef->weapVariantDef.attachViewModelTag = fullDef->attachViewModelTag; - } - - if (weapon->attachWorldModelTag) - { - assert(sizeof(WeaponFullDef::attachWorldModelTag) >= sizeof(void*) * std::extent_v); - memcpy(fullDef->attachWorldModelTag, weapon->attachWorldModelTag, sizeof(void*) * std::extent_v); - fullDef->weapVariantDef.attachWorldModelTag = fullDef->attachWorldModelTag; - } - - if (fullDef->weapDef.parallelBounce) - { - assert(sizeof(WeaponFullDef::parallelBounce) >= sizeof(float) * SURF_TYPE_NUM); - memcpy(fullDef->parallelBounce, fullDef->weapDef.parallelBounce, sizeof(float) * SURF_TYPE_NUM); - fullDef->weapDef.parallelBounce = fullDef->parallelBounce; - } - - if (fullDef->weapDef.perpendicularBounce) - { - assert(sizeof(WeaponFullDef::perpendicularBounce) >= sizeof(float) * SURF_TYPE_NUM); - memcpy(fullDef->perpendicularBounce, fullDef->weapDef.perpendicularBounce, sizeof(float) * SURF_TYPE_NUM); - fullDef->weapDef.perpendicularBounce = fullDef->perpendicularBounce; - } - - if (fullDef->weapDef.locationDamageMultipliers) - { - assert(sizeof(WeaponFullDef::locationDamageMultipliers) >= sizeof(float) * HITLOC_COUNT); - memcpy(fullDef->locationDamageMultipliers, fullDef->weapDef.locationDamageMultipliers, sizeof(float) * HITLOC_COUNT); - fullDef->weapDef.locationDamageMultipliers = fullDef->locationDamageMultipliers; - } - - if (fullDef->weapDef.weaponCamo && fullDef->weapDef.weaponCamo->name) - { - strncpy(fullDef->weaponCamo, fullDef->weapDef.weaponCamo->name, std::extent_v); - } -} - -InfoString AssetDumperWeapon::CreateInfoString(XAssetInfo* asset) -{ - const auto fullDef = std::make_unique(); - memset(fullDef.get(), 0, sizeof(WeaponFullDef)); - CopyToFullDef(asset->Asset(), fullDef.get()); - - InfoStringFromWeaponConverter converter(fullDef.get(), - weapon_fields, - std::extent_v, - [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 ""; - - return asset->m_zone->m_script_strings[scrStr]; - }); - - return converter.Convert(); -} - -void AssetDumperWeapon::DumpAccuracyGraphs(AssetDumpingContext& context, XAssetInfo* asset) -{ - auto* accuracyGraphWriter = context.GetZoneAssetDumperState(); - const auto weapon = asset->Asset(); - const auto* weapDef = weapon->weapDef; - - if (!weapDef) - return; - - if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots - && accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName)) - { - AccuracyGraphWriter::DumpAiVsAiGraph( - context, - ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName, weapDef->originalAiVsAiAccuracyGraphKnots, weapDef->originalAiVsAiAccuracyGraphKnotCount)); - } - - if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots - && accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName)) - { - AccuracyGraphWriter::DumpAiVsPlayerGraph(context, - ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName, - weapDef->originalAiVsPlayerAccuracyGraphKnots, - weapDef->originalAiVsPlayerAccuracyGraphKnotCount)); - } -} - -bool AssetDumperWeapon::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperWeapon::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - // 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); - - if (!assetFile) + if (!weapDef) return; - 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()); + if (weapDef->aiVsAiAccuracyGraphName && weapDef->originalAiVsAiAccuracyGraphKnots + && accuracyGraphWriter->ShouldDumpAiVsAiGraph(weapDef->aiVsAiAccuracyGraphName)) + { + AccuracyGraphWriter::DumpAiVsAiGraph(context, + ConvertAccuracyGraph(weapDef->aiVsAiAccuracyGraphName, + weapDef->originalAiVsAiAccuracyGraphKnots, + weapDef->originalAiVsAiAccuracyGraphKnotCount)); + } + + if (weapDef->aiVsPlayerAccuracyGraphName && weapDef->originalAiVsPlayerAccuracyGraphKnots + && accuracyGraphWriter->ShouldDumpAiVsPlayerGraph(weapDef->aiVsPlayerAccuracyGraphName)) + { + AccuracyGraphWriter::DumpAiVsPlayerGraph(context, + ConvertAccuracyGraph(weapDef->aiVsPlayerAccuracyGraphName, + weapDef->originalAiVsPlayerAccuracyGraphKnots, + weapDef->originalAiVsPlayerAccuracyGraphKnotCount)); + } + } +} // namespace + +namespace T6::weapon +{ + bool Dumper::ShouldDump(XAssetInfo* asset) + { + return true; } - DumpAccuracyGraphs(context, asset); -} + void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + // 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(GetFileNameForAssetName(asset->m_name)); + + if (!assetFile) + return; + + 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()); + } + + DumpAccuracyGraphs(context, asset); + } +} // namespace T6::weapon diff --git a/src/ObjWriting/Game/T6/Weapon/WeaponDumperT6.h b/src/ObjWriting/Game/T6/Weapon/WeaponDumperT6.h new file mode 100644 index 00000000..15ac83b6 --- /dev/null +++ b/src/ObjWriting/Game/T6/Weapon/WeaponDumperT6.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Dumping/AbstractAssetDumper.h" +#include "Game/T6/T6.h" + +namespace T6::weapon +{ + class Dumper final : public AbstractAssetDumper + { + protected: + bool ShouldDump(XAssetInfo* asset) override; + void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; + }; +} // namespace T6::weapon