refactor(repo)!: move apps, shared packages, and patch definitions

Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:

  apps/server        the local server (was packages/local-service),
                     package @wto/server
  packages/patcher   builds the game copy (was packages/build),
                     package @wto/patcher
  patches/exe        exe patch definitions (was exe-patches)
  patches/gui        GUI script patches (was gui-patches)

Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".

The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.

The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.


Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.

BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
This commit is contained in:
N0VAN0M4LY committed 2026-11-29 03:20:54 +08:00
1 parent 9c813ccf7d
commit 930ea07630
476 files changed
+275 -251

No files matched your search

@@ -0,0 +1,152 @@
/**
* Decorator coupons (skins, decals, attachables), unlock/profile-icon coupons, and hidden
* workshop stub itemdefs.
*/
import type {
ExternalItemSources,
MarketplaceDecorCoupon,
MarketplaceUnlockCoupon,
} from '../../game-data/datasets/external-item-sources.ts';
import {
makeLocalizedItemDef,
QUALITY_COLORS,
type CouponAction,
type LocalizedItemDef,
type MarketplaceListing,
} from '../itemdef-types.ts';
import { cosmeticCouponPrice, type MarketplaceTuning } from '../marketplace-tuning.ts';
const ICON_BY_KIND = {
skin: '!#ui/gameuiskin#item_type_skin.svg',
decal: '!#ui/gameuiskin#item_type_decal.svg',
attachable: '!#ui/gameuiskin#item_type_attachable.svg',
} as const;
const LABEL_ZH_BY_KIND = {
skin: '涂装兑换券',
decal: '贴花兑换券',
attachable: '3D 装饰挂件兑换券',
} as const;
export interface CosmeticCouponBuildResult {
readonly defs: readonly LocalizedItemDef[];
readonly coupons: ReadonlyArray<readonly [number, CouponAction]>;
readonly listings: readonly MarketplaceListing[];
/** Sorted ascending by itemdefId per category for deterministic chest selection. */
readonly skinCouponIds: readonly number[];
readonly decalCouponIds: readonly number[];
readonly attachableCouponIds: readonly number[];
readonly workshopStubs: readonly LocalizedItemDef[];
}
export function buildCosmeticCoupons(sources: ExternalItemSources, tuning: MarketplaceTuning): CosmeticCouponBuildResult {
const defs: LocalizedItemDef[] = [];
const coupons: Array<readonly [number, CouponAction]> = [];
const listings: MarketplaceListing[] = [];
const skinCouponIds: number[] = [];
const decalCouponIds: number[] = [];
const attachableCouponIds: number[] = [];
const sortedDecors = [...sources.decorCoupons].sort((a, b) => a.itemdefId - b.itemdefId);
for (const decor of sortedDecors) {
const built = buildSingleDecorCoupon(decor, tuning);
defs.push(built.def);
coupons.push([decor.itemdefId, built.action]);
listings.push(built.listing);
if (decor.kind === 'skin') skinCouponIds.push(decor.itemdefId);
else if (decor.kind === 'decal') decalCouponIds.push(decor.itemdefId);
else attachableCouponIds.push(decor.itemdefId);
}
const sortedUnlocks = [...sources.unlockCoupons].sort((a, b) => a.itemdefId - b.itemdefId);
for (const unlock of sortedUnlocks) {
const built = buildSingleUnlockCoupon(unlock, tuning);
defs.push(built.def);
coupons.push([unlock.itemdefId, built.action]);
listings.push(built.listing);
}
const workshopStubs = [...sources.workshopItemdefIds]
.sort((a, b) => a - b)
.map((workshopId) => makeLocalizedItemDef(workshopId, {
type: 'item',
marketable: false,
item_quality: 1,
tags: 'type:craft_part;devItem:yes;hideDesc:yes',
icon_url: '!#ui/gameuiskin#item_type_craftpart.svg',
}, { en: `Workshop Component #${workshopId}`, zh: `工坊组件 #${workshopId}` }, { en: '', zh: '' }));
return { defs, coupons, listings, skinCouponIds, decalCouponIds, attachableCouponIds, workshopStubs };
}
function buildSingleDecorCoupon(decor: MarketplaceDecorCoupon, tuning: MarketplaceTuning): {
readonly def: LocalizedItemDef;
readonly action: CouponAction;
readonly listing: MarketplaceListing;
} {
const { gjnCents, quality } = cosmeticCouponPrice(tuning, decor.kind, decor.resourceKey);
const color = QUALITY_COLORS[quality] ?? '';
const hashName = `${decor.kind}_${decor.itemdefId}`;
const def = makeLocalizedItemDef(decor.itemdefId, {
type: 'item',
marketable: true,
market_hash_name: hashName,
item_quality: quality,
name_color: color,
tags: `type:${decor.kind}`,
meta: `resource:t="${decor.resourceKey}"\nresourceType:t="${decor.kind}"`,
icon_url: ICON_BY_KIND[decor.kind],
}, decor.name, {
en: `Coupon for ${decor.kind}: ${decor.name.en}.`,
zh: `${LABEL_ZH_BY_KIND[decor.kind]}:${decor.name.zh}。`,
});
const action: CouponAction = { kind: 'decor', decorKind: decor.kind, resourceKey: decor.resourceKey };
const listing: MarketplaceListing = {
itemdefId: decor.itemdefId,
marketHashName: hashName,
category: decor.kind,
gjnCostCents: gjnCents,
quality,
nameColor: color,
title: decor.name,
subtitle: { en: `${decor.kind} coupon`, zh: LABEL_ZH_BY_KIND[decor.kind] },
targetKey: decor.resourceKey,
};
return { def, action, listing };
}
function buildSingleUnlockCoupon(unlock: MarketplaceUnlockCoupon, tuning: MarketplaceTuning): {
readonly def: LocalizedItemDef;
readonly action: CouponAction;
readonly listing: MarketplaceListing;
} {
const { gjnCents, quality } = cosmeticCouponPrice(tuning, 'unlock', unlock.unlockId);
const color = QUALITY_COLORS[quality] ?? '';
const hashName = `unlock_${unlock.itemdefId}`;
const def = makeLocalizedItemDef(unlock.itemdefId, {
type: 'item',
marketable: true,
market_hash_name: hashName,
item_quality: quality,
name_color: color,
tags: 'type:unlock',
meta: `unlock:t="${unlock.unlockId}"`,
icon_url: '!#ui/gameuiskin#item_type_unlock.svg',
}, unlock.name, {
en: `Coupon for unlock: ${unlock.name.en}.`,
zh: `头像/收藏解锁兑换券:${unlock.name.zh}。`,
});
const action: CouponAction = { kind: 'unlock', unlockId: unlock.unlockId };
const listing: MarketplaceListing = {
itemdefId: unlock.itemdefId,
marketHashName: hashName,
category: 'unlock',
gjnCostCents: gjnCents,
quality,
nameColor: color,
title: unlock.name,
subtitle: { en: 'Profile icon / unlock coupon', zh: '头像与解锁兑换券' },
targetKey: unlock.unlockId,
};
return { def, action, listing };
}
@@ -0,0 +1,110 @@
/**
* Marketplace vehicle coupon definitions (`shop.blk` `marketplaceItemdefId`, 233 vehicles in
* 2.61.0.37; implementation notes).
*/
import type { LocalizedText } from '../../game-data/datasets/unit-names.ts';
import type { CatalogueVehicle } from '../../game-data/datasets/vehicle-catalogue.ts';
import { vehicleTypeOfClass } from '../../research/vehicle-types.ts';
import {
makeLocalizedItemDef,
QUALITY_COLORS,
type CouponAction,
type LocalizedItemDef,
type MarketplaceListing,
} from '../itemdef-types.ts';
import { vehicleCouponPrice, type MarketplaceTuning } from '../marketplace-tuning.ts';
export interface VehicleCouponBuildResult {
readonly defs: readonly LocalizedItemDef[];
readonly coupons: ReadonlyArray<readonly [number, CouponAction]>;
readonly listings: readonly MarketplaceListing[];
/** Marketplace vehicles sorted deterministically by (rank, country, name). */
readonly sortedVehicles: readonly CatalogueVehicle[];
}
export function buildVehicleCoupons(
vehicles: readonly CatalogueVehicle[],
unitNames: Readonly<Record<string, LocalizedText>>,
tuning: MarketplaceTuning,
): VehicleCouponBuildResult {
const defs: LocalizedItemDef[] = [];
const coupons: Array<readonly [number, CouponAction]> = [];
const listings: MarketplaceListing[] = [];
const sortedVehicles = vehicles
.filter((vehicle) => vehicle.marketplaceItemdefId !== undefined)
.sort((a, b) => (a.rank - b.rank) || a.country.localeCompare(b.country) || a.name.localeCompare(b.name));
for (const vehicle of sortedVehicles) {
const id = vehicle.marketplaceItemdefId!;
const unitTitle = unitNames[vehicle.name] ?? { en: vehicle.name, zh: vehicle.name };
const { gjnCents: gjnCostCents, quality } = vehicleCouponPrice(tuning, vehicle.name, vehicle.rank);
const color = QUALITY_COLORS[quality] ?? '';
const tagType = unitClassTag(vehicle.unitClass);
defs.push(makeLocalizedItemDef(id, {
type: 'item',
marketable: true,
market_hash_name: vehicle.name,
item_quality: quality,
name_color: color,
tags: `type:${tagType}`,
meta: `unit:t="${vehicle.name}"`,
icon_url: '!#ui/gameuiskin#item_type_blueprints.svg',
icon_url_large: '!#ui/gameuiskin#item_type_blueprints.svg',
}, unitTitle, {
en: `Exchangeable coupon for ${unitTitle.en} (Rank ${vehicle.rank}).`,
zh: `可兑换载具券:${unitTitle.zh}(${vehicle.rank} 级)。`,
}));
coupons.push([id, { kind: 'vehicle', unitName: vehicle.name, parts: vehicle.parts }]);
listings.push({
itemdefId: id,
marketHashName: vehicle.name,
category: 'vehicle',
gjnCostCents,
quality,
nameColor: color,
title: unitTitle,
subtitle: { en: `Rank ${vehicle.rank} ${tagType}`, zh: `${vehicle.rank} 级载具兑换券` },
country: vehicle.country,
unitClass: marketUnitClassOf(vehicle.unitClass),
rank: vehicle.rank,
targetKey: vehicle.name,
});
}
return { defs, coupons, listings, sortedVehicles };
}
function unitClassTag(unitClass: string): string {
switch (vehicleTypeOfClass(unitClass)) {
case 'Aircraft':
return 'aircraft';
case 'Helicopter':
return 'helicopter';
case 'Tank':
return 'tank';
case 'Ship':
case 'Boat':
return 'ship';
default:
return 'tank';
}
}
function marketUnitClassOf(unitClass: string): string {
switch (vehicleTypeOfClass(unitClass)) {
case 'Aircraft':
return 'aircraft';
case 'Helicopter':
return 'helicopter';
case 'Tank':
return 'tank';
case 'Ship':
return 'ship';
case 'Boat':
return 'boat';
default:
return 'tank';
}
}