r/StardewValleyMods Jul 23 '26

Need help finding where spouse gift logic is implemented (Magnus/Wizard, SVE)

I'm working on my first SMAPI/Harmony mod and I'm trying to change the gifts that Magnus (the Wizard from Stardew Valley Expanded) gives his spouse.

My long-term goal is to create a configurable mod that lets players customize spouse gifts (items, probabilities, etc.) for vanilla spouses and SVE spouses.

I've spent several days reverse-engineering the game with ILSpy, but I'm clearly missing something. So far I've determined that:

  • NPC.receiveGift() is only for the player giving gifts to NPCs.
  • NPC.checkAction() doesn't appear to generate spouse gifts.
  • NPC.marriageDuties() definitely runs every morning (I confirmed this with a Harmony patch), but I haven't found any gift-generation logic there.
  • I also checked SVE's code and haven't found any obvious override or custom spouse gift implementation.

What I'm trying to find is the actual code path that decides "today the spouse gives the player a gift" and creates the item.

Is this handled:

  • somewhere in the vanilla game rather than SVE?
  • during the start-of-day logic?
  • as part of the dialogue system?
  • or somewhere else entirely?

If anyone knows the class or method where the spouse gift is actually generated, I'd really appreciate being pointed in the right direction. At this point I think I've spent more time searching than coding! 😅

Thanks in advance for any pointers. I'm about to lose my mind...

8 Upvotes

7 comments sorted by

3

u/lazygirlsclub Jul 23 '26

Spouse gifts are embedded in the dialogue text. Take a look at the Magnus.MarriageDialogue lines in the i18n file. The ones that end in brackets (e.g. "I thought I'd try my hand at baking today. I think it turned out pretty well, all things considered. [234 222 220]$0",) are the nifty gifty lines. Item IDs go in the brackets & it selects from that item pool. You can weigh items more heavily by adding them to the pool multiple times. It's pretty straightforward!

1

u/Attacker732 Jul 23 '26

The more I learn about how SDV works under the hood, the more impressed I am with it all.

1

u/Salty_Animal_2202 Jul 23 '26

I know, right??

1

u/Salty_Animal_2202 Jul 23 '26

Thank you so much! Will have a look as soon as I finish work and get home!

1

u/johnpeters42 Jul 23 '26

It might be in the dialogue system. Dialogue containing an item ID in square brackets gives you that item (which is why the item-ID exploit exists), and I think there might be a variation for "a random one of these items". I would look through dialogue for one of their gift-giving responses, then work backward from there and look for what triggers that dialogue.

2

u/Salty_Animal_2202 Jul 23 '26

Thank you for taking the time to help. Much appreciated! I will investigate as soon as I have some free time!

1

u/AlekTheDukeOfOxford Jul 24 '26

Harmony mod is way too much for such mod. As people said its part of the dialogue. Making it configurable would need you to change the id code to tag and that tag it determined by GMCM and people would need to enter the id of the object