Skip to content

Commit 47e6ded

Browse files
n-delicclaude
andauthored
Your own Visual C++ 2.x, 4.x or 5.0 builds the games they compiled (#163)
* Xbox games start from their own default.xbe or disc image (beta) An XBE is read and made a Windows program at the same addresses, which the PC path imports as it is: Ghidra, the delinker, objdiff, the rebuild check and every PC feature work on Xbox games. Kernel imports are named from nxdk's CC0 list, the XDK's library sections are set aside, and the compiler comes from the XDK build in the library version table. A compiled demo (Visual C++ 7.1) passes the console conformance tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * The Xbox in the table, the docs and the site: every feature ran on its demo Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Xbox: the rebuild gives back the game's XBE, early XDKs build with Visual C++ 7.0, Bink is set aside The PE view keeps the XBE whole inside it and says where, so tools/rebuild.py writes default.xbe beside the program (byte for byte your copy on a real game). XDKs before 5233 shipped Visual C++ 7.0 builds: 4627's is the pack's 7.0, earlier ones get it as the nearest. RAD's Bink sections are licensed middleware, set aside like the XDK's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Xbox: your own XDK sets its library code aside and builds early games with its own compiler Setup takes the folder of your own Xbox Development Kit (checked and recorded, never downloaded or copied). With it, the XDK's functions the linker put into .text (the C runtime, XAPI) are found by its libraries' bytes and set aside: 432 of them in a real game, in seconds. XDKs before 5233 shipped Visual C++ 7.0 builds of their own (13.00.9254 in 3911, not the pack's 9466): a game of that XDK builds with it (MSVC/xdk, configure.py --xdk) where it's set up. XDK 5849's compiler is byte for byte the msvc pack's 7.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Kits: a connector for the compilers and SDKs users bring, the Xbox XDK the first A compiler that only ever came in a proprietary SDK, or an SDK a console's games need, can't be pinned and downloaded. kits/ is its connector, like consoles/ and agents/: a kit says what proves its folder, its build, its compilers and the SHA-256 of the builds decompdecomp knows. Setup records the user's folder (a local toolchain, nothing copied) and says whether the copy is a known build; a console takes a kit by naming it (Console.kits) and its compilers reach the build through configure.py --own. The XDK moves there from toolchains.toml; the Xbox takes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * Xbox: games built with Visual C++ 7.0 or an early XDK's compiler build without /arch:SSE Their compilers don't have it (7.1 added it), and warned on every file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * PC projects can build a unit in LTCG harness mode, with Visual C++'s linker run through wine Games built with /GL and /LTCG can't match one file at a time: the linker picks register conventions and inlines across files. A unit whose harness/<unit>.drv.cpp defines HarnessEntry now compiles with /GL, links with /LTCG into a DLL (tools/ltcg.py; link.exe and lib.exe go through wine, which wibo can't run them on) and tools/dll2coff.py cuts its functions into an object laid out like the delinked original, with an address-mapping check. Other units and ordinary PC projects build as before; LTCG is a kept setting when tools are brought up to date, and pc.create takes a plan hook for choices that depend on the analysed program. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * Xbox imports tell link-time code generation apart and judge harness units The import detects LTCG from call sites that load registers no standard convention uses (forks/convention.py), logs why, writes ltcg and its evidence in the manifest, uses the LTCG flags and writes a driver skeleton per game unit (forks/ltcg.py). The judge counts a function that fails the mapping or data check as not matched, repeat-compile detection sees the harness files, and Xbox builds are given wine. The demo builds with 'build.py ltcg' and tests/test_ltcg.py imports it and matches a register-convention function. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * The docs say what Xbox has now: your default.xbe rebuilt, your own XDK, three real games imported Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * A piece another function jumps into stays a function of its own, so the program still rebuilds merge_pieces counted only calls and addresses as references to a piece Ghidra cut off. A linker that shares one tail between functions (link-time code generation: an Xbox game of 23,000 functions had two) left the other function's jump naming a symbol the join took away, and the rebuild check could no longer place it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * Agents can work a game built with link-time code generation: convention evidence in briefs, standins_for and unresolved names by kind Stage 1 built LTCG units through a harness, but an agent had nothing to write one with. The brief of an LTCG project's function now shows its convention in the original (registers read before written, stack arguments, ret N, saves, a few call sites) and says whether the unit's compile goes through a driver yet, how to name a decorated function (`// FUNCTION: 0x<address>`) and where to start. The new standins_for tool (forks/standins.py) writes a starting harness for a unit: stand-ins for what it calls or reads elsewhere with their conventions, a HarnessEntry with each function's call sites, and the declarations. Names a harness link left unresolved reach compile_and_diff, the brief and a pushed-back release by kind (data, standard callee, register callee, inlined callee, library; forks/unresolved.py), and a function missing from the unit's object says what the build said about it. The Xbox guide now teaches harness mode instead of telling agents to release LTCG functions. tests/test_ltcg.py goes from claim to match through the tools an agent has, then checks the rebuild. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * The import can force link-time code generation on or off for an Xbox game Detection from the program is a guess a user may know better than: the import dialog now asks (auto, on, off) for consoles that declare import_options. The connector gets a small generic hook (Console.import_options, passed as keywords to create_project through import_game/create_scratch and the import route's `options` query), so nothing outside consoles/ compares console names. Paths picked by typing them stay on auto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * The roadmap says link-time code generation works on Xbox games, and what's left of it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * LTCG briefs and standins_for say when a function is a member function, of which struct, with its fields and a declaration Under link-time code generation `this` can arrive in eax, esi, edi, ebx or ecx, which the ECX-only struct reader and the RTTI classes miss, so agents wrote member functions as free functions taking a pointer and guessed the fields. forks/methods.py (ported from the prototype) reads it from the registers a function uses as the base of fixed-offset accesses, notes "two objects alike" when two registers hit the same offsets, and groups functions by shared evidence (vtable stores, callers passing the same global object). standins_for declares member functions as such and writes the structs. Where RTTI already named the class, the brief only adds the register. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * An LTCG attempt whose function got another convention than the original's says which registers differ A helper or driver call adds a call site, and the linker can then pick another convention for the callee, so the bytes differ for a reason the C doesn't show. After an unmatched attempt the result compares the harness-made object's function (convention.analyse) with the original's and names the registers, stack arguments or ret that differ, with the hint to keep the original's number of call sites and check the driver's calls. The Xbox guide gets the member-function and call-site paragraphs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * The roadmap says all of the prototype's LTCG work is in Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * Your own Visual C++ and several copies of any kit: games build with the compiler build they were made with A game built with a Visual C++ build the downloadable packs don't have (a hotfix, 2012 to 2015, 2017 and newer) could not match, and a kit held one folder only, so a user with two XDKs or several Visual C++ versions had to pick. Setup now records any number of copies per kit (old single-folder manifests still read), lists each with its build and a Remove button, and adds a new "Visual C++ (your own copy)" kit for PC that recognises VC98, VC and VC/Tools/MSVC layouts. Each compiler carries its exact build, read from c2.dll's version resource, and a name unique per copy (xdk-3911, own-9.0.30729). The Xbox picks the XDK copy whose build is the game's; the PC picks the copy whose build the Rich header names (else the nearest of the same version), so games the packs can't build, 2017 and newer included, are in scope with a matching copy. The kits' compilers are listed as compilers of their console so a file can be switched to one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * Adding a kit explains several copies and matching by build Kits now hold any number of copies and consoles choose the copy whose build is the game's; contributors adding a kit need to know parts read one copy only and version names must be unique per copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * Your own Visual C++ is read by its cl.exe version, as its c2.dll says it c2.dll's file version is cl.exe's (Visual C++ 6.0 is 12.0.8168, 2008 is 15.0.30729, 2017 is 19.16.27023), not Visual Studio's: read as Visual Studio's, no copy matched a game's Rich header, and 2005 to 2010 ran through wine instead of wibo. Checked against the msvc packs' own compilers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * The docs say PC games of any Visual C++ build with your own copy of it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * The site's PC card says any Visual C++ builds from your own copy Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * Setup lists the kits users bring, and a filter chip for every platform it has Compilers & tools showed only the compilers and the consoles' packs: the XDK and your own Visual C++ never reached the page, so they couldn't be set up. Its filter chips were a fixed list too, without Xbox, PS1 or GBA; now they come from the platforms on the page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * A kit's copies fit their card in Setup: the build, whether it's known, and the folder's end, wrapped Each copy showed its whole folder path in the monospace installed mark, which doesn't wrap: the cards ran into each other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * No game is named in the Xbox code and tests: a title ID example and a test's story say what kind of game Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * The fork-setup test's stand-in for PC's tool_args takes the kits it's now given CI failed on every system: tool_args takes the console's kits since kits came in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * Your own Visual C++ 2.x, 4.x or 5.0 can build the games they compiled A game built with Visual C++ 2.0 to 5.0 can't use the compiler packs (those compilers can't be pinned), and it has no Rich header, so its linker's version (2.5x, 3.x/4.x, 5.x) now names the Visual C++ and picks the user's matching copy; without a copy the message names the version to set up. #137: the visualcpp kit reads MSVC20, MSDEV and DevStudio/VC copies (the version from c2.dll, c2.exe or cl.exe), and rich_version maps cl 9.x to 2.0, 10.0/10.10/10.20 to 4.0/4.1/4.2 and 11.0 to 5.0. Visual C++ 1.x (16-bit) is refused. They run through wibo, which is unverified for compilers this old: no copy was available to try. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH * A kit file rewritten within one tick of the clock is read again, not taken from the cache file_version cached by path and mtime; Windows' coarse clock gave a stand-in rewritten at once the same mtime, and CI on Windows read the old version. The size is in the key too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw52ayMLQzgUMTVxfzDfXH --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ec3ec35 commit 47e6ded

4 files changed

Lines changed: 77 additions & 13 deletions

File tree

‎src/decompnet/consoles/pc/scratch.py‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
)
7979
# Visual C++ 2015 to 2026 share their tools' ids: the first build of each (comp_id.txt)
8080
VC14_BUILDS = ((35503, "14.5"), (30401, "14.3"), (27508, "14.2"), (25017, "14.1"), (0, "14.0"))
81-
VISUAL_STUDIO = {"6.0": "6.0", "7.0": ".NET 2002", "7.1": ".NET 2003", "8.0": "2005", "9.0": "2008", "10.0": "2010",
81+
VISUAL_STUDIO = {"2.0": "2.0", "4.0": "4.0", "4.1": "4.1", "4.2": "4.2", "5.0": "5.0", "6.0": "6.0", "7.0": ".NET 2002", "7.1": ".NET 2003", "8.0": "2005", "9.0": "2008", "10.0": "2010",
8282
"11.0": "2012", "12.0": "2013", "14.0": "2015", "14.1": "2017", "14.2": "2019", "14.3": "2022",
8383
"14.4": "2022", "14.5": "2026"}
8484
# the release each common build is (comp_id.txt), so the import says "2008 SP1": each update generates other code
@@ -384,6 +384,9 @@ def blockers(self) -> list[str]:
384384
def cannot_match(self) -> list[str]:
385385
"""Why a program decompdecomp does start can't match (all of it, or some): none, it can."""
386386
out = []
387+
if self.version is not None and self.own is None and _version_key(self.version) < (6, 0):
388+
out.append(f"it was built with {self.compiler}, which the compiler packs don't have: nothing matches until "
389+
f"you set up your own Visual C++ {self.version} copy in Setup (the Visual C++ kit)")
387390
if self.newer_than_pack and self.own is None:
388391
out.append(f"it was built with {self.compiler}, and decompdecomp builds games with Visual C++ 6.0 to "
389392
"2010 so far: 2012 to 2015 come next (ROADMAP.md, Newer Windows games; 2017's compiler can "
@@ -413,7 +416,13 @@ def rich_version(build: str) -> tuple[str, int]:
413416
major, minor, number = (int(part) for part in build.split(".")[:3])
414417
if major >= 19:
415418
return next(v for first, v in VC14_BUILDS if number >= first), number
416-
return ("7.1" if minor else "7.0") if major == 13 else f"{major - 6}.0", number
419+
if major == 13:
420+
return ("7.1" if minor else "7.0"), number
421+
if major == 9: # Visual C++ 2.x (32-bit); 1.x (cl 8, 16-bit) has none
422+
return "2.0", number
423+
if major == 10: # 4.0, 4.1, 4.2: cl 10.00, 10.10, 10.20
424+
return f"4.{min(minor // 10, 2)}", number
425+
return ("5.0" if major == 11 else f"{major - 6}.0"), number
417426

418427

419428
def own_copy(version: str | None, number: int | None) -> kits.OwnCompiler | None:
@@ -464,7 +473,9 @@ def describe(data: bytes) -> Build:
464473
number = max(k[1] for k in files if k[0] == version and files[k] * MAIN_BUILD_SHARE >= by_version[version])
465474
else: # no Rich header (stripped, or a store's signature in its place): the linker's version names the toolset
466475
major, minor = data[at + OPTIONAL_HEADER_AT + LINKER_VERSION_AT:at + OPTIONAL_HEADER_AT + LINKER_VERSION_AT + 2]
467-
version = {6: "6.0", 7: "7.1" if minor >= 10 else "7.0"}.get(major, f"{major}.{minor // 10 if major == 14 else 0}")
476+
# (Visual C++ 2.x's linker is 2.5x, 4.x's 3.0 to 4.2, 5.0's 5.0; a Rich header began with 6.0's tools)
477+
version = {2: "2.0", 3: "4.0", 4: f"4.{min(minor // 10, 2)}", 5: "5.0", 6: "6.0",
478+
7: "7.1" if minor >= 10 else "7.0"}.get(major, f"{major}.{minor // 10 if major == 14 else 0}")
468479
version, number = (version if version in VISUAL_STUDIO else None), None
469480
first = at + OPTIONAL_HEADER_AT + opt_size
470481
names = [data[first + SECTION_HEADER_BYTES * i:first + SECTION_HEADER_BYTES * i + 8].rstrip(b"\0").decode("latin-1")
@@ -515,8 +526,12 @@ def game_info(path: Path) -> dict:
515526
why = f"it was built with {built.compiler}"
516527
elif built.own is not None: # a build of the user's own: the very one, or the nearest of that Visual C++
517528
same = rich_version(built.own.build)[1] == built.build
518-
why = (f"it was built with {built.compiler}; {built.own.name} builds it" if same else
529+
why = (f"it was built with {built.compiler}; your newest copy of it, {built.own.name}, builds it" if not built.build
530+
else f"it was built with {built.compiler}; {built.own.name} builds it" if same else
519531
f"it was built with {built.compiler}; the nearest of your copies is {built.own.name}")
532+
elif _version_key(built.version) < (6, 0): # Visual C++ 2.x to 5.0: no pack, only the user's own copy (#137)
533+
why = (f"it was built with {built.compiler}, and no compiler pack has that Visual C++: set up your own Visual "
534+
f"C++ {built.version} copy in Setup (Visual C++, your own copy); until then the closest the packs have is")
520535
else: # another update of its version (the packs have the common ones), or a version they don't have yet
521536
why = f"it was built with {built.compiler}; the closest the compiler packs have is"
522537
return {"platform": "pc", "id": stem, "title": path.stem, "region": "PC", "sha1": hashlib.sha1(data).hexdigest(),

‎src/decompnet/kits/visualcpp.py‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
decompdecomp downloads (the msvc packs) are particular builds; a game built with another build (a service pack the
33
packs don't have, 2012, 2013, 2015's later updates, 2017 and newer) matches only with its own. A copy is the folder
44
the compiler is in, as the products lay it out:
5+
- Visual C++ 2.x: MSVC20 (bin, include); 4.x: MSDEV (bin, include); 5.0: DevStudio/VC (the same inside). Their cl.exe
6+
is 32-bit and 9.x (2.x), 10.x (4.0 to 4.2) or 11.0 (5.0); 1.5 is 16-bit (cl 8.x) and out of scope. These folder
7+
layouts and which of cl.exe, c2.dll or c2.exe holds the version are from the products' documentation, not from a
8+
copy (#137): the code reads c2.dll, then c2.exe, then cl.exe, whichever has a version resource.
59
- Visual C++ 6.0: VC98 (bin/cl.exe, bin/c2.dll, include)
610
- .NET 2002 to 2013: VC, Vc7 (the same inside)
711
- 2015 and newer: VC/Tools/MSVC/<version> (bin/Hostx86/x86/cl.exe, ...), which the user may also give as the Visual
812
Studio folder, Tools/MSVC or the version's folder.
913
Its build is its code generator's, c2.dll's file version ("9.0.30729.1"), the number a game's Rich header gives for the
1014
compiler (consoles/pc/scratch.py). 2015 and newer run through wine on Linux and macOS (wine.py, as the msvc2015
11-
pack's), older ones through wibo. Their Windows SDK headers are found beside the copy (Windows Kits) when they are
15+
pack's), older ones through wibo (unverified for 2.x to 5.0: no copy has been tried). Their Windows SDK headers are found beside the copy (Windows Kits) when they are
1216
there; verify says when not.
1317
"""
1418

@@ -23,6 +27,8 @@
2327
range(19, 99): ("10", ("ucrt", "um", "shared")), # 2015 and newer
2428
range(17, 19): ("8.1", ("um", "shared")), # 2012 and 2013
2529
}
30+
C2 = ("c2.dll", "c2.exe", "cl.exe") # (the files that hold the compiler's version, in order)
31+
FIRST = 9 # the first 32-bit cl (Visual C++ 2.0); 8.x is Visual C++ 1.x, 16-bit
2632
BIN = ("bin", "bin/Hostx86/x86", "bin/Hostx64/x86") # (a 2017 copy's compiler for 32-bit programs, by host)
2733

2834

@@ -37,7 +43,7 @@ def _bin(base: Path) -> Path | None:
3743
"""The folder of a copy's compiler: cl.exe and its code generator c2.dll."""
3844
for sub in BIN:
3945
at = find(base, sub, dirs=True)
40-
if at is not None and find(at, "cl.exe") and find(at, "c2.dll"):
46+
if at is not None and find(at, "cl.exe") and (find(at, "c2.dll") or find(at, "c2.exe")):
4147
return at
4248
return None
4349

@@ -46,8 +52,8 @@ class VisualCpp(Kit):
4652
id = "visualcpp"
4753
name = "Microsoft Visual C++ (your own copy)"
4854
platform = "PC"
49-
description = ("A Visual C++ of your own for games the downloadable ones don't build exactly: any version from 6.0 "
50-
"to 2022. Give the folder of its compiler (VC98, VC, or VC/Tools/MSVC/<version>) or of Visual "
55+
description = ("A Visual C++ of your own for games the downloadable ones don't build exactly: any version from 2.0 "
56+
"to 2022. Give the folder of its compiler (MSVC20, MSDEV, VC98, VC, or VC/Tools/MSVC/<version>) or of Visual "
5157
"Studio; add as many copies as you have.")
5258
files = ("bin/cl.exe", "bin/c2.dll")
5359

@@ -60,8 +66,8 @@ def locate(self, folder: Path) -> Path | None:
6066

6167
def build(self, folder: Path) -> str | None:
6268
"""c2.dll's file version, "9.0.30729.1": Visual Studio's version, then the build number."""
63-
c2 = (b := _bin(folder)) and find(b, "c2.dll")
64-
return (file_version(c2) or None) if c2 else None
69+
b = _bin(folder)
70+
return next((v for n in C2 if b and (f := find(b, n)) and (v := file_version(f))), None)
6571

6672
def sdk(self, folder: Path, build: str) -> list[Path]:
6773
"""The Windows SDK header folders beside the copy that its Visual C++ needs (none to look for: 2010 and
@@ -81,7 +87,7 @@ def sdk(self, folder: Path, build: str) -> list[Path]:
8187

8288
def compilers(self, folder: Path) -> list[OwnCompiler]:
8389
build, bin_ = self.build(folder), _bin(folder)
84-
if build is None or bin_ is None:
90+
if build is None or bin_ is None or int(build.split(".")[0]) < FIRST:
8591
return []
8692
include = find(folder, "include", dirs=True)
8793
old_sdk = find(folder, "PlatformSDK/include", dirs=True) # (.NET 2003 brought one)
@@ -97,6 +103,8 @@ def verify(self, folder: Path) -> str:
97103
return "its c2.dll has no version resource: decompdecomp can't tell which build it is"
98104
say = f"Visual C++ {build}"
99105
major = int(build.split(".")[0])
106+
if major < FIRST:
107+
return f"Visual C++ {build} is 16-bit (1.x): decompdecomp builds 32-bit programs only"
100108
if any(major in r for r in SDKS) and not self.sdk(folder, build):
101109
return (f"{say}; no Windows SDK was found beside it (Windows Kits), so a game's #include <windows.h> "
102110
"won't find its headers")

‎tests/test_kits.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,24 @@ def test_setup_lists_every_kit_a_console_takes():
185185
assert {kid for c in consoles.CONSOLES for kid in c.kits} <= set(TOOLS)
186186

187187

188+
def test_visualcpp_reads_old_32_bit_copies_from_their_folders_and_refuses_16_bit_ones(tmp_path):
189+
"""#137: Visual C++ 2.x (MSVC20), 4.x (MSDEV) and 5.0 (DevStudio/VC) keep cl.exe and c2 in a bin folder; the
190+
version is c2.dll's, else c2.exe's. 1.x (cl 8.x) is 16-bit."""
191+
kit = kits.get("visualcpp")
192+
two = make_vc(tmp_path / "a", "9.0.2196.0", "MSVC20/BIN")
193+
four = make_vc(tmp_path / "b", "10.20.6166.0", "MSDEV/BIN")
194+
five = make_vc(tmp_path / "c", "11.0.7022.0", "DevStudio/VC/BIN")
195+
for copy, build in ((two, "9.0.2196.0"), (four, "10.20.6166.0"), (five, "11.0.7022.0")):
196+
assert kit.locate(copy.parent) == copy.resolve() # (the product's folder: MSVC20, MSDEV, DevStudio)
197+
[own] = kit.compilers(copy)
198+
assert own.build == build and own.runner == "wibo" and own.includes == (copy / "include",)
199+
exe = make_vc(tmp_path / "d", "9.0.2196.0", "MSVC20/BIN")
200+
(exe / "BIN" / "c2.dll").rename(exe / "BIN" / "c2.exe")
201+
assert kit.build(exe) == "9.0.2196.0"
202+
sixteen = make_vc(tmp_path / "e", "8.0.2000.0", "MSVC/BIN")
203+
assert kit.compilers(sixteen) == [] and "16-bit" in kit.verify(sixteen)
204+
205+
188206
# ---- the PS3 SDK kit, and a kit's compiler in ROM mode (stand-ins: a shell script is the "compiler")
189207

190208
STAMP = b"4.1.1 (SDK270, $Rev: 3019 $)"

‎tests/test_pc.py‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ def built(linker):
879879
assert built((9, 0)).pack_version == "9.0SP1" # the newest build of its version: the most games had it
880880
assert (built((7, 10)).version, built((7, 0)).version, built((10, 10)).version) == ("7.1", "7.0", "10.0")
881881
assert built((7, 10)).cannot_match() == [] and built((14, 29)).out_of_scope
882-
unknown = built((2, 50)) # not a Microsoft linker's version
882+
unknown = built((1, 0)) # not a Microsoft linker's version
883883
assert unknown.version is None and unknown.pack_version == "6.0" and unknown.blockers() == []
884884

885885

@@ -2505,8 +2505,31 @@ def test_configure_names_each_of_two_own_copies_compilers_in_the_ninja_build(tmp
25052505
("12.0.8168.0", ("6.0", 8168)), ("13.0.9466.0", ("7.0", 9466)), ("13.10.3077.0", ("7.1", 3077)),
25062506
("14.0.50727.762", ("8.0", 50727)), ("15.0.30729.1", ("9.0", 30729)), ("16.0.40219.1", ("10.0", 40219)),
25072507
("17.0.61030.0", ("11.0", 61030)), ("18.0.40629.0", ("12.0", 40629)), ("19.0.24215.1", ("14.0", 24215)),
2508-
("19.16.27023.0", ("14.1", 27023)), ("19.29.30137.0", ("14.2", 30137))])
2508+
("19.16.27023.0", ("14.1", 27023)), ("19.29.30137.0", ("14.2", 30137)),
2509+
("9.0.2196.0", ("2.0", 2196)), ("10.0.5270.0", ("4.0", 5270)), ("10.10.6038.0", ("4.1", 6038)),
2510+
("10.20.6166.0", ("4.2", 6166)), ("11.0.7022.0", ("5.0", 7022))])
25092511
def test_a_copys_compiler_build_is_read_as_the_rich_header_reads_it(build, version):
25102512
"""c2.dll's file version is cl.exe's (the msvc packs' 6.0 to 2010 say 12.0 to 16.0): a copy matches a game's
25112513
Rich header only as its Visual C++ version."""
25122514
assert scratch_pe.rich_version(build) == version
2515+
2516+
2517+
@pytest.mark.parametrize("linker, version", [((2, 50), "2.0"), ((3, 0), "4.0"), ((4, 10), "4.1"), ((4, 20), "4.2"),
2518+
((5, 0), "5.0")])
2519+
def test_a_game_without_a_rich_header_names_old_visual_cpp_by_its_linker_and_takes_the_users_copy(
2520+
tmp_path, monkeypatch, linker, version):
2521+
"""#137: a game built with Visual C++ 2.x to 5.0 has no Rich header; its linker's version says which. Without the
2522+
user's copy the packs' 6.0 stands in and the message names the copy to set up; with it, that copy builds the game."""
2523+
game = _windows_program(linker=linker)
2524+
plain = scratch_pe.describe(game)
2525+
assert (plain.version, plain.build, plain.own, plain.pack_version) == (version, None, None, "6.0")
2526+
assert version in plain.cannot_match()[0] and plain.blockers() == []
2527+
cl = {"2.0": "9.0.2196.0", "4.0": "10.0.5270.0", "4.1": "10.10.6038.0", "4.2": "10.20.6166.0", "5.0": "11.0.7022.0"}
2528+
_own_copies(tmp_path, monkeypatch, "15.0.30729.1", cl[version], "12.0.8168.0")
2529+
built = scratch_pe.describe(game)
2530+
assert built.own is not None and built.own.build == cl[version] and built.own.runner == "wibo"
2531+
assert built.cannot_match() == [] and built.pack_version == built.own.version
2532+
path = tmp_path / "old.exe"
2533+
path.write_bytes(game)
2534+
why = scratch_pe.game_info(path)["compiler_why"]
2535+
assert "your newest copy of it" in why and "by its linker's version" in why

0 commit comments

Comments
 (0)