chore(battle): snapshot the LocalMP rework baseline

Records the uncommitted battle-session work exactly as it was left
(local service matchmaking, settlement, chat, native LocalMP hooks,
battle gui/exe patches) so the following review and rework commits
show every correction as a diff against this state.

This commit is not reviewed and is known to be incomplete: in-game
testing reported wrong settlement rewards, single-country teams,
missing random/fixed supplement slots, misattributed hit messages and
other regressions. Do not merge this branch before the rework lands.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 03:15:47 +08:00
1 parent 5c9204c031
commit b260d2899e
97 files changed
+7676 -396

No files matched your search

@@ -1,10 +1,11 @@
/**
* Crew skills, skill points and specializations inside a crew block:
* Crew skills, skill points, specializations, and Expert-to-Ace RP inside a crew block:
*
* crews{
* c0{
* country:t="country_usa"
* aircrafts{ trained:t="us_m2a4" spec:i=1 trained:t="us_m22_locust" spec:i=0 current:t="us_m2a4" }
* expertToAceProgress{ us_m2a4:i=12000 }
* commander{ crewMember_0{ eyesight:i64=5 field_repair:i64=2 } }
* skillPointsStat:i64=0
* skillPointsManualChanges:i64=150000
@@ -15,7 +16,8 @@
* kept times 100: the client shows (skillPointsStat + skillPointsManualChanges) / 100
* (get_crew_info, 0x179dbac); the local service books what the player buys and spends in
* skillPointsManualChanges. Every trained vehicle is followed by its spec (0 none, 1 expert,
* 2 ace), as the client writes them (0x939ed0..0x939f55).
* 2 ace), as the client writes them (0x939ed0..0x939f55), and per-vehicle Expert-to-Ace RP sits
* in expertToAceProgress/<vehicle>:i (0x93b0d0..0x93b4eb).
*/
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock, type BlkParam } from '@wto/blk';
@@ -26,6 +28,7 @@ const POINTS_SCALE = 100;
const VEHICLES = 'aircrafts';
const TRAINED = 'trained';
const SPEC = 'spec';
const ACE_PROGRESS = 'expertToAceProgress';
export function skillLevel(crew: BlkBlock, page: string, skill: string): number {
const pageBlock = findBlock(crew, page);
@@ -78,6 +81,18 @@ export function trainedPairs(crew: BlkBlock): { vehicle: string; spec: number }[
return pairs;
}
export function expertToAceRp(crew: BlkBlock, vehicle: string): number {
const progress = findBlock(crew, ACE_PROGRESS);
return progress ? intOf(progress, vehicle) : 0;
}
export function addExpertToAceRp(crew: BlkBlock, vehicle: string, deltaRp: number, maxRp: number): void {
if (deltaRp <= 0 || maxRp <= 0) return;
const current = expertToAceRp(crew, vehicle);
const next = Math.min(maxRp, Math.max(0, current + Math.trunc(deltaRp)));
if (next !== current) setParam(ensureBlock(crew, ACE_PROGRESS), vehicle, { type: 'int', value: next });
}
function intOf(block: BlkBlock, name: string): number {
const value = findParam(block, name)?.value;
if (value?.type === 'int64') return Number(value.value);
@@ -33,6 +33,38 @@ export function crewCountOf(profile: BlkBlock, country: string): number {
return (profile.blocks.find((block) => block.name === CREWS)?.blocks ?? []).filter((crew) => crewCountry(crew) === country).length;
}
/** Non-empty vehicles currently slotted in the country's crews, in profile order. */
export function crewVehiclesOfCountry(profile: BlkBlock, country: string): string[] {
return allCrews(profile)
.filter((crew) => crewCountry(crew) === country)
.flatMap((crew) => {
const current = crew.blocks.find((block) => block.name === VEHICLES)?.params.find((param) => param.name === CURRENT)?.value;
return current?.type === 'string' && current.value.length > 0 ? [current.value] : [];
});
}
/** Vehicle slotted in the country's `slotIndex`-th crew (`idInCountry`), if non-empty. */
export function crewSlotVehicleOfCountry(profile: BlkBlock, country: string, slotIndex: number): string | undefined {
if (!Number.isInteger(slotIndex) || slotIndex < 0) return undefined;
const crew = allCrews(profile).filter((entry) => crewCountry(entry) === country)[slotIndex];
const current = crew?.blocks.find((block) => block.name === VEHICLES)?.params.find((param) => param.name === CURRENT)?.value;
return current?.type === 'string' && current.value.length > 0 ? current.value : undefined;
}
/** Crew block in `country` currently equipping `vehicle` (or trained for it as fallback). */
export function crewForVehicleInCountry(profile: BlkBlock, country: string, vehicle: string): BlkBlock | undefined {
const crews = allCrews(profile).filter((entry) => crewCountry(entry) === country);
const slotted = crews.find((entry) => {
const current = entry.blocks.find((block) => block.name === VEHICLES)?.params.find((param) => param.name === CURRENT)?.value;
return current?.type === 'string' && current.value === vehicle;
});
if (slotted) return slotted;
return crews.find((entry) =>
(entry.blocks.find((block) => block.name === VEHICLES)?.params ?? []).some(
(param) => param.name === TRAINED && param.value.type === 'string' && param.value.value === vehicle,
));
}
/** Add an empty crew for the country, numbered after every existing crew; returns its id. */
export function addCrew(profile: BlkBlock, country: string): number {
const crews = ensureBlock(profile, CREWS);
@@ -0,0 +1,96 @@
/**
* Cross-branch research-point redirection in profile.blk ("Research helicopters by playing
* ground vehicles", gui.vromfs.bin scripts/shop/shop.nut:2341-2354).
*
* Profile contract (verified in aces.exe 2.61.0.37 0x930150..0x93082a & 0x903ca0):
* researchUnits{
* country_usa{
* destTypeRPTank:t="Helicopter"
* }
* }
* - Reader (0x93020e..0x930247): reads "destTypeRP<SrcType>" inside researchUnits.<country>
* and maps it against VEHICLE_TYPES (0..6); missing or unrecognized values become -1
* (ES_UNIT_TYPE_INVALID), exposed to Squirrel by getDestinationRPUnitType (0x15532f0).
* - Writer (0x9307eb..0x93082a): writes "destTypeRP<SrcType>" only when 0 <= destType <= 6
* and omits the parameter when disabled (-1).
*/
import { ensureBlock, findBlock, type BlkBlock } from '@wto/blk';
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
import type { TechTree } from '../research/tech-tree.ts';
import { VEHICLE_TYPES, vehicleTypeById, type VehicleType } from '../research/vehicle-types.ts';
import { removeParam, stringField } from './blk-fields.ts';
import { researchTarget } from './profile-research-targets.ts';
const RESEARCH_UNITS = 'researchUnits';
const DEST_TYPE_PREFIX = 'destTypeRP';
const INVALID_UNIT_TYPE = -1;
export type VehicleDomain = VehicleType;
const VALID_DOMAINS: ReadonlySet<string> = new Set<string>(VEHICLE_TYPES);
export function destinationRpDomain(
profile: BlkBlock,
country: string,
sourceDomain: VehicleDomain,
): VehicleDomain | undefined {
const countryBlock = findBlock(findBlock(profile, RESEARCH_UNITS) ?? { name: '', params: [], blocks: [] }, country);
const raw = stringField(countryBlock, `${DEST_TYPE_PREFIX}${sourceDomain}`);
if (!raw || !VALID_DOMAINS.has(raw) || raw === sourceDomain) return undefined;
return raw as VehicleDomain;
}
export function setDestinationRpDomain(
profile: BlkBlock,
country: string,
sourceDomain: VehicleDomain,
destinationDomain: VehicleDomain | undefined,
): void {
const countryBlock = ensureBlock(ensureBlock(profile, RESEARCH_UNITS), country);
const paramName = `${DEST_TYPE_PREFIX}${sourceDomain}`;
if (!destinationDomain || destinationDomain === sourceDomain) {
removeParam(countryBlock, paramName);
return;
}
removeParam(countryBlock, paramName);
countryBlock.params.push({ name: paramName, value: { type: 'string', value: destinationDomain } });
}
/** Validate and apply cln_set_dest_rp_unit_type (country:t, srcType:i, destType:i). */
export function applySetDestinationRpRule(
profile: BlkBlock,
techTree: TechTree,
country: string,
srcTypeId: number,
destTypeId: number,
): RuleOutcome {
const sourceDomain = vehicleTypeById(srcTypeId);
if (!country || !techTree.hasCountry(country) || !sourceDomain) return refused('BAD_PARAMS');
if (destTypeId === INVALID_UNIT_TYPE) {
setDestinationRpDomain(profile, country, sourceDomain, undefined);
return ACCEPTED;
}
const destinationDomain = vehicleTypeById(destTypeId);
if (!destinationDomain || destinationDomain === sourceDomain) return refused('BAD_PARAMS');
const hasDestinationBranch = techTree.branches().some(
(branch) => branch.country === country && branch.type === destinationDomain,
);
if (!hasDestinationBranch) return refused('NOT_AVAILABLE');
setDestinationRpDomain(profile, country, sourceDomain, destinationDomain);
return ACCEPTED;
}
/**
* Resolve the effective research branch for battle settlement: returns the redirected domain
* (such as 'Helicopter' when playing 'Tank') when configured and that branch still has an
* active currUnit research target, otherwise falls back to sourceDomain.
*/
export function readRedirectedResearchDomain(
profile: BlkBlock,
country: string,
sourceDomain: VehicleDomain,
): VehicleDomain {
const redirected = destinationRpDomain(profile, country, sourceDomain);
if (!redirected) return sourceDomain;
return researchTarget(profile, country, redirected) !== '' ? redirected : sourceDomain;
}
@@ -23,6 +23,12 @@ export function spendFreeResearchPoints(profile: BlkBlock, amount: number): void
setCounter(profile, SPENT, counter(profile, SPENT) + amount);
}
/** Credit convertible (free) research points earned in battle (`experience:i64`). */
export function addFreeResearchPoints(profile: BlkBlock, amount: number): void {
if (!Number.isSafeInteger(amount) || amount < 0) throw new RangeError(`amount out of range: ${amount}`);
if (amount > 0) setCounter(profile, EARNED, counter(profile, EARNED) + amount);
}
/** Make the free research points this amount (the save editor). */
export function setFreeResearchPoints(profile: BlkBlock, amount: number): void {
if (!Number.isSafeInteger(amount) || amount < 0) throw new RangeError(`amount out of range: ${amount}`);
@@ -1,6 +1,6 @@
/**
* The current research target and the just-finished research of each country and vehicle
* type.
* Current research target, just-finished research vehicle, and banked excess RP per country
* and vehicle branch (`aces.exe` `0x930150`):
*
* researchUnits{
* country_usa{
@@ -24,6 +24,7 @@ import { ensureBlock, findBlock, findParam, setParam, type BlkBlock } from '@wto
const RESEARCH_UNITS = 'researchUnits';
const CURRENT = 'currUnit';
const FINISHED = 'prevUnit';
const EXCESS_EXP = 'exp';
export function researchTarget(profile: BlkBlock, country: string, vehicleType: string): string {
return field(profile, country, `${CURRENT}${vehicleType}`);
@@ -41,6 +42,22 @@ export function setFinishedResearch(profile: BlkBlock, country: string, vehicleT
setField(profile, country, `${FINISHED}${vehicleType}`, vehicle);
}
export function branchExcessRp(profile: BlkBlock, country: string, vehicleType: string): number {
const units = findBlock(profile, RESEARCH_UNITS);
const block = units && findBlock(units, country);
const value = block && findParam(block, `${EXCESS_EXP}${vehicleType}`)?.value;
if (value?.type === 'int64') return Math.max(0, Number(value.value));
return value?.type === 'int' ? Math.max(0, value.value) : 0;
}
export function setBranchExcessRp(profile: BlkBlock, country: string, vehicleType: string, amount: number): void {
const clamped = Math.max(0, Math.trunc(amount));
setParam(ensureBlock(ensureBlock(profile, RESEARCH_UNITS), country), `${EXCESS_EXP}${vehicleType}`, {
type: 'int64',
value: BigInt(clamped),
});
}
function field(profile: BlkBlock, country: string, name: string): string {
const units = findBlock(profile, RESEARCH_UNITS);
const block = units && findBlock(units, country);
@@ -12,7 +12,8 @@ const TROPHIES = 'trophies';
const USERLOGS = 'userlogs';
const PURCHASE_RECEIPT = 'purchaseReceipt';
// Registered by the client at 0x1a5569e (2.61.0.37).
// Registered by the client at 0x1a554dc / 0x1a5569e / 0x1a5599b (2.61.0.37).
export const EULT_SESSION_RESULT = 2;
const EULT_BUYENTITLEMENT = 13;
export const EULT_OPEN_TROPHY = 30;
export const EULT_BUY_TROPHY = 20;
@@ -32,6 +33,7 @@ export function incrementTrophyOpenCount(profile: BlkBlock, trophyId: string, de
export interface NewUserLogEntry {
readonly type: number;
readonly timeSec: number;
readonly roomId?: bigint;
readonly bodyParams: readonly BlkParam[];
readonly bodyBlocks?: readonly BlkBlock[];
}
@@ -53,7 +55,7 @@ export function appendUserLog(profile: BlkBlock, entry: NewUserLogEntry): string
params: [
{ name: 'type', value: { type: 'int', value: entry.type } },
{ name: 'time', value: { type: 'int', value: entry.timeSec } },
{ name: 'roomId', value: { type: 'int64', value: 0n } },
{ name: 'roomId', value: { type: 'int64', value: entry.roomId ?? 0n } },
],
blocks: [{
name: 'body',
@@ -1,17 +1,20 @@
/**
* Per-vehicle fields of owned vehicles: hangar{ <vehicle>{ ... } },
* read by name by AircraftInfo::serialize (aces.exe 0x940510). Only the fields the local
* service maintains are handled here:
* investMode:t the modification being researched (empty = none)
* tierNumber:i the highest open modification tier (script is_tier_available)
* spareAircraftsCount:i spares the player has for this vehicle
* Per-vehicle fields of owned vehicles under `hangar{ <vehicle>{ ... } }`, read by name in
* `AircraftInfo::serialize` (`aces.exe` `0x940510`):
* investMode:t the modification currently selected for research (`+0x100`)
* investModePrev:t the modification whose research just finished (`+0x108`)
* tierNumber:i the highest open modification tier
* spareAircraftsCount:i vehicle-specific backups owned
* excessExp:i64 banked modification overflow RP (`+0x70`)
*/
import { findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
const HANGAR = 'hangar';
const RESEARCH_TARGET = 'investMode';
const FINISHED_TARGET = 'investModePrev';
const OPEN_TIER = 'tierNumber';
const SPARES = 'spareAircraftsCount';
const EXCESS_EXP = 'excessExp';
export function moduleResearchTarget(profile: BlkBlock, vehicle: string): string {
const value = fieldOf(profile, vehicle, RESEARCH_TARGET);
@@ -23,6 +26,16 @@ export function setModuleResearchTarget(profile: BlkBlock, vehicle: string, modi
if (entry) setParam(entry, RESEARCH_TARGET, { type: 'string', value: modification });
}
export function finishedModuleResearch(profile: BlkBlock, vehicle: string): string {
const value = fieldOf(profile, vehicle, FINISHED_TARGET);
return value?.type === 'string' ? value.value : '';
}
export function setFinishedModuleResearch(profile: BlkBlock, vehicle: string, modification: string): void {
const entry = vehicleEntry(profile, vehicle);
if (entry) setParam(entry, FINISHED_TARGET, { type: 'string', value: modification });
}
export function setOpenTier(profile: BlkBlock, vehicle: string, tier: number): void {
const entry = vehicleEntry(profile, vehicle);
if (entry) setParam(entry, OPEN_TIER, { type: 'int', value: tier });
@@ -38,6 +51,17 @@ export function setSpareCount(profile: BlkBlock, vehicle: string, count: number)
if (entry) setParam(entry, SPARES, { type: 'int', value: count });
}
export function vehicleExcessRp(profile: BlkBlock, vehicle: string): number {
const value = fieldOf(profile, vehicle, EXCESS_EXP);
if (value?.type === 'int64') return Math.max(0, Number(value.value));
return value?.type === 'int' ? Math.max(0, value.value) : 0;
}
export function setVehicleExcessRp(profile: BlkBlock, vehicle: string, amount: number): void {
const entry = vehicleEntry(profile, vehicle);
if (entry) setParam(entry, EXCESS_EXP, { type: 'int64', value: BigInt(Math.max(0, Math.trunc(amount))) });
}
function fieldOf(profile: BlkBlock, vehicle: string, name: string) {
const entry = vehicleEntry(profile, vehicle);
return entry && findParam(entry, name)?.value;
@@ -0,0 +1,98 @@
/**
* Vehicle wishlist persistence in profile.blk (cln_add_to_wish_list / cln_remove_from_wish_list).
*
* Binary & script contract (verified in aces.exe 2.61.0.37 0x967c30..0x96891b, getWishList
* 0x1553470, and gui.vromfs.bin scripts/wishlist/wishlistManager.nut):
* wishList{
* units{
* us_m1_abrams{
* cmnts:t="optional note"
* ts:i64=1764260000
* }
* }
* }
* - When reading profile.blk (0x967c40..0x967d8a), if top-level "wishList" is absent the client
* returns early without clearing its in-memory wishlist vector ([econ + 0xe868]). Keeping an
* empty wishList { units {} } block on removal ensures 0x967ebd..0x967f19 clears the client's
* vector immediately upon profile sync.
* - Static limits come from char.vromfs.bin config/warpoints.blk: maxWishListSize:i=100 and
* maxWishListCommentSize:i=100 (exposed via getMaxWishListSize 0x1553450 and
* getMaxWishListCommentSize 0x1553460).
*/
import { ensureBlock, findBlock, type BlkBlock, type BlkParam } from '@wto/blk';
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
import type { TechTree } from '../research/tech-tree.ts';
import { int64Field, stringField } from './blk-fields.ts';
import { ownsVehicle } from './profile-hangar.ts';
const WISH_LIST_BLOCK = 'wishList';
const UNITS_BLOCK = 'units';
const COMMENT_PARAM = 'cmnts';
const TIMESTAMP_PARAM = 'ts';
/** Limits defined in char.vromfs.bin config/warpoints.blk (maxWishListSize / maxWishListCommentSize). */
export const DEFAULT_WISHLIST_LIMITS: WishlistLimits = {
maxSize: 100,
maxCommentLength: 100,
};
export interface WishlistLimits {
readonly maxSize: number;
readonly maxCommentLength: number;
}
export interface WishlistEntry {
readonly unit: string;
readonly comment: string;
readonly timestampSec: number;
}
export function readWishlist(profile: BlkBlock): WishlistEntry[] {
const unitsBlock = findBlock(findBlock(profile, WISH_LIST_BLOCK) ?? { name: '', params: [], blocks: [] }, UNITS_BLOCK);
if (!unitsBlock) return [];
return unitsBlock.blocks
.filter((entry) => entry.name.length > 0)
.map((entry) => ({
unit: entry.name,
comment: stringField(entry, COMMENT_PARAM),
timestampSec: Number(int64Field(entry, TIMESTAMP_PARAM, 0n)),
}));
}
export function hasWishlistUnit(profile: BlkBlock, unit: string): boolean {
const unitsBlock = findBlock(findBlock(profile, WISH_LIST_BLOCK) ?? { name: '', params: [], blocks: [] }, UNITS_BLOCK);
return unitsBlock !== undefined && unitsBlock.blocks.some((entry) => entry.name === unit);
}
export function addWishlistUnit(
profile: BlkBlock,
techTree: TechTree,
unit: string,
comment: string,
timestampSec: number,
limits: WishlistLimits = DEFAULT_WISHLIST_LIMITS,
): RuleOutcome {
if (!unit || [...comment].length > limits.maxCommentLength) return refused('BAD_PARAMS');
const vehicle = techTree.vehicle(unit);
if (!vehicle || vehicle.kind === 'part' || vehicle.kind === 'hidden') return refused('BAD_PARAMS');
if (ownsVehicle(profile, unit) || hasWishlistUnit(profile, unit)) return refused('NOT_AVAILABLE');
const unitsBlock = ensureWishlistUnitsBlock(profile);
if (unitsBlock.blocks.length >= limits.maxSize) return refused('NOT_AVAILABLE');
const params: BlkParam[] = [];
if (comment.length > 0) params.push({ name: COMMENT_PARAM, value: { type: 'string', value: comment } });
params.push({ name: TIMESTAMP_PARAM, value: { type: 'int64', value: BigInt(Math.max(0, Math.trunc(timestampSec))) } });
unitsBlock.blocks.push({ name: unit, params, blocks: [] });
return ACCEPTED;
}
export function removeWishlistUnit(profile: BlkBlock, unit: string): RuleOutcome {
if (!unit) return refused('BAD_PARAMS');
const unitsBlock = ensureWishlistUnitsBlock(profile);
unitsBlock.blocks = unitsBlock.blocks.filter((entry) => entry.name !== unit);
return ACCEPTED;
}
function ensureWishlistUnitsBlock(profile: BlkBlock): BlkBlock {
return ensureBlock(ensureBlock(profile, WISH_LIST_BLOCK), UNITS_BLOCK);
}