Skip to content

Refactor: Read the last game folder offsets as members - #7652

Merged
ozgb merged 2 commits into
HectorBailey:mainfrom
giveen:issue-7078-6
Nov 14, 2026
Merged

ozgb merged 2 commits into
HectorBailey:mainfrom
giveen:issue-7078-6

Conversation

@giveen

@giveen giveen commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Part of #7078

Model: Ares / claude-opus-5

Rewrites the last 5 counted byte-offset accesses in src/game, taking the folder to 0 and the repo count from 55 to 50.

  • 0x4295b0 (LoadRadarPic): the 0x40-byte block it reads was a char header[0x40] read with offset casts. It is now RadarPicHeader, with mapWTiles (+0x4), mapHTiles (+0x8), pixelOffset (+0x28) and hasPixels (+0x2c), so the casts are member reads and the comment no longer has to quote offsets.
  • 0x464500 (UpdatePlayers): u = (Unit*)((char*)u + 0x118) becomes u++. The file forward-declared struct Unit only, so the stride had to be spelled; including ../units/unit.h makes Unit complete and the pointer arithmetic says what it means. The forward declaration goes with it.
  • 0x417bb0 (AiSearchGoal::DrawOnSurface): owner was a char* and the call read (short*)(this->owner + 0x76) and *(int*)(this->owner + 0x7e). owner is now Unit* and the file gets a Unit view with cell (+0x76) and footprint (+0x7e), both Point16 exactly as units/unit.h declares them, so the call reads (short*)&this->owner->cell and *(int*)&this->owner->footprint. The cast on the second stays because the call passes the pair packed into one int.

The names come from data/thaldren/functions.csv: Thaldren has Map_LoadRadarPic(char * pszMapPath, int * pOutMapWTiles, int * pOutMapHTiles), which is this function, and its two output parameters are the +0x4 and +0x8 dwords. pixelOffset and hasPixels are named from their use: the code seeks to the first and tests bit 0 of the second before reading any pixels. cell and footprint are units/unit.hs own names for +0x76 and +0x7e.

Checks: checkall 127 of 127 MATCH (every function in data_files.cpp, players_464290.cpp and console_commands.cpp); place.py MD5 8e74a1dffa1f5988624c52048f5b20cd, with and without --no-orig --strict; modules.py --check passes; cleanup_progress.py byte-offset count 55 to 50

Left out:

  • *(int*)(c + 0x142e9) and *(int*)(c + 0x142ed) in 0x424720 (radar.cpp). c is a Cell* and those reach a game-level structure 0x142e9 bytes past it. Nothing in src/ names that structure or that pair of fields, so there is no member to write, and inventing a type that far off a Cell* would read worse than the cast.

Two #7244-pattern mismatches I found and did not touch, since fixing either is a rename rather than an offset rewrite:

  • src/sound/sound.cpp:217 declares int __stdcall IsUnitVisible(Unit* unit) and calls it at 593 and 601, while src/ingame/selection.cpp:176 defines int __stdcall IsUnitVisible(char* unit). Only the char* form (?IsUnitVisible@@YGHPAD) appears anywhere in data/, so sound.cpp emits a reference to a decorated name the project never records.
  • src/game/console_commands.cpp:372 declares DrawMapTileSelectionOutline(void*, short*, int) and src/ingame/info_panel.cpp:1066 defines it as (void*, Size_0046b9d0*, int), which is the only spelling in data/. Size_0046b9d0 is declared inside info_panel.cpp with no header, so the caller cannot name it today.

Suspected original bugs:

  • none in what I rewrote. 0x4295b0 does *pWTiles = pic.mapWTiles - 1 and *pHTiles = pic.mapHTiles - 1, so the header stores a count one larger than the value the caller gets; that is consistent with a 1-based tile count and I left it.

@ozgb
ozgb merged commit f799205 into HectorBailey:main Nov 14, 2026
1 of 2 checks passed
@ozgb

ozgb commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Merged, thank you! Checked with #7651: all MATCH, shipped MD5 in both place.py modes. RadarPicHeader with Thaldren's Map_LoadRadarPic as evidence reads really well, and u++ is much clearer than the 0x118 stride.

On the two mismatches you found (IsUnitVisible in sound.cpp and DrawMapTileSelectionOutline in console_commands.cpp): thank you for flagging them. They're the kind #7513 tracks, through uv run tools/linkcheck.py --verbose's same name, other signature list. IsUnitVisibleToPlayer has the same problem: six callers declare it on Player* or void*, while players_465ac0.cpp defines it on ExploredMap*. If you'd like to take any of these, a folder claim on #7513 is the way in. Note that game is claimed there at the moment.

This branch is waiting to be deployed

1 waiting deployment
fork-ci — 8b1f1ef8 Waiting Nov 14, 2026 by giveen via build #3579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants