Support first-run selection and optional tutorials

Save the selected country, starting crew, and unlocks when the client
submits its first-run selection. Use the stock unlock and crew formats.
Enable the existing option to skip the basic tutorial.

The client reached the hangar. Tutorial verification is pending.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 10:01:47 +08:00
1 parent c3c5f583ad
commit 6ed498e4d0
8 files changed
+227 -10

No files matched your search

+15 -4
View File
@@ -1,16 +1,27 @@
/** Rebuild char.vromfs.bin with config/network.blk pointed at the local service. */
/**
* Rebuild char.vromfs.bin: config/network.blk pointed at the local service, and the offline
* version's features turned on in config/game_settings.blk.
*/
import { enableFeaturesForEveryone, GAME_SETTINGS_PATH, OFFLINE_FEATURES } from './features/offline-features.ts';
import type { LocalEndpoint } from './network/local-endpoint.ts';
import { redirectNetworkConfig, type NetworkRedirectReport } from './network/redirect-network-config.ts';
import { editPackBlk } from './pack-edit.ts';
import { editPackBlks } from './pack-edit.ts';
export const NETWORK_CONFIG_PATH = 'config/network.blk';
export interface CharPackResult {
readonly pack: Uint8Array;
readonly network: NetworkRedirectReport;
/** Features that are now on for every player. */
readonly features: readonly string[];
}
export function rebuildCharPack(stockPack: Uint8Array, endpoint: LocalEndpoint): CharPackResult {
const { pack, report } = editPackBlk(stockPack, NETWORK_CONFIG_PATH, (root) => redirectNetworkConfig(root, endpoint));
return { pack, network: report };
let network: NetworkRedirectReport | undefined;
let features: string[] = [];
const pack = editPackBlks(stockPack, [
{ path: NETWORK_CONFIG_PATH, edit: (root) => { network = redirectNetworkConfig(root, endpoint); } },
{ path: GAME_SETTINGS_PATH, edit: (root) => { features = enableFeaturesForEveryone(root, OFFLINE_FEATURES); } },
]);
return { pack, network: network!, features };
}
+1
View File
@@ -48,6 +48,7 @@ function main(): number {
if (values.verbose) {
for (const change of charPack.network.addresses) console.log(` ${change.path}: ${change.before} -> ${change.after}`);
}
console.log(`game_settings.blk: features on for every player: ${charPack.features.join(', ') || '(already on)'}`);
const mainPack = rebuildMainPack(readFileSync(join(values.game, GAME_FILES.mainPack)), endpoint);
console.log(`settings.blk: ${mainPack.addresses.length} address(es) now point to ${endpoint.host}:${endpoint.port}`);
@@ -0,0 +1,31 @@
/**
* Game features (feature flags) the offline version turns on for every player.
*
* char.vromfs.bin config/game_settings.blk lists features as features{ <name>{ condition:t } };
* condition:t="" means every player has it (the UI scripts ask with hasFeature, which falls
* back to the native local_player_has_feature, scripts/user/features.nut).
*
* AllowedToSkipBaseTutorials: lets the player skip the base tutorials. The stock tutorial
* offer (scripts/tutorials/nextTutorialHandler.nut) enables its skip and close buttons only
* with this feature (tutorialsData.nut canSkipByFeature). The offline version makes the
* tutorial optional (local verification).
*/
import { ensureBlock, setParam, type BlkBlock } from '@wto/blk';
export const GAME_SETTINGS_PATH = 'config/game_settings.blk';
export const OFFLINE_FEATURES: readonly string[] = ['AllowedToSkipBaseTutorials'];
/** Give every player the features; returns the ones that were not on for everyone before. */
export function enableFeaturesForEveryone(gameSettings: BlkBlock, names: readonly string[]): string[] {
const features = ensureBlock(gameSettings, 'features');
const changed: string[] = [];
for (const name of names) {
const feature = ensureBlock(features, name);
const condition = feature.params.find((param) => param.name === 'condition')?.value;
if (condition?.type === 'string' && condition.value === '') continue;
setParam(feature, 'condition', { type: 'string', value: '' });
changed.push(name);
}
return changed;
}
+20 -6
View File
@@ -1,6 +1,6 @@
/**
* Rebuild a data pack with one of its BLK documents edited. Every other file of the pack is
* kept byte for byte. The edited document is stored self-contained (it no longer depends on
* Rebuild a data pack with some of its BLK documents edited. Every other file of the pack is
* kept byte for byte. Edited documents are stored self-contained (they no longer depend on
* the pack's shared name map), which the game accepts in every loading mode
*.
*/
@@ -12,14 +12,28 @@ export interface PackEditResult<T> {
readonly report: T;
}
/** One BLK document of the pack and the change to make to it. */
export interface BlkEdit {
readonly path: string;
readonly edit: (root: BlkBlock) => void;
}
export function editPackBlk<T>(stockPack: Uint8Array, blkPath: string, edit: (root: BlkBlock) => T): PackEditResult<T> {
let report: T | undefined;
const pack = editPackBlks(stockPack, [{ path: blkPath, edit: (root) => { report = edit(root); } }]);
return { pack, report: report as T };
}
export function editPackBlks(stockPack: Uint8Array, edits: readonly BlkEdit[]): Uint8Array {
const archive = readArchive(stockPack);
const dictionary = findDictionary(archive);
const names = archive.files.has(NAME_MAP_PATH) ? parseSharedNameMap(getFile(archive, NAME_MAP_PATH), dictionary).names : [];
const root = decodeBlk(getFile(archive, blkPath), { names, dictionary });
const report = edit(root);
putFile(archive, blkPath, encodeBlk(root));
return { pack: writeArchive(archive), report };
for (const { path, edit } of edits) {
const root = decodeBlk(getFile(archive, path), { names, dictionary });
edit(root);
putFile(archive, path, encodeBlk(root));
}
return writeArchive(archive);
}
/** The pack's zstd dictionary, if it has one. */