feat(saves): edit account levels and avatars
Read rank thresholds and available avatar artwork from the selected copy. Persist avatar selections in the player profile and preserve free research points when a level changes.
This commit is contained in:
1 parent
d043a8f0f8
commit
5d1d7001b8
22 files changed
+337
-63
No files matched your search
@@ -111,19 +111,23 @@ class TrackedSource implements DatasetSource {
|
||||
}
|
||||
|
||||
readBlk(pack: GamePackName, path: string): BlkBlock {
|
||||
const gamePack = this.#gameFiles.pack(pack);
|
||||
const sha1 = gamePack.fileDigest(path);
|
||||
if (sha1 === undefined) throw new Error(`${pack} has no file ${path}`);
|
||||
this.#files.set(`${pack}/${path}`, { pack, path, sha1 });
|
||||
return gamePack.readBlk(path);
|
||||
return this.#trackFile(pack, path).readBlk(path);
|
||||
}
|
||||
|
||||
readText(pack: GamePackName, path: string): string {
|
||||
return this.#trackFile(pack, path).readText(path);
|
||||
}
|
||||
|
||||
readBytes(pack: GamePackName, path: string): Uint8Array {
|
||||
return this.#trackFile(pack, path).readBytes(path);
|
||||
}
|
||||
|
||||
#trackFile(pack: GamePackName, path: string) {
|
||||
const gamePack = this.#gameFiles.pack(pack);
|
||||
const sha1 = gamePack.fileDigest(path);
|
||||
if (sha1 === undefined) throw new Error(`${pack} has no file ${path}`);
|
||||
this.#files.set(`${pack}/${path}`, { pack, path, sha1 });
|
||||
return gamePack.readText(path);
|
||||
return gamePack;
|
||||
}
|
||||
|
||||
listFiles(pack: GamePackName): readonly string[] {
|
||||
|
||||
@@ -11,6 +11,7 @@ import type { GamePackName } from '../game-files.ts';
|
||||
export interface DatasetSource {
|
||||
readBlk(pack: GamePackName, path: string): BlkBlock;
|
||||
readText(pack: GamePackName, path: string): string;
|
||||
readBytes(pack: GamePackName, path: string): Uint8Array;
|
||||
/** Every file path in a pack, sorted. */
|
||||
listFiles(pack: GamePackName): readonly string[];
|
||||
}
|
||||
|
||||
@@ -16,6 +16,22 @@ import type { Dataset } from './dataset.ts';
|
||||
const RANK = 'config/rank.blk';
|
||||
const SLOT = /^slot(\d+)$/;
|
||||
|
||||
/** Cumulative XP thresholds read in the same order as scripts/ranks.nut. */
|
||||
export const playerRankThresholds: Dataset<readonly number[]> = {
|
||||
id: 'player-rank-thresholds',
|
||||
version: 1,
|
||||
extract: (source) => {
|
||||
const block = source.readBlk('char.vromfs.bin', RANK).blocks.find((child) => child.name === 'exp_for_playerRank');
|
||||
const thresholds: number[] = [];
|
||||
for (const { value } of block?.params ?? []) {
|
||||
const threshold = value.type === 'int' || value.type === 'int64' ? Number(value.value) : NaN;
|
||||
if (!Number.isSafeInteger(threshold) || threshold <= (thresholds.at(-1) ?? 0)) return [];
|
||||
thresholds.push(threshold);
|
||||
}
|
||||
return thresholds;
|
||||
},
|
||||
};
|
||||
|
||||
/** country -> parameter name -> vehicles needed, as written. */
|
||||
export type EraRequirements = Readonly<Record<string, Readonly<Record<string, number>>>>;
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ export type GamePackName =
|
||||
| 'aces.vromfs.bin'
|
||||
| 'gui.vromfs.bin'
|
||||
| 'lang.vromfs.bin'
|
||||
| 'ui/atlases.vromfs.bin';
|
||||
| 'ui/atlases.vromfs.bin'
|
||||
| 'ui/images.vromfs.bin';
|
||||
|
||||
/** Size and modification time provide a quick preliminary check of a pack file. */
|
||||
export interface PackStamp {
|
||||
|
||||
@@ -27,7 +27,11 @@ export class GamePack {
|
||||
}
|
||||
|
||||
readText(pathInPack: string): string {
|
||||
return Buffer.from(getFile(this.#archive, pathInPack)).toString('utf8');
|
||||
return Buffer.from(this.readBytes(pathInPack)).toString('utf8');
|
||||
}
|
||||
|
||||
readBytes(pathInPack: string): Uint8Array {
|
||||
return getFile(this.#archive, pathInPack);
|
||||
}
|
||||
|
||||
/** Every file path in the pack, sorted. */
|
||||
|
||||
Reference in new issue
Block a user