# build-env — Extracted MW4 / FireStorm build toolchain

Everything here was extracted from the **original build machine's disk image**
(mounted at `E:\`). It is self-contained — no external installs required to
compile the game. Build user on the original machine was **`jeff`**.

## Contents
| Folder | Source on image | Purpose |
|--------|-----------------|---------|
| `VisualStudio6/` | `E:\Program Files\Microsoft Visual Studio` | Visual C++ 6.0 — compiler (`VC98\Bin\CL.EXE`, `LINK.EXE`, `NMAKE.EXE`), IDE (`Common\MSDev98\Bin\MSDEV.EXE`), headers, libs, MFC/ATL. 204 MB. |
| `dx7asdk/` | `E:\Code\dx7asdk` | **DirectX 7.0a SDK** — `include\` (ddraw.h `DIRECTDRAW_VERSION 0x0700`, d3d.h immediate mode, dinput.h, dsound.h) + `lib\` (ddraw.lib, dinput.lib, dsound.lib, d3dim.lib …). Matches GameOS `GOS_REQUIRES_DX7A`. |
| `DXMedia/` | `E:\Code\DXMedia` | **DirectX Media 6.0 SDK** — DirectShow headers (amstream.h, control.h, strmif.h) + libs (strmiids.lib, quartz.lib, strmbase.lib …). Needed by GameOS for video. |
| `CommonFiles-MSShared/` | `E:\Program Files\Common Files\Microsoft Shared\{VS98,MSDesigners98}` | Shared VS components referenced by the HKLM registration (help/designer DLLs). |
| `setup-mw4-build.bat` | (generated) | Sets `PATH/INCLUDE/LIB` for command-line builds — **exact original ordering**. |
| `vc6-directories.reg` | (generated) | HKCU import — exact original Tools→Options→Directories (rebased) so headers resolve DX7-correctly. |
| `vc6-hklm-registration.reg` | (generated) | HKLM import — VC6 install registration (rebased + redirected under `Wow6432Node`) so `msdev.exe` runs from the copy. |
| `_raw_visualstudio6.reg`, `_raw_devstudio6.reg` | exported from image software hive | Untransformed source exports (provenance; not for import). |

### Not copied (intentionally)
- **EAX SDK** — not required as a separate install; `eax.h` is bundled in the
  repo (`Gameleap\code/CoreTech/Libraries/GameOS/Eax.h`) and no `eax.lib`
  exists on the image (EAX is resolved at runtime, not statically linked).
- **DirectX 8 SDK** — `d3d8.lib/d3dx8.lib` are NOT on the image. Only a few
  standalone *tools* (Gos2Light, Gos2Text, HighTide) link DX8; the **game and
  editor build entirely on DX7**, so their absence does not block the main build.

## Exact original directory ordering (recovered from jeff's NTUSER.DAT)
Source key: `HKCU\Software\Microsoft\DevStudio\6.0\Build System\Components\Platforms\Win32 (x86)\Directories`

- **Include:** `DXMedia\include → dx7asdk\include → VC98\INCLUDE → VC98\MFC\INCLUDE → VC98\ATL\INCLUDE`
- **Library:** `VC98\LIB → VC98\MFC\LIB`  *(only VC98 — see below)*

Two non-obvious but verified facts that make this work:
1. **DXMedia\include has no core DX headers** (only DirectShow: amstream/control/strmif),
   so listing it first does NOT override DirectDraw. `ddraw.h` still resolves from
   `dx7asdk` (next in line) — satisfying `GameOS\pch.hpp`'s
   `#if DIRECTDRAW_VERSION != 0x0700 → #error DirectX 7 SDK is required` — before
   VC98's older `ddraw.h` (last) is ever reached.
2. **Library Dirs lists only VC98** because the DirectX/DirectShow `.lib`s
   (ddraw, dinput, dsound, dxguid, strmiids, quartz, strmbase, amstrmid) were
   **copied into `VC98\Lib`** on the original machine. They're pulled in via
   `#pragma comment(lib,...)` (e.g. `GameOS\guids.cpp`), not via the link line.
   Our copied VC98 tree already contains them.

## How to build

### `stlnative/` — native headers STLport wraps (now in-tree)
STLport (`mw4\Libraries\stlport`) wraps a 27 MB snapshot of the VC98 + Platform SDK
headers (974 files). It used to require a hardcoded `C:\stlnative`; it now lives here at
`build-env\stlnative\`, and the 3 macros in `stl_inc_find.hpp` point at
`<c:\VWE\firestorm\build-env\stlnative/##x>`. No external `C:\stlnative` is needed — the build is
self-contained under `c:\VWE\firestorm`. (If you ever relocate the working tree, update those 3
macro lines to the new absolute path.)

### One-time setup: register VC6 + the directory paths
Run **elevated** (HKLM write needs admin; do both in the same shell):
```cmd
reg import c:\VWE\firestorm\build-env\vc6-hklm-registration.reg
reg import c:\VWE\firestorm\build-env\vc6-directories.reg
```
- `vc6-hklm-registration.reg` → registers the VC6 install (ProductDir/InstallDir,
  environment packages) under `HKLM\SOFTWARE\Wow6432Node\Microsoft\{VisualStudio,DevStudio}\6.0`
  so 32-bit `msdev.exe` finds itself when launched from the copied tree.
- `vc6-directories.reg` → HKCU; the exact original include/lib/path ordering.

> **Wow6432Node, why:** on 64-bit Windows a 32-bit process (`msdev.exe`) reads
> `HKLM\SOFTWARE\Microsoft\...` redirected to `HKLM\SOFTWARE\Wow6432Node\Microsoft\...`,
> so the HKLM keys are placed there. HKCU\Software is **not** redirected, so the
> directories key stays at its normal path.

### Option A — IDE (most faithful to original)
1. Launch `VisualStudio6\Common\MSDev98\Bin\MSDEV.EXE`.
2. (Directories are already set by the `.reg` import — verify under
   Tools → Options → Directories if desired.)
3. Open `c:\VWE\firestorm\Gameleap\code\mw4\Code\MechWarrior4.dsw`, set
   **MW4Application** as the Active Project, pick a config, Build.

### Option B — command line (scriptable)
```cmd
cd c:\VWE\firestorm\build-env
setup-mw4-build.bat
cd c:\VWE\firestorm\Gameleap\code\mw4\Code
msdev MechWarrior4.dsw /MAKE "MW4Application - Win32 Release"
```
> `msdev /MAKE` reads include/lib dirs from the **registry** (the `.reg` above),
> not from `%INCLUDE%`. The `setup-mw4-build.bat` env vars matter only if you drive
> `cl`/`nmake` directly. Run the `.reg` import once and either path works.
> Caveat: `msdev.exe` run from a copied tree may still expect its HKLM install
> registration; if it misbehaves, use the IDE (Option A) or install VC6 from the image.
