Skip to content

Fix spectral card RNG parity with vanilla Balatro#1231

Open
liafonx wants to merge 2 commits intoSteamodded:mainfrom
liafonx:fix-hand-cards-rng
Open

Fix spectral card RNG parity with vanilla Balatro#1231
liafonx wants to merge 2 commits intoSteamodded:mainfrom
liafonx:fix-hand-cards-rng

Conversation

@liafonx
Copy link

@liafonx liafonx commented Feb 25, 2026

Problem

SMODS overrides spectral consumables to support custom suits/ranks, but diverges from vanilla RNG in two ways:

  1. Pool sort orderpseudorandom_element sorts by sort_id when present, falling back to key order. Vanilla suits/ranks use integer-keyed arrays (Spades=1, Hearts=2, Diamonds=3, Clubs=4; 2=1…Ace=13). SMODS uses string-keyed tables with no sort_id, so the fallback sorts alphabetically — a different order which breaks seeded results.

  2. Call order in c_familiar / c_incantation — vanilla draws rank first then suit; the SMODS override drew suit first then rank, reversing the two RNG calls.

Fix

Single file: src/game_object.lua

Fix 1 — sort order (restores RNG parity for c_sigil, c_ouija, and all spectral cards):

  • Added max_sort_id counter to SMODS.Suit (init 4) and SMODS.Rank (init 13).
  • register auto-assigns sort_id from the counter if not set — custom suits/ranks append after vanilla (≥ 5 / ≥ 14).
  • All 4 vanilla suits and 13 vanilla ranks given explicit sort_id matching their vanilla integer-key positions.

Fix 2 — call order (further restores parity for c_familiar and c_incantation):

  • Swapped to _rank, _suit assignment so rank RNG fires before suit, matching vanilla.
  • c_grim is unaffected (rank hardcoded 'A'; only stale TODO removed).

Testing

Tested with seeded runs — all five spectral cards (c_grim, c_familiar, c_incantation, c_sigil, c_ouija) produce identical outcomes to unmodded Balatro with the same seed.

Compatibility

No API change. sort_id is additive; mods that don't set it get auto-assigned values appended after vanilla. No new Lovely patches required.

Additional Info:

I didn't modify api's
I didn't modify api's or I've updated lsp definitions.
I didn't make new lovely files or all new lovely files have appropriate priority.

- Add sort_id to SMODS.Suit (vanilla: S=1,H=2,D=3,C=4) and SMODS.Rank
  (vanilla: 2=1..Ace=13) so pseudorandom_element iterates in the same
  order as vanilla integer-keyed arrays; custom suits/ranks auto-assign
  sort_id >= 5 / >= 14 via a shared max_sort_id counter
- Swap c_familiar and c_incantation to draw rank before suit, matching
  vanilla call order; fixes downstream RNG shift on seeded runs
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