2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-06 00:37:26 +00:00

refactor: streamline weapon dumping

This commit is contained in:
Jan Laupetin
2025-08-03 13:12:50 +02:00
parent 58de885ebe
commit 0546572ecf
68 changed files with 1380 additions and 1349 deletions

View File

@@ -32,13 +32,13 @@
#include "Tracer/RawLoaderTracerT6.h"
#include "Vehicle/GdtLoaderVehicleT6.h"
#include "Vehicle/RawLoaderVehicleT6.h"
#include "Weapon/GdtLoaderAttachmentT6.h"
#include "Weapon/GdtLoaderAttachmentUniqueT6.h"
#include "Weapon/GdtLoaderWeaponT6.h"
#include "Weapon/LoaderWeaponCamoT6.h"
#include "Weapon/RawLoaderAttachmentT6.h"
#include "Weapon/RawLoaderAttachmentUniqueT6.h"
#include "Weapon/RawLoaderWeaponT6.h"
#include "Weapon/AttachmentGdtLoaderT6.h"
#include "Weapon/AttachmentRawLoaderT6.h"
#include "Weapon/AttachmentUniqueGdtLoaderT6.h"
#include "Weapon/AttachmentUniqueRawLoaderT6.h"
#include "Weapon/CamoJsonLoaderT6.h"
#include "Weapon/WeaponGdtLoaderT6.h"
#include "Weapon/WeaponRawLoaderT6.h"
#include "ZBarrier/GdtLoaderZBarrierT6.h"
#include "ZBarrier/RawLoaderZBarrierT6.h"
@@ -418,13 +418,13 @@ namespace T6
// collection.AddAssetCreator(std::make_unique<AssetLoaderMenuList>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderMenu>(memory));
collection.AddAssetCreator(CreateLocalizeLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateRawWeaponLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateGdtWeaponLoader(memory, searchPath, gdt, zone));
collection.AddAssetCreator(CreateRawAttachmentLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateGdtAttachmentLoader(memory, searchPath, gdt, zone));
collection.AddAssetCreator(CreateRawAttachmentUniqueLoader(memory, searchPath, zone));
collection.AddAssetCreator(CreateGdtAttachmentUniqueLoader(memory, searchPath, gdt, zone));
collection.AddAssetCreator(CreateWeaponCamoLoader(memory, searchPath));
collection.AddAssetCreator(weapon::CreateRawLoader(memory, searchPath, zone));
collection.AddAssetCreator(weapon::CreateGdtLoader(memory, searchPath, gdt, zone));
collection.AddAssetCreator(attachment::CreateRawLoader(memory, searchPath, zone));
collection.AddAssetCreator(attachment::CreateGdtLoader(memory, searchPath, gdt, zone));
collection.AddAssetCreator(attachment_unique::CreateRawLoader(memory, searchPath, zone));
collection.AddAssetCreator(attachment_unique::CreateGdtLoader(memory, searchPath, gdt, zone));
collection.AddAssetCreator(camo::CreateJsonLoader(memory, searchPath));
// collection.AddAssetCreator(std::make_unique<AssetLoaderSoundDriverGlobals>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderFx>(memory));
// collection.AddAssetCreator(std::make_unique<AssetLoaderImpactFx>(memory));

View File

@@ -1,9 +1,9 @@
#include "GdtLoaderAttachmentT6.h"
#include "AttachmentGdtLoaderT6.h"
#include "AttachmentInfoStringLoaderT6.h"
#include "Game/T6/ObjConstantsT6.h"
#include "Game/T6/T6.h"
#include "InfoString/InfoString.h"
#include "InfoStringLoaderAttachmentT6.h"
#include <cstring>
#include <format>
@@ -40,14 +40,14 @@ namespace
private:
IGdtQueryable& m_gdt;
InfoStringLoaderAttachment m_info_string_loader;
T6::attachment::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::attachment
{
std::unique_ptr<AssetCreator<AssetAttachment>> CreateGdtAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
std::unique_ptr<AssetCreator<AssetAttachment>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
{
return std::make_unique<GdtLoaderAttachment>(memory, searchPath, gdt, zone);
}
} // namespace T6
} // namespace T6::attachment

