Skip to content

Engine Fix: party XP arithmetic and formatting - #160

Open
4Luke4 wants to merge 1 commit into
Bubb13:develfrom
4Luke4:XP
Open

4Luke4 wants to merge 1 commit into
Bubb13:develfrom
4Luke4:XP

Conversation

@4Luke4

@4Luke4 4Luke4 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Party XP arithmetic and formatting

Warning

Known bugs:

  • AddXPObject queues permanent additive opcode 104 and immediately asks for character XP feedback. The effect adds a signed delta to unsigned CGameSprite.m_baseStats.m_xp. Subtracting more XP than available wraps below zero.
  • CGameSprite::FeedBack formats int1 with %d and always fetches the gain message.
  • CInfGame::AddPartyXP divides its post-bonus total using unsigned DIV. Its recipient loop also consumes only positive remainders.

Tip

Fixes:

  • A C++ leaf normalizes only negative deltas to the available balance; the hook then executes the original ADD and completion/repass instructions. It does not change the effect's stored requested amount. Absolute, percentage and temporary-modifier paths remain native, as do positive additions and XP caps.
  • A targeted C++ call replacement formats negative amounts with %u using an unsigned magnitude, including INT_MIN -> 2147483648. A before-call hook selects a translatable character-loss TLK entry for negative int1. Native eligibility/feedback settings, the EXPERIENCEAMOUNT token, character attribution, colors and message construction remain in the engine.
  • Two C++ integer leaves replace the split and remainder region: signed division truncates toward zero; each extra point has the total's sign and is assigned in native recipient order. Thus -100 split among three eligible characters requests -34/-33/-33.
    Each recipient independently clamps at zero; an unaffordable portion is not reassigned. Native alive/valid-recipient selection and bonus adjustment remain in place. Party feedback retains its existing localized loss string and total; only its XP formatter is replaced to handle the INT_MIN magnitude safely.

Notes:

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