Merge pull request #118 from Laupetin/fix/attachment-unique-hidetags

fix: weapon attachment unique hidetags not making a difference between nullptr and empty string
This commit is contained in:
Jan 2024-02-14 00:06:24 +01:00 committed by GitHub
commit d712cbd2f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 38 deletions

View File

@ -24,13 +24,13 @@ namespace T6
std::vector<std::string> valueArray;
if (!ParseAsArray(value, valueArray))
{
std::cout << "Failed to parse hide tags as array\n";
std::cerr << "Failed to parse hide tags as array\n";
return false;
}
if (valueArray.size() > std::extent_v<decltype(WeaponFullDef::hideTags)>)
{
std::cout << "Cannot have more than " << std::extent_v<decltype(WeaponFullDef::hideTags)> << " hide tags!\n";
std::cerr << "Cannot have more than " << std::extent_v<decltype(WeaponFullDef::hideTags)> << " hide tags!\n";
return false;
}
@ -83,13 +83,13 @@ namespace T6
std::vector<std::pair<std::string, std::string>> pairs;
if (!ParseAsPairs(value, pairs))
{
std::cout << "Failed to parse notetracksoundmap as pairs\n";
std::cerr << "Failed to parse notetracksoundmap as pairs\n";
return false;
}
if (pairs.size() > std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)>)
{
std::cout << "Cannot have more than " << std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)> << " notetracksoundmap entries!\n";
std::cerr << "Cannot have more than " << std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)> << " notetracksoundmap entries!\n";
return false;
}
@ -139,7 +139,7 @@ namespace T6
if (camo == nullptr)
{
std::cout << "Failed to load camo asset \"" << value << "\"" << std::endl;
std::cerr << "Failed to load camo asset \"" << value << "\"\n";
return false;
}
@ -154,7 +154,7 @@ namespace T6
std::vector<std::string> valueArray;
if (!ParseAsArray(value, valueArray))
{
std::cout << "Failed to parse attachments as array" << std::endl;
std::cerr << "Failed to parse attachments as array\n";
return false;
}
@ -165,7 +165,7 @@ namespace T6
auto* attachmentAssetInfo = m_loading_manager->LoadDependency(ASSET_TYPE_ATTACHMENT, attachmentName);
if (attachmentAssetInfo == nullptr)
{
std::cout << "Failed to load attachment asset \"" << attachmentName << "\"" << std::endl;
std::cerr << "Failed to load attachment asset \"" << attachmentName << "\"\n";
return false;
}
@ -173,15 +173,14 @@ namespace T6
if (static_cast<unsigned>(attachmentAsset->attachmentType) >= ATTACHMENT_TYPE_COUNT)
{
std::cout << "Invalid attachment type " << attachmentAsset->attachmentType << " for attachment asset \"" << attachmentName << "\""
<< std::endl;
std::cerr << "Invalid attachment type " << attachmentAsset->attachmentType << " for attachment asset \"" << attachmentName << "\"\n";
return false;
}
if (attachments[attachmentAsset->attachmentType] != nullptr)
{
std::cout << "Already loaded attachment with same type " << attachmentAsset->attachmentType << ": \""
<< attachments[attachmentAsset->attachmentType]->szInternalName << "\", \"" << attachmentName << "\"" << std::endl;
std::cerr << "Already loaded attachment with same type " << attachmentAsset->attachmentType << ": \""
<< attachments[attachmentAsset->attachmentType]->szInternalName << "\", \"" << attachmentName << "\"\n";
return false;
}
@ -203,7 +202,7 @@ namespace T6
std::vector<std::string> valueArray;
if (!ParseAsArray(value, valueArray))
{
std::cout << "Failed to parse attachment uniques as array" << std::endl;
std::cerr << "Failed to parse attachment uniques as array\n";
return false;
}
@ -215,7 +214,7 @@ namespace T6
auto* attachmentUniqueAssetInfo = m_loading_manager->LoadDependency(ASSET_TYPE_ATTACHMENT_UNIQUE, attachmentUniqueName);
if (attachmentUniqueAssetInfo == nullptr)
{
std::cout << "Failed to load attachment unique asset \"" << attachmentUniqueName << "\"" << std::endl;
std::cerr << "Failed to load attachment unique asset \"" << attachmentUniqueName << "\"\n";
return false;
}
@ -225,7 +224,7 @@ namespace T6
{
if (attachmentCombinationIndex >= std::extent_v<decltype(WeaponFullDef::attachmentUniques)>)
{
std::cout << "Cannot have more than "
std::cerr << "Cannot have more than "
<< (std::extent_v<decltype(WeaponFullDef::attachmentUniques)> - std::extent_v<decltype(WeaponFullDef::attachments)>)
<< " combined attachment attachment unique entries!\n";
return false;
@ -238,14 +237,14 @@ namespace T6
{
if (static_cast<unsigned>(attachmentUniqueAsset->attachmentType) >= ATTACHMENT_TYPE_COUNT)
{
std::cout << "Invalid attachment type " << attachmentUniqueAsset->attachmentType << " for attachment unique asset \""
std::cerr << "Invalid attachment type " << attachmentUniqueAsset->attachmentType << " for attachment unique asset \""
<< attachmentUniqueName << "\"\n";
return false;
}
if (attachmentUniques[attachmentUniqueAsset->attachmentType] != nullptr)
{
std::cout << "Already loaded attachment unique with same type " << attachmentUniqueAsset->attachmentType << ": \""
std::cerr << "Already loaded attachment unique with same type " << attachmentUniqueAsset->attachmentType << ": \""
<< attachmentUniques[attachmentUniqueAsset->attachmentType]->szInternalName << "\", \"" << attachmentUniqueName << "\"\n";
return false;
}
@ -534,7 +533,7 @@ void AssetLoaderWeapon::CalculateAttachmentFields(const WeaponFullDef* weapon, u
}
}
void AssetLoaderWeapon::CalculateAttachmentFields(WeaponFullDef* weapon)
void AssetLoaderWeapon::CalculateAttachmentFields(const WeaponFullDef* weapon)
{
for (auto attachmentUniqueIndex = 0u; attachmentUniqueIndex < std::extent_v<decltype(WeaponFullDef::attachmentUniques)>; attachmentUniqueIndex++)
{
@ -556,7 +555,7 @@ bool AssetLoaderWeapon::LoadFromInfoString(
infoString, weaponFullDef, zone->m_script_strings, memory, manager, weapon_fields, std::extent_v<decltype(weapon_fields)>);
if (!converter.Convert())
{
std::cout << "Failed to parse weapon: \"" << assetName << "\"" << std::endl;
std::cerr << "Failed to parse weapon: \"" << assetName << "\"\n";
return true;
}
@ -594,14 +593,14 @@ bool AssetLoaderWeapon::CanLoadFromGdt() const
bool AssetLoaderWeapon::LoadFromGdt(
const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
{
auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON, assetName);
const auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON, assetName);
if (gdtEntry == nullptr)
return false;
InfoString infoString;
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read weapon gdt entry: \"" << assetName << "\"" << std::endl;
std::cerr << "Failed to read weapon gdt entry: \"" << assetName << "\"\n";
return true;
}
@ -624,7 +623,7 @@ bool AssetLoaderWeapon::LoadFromRaw(
InfoString infoString;
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON, *file.m_stream))
{
std::cout << "Failed to read weapon raw file: \"" << fileName << "\"" << std::endl;
std::cerr << "Failed to read weapon raw file: \"" << fileName << "\"\n";
return true;
}

View File

@ -22,7 +22,7 @@ namespace T6
static void CalculateWeaponFields(WeaponFullDef* weapon);
static void CalculateAttachmentFields(const WeaponFullDef* weapon, unsigned attachmentIndex, WeaponAttachmentUnique* attachmentUnique);
static void CalculateAttachmentFields(WeaponFullDef* weapon);
static void CalculateAttachmentFields(const WeaponFullDef* weapon);
static bool
LoadFromInfoString(const InfoString& infoString, const std::string& assetName, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone);

View File

@ -48,7 +48,7 @@ namespace T6
ATTACHMENT_POINT_TOP, // vzoom
};
static_assert(std::extent<decltype(attachmentPointByAttachmentTable)>::value == ATTACHMENT_TYPE_COUNT);
static_assert(std::extent_v<decltype(attachmentPointByAttachmentTable)> == ATTACHMENT_TYPE_COUNT);
class InfoStringToWeaponAttachmentConverter final : public InfoStringToStructConverter
{
@ -58,13 +58,13 @@ namespace T6
switch (static_cast<attachmentFieldType_t>(field.iFieldType))
{
case AFT_ATTACHMENTTYPE:
return ConvertEnumInt(value, field.iOffset, szAttachmentTypeNames, std::extent<decltype(szAttachmentTypeNames)>::value);
return ConvertEnumInt(value, field.iOffset, szAttachmentTypeNames, std::extent_v<decltype(szAttachmentTypeNames)>);
case AFT_PENETRATE_TYPE:
return ConvertEnumInt(value, field.iOffset, penetrateTypeNames, std::extent<decltype(penetrateTypeNames)>::value);
return ConvertEnumInt(value, field.iOffset, penetrateTypeNames, std::extent_v<decltype(penetrateTypeNames)>);
case AFT_FIRETYPE:
return ConvertEnumInt(value, field.iOffset, szWeapFireTypeNames, std::extent<decltype(szWeapFireTypeNames)>::value);
return ConvertEnumInt(value, field.iOffset, szWeapFireTypeNames, std::extent_v<decltype(szWeapFireTypeNames)>);
default:
assert(false);
@ -102,17 +102,18 @@ bool AssetLoaderWeaponAttachment::LoadFromInfoString(
memset(attachment, 0, sizeof(WeaponAttachment));
InfoStringToWeaponAttachmentConverter converter(
infoString, attachment, zone->m_script_strings, memory, manager, attachment_fields, std::extent<decltype(attachment_fields)>::value);
infoString, attachment, zone->m_script_strings, memory, manager, attachment_fields, std::extent_v<decltype(attachment_fields)>);
if (!converter.Convert())
{
std::cout << "Failed to parse attachment: \"" << assetName << "\"" << std::endl;
std::cerr << "Failed to parse attachment: \"" << assetName << "\"\n";
return true;
}
CalculateAttachmentFields(attachment);
attachment->szInternalName = memory->Dup(assetName.c_str());
manager->AddAsset(ASSET_TYPE_ATTACHMENT, assetName, attachment, converter.GetDependencies(), converter.GetUsedScriptStrings());
manager->AddAsset(
ASSET_TYPE_ATTACHMENT, assetName, attachment, converter.GetDependencies(), converter.GetUsedScriptStrings(), converter.GetIndirectAssetReferences());
return true;
}
@ -134,14 +135,14 @@ bool AssetLoaderWeaponAttachment::CanLoadFromGdt() const
bool AssetLoaderWeaponAttachment::LoadFromGdt(
const std::string& assetName, IGdtQueryable* gdtQueryable, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
{
auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT, assetName);
const auto* gdtEntry = gdtQueryable->GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_WEAPON_ATTACHMENT, assetName);
if (gdtEntry == nullptr)
return false;
InfoString infoString;
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cout << "Failed to read attachment gdt entry: \"" << assetName << "\"" << std::endl;
std::cerr << "Failed to read attachment gdt entry: \"" << assetName << "\"\n";
return true;
}
@ -164,7 +165,7 @@ bool AssetLoaderWeaponAttachment::LoadFromRaw(
InfoString infoString;
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT, *file.m_stream))
{
std::cout << "Failed to read attachment raw file: \"" << fileName << "\"" << std::endl;
std::cerr << "Failed to read attachment raw file: \"" << fileName << "\"\n";
return true;
}

View File

@ -23,34 +23,36 @@ namespace T6
std::vector<std::string> valueArray;
if (!ParseAsArray(value, valueArray))
{
std::cerr << "Failed to parse hide tags as array" << std::endl;
std::cerr << "Failed to parse hide tags as array\n";
return false;
}
if (valueArray.size() > std::extent_v<decltype(WeaponFullDef::hideTags)>)
{
std::cerr << "Cannot have more than " << std::extent_v<decltype(WeaponFullDef::hideTags)> << " hide tags!" << std::endl;
std::cerr << "Cannot have more than " << std::extent_v<decltype(WeaponFullDef::hideTags)> << " hide tags!\n";
return false;
}
auto* hideTags = reinterpret_cast<scr_string_t*>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
auto currentHideTag = 0u;
if (valueArray.size() < std::extent_v<decltype(WeaponFullDef::hideTags)>)
{
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_v<decltype(WeaponFullDef::hideTags)>; currentHideTag++)
{
hideTags[currentHideTag] = m_zone_script_strings.GetScriptString("");
hideTags[currentHideTag] = m_zone_script_strings.GetScriptString(nullptr);
}
return true;