Decompiled source of SuperArchers v36.0.0

Archery Range.dll

Decompiled a month ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using Voxels.TowerDefense;
using Voxels.TowerDefense.Ballistics;
using Voxels.TowerDefense.Upgrades;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Archery Range")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Archery Range")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0ed01aa3-43f4-4f37-bf64-a72520b8fc0b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BadNorthArcheryMod;

[BepInPlugin("com.zazaxc.superarchers", "Super Archers V36 Adjustable Range", "36.0.0")]
public class SuperArchersPlugin : BaseUnityPlugin
{
	public static List<Archery> EnglishArchers = new List<Archery>();

	public static Dictionary<Archery, float> ArcherLastActiveTime = new Dictionary<Archery, float>();

	public const float AttackRange = 70f;

	public const float AttackRangeSqr = 4900f;

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.zazaxc.superarchers");
		val.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Super Archers V36: Range set to {70f}");
	}
}
public static class Utility
{
	public static void CloneProjectileSettings(ProjectileSettings source, ProjectileSettings destination)
	{
		FieldInfo[] fields = typeof(ProjectileSettings).GetFields();
		FieldInfo[] array = fields;
		foreach (FieldInfo fieldInfo in array)
		{
			fieldInfo.SetValue(destination, fieldInfo.GetValue(source));
		}
	}
}
[HarmonyPatch(typeof(Archery), "Setup")]
public class Archery_Setup_Patch
{
	private static void Postfix(Archery __instance)
	{
		if (Object.op_Implicit((Object)(object)((AgentComponent)__instance).agent) && ((AgentComponent)__instance).agent.isEnglish && !SuperArchersPlugin.EnglishArchers.Contains(__instance))
		{
			SuperArchersPlugin.EnglishArchers.Add(__instance);
		}
	}
}
[HarmonyPatch(typeof(Archery), "OnDestroy")]
public class Archery_OnDestroy_Patch
{
	private static void Prefix(Archery __instance)
	{
		if (SuperArchersPlugin.EnglishArchers.Contains(__instance))
		{
			SuperArchersPlugin.EnglishArchers.Remove(__instance);
		}
		if (SuperArchersPlugin.ArcherLastActiveTime.ContainsKey(__instance))
		{
			SuperArchersPlugin.ArcherLastActiveTime.Remove(__instance);
		}
	}
}
[HarmonyPatch(typeof(LineOfSight), "SetupLineOfSight")]
public class LineOfSight_Setup_Patch
{
	private static void Postfix(LineOfSight __instance)
	{
		if (Object.op_Implicit((Object)(object)((AgentComponent)__instance).agent) && ((AgentComponent)__instance).agent.isEnglish)
		{
			float num = 70f;
			typeof(LineOfSight).GetField("radius", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(__instance, num);
			typeof(LineOfSight).GetField("sqRadius", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(__instance, num * num);
		}
	}
}
[HarmonyPatch(typeof(LineOfSight), "GetSight")]
public class LineOfSight_GetSight_Patch
{
	private static bool Prefix(LineOfSight __instance, ref Sight __result)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: 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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		if (!((AgentComponent)__instance).agent.isEnglish)
		{
			return true;
		}
		Faction enemy = ((AgentComponent)__instance).agent.faction.enemy;
		if ((Object)(object)enemy == (Object)null)
		{
			return true;
		}
		List<Agent> agents = enemy.agents;
		Agent val = null;
		float num = float.MaxValue;
		Vector3 chestPos = ((AgentComponent)__instance).agent.chestPos;
		int num2 = LayerMask.op_Implicit(LayerMaster.arrowLow);
		RaycastHit val5 = default(RaycastHit);
		for (int i = 0; i < agents.Count; i++)
		{
			Agent val2 = agents[i];
			if (!Object.op_Implicit((Object)(object)val2) || !((Component)val2).gameObject.activeInHierarchy || !val2.aliveAndGrounded.active)
			{
				continue;
			}
			Vector3 val3 = val2.chestPos - chestPos;
			float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
			if (sqrMagnitude < num && sqrMagnitude < 4900f)
			{
				val3 = val2.chestPos - chestPos;
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				Vector3 val4 = chestPos + Vector3.up * 0.5f;
				float num3 = Mathf.Sqrt(sqrMagnitude);
				if (!Physics.Raycast(val4, normalized, ref val5, num3 * 0.9f, num2))
				{
					num = sqrMagnitude;
					val = val2;
				}
			}
		}
		if ((Object)(object)val != (Object)null)
		{
			Sight val6 = default(Sight);
			val6.agent = val;
			val6.mask0 = LayerMaster.arrowLow;
			val6.mask1 = LayerMaster.arrowHigh;
			val6.score = 0f - num;
			__instance.enemies.Clear();
			__instance.enemies.Add(val6);
			__result = val6;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(ArcheryTargeter), "InSight")]
public class ArcheryTargeter_InSight_Patch
{
	private static bool Prefix(Vector3 testPosition, Vector3 targeterPosition, ref bool __result)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		if (Vector3.Distance(testPosition, targeterPosition) < 70f)
		{
			__result = true;
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(Archery), "AimAt")]
public class Archery_AimAt_Patch
{
	private static bool Prefix(Archery __instance, TrajectoryUtility trajectory, Vector3 targetPos, Vector3 targetVelocity, ref bool __result)
	{
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: 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)
		if (!((AgentComponent)__instance).agent.isEnglish)
		{
			return true;
		}
		ArcheryFocusComponent component = ((Component)__instance).gameObject.GetComponent<ArcheryFocusComponent>();
		if ((Object)(object)component != (Object)null && component.focus != null && component.focus.active)
		{
			return true;
		}
		if (!__instance.shooting.active)
		{
			return true;
		}
		Vector3 val = targetPos - __instance.ShootPos;
		val.y = 0f;
		Vector3 val2 = ((Vector3)(ref val)).normalized * 10f;
		val2.y = 3f;
		typeof(Archery).GetField("aimDirTarget", BindingFlags.Instance | BindingFlags.Public)?.SetValue(__instance, val2);
		__result = true;
		return false;
	}
}
[HarmonyPatch(typeof(Archery), "Shoot")]
public class Archery_Shoot_Patch
{
	private static bool Prefix(Archery __instance, ref Vector3 shootDir, ref ProjectileSettings projectileSettings)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: 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_019f: Expected O, but got Unknown
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		if (!((AgentComponent)__instance).agent.isEnglish)
		{
			return true;
		}
		ArcheryFocusComponent component = ((Component)__instance).gameObject.GetComponent<ArcheryFocusComponent>();
		if ((Object)(object)component != (Object)null && component.focus != null && component.focus.active)
		{
			return true;
		}
		if (!__instance.shooting.active)
		{
			return true;
		}
		LineOfSight component2 = ((Component)__instance).GetComponent<LineOfSight>();
		Agent val = ((component2.enemies.Count > 0) ? component2.enemies[0].agent : null);
		if ((Object)(object)val == (Object)null || !val.aliveAndGrounded.active)
		{
			return false;
		}
		Vector3 chestPos = val.chestPos;
		Vector3 velocity = ((NavPos)(ref val.navPos)).velocity;
		float num = Vector3.Distance(__instance.ShootPos, chestPos);
		Vector3 val2 = chestPos - __instance.ShootPos;
		Vector3 normalized = ((Vector3)(ref val2)).normalized;
		Vector3 val3 = __instance.ShootPos + Vector3.up * 0.5f;
		RaycastHit val4 = default(RaycastHit);
		if (Physics.Raycast(val3, normalized, ref val4, num * 0.9f, LayerMask.op_Implicit(LayerMaster.arrowLow)) && (Object)(object)((Component)((RaycastHit)(ref val4)).collider).transform.root != (Object)(object)((Component)val).transform.root && (Object)(object)((Component)((RaycastHit)(ref val4)).collider).transform.root != (Object)(object)((Component)((AgentComponent)__instance).agent).transform.root)
		{
			return false;
		}
		ProjectileSettings val5 = new ProjectileSettings();
		Utility.CloneProjectileSettings(projectileSettings, val5);
		val5.maxSpeed = 100f;
		val5.drag = 0f;
		val5.startOffset = 0.6f;
		float num2 = ((num < 12f) ? (num / 10f) : (num / 5f));
		if (num2 < 0.2f)
		{
			num2 = 0.2f;
		}
		Vector3 val6 = chestPos + velocity * num2 * 1.1f;
		float num3 = Mathf.Abs(val5.gravity);
		Vector3 val7 = val6 - __instance.ShootPos;
		Vector3 val8 = new Vector3(val7.x, 0f, val7.z) / num2;
		float y = (val7.y + 0.5f * num3 * num2 * num2) / num2;
		Vector3 val9 = val8;
		val9.y = y;
		float num4 = ((AgentComponent)__instance).agent.squad.level switch
		{
			1 => 5f, 
			0 => 15f, 
			_ => 1f, 
		};
		if (num < 10f)
		{
			num4 *= 0.1f;
		}
		Vector3 val10 = Random.insideUnitSphere * num4;
		val9 += val10;
		shootDir = val9;
		projectileSettings = val5;
		typeof(Archery).GetField("aimDirTarget", BindingFlags.Instance | BindingFlags.Public)?.SetValue(__instance, Vector3.zero);
		return true;
	}
}
[HarmonyPatch(typeof(Worry), "Update")]
public class Worry_Update_Patch
{
	private static void Prefix(Worry __instance)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo field = typeof(Worry).GetField("owner", BindingFlags.Instance | BindingFlags.NonPublic);
		Agent val = (Agent)field.GetValue(__instance);
		if (!Object.op_Implicit((Object)(object)val) || !val.aliveAndGrounded.active || val.isEnglish)
		{
			return;
		}
		for (int i = 0; i < SuperArchersPlugin.EnglishArchers.Count; i++)
		{
			Archery val2 = SuperArchersPlugin.EnglishArchers[i];
			if ((Object)(object)val2 == (Object)null || !((AgentComponent)val2).agent.aliveAndGrounded.active)
			{
				continue;
			}
			bool flag = val2.aiming.active || val2.shooting.active;
			if (flag)
			{
				SuperArchersPlugin.ArcherLastActiveTime[val2] = Time.time;
			}
			bool flag2 = false;
			if (SuperArchersPlugin.ArcherLastActiveTime.TryGetValue(val2, out var value) && Time.time - value < 3f)
			{
				flag2 = true;
			}
			if (flag || flag2)
			{
				Vector3 val3 = ((AgentComponent)val2).agent.wPos - val.wPos;
				float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
				if (sqrMagnitude < 4900f)
				{
					__instance.PoseThreat((IThreat)(object)val2);
				}
			}
		}
	}
}
[HarmonyPatch(typeof(Worry), "get_valid")]
public class Worry_Valid_Patch
{
	private static void Postfix(Worry __instance, ref bool __result)
	{
		if (__result || !((Object)(object)__instance.threatComponent != (Object)null))
		{
			return;
		}
		Archery component = ((Component)__instance.threatComponent).GetComponent<Archery>();
		if ((Object)(object)component != (Object)null && ((AgentComponent)component).agent.isEnglish)
		{
			bool flag = component.aiming.active || component.shooting.active;
			bool flag2 = false;
			if (SuperArchersPlugin.ArcherLastActiveTime.TryGetValue(component, out var value) && Time.time - value < 3f)
			{
				flag2 = true;
			}
			if (flag || flag2)
			{
				__result = true;
			}
		}
	}
}
[HarmonyPatch(typeof(Archery), "GetThreatDir")]
public class Archery_GetThreatDir_Patch
{
	private static bool Prefix(Archery __instance, Agent victim, ref Vector3 __result)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: 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_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = ((AgentComponent)__instance).agent.chestPos - victim.chestPos;
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		__result = normalized;
		return false;
	}
}
[HarmonyPatch(typeof(Archery), "GetThreatDistance")]
public class Archery_GetThreatDistance_Patch
{
	private static bool Prefix(Archery __instance, Agent victim, ref float __result)
	{
		__result = 1f;
		return false;
	}
}