Add scriptstring value callback to weapon loading of t6

This commit is contained in:
Jan 2020-10-23 12:52:44 +02:00
parent 068add0eef
commit 6cca45fc26
6 changed files with 61 additions and 40 deletions

View File

@ -85,7 +85,8 @@ void InfoStringFromStructConverter::FillFromBaseField(const cspField_t& field)
case CSPFT_MATERIAL: case CSPFT_MATERIAL:
case CSPFT_MATERIAL_STREAM: case CSPFT_MATERIAL_STREAM:
{ {
const auto* material = *reinterpret_cast<Material**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset); const auto* material = *reinterpret_cast<Material**>(reinterpret_cast<uintptr_t>(m_structure) + field.
iOffset);
if (material) if (material)
m_info_string.SetValueForKey(std::string(field.szName), std::string(material->info.name)); m_info_string.SetValueForKey(std::string(field.szName), std::string(material->info.name));
@ -96,7 +97,8 @@ void InfoStringFromStructConverter::FillFromBaseField(const cspField_t& field)
case CSPFT_PHYS_PRESET: case CSPFT_PHYS_PRESET:
{ {
const auto* physPreset = *reinterpret_cast<PhysPreset**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset); const auto* physPreset = *reinterpret_cast<PhysPreset**>(reinterpret_cast<uintptr_t>(m_structure) + field.
iOffset);
if (physPreset) if (physPreset)
m_info_string.SetValueForKey(std::string(field.szName), std::string(physPreset->name)); m_info_string.SetValueForKey(std::string(field.szName), std::string(physPreset->name));
@ -111,7 +113,8 @@ void InfoStringFromStructConverter::FillFromBaseField(const cspField_t& field)
case CSPFT_TRACER: case CSPFT_TRACER:
{ {
const auto* tracer = *reinterpret_cast<TracerDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset); const auto* tracer = *reinterpret_cast<TracerDef**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset
);
if (tracer) if (tracer)
m_info_string.SetValueForKey(std::string(field.szName), std::string(tracer->name)); m_info_string.SetValueForKey(std::string(field.szName), std::string(tracer->name));
@ -153,3 +156,11 @@ InfoStringFromStructConverter::InfoStringFromStructConverter(const void* structu
m_field_count(fieldCount) m_field_count(fieldCount)
{ {
} }
InfoStringFromStructConverter::InfoStringFromStructConverter(const void* structure, const cspField_t* fields, const size_t fieldCount,
std::function<const std::string&(scr_string_t)> scriptStringValueCallback)
: InfoStringFromStructConverterBase(structure, std::move(scriptStringValueCallback)),
m_fields(fields),
m_field_count(fieldCount)
{
}

View File

@ -28,5 +28,6 @@ namespace T6
public: public:
InfoStringFromStructConverter(const void* structure, const cspField_t* fields, size_t fieldCount); InfoStringFromStructConverter(const void* structure, const cspField_t* fields, size_t fieldCount);
InfoStringFromStructConverter(const void* structure, const cspField_t* fields, size_t fieldCount, std::function<const std::string&(scr_string_t)> scriptStringValueCallback);
}; };
} }

View File

