Merge pull request #49 from diamante0018/iw5/dump-scriptfile

feat: dump scriptfiles to gsc bin (gsc-tool) format
This commit is contained in:
Jan 2023-12-09 22:33:00 +01:00 committed by GitHub
commit f7eb5182c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 23 deletions

View File

@ -10,25 +10,6 @@ bool AssetDumperRawFile::ShouldDump(XAssetInfo<RawFile>* asset)
return true;
}
std::string AssetDumperRawFile::GetAssetFileName(XAssetInfo<GfxImage>* asset)
{
std::string cleanAssetName = asset->m_name;
for (auto& c : cleanAssetName)
{
switch (c)
{
case '*':
c = '_';
break;
default:
break;
}
}
return cleanAssetName;
}
void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawFile>* asset)
{
const auto* rawFile = asset->Asset();
@ -68,7 +49,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
if (ret < 0)
{
printf("Inflate failed for dumping rawfile '%s'\n", rawFile->name);
std::cerr << "Inflate failed when attempting to dump rawfile " << rawFile->name << std::endl;
inflateEnd(&zs);
return;
}

View File

@ -7,8 +7,6 @@ namespace IW5
{
class AssetDumperRawFile final : public AbstractAssetDumper<RawFile>
{
static std::string GetAssetFileName(XAssetInfo<GfxImage>* asset);
protected:
bool ShouldDump(XAssetInfo<RawFile>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<RawFile>* asset) override;

View File

@ -0,0 +1,30 @@
#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,14 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/IW5/IW5.h"
namespace IW5
{
class AssetDumperScriptFile final : public AbstractAssetDumper<ScriptFile>
{
protected:
bool ShouldDump(XAssetInfo<ScriptFile>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<ScriptFile>* asset) override;
};
} // namespace IW5

View File

@ -7,6 +7,7 @@
#include "AssetDumpers/AssetDumperMenuDef.h"
#include "AssetDumpers/AssetDumperMenuList.h"
#include "AssetDumpers/AssetDumperRawFile.h"
#include "AssetDumpers/AssetDumperScriptFile.h"
#include "AssetDumpers/AssetDumperStringTable.h"
#include "AssetDumpers/AssetDumperXModel.h"
#include "Game/IW5/GameAssetPoolIW5.h"
@ -63,7 +64,7 @@ bool ZoneDumper::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(AssetDumperRawFile, m_raw_file, ASSET_TYPE_RAWFILE)
// DUMP_ASSET_POOL(AssetDumperScriptFile, m_script_file, ASSET_TYPE_SCRIPTFILE)
DUMP_ASSET_POOL(AssetDumperScriptFile, m_script_file, ASSET_TYPE_SCRIPTFILE)
DUMP_ASSET_POOL(AssetDumperStringTable, m_string_table, ASSET_TYPE_STRINGTABLE)
// DUMP_ASSET_POOL(AssetDumperLeaderboardDef, m_leaderboard, ASSET_TYPE_LEADERBOARD)
// DUMP_ASSET_POOL(AssetDumperStructuredDataDefSet, m_structed_data_def_set, ASSET_TYPE_STRUCTURED_DATA_DEF)