Skip to content
22 changes: 22 additions & 0 deletions .github/workflows/test-ultimate-tuning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test Ultimate 350 Tuning

on:
push:
branches: [ultimate-350-tuning]
pull_request:
branches: [main]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm test
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ nfsu2-web pairs `GARAGE.DAT` with its profile through a fingerprint of the caree
- **MAX OUT** (in the tuning dialog header) enables the 54 active performance bytes, including mutually exclusive parts, and sets the nine unique flags; the game's own apply routine does not do this. It does not change the visual-related flags, purchase bookkeeping or inactive IDs. Only the muffler (15) and cold air intake (16) edits are confirmed by in-game save diffs.
- **Unique** controls edit separate per-car category flags without a confirmation prompt. They do not emulate the unique shop's event-status update or full reward process. See [technical.md](technical.md) for the code trace and evidence limits.
- **Unlock all** sets the 420 bytes that NFSU2-ProfileCreator writes as `0xFF` in each car slot (ranges in [src/data/unlock-table.ts](src/data/unlock-table.ts), offsets `+0x462` to `+0x7E1`). It only writes those bytes. The byte-to-part mapping and the in-game effect are not verified yet.
- **Ultimate Top Speed — All Cars** (experimental, on the DYNO tab) creates a top-speed optimization for every filled, unlocked, supported garage car across all five dyno setups. It uses the installed parts, each car's traced gear ranges and the game's dyno simulator; it does not install upgrades or bypass the game's speed limiter/gear clamps. Unsupported, locked, empty and experimental traffic slots are skipped. This is a top-speed optimization, **not a guarantee of 350 km/h**: actual speed depends on each car's physics, installed transmission and game limits. The edited setups are applied to the in-browser save; download a separate save and keep the original backup. In-game verification is required.
- **Dyno** (in the tuning dialog) reads car data from `GLOBAL\GLOBALB.BUN` in your NFSU2 folder; the file is read locally and not shipped with the editor. A car needs at least one tunable performance or body package installed. The **ECU** and **Turbo** tabs show the game's 9-point torque graph (idle to redline) with each point's min–max range, stock value and current setting. Click or drag a column, or focus the graph and use the arrow keys (Shift = 10 steps). By default edits follow the game's tuning screen: raising a point also lifts its direct neighbours and lowers the points further away, so the curve's total torque stays the same. **Cheat limits (save-only)** sets each point on its own instead, which only a save edit can do. When the save loads, the game spreads the change in total torque evenly over all nine points, so lowering some points pushes the others past their maximum; dashed **In game** marks show those values, and the result table includes them. The **Drivetrain** tab is the game's Gear Ratios screen: each gear's speed at the rev limiter on a 0–420 km/h bar (green up to the current setting, red for the rest of its range) and the final drive from Top speed to Acceleration. Click or drag a bar, or use −/+ or the arrow keys; like the game, moving a gear pushes its neighbours to keep a 0.05 ratio gap. The ranges come from the installed transmission parts and cannot be unlocked through the save, because the game clamps out-of-range values when it loads. **Auto-tune ECU & turbo** starts from the graph and loads its result into it for manual adjustment; it always sets points independently, so its curves use the cheat limits whether or not the box is checked. Edits are drafts per slot and setup (a **Saved / Edited** comparison) until you **Apply** them; **Discard changes** drops them. Apply writes the selected setup's 18 curve bytes, plus its gearing and scalar bytes when you changed them. Times come from the game's own dyno simulation and are not yet checked against the in-game screen. See [technical.md](technical.md).
- **Optimize gearing & shift spacing** is unchecked by default. Enable it to include unlocked final-drive and forward-gear settings in event tuning. The search checks every shift, including gears outside the timed run, and balances usable power and event performance with average/worst-shift power-band coverage and more even percentage RPM drops. Excessive RPM drops are capped against the neutral transmission and its geometric spacing. This tunes ratios, not the game's shift-RPM thresholds. Apply saves those settings alongside the curves, leaving other setups and unrelated bytes unchanged. Locked and unused gears are preserved. Gearing is frozen during the initial and final usable-power passes. The game's adjacent-gear constraints and byte normalization are included; see [technical.md](technical.md#gearing-trace).
- **Event-specific auto-tuning** replaces the goal slider. Selecting Circuit or URL targets broad usable power through shift recovery, Drag targets sustained high-RPM power and top-speed-biased gearing, and Drift/Street X target low–mid RPM response and acceleration. The [wiki's tuning guidance](https://nfs.fandom.com/wiki/Need_for_Speed:_Underground_2/Performance_Tuning) recommends acceleration for short tracks/drift and top speed for drag; the exact RPM targets are editor heuristics, not prescriptions from the wiki or a lap/drift simulation. The displayed target band is split into three equal RPM regions and their average powers are combined geometrically, so a lone peak cannot substitute for usable power across the band. Auto-tune builds that power, runs two event/performance passes with optional gearing, then refines it with gearing fixed. Final refinement cannot worsen any resulting acceleration time or top/trap speed.
Expand Down
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ <h4>{{ palette.name }}</h4>
</div>
<div class="dyno-panel" ng-if="tuning.tab === 'DYNO'">
<p class="muted" ng-if="tuning.dyno.blocked">{{ tuning.dyno.blocked }}</p>
<div class="dyno-controls">
<button type="button" class="profile-action-btn" ng-click="ultimateTuneAll()" ng-disabled="tuning.dyno.busy || !tuning.dyno.gameName">
ULTIMATE TOP SPEED — ALL CARS
</button>
<span class="muted">Optimizes every supported unlocked garage car across all five setups.</span>
</div>
<div ng-if="tuning.dyno.rows.length">
<div class="dyno-setups" role="tablist" aria-label="Dyno setups">
<button type="button" role="tab" ng-repeat="name in tuning.dyno.setupNames track by $index"
Expand Down
77 changes: 76 additions & 1 deletion src/controller/editor-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { TRAFFIC_CARS } from '../data/traffic-cars.js';
import { setSlotTrafficCar } from '../model/slots.js';
import { colorPalettes, isVisualColorSlot, parseVisualData, readVisual, VISUAL_SLOTS, VisualCatalog } from '../model/visual.js';
import {
CURVE_POINTS, DynoModel, ECU_OFF, findCar, KW_TO_HP, MPH_TO_KMH, NEUTRAL_BYTE, NM_TO_LBFT, optimizeDynoSetup, parseGameData,
CURVE_POINTS, DynoModel, ECU_OFF, findCar, KW_TO_HP, MPH_TO_KMH, NEUTRAL_BYTE, NM_TO_LBFT, optimizeDynoSetup, optimizeSetup, parseGameData,
readSlotDyno, setSetupTuning, SETUP_NAMES, SETUP_SIZE, TURBO_OFF,
type CurveKind, type CurvePoint, type DynoEvent, type DynoResult, type GameData, type Gearing, type ScalarRow, type TuningBand,
} from '../model/dyno.js';
Expand Down Expand Up @@ -843,6 +843,81 @@ export function EditorController($scope: EditorScope): void {
}, 30);
};

