Skip to content

Commit

Permalink
add spt forced linker
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Feb 16, 2025
1 parent 067bdfe commit 582aa20
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/acts/tools/ff/linkers/bo4/linker_bo4_rawfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ namespace fastfile::linker::bo4 {

RawFile& rf{ utils::Allocate<RawFile>(ctx.assetData) };

rf.name.hash = HashPathName(rfpath);
uint64_t hash = HashPathName(rfpath);
rf.name.hash = hash;
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);
LOG_INFO("Added asset rawfile {} (hash_{:x})", path.string(), hash);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace fastfile::linker::bo4 {
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);
LOG_INFO("Added asset scriptparsetree {} (hash_{:x})", path.string(), obj.name);
}

void Compute(BO4LinkContext& ctx) override {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <includes.hpp>
#include <tools/ff/linkers/linker_bo4.hpp>

namespace fastfile::linker::bo4 {
class ScriptParseTreeForcedWorker : public LinkerWorker {
public:
ScriptParseTreeForcedWorker() : LinkerWorker("ScriptParseTreeForced") {}

void Compute(BO4LinkContext& ctx) override {

std::filesystem::path forcedConfigPath{ ctx.linkCtx.input / "sptforced.json" };
core::config::Config forcedConfig{ forcedConfigPath };
forcedConfig.SyncConfig(false);
if (forcedConfig.main.Empty()) return; // nothing to force

std::vector<XHash> serverScripts{};
std::vector<XHash> clientScripts{};

if (forcedConfig.main.HasMember("server")) {
for (auto& e : forcedConfig.main["server"].GetArray()) {
if (!e.IsString()) {
LOG_WARNING("Invalid entry in sptforced.json: {}", e.GetString());
continue;
}
serverScripts.emplace_back(hash::Hash64Pattern(e.GetString()), 0);
}
}
if (forcedConfig.main.HasMember("client")) {
for (auto& e : forcedConfig.main["client"].GetArray()) {
if (!e.IsString()) {
LOG_WARNING("Invalid entry in sptforced.json: {}", e.GetString());
continue;
}
clientScripts.emplace_back(hash::Hash64Pattern(e.GetString()), 0);
}
}

if (clientScripts.empty() && serverScripts.empty()) {
LOG_INFO("Nothing to compile for spt forced: {}", forcedConfigPath.string());
return; // nothing to compile
}

struct ScriptParseTreeForced {
XHash name;
uint32_t gscCount;
uint32_t cscCount;
uintptr_t gscScripts; // XHash*
uintptr_t cscScripts; // XHash*
};

ScriptParseTreeForced& header{ utils::Allocate<ScriptParseTreeForced>(ctx.assetData) };
header.name.hash = ctx.ffnameHash;
header.gscCount = (uint32_t)serverScripts.size();
header.cscCount = (uint32_t)clientScripts.size();
if (serverScripts.size()) header.gscScripts = fastfile::ALLOC_PTR;
if (clientScripts.size()) header.cscScripts = fastfile::ALLOC_PTR;

utils::WriteValue(ctx.assetData, serverScripts.data(), serverScripts.size() * sizeof(serverScripts[0]));
utils::WriteValue(ctx.assetData, clientScripts.data(), clientScripts.size() * sizeof(clientScripts[0]));
ctx.assets.emplace_back(games::bo4::pool::ASSET_TYPE_SCRIPTPARSETREEFORCED, fastfile::ALLOC_PTR);
LOG_INFO("Added asset scriptparsetreeforced {} (hash_{:x})", forcedConfigPath.string(), ctx.ffnameHash);
}
};

utils::ArrayAdder<ScriptParseTreeForcedWorker, LinkerWorker> impl{ GetWorkers() };
}
1 change: 1 addition & 0 deletions src/acts/tools/ff/linkers/linker_bo4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace fastfile::linker::bo4 {
}

BO4LinkContext bo4ctx{ ctx, cfg };
bo4ctx.ffnameHash = hash::Hash64Pattern(ctx.ffname);


// load files into bo4ctx.assetData
Expand Down
1 change: 1 addition & 0 deletions src/acts/tools/ff/linkers/linker_bo4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace fastfile::linker::bo4 {
std::vector<const char*> strings{};
std::vector<XAsset> assets{};
bool error{};
uint64_t ffnameHash{};
};

class LinkerWorker {
Expand Down
8 changes: 8 additions & 0 deletions test/ff-linker/core_test/sptforced.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"server": [
"scripts/core_common/acts/test_shared.gsc"
],
"client": [
"scripts/core_common/acts/test_shared.csc"
]
}

0 comments on commit 582aa20

Please sign in to comment.