rh-hideout / pokeemerald-expansion

Feature branche for the pokeemerald decompilation. See the wiki for more info.
361 stars 1.09k forks source link

Setting trainer pokemon's nature or gender can inadverdently change their default nature, gender, and ability. #4123

Closed HungryPickle closed 8 months ago

HungryPickle commented 8 months ago

Description

Setting a nature or gender in trainer_parties.h results in any unset nature, gender, or ability liable to be inadvertently changed from its default. This relates to #3641 which shows trainers already don't have their vanilla emerald PID/nature. That issue's proposed solution of explicitly setting trainer pokemon natures in trainer_parties.h will fix natures but in the process break gender and ability from their vanilla values. The following shows that setting nature can change a pokemon's default gender (even with the personalityHash problem from #3641 commented out).

Screenshot 2024-02-03 030837 Screenshot 2024-02-03 030420

To explain, the personality value of this poochyena is 136 and it has whatever nature is 11. The modify nature function simply adds or subtracts from personality to get to the new nature. If I set the nature to 1, it subtracts 10 from 136 to get 126. Only 126 is below the gender ratio of 127 for poochyena, so it becomes female. "Life uhhhh finds a way."

The solutions I see are:

  1. Don't care about vanilla nature, gender, ability, or default values being changed by unrelated set values.
  2. Restore nameHash from vanilla emerald to get the nature, then generate a PID from nature, gender, and ability all at once.
  3. Go ahead in setting vanilla natures in trainer_parties.h but still generate a PID like above.

I wrote a function that can generate a PID like I mentioned, just waiting for the greenlight. I think solution 3 makes the most sense as nameHash is only useful for getting the nature. But, nature is the only value of the personality-derived values (nature, gender, ability) that isn't immediately obvious from looking at the code and most trainer pokemon natures can't be looked up anywhere.

Version

1.7.3 (Latest release)

Upcoming/master Version

No response

Discord contact info

hungry_pickle

Bassoonian commented 8 months ago

Fixed by #4172