@ -117,9 +117,7 @@ InfoStringFromStructConverterBase::InfoStringFromStructConverterBase(const void*
{ {
} }
InfoStringFromStructConverterBase::InfoStringFromStructConverterBase(const void* structure, InfoStringFromStructConverterBase::InfoStringFromStructConverterBase(const void* structure, std::function<const std::string&(scr_string_t)> scriptStringValueCallback)
std::function<std::string(scr_string_t)>
scriptStringValueCallback)
: m_structure(structure), : m_structure(structure),
m_get_scr_string(std::move(scriptStringValueCallback)) m_get_scr_string(std::move(scriptStringValueCallback))
{ {

View File

@ -50,7 +50,7 @@ class InfoStringFromStructConverterBase
protected: protected:
InfoString m_info_string; InfoString m_info_string;
const void* m_structure; const void* m_structure;
const std::function<std::string(scr_string_t)> m_get_scr_string; const std::function<const std::string&(scr_string_t)> m_get_scr_string;
void FillFromString(const std::string& key, size_t offset); void FillFromString(const std::string& key, size_t offset);
void FillFromStringBuffer(const std::string& key, size_t offset, size_t bufferSize); void FillFromStringBuffer(const std::string& key, size_t offset, size_t bufferSize);
@ -67,7 +67,7 @@ protected:
public: public:
explicit InfoStringFromStructConverterBase(const void* structure); explicit InfoStringFromStructConverterBase(const void* structure);
InfoStringFromStructConverterBase(const void* structure, std::function<std::string(scr_string_t)> scriptStringValueCallback); InfoStringFromStructConverterBase(const void* structure, std::function<const std::string&(scr_string_t)> scriptStringValueCallback);
virtual ~InfoStringFromStructConverterBase(); virtual ~InfoStringFromStructConverterBase();
InfoStringFromStructConverterBase(const InfoStringFromStructConverterBase& other) = delete; InfoStringFromStructConverterBase(const InfoStringFromStructConverterBase& other) = delete;
InfoStringFromStructConverterBase(InfoStringFromStructConverterBase&& other) noexcept = delete; InfoStringFromStructConverterBase(InfoStringFromStructConverterBase&& other) noexcept = delete;

View File

@ -1,11 +1,14 @@
#include "AssetDumperWeapon.h" #include "AssetDumperWeapon.h"
#include <cassert> #include <cassert>
#include <sstream>
#include "Game/T6/InfoStringT6.h" #include "Game/T6/InfoStringT6.h"
using namespace T6; using namespace T6;
const std::string AssetDumperWeapon::EMPTY_STRING;
cspField_t AssetDumperWeapon::weapon_fields[] cspField_t AssetDumperWeapon::weapon_fields[]
{ {
{"displayName", offsetof(WeaponFullDef, weapVariantDef.szDisplayName), CSPFT_STRING}, {"displayName", offsetof(WeaponFullDef, weapVariantDef.szDisplayName), CSPFT_STRING},
@ -1445,8 +1448,8 @@ namespace T6
} }
public: public:
InfoStringFromWeaponConverter(const WeaponFullDef* structure, const cspField_t* fields, const size_t fieldCount) InfoStringFromWeaponConverter(const WeaponFullDef* structure, const cspField_t* fields, const size_t fieldCount, std::function<const std::string&(scr_string_t)> scriptStringValueCallback)
: InfoStringFromStructConverter(structure, fields, fieldCount) : InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback))
{ {
} }
}; };
@ -1585,7 +1588,14 @@ void AssetDumperWeapon::DumpAsset(Zone* zone, XAssetInfo<WeaponVariantDef>* asse
memset(fullDef, 0, sizeof WeaponFullDef); memset(fullDef, 0, sizeof WeaponFullDef);
CopyToFullDef(asset->Asset(), fullDef); CopyToFullDef(asset->Asset(), fullDef);
InfoStringFromWeaponConverter converter(fullDef, weapon_fields, _countof(weapon_fields)); InfoStringFromWeaponConverter converter(fullDef, weapon_fields, _countof(weapon_fields), [asset](const scr_string_t scrStr) -> const std::string&
{
if (scrStr >= asset->m_script_strings.size())
return EMPTY_STRING;
return asset->m_script_strings[scrStr];
});
const auto infoString = converter.Convert(); const auto infoString = converter.Convert();
const auto stringValue = infoString.ToString("WEAPONFILE"); const auto stringValue = infoString.ToString("WEAPONFILE");
out->Write(stringValue.c_str(), 1, stringValue.length()); out->Write(stringValue.c_str(), 1, stringValue.length());

View File

@ -7,6 +7,7 @@ namespace T6
{ {
class AssetDumperWeapon final : public AbstractAssetDumper<WeaponVariantDef> class AssetDumperWeapon final : public AbstractAssetDumper<WeaponVariantDef>
{ {
static const std::string EMPTY_STRING;
static cspField_t weapon_fields[]; static cspField_t weapon_fields[];
void CopyToFullDef(const WeaponVariantDef* weapon, WeaponFullDef* fullDef) const; void CopyToFullDef(const WeaponVariantDef* weapon, WeaponFullDef* fullDef) const;