FunkFrog / ShareSuite

Risk of Rain 2 Item, Money, & Equipment sharing mod build upon BepInEx
https://thunderstore.io/package/FunkFrog-and-Sipondo/ShareSuite/
GNU General Public License v3.0
40 stars 26 forks source link

Fixed crash with blacklisted boss items #82

Closed Splamy closed 4 years ago

Splamy commented 4 years ago

Issue

The game will freeze with randomize shared items enabled when picking up a boss items wich is also on the blacklist.

Cause

  1. ShareSuite will random an item for each player except the one who picked it up https://github.com/FunkFrog/RoR2SharedItems/blob/5b7bced132efeccd7b147c6fb3b7b5ddd5041fb0/ShareSuite/ItemSharingHooks.cs#L64
  2. Then check if it is blacklisted, and rerandom it https://github.com/FunkFrog/RoR2SharedItems/blob/5b7bced132efeccd7b147c6fb3b7b5ddd5041fb0/ShareSuite/ItemSharingHooks.cs#L67
  3. But since GetRandomItemOfTier always returns the same boss item, the while loop will never exit https://github.com/FunkFrog/RoR2SharedItems/blob/5b7bced132efeccd7b147c6fb3b7b5ddd5041fb0/ShareSuite/ItemSharingHooks.cs#L280-L281

Fix

I created a own BlackList class which manages blacklisted items and also offers available item lists which are already pre-filtered with the blacklist. A random pick from one of these lists is now always guarateed to not have a blacklisted item, and if the available list is empty instead no item will be shared.

This change should also improve performance when picking up a lot of items since there are no more allocations nor loops at runtime. The precalculated lists will be refreshed whenever either the config changes or new items get unlocked.

Other stuff