harbingerofme / R2Mods

Harb's mods for Risk of Rain 2
GNU General Public License v3.0
1 stars 4 forks source link

Dilluvian + GeneralFixes OSP compatibility. #4

Closed Reinms closed 4 years ago

Reinms commented 4 years ago

Currently they conflict due to missing matches (two different missed matches are possible based on load order)

Solution: Rather than removing the conditional for hasOneshotProtection, emit as true or hasOneshotProtection.

On my end, I am no longer replacing the entire block (which causes you to miss your match to 0.9) and instead removing parts before and after that 0.9 and then doing my calculations based on whatever value is there.

The (or close to the) IL hook I will be switching to:

        private void HealthComponent_TakeDamage( ILContext il )
        {
            ILCursor c = new ILCursor( il );

            c.GotoNext( MoveType.After, x => x.MatchCallOrCallvirt<RoR2.HealthComponent>( "get_hasOneshotProtection" ) );
            c.GotoNext( MoveType.Before, x => x.MatchCallOrCallvirt<RoR2.HealthComponent>( "get_fullCombinedHealth" ) );
            c.RemoveRange( 2 );
            c.GotoNext( MoveType.Before, x => x.MatchLdfld<RoR2.HealthComponent>( "barrier" ) );
            c.RemoveRange( 2 );
            c.GotoNext( MoveType.Before, x => x.MatchMul() );
            c.RemoveRange( 2 );
            c.EmitDelegate<Func<Single, HealthComponent, Single, Single>>( ( num, healthComp, osp ) =>
            {
                var temp = num;
                temp -= healthComp.shield;
                temp -= healthComp.barrier;

                var protection = healthComp.fullHealth * osp;
                if( temp <= protection )
                {
                    return num;
                }
                temp -= healthComp.fullHealth * ( 1f + ( 1f / osp ) );
                temp = Mathf.Max( 0f, temp );
                temp += protection;
                temp += healthComp.shield;
                temp += healthComp.barrier;

                return temp;
            } );
        }
harbingerofme commented 4 years ago

Fix implemented in 2af7959ec42b51c19e04a98333fda4c74a6f40de. To do:

harbingerofme commented 4 years ago

If people are currently experiencing issues with this incompatibility, you may find a prerelease of r2api and diluvian here: https://github.com/harbingerofme/R2Mods/releases/tag/Diluvian-1.0.3

harbingerofme commented 4 years ago

Should be live now.