feat: T4 and T5 physconstraints dumping (#879)

* feat: T4 and T5 physconstraints dumping

* chore: small style adjustments

---------

Co-authored-by: Jan Laupetin <[email protected]>
This commit is contained in:
Ash
2026-07-12 14:17:11 +02:00
committed by GitHub
co-authored by Jan Laupetin
parent 28e27409f5
commit e45272137f
15 changed files with 417 additions and 5 deletions
+2 -1
View File
@@ -9,6 +9,7 @@
#include "LightDef/LightDefDumperT5.h"
#include "Localize/LocalizeDumperT5.h"
#include "Maps/MapEntsDumperT5.h"
#include "PhysConstraints/PhysConstraintsInfoStringDumperT5.h"
#include "PhysPreset/PhysPresetInfoStringDumperT5.h"
#include "RawFile/RawFileDumperT5.h"
#include "StringTable/StringTableDumperT5.h"
@@ -19,7 +20,7 @@ using namespace T5;
void ObjWriter::RegisterAssetDumpers(AssetDumpingContext& context)
{
RegisterAssetDumper(std::make_unique<phys_preset::InfoStringDumperT5>());
// REGISTER_DUMPER(AssetDumperPhysConstraints, m_phys_constraints)
RegisterAssetDumper(std::make_unique<phys_constraints::InfoStringDumperT5>());
// REGISTER_DUMPER(AssetDumperDestructibleDef, m_destructible_def)
RegisterAssetDumper(std::make_unique<xanim::DumperT5>());
RegisterAssetDumper(std::make_unique<xmodel::DumperT5>());
@@ -0,0 +1,87 @@
#include "PhysConstraintsInfoStringDumperT5.h"
#include "Game/T5/InfoString/InfoStringFromStructConverter.h"
#include "Game/T5/ObjConstantsT5.h"
#include "Game/T5/PhysConstraints/PhysConstraintsFields.h"
#include "PhysConstraints/PhysConstraintsCommon.h"
#include <cassert>
#include <type_traits>
using namespace T5;
namespace
{
class InfoStringFromPhysConstraintsConverter final : public InfoStringFromStructConverter
{
protected:
void FillFromExtensionField(const cspField_t& field) override
{
switch (static_cast<constraintsFieldType_t>(field.iFieldType))
{
case CFT_TYPE:
FillFromEnumInt(std::string(field.szName), field.iOffset, s_constraintTypeNames, std::extent_v<decltype(s_constraintTypeNames)>);
break;
default:
assert(false);
break;
}
}
public:
InfoStringFromPhysConstraintsConverter(const PhysConstraints* structure,
const cspField_t* fields,
const size_t fieldCount,
std::function<std::string(scr_string_t)> scriptStringValueCallback)
: InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback))
{
}
};
InfoString CreateInfoString(const XAssetInfo<PhysConstraints>& asset)
{
assert(asset.Asset()->count <= 4);
InfoStringFromPhysConstraintsConverter converter(asset.Asset(),
phys_constraints_fields,
std::extent_v<decltype(phys_constraints_fields)>,
[asset](const scr_string_t scrStr) -> std::string
{
assert(scrStr < asset.m_zone->m_script_strings.Count());
if (scrStr >= asset.m_zone->m_script_strings.Count())
return "";
return asset.m_zone->m_script_strings[scrStr];
});
return converter.Convert();
}
} // namespace
namespace phys_constraints
{
void InfoStringDumperT5::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetPhysConstraints::Type>& asset)
{
// Only dump raw when no gdt available
if (context.m_gdt)
{
const auto infoString = CreateInfoString(asset);
GdtEntry gdtEntry(asset.m_name, GDF_FILENAME_PHYS_CONSTRAINTS);
infoString.ToGdtProperties(INFO_STRING_PREFIX_PHYS_CONSTRAINTS, gdtEntry);
context.m_gdt->WriteEntry(gdtEntry);
}
else
{
const auto assetFile = context.OpenAssetFile(GetFileNameForAssetName(asset.m_name));
if (!assetFile)
return;
auto& stream = *assetFile;
const auto infoString = CreateInfoString(asset);
const auto stringValue = infoString.ToString(INFO_STRING_PREFIX_PHYS_CONSTRAINTS);
stream.write(stringValue.c_str(), stringValue.size());
}
}
} // namespace phys_constraints
@@ -0,0 +1,13 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T5/T5.h"
namespace phys_constraints
{
class InfoStringDumperT5 final : public AbstractAssetDumper<T5::AssetPhysConstraints>
{
protected:
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<T5::AssetPhysConstraints::Type>& asset) override;
};
} // namespace phys_constraints