mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-08-30 21:53:15 +00:00
refactor: streamline vehicle dumping
This commit is contained in:
11
src/ObjCommon/Vehicle/VehicleCommon.cpp
Normal file
11
src/ObjCommon/Vehicle/VehicleCommon.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "VehicleCommon.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace vehicle
|
||||
{
|
||||
std::string GetFileNameForAssetName(const std::string& assetName)
|
||||
{
|
||||
return std::format("vehicles/{}", assetName);
|
||||
}
|
||||
} // namespace vehicle
|
8
src/ObjCommon/Vehicle/VehicleCommon.h
Normal file
8
src/ObjCommon/Vehicle/VehicleCommon.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace vehicle
|
||||
{
|
||||
std::string GetFileNameForAssetName(const std::string& assetName);
|
||||
}
|
@@ -4,12 +4,14 @@
|
||||
#include "Game/T6/T6.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "InfoStringLoaderVehicleT6.h"
|
||||
#include "Vehicle/VehicleCommon.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace T6;
|
||||
using namespace ::vehicle;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -24,7 +26,7 @@ namespace
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto fileName = std::format("vehicles/{}", assetName);
|
||||
const auto fileName = GetFileNameForAssetName(assetName);
|
||||
const auto file = m_search_path.Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#include "StructuredDataDef/AssetDumperStructuredDataDefSet.h"
|
||||
#include "Techset/TechsetDumperIW4.h"
|
||||
#include "Tracer/TracerDumperIW4.h"
|
||||
#include "Vehicle/AssetDumperVehicle.h"
|
||||
#include "Vehicle/VehicleDumperIW4.h"
|
||||
#include "Weapon/AssetDumperWeapon.h"
|
||||
|
||||
using namespace IW4;
|
||||
@@ -75,7 +75,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
DUMP_ASSET_POOL(leaderboard::JsonDumper, m_leaderboard, ASSET_TYPE_LEADERBOARD)
|
||||
DUMP_ASSET_POOL(AssetDumperStructuredDataDefSet, m_structed_data_def_set, ASSET_TYPE_STRUCTURED_DATA_DEF)
|
||||
DUMP_ASSET_POOL(tracer::Dumper, m_tracer, ASSET_TYPE_TRACER)
|
||||
DUMP_ASSET_POOL(AssetDumperVehicle, m_vehicle, ASSET_TYPE_VEHICLE)
|
||||
DUMP_ASSET_POOL(vehicle::Dumper, m_vehicle, ASSET_TYPE_VEHICLE)
|
||||
DUMP_ASSET_POOL(addon_map_ents::Dumper, m_addon_map_ents, ASSET_TYPE_ADDON_MAP_ENTS)
|
||||
|
||||
return true;
|
||||
|
@@ -1,18 +1,20 @@
|
||||
#include "AssetDumperVehicle.h"
|
||||
#include "VehicleDumperIW4.h"
|
||||
|
||||
#include "Game/IW4/CommonIW4.h"
|
||||
#include "Game/IW4/InfoString/EnumStrings.h"
|
||||
#include "Game/IW4/InfoString/InfoStringFromStructConverter.h"
|
||||
#include "Game/IW4/ObjConstantsIW4.h"
|
||||
#include "Game/IW4/Vehicle/VehicleFields.h"
|
||||
#include "Vehicle/VehicleCommon.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace IW4;
|
||||
using namespace ::vehicle;
|
||||
|
||||
namespace IW4
|
||||
namespace
|
||||
{
|
||||
class InfoStringFromVehicleConverter final : public InfoStringFromStructConverter
|
||||
{
|
||||
@@ -71,50 +73,53 @@ namespace IW4
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace IW4
|
||||
|
||||
InfoString AssetDumperVehicle::CreateInfoString(XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
InfoStringFromVehicleConverter converter(asset->Asset(),
|
||||
vehicle_fields,
|
||||
std::extent_v<decltype(vehicle_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();
|
||||
}
|
||||
|
||||
bool AssetDumperVehicle::ShouldDump(XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperVehicle::DumpAsset(AssetDumpingContext& context, XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
// Only dump raw when no gdt available
|
||||
if (context.m_gdt)
|
||||
InfoString CreateInfoString(XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_VEHICLE);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_VEHICLE, gdtEntry);
|
||||
context.m_gdt->WriteEntry(gdtEntry);
|
||||
InfoStringFromVehicleConverter converter(asset->Asset(),
|
||||
vehicle_fields,
|
||||
std::extent_v<decltype(vehicle_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();
|
||||
}
|
||||
else
|
||||
} // namespace
|
||||
|
||||
namespace IW4::vehicle
|
||||
{
|
||||
bool Dumper::ShouldDump(XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
const auto assetFile = context.OpenAssetFile("vehicles/" + asset->m_name);
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_VEHICLE);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
// Only dump raw when no gdt available
|
||||
if (context.m_gdt)
|
||||
{
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_VEHICLE);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_VEHICLE, 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(ObjConstants::INFO_STRING_PREFIX_VEHICLE);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
}
|
||||
}
|
||||
} // namespace IW4::vehicle
|
@@ -4,14 +4,12 @@
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace IW4
|
||||
namespace IW4::vehicle
|
||||
{
|
||||
class AssetDumperVehicle final : public AbstractAssetDumper<VehicleDef>
|
||||
class Dumper final : public AbstractAssetDumper<VehicleDef>
|
||||
{
|
||||
static InfoString CreateInfoString(XAssetInfo<VehicleDef>* asset);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<VehicleDef>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<VehicleDef>* asset) override;
|
||||
};
|
||||
} // namespace IW4
|
||||
} // namespace IW4::vehicle
|
@@ -20,7 +20,7 @@
|
||||
#include "StringTable/StringTableDumperT6.h"
|
||||
#include "Techset/TechsetDumperT6.h"
|
||||
#include "Tracer/TracerDumperT6.h"
|
||||
#include "Vehicle/AssetDumperVehicle.h"
|
||||
#include "Vehicle/VehicleDumperT6.h"
|
||||
#include "Weapon/AssetDumperWeapon.h"
|
||||
#include "Weapon/AssetDumperWeaponAttachment.h"
|
||||
#include "Weapon/AssetDumperWeaponAttachmentUnique.h"
|
||||
@@ -84,7 +84,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
// DUMP_ASSET_POOL(AssetDumperEmblemSet, m_emblem_set, ASSET_TYPE_EMBLEMSET)
|
||||
DUMP_ASSET_POOL(script::Dumper, m_script, ASSET_TYPE_SCRIPTPARSETREE)
|
||||
// DUMP_ASSET_POOL(AssetDumperKeyValuePairs, m_key_value_pairs, ASSET_TYPE_KEYVALUEPAIRS)
|
||||
DUMP_ASSET_POOL(AssetDumperVehicle, m_vehicle, ASSET_TYPE_VEHICLEDEF)
|
||||
DUMP_ASSET_POOL(vehicle::Dumper, m_vehicle, ASSET_TYPE_VEHICLEDEF)
|
||||
// DUMP_ASSET_POOL(AssetDumperMemoryBlock, m_memory_block, ASSET_TYPE_MEMORYBLOCK)
|
||||
// DUMP_ASSET_POOL(AssetDumperAddonMapEnts, m_addon_map_ents, ASSET_TYPE_ADDON_MAP_ENTS)
|
||||
DUMP_ASSET_POOL(tracer::Dumper, m_tracer, ASSET_TYPE_TRACER)
|
||||
|
@@ -1,15 +1,17 @@
|
||||
#include "AssetDumperVehicle.h"
|
||||
#include "VehicleDumperT6.h"
|
||||
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
#include "Game/T6/ObjConstantsT6.h"
|
||||
#include "Game/T6/Vehicle/VehicleFields.h"
|
||||
#include "Vehicle/VehicleCommon.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace T6;
|
||||
using namespace ::vehicle;
|
||||
|
||||
namespace T6
|
||||
namespace
|
||||
{
|
||||
class InfoStringFromVehicleConverter final : public InfoStringFromStructConverter
|
||||
{
|
||||
@@ -88,50 +90,53 @@ namespace T6
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace T6
|
||||
|
||||
InfoString AssetDumperVehicle::CreateInfoString(XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
InfoStringFromVehicleConverter converter(asset->Asset(),
|
||||
vehicle_fields,
|
||||
std::extent_v<decltype(vehicle_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();
|
||||
}
|
||||
|
||||
bool AssetDumperVehicle::ShouldDump(XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperVehicle::DumpAsset(AssetDumpingContext& context, XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
// Only dump raw when no gdt available
|
||||
if (context.m_gdt)
|
||||
InfoString CreateInfoString(XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_VEHICLE);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_VEHICLE, gdtEntry);
|
||||
context.m_gdt->WriteEntry(gdtEntry);
|
||||
InfoStringFromVehicleConverter converter(asset->Asset(),
|
||||
vehicle_fields,
|
||||
std::extent_v<decltype(vehicle_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();
|
||||
}
|
||||
else
|
||||
} // namespace
|
||||
|
||||
namespace T6::vehicle
|
||||
{
|
||||
bool Dumper::ShouldDump(XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
const auto assetFile = context.OpenAssetFile("vehicles/" + asset->m_name);
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_VEHICLE);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<VehicleDef>* asset)
|
||||
{
|
||||
// Only dump raw when no gdt available
|
||||
if (context.m_gdt)
|
||||
{
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_VEHICLE);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_VEHICLE, 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(ObjConstants::INFO_STRING_PREFIX_VEHICLE);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
}
|
||||
}
|
||||
} // namespace T6::vehicle
|
@@ -4,14 +4,12 @@
|
||||
#include "Game/T6/T6.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
namespace T6::vehicle
|
||||
{
|
||||
class AssetDumperVehicle final : public AbstractAssetDumper<VehicleDef>
|
||||
class Dumper final : public AbstractAssetDumper<VehicleDef>
|
||||
{
|
||||
static InfoString CreateInfoString(XAssetInfo<VehicleDef>* asset);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<VehicleDef>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<VehicleDef>* asset) override;
|
||||
};
|
||||
} // namespace T6
|
||||
} // namespace T6::vehicle
|
Reference in New Issue
Block a user