2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-08-30 21:53:15 +00:00

refactor: streamline slug, qdb and script dumper

This commit is contained in:
Jan Laupetin
2025-07-30 21:41:39 +01:00
parent bcb52391dc
commit 0eb14890ab
14 changed files with 122 additions and 110 deletions

View File

@@ -11,7 +11,7 @@
#include "Menu/AssetDumperMenuList.h"
#include "ObjWriting.h"
#include "RawFile/RawFileDumperIW5.h"
#include "Script/AssetDumperScriptFile.h"
#include "Script/ScriptDumperIW5.h"
#include "Sound/AssetDumperLoadedSound.h"
#include "StringTable/AssetDumperStringTable.h"
#include "Weapon/AssetDumperWeapon.h"
@@ -62,7 +62,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
// DUMP_ASSET_POOL(AssetDumperFxImpactTable, m_fx_impact_table, ASSET_TYPE_IMPACT_FX)
// DUMP_ASSET_POOL(AssetDumperSurfaceFxTable, m_surface_fx_table, ASSET_TYPE_SURFACE_FX)
DUMP_ASSET_POOL(raw_file::Dumper, m_raw_file, ASSET_TYPE_RAWFILE)
DUMP_ASSET_POOL(AssetDumperScriptFile, m_script_file, ASSET_TYPE_SCRIPTFILE)
DUMP_ASSET_POOL(script::Dumper, m_script_file, ASSET_TYPE_SCRIPTFILE)
DUMP_ASSET_POOL(AssetDumperStringTable, m_string_table, ASSET_TYPE_STRINGTABLE)
DUMP_ASSET_POOL(leaderboard::JsonDumper, m_leaderboard, ASSET_TYPE_LEADERBOARD)
// DUMP_ASSET_POOL(AssetDumperStructuredDataDefSet, m_structed_data_def_set, ASSET_TYPE_STRUCTURED_DATA_DEF)

View File

@@ -1,30 +0,0 @@
#include "AssetDumperScriptFile.h"
using namespace IW5;
bool AssetDumperScriptFile::ShouldDump(XAssetInfo<ScriptFile>* asset)
{
return true;
}
// See https://github.com/xensik/gsc-tool#file-format for an in-depth explanation about the .gscbin format
void AssetDumperScriptFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<ScriptFile>* asset)
{
auto* scriptFile = asset->Asset();
const auto assetFile = context.OpenAssetFile(asset->m_name + ".gscbin");
if (!assetFile)
return;
auto& stream = *assetFile;
// Dump the name and the numeric fields
stream.write(asset->m_name.c_str(), asset->m_name.size() + 1);
stream.write(reinterpret_cast<char*>(&scriptFile->compressedLen), sizeof(scriptFile->compressedLen));
stream.write(reinterpret_cast<char*>(&scriptFile->len), sizeof(scriptFile->len));
stream.write(reinterpret_cast<char*>(&scriptFile->bytecodeLen), sizeof(scriptFile->bytecodeLen));
// Dump the buffers
stream.write(scriptFile->buffer, scriptFile->compressedLen);
stream.write(reinterpret_cast<char*>(scriptFile->bytecode), scriptFile->bytecodeLen);
}

View File

@@ -0,0 +1,33 @@
#include "ScriptDumperIW5.h"
using namespace IW5;
namespace IW5::script
{
bool Dumper::ShouldDump(XAssetInfo<ScriptFile>* asset)
{
return true;
}
// See https://github.com/xensik/gsc-tool#file-format for an in-depth explanation about the .gscbin format
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<ScriptFile>* asset)
{
auto* scriptFile = asset->Asset();
const auto assetFile = context.OpenAssetFile(asset->m_name + ".gscbin");
if (!assetFile)
return;
auto& stream = *assetFile;
// Dump the name and the numeric fields
stream.write(asset->m_name.c_str(), asset->m_name.size() + 1);
stream.write(reinterpret_cast<char*>(&scriptFile->compressedLen), sizeof(scriptFile->compressedLen));
stream.write(reinterpret_cast<char*>(&scriptFile->len), sizeof(scriptFile->len));
stream.write(reinterpret_cast<char*>(&scriptFile->bytecodeLen), sizeof(scriptFile->bytecodeLen));
// Dump the buffers
stream.write(scriptFile->buffer, scriptFile->compressedLen);
stream.write(reinterpret_cast<char*>(scriptFile->bytecode), scriptFile->bytecodeLen);
}
} // namespace IW5::script

