Skip to content

Refactor: Share the HPI archive views - #7651

Merged
ozgb merged 1 commit into
HectorBailey:mainfrom
giveen:issue-7078-5
Nov 14, 2026
Merged

ozgb merged 1 commit into
HectorBailey:mainfrom
giveen:issue-7078-5

Conversation

@giveen

@giveen giveen commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Part of #7078

Model: Ares / claude-opus-5

Takes src/util to zero counted byte-offset accesses, and folds the two HPI archive views that the folder duplicated.

  • *(int*)(8 + base) in 0x4bd830 (HAPI_WriteArchiveData) becomes (int)((Header*)base)->size.
  • Adds src/util/hpi_header.h, one Header (the 0x14-byte archive header: magic, version, size, obfuscate flag, directory offset), and includes it in hpi.cpp and hpi_4bd830.cpp, which each carried an identical copy.
  • hpi.cpp now also includes the archive_directory.h that Refactor: Read the archive and squash offsets as members #7650 added, so ArchiveDirectory has one declaration for the whole folder instead of five copies becoming two.

Both folds cost hpi.cpp 4 symbol ids, and 0x4bb2e0 (HAPI_OpenFile) and 0x4bd160 (HAPI_CloseFile) only match again with filler: tools/idpad.py finds no set that works without the four declarations now above the views. They are real functions that other files already declare the same way (ProtectUnitDefsReadOnly and ProtectUnitDefsReadWrite in 25 places including src/units/unit.cpp and src/orders/order_targets.cpp; SetMemFussyDefault and IsMemFussy in 32 including src/graphics/draw.cpp and src/gui/dialogs.cpp), and hpi.cpp already carried an "Unused here" block of the same kind for 0x4bb190. The comment above them says which two functions they hold.

This corrects the last "Left out" bullet of #7650, which said the base + 8 access had "no struct to point at". That was wrong: hpi_4bd830.cpp already declared the archive header as Header with unsigned int size at +0x8, and hpi.cpp named the same block Header too. I had searched for a type named after an archive instead of for the name the file already uses.

Checks: checkall 240 of 240 MATCH (every function in all 14 src/util files); place.py MD5 8e74a1dffa1f5988624c52048f5b20cd, with and without --no-orig --strict; modules.py --check passes; cleanup_progress.py byte-offset count 56 to 55, and tools/rewrite_offsets.py --dry-run reports 0 rewrites for every file in the folder

The layout is the same inside and outside the pack(1) region (hpi_4bd830.cpp includes the header inside it, hpi.cpp outside it): magic 0, version 4, size 8, obfuscate 0xc, unknown_d 0xd, list 0x10, total 0x14 either way, which is what the field comments already said. Neither file includes graphics/gaf.h, which has its own unrelated Header.

Left out:

  • TdfFieldList in tdf_4c3120.cpp and tdf_4c51b0.cpp has the same body in both, but cannot share a header: tdf_4c51b0.cpp deliberately declares TdfField differently (its next is a TdfEntry* and it carries a key), and the issue says a view that disagrees with the definition stays out. One TdfFieldList would bind to two different element types.
  • OPENHAPIFILE and OpenHapiFile are the same block in hpi.cpp and hpi_4bd830.cpp under two spellings. Folding them means picking one spelling for both files, which is a rename rather than a gather, and Clean-up: rewrite the byte-offset accesses left #7078 asks for offset rewrites only.

Suspected original bugs:

@ozgb
ozgb merged commit a9d986b 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 giveen! Checked together with #7652: all 181 functions in the touched files MATCH, and place.py gives the shipped MD5 both with the original exe and with --no-orig --strict. I checked the four filler names against their definitions (ai/ai_profile.cpp and debug/debug_lib.cpp), and they're real. Thanks also for correcting #7650's "no struct to point at" note in the open. Getting src/util to zero counted offsets is a nice milestone.

This branch is waiting to be deployed

1 waiting deployment
fork-ci — a75aa3ce Waiting Nov 14, 2026 by giveen via build #3576
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