-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
291 additions
and
30 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
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
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,52 @@ | ||
#include <includes.hpp> | ||
#include <tools/ff/linkers/linker_bo4.hpp> | ||
|
||
namespace fastfile::linker::bo4 { | ||
class RawFileWorker : public LinkerWorker { | ||
public: | ||
RawFileWorker() : LinkerWorker("RawFile") {} | ||
|
||
void Compute(BO4LinkContext& ctx) override { | ||
std::vector<std::filesystem::path> files{}; | ||
utils::GetFileRecurseExt(ctx.linkCtx.input, files, | ||
// all the extensions to read into the rawfile assets | ||
".cfg\0" | ||
".txt\0" | ||
".vision\0" | ||
".graph\0" | ||
".baseline\0" | ||
// extension used in the dump | ||
".raw\0" | ||
, true); | ||
|
||
for (const std::filesystem::path& rfpath : files) { | ||
std::filesystem::path path{ ctx.linkCtx.input / rfpath }; | ||
std::string buffer{}; | ||
if (!utils::ReadFile(path, buffer)) { | ||
LOG_ERROR("Can't read {}", path.string()); | ||
ctx.error = true; | ||
continue; | ||
} | ||
|
||
struct RawFile { | ||
XHash name; | ||
int32_t len; | ||
uintptr_t buffer; | ||
}; static_assert(sizeof(RawFile) == 0x20); | ||
|
||
RawFile& rf{ utils::Allocate<RawFile>(ctx.assetData) }; | ||
|
||
rf.name.hash = HashPathName(rfpath); | ||
rf.buffer = fastfile::ALLOC_PTR; | ||
rf.len = (uint32_t)buffer.size(); | ||
|
||
// write header | ||
utils::WriteValue(ctx.assetData, buffer.data(), buffer.length() + 1); // add \0 | ||
ctx.assets.emplace_back(games::bo4::pool::ASSET_TYPE_RAWFILE, fastfile::ALLOC_PTR); | ||
LOG_INFO("Added asset rawfile {} (hash_{:x})", path.string(), rf.name.hash); | ||
} | ||
} | ||
}; | ||
|
||
utils::ArrayAdder<RawFileWorker, LinkerWorker> impl{ GetWorkers() }; | ||
} |
88 changes: 88 additions & 0 deletions
88
src/acts/tools/ff/linkers/bo4/linker_bo4_scriptparsetree.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,88 @@ | ||
#include <includes.hpp> | ||
#include <tools/ff/linkers/linker_bo4.hpp> | ||
#include <tools/gsc.hpp> | ||
#include <compiler/gsc_compiler.hpp> | ||
|
||
namespace fastfile::linker::bo4 { | ||
class ScriptParseTreeWorker : public LinkerWorker { | ||
public: | ||
ScriptParseTreeWorker() : LinkerWorker("ScriptParseTree") {} | ||
|
||
static void AddGscHeader(BO4LinkContext& ctx, std::vector<byte>& buffer, const std::filesystem::path& path) { | ||
if (buffer.size() < sizeof(tool::gsc::T8GSCOBJ)) { | ||
LOG_ERROR("Can't read compiled gsc header for {}", path.string()); | ||
return; | ||
} | ||
tool::gsc::T8GSCOBJ& obj{ *(tool::gsc::T8GSCOBJ*)buffer.data() }; | ||
|
||
struct ScriptParseTree { | ||
XHash name; | ||
uintptr_t buffer; | ||
uint32_t len; | ||
}; static_assert(sizeof(ScriptParseTree) == 0x20); | ||
|
||
ScriptParseTree& spt{ utils::Allocate<ScriptParseTree>(ctx.assetData) }; | ||
|
||
spt.name.hash = obj.name; | ||
spt.buffer = fastfile::ALLOC_PTR; | ||
spt.len = (uint32_t)buffer.size(); | ||
|
||
// write script header | ||
buffer.push_back(0); // the game is reading (len + 1) so we add a byte at the end | ||
utils::WriteValue(ctx.assetData, buffer.data(), buffer.size()); | ||
ctx.assets.emplace_back(games::bo4::pool::ASSET_TYPE_SCRIPTPARSETREE, fastfile::ALLOC_PTR); | ||
LOG_INFO("Added asset scriptparsetree {} (hash_{:x})", path.string(), spt.name.hash); | ||
} | ||
|
||
void Compute(BO4LinkContext& ctx) override { | ||
std::vector<std::filesystem::path> scripts{}; | ||
std::filesystem::path scriptDir{ ctx.linkCtx.input / "scripts" }; | ||
utils::GetFileRecurseExt(scriptDir, scripts, ".csc\0.gsc\0", true); | ||
|
||
for (const std::filesystem::path& sub : scripts) { | ||
std::filesystem::path path{ scriptDir / sub }; | ||
std::filesystem::path scriptName{ std::filesystem::path{"scripts"} / sub }; | ||
LOG_TRACE("Processing {} ({})", scriptName.string(), path.string()); | ||
|
||
// compile file | ||
acts::compiler::CompilerConfig cfg{}; | ||
std::string snp{ scriptName.string() }; | ||
cfg.name = hashutils::CleanPath(snp.data()); | ||
cfg.platform = tool::gsc::opcode::PLATFORM_PC; | ||
cfg.vm = tool::gsc::opcode::VMI_T8; | ||
cfg.detourType = acts::compiler::DETOUR_ACTS; | ||
cfg.clientScript = scriptName.extension() == ".csc"; | ||
cfg.processorOpt.defines.insert(std::format("_FF_GEN_{}", ctx.linkCtx.ffname)); | ||
|
||
std::vector<byte> buffer{}; | ||
try { | ||
acts::compiler::CompileGsc(path, buffer, cfg); | ||
} | ||
catch (std::runtime_error& re) { | ||
LOG_ERROR("Can't compile {}: {}", path.string(), re.what()); | ||
ctx.error = true; | ||
continue; | ||
} | ||
|
||
|
||
LOG_INFO("Compiled {} ({})", path.string(), cfg.name); | ||
AddGscHeader(ctx, buffer, path); | ||
// TODO: generate and add ScriptParseTreeDBG header | ||
} | ||
|
||
scripts.clear(); | ||
utils::GetFileRecurseExt(ctx.linkCtx.input, scripts, ".cscc\0.gscc\0"); | ||
for (const std::filesystem::path& path : scripts) { | ||
std::vector<byte> buffer{}; | ||
if (!utils::ReadFile(path, buffer)) { | ||
LOG_ERROR("Can't read {}", path.string()); | ||
ctx.error = true; | ||
continue; | ||
} | ||
AddGscHeader(ctx, buffer, path); | ||
} | ||
} | ||
}; | ||
|
||
utils::ArrayAdder<ScriptParseTreeWorker, LinkerWorker> impl{ GetWorkers() }; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
#include <core/config.hpp> | ||
#include <tools/ff/fastfile_handlers.hpp> | ||
#include <games/bo4/pool.hpp> | ||
|
||
namespace fastfile::linker::bo4 { | ||
struct XHash { | ||
uint64_t hash; | ||
uint64_t nulled; | ||
}; | ||
struct XAsset { | ||
games::bo4::pool::XAssetType type; | ||
uintptr_t header; // XAssetHeader | ||
}; | ||
|
||
struct ScriptStringList { | ||
int count; | ||
uintptr_t strings; // const char** | ||
}; | ||
|
||
struct XAssetList { | ||
ScriptStringList stringList; | ||
int assetCount; | ||
uintptr_t assets; // XAsset* | ||
}; | ||
|
||
struct BO4LinkContext { | ||
FastFileLinkerContext& linkCtx; | ||
core::config::Config& ffConfig; | ||
std::vector<byte> assetData{}; | ||
std::vector<const char*> strings{}; | ||
std::vector<XAsset> assets{}; | ||
bool error{}; | ||
}; | ||
|
||
class LinkerWorker { | ||
public: | ||
const char* id; | ||
LinkerWorker(const char* id) : id(id) {} | ||
|
||
virtual void Compute(BO4LinkContext& ctx) = 0; | ||
}; | ||
|
||
uint64_t HashPathName(const std::filesystem::path& path); | ||
|
||
std::vector<LinkerWorker*>& GetWorkers(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is a raw file with some data! |
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,5 @@ | ||
{ | ||
"data": { | ||
"name": "core_test" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test/ff-linker/core_test/scripts/core_common/acts/test_shared.csc
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,8 @@ | ||
#using scripts\core_common\array_shared; | ||
#using scripts\core_common\system_shared; | ||
|
||
#namespace test_shared; | ||
|
||
function test_function() { | ||
return "csc"; | ||
} |
Oops, something went wrong.