Skip to content

Drop the space the port inserted into two-digit weapon file numbers - #218

Closed
IvanPerrella wants to merge 1 commit into
TheMoonPeople:masterfrom
IvanPerrella:fix/weapon-path-padding
Closed

IvanPerrella wants to merge 1 commit into
TheMoonPeople:masterfrom
IvanPerrella:fix/weapon-path-padding

Conversation

@IvanPerrella

Copy link
Copy Markdown
Contributor

Summary

Two native-port path builders from 98580bd mistranslated the original's sprintf(number, "%2d", n) for weapon indices from ten up: "%2d" pads nothing at that width, but the port inserted a space.

  • ItemPaths (port/src/btitem.cpp): opening a big treasure box with such a weapon loaded dun/item/main_wep/c01w 33.img. The file doesn't exist, so the texture buffer stayed empty, and EnterIMGFile read a garbage offset and crashed (0xC0000005).
  • WeaponNames (port/src/menu_misc.cpp): the weapon menu looked for c01w 34.cfg inside the weapon pack. LoadPackData3 found nothing and built no model, so the menu showed only the character's shadow (e.g. Toan's Sax).

Both now only add the leading zero below ten, matching makeWeaponName and BtGetWeaponNamePath2 in ps2/src/btmisc.cpp. Those two are the only padded-number file names in the original code.

Backtrace (windows-x64-release, PAL, from the crash minidump)

* thread #1, stop reason = Exception 0xc0000005
  frame #0: CTextureManager::EnterIMGFile(buffer="", block=28, mipmap=0, extend=1) at texture.cpp:955:23
  frame #1: CTextureManager::LoadTextureBlockEX(block=28, ...) at texture.cpp:1638:21
  frame #2: SetTempTexture(block=28, ...) at gameloop.cpp:1386:16
  frame #3: BtGetTreasureboxBig_Loop() at btitem.cpp:199:17
  frame #4: DunMoveChara() at movechara.cpp:2731:17

TreasureboxBig_itemNo was 290 (Bone Rapier, Toan's weapon 33).

Test plan

  • build.bat windows-x64 and build.bat windows-x64-release build on Windows 11
  • Every weapon slot of all six characters resolves to an existing dun/item/main_wep/*.mds/.img, and every commenu/weapon/*.chr contains the .cfg name WeaponNames now builds (111 of 111). The only slots with no files are the unused "Dummy"/unnamed ones.
  • In game: open a big box holding a weapon numbered 10 or higher, and check the weapon menu models (e.g. Sax)

🤖 Generated with Claude Code

The original builds weapon file names with "%2d" for indices from ten up, which pads nothing, but
ItemPaths and WeaponNames inserted a space there. Opening a big treasure box with such a weapon
loaded "c01w 33.img", found nothing and crashed in EnterIMGFile; the weapon menu looked for
"c01w 34.cfg" and built no model, leaving only the character's shadow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IvanPerrella

Copy link
Copy Markdown
Contributor Author

Closing: f510a66 on master already drops the space in both ItemPaths and WeaponNames.

@IvanPerrella
IvanPerrella deleted the fix/weapon-path-padding branch October 25, 2026 10:30
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.

1 participant