mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
Merge branch 'Laupetin:main' into main
This commit is contained in:
@ -19,17 +19,15 @@ AssetLoadingContext* AssetLoadingManager::GetAssetLoadingContext() const
|
||||
return &m_context;
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetLoadingManager::AddAsset(const asset_type_t assetType,
|
||||
const std::string& assetName,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings,
|
||||
Zone* zone)
|
||||
XAssetInfoGeneric* AssetLoadingManager::AddAssetInternal(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
m_last_dependency_loaded = m_context.m_zone->m_pools->AddAsset(assetType, assetName, asset, std::move(dependencies), std::move(usedScriptStrings), zone);
|
||||
const auto assetType = xAssetInfo->m_type;
|
||||
const auto* pAssetName = xAssetInfo->m_name.c_str();
|
||||
|
||||
m_last_dependency_loaded = m_context.m_zone->m_pools->AddAsset(std::move(xAssetInfo));
|
||||
if (m_last_dependency_loaded == nullptr)
|
||||
std::cout << "Failed to add asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\" to pool: \"" << assetName << "\""
|
||||
<< std::endl;
|
||||
std::cout << "Failed to add asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\" to pool: \"" << pAssetName << "\"\n";
|
||||
|
||||
return m_last_dependency_loaded;
|
||||
}
|
||||
|
||||
@ -39,11 +37,24 @@ XAssetInfoGeneric* AssetLoadingManager::AddAsset(const asset_type_t assetType,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings)
|
||||
{
|
||||
m_last_dependency_loaded = m_context.m_zone->m_pools->AddAsset(assetType, assetName, asset, std::move(dependencies), std::move(usedScriptStrings));
|
||||
if (m_last_dependency_loaded == nullptr)
|
||||
std::cout << "Failed to add asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\" to pool: \"" << assetName << "\""
|
||||
<< std::endl;
|
||||
return m_last_dependency_loaded;
|
||||
return AddAsset(std::make_unique<XAssetInfoGeneric>(assetType, assetName, asset, std::move(dependencies), std::move(usedScriptStrings)));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetLoadingManager::AddAsset(asset_type_t assetType,
|
||||
const std::string& assetName,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences)
|
||||
{
|
||||
return AddAsset(std::make_unique<XAssetInfoGeneric>(
|
||||
assetType, assetName, asset, std::move(dependencies), std::move(usedScriptStrings), std::move(indirectAssetReferences)));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetLoadingManager::AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo)
|
||||
{
|
||||
xAssetInfo->m_zone = m_context.m_zone;
|
||||
return AddAssetInternal(std::move(xAssetInfo));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetLoadingManager::LoadIgnoredDependency(const asset_type_t assetType, const std::string& assetName, IAssetLoader* loader)
|
||||
@ -64,20 +75,13 @@ XAssetInfoGeneric* AssetLoadingManager::LoadIgnoredDependency(const asset_type_t
|
||||
auto* existingAsset = loader->LoadFromGlobalAssetPools(assetName);
|
||||
if (existingAsset)
|
||||
{
|
||||
std::vector<XAssetInfoGeneric*> dependencies;
|
||||
AddAsset(existingAsset->m_type,
|
||||
existingAsset->m_name,
|
||||
existingAsset->m_ptr,
|
||||
std::vector<XAssetInfoGeneric*>(),
|
||||
std::vector<scr_string_t>(),
|
||||
existingAsset->m_zone);
|
||||
AddAssetInternal(std::make_unique<XAssetInfoGeneric>(*existingAsset));
|
||||
auto* lastDependency = m_last_dependency_loaded;
|
||||
m_last_dependency_loaded = nullptr;
|
||||
return lastDependency;
|
||||
}
|
||||
|
||||
std::cout << "Failed to create empty asset \"" << assetName << "\" for type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\""
|
||||
<< std::endl;
|
||||
std::cout << "Failed to create empty asset \"" << assetName << "\" for type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\"\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -105,6 +109,7 @@ XAssetInfoGeneric* AssetLoadingManager::LoadAssetDependency(const asset_type_t a
|
||||
if (existingAsset)
|
||||
{
|
||||
std::vector<XAssetInfoGeneric*> dependencies;
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences;
|
||||
for (const auto* dependency : existingAsset->m_dependencies)
|
||||
{
|
||||
auto* newDependency = LoadDependency(dependency->m_type, dependency->m_name);
|
||||
@ -114,23 +119,29 @@ XAssetInfoGeneric* AssetLoadingManager::LoadAssetDependency(const asset_type_t a
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
indirectAssetReferences.reserve(existingAsset->m_indirect_asset_references.size());
|
||||
for (const auto& indirectAssetReference : existingAsset->m_indirect_asset_references)
|
||||
indirectAssetReferences.emplace_back(LoadIndirectAssetReference(indirectAssetReference.m_type, indirectAssetReference.m_name));
|
||||
|
||||
// Make sure any used script string is available in the created zone
|
||||
// The replacement of the scr_string_t values will be done upon writing
|
||||
for (const auto scrString : existingAsset->m_used_script_strings)
|
||||
m_context.m_zone->m_script_strings.AddOrGetScriptString(existingAsset->m_zone->m_script_strings.CValue(scrString));
|
||||
|
||||
AddAsset(existingAsset->m_type,
|
||||
existingAsset->m_name,
|
||||
existingAsset->m_ptr,
|
||||
std::move(dependencies),
|
||||
existingAsset->m_used_script_strings,
|
||||
existingAsset->m_zone);
|
||||
AddAssetInternal(std::make_unique<XAssetInfoGeneric>(existingAsset->m_type,
|
||||
existingAsset->m_name,
|
||||
existingAsset->m_ptr,
|
||||
std::move(dependencies),
|
||||
existingAsset->m_used_script_strings,
|
||||
std::move(indirectAssetReferences),
|
||||
existingAsset->m_zone));
|
||||
|
||||
auto* lastDependency = m_last_dependency_loaded;
|
||||
m_last_dependency_loaded = nullptr;
|
||||
return lastDependency;
|
||||
}
|
||||
|
||||
std::cout << "Failed to load asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\": \"" << assetName << "\"" << std::endl;
|
||||
std::cout << "Failed to load asset of type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\": \"" << assetName << "\"\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -154,6 +165,27 @@ XAssetInfoGeneric* AssetLoadingManager::LoadDependency(const asset_type_t assetT
|
||||
return LoadAssetDependency(assetType, assetName, loader->second.get());
|
||||
}
|
||||
|
||||
std::cout << "Failed to find loader for asset type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\"" << std::endl;
|
||||
std::cout << "Failed to find loader for asset type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\"\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IndirectAssetReference AssetLoadingManager::LoadIndirectAssetReference(const asset_type_t assetType, const std::string& assetName)
|
||||
{
|
||||
const auto* alreadyLoadedAsset = m_context.m_zone->m_pools->GetAsset(assetType, assetName);
|
||||
if (alreadyLoadedAsset)
|
||||
return IndirectAssetReference(assetType, assetName);
|
||||
|
||||
const auto ignoreEntry = m_context.m_ignored_asset_map.find(assetName);
|
||||
if (ignoreEntry != m_context.m_ignored_asset_map.end() && ignoreEntry->second == assetType)
|
||||
return IndirectAssetReference(assetType, assetName);
|
||||
|
||||
const auto loader = m_asset_loaders_by_type.find(assetType);
|
||||
if (loader != m_asset_loaders_by_type.end())
|
||||
{
|
||||
LoadAssetDependency(assetType, assetName, loader->second.get());
|
||||
return IndirectAssetReference(assetType, assetName);
|
||||
}
|
||||
|
||||
std::cout << "Failed to find loader for asset type \"" << m_context.m_zone->m_pools->GetAssetTypeName(assetType) << "\"\n";
|
||||
return IndirectAssetReference(assetType, assetName);
|
||||
}
|
||||
|
@ -14,12 +14,7 @@ class AssetLoadingManager final : public IAssetLoadingManager
|
||||
XAssetInfoGeneric* LoadIgnoredDependency(asset_type_t assetType, const std::string& assetName, IAssetLoader* loader);
|
||||
XAssetInfoGeneric* LoadAssetDependency(asset_type_t assetType, const std::string& assetName, IAssetLoader* loader);
|
||||
|
||||
XAssetInfoGeneric* AddAsset(asset_type_t assetType,
|
||||
const std::string& assetName,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings,
|
||||
Zone* zone);
|
||||
XAssetInfoGeneric* AddAssetInternal(std::unique_ptr<XAssetInfoGeneric> xAssetInfo);
|
||||
|
||||
public:
|
||||
AssetLoadingManager(const std::map<asset_type_t, std::unique_ptr<IAssetLoader>>& assetLoadersByType, AssetLoadingContext& context);
|
||||
@ -33,5 +28,13 @@ public:
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings) override;
|
||||
XAssetInfoGeneric* AddAsset(asset_type_t assetType,
|
||||
const std::string& assetName,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences) override;
|
||||
XAssetInfoGeneric* AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) override;
|
||||
XAssetInfoGeneric* LoadDependency(asset_type_t assetType, const std::string& assetName) override;
|
||||
IndirectAssetReference LoadIndirectAssetReference(asset_type_t assetType, const std::string& assetName) override;
|
||||
};
|
||||
|
@ -23,6 +23,13 @@ public:
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings) = 0;
|
||||
virtual XAssetInfoGeneric* AddAsset(asset_type_t assetType,
|
||||
const std::string& assetName,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences) = 0;
|
||||
virtual XAssetInfoGeneric* AddAsset(std::unique_ptr<XAssetInfoGeneric> xAssetInfo) = 0;
|
||||
|
||||
XAssetInfoGeneric* AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset)
|
||||
{
|
||||
@ -30,4 +37,5 @@ public:
|
||||
}
|
||||
|
||||
virtual XAssetInfoGeneric* LoadDependency(asset_type_t assetType, const std::string& assetName) = 0;
|
||||
virtual IndirectAssetReference LoadIndirectAssetReference(asset_type_t assetType, const std::string& assetName) = 0;
|
||||
};
|
||||
|
@ -24,34 +24,36 @@ namespace T6
|
||||
std::vector<std::string> 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<decltype(WeaponFullDef::hideTags)>::value)
|
||||
if (valueArray.size() > std::extent_v<decltype(WeaponFullDef::hideTags)>)
|
||||
{
|
||||
std::cout << "Cannot have more than " << std::extent<decltype(WeaponFullDef::hideTags)>::value << " hide tags!" << std::endl;
|
||||
std::cout << "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<decltype(WeaponFullDef::hideTags)>::value)
|
||||
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<decltype(WeaponFullDef::hideTags)>::value; currentHideTag++)
|
||||
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;
|
||||
@ -81,38 +83,43 @@ namespace T6
|
||||
std::vector<std::pair<std::string, std::string>> 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<decltype(WeaponFullDef::notetrackSoundMapKeys)>::value)
|
||||
if (pairs.size() > std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)>)
|
||||
{
|
||||
std::cout << "Cannot have more than " << std::extent<decltype(WeaponFullDef::notetrackSoundMapKeys)>::value << " notetracksoundmap entries!"
|
||||
<< std::endl;
|
||||
std::cout << "Cannot have more than " << std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)> << " notetracksoundmap entries!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* keys = reinterpret_cast<scr_string_t*>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
auto* values = &keys[std::extent<decltype(WeaponFullDef::notetrackSoundMapKeys)>::value];
|
||||
auto* values = &keys[std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)>];
|
||||
auto currentEntryNum = 0u;
|
||||
|
||||
if (pairs.size() < std::extent<decltype(WeaponFullDef::notetrackSoundMapKeys)>::value)
|
||||
if (pairs.size() < std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)>)
|
||||
{
|
||||
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);
|
||||
|
||||
values[currentEntryNum] = m_zone_script_strings.AddOrGetScriptString(pairs[currentEntryNum].second);
|
||||
m_used_script_string_list.emplace(values[currentEntryNum]);
|
||||
keys[currentEntryNum] = keyScriptString;
|
||||
m_used_script_string_list.emplace(keyScriptString);
|
||||
|
||||
values[currentEntryNum] = valueScriptString;
|
||||
m_used_script_string_list.emplace(valueScriptString);
|
||||
}
|
||||
|
||||
for (; currentEntryNum < std::extent<decltype(WeaponFullDef::notetrackSoundMapKeys)>::value; currentEntryNum++)
|
||||
for (; currentEntryNum < std::extent_v<decltype(WeaponFullDef::notetrackSoundMapKeys)>; 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<WeaponAttachmentUnique**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
auto attachmentCombinationIndex = std::extent<decltype(WeaponFullDef::attachments)>::value;
|
||||
auto attachmentCombinationIndex = std::extent_v<decltype(WeaponFullDef::attachments)>;
|
||||
|
||||
for (const auto& attachmentUniqueName : valueArray)
|
||||
{
|
||||
@ -216,11 +223,11 @@ namespace T6
|
||||
|
||||
if (HasMoreThanOneAttachmentSetInMask(attachmentUniqueAsset->combinedAttachmentTypeMask))
|
||||
{
|
||||
if (attachmentCombinationIndex >= std::extent<decltype(WeaponFullDef::attachmentUniques)>::value)
|
||||
if (attachmentCombinationIndex >= std::extent_v<decltype(WeaponFullDef::attachmentUniques)>)
|
||||
{
|
||||
std::cout << "Cannot have more than "
|
||||
<< (std::extent<decltype(WeaponFullDef::attachmentUniques)>::value - std::extent<decltype(WeaponFullDef::attachments)>::value)
|
||||
<< " combined attachment attachment unique entries!" << std::endl;
|
||||
<< (std::extent_v<decltype(WeaponFullDef::attachmentUniques)> - std::extent_v<decltype(WeaponFullDef::attachments)>)
|
||||
<< " combined attachment attachment unique entries!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -232,15 +239,14 @@ namespace T6
|
||||
if (static_cast<unsigned>(attachmentUniqueAsset->attachmentType) >= ATTACHMENT_TYPE_COUNT)
|
||||
{
|
||||
std::cout << "Invalid attachment type " << attachmentUniqueAsset->attachmentType << " for attachment unique asset \""
|
||||
<< attachmentUniqueName << "\"" << std::endl;
|
||||
<< attachmentUniqueName << "\"\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (attachmentUniques[attachmentUniqueAsset->attachmentType] != nullptr)
|
||||
{
|
||||
std::cout << "Already loaded attachment unique with same type " << attachmentUniqueAsset->attachmentType << ": \""
|
||||
<< attachmentUniques[attachmentUniqueAsset->attachmentType]->szInternalName << "\", \"" << attachmentUniqueName << "\""
|
||||
<< std::endl;
|
||||
<< attachmentUniques[attachmentUniqueAsset->attachmentType]->szInternalName << "\", \"" << attachmentUniqueName << "\"\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -252,80 +258,92 @@ namespace T6
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConvertAnimName(const cspField_t& field, const std::string& value)
|
||||
{
|
||||
if (ConvertString(value, field.iOffset))
|
||||
{
|
||||
if (!value.empty())
|
||||
m_indirect_asset_references.emplace(m_loading_manager->LoadIndirectAssetReference(ASSET_TYPE_XANIMPARTS, value));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool ConvertExtensionField(const cspField_t& field, const std::string& value) override
|
||||
{
|
||||
switch (static_cast<weapFieldType_t>(field.iFieldType))
|
||||
{
|
||||
case WFT_WEAPONTYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapTypeNames, std::extent<decltype(szWeapTypeNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapTypeNames, std::extent_v<decltype(szWeapTypeNames)>);
|
||||
|
||||
case WFT_WEAPONCLASS:
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapClassNames, std::extent<decltype(szWeapClassNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapClassNames, std::extent_v<decltype(szWeapClassNames)>);
|
||||
|
||||
case WFT_OVERLAYRETICLE:
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapOverlayReticleNames, std::extent<decltype(szWeapOverlayReticleNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapOverlayReticleNames, std::extent_v<decltype(szWeapOverlayReticleNames)>);
|
||||
|
||||
case WFT_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 WFT_IMPACT_TYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, impactTypeNames, std::extent<decltype(impactTypeNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, impactTypeNames, std::extent_v<decltype(impactTypeNames)>);
|
||||
|
||||
case WFT_STANCE:
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapStanceNames, std::extent<decltype(szWeapStanceNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapStanceNames, std::extent_v<decltype(szWeapStanceNames)>);
|
||||
|
||||
case WFT_PROJ_EXPLOSION:
|
||||
return ConvertEnumInt(value, field.iOffset, szProjectileExplosionNames, std::extent<decltype(szProjectileExplosionNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, szProjectileExplosionNames, std::extent_v<decltype(szProjectileExplosionNames)>);
|
||||
|
||||
case WFT_OFFHAND_CLASS:
|
||||
return ConvertEnumInt(value, field.iOffset, offhandClassNames, std::extent<decltype(offhandClassNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, offhandClassNames, std::extent_v<decltype(offhandClassNames)>);
|
||||
|
||||
case WFT_OFFHAND_SLOT:
|
||||
return ConvertEnumInt(value, field.iOffset, offhandSlotNames, std::extent<decltype(offhandSlotNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, offhandSlotNames, std::extent_v<decltype(offhandSlotNames)>);
|
||||
|
||||
case WFT_ANIMTYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, playerAnimTypeNames, std::extent<decltype(playerAnimTypeNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, playerAnimTypeNames, std::extent_v<decltype(playerAnimTypeNames)>);
|
||||
|
||||
case WFT_ACTIVE_RETICLE_TYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, activeReticleNames, std::extent<decltype(activeReticleNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, activeReticleNames, std::extent_v<decltype(activeReticleNames)>);
|
||||
|
||||
case WFT_GUIDED_MISSILE_TYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, guidedMissileNames, std::extent<decltype(guidedMissileNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, guidedMissileNames, std::extent_v<decltype(guidedMissileNames)>);
|
||||
|
||||
case WFT_BOUNCE_SOUND:
|
||||
return ConvertBounceSounds(field, value);
|
||||
|
||||
case WFT_STICKINESS:
|
||||
return ConvertEnumInt(value, field.iOffset, stickinessNames, std::extent<decltype(stickinessNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, stickinessNames, std::extent_v<decltype(stickinessNames)>);
|
||||
|
||||
case WFT_ROTATETYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, rotateTypeNames, std::extent<decltype(rotateTypeNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, rotateTypeNames, std::extent_v<decltype(rotateTypeNames)>);
|
||||
|
||||
case WFT_OVERLAYINTERFACE:
|
||||
return ConvertEnumInt(value, field.iOffset, overlayInterfaceNames, std::extent<decltype(overlayInterfaceNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, overlayInterfaceNames, std::extent_v<decltype(overlayInterfaceNames)>);
|
||||
|
||||
case WFT_INVENTORYTYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapInventoryTypeNames, std::extent<decltype(szWeapInventoryTypeNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapInventoryTypeNames, std::extent_v<decltype(szWeapInventoryTypeNames)>);
|
||||
|
||||
case WFT_FIRETYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapFireTypeNames, std::extent<decltype(szWeapFireTypeNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapFireTypeNames, std::extent_v<decltype(szWeapFireTypeNames)>);
|
||||
|
||||
case WFT_CLIPTYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapClipTypeNames, std::extent<decltype(szWeapClipTypeNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, szWeapClipTypeNames, std::extent_v<decltype(szWeapClipTypeNames)>);
|
||||
|
||||
case WFT_AMMOCOUNTER_CLIPTYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, ammoCounterClipNames, std::extent<decltype(ammoCounterClipNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, ammoCounterClipNames, std::extent_v<decltype(ammoCounterClipNames)>);
|
||||
|
||||
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<decltype(weapIconRatioNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, weapIconRatioNames, std::extent_v<decltype(weapIconRatioNames)>);
|
||||
|
||||
case WFT_BARRELTYPE:
|
||||
return ConvertEnumInt(value, field.iOffset, barrelTypeNames, std::extent<decltype(barrelTypeNames)>::value);
|
||||
return ConvertEnumInt(value, field.iOffset, barrelTypeNames, std::extent_v<decltype(barrelTypeNames)>);
|
||||
|
||||
case WFT_HIDETAGS:
|
||||
return ConvertHideTags(field, value);
|
||||
@ -345,7 +363,9 @@ namespace T6
|
||||
case WFT_ATTACHMENT_UNIQUES:
|
||||
return ConvertAttachmentUniques(field, value);
|
||||
|
||||
case WFT_NUM_FIELD_TYPES:
|
||||
case WFT_ANIM_NAME:
|
||||
return ConvertAnimName(field, value);
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
return false;
|
||||
@ -418,7 +438,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 +459,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<unsigned>(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<decltype(WeaponFullDef::szXAnims)>::value; animIndex++)
|
||||
for (auto animIndex = 0u; animIndex < std::extent_v<decltype(WeaponFullDef::szXAnims)>; animIndex++)
|
||||
{
|
||||
if (IsStringOverride(weapon->szXAnims[animIndex], attachmentUnique->szXAnims[animIndex]))
|
||||
attachmentUnique->animationOverrides[animIndex / 32] |= 1 << (animIndex % 32);
|
||||
@ -485,8 +505,8 @@ void AssetLoaderWeapon::CalculateAttachmentFields(WeaponFullDef* weapon, unsigne
|
||||
if (attachmentUnique->combinedAttachmentTypeMask == 0)
|
||||
{
|
||||
WeaponAttachmentUnique* lastSibling = nullptr;
|
||||
for (auto attachmentUniqueIndex = std::extent<decltype(WeaponFullDef::attachments)>::value;
|
||||
attachmentUniqueIndex < std::extent<decltype(WeaponFullDef::attachmentUniques)>::value;
|
||||
for (auto attachmentUniqueIndex = std::extent_v<decltype(WeaponFullDef::attachments)>;
|
||||
attachmentUniqueIndex < std::extent_v<decltype(WeaponFullDef::attachmentUniques)>;
|
||||
attachmentUniqueIndex++)
|
||||
{
|
||||
if (weapon->attachmentUniques[attachmentUniqueIndex] != nullptr
|
||||
@ -516,7 +536,7 @@ void AssetLoaderWeapon::CalculateAttachmentFields(WeaponFullDef* weapon, unsigne
|
||||
|
||||
void AssetLoaderWeapon::CalculateAttachmentFields(WeaponFullDef* weapon)
|
||||
{
|
||||
for (auto attachmentUniqueIndex = 0u; attachmentUniqueIndex < std::extent<decltype(WeaponFullDef::attachmentUniques)>::value; attachmentUniqueIndex++)
|
||||
for (auto attachmentUniqueIndex = 0u; attachmentUniqueIndex < std::extent_v<decltype(WeaponFullDef::attachmentUniques)>; attachmentUniqueIndex++)
|
||||
{
|
||||
if (weapon->attachmentUniques[attachmentUniqueIndex] == nullptr)
|
||||
continue;
|
||||
@ -533,7 +553,7 @@ bool AssetLoaderWeapon::LoadFromInfoString(
|
||||
LinkWeaponFullDefSubStructs(weaponFullDef);
|
||||
|
||||
InfoStringToWeaponConverter converter(
|
||||
infoString, weaponFullDef, zone->m_script_strings, memory, manager, weapon_fields, std::extent<decltype(weapon_fields)>::value);
|
||||
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;
|
||||
@ -546,7 +566,12 @@ bool AssetLoaderWeapon::LoadFromInfoString(
|
||||
CalculateWeaponFields(weaponFullDef);
|
||||
CalculateAttachmentFields(weaponFullDef);
|
||||
|
||||
manager->AddAsset(ASSET_TYPE_WEAPON, assetName, &weaponFullDef->weapVariantDef, converter.GetDependencies(), converter.GetUsedScriptStrings());
|
||||
manager->AddAsset(ASSET_TYPE_WEAPON,
|
||||
assetName,
|
||||
&weaponFullDef->weapVariantDef,
|
||||
converter.GetDependencies(),
|
||||
converter.GetUsedScriptStrings(),
|
||||
converter.GetIndirectAssetReferences());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -41,7 +41,7 @@ bool InfoStringToStructConverterBase::ParseAsArray(const std::string& value, std
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InfoStringToStructConverterBase::ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray) const
|
||||
bool InfoStringToStructConverterBase::ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray)
|
||||
{
|
||||
std::string key;
|
||||
auto isKey = true;
|
||||
@ -227,6 +227,7 @@ bool InfoStringToStructConverterBase::ConvertEnumInt(const std::string& value, c
|
||||
std::vector<scr_string_t> InfoStringToStructConverterBase::GetUsedScriptStrings() const
|
||||
{
|
||||
std::vector<scr_string_t> scrStringList;
|
||||
scrStringList.reserve(m_used_script_string_list.size());
|
||||
for (auto scrStr : m_used_script_string_list)
|
||||
{
|
||||
scrStringList.push_back(scrStr);
|
||||
@ -238,6 +239,7 @@ std::vector<scr_string_t> InfoStringToStructConverterBase::GetUsedScriptStrings(
|
||||
std::vector<XAssetInfoGeneric*> InfoStringToStructConverterBase::GetDependencies() const
|
||||
{
|
||||
std::vector<XAssetInfoGeneric*> dependencyList;
|
||||
dependencyList.reserve(m_dependencies.size());
|
||||
for (auto* dependency : m_dependencies)
|
||||
{
|
||||
dependencyList.push_back(dependency);
|
||||
@ -245,3 +247,15 @@ std::vector<XAssetInfoGeneric*> InfoStringToStructConverterBase::GetDependencies
|
||||
|
||||
return dependencyList;
|
||||
}
|
||||
|
||||
std::vector<IndirectAssetReference> InfoStringToStructConverterBase::GetIndirectAssetReferences() const
|
||||
{
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences;
|
||||
indirectAssetReferences.reserve(m_indirect_asset_references.size());
|
||||
for (auto& assetReference : m_indirect_asset_references)
|
||||
{
|
||||
indirectAssetReferences.emplace_back(assetReference);
|
||||
}
|
||||
|
||||
return indirectAssetReferences;
|
||||
}
|
||||
|
@ -17,11 +17,12 @@ protected:
|
||||
ZoneScriptStrings& m_zone_script_strings;
|
||||
std::unordered_set<scr_string_t> m_used_script_string_list;
|
||||
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
|
||||
std::unordered_set<IndirectAssetReference> m_indirect_asset_references;
|
||||
MemoryManager* m_memory;
|
||||
void* m_structure;
|
||||
|
||||
static bool ParseAsArray(const std::string& value, std::vector<std::string>& valueArray);
|
||||
bool ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray) const;
|
||||
static bool ParseAsPairs(const std::string& value, std::vector<std::pair<std::string, std::string>>& valueArray);
|
||||
|
||||
bool ConvertString(const std::string& value, size_t offset);
|
||||
bool ConvertStringBuffer(const std::string& value, size_t offset, size_t bufferSize);
|
||||
@ -45,4 +46,5 @@ public:
|
||||
virtual bool Convert() = 0;
|
||||
_NODISCARD std::vector<scr_string_t> GetUsedScriptStrings() const;
|
||||
_NODISCARD std::vector<XAssetInfoGeneric*> GetDependencies() const;
|
||||
_NODISCARD std::vector<IndirectAssetReference> GetIndirectAssetReferences() const;
|
||||
};
|
||||
|
Reference in New Issue
Block a user