From fecd486f44ba886b2678fc83d67246e0cc720895 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 7 Apr 2024 13:28:26 +0200 Subject: [PATCH] chore: dump iw5 attachments that are used by weapons --- src/Common/Game/IW5/IW5.h | 1 + src/Common/Game/IW5/IW5_Assets.h | 3 + .../Game/IW5/InfoString/WeaponFields.h | 4 +- .../IW5/AssetDumpers/AssetDumperWeapon.cpp | 85 +++++++++++++++++-- 4 files changed, 84 insertions(+), 9 deletions(-) diff --git a/src/Common/Game/IW5/IW5.h b/src/Common/Game/IW5/IW5.h index 6b850094..a3cdbf2f 100644 --- a/src/Common/Game/IW5/IW5.h +++ b/src/Common/Game/IW5/IW5.h @@ -115,6 +115,7 @@ namespace IW5 // Custom WFT_ANIM_NAME, + WFT_ATTACHMENT, WFT_NUM_FIELD_TYPES, }; diff --git a/src/Common/Game/IW5/IW5_Assets.h b/src/Common/Game/IW5/IW5_Assets.h index ae42784e..fed67893 100644 --- a/src/Common/Game/IW5/IW5_Assets.h +++ b/src/Common/Game/IW5/IW5_Assets.h @@ -4006,6 +4006,9 @@ namespace IW5 float parallelBounce[31]; float perpendicularBounce[31]; float locationDamageMultipliers[20]; + WeaponAttachment* scopes[6]; + WeaponAttachment* underBarrels[3]; + WeaponAttachment* others[4]; }; struct FxFloatRange diff --git a/src/ObjCommon/Game/IW5/InfoString/WeaponFields.h b/src/ObjCommon/Game/IW5/InfoString/WeaponFields.h index b47a7ce0..b1e7b837 100644 --- a/src/ObjCommon/Game/IW5/InfoString/WeaponFields.h +++ b/src/ObjCommon/Game/IW5/InfoString/WeaponFields.h @@ -4,9 +4,6 @@ namespace IW5 { // WeaponCompleteDef: - // TODO: scopes - // TODO: underBarrels - // TODO: others // TODO: animOverrides // TODO: soundOverrides // TODO: fxOverrides @@ -736,6 +733,7 @@ namespace IW5 {"missileConeSoundCrossfadeEnabled", offsetof(WeaponFullDef, weapDef.missileConeSoundCrossfadeEnabled), CSPFT_BOOL }, {"missileConeSoundCrossfadeTopSize", offsetof(WeaponFullDef, weapDef.missileConeSoundCrossfadeTopSize), CSPFT_FLOAT }, {"missileConeSoundCrossfadeBottomSize", offsetof(WeaponFullDef, weapDef.missileConeSoundCrossfadeBottomSize), CSPFT_FLOAT }, + {"attachments", offsetof(WeaponFullDef, scopes), WFT_ATTACHMENT }, }; inline const char* szWeapTypeNames[]{ diff --git a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperWeapon.cpp b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperWeapon.cpp index 59017ed2..4733ff99 100644 --- a/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperWeapon.cpp +++ b/src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperWeapon.cpp @@ -16,6 +16,16 @@ namespace IW5 { class InfoStringFromWeaponConverter final : public InfoStringFromStructConverter { + public: + InfoStringFromWeaponConverter(const WeaponFullDef* structure, + const cspField_t* fields, + const size_t fieldCount, + std::function scriptStringValueCallback) + : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)), + m_weapon(structure) + { + } + protected: void FillFromExtensionField(const cspField_t& field) override { @@ -202,6 +212,10 @@ namespace IW5 FillFromString(std::string(field.szName), field.iOffset); break; + case WFT_ATTACHMENT: + FillFromAttachments(std::string(field.szName)); + break; + case WFT_NUM_FIELD_TYPES: default: assert(false); @@ -209,14 +223,55 @@ namespace IW5 } } - public: - InfoStringFromWeaponConverter(const WeaponFullDef* structure, - const cspField_t* fields, - const size_t fieldCount, - std::function scriptStringValueCallback) - : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback)) + private: + void FillFromAttachments(const std::string& key) { + std::stringstream ss; + bool first = true; + + for (const auto& scope : m_weapon->scopes) + { + if (scope && scope->szInternalName) + { + if (!first) + ss << "\n"; + else + first = false; + + ss << scope->szInternalName; + } + } + + for (const auto& underBarrel : m_weapon->underBarrels) + { + if (underBarrel && underBarrel->szInternalName) + { + if (!first) + ss << "\n"; + else + first = false; + + ss << underBarrel->szInternalName; + } + } + + for (const auto& other : m_weapon->others) + { + if (other && other->szInternalName) + { + if (!first) + ss << "\n"; + else + first = false; + + ss << other->szInternalName; + } + } + + m_info_string.SetValueForKey(key, ss.str()); } + + const WeaponFullDef* m_weapon; }; } // namespace IW5 @@ -326,6 +381,24 @@ void AssetDumperWeapon::CopyToFullDef(const WeaponCompleteDef* weapon, WeaponFul 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)