chore: dump iw5 attachments that are used by weapons

This commit is contained in:
Jan 2024-04-07 13:28:26 +02:00
parent c68f4015d2
commit fecd486f44
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
4 changed files with 84 additions and 9 deletions

View File

@ -115,6 +115,7 @@ namespace IW5
// Custom
WFT_ANIM_NAME,
WFT_ATTACHMENT,
WFT_NUM_FIELD_TYPES,
};

View File

@ -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

View File

@ -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[]{

View File

@ -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<std::string(scr_string_t)> 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<std::string(scr_string_t)> 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<decltype(WeaponFullDef::locationDamageMultipliers)>);
fullDef->weapDef.locationDamageMultipliers = fullDef->locationDamageMultipliers;
}
if (fullDef->weapCompleteDef.scopes)
{
memcpy(fullDef->scopes, fullDef->weapCompleteDef.scopes, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::scopes)>);
fullDef->weapCompleteDef.scopes = fullDef->scopes;
}
if (fullDef->weapCompleteDef.underBarrels)
{
memcpy(fullDef->underBarrels, fullDef->weapCompleteDef.underBarrels, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::underBarrels)>);
fullDef->weapCompleteDef.underBarrels = fullDef->underBarrels;
}
if (fullDef->weapCompleteDef.others)
{
memcpy(fullDef->others, fullDef->weapCompleteDef.others, sizeof(void*) * std::extent_v<decltype(WeaponFullDef::others)>);
fullDef->weapCompleteDef.others = fullDef->others;
}
}
InfoString AssetDumperWeapon::CreateInfoString(XAssetInfo<WeaponCompleteDef>* asset)