Decompiled source of ChillRework v1.3.3

ChillRework.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.Projectile;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ChillRework")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ChillRework")]
[assembly: AssemblyTitle("ChillRework")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ChillRework;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.RiskOfBrainrot.ChillRework", "ChillRework", "1.3.0")]
[R2APISubmoduleDependency(new string[] { "LanguageAPI", "ContentAddition", "DamageAPI", "RecalculateStatsAPI" })]
public class ChillRework : BaseUnityPlugin
{
	public static GameObject iceExplosion;

	private Texture2D iceBombTex;

	public const string guid = "com.RiskOfBrainrot.ChillRework";

	public const string teamName = "RiskOfBrainrot";

	public const string modName = "ChillRework";

	public const string version = "1.3.0";

	public static BuffDef ChillBuff;

	public static ModdedDamageType ChillOnHit;

	public static ModdedDamageType MultiChillOnHit;

	public const string chillKeywordToken = "2R4R_KEYWORD_CHILL";

	public const int chillStacksMax = 10;

	public const int chillStacksOnFreeze = 3;

	public const float chillProcDuration = 8f;

	public const int chillProcChance = 100;

	private readonly Dictionary<GameObject, GameObject> frozenBy = new Dictionary<GameObject, GameObject>();

	public static PluginInfo PInfo { get; private set; }

	public static event Action<CharacterBody, CharacterBody> OnMaxChill;

	public static EffectDef RegisterEffect(GameObject effect)
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Expected O, but got Unknown
		if ((Object)(object)effect == (Object)null)
		{
			Debug.LogError((object)"Effect prefab was null");
			return null;
		}
		EffectComponent component = effect.GetComponent<EffectComponent>();
		if ((Object)(object)component == (Object)null)
		{
			Debug.LogErrorFormat("Effect prefab: \"{0}\" does not have an EffectComponent.", new object[1] { ((Object)effect).name });
			return null;
		}
		VFXAttributes component2 = effect.GetComponent<VFXAttributes>();
		if ((Object)(object)component2 == (Object)null)
		{
			Debug.LogErrorFormat("Effect prefab: \"{0}\" does not have a VFXAttributes component.", new object[1] { ((Object)effect).name });
			return null;
		}
		ContentAddition.AddEffect(effect);
		return new EffectDef
		{
			prefab = effect,
			prefabEffectComponent = component,
			prefabVfxAttributes = component2,
			prefabName = ((Object)effect).name,
			spawnSoundEventName = component.soundName
		};
	}

	private static Texture2D CreateNewRampTex(Gradient grad)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(256, 8, (TextureFormat)4, false);
		Color[] array = (Color[])(object)new Color[8];
		for (int i = 0; i < 256; i++)
		{
			Color val2 = grad.Evaluate((float)i / 255f);
			for (int j = 0; j < 8; j++)
			{
				array[j] = val2;
			}
			val.SetPixels(i, 0, 1, 8, array);
		}
		((Texture)val).wrapMode = (TextureWrapMode)1;
		val.Apply();
		return val;
	}

	private void CreateIceNovaAssets()
	{
		iceExplosion = CreateIceExplosion();
		ContentAddition.AddProjectile(iceExplosion);
	}

	private GameObject CreateIceExplosion()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = PrefabAPI.InstantiateClone(LegacyResourcesAPI.Load<GameObject>("Prefabs/NetworkedObjects/GenericDelayBlast"), "IceDelayBlast", false);
		DelayBlast component = val.GetComponent<DelayBlast>();
		component.crit = false;
		component.procCoefficient = 1f;
		component.maxTimer = 0.25f;
		component.falloffModel = (FalloffModel)0;
		component.explosionEffect = CreateIceExplosionEffect();
		component.delayEffect = CreateIceDelayEffect();
		component.damageType = DamageTypeCombo.op_Implicit((DamageType)256);
		component.baseForce = 250f;
		ProjectileController val2 = val.AddComponent<ProjectileController>();
		return val;
	}

	private GameObject CreateIceDelayEffect()
	{
		CreateIceBombTex();
		GameObject val = PrefabAPI.InstantiateClone(LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/AffixWhiteDelayEffect"), "iceDelay", false);
		val.GetComponent<DestroyOnTimer>().duration = 0.2f;
		ParticleSystemRenderer component = ((Component)val.transform.Find("Nova Sphere")).GetComponent<ParticleSystemRenderer>();
		Material val2 = Object.Instantiate<Material>(((Renderer)component).material);
		val2.SetTexture("_RemapTex", (Texture)(object)iceBombTex);
		((Renderer)component).material = val2;
		RegisterEffect(val);
		return val;
	}

	private GameObject CreateIceExplosionEffect()
	{
		CreateIceBombTex();
		GameObject val = PrefabAPI.InstantiateClone(LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/ImpactEffects/AffixWhiteExplosion"), "IceExplosion", false);
		ParticleSystemRenderer component = ((Component)val.transform.Find("Nova Sphere")).GetComponent<ParticleSystemRenderer>();
		Material val2 = Object.Instantiate<Material>(((Renderer)component).material);
		val2.SetTexture("_RemapTex", (Texture)(object)iceBombTex);
		((Renderer)component).material = val2;
		RegisterEffect(val);
		return val;
	}

	private void CreateIceBombTex()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)iceBombTex != (Object)null))
		{
			Gradient val = new Gradient();
			val.mode = (GradientMode)0;
			val.alphaKeys = (GradientAlphaKey[])(object)new GradientAlphaKey[8]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(0f, 0.14f),
				new GradientAlphaKey(0.22f, 0.46f),
				new GradientAlphaKey(0.22f, 0.61f),
				new GradientAlphaKey(0.72f, 0.63f),
				new GradientAlphaKey(0.72f, 0.8f),
				new GradientAlphaKey(0.87f, 0.81f),
				new GradientAlphaKey(0.87f, 1f)
			};
			val.colorKeys = (GradientColorKey[])(object)new GradientColorKey[8]
			{
				new GradientColorKey(new Color(0f, 0f, 0f), 0f),
				new GradientColorKey(new Color(0f, 0f, 0f), 0.14f),
				new GradientColorKey(new Color(0.179f, 0.278f, 0.25f), 0.46f),
				new GradientColorKey(new Color(0.179f, 0.278f, 0.25f), 0.61f),
				new GradientColorKey(new Color(0.5f, 0.8f, 0.75f), 0.63f),
				new GradientColorKey(new Color(0.5f, 0.8f, 0.75f), 0.8f),
				new GradientColorKey(new Color(0.6f, 0.9f, 0.85f), 0.81f),
				new GradientColorKey(new Color(0.6f, 0.9f, 0.85f), 1f)
			};
			Gradient grad = val;
			iceBombTex = CreateNewRampTex(grad);
		}
	}

	public void Awake()
	{
		Debug.Log((object)"Chill Rework initializing!");
		CreateIceNovaAssets();
		LangFixes();
		FixSnapfreeze();
		ReworkChill();
	}

	public void ReworkChill()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		ChillBuff = Addressables.LoadAssetAsync<BuffDef>((object)"RoR2/Base/Common/bdSlow80.asset").WaitForCompletion();
		ChillBuff.canStack = true;
		ChillOnHit = DamageAPI.ReserveDamageType();
		MultiChillOnHit = DamageAPI.ReserveDamageType();
		ChillHooks();
	}

	public void LangFixes()
	{
		LanguageAPI.Add("2R4R_KEYWORD_CHILL", "<style=cKeywordName>Chilling</style><style=cSub>Has a chance to temporarily <style=cIsUtility>slow enemy speed</style> by <style=cIsDamage>80%.</style></style>");
		LanguageAPI.Add("KEYWORD_FREEZING", "<style=cKeywordName>Freezing</style><style=cSub>Freeze enemies in place and <style=cIsUtility>Chill</style> them, slowing them by 80% after they thaw. Frozen enemies are <style=cIsHealth>instantly killed</style> if below <style=cIsHealth>30%</style> health.");
		LanguageAPI.Add("ITEM_ICERING_DESC", "Hits that deal <style=cIsDamage>more than 400% damage</style> also blasts enemies with a <style=cIsDamage>runic ice blast</style>, <style=cIsUtility>Chilling</style> them for <style=cIsUtility>3s</style> <style=cStack>(+3s per stack)</style> and dealing <style=cIsDamage>250%</style> <style=cStack>(+250% per stack)</style> TOTAL damage. Recharges every <style=cIsUtility>10</style> seconds.");
		LanguageAPI.Add("ITEM_ICICLE_DESC", "Killing an enemy surrounds you with an <style=cIsDamage>ice storm</style> that deals <style=cIsDamage>600% damage per second</style> and <style=cIsUtility>Chills</style> enemies for <style=cIsUtility>1.5s</style>. The storm <style=cIsDamage>grows with every kill</style>, increasing its radius by <style=cIsDamage>1m</style>. Stacks up to <style=cIsDamage>6m</style> <style=cStack>(+6m per stack)</style>.");
		LanguageAPI.Add("MAGE_UTILITY_ICE_DESCRIPTION", "<style=cIsUtility>Freezing</style>. Create a barrier that hurts enemies for up to <style=cIsDamage>12x100% damage</style>.");
	}

	public static void ApplyChillStacks(CharacterMaster attackerMaster, CharacterBody vBody, float procChance, float chillCount = 1f, float chillDuration = 8f)
	{
		ApplyChillStacks(vBody, procChance, chillCount, chillDuration, Object.op_Implicit((Object)(object)attackerMaster) ? attackerMaster.luck : 1f);
	}

	public static void ApplyChillStacks(CharacterBody vBody, float procChance, float chillCount = 1f, float chillDuration = 8f, float luck = 1f)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; (float)i < chillCount; i++)
		{
			if (Util.CheckRoll(procChance, luck, (CharacterMaster)null))
			{
				vBody.AddTimedBuffAuthority(Buffs.Slow80.buffIndex, chillDuration);
			}
		}
	}

	public static void ApplyChillSphere(Vector3 origin, float radius, TeamIndex teamIndex, float duration = 8f, float chillCount = 3f)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		SphereSearch val = new SphereSearch();
		val.origin = origin;
		val.mask = ((LayerIndex)(ref LayerIndex.entityPrecise)).mask;
		val.radius = radius;
		val.RefreshCandidates();
		val.FilterCandidatesByHurtBoxTeam(TeamMask.GetUnprotectedTeams(teamIndex));
		val.FilterCandidatesByDistinctHurtBoxEntities();
		val.OrderCandidatesByDistance();
		List<HurtBox> list = new List<HurtBox>();
		val.GetHurtBoxes(list);
		val.ClearCandidates();
		for (int i = 0; i < list.Count; i++)
		{
			HurtBox val2 = list[i];
			CharacterBody val3 = val2.healthComponent?.body;
			if (Object.op_Implicit((Object)(object)val3))
			{
				ApplyChillStacks(val3, 100f, chillCount, duration);
			}
		}
		list.Clear();
	}

	public static float CalculateChillSlowCoefficient(int chillStacks, float baseSlowCoefficient = 0.8f)
	{
		chillStacks = Mathf.Min(chillStacks, 10);
		return Mathf.Lerp(0f, baseSlowCoefficient * 2f, (float)(chillStacks / 10));
	}

	public void FixSnapfreeze()
	{
		GameObject val = LegacyResourcesAPI.Load<GameObject>("prefabs/projectiles/MageIcewallPillarProjectile");
		ProjectileImpactExplosion componentInChildren = val.GetComponentInChildren<ProjectileImpactExplosion>();
		if (Object.op_Implicit((Object)(object)componentInChildren))
		{
			componentInChildren.destroyOnEnemy = false;
		}
	}

	public void ChillHooks()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		GlobalEventManager.ProcessHitEnemy += new hook_ProcessHitEnemy(ChillOnHitHook);
		CharacterBody.FixedUpdate += new hook_FixedUpdate(ChillOnFixedUpdate);
		GlobalEventManager.ProcessHitEnemy += new Manipulator(IceRingMultiChill);
		RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(ChillStats);
	}

	private void ChillOnFixedUpdate(orig_FixedUpdate orig, CharacterBody self)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self);
		if (self.GetBuffCount(Buffs.Slow80.buffIndex) < 10)
		{
			return;
		}
		if (NetworkServer.active)
		{
			self.ClearTimedBuffs(Buffs.Slow80.buffIndex);
			SetStateOnHurt component = ((Component)self.healthComponent).GetComponent<SetStateOnHurt>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetFrozen(2f);
			}
		}
		GameObject lastHitAttacker = self.healthComponent.lastHitAttacker;
		CharacterBody arg = default(CharacterBody);
		if ((Object)(object)lastHitAttacker != (Object)null && lastHitAttacker.TryGetComponent<CharacterBody>(ref arg))
		{
			ChillRework.OnMaxChill?.Invoke(arg, self);
		}
	}

	private void ChillStats(CharacterBody sender, StatHookEventArgs args)
	{
		int buffCount = sender.GetBuffCount(Buffs.Slow80);
		if (buffCount > 0)
		{
			args.moveSpeedReductionMultAdd -= 0.8f;
			args.moveSpeedReductionMultAdd += CalculateChillSlowCoefficient(buffCount);
		}
	}

	private void ChillStatRework(ILContext il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, "RoR.RoR2Content/Buffs", "Slow80")
		});
		float num = default(float);
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, ref num)
		});
		val.Emit(OpCodes.Ldarg_0);
		val.EmitDelegate<Func<float, CharacterBody, float>>((Func<float, CharacterBody, float>)delegate(float baseSlowCoefficient, CharacterBody body)
		{
			int buffCount = body.GetBuffCount(Buffs.Slow80);
			return CalculateChillSlowCoefficient(buffCount, baseSlowCoefficient);
		});
	}

	private void IceRingMultiChill(ILContext il)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected O, but got Unknown
		ILCursor val = new ILCursor(il);
		int itemCountLocation = 51;
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[3]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, "RoR2.RoR2Content/Items", "IceRing"),
			(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "GetItemCount"),
			(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref itemCountLocation)
		});
		int victimBodyLocation = 2;
		val.GotoNext((MoveType)2, new Func<Instruction, bool>[2]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref victimBodyLocation),
			(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, "RoR2.RoR2Content/Buffs", "Slow80")
		});
		val.GotoNext((MoveType)0, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "AddTimedBuff")
		});
		val.Remove();
		val.EmitDelegate<Action<CharacterBody, BuffDef, float>>((Action<CharacterBody, BuffDef, float>)delegate(CharacterBody victimBody, BuffDef buffDef, float duration)
		{
			ApplyChillStacks(victimBody, 100f, 3f, duration);
		});
	}

	private void ChillOnHitHook(orig_ProcessHitEnemy orig, GlobalEventManager self, DamageInfo damageInfo, GameObject victim)
	{
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		CharacterMaster attackerMaster = null;
		if ((Object)(object)damageInfo.attacker != (Object)null)
		{
			CharacterBody component = damageInfo.attacker.GetComponent<CharacterBody>();
			if ((Object)(object)component != (Object)null)
			{
				attackerMaster = component.master;
			}
		}
		if ((Object)(object)victim != (Object)null)
		{
			CharacterBody val = ((victim != null) ? victim.GetComponent<CharacterBody>() : null);
			if ((Object)(object)val != (Object)null)
			{
				float procCoefficient = damageInfo.procCoefficient;
				if (procCoefficient != 0f && !damageInfo.rejected)
				{
					if (((Enum)damageInfo.damageType.damageType).HasFlag((Enum)(object)(DamageType)256))
					{
						frozenBy[victim] = damageInfo.attacker;
						float num = 3f;
						if (((Enum)damageInfo.damageType.damageType).HasFlag((Enum)(object)(DamageType)131072))
						{
							num -= 1f;
						}
						ApplyChillStacks(attackerMaster, val, procCoefficient * 100f, num);
					}
					else
					{
						bool flag = DamageAPI.HasModdedDamageType(damageInfo, ChillOnHit);
						bool flag2 = DamageAPI.HasModdedDamageType(damageInfo, MultiChillOnHit);
						if (flag || flag2)
						{
							if (flag)
							{
								DamageAPI.RemoveModdedDamageType(damageInfo, ChillOnHit);
							}
							if (flag2)
							{
								DamageAPI.RemoveModdedDamageType(damageInfo, MultiChillOnHit);
							}
							float procChance = 100f * procCoefficient * 100f;
							ApplyChillStacks(attackerMaster, val, procChance, (!flag2) ? 1 : 3);
						}
					}
				}
			}
		}
		orig.Invoke(self, damageInfo, victim);
	}
}