View File

@@ -3,12 +3,12 @@
#include "Dumping/AbstractAssetDumper.h"
#include "Game/IW5/IW5.h"
namespace IW5
namespace IW5::script
{
class AssetDumperScriptFile final : public AbstractAssetDumper<ScriptFile>
class Dumper final : public AbstractAssetDumper<ScriptFile>
{
protected:
bool ShouldDump(XAssetInfo<ScriptFile>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<ScriptFile>* asset) override;
};
} // namespace IW5
} // namespace IW5::script

View File

@@ -11,10 +11,10 @@
#include "ObjWriting.h"
#include "PhysConstraints/PhysConstraintsInfoStringDumperT6.h"
#include "PhysPreset/PhysPresetInfoStringDumperT6.h"
#include "Qdb/AssetDumperQdb.h"
#include "Qdb/QdbDumperT6.h"
#include "RawFile/RawFileDumperT6.h"
#include "Script/AssetDumperScriptParseTree.h"
#include "Slug/AssetDumperSlug.h"
#include "Script/ScriptDumperT6.h"
#include "Slug/SlugDumperT6.h"
#include "Sound/AssetDumperSndBank.h"
#include "Sound/AssetDumperSndDriverGlobals.h"
#include "StringTable/AssetDumperStringTable.h"
@@ -82,15 +82,15 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
// DUMP_ASSET_POOL(AssetDumperDDLRoot, m_ddl, ASSET_TYPE_DDL)
// DUMP_ASSET_POOL(AssetDumperGlasses, m_glasses, ASSET_TYPE_GLASSES)
// DUMP_ASSET_POOL(AssetDumperEmblemSet, m_emblem_set, ASSET_TYPE_EMBLEMSET)
DUMP_ASSET_POOL(AssetDumperScriptParseTree, m_script, ASSET_TYPE_SCRIPTPARSETREE)
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(AssetDumperMemoryBlock, m_memory_block, ASSET_TYPE_MEMORYBLOCK)
// DUMP_ASSET_POOL(AssetDumperAddonMapEnts, m_addon_map_ents, ASSET_TYPE_ADDON_MAP_ENTS)
DUMP_ASSET_POOL(AssetDumperTracer, m_tracer, ASSET_TYPE_TRACER)
// DUMP_ASSET_POOL(AssetDumperSkinnedVertsDef, m_skinned_verts, ASSET_TYPE_SKINNEDVERTS)
DUMP_ASSET_POOL(AssetDumperQdb, m_qdb, ASSET_TYPE_QDB)
DUMP_ASSET_POOL(AssetDumperSlug, m_slug, ASSET_TYPE_SLUG)
DUMP_ASSET_POOL(qdb::Dumper, m_qdb, ASSET_TYPE_QDB)
DUMP_ASSET_POOL(slug::Dumper, m_slug, ASSET_TYPE_SLUG)
// DUMP_ASSET_POOL(AssetDumperFootstepTableDef, m_footstep_table, ASSET_TYPE_FOOTSTEP_TABLE)
// DUMP_ASSET_POOL(AssetDumperFootstepFXTableDef, m_footstep_fx_table, ASSET_TYPE_FOOTSTEPFX_TABLE)
DUMP_ASSET_POOL(AssetDumperZBarrier, m_zbarrier, ASSET_TYPE_ZBARRIER)

View File

@@ -1,20 +0,0 @@
#include "AssetDumperQdb.h"
using namespace T6;
bool AssetDumperQdb::ShouldDump(XAssetInfo<Qdb>* asset)
{
return true;
}
void AssetDumperQdb::DumpAsset(AssetDumpingContext& context, XAssetInfo<Qdb>* asset)
{
const auto* qdb = asset->Asset();
const auto assetFile = context.OpenAssetFile(asset->m_name);
if (!assetFile)
return;
auto& stream = *assetFile;
stream.write(qdb->buffer, qdb->len);
}

