Decompiled source of CombinableTurrets v1.0.1

CombinableTurrets/CombinableTurrets.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using EntityStates.DroneCombiner;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.EntityStates.DroneCombiner;
using On.RoR2;
using R2API;
using RoR2;
using RoR2.Navigation;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;

[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("CombinableTurrets")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CombinableTurrets")]
[assembly: AssemblyTitle("CombinableTurrets")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CombinableTurrets;

internal static class Log
{
	private static ManualLogSource _logSource;

	internal static void Init(ManualLogSource logSource)
	{
		_logSource = logSource;
	}

	internal static void Debug(object data)
	{
		_logSource.LogDebug(data);
	}

	internal static void Error(object data)
	{
		_logSource.LogError(data);
	}

	internal static void Fatal(object data)
	{
		_logSource.LogFatal(data);
	}

	internal static void Info(object data)
	{
		_logSource.LogInfo(data);
	}

	internal static void Message(object data)
	{
		_logSource.LogMessage(data);
	}

	internal static void Warning(object data)
	{
		_logSource.LogWarning(data);
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Samuel17.CombinableTurrets", "CombinableTurrets", "1.0.1")]
public class Main : BaseUnityPlugin
{
	public static GameObject turretPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Drones/Turret1Body.prefab").WaitForCompletion();

	public static GameObject teleportHelperPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Common/DirectorSpawnProbeHelperPrefab.prefab").WaitForCompletion();

	public static SkillDef turretSkillDef = Addressables.LoadAssetAsync<SkillDef>((object)"RoR2/Base/Drones/Turret1BodyTurret.asset").WaitForCompletion();

	public static int extraBulletsPerTier = 20;

	public static float extraAtkSpeedMultiplierPerTier = 0.5f;

	public void Awake()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Expected O, but got Unknown
		Log.Init(((BaseUnityPlugin)this).Logger);
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate
		{
			DroneDef val2 = DroneCatalog.FindDroneDefFromBody(turretPrefab);
			if (Object.op_Implicit((Object)(object)val2))
			{
				val2.canCombine = true;
			}
		});
		DroneCombinerController.TryGetCombinableDrones += (Manipulator)delegate(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "bodyFlags")
			}))
			{
				val.RemoveRange(3);
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Combinable Gunner Turret hook failed!");
			}
		};
		TeleportHelper.OnTeleport_GameObject_Vector3_Vector3_Quaternion_bool += new hook_OnTeleport_GameObject_Vector3_Vector3_Quaternion_bool(TurretException);
		DroneCombinerCombining.UpgradeAndEjectDrone += new hook_UpgradeAndEjectDrone(TeleportNearby);
		RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(GunnerTurretBonus);
	}

	private void TurretException(orig_OnTeleport_GameObject_Vector3_Vector3_Quaternion_bool orig, GameObject gameObject, Vector3 newPosition, Vector3 delta, Quaternion newRotation, bool useRotation)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		CharacterBody component = gameObject.GetComponent<CharacterBody>();
		if (Object.op_Implicit((Object)(object)component) && (Object)(object)BodyCatalog.GetBodyPrefab(component.bodyIndex) == (Object)(object)turretPrefab)
		{
			gameObject.transform.position = newPosition;
		}
		else
		{
			orig.Invoke(gameObject, newPosition, delta, newRotation, useRotation);
		}
	}

	private void TeleportNearby(orig_UpgradeAndEjectDrone orig, DroneCombinerCombining self, CharacterBody drone)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Expected O, but got Unknown
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self, drone);
		if (!Object.op_Implicit((Object)(object)drone) || !((Object)(object)BodyCatalog.GetBodyPrefab(drone.bodyIndex) == (Object)(object)turretPrefab))
		{
			return;
		}
		Vector3 position = ((EntityState)self).transform.position;
		SpawnCard val = ScriptableObject.CreateInstance<SpawnCard>();
		val.hullSize = drone.hullClassification;
		val.nodeGraphType = (GraphType)0;
		val.prefab = teleportHelperPrefab;
		GameObject val2 = DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(val, new DirectorPlacementRule
		{
			placementMode = (PlacementMode)1,
			position = position,
			minDistance = 5f,
			maxDistance = 20f
		}, RoR2Application.rng));
		if (Object.op_Implicit((Object)(object)val2))
		{
			Vector3 position2 = val2.transform.position;
			TeleportHelper.TeleportBody(drone, position2, false);
			GameObject teleportEffectPrefab = Run.instance.GetTeleportEffectPrefab(((Component)drone).gameObject);
			if (Object.op_Implicit((Object)(object)teleportEffectPrefab))
			{
				EffectManager.SimpleEffect(teleportEffectPrefab, position2, Quaternion.identity, true);
			}
			Object.Destroy((Object)(object)val2);
		}
	}

	private void GunnerTurretBonus(CharacterBody body, StatHookEventArgs args)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)body) || !((Object)(object)BodyCatalog.GetBodyPrefab(body.bodyIndex) == (Object)(object)turretPrefab) || !Object.op_Implicit((Object)(object)body.inventory))
		{
			return;
		}
		int itemCountEffective = body.inventory.GetItemCountEffective(Items.DroneUpgradeHidden);
		if (itemCountEffective > 0)
		{
			args.primarySkill.bonusStockAdd += extraBulletsPerTier * itemCountEffective;
			args.attackSpeedTotalMult *= 1f + extraAtkSpeedMultiplierPerTier * (float)itemCountEffective;
			if (Object.op_Implicit((Object)(object)body.skillLocator) && Object.op_Implicit((Object)(object)body.skillLocator.primary) && Object.op_Implicit((Object)(object)body.skillLocator.primary.skillDef) && (Object)(object)body.skillLocator.primary.skillDef == (Object)(object)turretSkillDef)
			{
				body.skillLocator.primary.skillDef.rechargeStock = body.skillLocator.primary.maxStock;
			}
		}
	}
}