-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dump scriptfiles to gsc bin (gsc-tool) format
- Loading branch information
1 parent
fe1d764
commit 902a2bc
Showing
5 changed files
with
47 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperScriptFile.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
src/ObjWriting/Game/IW5/AssetDumpers/AssetDumperScriptFile.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters