xiaoxiao921 / ItemLib

library for custom items in RoR2
1 stars 1 forks source link

Holding custom equipment causes once-per-frame(?) IndexOutOfRange error in StatManager.ProcessCharacterUpdateEvents #3

Closed ThinkInvis closed 5 years ago

ThinkInvis commented 5 years ago

While holding a custom equipment added by ItemLib, the function RoR2.Stats.StatManager.ProcessCharacterUpdateEvents rapidly throws IndexOutOfRange exceptions. This appears to be caused by PerEquipmentStatDef.totalTimeHeld.FindStatDef(currentEquipmentIndex) on line 349 of the relevant dnSpy file, which internally uses a fixed array of size 30 (original equipment count).

Given that other methods in ItemLib disable addition of custom items/equipment to profile stats, the solution to this is likely to use IL to insert a second condition to the if check on line 347 (if (currentEquipmentIndex != EquipmentIndex.None) --> if (currentEquipmentIndex != EquipmentIndex.None && currentEquipmentIndex < EquipmentIndex.Count)). I'd submit this as a pull request if I had any idea how to work IL :(

xiaoxiao921 commented 5 years ago

Thanks for the report, fixed :

https://github.com/xiaoxiao921/ItemLib/blob/1ba83cd77cfc6c178a44e30ecf055d3224689e74/ItemLib/ItemLib.cs#L885