/** Apply the top-speed objective to every supported filled garage slot and all five setups. */
$scope.ultimateTuneAll = function (): void {
const view = $scope.tuning.dyno;
if (!data || !game || view.busy) {
setStatus('error', 'Load a career save and GLOBAL\\\\GLOBALB.BUN before tuning all cars.');
return;
}
if (!confirm('Create a top-speed tuning draft for every supported filled car and all five setups?\\n\\nOnly existing installed parts and in-game gear ranges are used. The original save is unchanged until you download. Keep a backup.')) return;

const source = data;
const sourceGame = game;
let next: Uint8Array<ArrayBufferLike> = source.slice();
const jobs: { slot: number; setup: number; model: DynoModel; bytes: Uint8Array; carName: string }[] = [];
const completed = new Set<number>();
const skippedSlots: string[] = [];
let successfulSetups = 0;
const topBySlot = new Map<number, number>();

for (let slot = 0; slot < slotCount(source); slot++) {
if (!isSlotUsed(source, slot) || isSlotLocked(source, slot)) { skippedSlots.push(`Slot ${slot + 1}: empty or locked`); continue; }
const sd = readSlotDyno(source, slot);
if (TRAFFIC_CARS.some((car) => car.hash === sd.hash)) { skippedSlots.push(`Slot ${slot + 1}: experimental traffic car`); continue; }
const car = findCar(game, sd.hash);
if (!car) { skippedSlots.push(`Slot ${slot + 1}: car not found in GLOBALB.BUN`); continue; }
const model = new DynoModel(game, car, sd.installed, sd.uniques);
if (!model.ecuTunable && !model.turboTunable && !model.gearingParameters.length) {
skippedSlots.push(`Slot ${slot + 1}: no supported tuning parts`);
continue;
}
for (let setup = 0; setup < SETUP_NAMES.length; setup++) {
jobs.push({ slot, setup, model, bytes: sd.setups[setup], carName: car.name });
}
}

if (!jobs.length) {
setStatus('error', 'No supported filled cars were available. Check the save, installed parts and GLOBALB.BUN.');
return;
}

const totalJobs = jobs.length;
view.busy = true;
setStatus('', `Preparing top-speed tunes: 0 / ${totalJobs} setups…`);
const runNext = (): void => {
if (data !== source || game !== sourceGame) {
view.busy = false;
setStatus('error', 'The save changed while tuning was running. The unfinished batch was discarded.');
return;
}
const job = jobs.shift();
if (!job) {
view.busy = false;
if (!completed.size) {
setStatus('error', 'No setup could be optimized. The save was not changed.');
return;
}
applyResult(next);
const notes = Array.from(topBySlot, ([slot, speed]) => `slot ${slot + 1}: ${Math.round(speed)} km/h`);
setStatus('success', `Top-speed optimization applied to ${completed.size} cars (${successfulSetups}/${totalJobs} setups optimized); ${skippedSlots.length} slots/setups skipped. Simulated estimates: ${notes.join(' | ')}. This does not guarantee 350 km/h; the game's physics, installed parts and speed limiter still apply. Download to save.`);
return;
}
try {
const result = optimizeSetup(job.model, job.bytes, 'top', true);
next = setSetupTuning(next, job.slot, job.setup as DynoEvent, result.setup, true, false);
completed.add(job.slot);
successfulSetups++;
topBySlot.set(job.slot, Math.max(topBySlot.get(job.slot) ?? 0, result.after.topSpeed * MPH_TO_KMH));
} catch (err) {
skippedSlots.push(`Slot ${job.slot + 1} / ${SETUP_NAMES[job.setup]}: ${errorMessage(err)}`);
}
setStatus('', `Preparing top-speed tunes: ${successfulSetups} / ${totalJobs} setups optimized…`);
setTimeout(() => $scope.$apply(runNext), 0);
};
setTimeout(() => $scope.$apply(runNext), 30);
};

$scope.applyDyno = function (): void {
const built = dynoModel();
const key = draftKey(), bytes = drafts.get(key)?.bytes;
Expand Down
1 change: 1 addition & 0 deletions src/controller/editor-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export interface EditorScope extends angular.IScope {
resetScalar(param: number): void;
selectSetup(setup: DynoEvent): void;
optimizeDyno(): void;
ultimateTuneAll(): void;
applyDyno(): void;
discardDyno(): void;
selectCurve(kind: DynoTab): void;
Expand Down