mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
Remove outdated StructuredDataDef Dumper
This commit is contained in:
@ -4,346 +4,11 @@
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Dumping/StructuredDataDef/StructuredDataDefDumper.h"
|
||||
#include "StructuredDataDef/StructuredDataDefDumper.h"
|
||||
|
||||
using namespace IW4;
|
||||
using namespace std::string_literals;
|
||||
|
||||
bool AssetDumperStructuredDataDefSet::GetNextHeadValue(const StructuredDataDef* def, const bool isFirstStruct, const std::vector<bool>& structsIncludedInOrder, size_t& nextHeadValue)
|
||||
{
|
||||
if (isFirstStruct
|
||||
&& def->rootType.type == DATA_STRUCT
|
||||
&& def->rootType.u.structIndex >= 0
|
||||
&& def->rootType.u.structIndex < def->structCount)
|
||||
{
|
||||
nextHeadValue = def->rootType.u.structIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto firstNotIncludedStruct = std::find(structsIncludedInOrder.begin(), structsIncludedInOrder.end(), false);
|
||||
assert(firstNotIncludedStruct != structsIncludedInOrder.end());
|
||||
|
||||
if (firstNotIncludedStruct == structsIncludedInOrder.end())
|
||||
return false;
|
||||
|
||||
nextHeadValue = static_cast<size_t>(firstNotIncludedStruct - structsIncludedInOrder.begin());
|
||||
return false;
|
||||
}
|
||||
|
||||
StructuredDataType AssetDumperStructuredDataDefSet::GetBaseType(const StructuredDataDef* def, StructuredDataType type)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (type.type == DATA_INDEXED_ARRAY)
|
||||
{
|
||||
if (def->indexedArrays != nullptr && type.u.indexedArrayIndex >= 0 && type.u.indexedArrayIndex < def->indexedArrayCount)
|
||||
type = def->indexedArrays[type.u.indexedArrayIndex].elementType;
|
||||
else
|
||||
break;
|
||||
}
|
||||
else if (type.type == DATA_ENUM_ARRAY)
|
||||
{
|
||||
if (def->enumedArrays != nullptr && type.u.enumedArrayIndex >= 0 && type.u.enumedArrayIndex < def->enumedArrayCount)
|
||||
type = def->enumedArrays[type.u.enumedArrayIndex].elementType;
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
std::vector<size_t> AssetDumperStructuredDataDefSet::CalculateStructDumpingOrder(const StructuredDataDef* def)
|
||||
{
|
||||
if (def->structCount <= 0 || def->structs == nullptr)
|
||||
return {};
|
||||
|
||||
const auto structCount = static_cast<size_t>(def->structCount);
|
||||
|
||||
std::vector<size_t> result;
|
||||
auto resultStructHead = 0u;
|
||||
auto resultStructTail = 0u;
|
||||
|
||||
result.reserve(def->structCount);
|
||||
std::vector<bool> structIncludedInOrder(def->structCount);
|
||||
|
||||
while (resultStructTail < structCount)
|
||||
{
|
||||
size_t nextHeadValue;
|
||||
if (!GetNextHeadValue(def, resultStructHead == 0, structIncludedInOrder, nextHeadValue))
|
||||
return result;
|
||||
result.push_back(nextHeadValue);
|
||||
structIncludedInOrder[nextHeadValue] = true;
|
||||
++resultStructHead;
|
||||
|
||||
while (resultStructHead > resultStructTail)
|
||||
{
|
||||
const auto& currentStruct = def->structs[result[resultStructTail++]];
|
||||
|
||||
if (currentStruct.properties == nullptr)
|
||||
continue;
|
||||
|
||||
for (auto i = 0; i < currentStruct.propertyCount; i++)
|
||||
{
|
||||
const auto baseType = GetBaseType(def, currentStruct.properties[i].type);
|
||||
if (baseType.type == DATA_STRUCT
|
||||
&& baseType.u.structIndex >= 0
|
||||
&& static_cast<size_t>(baseType.u.structIndex) < structCount
|
||||
&& structIncludedInOrder[static_cast<size_t>(baseType.u.structIndex)] == false)
|
||||
{
|
||||
result.push_back(static_cast<size_t>(baseType.u.structIndex));
|
||||
structIncludedInOrder[static_cast<size_t>(baseType.u.structIndex)] = true;
|
||||
++resultStructHead;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AssetDumperStructuredDataDefSet::ShouldDump(XAssetInfo<StructuredDataDefSet>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperStructuredDataDefSet::DumpEnum(StructuredDataDefDumper& dumper, const int enumIndex, const StructuredDataEnum* _enum)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "ENUM_" << enumIndex;
|
||||
|
||||
dumper.BeginEnum(ss.str(), static_cast<size_t>(_enum->entryCount), static_cast<size_t>(_enum->reservedEntryCount));
|
||||
|
||||
if (_enum->entries && _enum->entryCount > 0)
|
||||
{
|
||||
for (auto i = 0; i < _enum->entryCount; i++)
|
||||
{
|
||||
const auto& entry = _enum->entries[i];
|
||||
|
||||
assert(entry.string);
|
||||
if (!entry.string)
|
||||
continue;
|
||||
|
||||
dumper.WriteEnumEntry(entry.string, entry.index);
|
||||
}
|
||||
}
|
||||
|
||||
dumper.EndEnum();
|
||||
}
|
||||
|
||||
size_t AssetDumperStructuredDataDefSet::GetPropertySizeInBits(const StructuredDataStructProperty& property, const StructuredDataDef* def)
|
||||
{
|
||||
switch (property.type.type)
|
||||
{
|
||||
case DATA_FLOAT:
|
||||
case DATA_INT:
|
||||
return 32;
|
||||
case DATA_BYTE:
|
||||
return 8;
|
||||
case DATA_BOOL:
|
||||
return 1;
|
||||
case DATA_SHORT:
|
||||
case DATA_ENUM:
|
||||
return 16;
|
||||
case DATA_STRING:
|
||||
return property.type.u.stringDataLength * 8;
|
||||
case DATA_STRUCT:
|
||||
if (property.type.u.structIndex < 0 || property.type.u.structIndex >= def->structCount || def->structs == nullptr)
|
||||
{
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
return static_cast<size_t>(def->structs[property.type.u.structIndex].size) * 8;
|
||||
case DATA_INDEXED_ARRAY:
|
||||
{
|
||||
if (property.type.u.indexedArrayIndex < 0 || property.type.u.indexedArrayIndex >= def->indexedArrayCount || def->indexedArrays == nullptr)
|
||||
{
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
const auto& indexedArray = def->indexedArrays[property.type.u.indexedArrayIndex];
|
||||
const auto elementSize = indexedArray.elementType.type == DATA_BOOL ? 1 : indexedArray.elementSize * 8;
|
||||
return elementSize * static_cast<size_t>(def->indexedArrays[property.type.u.indexedArrayIndex].arraySize);
|
||||
}
|
||||
case DATA_ENUM_ARRAY:
|
||||
{
|
||||
if (property.type.u.enumedArrayIndex < 0 || property.type.u.enumedArrayIndex >= def->enumedArrayCount || def->enumedArrays == nullptr)
|
||||
{
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto& enumedArray = def->enumedArrays[property.type.u.enumedArrayIndex];
|
||||
if (enumedArray.enumIndex < 0 || enumedArray.enumIndex >= def->enumCount || def->enums == nullptr)
|
||||
{
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const auto elementSize = enumedArray.elementType.type == DATA_BOOL ? 1 : enumedArray.elementSize * 8;
|
||||
return elementSize * static_cast<size_t>(def->enums[enumedArray.enumIndex].reservedEntryCount);
|
||||
}
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t AssetDumperStructuredDataDefSet::GetPropertyAlign(const StructuredDataStructProperty& property)
|
||||
{
|
||||
return property.type.type == DATA_BOOL ? 0 : 8;
|
||||
}
|
||||
|
||||
void AssetDumperStructuredDataDefSet::DumpProperty(StructuredDataDefDumper& dumper, const StructuredDataStructProperty& property, const StructuredDataDef* def, const int rootStructIndex)
|
||||
{
|
||||
dumper.BeginProperty(property.name, property.type.type == DATA_BOOL ? property.offset : property.offset * 8, GetPropertySizeInBits(property, def), GetPropertyAlign(property));
|
||||
|
||||
auto currentType = property.type;
|
||||
auto stopTypeIteration = false;
|
||||
do
|
||||
{
|
||||
switch (currentType.type)
|
||||
{
|
||||
case DATA_INT:
|
||||
dumper.SetPropertyTypeName("int");
|
||||
stopTypeIteration = true;
|
||||
break;
|
||||
case DATA_BYTE:
|
||||
dumper.SetPropertyTypeName("byte");
|
||||
stopTypeIteration = true;
|
||||
break;
|
||||
case DATA_BOOL:
|
||||
dumper.SetPropertyTypeName("bool");
|
||||
stopTypeIteration = true;
|
||||
break;
|
||||
case DATA_FLOAT:
|
||||
dumper.SetPropertyTypeName("float");
|
||||
stopTypeIteration = true;
|
||||
break;
|
||||
case DATA_SHORT:
|
||||
dumper.SetPropertyTypeName("short");
|
||||
stopTypeIteration = true;
|
||||
break;
|
||||
case DATA_STRING:
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "string(" << currentType.u.stringDataLength << ")";
|
||||
dumper.SetPropertyTypeName(ss.str());
|
||||
stopTypeIteration = true;
|
||||
break;
|
||||
}
|
||||
case DATA_ENUM:
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "ENUM_" << currentType.u.enumIndex;
|
||||
dumper.SetPropertyTypeName(ss.str());
|
||||
stopTypeIteration = true;
|
||||
break;
|
||||
}
|
||||
case DATA_STRUCT:
|
||||
{
|
||||
if (currentType.u.structIndex == rootStructIndex)
|
||||
{
|
||||
dumper.SetPropertyTypeName("root");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "STRUCT_" << currentType.u.enumIndex;
|
||||
dumper.SetPropertyTypeName(ss.str());
|
||||
}
|
||||
stopTypeIteration = true;
|
||||
break;
|
||||
}
|
||||
case DATA_INDEXED_ARRAY:
|
||||
{
|
||||
if (def->indexedArrays == nullptr
|
||||
|| currentType.u.indexedArrayIndex < 0
|
||||
|| currentType.u.indexedArrayIndex >= def->indexedArrayCount)
|
||||
{
|
||||
assert(false);
|
||||
dumper.SetPropertyTypeName("ERRORTYPE");
|
||||
stopTypeIteration = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto& indexedArray = def->indexedArrays[currentType.u.indexedArrayIndex];
|
||||
dumper.AddPropertyArraySpecifier(std::to_string(indexedArray.arraySize));
|
||||
currentType = indexedArray.elementType;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DATA_ENUM_ARRAY:
|
||||
{
|
||||
if (def->enumedArrays == nullptr
|
||||
|| currentType.u.enumedArrayIndex < 0
|
||||
|| currentType.u.enumedArrayIndex >= def->enumedArrayCount)
|
||||
{
|
||||
assert(false);
|
||||
dumper.SetPropertyTypeName("ERRORTYPE");
|
||||
stopTypeIteration = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto& enumedArray = def->enumedArrays[currentType.u.enumedArrayIndex];
|
||||
std::ostringstream ss;
|
||||
ss << "ENUM_" << enumedArray.enumIndex;
|
||||
dumper.AddPropertyArraySpecifier(ss.str());
|
||||
currentType = enumedArray.elementType;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (!stopTypeIteration);
|
||||
|
||||
dumper.EndProperty();
|
||||
}
|
||||
|
||||
void AssetDumperStructuredDataDefSet::DumpStruct(StructuredDataDefDumper& dumper, const size_t structIndex, const StructuredDataStruct* _struct, const StructuredDataDef* def,
|
||||
const int rootStructIndex)
|
||||
{
|
||||
std::string structName;
|
||||
size_t actualStructSize;
|
||||
size_t initialOffset;
|
||||
if (static_cast<int>(structIndex) == rootStructIndex)
|
||||
{
|
||||
structName = "root";
|
||||
actualStructSize = def->size;
|
||||
initialOffset = 64;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "STRUCT_" << structIndex;
|
||||
structName = ss.str();
|
||||
actualStructSize = static_cast<size_t>(_struct->size);
|
||||
initialOffset = 0;
|
||||
}
|
||||
|
||||
dumper.WriteLineComment("BitOffset: "s + std::to_string(_struct->bitOffset));
|
||||
dumper.WriteLineComment("Size: "s + std::to_string(_struct->size));
|
||||
dumper.BeginStruct(structName, static_cast<size_t>(_struct->propertyCount), actualStructSize * 8, initialOffset);
|
||||
|
||||
if (_struct->properties && _struct->propertyCount > 0)
|
||||
{
|
||||
for (auto i = 0; i < _struct->propertyCount; i++)
|
||||
{
|
||||
const auto& property = _struct->properties[i];
|
||||
|
||||
DumpProperty(dumper, property, def, rootStructIndex);
|
||||
}
|
||||
}
|
||||
|
||||
dumper.EndStruct();
|
||||
}
|
||||
|
||||
CommonStructuredDataType AssetDumperStructuredDataDefSet::ConvertType(const CommonStructuredDataDef* def, const StructuredDataType in)
|
||||
{
|
||||
CommonStructuredDataType out;
|
||||
@ -511,6 +176,11 @@ std::unique_ptr<CommonStructuredDataDef> AssetDumperStructuredDataDefSet::Conver
|
||||
return out;
|
||||
}
|
||||
|
||||
bool AssetDumperStructuredDataDefSet::ShouldDump(XAssetInfo<StructuredDataDefSet>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperStructuredDataDefSet::DumpAsset(AssetDumpingContext& context, XAssetInfo<StructuredDataDefSet>* asset)
|
||||
{
|
||||
const auto* set = asset->Asset();
|
||||
|
@ -1,10 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Dumping/StructuredDataDef/StructuredDataDefDumper.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "StructuredDataDef/CommonStructuredDataDef.h"
|
||||
|
||||
@ -12,21 +10,13 @@ namespace IW4
|
||||
{
|
||||
class AssetDumperStructuredDataDefSet final : public AbstractAssetDumper<StructuredDataDefSet>
|
||||
{
|
||||
static bool GetNextHeadValue(const StructuredDataDef* def, bool isFirstStruct, const std::vector<bool>& structsIncludedInOrder, size_t& nextHeadValue);
|
||||
static StructuredDataType GetBaseType(const StructuredDataDef* def, StructuredDataType type);
|
||||
static std::vector<size_t> CalculateStructDumpingOrder(const StructuredDataDef* def);
|
||||
static void DumpEnum(StructuredDataDefDumper& dumper, int enumIndex, const StructuredDataEnum* _enum);
|
||||
static size_t GetPropertySizeInBits(const StructuredDataStructProperty& property, const StructuredDataDef* def);
|
||||
static size_t GetPropertyAlign(const StructuredDataStructProperty& property);
|
||||
static void DumpProperty(StructuredDataDefDumper& dumper, const StructuredDataStructProperty& property, const StructuredDataDef* def, int rootStructIndex);
|
||||
static void DumpStruct(StructuredDataDefDumper& dumper, size_t structIndex, const StructuredDataStruct* _struct, const StructuredDataDef* def, int rootStructIndex);
|
||||
|
||||
static CommonStructuredDataType ConvertType(const CommonStructuredDataDef* def, const StructuredDataType in);
|
||||
static CommonStructuredDataType ConvertType(const CommonStructuredDataDef* def, StructuredDataType in);
|
||||
static void ConvertEnum(CommonStructuredDataEnum* out, const StructuredDataEnum* in, size_t enumIndex);
|
||||
static void ConvertStruct(const CommonStructuredDataDef* def, const StructuredDataDef* gameDef, CommonStructuredDataStruct* out, const StructuredDataStruct* in, const size_t structIndex);
|
||||
static void ConvertStruct(const CommonStructuredDataDef* def, const StructuredDataDef* gameDef, CommonStructuredDataStruct* out, const StructuredDataStruct* in, size_t structIndex);
|
||||
static void ConvertIndexedArray(const CommonStructuredDataDef* def, CommonStructuredDataIndexedArray* out, const StructuredDataIndexedArray* in);
|
||||
static void ConvertEnumedArray(const CommonStructuredDataDef* def, CommonStructuredDataEnumedArray* out, const StructuredDataEnumedArray* in);
|
||||
static std::unique_ptr<CommonStructuredDataDef> ConvertDef(const StructuredDataDef* in);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<StructuredDataDefSet>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<StructuredDataDefSet>* asset) override;
|
||||
|
Reference in New Issue
Block a user