View File

@@ -0,0 +1,23 @@
#include "QdbDumperT6.h"
using namespace T6;
namespace T6::qdb
{
bool Dumper::ShouldDump(XAssetInfo<Qdb>* asset)
{
return true;
}
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<Qdb>* asset)
{
const auto* qdb = asset->Asset();
const auto assetFile = context.OpenAssetFile(asset->m_name);
if (!assetFile)
return;
auto& stream = *assetFile;
stream.write(qdb->buffer, qdb->len);
}
} // namespace T6::qdb

View File

@@ -3,12 +3,12 @@
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
namespace T6
namespace T6::qdb
{
class AssetDumperQdb final : public AbstractAssetDumper<Qdb>
class Dumper final : public AbstractAssetDumper<Qdb>
{
protected:
bool ShouldDump(XAssetInfo<Qdb>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<Qdb>* asset) override;
};
} // namespace T6
} // namespace T6::qdb

View File

@@ -1,20 +0,0 @@
#include "AssetDumperScriptParseTree.h"
using namespace T6;
bool AssetDumperScriptParseTree::ShouldDump(XAssetInfo<ScriptParseTree>* asset)
{
return true;
}
void AssetDumperScriptParseTree::DumpAsset(AssetDumpingContext& context, XAssetInfo<ScriptParseTree>* asset)
{
const auto* scriptParseTree = asset->Asset();
const auto assetFile = context.OpenAssetFile(asset->m_name);
if (!assetFile)
return;
auto& stream = *assetFile;
stream.write(scriptParseTree->buffer, scriptParseTree->len);
}

View File

@@ -0,0 +1,23 @@
#include "ScriptDumperT6.h"
using namespace T6;
namespace T6::script
{
bool Dumper::ShouldDump(XAssetInfo<ScriptParseTree>* asset)
{
return true;
}
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<ScriptParseTree>* asset)
{
const auto* scriptParseTree = asset->Asset();
const auto assetFile = context.OpenAssetFile(asset->m_name);
if (!assetFile)
return;
auto& stream = *assetFile;
stream.write(scriptParseTree->buffer, scriptParseTree->len);
}
} // namespace T6::script

View File

@@ -3,12 +3,12 @@
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
namespace T6
namespace T6::script
{
class AssetDumperScriptParseTree final : public AbstractAssetDumper<ScriptParseTree>
class Dumper final : public AbstractAssetDumper<ScriptParseTree>
{
protected:
bool ShouldDump(XAssetInfo<ScriptParseTree>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<ScriptParseTree>* asset) override;
};
} // namespace T6
} // namespace T6::script

View File

@@ -1,20 +0,0 @@
#include "AssetDumperSlug.h"
using namespace T6;
bool AssetDumperSlug::ShouldDump(XAssetInfo<Slug>* asset)
{
return true;
}
void AssetDumperSlug::DumpAsset(AssetDumpingContext& context, XAssetInfo<Slug>* asset)
{
const auto* slug = asset->Asset();
const auto assetFile = context.OpenAssetFile(asset->m_name);
if (!assetFile)
return;
auto& stream = *assetFile;
stream.write(slug->buffer, slug->len);
}

View File

@@ -0,0 +1,23 @@
#include "SlugDumperT6.h"
using namespace T6;
namespace T6::slug
{
bool Dumper::ShouldDump(XAssetInfo<Slug>* asset)
{
return true;
}
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<Slug>* asset)
{
const auto* slug = asset->Asset();
const auto assetFile = context.OpenAssetFile(asset->m_name);
if (!assetFile)
return;
auto& stream = *assetFile;
stream.write(slug->buffer, slug->len);
}
} // namespace T6::slug

View File

@@ -3,12 +3,12 @@
#include "Dumping/AbstractAssetDumper.h"
#include "Game/T6/T6.h"
namespace T6
namespace T6::slug
{
class AssetDumperSlug final : public AbstractAssetDumper<Slug>
class Dumper final : public AbstractAssetDumper<Slug>
{
protected:
bool ShouldDump(XAssetInfo<Slug>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<Slug>* asset) override;
};
} // namespace T6
} // namespace T6::slug