Skip to content

Commit

Permalink
feat: dump scriptfiles to gsc bin (gsc-tool) format
Browse files Browse the repository at this point in the history
  • Loading branch information
diamante0018 committed Dec 9, 2023
1 parent fe1d764 commit 902a2bc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
21 changes: 1 addition & 20 deletions src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperRawFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperScriptFile.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
14 changes: 14 additions & 0 deletions src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperScriptFile.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/ObjWriting/Game/IW5/ZoneDumperIW5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 902a2bc

Please sign in to comment.