| 459 | return Count; |
| 460 | } |
| 461 | |
| 462 | // Mirrors the data-folder layout DotNetHost::Initialize and DotNet::LoadCookedScripts probe. |
| 463 | void CopyDotNetPayload(const FPackagePlatformRules& Rules, |
| 464 | FStringView EngineInstallDir, |
| 465 | FStringView BinariesDir, |
| 466 | FStringView DataDir, |
| 467 | bool bStageSymbols, |
| 468 | const TFunction<void(FStringView)>& LogFunc) |
| 469 | { |
| 470 | // 1. The managed bootstrap alone, since scripts arrive prebuilt and the script compiler and its generators never run in a game. |
| 471 | const FFixedString ManagedSrc = Paths::Combine(BinariesDir, "DotNet/Managed"); |
| 472 | const FFixedString ManagedDst = Paths::Combine(DataDir, "Managed"); |
| 473 | const FStringView BootstrapFiles[] = { "LuminaSharp.dll", "LuminaSharp.runtimeconfig.json" }; |
| 474 | size_t BootstrapCopied = 0; |
| 475 | for (const FStringView File : BootstrapFiles) |
| 476 | { |
| 477 | BootstrapCopied += CopyFileTo(Paths::Combine(ManagedSrc, File), Paths::Combine(ManagedDst, File)) ? 1 : 0; |
| 478 | } |
| 479 | if (bStageSymbols) |
| 480 | { |
| 481 | CopyFileTo(Paths::Combine(ManagedSrc, "LuminaSharp.pdb"), Paths::Combine(ManagedDst, "LuminaSharp.pdb")); |
| 482 | } |
| 483 | if (BootstrapCopied == std::size(BootstrapFiles)) |
| 484 | { |
| 485 | LogPackager(LogFunc, "DotNet: staged the managed bootstrap."); |
| 486 | } |
| 487 | else |
| 488 | { |
| 489 | LogPackager(LogFunc, *Format("DotNet: [warn] managed bootstrap not found at {}; C# disabled in package.", *ManagedSrc)); |
| 490 | } |
| 491 | |
| 492 | // 2. The bundled .NET runtime for the target platform, which the host resolves as Runtime/<rid>. |
| 493 | FFixedString RuntimeSrc = Paths::Combine(EngineInstallDir, "External/DotNet/runtime", Rules.DotNetRuntimeRid); |
| 494 | if (!Filesystem::Exists(RuntimeSrc)) |
| 495 | { |
| 496 | // A Linux build in WSL brings its runtime back beside the binaries, since External may be another checkout's. |
| 497 | RuntimeSrc = Paths::Combine(BinariesDir, "DotNet/runtime", Rules.DotNetRuntimeRid); |
| 498 | } |
| 499 | if (Filesystem::Exists(RuntimeSrc)) |
| 500 | { |
| 501 | LogPackager(LogFunc, "DotNet: copying bundled .NET runtime (this can take a moment)..."); |
| 502 | const size_t N = CopyDirectoryRecursive(RuntimeSrc, Paths::Combine(DataDir, "Runtime", Rules.DotNetRuntimeRid)); |
| 503 | LogPackager(LogFunc, *Format("DotNet: staged .NET runtime ({} file(s)).", N)); |
| 504 | } |
| 505 | else |
| 506 | { |
| 507 | LogPackager(LogFunc, *Format("DotNet: [warn] bundled runtime not found at {}; C# disabled in package.", *RuntimeSrc)); |
| 508 | } |
| 509 | |
| 510 | // 3. Prebuilt script assemblies + the manifest the cooked loader reads, beside the bootstrap that loads them. |
| 511 | TVector<DotNet::FPackagedScriptUnit> Units; |
| 512 | DotNet::GatherScriptUnitsForPackaging(Units); |
| 513 | |
| 514 | const FFixedString& ScriptsDst = ManagedDst; |
| 515 | FString Manifest = "{\n \"Units\": [\n"; |
| 516 | size_t Staged = 0; |
| 517 | for (const DotNet::FPackagedScriptUnit& Unit : Units) |