feat(profile): support first-run selection and tutorial skipping
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:
1 parent
ac2c185d4c
commit
d88aa3ff4f
8 files changed
+227
-10
No files matched your search
@@ -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 };
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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. */
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { acceptEula } from './agreement-actions.ts';
|
||||
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
|
||||
import { setStartingInfo } from './starting-info-actions.ts';
|
||||
|
||||
export interface ActionDependencies {
|
||||
readonly profiles: PlayerProfiles;
|
||||
@@ -16,5 +17,6 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
|
||||
['cln_upd_entitlements_full', entitlementsFull(deps.profiles, deps.accounts)],
|
||||
['cln_legacy_get_userdata', legacyUserData(deps.profiles, deps.accounts)],
|
||||
['cln_accept_eula', acceptEula(deps.profiles, deps.accounts)],
|
||||
['cln_set_starting_info', setStartingInfo(deps.profiles, deps.accounts)],
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* The new player's first choice (implementation notes, step 6).
|
||||
*
|
||||
* The stock "first choice" window (gui.vromfs.bin scripts/firstChoice/unitTypeChoiceHandler.nut,
|
||||
* clnSetStartingInfo) sends cln_set_starting_info with:
|
||||
* country:t the country picked
|
||||
* unitType:i the vehicle type picked
|
||||
* unlock:t repeated: every country, and "chosen_unit_type_<type>" for the type picked
|
||||
* batchTrainCrew{ trainCrew{ crewId:i unitName:t } ... } the vehicle for every crew slot
|
||||
* ("" leaves the slot empty)
|
||||
* The login script waits until the vehicle type counts as chosen, which the client reads as
|
||||
* the unlock "chosen_unit_type_<type>" being earned (scripts/unit/unitTypesList.nut
|
||||
* isFirstChosen). The client applies the answer as a profile update
|
||||
* (GameSaveData::onAsyncEconTransComplete -> onUpdateProfile, job type 13), so the answer is
|
||||
* the whole updated profile.
|
||||
*
|
||||
* The country picked is also recorded as chosen ("chosen_country_<country>", defined in
|
||||
* config/unlocks.blk). The stock scripts start the base tutorial by force for a player who
|
||||
* has a chosen vehicle type but no chosen country (scripts/tutorials.nut checkTutorialOnStart:
|
||||
* needAutoStartTutorial = !hasRunTutorialDialog(), which is false while
|
||||
* scripts/user/newbieTutorialDisplay.nut reqFirstCountryChoice() holds). With the country
|
||||
* chosen, they offer the tutorial instead, which the player may skip (local verification; the
|
||||
* skip itself is the feature AllowedToSkipBaseTutorials, set by the build).
|
||||
*/
|
||||
import { findBlock, findParam, type BlkBlock } from '@wto/blk';
|
||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||
import { clientProfile } from '../../profile/client-profile.ts';
|
||||
import { crewOf, putVehicleInCrew } from '../../profile/profile-crews.ts';
|
||||
import { addUnlock } from '../../profile/profile-unlocks.ts';
|
||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { withAccount } from './account-context.ts';
|
||||
|
||||
interface CrewVehicle {
|
||||
readonly crewId: number;
|
||||
readonly vehicle: string;
|
||||
}
|
||||
|
||||
export function setStartingInfo(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
return (context) => withAccount(context, accounts, (account) => {
|
||||
const payload = context.payload;
|
||||
if (!payload) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
const unlocks = payload.params.flatMap((param) => (param.name === 'unlock' && param.value.type === 'string' ? [param.value.value] : []));
|
||||
const country = findParam(payload, 'country')?.value;
|
||||
const crews = crewVehicles(findBlock(payload, 'batchTrainCrew'));
|
||||
if (unlocks.length === 0 || crews === undefined || country?.type !== 'string' || !country.value.startsWith('country_')) {
|
||||
return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
}
|
||||
unlocks.push(`chosen_${country.value}`);
|
||||
|
||||
const current = profiles.profileOf(account.userId);
|
||||
if (crews.some(({ crewId }) => crewOf(current, crewId) === undefined)) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
|
||||
const profile = profiles.update(account.userId, (saved) => {
|
||||
for (const unlock of unlocks) addUnlock(saved, unlock);
|
||||
for (const { crewId, vehicle } of crews) {
|
||||
if (vehicle !== '') putVehicleInCrew(crewOf(saved, crewId)!, vehicle);
|
||||
}
|
||||
});
|
||||
return { kind: 'data', blk: clientProfile(profile, account) };
|
||||
});
|
||||
}
|
||||
|
||||
/** The crew slots of batchTrainCrew, or undefined when an entry is malformed. */
|
||||
function crewVehicles(batch: BlkBlock | undefined): CrewVehicle[] | undefined {
|
||||
if (!batch) return [];
|
||||
const result: CrewVehicle[] = [];
|
||||
for (const entry of batch.blocks) {
|
||||
if (entry.name !== 'trainCrew') continue;
|
||||
const crewId = findParam(entry, 'crewId')?.value;
|
||||
const vehicle = findParam(entry, 'unitName')?.value;
|
||||
if (crewId?.type !== 'int' || vehicle?.type !== 'string') return undefined;
|
||||
result.push({ crewId: crewId.value, vehicle: vehicle.value });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Crews in the profile, as in Gaijin's config/default_user.blk:
|
||||
*
|
||||
* crews{
|
||||
* c0{
|
||||
* country:t="country_usa"
|
||||
* aircrafts{ trained:t="bf2c_1" trained:t="p-26a_34_m2" current:t="bf2c_1" }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* "trained" lists the vehicles the crew is trained for (repeated), "current" is the vehicle
|
||||
* in its slot.
|
||||
*/
|
||||
import { ensureBlock, setParam, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const CREWS = 'crews';
|
||||
const VEHICLES = 'aircrafts';
|
||||
const TRAINED = 'trained';
|
||||
const CURRENT = 'current';
|
||||
|
||||
export function crewOf(profile: BlkBlock, crewId: number): BlkBlock | undefined {
|
||||
return profile.blocks.find((block) => block.name === CREWS)?.blocks.find((crew) => crew.name === `c${crewId}`);
|
||||
}
|
||||
|
||||
/** Train the crew for the vehicle (if it is not yet) and put the vehicle in its slot. */
|
||||
export function putVehicleInCrew(crew: BlkBlock, vehicle: string): void {
|
||||
const vehicles = ensureBlock(crew, VEHICLES);
|
||||
const trained = vehicles.params.some((param) => param.name === TRAINED && param.value.type === 'string' && param.value.value === vehicle);
|
||||
if (!trained) vehicles.params.push({ name: TRAINED, value: { type: 'string', value: vehicle } });
|
||||
setParam(vehicles, CURRENT, { type: 'string', value: vehicle });
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Earned unlocks in the profile.
|
||||
*
|
||||
* unlocks{
|
||||
* unlock{ item:t="country_usa" cachedIndex:i=-1 expired:b=no earned:b=yes }
|
||||
* }
|
||||
*
|
||||
* The client's profile reader (aces.exe 2.61.0.37 0x919060, from 0x91bad2) walks the
|
||||
* sub-blocks of "unlocks" named "unlock" and reads each one's parameters in this order,
|
||||
* matching every position by name:
|
||||
* item:t the unlock's id from config/unlocks.blk; must come first
|
||||
* ("TROPHY: Bad DataBlock for unlock - NO id param" otherwise)
|
||||
* cachedIndex:i optional; the unlock's position in the client's table, only a
|
||||
* lookup hint: a negative value makes the client look it up by name
|
||||
* (0x91c052)
|
||||
* expired:b optional
|
||||
* removeTimeMinutes:i optional
|
||||
* earned:b only "earned:b=yes" marks the unlock earned (0x91c289..0x91c2b7
|
||||
* sets the flag that the script function is_unlocked, 0x179eae0,
|
||||
* reads); without it the unlock is registered but not earned
|
||||
* The client's own profile writer (0x91cd6f..) emits the same head: item, cachedIndex,
|
||||
* expired, then removeTimeMinutes when set, then earned.
|
||||
*/
|
||||
import { ensureBlock, findParam, type BlkBlock, type BlkParam } from '@wto/blk';
|
||||
|
||||
const UNLOCKS = 'unlocks';
|
||||
const UNLOCK = 'unlock';
|
||||
const ITEM = 'item';
|
||||
|
||||
/** Record the unlock as earned, rewriting an existing entry for it. */
|
||||
export function addUnlock(profile: BlkBlock, name: string): void {
|
||||
const unlocks = ensureBlock(profile, UNLOCKS);
|
||||
const existing = unlocks.blocks.find((unlock) => unlockName(unlock) === name);
|
||||
if (existing) existing.params = earnedUnlockParams(name);
|
||||
else unlocks.blocks.push({ name: UNLOCK, params: earnedUnlockParams(name), blocks: [] });
|
||||
}
|
||||
|
||||
function earnedUnlockParams(name: string): BlkParam[] {
|
||||
return [
|
||||
{ name: ITEM, value: { type: 'string', value: name } },
|
||||
{ name: 'cachedIndex', value: { type: 'int', value: -1 } },
|
||||
{ name: 'expired', value: { type: 'bool', value: false } },
|
||||
{ name: 'earned', value: { type: 'bool', value: true } },
|
||||
];
|
||||
}
|
||||
|
||||
function unlockName(unlock: BlkBlock): string | undefined {
|
||||
if (unlock.name !== UNLOCK) return undefined;
|
||||
const item = findParam(unlock, ITEM)?.value;
|
||||
return item?.type === 'string' ? item.value : undefined;
|
||||
}
|
||||
Reference in new issue
Block a user