Keroro1454 / Supply-Drop

Incoming Supply Drop! Adds new items to enhance your Risk of Rain 2 experience.
GNU General Public License v3.0
1 stars 4 forks source link

Healing with is outright doubled? #13

Closed SyfleNov closed 3 years ago

SyfleNov commented 3 years ago

Hey its me again, sorry to bother you again. I am not sure if this bug was intended, but healing is outright doubled in this version. I mean this is a nice thing, but I am very sure that you were not intending for that to happen outright.

So the usual thing I did was install 1.4.3 as you updated the mod due to the previous bug. I tried the game, and noticed healing was outright doubled. I did what I did previously in isolating your mod. Found that the mod was by itself causing healing to be doubled.

How to get this bug in RoR2 with Supply drop: -Acquire healing items in vanilla RoR2 installed note down rate of healing -Acquire healing items with supply drop 1.4.3 installed note down rate of healing -Further test other healing items proves that not just bustling fungus its also effects leech seed, harvester scythe, rejuvenation rack -Further testing shows adding damage items with the plague mask does not increase healing. -Further testing shows adding more masks does nothing.

Mods Used: -BeppinExPack by beppis -R2API by tristanmcpherson -TILER2 by ThinkInvis -Supply Drop by Keroro1454 -Risk of Options by Rune850 (Is a mod RoR2Cheats is dependent on) -RoR2Cheats by Loadington (Used this to get the items to recreate the bug)

So this time I took a look at your code, and don't understand what was going on entirely. I do understand a bit cause I have coded before.Though I noticed at the bottom of your code for the plaguemask.cs at the

 c.EmitDelegate<Func<HealthComponent, ItemIndex, float, float>>((healthComponent, maskIndex, healAmount) =>
        {
            if (!healthComponent || !healthComponent.body || !healthComponent.body.inventory)
            {
                return 0;
            }
            **if (!PlagueMask.DamageItemCounts.TryGetValue(healthComponent.body.netId, out int damageItemCount))
                damageItemCount = 0;**
            if (GetCount(healthComponent.body) == 0)
            {
                return healAmount;
            }
            **return healAmount + healAmount * (0.04f + (0.02f * ((float)healthComponent.body.inventory.GetItemCount(maskIndex) - 1)) * damageItemCount);**
        });

I went over and over reading your code. TO try and maybe figure what might be causing the issue. It accounts for rejuvenation racks as when you get one it does double healing. I am not sure if I fully understand, but I think you are not checking for a mask value count for the bottom return healAmount + healAmount. What would be ideal for the healing to be doubled as in the care would be to include a if statement or a conditional that you prefer to check the mask index count. I tried to calculate with your equation and it just adds more healing outright.

If the (float)healthComponent.body.inventory.GetItemCount(maskIndex) is 0 then it would be subtracted, but then its all in vain due to damageItemCount always being -1. The damageItemCount will turn the healing to (0.04f +(0.02f -1-1)

Sorry I am not able to articulate things well due to lack of ability on my part. I am sure you can figure it out, but in a nutshell : -damageItemCount is always being -1 ( i think its always being set to -1 due to no check conditional) -return healAmount + healAmount * (healing equation) is just doubling healing anyways without checking to see if there is a mask (adding 1 mask does increase healing slightly)

Thats all I got on my part, and I could record it in action. Though it doesn't really do much in painting the picture.

*edit due me thinking it over more, and figuring out that it gets set to -1 for no reason?

Keroro1454 commented 3 years ago

Not quite sure why you're getting damageItemCount returning -1? I'll run some tests myself but I had previously seen damageItemCount being correctly set within the OnInventoryChanged hook. The "=0" part from the IL hook only occurs in situations where the TryGetValue cannot find a dictionary key equal to the player's netid.

I suspect I need to add an else condition to encapsulate the final "return healAmount +..." In the IL hook, will try that and test it.

Keroro1454 commented 3 years ago

Issue was determined; the first if should be returning 0 because the returned value is added to the original healAmount, not replacing it. Likewise, the healAmount + healAmount... following the if does not need an if, but simply needs to have the "healAmount +" removed.

Will test this fix and hopefully push the final patch for the item by tonight.

Keroro1454 commented 3 years ago

Fixed (fingers crossed) with the release of 1.4.4. Thank you again for the report!