diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp index 59d1638de..88c950a11 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp @@ -24,34 +24,36 @@ namespace T6 std::vector valueArray; if (!ParseAsArray(value, valueArray)) { - std::cout << "Failed to parse hide tags as array" << std::endl; + std::cout << "Failed to parse hide tags as array\n"; return false; } - if (valueArray.size() > std::extent::value) + if (valueArray.size() > std::extent_v) { - std::cout << "Cannot have more than " << std::extent::value << " hide tags!" << std::endl; + std::cout << "Cannot have more than " << std::extent_v << " hide tags!\n"; return false; } auto* hideTags = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - auto currentHideTag = 0u; - if (valueArray.size() < std::extent::value) + if (valueArray.size() < std::extent_v) { - m_used_script_string_list.emplace(m_zone_script_strings.AddOrGetScriptString("")); + m_used_script_string_list.emplace(m_zone_script_strings.AddOrGetScriptString(nullptr)); } + auto currentHideTag = 0u; for (; currentHideTag < valueArray.size(); currentHideTag++) { - const auto scrString = m_zone_script_strings.AddOrGetScriptString(valueArray[currentHideTag]); + const auto& currentValue = valueArray[currentHideTag]; + const auto scrString = + !currentValue.empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue) : m_zone_script_strings.AddOrGetScriptString(nullptr); hideTags[currentHideTag] = scrString; m_used_script_string_list.emplace(scrString); } - for (; currentHideTag < std::extent::value; currentHideTag++) + for (; currentHideTag < std::extent_v; currentHideTag++) { - hideTags[currentHideTag] = m_zone_script_strings.GetScriptString(""); + hideTags[currentHideTag] = m_zone_script_strings.GetScriptString(nullptr); } return true; @@ -81,38 +83,43 @@ namespace T6 std::vector> pairs; if (!ParseAsPairs(value, pairs)) { - std::cout << "Failed to parse notetracksoundmap as pairs" << std::endl; + std::cout << "Failed to parse notetracksoundmap as pairs\n"; return false; } - if (pairs.size() > std::extent::value) + if (pairs.size() > std::extent_v) { - std::cout << "Cannot have more than " << std::extent::value << " notetracksoundmap entries!" - << std::endl; + std::cout << "Cannot have more than " << std::extent_v << " notetracksoundmap entries!\n"; return false; } auto* keys = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - auto* values = &keys[std::extent::value]; + auto* values = &keys[std::extent_v]; auto currentEntryNum = 0u; - if (pairs.size() < std::extent::value) + if (pairs.size() < std::extent_v) { - m_used_script_string_list.emplace(m_zone_script_strings.AddOrGetScriptString("")); + m_used_script_string_list.emplace(m_zone_script_strings.AddOrGetScriptString(nullptr)); } for (; currentEntryNum < pairs.size(); currentEntryNum++) { - keys[currentEntryNum] = m_zone_script_strings.AddOrGetScriptString(pairs[currentEntryNum].first); - m_used_script_string_list.emplace(keys[currentEntryNum]); + const auto& currentValue = pairs[currentEntryNum]; + const auto keyScriptString = !currentValue.first.empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue.first) + : m_zone_script_strings.AddOrGetScriptString(nullptr); + const auto valueScriptString = !currentValue.second.empty() ? m_zone_script_strings.AddOrGetScriptString(currentValue.second) + : m_zone_script_strings.AddOrGetScriptString(nullptr); + + keys[currentEntryNum] = keyScriptString; + m_used_script_string_list.emplace(keyScriptString); - values[currentEntryNum] = m_zone_script_strings.AddOrGetScriptString(pairs[currentEntryNum].second); - m_used_script_string_list.emplace(values[currentEntryNum]); + values[currentEntryNum] = valueScriptString; + m_used_script_string_list.emplace(valueScriptString); } - for (; currentEntryNum < std::extent::value; currentEntryNum++) + for (; currentEntryNum < std::extent_v; currentEntryNum++) { - const auto emptyScr = m_zone_script_strings.GetScriptString(""); + const auto emptyScr = m_zone_script_strings.GetScriptString(nullptr); keys[currentEntryNum] = emptyScr; values[currentEntryNum] = emptyScr; } @@ -201,7 +208,7 @@ namespace T6 } auto** attachmentUniques = reinterpret_cast(reinterpret_cast(m_structure) + field.iOffset); - auto attachmentCombinationIndex = std::extent::value; + auto attachmentCombinationIndex = std::extent_v; for (const auto& attachmentUniqueName : valueArray) { @@ -216,10 +223,10 @@ namespace T6 if (HasMoreThanOneAttachmentSetInMask(attachmentUniqueAsset->combinedAttachmentTypeMask)) { - if (attachmentCombinationIndex >= std::extent::value) + if (attachmentCombinationIndex >= std::extent_v) { std::cout << "Cannot have more than " - << (std::extent::value - std::extent::value) + << (std::extent_v - std::extent_v) << " combined attachment attachment unique entries!" << std::endl; return false; } @@ -258,74 +265,74 @@ namespace T6 switch (static_cast(field.iFieldType)) { case WFT_WEAPONTYPE: - return ConvertEnumInt(value, field.iOffset, szWeapTypeNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, szWeapTypeNames, std::extent_v); case WFT_WEAPONCLASS: - return ConvertEnumInt(value, field.iOffset, szWeapClassNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, szWeapClassNames, std::extent_v); case WFT_OVERLAYRETICLE: - return ConvertEnumInt(value, field.iOffset, szWeapOverlayReticleNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, szWeapOverlayReticleNames, std::extent_v); case WFT_PENETRATE_TYPE: - return ConvertEnumInt(value, field.iOffset, penetrateTypeNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, penetrateTypeNames, std::extent_v); case WFT_IMPACT_TYPE: - return ConvertEnumInt(value, field.iOffset, impactTypeNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, impactTypeNames, std::extent_v); case WFT_STANCE: - return ConvertEnumInt(value, field.iOffset, szWeapStanceNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, szWeapStanceNames, std::extent_v); case WFT_PROJ_EXPLOSION: - return ConvertEnumInt(value, field.iOffset, szProjectileExplosionNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, szProjectileExplosionNames, std::extent_v); case WFT_OFFHAND_CLASS: - return ConvertEnumInt(value, field.iOffset, offhandClassNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, offhandClassNames, std::extent_v); case WFT_OFFHAND_SLOT: - return ConvertEnumInt(value, field.iOffset, offhandSlotNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, offhandSlotNames, std::extent_v); case WFT_ANIMTYPE: - return ConvertEnumInt(value, field.iOffset, playerAnimTypeNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, playerAnimTypeNames, std::extent_v); case WFT_ACTIVE_RETICLE_TYPE: - return ConvertEnumInt(value, field.iOffset, activeReticleNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, activeReticleNames, std::extent_v); case WFT_GUIDED_MISSILE_TYPE: - return ConvertEnumInt(value, field.iOffset, guidedMissileNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, guidedMissileNames, std::extent_v); case WFT_BOUNCE_SOUND: return ConvertBounceSounds(field, value); case WFT_STICKINESS: - return ConvertEnumInt(value, field.iOffset, stickinessNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, stickinessNames, std::extent_v); case WFT_ROTATETYPE: - return ConvertEnumInt(value, field.iOffset, rotateTypeNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, rotateTypeNames, std::extent_v); case WFT_OVERLAYINTERFACE: - return ConvertEnumInt(value, field.iOffset, overlayInterfaceNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, overlayInterfaceNames, std::extent_v); case WFT_INVENTORYTYPE: - return ConvertEnumInt(value, field.iOffset, szWeapInventoryTypeNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, szWeapInventoryTypeNames, std::extent_v); case WFT_FIRETYPE: - return ConvertEnumInt(value, field.iOffset, szWeapFireTypeNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, szWeapFireTypeNames, std::extent_v); case WFT_CLIPTYPE: - return ConvertEnumInt(value, field.iOffset, szWeapClipTypeNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, szWeapClipTypeNames, std::extent_v); case WFT_AMMOCOUNTER_CLIPTYPE: - return ConvertEnumInt(value, field.iOffset, ammoCounterClipNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, ammoCounterClipNames, std::extent_v); case WFT_ICONRATIO_HUD: case WFT_ICONRATIO_AMMOCOUNTER: case WFT_ICONRATIO_KILL: case WFT_ICONRATIO_DPAD: case WFT_ICONRATIO_INDICATOR: - return ConvertEnumInt(value, field.iOffset, weapIconRatioNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, weapIconRatioNames, std::extent_v); case WFT_BARRELTYPE: - return ConvertEnumInt(value, field.iOffset, barrelTypeNames, std::extent::value); + return ConvertEnumInt(value, field.iOffset, barrelTypeNames, std::extent_v); case WFT_HIDETAGS: return ConvertHideTags(field, value); @@ -418,7 +425,7 @@ bool AssetLoaderWeapon::IsStringOverride(const char* str1, const char* str2) return strcmp(str1, str2) != 0; } -bool AssetLoaderWeapon::IsFxOverride(FxEffectDef* effect1, FxEffectDef* effect2) +bool AssetLoaderWeapon::IsFxOverride(const FxEffectDef* effect1, const FxEffectDef* effect2) { if ((effect1 == nullptr) != (effect2 == nullptr)) return true; @@ -439,20 +446,20 @@ void AssetLoaderWeapon::HandleSoundOverride(WeaponAttachmentUnique* attachmentUn } void AssetLoaderWeapon::HandleFxOverride(WeaponAttachmentUnique* attachmentUnique, - FxEffectDef* effect1, - FxEffectDef* effect2, + const FxEffectDef* effect1, + const FxEffectDef* effect2, const eAttachmentOverrideEffects fxOverrideIndex) { if (IsFxOverride(effect1, effect2)) attachmentUnique->effectOverrides |= 1 << static_cast(fxOverrideIndex); } -void AssetLoaderWeapon::CalculateAttachmentFields(WeaponFullDef* weapon, unsigned attachmentIndex, WeaponAttachmentUnique* attachmentUnique) +void AssetLoaderWeapon::CalculateAttachmentFields(const WeaponFullDef* weapon, unsigned attachmentIndex, WeaponAttachmentUnique* attachmentUnique) { for (auto& val : attachmentUnique->animationOverrides) val = 0; - for (auto animIndex = 0u; animIndex < std::extent::value; animIndex++) + for (auto animIndex = 0u; animIndex < std::extent_v; animIndex++) { if (IsStringOverride(weapon->szXAnims[animIndex], attachmentUnique->szXAnims[animIndex])) attachmentUnique->animationOverrides[animIndex / 32] |= 1 << (animIndex % 32); @@ -485,8 +492,8 @@ void AssetLoaderWeapon::CalculateAttachmentFields(WeaponFullDef* weapon, unsigne if (attachmentUnique->combinedAttachmentTypeMask == 0) { WeaponAttachmentUnique* lastSibling = nullptr; - for (auto attachmentUniqueIndex = std::extent::value; - attachmentUniqueIndex < std::extent::value; + for (auto attachmentUniqueIndex = std::extent_v; + attachmentUniqueIndex < std::extent_v; attachmentUniqueIndex++) { if (weapon->attachmentUniques[attachmentUniqueIndex] != nullptr @@ -516,7 +523,7 @@ void AssetLoaderWeapon::CalculateAttachmentFields(WeaponFullDef* weapon, unsigne void AssetLoaderWeapon::CalculateAttachmentFields(WeaponFullDef* weapon) { - for (auto attachmentUniqueIndex = 0u; attachmentUniqueIndex < std::extent::value; attachmentUniqueIndex++) + for (auto attachmentUniqueIndex = 0u; attachmentUniqueIndex < std::extent_v; attachmentUniqueIndex++) { if (weapon->attachmentUniques[attachmentUniqueIndex] == nullptr) continue; @@ -533,7 +540,7 @@ bool AssetLoaderWeapon::LoadFromInfoString( LinkWeaponFullDefSubStructs(weaponFullDef); InfoStringToWeaponConverter converter( - infoString, weaponFullDef, zone->m_script_strings, memory, manager, weapon_fields, std::extent::value); + infoString, weaponFullDef, zone->m_script_strings, memory, manager, weapon_fields, std::extent_v); if (!converter.Convert()) { std::cout << "Failed to parse weapon: \"" << assetName << "\"" << std::endl; diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.h index d2ba1e041..301258b5d 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.h +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.h @@ -12,14 +12,16 @@ namespace T6 static void LinkWeaponFullDefSubStructs(WeaponFullDef* weapon); static bool IsStringOverride(const char* str1, const char* str2); - static bool IsFxOverride(FxEffectDef* effect1, FxEffectDef* effect2); + static bool IsFxOverride(const FxEffectDef* effect1, const FxEffectDef* effect2); static void HandleSoundOverride(WeaponAttachmentUnique* attachmentUnique, const char* snd1, const char* snd2, eAttachmentOverrideSounds sndOverrideIndex); - static void - HandleFxOverride(WeaponAttachmentUnique* attachmentUnique, FxEffectDef* effect1, FxEffectDef* effect2, eAttachmentOverrideEffects fxOverrideIndex); + static void HandleFxOverride(WeaponAttachmentUnique* attachmentUnique, + const FxEffectDef* effect1, + const FxEffectDef* effect2, + eAttachmentOverrideEffects fxOverrideIndex); static void CalculateWeaponFields(WeaponFullDef* weapon); - static void CalculateAttachmentFields(WeaponFullDef* weapon, unsigned attachmentIndex, WeaponAttachmentUnique* attachmentUnique); + static void CalculateAttachmentFields(const WeaponFullDef* weapon, unsigned attachmentIndex, WeaponAttachmentUnique* attachmentUnique); static void CalculateAttachmentFields(WeaponFullDef* weapon); static bool