2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-02 15:07:26 +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