feat(saves): seed new saves and reveal eligible hidden vehicles
Set initial Silver Lions and Golden Eagles balances and add a save editing command. Open rank I for each nation and branch and migrate older saves to format 3. Reveal eligible hidden vehicles while keeping split air-defense launchers out of the tech tree. Document the currency, rank, and unit status fields observed in the offline client.
This commit is contained in:
1 parent
ed0136f5fc
commit
e5452e925f
12 files changed
+282
-12
No files matched your search
@@ -56,6 +56,11 @@ export class AccountStore {
|
||||
return this.#file.accounts.find((account) => account.userId === userId);
|
||||
}
|
||||
|
||||
/** The account with this login, compared without regard to case. */
|
||||
byLogin(login: string): Account | undefined {
|
||||
return this.#find(login);
|
||||
}
|
||||
|
||||
#find(login: string): Account | undefined {
|
||||
const key = login.toLowerCase();
|
||||
return this.#file.accounts.find((account) => account.login.toLowerCase() === key);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Dataset: the tech-tree branches of each country.
|
||||
*
|
||||
* char.vromfs.bin config/shop.blk has one top-level block per country, and under it one block
|
||||
* per branch: army, helicopters, aviation, ships, boats (2.61.0.37: China, Sweden and Israel
|
||||
* have no naval branches).
|
||||
*/
|
||||
import type { Dataset } from './dataset.ts';
|
||||
|
||||
const SHOP = 'config/shop.blk';
|
||||
|
||||
export type ShopBranches = Readonly<Record<string, readonly string[]>>;
|
||||
|
||||
export const shopBranches: Dataset<ShopBranches> = {
|
||||
id: 'shop-branches',
|
||||
version: 1,
|
||||
extract: (source) => Object.fromEntries(source.readBlk('char.vromfs.bin', SHOP).blocks.map((country) => [country.name, country.blocks.map((branch) => branch.name)])),
|
||||
};
|
||||
@@ -10,6 +10,7 @@ import { DownloadableContentService } from './downloadable-content/downloadable-
|
||||
import { DatasetCache } from './game-data/datasets/dataset-cache.ts';
|
||||
import { multiplayerMissions } from './game-data/datasets/multiplayer-missions.ts';
|
||||
import { reserveVehicles } from './game-data/datasets/reserve-vehicles.ts';
|
||||
import { shopBranches } from './game-data/datasets/shop-branches.ts';
|
||||
import { shopCountries } from './game-data/datasets/shop-countries.ts';
|
||||
import { GameFiles } from './game-data/game-files.ts';
|
||||
import { GameModes } from './game-modes/game-modes.ts';
|
||||
@@ -46,7 +47,7 @@ export async function startLocalService(options: LocalServiceOptions): Promise<R
|
||||
// Static data first, before the port opens.
|
||||
const datasets = new DatasetCache(options.dataFolder, gameFiles, report);
|
||||
const gameModes = new GameModes(datasets.load(multiplayerMissions), datasets.load(shopCountries), report);
|
||||
const startingContent: StartingContent = { reserveVehicles: datasets.load(reserveVehicles) };
|
||||
const startingContent: StartingContent = { reserveVehicles: datasets.load(reserveVehicles), branches: datasets.load(shopBranches) };
|
||||
gameFiles.releasePacks();
|
||||
|
||||
const saves = new SaveStore(options.dataFolder, profileUpgrades(startingContent));
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
/**
|
||||
* A new account's profile: Gaijin's own new-account template from the player's game files
|
||||
* (config/default_user.blk), plus the offline starting content (starting-content.ts).
|
||||
* (config/default_user.blk), plus the offline starting content (starting-content.ts) and the
|
||||
* starting money. A new account online starts with 150,000 silver lions and 500 golden
|
||||
* eagles (local verification); the template has none.
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { setGoldenEagles, setSilverLions, type Balance } from './profile-currency.ts';
|
||||
import { applyStartingContent, type StartingContent } from './starting-content.ts';
|
||||
|
||||
export const STARTING_BALANCE: Balance = { silverLions: 150_000, goldenEagles: 500 };
|
||||
|
||||
export function newProfile(template: BlkBlock, content: StartingContent): BlkBlock {
|
||||
const profile = structuredClone(template);
|
||||
applyStartingContent(profile, content);
|
||||
setSilverLions(profile, STARTING_BALANCE.silverLions);
|
||||
setGoldenEagles(profile, STARTING_BALANCE.goldenEagles);
|
||||
return profile;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* The player's money in the profile (implementation notes; read by aces.exe 2.61.0.37
|
||||
* 0x919060):
|
||||
*
|
||||
* warpointsPos:i64 silver lions earned in total
|
||||
* warpointsNeg:i64 silver lions spent in total
|
||||
* goldBalance:i golden eagles (read and written as a 32-bit integer, 0x91b570 / 0x91b5cb)
|
||||
*
|
||||
* The silver lion balance is warpointsPos - warpointsNeg; setting it keeps the amount spent
|
||||
* and adjusts the amount earned.
|
||||
*/
|
||||
import { findParam, setParam, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const EARNED = 'warpointsPos';
|
||||
const SPENT = 'warpointsNeg';
|
||||
const GOLD = 'goldBalance';
|
||||
const MAX_GOLD = 0x7fffffff;
|
||||
|
||||
export interface Balance {
|
||||
readonly silverLions: number;
|
||||
readonly goldenEagles: number;
|
||||
}
|
||||
|
||||
export function balanceOf(profile: BlkBlock): Balance {
|
||||
return { silverLions: numberParam(profile, EARNED) - numberParam(profile, SPENT), goldenEagles: numberParam(profile, GOLD) };
|
||||
}
|
||||
|
||||
export function setSilverLions(profile: BlkBlock, amount: number): void {
|
||||
requireAmount(amount, Number.MAX_SAFE_INTEGER);
|
||||
setParam(profile, EARNED, { type: 'int64', value: BigInt(amount + numberParam(profile, SPENT)) });
|
||||
}
|
||||
|
||||
export function setGoldenEagles(profile: BlkBlock, amount: number): void {
|
||||
requireAmount(amount, MAX_GOLD);
|
||||
setParam(profile, GOLD, { type: 'int', value: amount });
|
||||
}
|
||||
|
||||
function numberParam(profile: BlkBlock, name: string): number {
|
||||
const value = findParam(profile, name)?.value;
|
||||
if (value?.type === 'int64') return Number(value.value);
|
||||
return value?.type === 'int' ? value.value : 0;
|
||||
}
|
||||
|
||||
function requireAmount(amount: number, max: number): void {
|
||||
if (!Number.isSafeInteger(amount) || amount < 0 || amount > max) throw new RangeError(`amount out of range: ${amount}`);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* The ranks open for research, per country and vehicle type.
|
||||
*
|
||||
* eras{
|
||||
* Aircraft_country_usa:i=1
|
||||
* Tank_country_germany:i=1
|
||||
* }
|
||||
*
|
||||
* Read and written by the client's profile serializer (aces.exe 2.61.0.37 0x919060, from
|
||||
* 0x921b86): for each vehicle type it builds the parameter name "<type>_<country>" from the
|
||||
* table at 0x72b6d58 (Aircraft, Tank, Ship, Helicopter, Boat, Human, Transport) and keeps an
|
||||
* integer, the highest rank open. The stock tech tree greys out and locks every rank above it
|
||||
* (gui.vromfs.bin scripts/shop/shop.nut, is_era_available).
|
||||
*
|
||||
* The tech-tree branch names of config/shop.blk map to these types as the stock scripts pair
|
||||
* them (scripts/unit/unitTypesList.nut armyId).
|
||||
*/
|
||||
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const ERAS = 'eras';
|
||||
|
||||
const ERA_TYPE_OF_BRANCH: Readonly<Record<string, string>> = {
|
||||
aviation: 'Aircraft',
|
||||
army: 'Tank',
|
||||
ships: 'Ship',
|
||||
helicopters: 'Helicopter',
|
||||
boats: 'Boat',
|
||||
};
|
||||
|
||||
/** The rank open for research in a country's branch; 0 when none is. */
|
||||
export function openRank(profile: BlkBlock, country: string, branch: string): number {
|
||||
const eras = findBlock(profile, ERAS);
|
||||
const value = eras && findParam(eras, eraName(country, branch))?.value;
|
||||
return value?.type === 'int' ? value.value : 0;
|
||||
}
|
||||
|
||||
/** Open the branch up to the rank; a higher rank already open stays open. */
|
||||
export function openRanksUpTo(profile: BlkBlock, country: string, branch: string, rank: number): void {
|
||||
if (openRank(profile, country, branch) >= rank) return;
|
||||
setParam(ensureBlock(profile, ERAS), eraName(country, branch), { type: 'int', value: rank });
|
||||
}
|
||||
|
||||
function eraName(country: string, branch: string): string {
|
||||
const type = ERA_TYPE_OF_BRANCH[branch];
|
||||
if (!type) throw new Error(`unknown tech-tree branch: ${branch}`);
|
||||
return `${type}_${country}`;
|
||||
}
|
||||
@@ -1,14 +1,18 @@
|
||||
/**
|
||||
* The save format's upgrade steps (saves/save-upgrades.ts), in version order. A step is
|
||||
* never changed once released; a later change to saves adds a new step.
|
||||
* The save format's upgrade steps (saves/save-upgrades.ts), in version order. A later change
|
||||
* to what saves hold adds a new step; released steps are not removed.
|
||||
*/
|
||||
import { SaveUpgrades } from '../saves/save-upgrades.ts';
|
||||
import { applyStartingContent, type StartingContent } from './starting-content.ts';
|
||||
|
||||
export function profileUpgrades(content: StartingContent): SaveUpgrades {
|
||||
// Applying the starting content is idempotent, so each step brings the save up to the
|
||||
// starting content of this release.
|
||||
const addStartingContent = (profile: Parameters<typeof applyStartingContent>[0]): void => applyStartingContent(profile, content);
|
||||
return new SaveUpgrades([
|
||||
// 1 -> 2: the starting content (reserve vehicles of every branch, completed
|
||||
// difficulty-gating tutorials) for saves made before new accounts had it.
|
||||
(profile) => applyStartingContent(profile, content),
|
||||
// 1 -> 2: reserve vehicles of every branch, completed difficulty-gating tutorials.
|
||||
addStartingContent,
|
||||
// 2 -> 3: rank I open in every branch.
|
||||
addStartingContent,
|
||||
]);
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
/**
|
||||
* What every account starts with besides Gaijin's new-account template
|
||||
* (config/default_user.blk), which owns only reserve aircraft.
|
||||
* (config/default_user.blk), which owns only reserve aircraft and opens no rank.
|
||||
*
|
||||
* - Every reserve vehicle of every country and branch (aircraft, ground vehicles, boats,
|
||||
* ships), as accounts have them online. The stock first-choice window and the slotbar
|
||||
* only offer reserve vehicles the player owns (scripts/slotbar/slotbarStateData.nut
|
||||
* checkReserveUnit: isBought), so without them a new player only has aircraft.
|
||||
* - Rank I open for research in every country's branches (profile-eras.ts), as online;
|
||||
* without it the whole tech tree is locked (local verification). Higher ranks open through
|
||||
* research.
|
||||
* - The base tutorials that gate a difficulty count as completed on every difficulty, so no
|
||||
* game mode asks for a tutorial first (user quotes 87, 92; the tutorials stay playable).
|
||||
* The stock rule (gui.vromfs.bin scripts/tutorials/tutorialsState.nut isDiffUnlocked)
|
||||
@@ -16,21 +19,28 @@
|
||||
* block "training").
|
||||
*
|
||||
* Applying it again changes nothing, so it also brings older saves up to date
|
||||
* (profile-upgrades.ts).
|
||||
* (profile-upgrades.ts). The starting money is only for new accounts (new-profile.ts).
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import type { ReserveVehicle } from '../game-data/datasets/reserve-vehicles.ts';
|
||||
import type { ShopBranches } from '../game-data/datasets/shop-branches.ts';
|
||||
import { openRanksUpTo } from './profile-eras.ts';
|
||||
import { addOwnedVehicle } from './profile-hangar.ts';
|
||||
import { recordMissionCompleted } from './profile-mission-progress.ts';
|
||||
|
||||
const DIFFICULTY_GATING_TUTORIALS = ['tutorial/tutorialB_takeoff_and_landing'] as const;
|
||||
const HIGHEST_DIFFICULTY = 2;
|
||||
const FIRST_RANK = 1;
|
||||
|
||||
export interface StartingContent {
|
||||
readonly reserveVehicles: readonly ReserveVehicle[];
|
||||
readonly branches: ShopBranches;
|
||||
}
|
||||
|
||||
export function applyStartingContent(profile: BlkBlock, content: StartingContent): void {
|
||||
for (const vehicle of content.reserveVehicles) addOwnedVehicle(profile, vehicle.name);
|
||||
for (const [country, branches] of Object.entries(content.branches)) {
|
||||
for (const branch of branches) openRanksUpTo(profile, country, branch, FIRST_RANK);
|
||||
}
|
||||
for (const tutorial of DIFFICULTY_GATING_TUTORIALS) recordMissionCompleted(profile, tutorial, HIGHEST_DIFFICULTY);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Development entry point for editing a save (the save editor of docs/implementation notes
|
||||
* section A; the launcher will call the same profile functions).
|
||||
*
|
||||
* node packages/local-service/src/save-cli.ts --game <game folder> --data <data folder>
|
||||
* --player <login or user id> [--silver <n>] [--gold <n>]
|
||||
*
|
||||
* Without --silver / --gold it only prints the balance. The edit is written to the save; the
|
||||
* game shows it after its next profile update (any action, or signing in again).
|
||||
*/
|
||||
import { parseArgs } from 'node:util';
|
||||
import { AccountStore } from './accounts/account-store.ts';
|
||||
import { DatasetCache } from './game-data/datasets/dataset-cache.ts';
|
||||
import { reserveVehicles } from './game-data/datasets/reserve-vehicles.ts';
|
||||
import { shopBranches } from './game-data/datasets/shop-branches.ts';
|
||||
import { GameFiles } from './game-data/game-files.ts';
|
||||
import { PlayerProfiles } from './profile/player-profiles.ts';
|
||||
import { balanceOf, setGoldenEagles, setSilverLions } from './profile/profile-currency.ts';
|
||||
import { profileUpgrades } from './profile/profile-upgrades.ts';
|
||||
import type { StartingContent } from './profile/starting-content.ts';
|
||||
import { SaveStore } from './saves/save-store.ts';
|
||||
|
||||
function main(): number {
|
||||
const { values } = parseArgs({
|
||||
options: {
|
||||
game: { type: 'string' },
|
||||
data: { type: 'string' },
|
||||
player: { type: 'string' },
|
||||
silver: { type: 'string' },
|
||||
gold: { type: 'string' },
|
||||
},
|
||||
});
|
||||
if (!values.game || !values.data || !values.player) {
|
||||
console.error('usage: save-cli.ts --game <game folder> --data <data folder> --player <login or user id> [--silver <n>] [--gold <n>]');
|
||||
return 2;
|
||||
}
|
||||
const silver = optionalAmount(values.silver);
|
||||
const gold = optionalAmount(values.gold);
|
||||
if (silver === null || gold === null) {
|
||||
console.error('--silver and --gold take a whole number of 0 or more');
|
||||
return 2;
|
||||
}
|
||||
|
||||
const accounts = new AccountStore(values.data);
|
||||
const account = accounts.byLogin(values.player) ?? accounts.byUserId(values.player);
|
||||
if (!account) {
|
||||
console.error(`no player "${values.player}" in ${values.data}`);
|
||||
return 1;
|
||||
}
|
||||
const gameFiles = new GameFiles(values.game);
|
||||
const datasets = new DatasetCache(values.data, gameFiles, () => {});
|
||||
const startingContent: StartingContent = { reserveVehicles: datasets.load(reserveVehicles), branches: datasets.load(shopBranches) };
|
||||
const profiles = new PlayerProfiles(new SaveStore(values.data, profileUpgrades(startingContent)), gameFiles, startingContent);
|
||||
|
||||
const profile = silver === undefined && gold === undefined
|
||||
? profiles.profileOf(account.userId)
|
||||
: profiles.update(account.userId, (saved) => {
|
||||
if (silver !== undefined) setSilverLions(saved, silver);
|
||||
if (gold !== undefined) setGoldenEagles(saved, gold);
|
||||
});
|
||||
const balance = balanceOf(profile);
|
||||
console.log(`${account.login} (${account.userId}): ${balance.silverLions} silver lions, ${balance.goldenEagles} golden eagles`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** undefined when not given, null when not a valid amount. */
|
||||
function optionalAmount(text: string | undefined): number | undefined | null {
|
||||
if (text === undefined) return undefined;
|
||||
return /^\d+$/.test(text) && Number.isSafeInteger(Number(text)) ? Number(text) : null;
|
||||
}
|
||||
|
||||
process.exitCode = main();
|
||||
Reference in new issue
Block a user