View File

@@ -0,0 +1,14 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "Gdt/IGdtQueryable.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6::attachment
{
std::unique_ptr<AssetCreator<AssetAttachment>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6::attachment

View File

@@ -1,4 +1,4 @@
#include "InfoStringLoaderAttachmentT6.h"
#include "AttachmentInfoStringLoaderT6.h"
#include "Game/T6/InfoString/InfoStringToStructConverter.h"
#include "Game/T6/T6.h"
@@ -93,29 +93,32 @@ namespace
}
} // namespace
InfoStringLoaderAttachment::InfoStringLoaderAttachment(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
namespace T6::attachment
{
}
AssetCreationResult InfoStringLoaderAttachment::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* attachment = m_memory.Alloc<WeaponAttachment>();
attachment->szInternalName = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetAttachment> registration(assetName, attachment);
InfoStringToAttachmentConverter converter(
infoString, *attachment, m_zone.m_script_strings, m_memory, context, registration, attachment_fields, std::extent_v<decltype(attachment_fields)>);
if (!converter.Convert())
InfoStringLoader::InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
{
std::cerr << std::format("Failed to parse attachment: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculateAttachmentFields(*attachment);
AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* attachment = m_memory.Alloc<WeaponAttachment>();
attachment->szInternalName = m_memory.Dup(assetName.c_str());
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
AssetRegistration<AssetAttachment> registration(assetName, attachment);
InfoStringToAttachmentConverter converter(
infoString, *attachment, m_zone.m_script_strings, m_memory, context, registration, attachment_fields, std::extent_v<decltype(attachment_fields)>);
if (!converter.Convert())
{
std::cerr << std::format("Failed to parse attachment: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculateAttachmentFields(*attachment);
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
} // namespace T6::attachment

View File

@@ -4,12 +4,12 @@
#include "Asset/AssetCreationResult.h"
#include "InfoString/InfoString.h"
namespace T6
namespace T6::attachment
{
class InfoStringLoaderAttachment
class InfoStringLoader
{
public:
InfoStringLoaderAttachment(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
@@ -18,4 +18,4 @@ namespace T6
ISearchPath& m_search_path;
Zone& m_zone;
};
} // namespace T6
} // namespace T6::attachment

View File

@@ -1,15 +1,17 @@
#include "RawLoaderAttachmentT6.h"
#include "AttachmentRawLoaderT6.h"
#include "AttachmentInfoStringLoaderT6.h"
#include "Game/T6/ObjConstantsT6.h"
#include "Game/T6/T6.h"
#include "InfoString/InfoString.h"
#include "InfoStringLoaderAttachmentT6.h"
#include "Weapon/AttachmentCommon.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace T6;
using namespace ::attachment;
namespace
{
@@ -24,7 +26,7 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = std::format("attachment/{}", assetName);
const auto fileName = GetInfoStringFileNameForAssetName(assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
@@ -41,14 +43,14 @@ namespace
private:
ISearchPath& m_search_path;
InfoStringLoaderAttachment m_info_string_loader;
T6::attachment::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::attachment
{
std::unique_ptr<AssetCreator<AssetAttachment>> CreateRawAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
std::unique_ptr<AssetCreator<AssetAttachment>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<RawLoaderAttachment>(memory, searchPath, zone);
}
} // namespace T6
} // namespace T6::attachment

View File

@@ -0,0 +1,13 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6::attachment
{
std::unique_ptr<AssetCreator<AssetAttachment>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6::attachment

View File

@@ -1,9 +1,9 @@
#include "GdtLoaderAttachmentUniqueT6.h"
#include "AttachmentUniqueGdtLoaderT6.h"
#include "AttachmentUniqueInfoStringLoaderT6.h"
#include "Game/T6/ObjConstantsT6.h"
#include "Game/T6/T6.h"
#include "InfoString/InfoString.h"
#include "InfoStringLoaderAttachmentUniqueT6.h"
#include <cstring>
#include <format>
@@ -40,15 +40,14 @@ namespace
private:
IGdtQueryable& m_gdt;
InfoStringLoaderAttachmentUnique m_info_string_loader;
T6::attachment_unique::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::attachment_unique
{
std::unique_ptr<AssetCreator<AssetAttachmentUnique>>
CreateGdtAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
std::unique_ptr<AssetCreator<AssetAttachmentUnique>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
{
return std::make_unique<GdtLoaderAttachmentUnique>(memory, searchPath, gdt, zone);
}
} // namespace T6
} // namespace T6::attachment_unique

View File

@@ -0,0 +1,14 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "Gdt/IGdtQueryable.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6::attachment_unique
{
std::unique_ptr<AssetCreator<AssetAttachmentUnique>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6::attachment_unique

View File

@@ -1,4 +1,4 @@
#include "InfoStringLoaderAttachmentUniqueT6.h"
#include "AttachmentUniqueInfoStringLoaderT6.h"
#include "Game/T6/InfoString/InfoStringToStructConverter.h"
#include "Game/T6/T6.h"
@@ -141,7 +141,7 @@ namespace
{
// combinedAttachmentTypeMask
std::vector<eAttachment> attachmentsFromName;
if (!InfoStringLoaderAttachmentUnique::ExtractAttachmentsFromAssetName(assetName, attachmentsFromName))
if (!T6::attachment_unique::ExtractAttachmentsFromAssetName(assetName, attachmentsFromName))
{
std::cerr << std::format("Failed to determine attachments from attachment unique name \"{}\"\n", assetName);
return false;
@@ -159,86 +159,89 @@ namespace
}
} // namespace
bool InfoStringLoaderAttachmentUnique::ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector<eAttachment>& attachmentList)
namespace T6::attachment_unique
{
std::vector<std::string> parts;
auto attachCount = 1u;
auto partStart = 0u;
for (auto ci = 0u; ci < assetName.size(); ci++)
bool ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector<eAttachment>& attachmentList)
{
if (assetName[ci] == '_')
std::vector<std::string> parts;
auto attachCount = 1u;
auto partStart = 0u;
for (auto ci = 0u; ci < assetName.size(); ci++)
{
parts.emplace_back(assetName, partStart, ci - partStart);
partStart = ci + 1;
}
else if (assetName[ci] == '+')
{
attachCount++;
parts.emplace_back(assetName, partStart, ci - partStart);
partStart = ci + 1;
}
}
if (partStart < assetName.size())
parts.emplace_back(assetName, partStart, assetName.size() - partStart);
for (auto attachPartOffset = parts.size() - attachCount; attachPartOffset < parts.size(); attachPartOffset++)
{
auto& specifiedAttachName = parts[attachPartOffset];
for (auto& c : specifiedAttachName)
c = static_cast<char>(tolower(c));
auto foundAttachment = false;
for (auto attachIndex = 0u; attachIndex < std::extent_v<decltype(szAttachmentTypeNames)>; attachIndex++)
{
if (specifiedAttachName == szAttachmentTypeNames[attachIndex])
if (assetName[ci] == '_')
{
attachmentList.push_back(static_cast<eAttachment>(attachIndex));
foundAttachment = true;
break;
parts.emplace_back(assetName, partStart, ci - partStart);
partStart = ci + 1;
}
else if (assetName[ci] == '+')
{
attachCount++;
parts.emplace_back(assetName, partStart, ci - partStart);
partStart = ci + 1;
}
}
if (!foundAttachment)
return false;
if (partStart < assetName.size())
parts.emplace_back(assetName, partStart, assetName.size() - partStart);
for (auto attachPartOffset = parts.size() - attachCount; attachPartOffset < parts.size(); attachPartOffset++)
{
auto& specifiedAttachName = parts[attachPartOffset];
for (auto& c : specifiedAttachName)
c = static_cast<char>(tolower(c));
auto foundAttachment = false;
for (auto attachIndex = 0u; attachIndex < std::extent_v<decltype(szAttachmentTypeNames)>; attachIndex++)
{
if (specifiedAttachName == szAttachmentTypeNames[attachIndex])
{
attachmentList.push_back(static_cast<eAttachment>(attachIndex));
foundAttachment = true;
break;
}
}
if (!foundAttachment)
return false;
}
return true;
}
return true;
}
InfoStringLoaderAttachmentUnique::InfoStringLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
{
}
AssetCreationResult InfoStringLoaderAttachmentUnique::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* attachmentUniqueFull = m_memory.Alloc<WeaponAttachmentUniqueFull>();
attachmentUniqueFull->attachment.szInternalName = m_memory.Dup(assetName.c_str());
LinkAttachmentUniqueFullSubStructs(*attachmentUniqueFull);
AssetRegistration<AssetAttachmentUnique> registration(assetName, &attachmentUniqueFull->attachment);
InfoStringToAttachmentUniqueConverter converter(infoString,
*attachmentUniqueFull,
m_zone.m_script_strings,
m_memory,
context,
registration,
attachment_unique_fields,
std::extent_v<decltype(attachment_unique_fields)>);
if (!converter.Convert())
InfoStringLoader::InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
{
std::cerr << std::format("Failed to parse attachment unique: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculateAttachmentUniqueFields(assetName, *attachmentUniqueFull);
AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* attachmentUniqueFull = m_memory.Alloc<WeaponAttachmentUniqueFull>();
attachmentUniqueFull->attachment.szInternalName = m_memory.Dup(assetName.c_str());
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
LinkAttachmentUniqueFullSubStructs(*attachmentUniqueFull);
AssetRegistration<AssetAttachmentUnique> registration(assetName, &attachmentUniqueFull->attachment);
InfoStringToAttachmentUniqueConverter converter(infoString,
*attachmentUniqueFull,
m_zone.m_script_strings,
m_memory,
context,
registration,
attachment_unique_fields,
std::extent_v<decltype(attachment_unique_fields)>);
if (!converter.Convert())
{
std::cerr << std::format("Failed to parse attachment unique: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculateAttachmentUniqueFields(assetName, *attachmentUniqueFull);
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
} // namespace T6::attachment_unique

View File

@@ -7,20 +7,20 @@
#include <vector>
namespace T6
namespace T6::attachment_unique
{
class InfoStringLoaderAttachmentUnique
bool ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector<eAttachment>& attachmentList);
class InfoStringLoader
{
public:
InfoStringLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
static bool ExtractAttachmentsFromAssetName(const std::string& assetName, std::vector<eAttachment>& attachmentList);
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
Zone& m_zone;
};
} // namespace T6
} // namespace T6::attachment_unique

View File

@@ -1,22 +1,24 @@
#include "RawLoaderAttachmentUniqueT6.h"
#include "AttachmentUniqueRawLoaderT6.h"
#include "AttachmentUniqueInfoStringLoaderT6.h"
#include "Game/T6/ObjConstantsT6.h"
#include "Game/T6/T6.h"
#include "InfoString/InfoString.h"
#include "InfoStringLoaderAttachmentUniqueT6.h"
#include "Weapon/AttachmentUniqueCommon.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace T6;
using namespace ::attachment_unique;
namespace
{
class RawLoaderAttachmentUnique final : public AssetCreator<AssetAttachmentUnique>
class RawLoader final : public AssetCreator<AssetAttachmentUnique>
{
public:
RawLoaderAttachmentUnique(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
RawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_search_path(searchPath),
m_info_string_loader(memory, searchPath, zone)
{
@@ -24,7 +26,7 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = std::format("attachmentunique/{}", assetName);
const auto fileName = GetFileNameForAssetName(assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
@@ -41,14 +43,14 @@ namespace
private:
ISearchPath& m_search_path;
InfoStringLoaderAttachmentUnique m_info_string_loader;
T6::attachment_unique::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::attachment_unique
{
std::unique_ptr<AssetCreator<AssetAttachmentUnique>> CreateRawAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
std::unique_ptr<AssetCreator<AssetAttachmentUnique>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<RawLoaderAttachmentUnique>(memory, searchPath, zone);
return std::make_unique<RawLoader>(memory, searchPath, zone);
}
} // namespace T6
} // namespace T6::attachment_unique

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace T6
namespace T6::attachment_unique
{
std::unique_ptr<AssetCreator<AssetAttachmentUnique>> CreateRawAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6
std::unique_ptr<AssetCreator<AssetAttachmentUnique>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6::attachment_unique

View File

@@ -1,14 +1,18 @@
#include "JsonWeaponCamoLoaderT6.h"
#include "CamoJsonLoaderT6.h"
#include "Game/T6/CommonT6.h"
#include "Game/T6/Json/JsonWeaponCamo.h"
#include "Game/T6/T6.h"
#include "Pool/GlobalAssetPool.h"
#include "Weapon/CamoCommon.h"
#include <cstring>
#include <format>
#include <iostream>
#include <nlohmann/json.hpp>
using namespace nlohmann;
using namespace T6;
using namespace ::camo;
namespace
{
@@ -55,7 +59,7 @@ namespace
private:
static void PrintError(const WeaponCamo& weaponCamo, const std::string& message)
{
std::cerr << "Cannot load weapon camo \"" << weaponCamo.name << "\": " << message << "\n";
std::cerr << std::format("Cannot load weapon camo \"{}\": {}\n", weaponCamo.name, message);
}
bool CreateWeaponCamoSetFromJson(const JsonWeaponCamoSet& jWeaponCamoSet, WeaponCamoSet& weaponCamoSet, const WeaponCamo& weaponCamo) const
@@ -237,15 +241,46 @@ namespace
AssetCreationContext& m_context;
AssetRegistration<AssetWeaponCamo>& m_registration;
};
class WeaponCamoLoader final : public AssetCreator<AssetWeaponCamo>
{
public:
WeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(GetJsonFileNameForAssetName(assetName));
if (!file.IsOpen())
return AssetCreationResult::NoAction();
auto* weaponCamo = m_memory.Alloc<WeaponCamo>();
weaponCamo->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetWeaponCamo> registration(assetName, weaponCamo);
const JsonLoader loader(*file.m_stream, m_memory, context, registration);
if (!loader.Load(*weaponCamo))
{
std::cerr << std::format("Failed to load weapon camo \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace T6
namespace T6::camo
{
bool LoadWeaponCamoAsJson(
std::istream& stream, WeaponCamo& weaponCamo, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetWeaponCamo>& registration)
std::unique_ptr<AssetCreator<AssetWeaponCamo>> CreateJsonLoader(MemoryManager& memory, ISearchPath& searchPath)
{
const JsonLoader loader(stream, memory, context, registration);
return loader.Load(weaponCamo);
return std::make_unique<WeaponCamoLoader>(memory, searchPath);
}
} // namespace T6
} // namespace T6::camo

View File

@@ -7,7 +7,7 @@
#include <memory>
namespace T6
namespace T6::camo
{
std::unique_ptr<AssetCreator<AssetWeaponCamo>> CreateWeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace T6
std::unique_ptr<AssetCreator<AssetWeaponCamo>> CreateJsonLoader(MemoryManager& memory, ISearchPath& searchPath);
} // namespace T6::camo

View File

@@ -1,14 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "Gdt/IGdtQueryable.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6
{
std::unique_ptr<AssetCreator<AssetAttachment>> CreateGdtAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6

View File

@@ -1,15 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "Gdt/IGdtQueryable.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6
{
std::unique_ptr<AssetCreator<AssetAttachmentUnique>>
CreateGdtAttachmentUniqueLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6

View File

@@ -1,14 +0,0 @@
#pragma once
#include "Asset/AssetCreationContext.h"
#include "Asset/AssetRegistration.h"
#include "Game/T6/T6.h"
#include "Utils/MemoryManager.h"
#include <istream>
namespace T6
{
bool LoadWeaponCamoAsJson(
std::istream& stream, WeaponCamo& weaponCamo, MemoryManager& memory, AssetCreationContext& context, AssetRegistration<AssetWeaponCamo>& registration);
} // namespace T6

View File

@@ -1,55 +0,0 @@
#include "LoaderWeaponCamoT6.h"
#include "Game/T6/T6.h"
#include "JsonWeaponCamoLoaderT6.h"
#include "Pool/GlobalAssetPool.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace T6;
namespace
{
class WeaponCamoLoader final : public AssetCreator<AssetWeaponCamo>
{
public:
WeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(std::format("camo/{}.json", assetName));
if (!file.IsOpen())
return AssetCreationResult::NoAction();
auto* weaponCamo = m_memory.Alloc<WeaponCamo>();
weaponCamo->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetWeaponCamo> registration(assetName, weaponCamo);
if (!LoadWeaponCamoAsJson(*file.m_stream, *weaponCamo, m_memory, context, registration))
{
std::cerr << std::format("Failed to load weapon camo \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace T6
{
std::unique_ptr<AssetCreator<AssetWeaponCamo>> CreateWeaponCamoLoader(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<WeaponCamoLoader>(memory, searchPath);
}
} // namespace T6

View File

@@ -1,13 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6
{
std::unique_ptr<AssetCreator<AssetAttachment>> CreateRawAttachmentLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6

View File

@@ -1,13 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6
{
std::unique_ptr<AssetCreator<AssetWeapon>> CreateRawWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6

View File

@@ -1,9 +1,9 @@
#include "GdtLoaderWeaponT6.h"
#include "WeaponGdtLoaderT6.h"
#include "Game/T6/ObjConstantsT6.h"
#include "Game/T6/T6.h"
#include "InfoString/InfoString.h"
#include "InfoStringLoaderWeaponT6.h"
#include "WeaponInfoStringLoaderT6.h"
#include <cstring>
#include <format>
@@ -40,14 +40,14 @@ namespace
private:
IGdtQueryable& m_gdt;
InfoStringLoaderWeapon m_info_string_loader;
T6::weapon::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::weapon
{
std::unique_ptr<AssetCreator<AssetWeapon>> CreateGdtWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
std::unique_ptr<AssetCreator<AssetWeapon>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
{
return std::make_unique<GdtLoaderWeapon>(memory, searchPath, gdt, zone);
}
} // namespace T6
} // namespace T6::weapon

View File

@@ -8,7 +8,7 @@
#include <memory>
namespace T6
namespace T6::weapon
{
std::unique_ptr<AssetCreator<AssetWeapon>> CreateGdtWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6
std::unique_ptr<AssetCreator<AssetWeapon>> CreateGdtLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6::weapon

View File

@@ -1,10 +1,10 @@
#include "InfoStringLoaderWeaponT6.h"
#include "WeaponInfoStringLoaderT6.h"
#include "AttachmentUniqueInfoStringLoaderT6.h"
#include "Game/T6/InfoString/InfoStringToStructConverter.h"
#include "Game/T6/T6.h"
#include "Game/T6/Weapon/WeaponFields.h"
#include "Game/T6/Weapon/WeaponStrings.h"
#include "InfoStringLoaderAttachmentUniqueT6.h"
#include "Weapon/AccuracyGraphLoader.h"
#include <cassert>
@@ -568,8 +568,7 @@ namespace
&& weapon.attachmentUniques[attachmentUniqueIndex]->attachmentType != attachmentUnique.attachmentType)
{
std::vector<eAttachment> attachments;
if (InfoStringLoaderAttachmentUnique::ExtractAttachmentsFromAssetName(weapon.attachmentUniques[attachmentUniqueIndex]->szInternalName,
attachments)
if (T6::attachment_unique::ExtractAttachmentsFromAssetName(weapon.attachmentUniques[attachmentUniqueIndex]->szInternalName, attachments)
&& attachments.front() == attachmentUnique.attachmentType)
{
if (lastSibling == nullptr)
@@ -600,34 +599,37 @@ namespace
}
} // namespace
InfoStringLoaderWeapon::InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
namespace T6::weapon
{
}
AssetCreationResult InfoStringLoaderWeapon::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* weaponFullDef = m_memory.Alloc<WeaponFullDef>();
weaponFullDef->weapVariantDef.szInternalName = m_memory.Dup(assetName.c_str());
LinkWeaponFullDefSubStructs(*weaponFullDef);
AssetRegistration<AssetWeapon> registration(assetName, &weaponFullDef->weapVariantDef);
InfoStringToWeaponConverter converter(
infoString, *weaponFullDef, m_zone.m_script_strings, m_memory, context, registration, weapon_fields, std::extent_v<decltype(weapon_fields)>);
if (!converter.Convert())
InfoStringLoader::InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
{
std::cerr << std::format("Failed to parse weapon: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculateWeaponFields(*weaponFullDef);
CalculateAttachmentFields(*weaponFullDef);
AssetCreationResult InfoStringLoader::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* weaponFullDef = m_memory.Alloc<WeaponFullDef>();
weaponFullDef->weapVariantDef.szInternalName = m_memory.Dup(assetName.c_str());
LoadAccuracyGraphs(*weaponFullDef, m_memory, m_search_path, context);
LinkWeaponFullDefSubStructs(*weaponFullDef);
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
AssetRegistration<AssetWeapon> registration(assetName, &weaponFullDef->weapVariantDef);
InfoStringToWeaponConverter converter(
infoString, *weaponFullDef, m_zone.m_script_strings, m_memory, context, registration, weapon_fields, std::extent_v<decltype(weapon_fields)>);
if (!converter.Convert())
{
std::cerr << std::format("Failed to parse weapon: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculateWeaponFields(*weaponFullDef);
CalculateAttachmentFields(*weaponFullDef);
LoadAccuracyGraphs(*weaponFullDef, m_memory, m_search_path, context);
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}
} // namespace T6::weapon

View File

@@ -4,12 +4,12 @@
#include "Asset/AssetCreationResult.h"
#include "InfoString/InfoString.h"
namespace T6
namespace T6::weapon
{
class InfoStringLoaderWeapon
class InfoStringLoader
{
public:
InfoStringLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
InfoStringLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
@@ -18,4 +18,4 @@ namespace T6
ISearchPath& m_search_path;
Zone& m_zone;
};
} // namespace T6
} // namespace T6::weapon

View File

@@ -1,22 +1,24 @@
#include "RawLoaderWeaponT6.h"
#include "WeaponRawLoaderT6.h"
#include "Game/T6/ObjConstantsT6.h"
#include "Game/T6/T6.h"
#include "InfoString/InfoString.h"
#include "InfoStringLoaderWeaponT6.h"
#include "Weapon/WeaponCommon.h"
#include "WeaponInfoStringLoaderT6.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace T6;
using namespace ::weapon;
namespace
{
class RawLoaderWeapon final : public AssetCreator<AssetWeapon>
class RawLoader final : public AssetCreator<AssetWeapon>
{
public:
RawLoaderWeapon(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
RawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_search_path(searchPath),
m_info_string_loader(memory, searchPath, zone)
{
@@ -24,7 +26,7 @@ namespace
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = std::format("weapons/{}", assetName);
const auto fileName = GetFileNameForAssetName(assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
@@ -41,14 +43,14 @@ namespace
private:
ISearchPath& m_search_path;
InfoStringLoaderWeapon m_info_string_loader;
T6::weapon::InfoStringLoader m_info_string_loader;
};
} // namespace
namespace T6
namespace T6::weapon
{
std::unique_ptr<AssetCreator<AssetWeapon>> CreateRawWeaponLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
std::unique_ptr<AssetCreator<AssetWeapon>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<RawLoaderWeapon>(memory, searchPath, zone);
return std::make_unique<RawLoader>(memory, searchPath, zone);
}
} // namespace T6
} // namespace T6::weapon

View File

@@ -0,0 +1,13 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6::weapon
{
std::unique_ptr<AssetCreator<AssetWeapon>> CreateRawLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6::weapon