Decompiled source of MeleeDeflect v1.0.0

MeleeDeflect.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using DM;
using HarmonyLib;
using Landfall.TABS;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MeleeDeflect")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("GeeztJeez")]
[assembly: AssemblyProduct("MeleeDeflect")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("MeleeDeflect")]
[assembly: ComVisible(false)]
[assembly: Guid("3a45c3cf-230c-4310-952f-0887d4266a22")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace MeleeDeflect;

[BepInPlugin("GeeztJeez.MeleeDeflect", "MeleeDeflect", "1.0.0")]
internal class Loader : BaseUnityPlugin
{
	private void Awake()
	{
		((MonoBehaviour)this).StartCoroutine("Call");
	}

	private IEnumerator Call()
	{
		yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ServiceLocator>() != (Object)null));
		yield return (object)new WaitUntil((Func<bool>)(() => ServiceLocator.GetService<ISaveLoaderService>() != null));
		yield return (object)new WaitForSeconds(1f);
		_ = ContentDatabase.Instance().LandfallContentDatabase;
		new Harmony("MeleeDeflect").PatchAll();
		Debug.Log((object)"Loading MeleeDeflect");
		GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
		for (int i = 0; i < array.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)array[i].GetComponentInChildren<MeleeWeapon>()))
			{
				array[i].AddComponent<AddDeflectOnSwing>();
			}
		}
		Debug.Log((object)"Loaded MeleeDeflect Successfully!");
	}
}
public class DeflectOnSwingBehaviour : ProjectileSurfaceEffect
{
	public float minOffset = 0.75f;

	public float maxOffset = 1.1f;

	public MeleeWeapon meleeWeapon;

	public float offset = 4f;

	public override bool DoEffect(HitData hit, GameObject projectile)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		if (((Behaviour)this).enabled && Object.op_Implicit((Object)(object)meleeWeapon) && (meleeWeapon.isSwinging || meleeWeapon.canDealDamageOutSideOfSwing))
		{
			ServiceLocator.GetService<ParticlePlayer>().PlayEffect(1, hit.point, Vector3.up, (SkinnedMeshRenderer)null);
			ServiceLocator.GetService<SoundPlayer>().PlaySoundEffect("Moves/WallShield_Slam", 1.2f, projectile.transform.position, (MaterialType)0, (Transform)null, 1f);
			MoveTransform component = projectile.GetComponent<MoveTransform>();
			TeamHolder component2 = projectile.GetComponent<TeamHolder>();
			ProjectileHit component3 = projectile.GetComponent<ProjectileHit>();
			RaycastTrail component4 = projectile.GetComponent<RaycastTrail>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.velocity *= 0f - Random.Range(minOffset, maxOffset);
				component.velocity = Randomize(component.velocity, offset);
			}
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.SwitchTeam();
			}
			if (Object.op_Implicit((Object)(object)component3))
			{
				component3.canHitOrgUnit = true;
			}
			if (Object.op_Implicit((Object)(object)component4))
			{
				component4.ignoredFrames = 1;
			}
			return true;
		}
		return false;
	}

	public Vector3 Randomize(Vector3 baseVector, float offset)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		float num = baseVector.x + Random.Range(0f - offset, offset);
		float num2 = baseVector.y + Random.Range(0f - offset, offset);
		float num3 = baseVector.z + Random.Range(0f - offset, offset);
		return new Vector3(num, num2, num3);
	}
}
public class AddDeflectOnSwing : MonoBehaviour
{
	private MeleeWeapon meleeWeapon;

	private Unit unit;

	public void Start()
	{
		meleeWeapon = ((Component)this).gameObject.GetComponentInChildren<MeleeWeapon>();
		unit = ((Weapon)meleeWeapon).connectedData.unit;
		Collider[] componentsInChildren = ((Component)meleeWeapon).GetComponentsInChildren<Collider>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			((Component)componentsInChildren[i]).gameObject.AddComponent<DeflectOnSwingBehaviour>().meleeWeapon = meleeWeapon;
		}
	}
}