Decompiled source of Synced Turrets v0.1.0

SyncedTurrets.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using On.RoR2;
using R2API.Utils;
using RoR2;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SyncedTurrets")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a315658135d68a10ab86627d7d9b7adaf0924ca5")]
[assembly: AssemblyProduct("SyncedTurrets")]
[assembly: AssemblyTitle("SyncedTurrets")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SyncedTurrets;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.WPhantom.SyncedTurrets", "SyncedTurrets", "0.0.3")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class SyncedTurrets : BaseUnityPlugin
{
	private const string ModID = "com.WPhantom.SyncedTurrets";

	private const string ModName = "SyncedTurrets";

	private const string ModVer = "0.0.3";

	public void Awake()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		CharacterMaster.AddDeployable += new hook_AddDeployable(HookThingy);
	}

	private static void HookThingy(orig_AddDeployable orig, CharacterMaster self, Deployable deployable, DeployableSlot slot)
	{
		//IL_0003: 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_000b: Invalid comparison between Unknown and I4
		orig.Invoke(self, deployable, slot);
		if ((int)slot == 1)
		{
			SyncTurrets syncTurrets = ((Component)deployable).gameObject.AddComponent<SyncTurrets>();
			syncTurrets.characterMaster = self;
			syncTurrets.Init();
		}
	}
}
public class SyncTurrets : MonoBehaviour
{
	internal CharacterMaster characterMaster;

	internal void Init()
	{
		characterMaster.inventory.onInventoryChanged += UpdateInventory;
	}

	private void UpdateInventory()
	{
		if ((Object)(object)((Component)this).gameObject == (Object)null)
		{
			Object.Destroy((Object)(object)this);
			return;
		}
		CharacterMaster component = ((Component)this).gameObject.GetComponent<CharacterMaster>();
		if ((Object)(object)component == (Object)null || !Object.op_Implicit((Object)(object)component))
		{
			return;
		}
		Inventory inventory = component.inventory;
		if ((Object)(object)characterMaster.inventory == (Object)null || !Object.op_Implicit((Object)(object)characterMaster.inventory))
		{
			characterMaster = ((Component)this).gameObject.GetComponent<Deployable>().ownerMaster;
		}
		inventory.CopyItemsFrom(characterMaster.inventory);
		inventory.ResetItem(Items.WardOnLevel);
		inventory.ResetItem(Items.BeetleGland);
		inventory.ResetItem(Items.CrippleWardOnLevel);
		inventory.ResetItem(Items.ExtraLife);
		inventory.ResetItem(Items.ExtraLifeConsumed);
		inventory.GiveItem(Items.ExtraLife, inventory.GetItemCount(Items.ExtraLife));
		inventory.GiveItem(Items.ExtraLifeConsumed, inventory.GetItemCount(Items.ExtraLifeConsumed));
		int itemCount = characterMaster.inventory.GetItemCount(Items.DroneWeapons);
		inventory.ResetItem(Items.DroneWeapons);
		inventory.ResetItem(Items.DroneWeaponsBoost);
		inventory.ResetItem(Items.DroneWeaponsDisplay1);
		inventory.ResetItem(Items.DroneWeaponsDisplay2);
		if (itemCount > 0)
		{
			inventory.GiveItem(Items.DroneWeaponsBoost, itemCount);
			ItemDef val = Items.DroneWeaponsDisplay1;
			if (Random.value < 0.1f)
			{
				val = Items.DroneWeaponsDisplay2;
			}
			inventory.GiveItem(val, itemCount);
		}
		inventory.ResetItem(Items.HealingPotion);
		inventory.ResetItem(Items.HealingPotionConsumed);
		inventory.GiveItem(Items.HealingPotion, inventory.GetItemCount(Items.HealingPotion));
		inventory.GiveItem(Items.HealingPotionConsumed, inventory.GetItemCount(Items.HealingPotionConsumed));
		inventory.ResetItem(Items.ExtraLifeVoid);
		inventory.ResetItem(Items.ExtraLifeVoidConsumed);
		inventory.GiveItem(Items.ExtraLifeVoid, inventory.GetItemCount(Items.ExtraLifeVoid));
		inventory.GiveItem(Items.ExtraLifeVoidConsumed, inventory.GetItemCount(Items.ExtraLifeVoidConsumed));
		inventory.ResetItem(Items.FragileDamageBonus);
		inventory.ResetItem(Items.FragileDamageBonusConsumed);
		inventory.GiveItem(Items.FragileDamageBonus, inventory.GetItemCount(Items.FragileDamageBonus));
		inventory.GiveItem(Items.FragileDamageBonusConsumed, inventory.GetItemCount(Items.FragileDamageBonusConsumed));
		component.GetBody().RecalculateStats();
	}

	private void OnDisable()
	{
		characterMaster.inventory.onInventoryChanged -= UpdateInventory;
		Object.Destroy((Object)(object)this);
	}
}