mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Add scriptstring value callback to weapon loading of t6
This commit is contained in:
parent
068add0eef
commit
6cca45fc26
@ -72,53 +72,56 @@ void InfoStringFromStructConverter::FillFromBaseField(const cspField_t& field)
|
||||
}
|
||||
|
||||
case CSPFT_XMODEL:
|
||||
{
|
||||
const auto* model = *reinterpret_cast<XModel**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
{
|
||||
const auto* model = *reinterpret_cast<XModel**>(reinterpret_cast<uintptr_t>(m_structure) + field.iOffset);
|
||||
|
||||
if (model)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(model->name));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
if (model)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(model->name));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_MATERIAL:
|
||||
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)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(material->info.name));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
if (material)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(material->info.name));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
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)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(physPreset->name));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
if (physPreset)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(physPreset->name));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_SCRIPT_STRING:
|
||||
FillFromScriptString(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
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)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(tracer->name));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
if (tracer)
|
||||
m_info_string.SetValueForKey(std::string(field.szName), std::string(tracer->name));
|
||||
else
|
||||
m_info_string.SetValueForKey(std::string(field.szName), "");
|
||||
break;
|
||||
}
|
||||
|
||||
case CSPFT_SOUND_ALIAS_ID:
|
||||
assert(false);
|
||||
@ -153,3 +156,11 @@ InfoStringFromStructConverter::InfoStringFromStructConverter(const void* structu
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
@ -28,5 +28,6 @@ namespace T6
|
||||
|
||||
public:
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
@ -117,9 +117,7 @@ InfoStringFromStructConverterBase::InfoStringFromStructConverterBase(const void*
|
||||
{
|
||||
}
|
||||
|
||||
InfoStringFromStructConverterBase::InfoStringFromStructConverterBase(const void* structure,
|
||||
std::function<std::string(scr_string_t)>
|
||||
scriptStringValueCallback)
|
||||
InfoStringFromStructConverterBase::InfoStringFromStructConverterBase(const void* structure, std::function<const std::string&(scr_string_t)> scriptStringValueCallback)
|
||||
: m_structure(structure),
|
||||
m_get_scr_string(std::move(scriptStringValueCallback))
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ class InfoStringFromStructConverterBase
|
||||
protected:
|
||||
InfoString m_info_string;
|
||||
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 FillFromStringBuffer(const std::string& key, size_t offset, size_t bufferSize);
|
||||
@ -67,7 +67,7 @@ protected:
|
||||
|
||||
public:
|
||||
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();
|
||||
InfoStringFromStructConverterBase(const InfoStringFromStructConverterBase& other) = delete;
|
||||
InfoStringFromStructConverterBase(InfoStringFromStructConverterBase&& other) noexcept = delete;
|
||||
|
@ -1,11 +1,14 @@
|
||||
#include "AssetDumperWeapon.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
|
||||
#include "Game/T6/InfoStringT6.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
const std::string AssetDumperWeapon::EMPTY_STRING;
|
||||
|
||||
cspField_t AssetDumperWeapon::weapon_fields[]
|
||||
{
|
||||
{"displayName", offsetof(WeaponFullDef, weapVariantDef.szDisplayName), CSPFT_STRING},
|
||||
@ -1445,8 +1448,8 @@ namespace T6
|
||||
}
|
||||
|
||||
public:
|
||||
InfoStringFromWeaponConverter(const WeaponFullDef* structure, const cspField_t* fields, const size_t fieldCount)
|
||||
: InfoStringFromStructConverter(structure, fields, 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, std::move(scriptStringValueCallback))
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -1585,7 +1588,14 @@ void AssetDumperWeapon::DumpAsset(Zone* zone, XAssetInfo<WeaponVariantDef>* asse
|
||||
memset(fullDef, 0, sizeof WeaponFullDef);
|
||||
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 stringValue = infoString.ToString("WEAPONFILE");
|
||||
out->Write(stringValue.c_str(), 1, stringValue.length());
|
||||
|
@ -7,6 +7,7 @@ namespace T6
|
||||
{
|
||||
class AssetDumperWeapon final : public AbstractAssetDumper<WeaponVariantDef>
|
||||
{
|
||||
static const std::string EMPTY_STRING;
|
||||
static cspField_t weapon_fields[];
|
||||
|
||||
void CopyToFullDef(const WeaponVariantDef* weapon, WeaponFullDef* fullDef) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user