public override void StoreItemCount(CharacterBody self) { ArtemisBlessingComponent cpt = self.gameObject.GetComponent <ArtemisBlessingComponent>(); if (GetCount(self) > 0 || cpt) { if (!cpt) { cpt = self.gameObject.AddComponent <ArtemisBlessingComponent>(); } cpt.cachedIcnt = GetCount(self); } }
private void IL_CBTakeDamage(ILContext il) { var c = new ILCursor(il); bool ILFound; int locDmg = -1; ILFound = c.TryGotoNext( x => x.MatchLdarg(1), x => x.MatchLdfld <DamageInfo>("damage"), x => x.MatchStloc(out locDmg)); if (!ILFound) { ilFailed = true; KevinsAdditionsPlugin._logger.LogError("Failed to apply Artemis' Blessing IL patch (damage var read), item will not work; target instructions not found"); return; } FieldReference locEnemy = null; int locThis = -1; ILFound = c.TryGotoNext( x => x.MatchLdloc(2), x => x.MatchLdarg(out locThis), x => x.MatchLdfld(out locEnemy), x => x.MatchCallOrCallvirt <CharacterBody>("get_teamComponent"), x => x.MatchCallOrCallvirt <TeamComponent>("get_teamIndex")); if (!ILFound) { ilFailed = true; KevinsAdditionsPlugin._logger.LogError("Failed to apply Artemis' Blessing IL patch (damage var read), item will not work; target instructions not found"); return; } int locChrm = -1; ILFound = c.TryGotoNext( x => x.MatchLdloc(out locChrm), x => x.MatchCallOrCallvirt <CharacterMaster>("get_inventory"), x => x.MatchLdcI4((int)ItemIndex.Crowbar)) && c.TryGotoPrev(MoveType.After, x => x.OpCode == OpCodes.Brfalse); if (ILFound) { c.Emit(OpCodes.Ldloc, locChrm); c.Emit(OpCodes.Ldarg, locThis); c.Emit(OpCodes.Ldloc, locDmg); c.EmitDelegate <Func <CharacterMaster, HealthComponent, float, float> >((chrm, body, origdmg) => { ArtemisBlessingComponent cpt = chrm.GetBodyObject().GetComponent <ArtemisBlessingComponent>(); if (!cpt || cpt.cachedIcnt == 0) { return(origdmg); } float aDist = (chrm.GetBody().corePosition - body.body.corePosition).magnitude; return(origdmg * (1 + (Math.Max((Math.Min(aDist, maxDist) - medDist) * effectMult, minReduction - 1.0f) * cpt.cachedIcnt))); //Damage Calculation }); c.Emit(OpCodes.Stloc, locDmg); } else { ilFailed = true; KevinsAdditionsPlugin._logger.LogError("Failed to apply Artemis' Blessing IL patch (damage var write), item will not work; target instructions not found"); return; } }
private void IL_CBDefaultHitCallback(ILContext il) // Reduces the damage falloff when equipped { var c = new ILCursor(il); bool ILFound; ArtemisBlessingComponent cpt = null; c.Emit(OpCodes.Ldarg_0); c.EmitDelegate <Action <BulletAttack> >((thing) => { cpt = thing.owner.GetComponent <ArtemisBlessingComponent>(); }); if (!cpt) { return; } ILFound = c.TryGotoNext( x => x.MatchLdcR4(0.5f), x => x.MatchLdcR4(60f), x => x.MatchLdcR4(25f), x => x.MatchLdarg(1), x => x.MatchLdfld <BulletAttack.BulletHit>("distance"), x => x.MatchCallOrCallvirt("UnityEngine.Mathf", "InverseLerp"), x => x.MatchCallOrCallvirt("UnityEngine.Mathf", "Clamp01"), x => x.MatchLdcR4(0.5f)); if (!ILFound) { ilFailed = true; KevinsAdditionsPlugin._logger.LogError("Failed to apply Artemis' Blessing IL patch (bulletfalloff var read), item will not work; target instructions not found"); return; } else { c.Next.Operand = falloffBullet; c.Index += 8; c.Next.Operand = 1f - falloffBullet; } ILFound = c.TryGotoNext( x => x.MatchLdcR4(0.25f), x => x.MatchLdcR4(25f), x => x.MatchLdcR4(7f), x => x.MatchLdarg(1), x => x.MatchLdfld <BulletAttack.BulletHit>("distance"), x => x.MatchCallOrCallvirt("UnityEngine.Mathf", "InverseLerp"), x => x.MatchCallOrCallvirt("UnityEngine.Mathf", "Clamp01"), x => x.MatchLdcR4(0.75f)); if (!ILFound) { ilFailed = true; KevinsAdditionsPlugin._logger.LogError("Failed to apply Artemis' Blessing IL patch (shotgunfalloff var read), item will not work; target instructions not found"); return; } c.Next.Operand = falloffShotgun; c.Index += 8; c.Next.Operand = 1f - falloffShotgun; }