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

+91
View File
@@ -0,0 +1,91 @@
/**
* Files shared by the local web pages, under /_wto/ui/:
* common.css, common.js layout and helpers both pages load
* official-images.json official image paths (static-ggc.gaijin.net) per vehicle /
* decor / item key, from the official market snapshot
*
* labels.json the game's country and vehicle type names (ui-labels dataset)
* vehicle/<vehicle>.svg the game's silhouette icon of a vehicle (web-icons dataset)
* flag/<country>.svg the game's country flag (web-icons dataset)
* official-store-media.json public store cover, screenshot and video paths by product
* store-media/<path> cached public store media from the manifest
* art/<kind>/<key> game artwork for vehicles, products and coupons
* asset-pack/<path> the player's own optional copy of official images, made by
* asset-pack-cli.ts into <data folder>/asset-pack/
* Icons and names come from the player's game files at start-up; nothing of Gaijin's is shipped.
* Store media prefers the asset pack and the service cache before fetching the public file.
*/
import { existsSync, readFileSync } from 'node:fs';
import { resolve, sep } from 'node:path';
import type { WebIcons } from '../game-data/datasets/web-icons.ts';
import type { UiLabels } from '../game-data/datasets/ui-labels.ts';
import type { Service, ServiceRequest, ServiceResponse } from '../transport/exchange.ts';
import type { GameArtwork } from './game-artwork.ts';
import { StoreMediaCache, STORE_MEDIA_PREFIX } from './store-media-cache.ts';
import { contentResponse, createStaticWebSite, notFound } from './web-helpers.ts';
const PREFIX = '/_wto/ui/';
const SHARED_FILES = createStaticWebSite(new URL('./web/', import.meta.url), ['common.css', 'common.js', 'official-images.json', 'official-store-media.json']);
const ICON_PATH = /^(vehicle|flag)\/([^/]+)\.svg$/;
const ART_PATH = /^art\/(vehicle|group|product|skin|decal|attachable|unlock)\/([^/]+)$/;
const PACK_PREFIX = 'asset-pack/';
const PACK_TYPES: Readonly<Record<string, string>> = { '.png': 'image/png', '.jpg': 'image/jpeg', '.webp': 'image/webp', '.json': 'application/json; charset=utf-8' };
export class WebUiService implements Service {
readonly name = 'web-ui';
readonly #icons: WebIcons;
readonly #labels: string;
readonly #packDir: string;
readonly #artwork: GameArtwork;
readonly #storeMedia: StoreMediaCache;
constructor(icons: WebIcons, labels: UiLabels, dataFolder: string, artwork: GameArtwork) {
this.#icons = icons;
this.#labels = JSON.stringify(labels);
this.#packDir = resolve(dataFolder, 'asset-pack');
this.#artwork = artwork;
this.#storeMedia = new StoreMediaCache(dataFolder);
}
accepts(request: ServiceRequest): boolean {
return request.originalHost === undefined && request.method === 'GET' && request.path.startsWith(PREFIX);
}
handle(request: ServiceRequest): ServiceResponse | Promise<ServiceResponse> {
const subPath = request.path.slice(PREFIX.length);
if (subPath === 'labels.json') return contentResponse(subPath, this.#labels, 'web ui: labels');
if (subPath.startsWith(STORE_MEDIA_PREFIX)) return this.#storeMedia.serve(subPath.slice(STORE_MEDIA_PREFIX.length), request.headers.range);
if (subPath.startsWith(PACK_PREFIX)) return this.#packFile(subPath.slice(PACK_PREFIX.length));
const art = ART_PATH.exec(subPath);
if (art) return this.#gamePicture(art[1]!, art[2]!);
const icon = ICON_PATH.exec(subPath);
if (icon) {
const [, kind, name] = icon;
const table = kind === 'vehicle' ? this.#icons.vehicles : this.#icons.flags;
const svg = Object.hasOwn(table, name!) ? table[name!] : undefined;
return svg ? contentResponse(subPath, svg, `web ui: ${kind} icon`) : notFound(`web ui: no ${kind} icon ${name}`);
}
return SHARED_FILES.serve(subPath, 'web ui') ?? notFound(`web ui 404: ${subPath}`);
}
#gamePicture(kind: string, encodedKey: string): ServiceResponse {
let key: string;
try {
key = decodeURIComponent(encodedKey);
} catch {
return notFound('web ui: invalid artwork key');
}
const picture = this.#artwork.image(kind, key);
return picture ? contentResponse(picture.filename, picture.bytes, 'web ui: game ' + kind + ' artwork')
: notFound('web ui: no game artwork for ' + kind + '/' + key);
}
/** A file of the player's asset pack; only image/json files inside the pack folder. */
#packFile(relative: string): ServiceResponse {
const decoded = decodeURIComponent(relative);
const full = resolve(this.#packDir, decoded);
const type = PACK_TYPES[decoded.slice(decoded.lastIndexOf('.')).toLowerCase()];
if (!type || !full.startsWith(this.#packDir + sep) || !existsSync(full)) return notFound(`asset pack: no ${decoded}`);
return { status: 200, headers: { 'content-type': type, 'cache-control': 'max-age=86400' }, body: readFileSync(full), logNotes: { summary: `asset pack: ${decoded}` } };
}
}