Skip to content

Commit 08f94a3

Browse files
committed
add --scriptsFormatter opt in fastfile tool to select gsc decompiler formatter
1 parent 964b40a commit 08f94a3

12 files changed

+36
-3
lines changed

src/acts/tools/fastfile/fastfile_handlers.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ namespace fastfile {
278278
}
279279

280280

281+
FastFileOption::FastFileOption() {
282+
gscFormatter = &tool::gsc::formatter::GetDefaultFormatter();
283+
}
284+
281285
FastFileOption::~FastFileOption() {
282286
if (cascStorage) {
283287
CascCloseStorage(cascStorage);
@@ -437,6 +441,21 @@ namespace fastfile {
437441
else if (!_strcmpi("--dumpBinaryAssetsMap", arg)) {
438442
dumpBinaryAssetsMap = true;
439443
}
444+
else if (!_strcmpi("--scriptsFormatter", arg)) {
445+
if (i + 1 == endIndex) {
446+
std::cerr << "Missing value for param: " << arg << "!\n";
447+
return false;
448+
}
449+
450+
const tool::gsc::formatter::FormatterInfo* fmt{ tool::gsc::formatter::GetFromName(args[++i]) };
451+
452+
if (!fmt) {
453+
LOG_ERROR("Unknown gsc formatter: {}!", args[i]);
454+
return false;
455+
}
456+
457+
gscFormatter = fmt;
458+
}
440459
else if (!_strcmpi("--disableScriptsDecomp", arg)) {
441460
disableScriptsDecomp = true;
442461
}
@@ -510,6 +529,7 @@ namespace fastfile {
510529
LOG_INFO("--dumpBinaryAssetsMap : Dump binary assets map");
511530
LOG_INFO("--dumpAssetNames : Dump binary assets");
512531
LOG_INFO("--dumpCompiledZone : Dump compiled zone file");
532+
LOG_INFO("--scriptsFormatter [f] : Set formatter for GSC decompiler");
513533
LOG_INFO("--disableScriptsDecomp : Disable GSC script decompilation");
514534
LOG_INFO("--dumpXStrings : Dump XStrings");
515535
LOG_INFO("--graphic : Dump graphic assets (do not share graphic assets)");

src/acts/tools/fastfile/fastfile_handlers.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <core/memory_allocator.hpp>
55
#include <tools/fastfile/fastfile_zone.hpp>
66
#include <tools/gsc/gsc_opcodes_load.hpp>
7+
#include <tools/gsc/decompiler/gsc_decompiler_formatter.hpp>
78
#include <utils/compress_utils.hpp>
89
#define LTC_NO_PROTOTYPES
910
#include <tomcrypt.h>
@@ -153,7 +154,9 @@ namespace fastfile {
153154
std::vector<std::set<uint64_t>> assetNames{};
154155
std::unordered_map<uint64_t, const char*> translationKeys{};
155156
core::memory_allocator::MemoryAllocator alloc{};
157+
const tool::gsc::formatter::FormatterInfo* gscFormatter{};
156158

159+
FastFileOption();
157160
~FastFileOption();
158161
bool Compute(const char** args, size_t startIndex, size_t endIndex);
159162
void PrintHelp();

src/acts/tools/fastfile/handlers/bo3/bo3_unlinker_scriptparsetree.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace {
4646
std::filesystem::path outSource{ opt.m_output / "bo3" / "source" };
4747
std::string outSourceStr{ outSource.string() };
4848
gdctx.opt.m_outputDir = outSourceStr.data();
49+
gdctx.opt.m_formatter = opt.gscFormatter;
4950

5051
std::vector<byte> scriptData;
5152
byte* alignedAlloc{ utils::Aligned(spt->buffer, 0x20) };

src/acts/tools/fastfile/handlers/bo4/bo4_unlinker_scriptparsetree.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace {
6969
std::filesystem::path outSource{ opt.m_output / "bo4" / "source" };
7070
std::string outSourceStr{ outSource.string() };
7171
gdctx.opt.m_outputDir = outSourceStr.data();
72+
gdctx.opt.m_formatter = opt.gscFormatter;
7273

7374
std::vector<byte> scriptData;
7475
byte* alignedAlloc{ utils::Aligned(spt->buffer, 0x20) };

src/acts/tools/fastfile/handlers/bo6/bo6_unlinker_gscobj.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace {
7272
std::filesystem::path outSource{ opt.m_output / gamePath / "source" };
7373
std::string outSourceStr{ outSource.string() };
7474
gdctx.opt.m_outputDir = outSourceStr.data();
75+
gdctx.opt.m_formatter = opt.gscFormatter;
7576
if (opt.translation) {
7677
gdctx.opt.LookupLocalizedFunc = LookupLocalizedImpl;
7778
}

src/acts/tools/fastfile/handlers/bo6sp/bo6sp_unlinker_gscobj.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace {
7272
std::filesystem::path outSource{ opt.m_output / "bo6sp" / "source" };
7373
std::string outSourceStr{ outSource.string() };
7474
gdctx.opt.m_outputDir = outSourceStr.data();
75+
gdctx.opt.m_formatter = opt.gscFormatter;
7576
if (opt.translation) {
7677
gdctx.opt.LookupLocalizedFunc = LookupLocalizedImpl;
7778
}

src/acts/tools/fastfile/handlers/bo7/bo7_unlinker_gscobj.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ namespace {
7474
std::filesystem::path outSource{ opt.m_output / gamePath / "source" };
7575
std::string outSourceStr{ outSource.string() };
7676
gdctx.opt.m_outputDir = outSourceStr.data();
77+
gdctx.opt.m_formatter = opt.gscFormatter;
7778
if (opt.translation) {
7879
gdctx.opt.LookupLocalizedFunc = LookupLocalizedImpl;
7980
}

src/acts/tools/fastfile/handlers/cw/cw_unlinker_scriptparsetree.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace {
4141
std::filesystem::path outSource{ opt.m_output / "cw" / "source" };
4242
std::string outSourceStr{ outSource.string() };
4343
gdctx.opt.m_outputDir = outSourceStr.data();
44+
gdctx.opt.m_formatter = opt.gscFormatter;
4445

4546
std::vector<byte> scriptData;
4647
byte* alignedAlloc{ utils::Aligned(asset->buffer, 0x20) };

src/acts/tools/fastfile/handlers/handler_gsc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace {
3232
std::filesystem::path outSource{ opt.m_output / "gsc_decomp" };
3333
std::string outSourceStr{ outSource.string() };
3434
gdctx.opt.m_outputDir = outSourceStr.data();
35+
gdctx.opt.m_formatter = opt.gscFormatter;
3536

3637
std::vector<byte> scriptData;
3738
byte* alignedAlloc{ utils::Aligned(file, 0x20) };

src/acts/tools/fastfile/handlers/mwiii/mwiii_unlinker_gscobj.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ namespace {
7373
std::filesystem::path outSource{ opt.m_output / gamePath / "source" };
7474
std::string outSourceStr{ outSource.string() };
7575
gdctx.opt.m_outputDir = outSourceStr.data();
76+
gdctx.opt.m_formatter = opt.gscFormatter;
7677
if (opt.translation) {
7778
gdctx.opt.LookupLocalizedFunc = LookupLocalizedImpl;
7879
}

0 commit comments

Comments
 (0)