Decompiled source of Proboinas Backpack Expansion v1.1.1

plugins/BackpackExpansion.dll

Decompiled 11 months ago
using System;
using System.Collections;
using System.Collections.Generic;
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 BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using SideLoader;
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("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[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]
public class SimpleTickTimer
{
	private float TickTime = 5f;

	private float TickTimer = 0f;

	public event Action OnTick;

	public SimpleTickTimer(float tickTime, Action onTickHandler)
	{
		TickTime = tickTime;
		this.OnTick = onTickHandler;
	}

	public void Tick(float timeDelta)
	{
		TickTimer += timeDelta;
		if (TickTimer >= TickTime)
		{
			this.OnTick?.Invoke();
			TickTimer = 0f;
		}
	}
}
namespace BackpackExpansion;

[BepInPlugin("Proboina.BackpackExpansion", "BackpackExpansion", "1.1.0")]
public class BackpackExpansion : BaseUnityPlugin
{
	public const string GUID = "Proboina.BackpackExpansion";

	public const string NAME = "BackpackExpansion";

	public const string VERSION = "1.1.0";

	internal static ManualLogSource Log;

	public static BackpackExpansion Mod;

	public static ConfigEntry<bool> ExampleConfig;

	internal void Awake()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		Mod = this;
		Log = ((BaseUnityPlugin)this).Logger;
		SL.OnPacksLoaded += SL_OnPacksLoaded;
		new Harmony("Proboina.BackpackExpansion").PatchAll();
	}

	private void SL_OnPacksLoaded()
	{
		//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_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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_0107: 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_0125: Unknown result type (might be due to invalid IL or missing references)
		Log.LogMessage((object)"SL_OnPacksLoaded :: BackpackExpansion... Modifying Prefabs!");
		Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(5300170);
		UpdateColorAndPS(itemPrefab, Color.yellow, Color.yellow);
		Item itemPrefab2 = ResourcesPrefabManager.Instance.GetItemPrefab(-30115);
		UpdateColorAndPS(itemPrefab2, new Color(0.7f, 0f, 0.9f), new Color(0.7f, 0f, 0.9f));
		Item itemPrefab3 = ResourcesPrefabManager.Instance.GetItemPrefab(-30116);
		UpdateColorAndPS(itemPrefab3, new Color(1f, 0.5f, 0f), new Color(1f, 0.5f, 0f));
		Item itemPrefab4 = ResourcesPrefabManager.Instance.GetItemPrefab(-30117);
		UpdateColorAndPS(itemPrefab4, new Color(0.8f, 1f, 1f), Color.cyan);
		Item itemPrefab5 = ResourcesPrefabManager.Instance.GetItemPrefab(-30118);
		UpdateColorAndPS(itemPrefab5, new Color(0f, 0.6f, 0f), new Color(0f, 0.6f, 0f) * 10f);
	}

	private void UpdateColorAndPS(Item Item, Color LightColor, Color PSColor)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		UpdateLightComponentsOnItem(Item.GetItemVisual(), LightColor);
		UpdateParticleSystemComponentsOnItem(Item.GetItemVisual(), PSColor);
	}

	private void UpdateLightComponentsOnItem(Transform ItemVisual, Color LightColor)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		Light[] componentsInChildren = ((Component)ItemVisual).GetComponentsInChildren<Light>();
		foreach (Light val in componentsInChildren)
		{
			val.color = LightColor;
		}
	}

	private void UpdateParticleSystemComponentsOnItem(Transform ItemVisual, Color PSColor)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		ParticleSystem[] componentsInChildren = ((Component)ItemVisual).GetComponentsInChildren<ParticleSystem>();
		foreach (ParticleSystem val in componentsInChildren)
		{
			if (!(((Object)((Component)val).gameObject.transform).name == "ItemHighlight"))
			{
				ParticleSystem val2 = val;
				if ((Object)(object)val2 != (Object)null)
				{
					MainModule main = val2.main;
					((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(PSColor);
				}
			}
		}
	}
}
[HarmonyPatch(typeof(Character))]
public static class CharacterStartPatch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void Character_Start_Postfix(Character __instance)
	{
		DelayDo(delegate
		{
			if (__instance.IsWorldHost)
			{
				((InventoryMenu)__instance.CharacterUI.EnchantmentMenu).m_inventoryDisplay.m_filter.m_equipmentTypes.Add((EquipmentSlotIDs)7);
			}
		}, 10f);
	}

	public static void DelayDo(Action OnAfterDelay, float DelayTime)
	{
		((MonoBehaviour)BackpackExpansion.Mod).StartCoroutine(DoAfterDelay(OnAfterDelay, DelayTime));
	}

	public static IEnumerator DoAfterDelay(Action OnAfterDelay, float DelayTime)
	{
		yield return (object)new WaitForSeconds(DelayTime);
		OnAfterDelay();
	}
}
[HarmonyPatch(typeof(AttackSkill), "OwnerHasAllRequiredItems")]
public class AttackSkill_OwnerHasAllRequiredItems
{
	[HarmonyPrefix]
	public static bool Prefix(AttackSkill __instance, ref bool __result)
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		if (((Item)__instance).ItemID == 8100210 || ((Item)__instance).ItemID == 8100220 || ((Item)__instance).ItemID == 8100230 || ((Item)__instance).ItemID == 8100240)
		{
			for (int i = 0; i < __instance.RequiredTags.Length; i++)
			{
				Item equippedItem = ((EffectSynchronizer)__instance).OwnerCharacter.Inventory.Equipment.GetEquippedItem((EquipmentSlotIDs)7);
				if ((Object)(object)equippedItem != (Object)null && equippedItem.HasTag(__instance.RequiredTags[i].Tag))
				{
					__result = true;
					return false;
				}
			}
		}
		return true;
	}
}
[HarmonyPatch(typeof(Equipment), "AddEnchantment")]
public class Equipment_Enchantment
{
	private static void Prefix(Equipment __instance, int _enchantmentID, bool _fromSync)
	{
		Bag val = (Bag)(object)((__instance is Bag) ? __instance : null);
		if (val != null && !__instance.m_enchantmentIDs.Contains(_enchantmentID))
		{
			if (_enchantmentID == -30420)
			{
				ItemContainerStatic container = val.Container;
				((ItemContainer)container).m_bonusContainerCapacity = ((ItemContainer)container).m_bonusContainerCapacity + 10f;
			}
			if (_enchantmentID == -30446)
			{
				ItemContainerStatic container2 = val.Container;
				((ItemContainer)container2).m_bonusContainerCapacity = ((ItemContainer)container2).m_bonusContainerCapacity + 15f;
			}
			if (_enchantmentID == -30444)
			{
				ItemContainerStatic container3 = val.Container;
				((ItemContainer)container3).m_bonusContainerCapacity = ((ItemContainer)container3).m_bonusContainerCapacity + 10f;
			}
			if (_enchantmentID == -30445)
			{
				ItemContainerStatic container4 = val.Container;
				((ItemContainer)container4).m_bonusContainerCapacity = ((ItemContainer)container4).m_bonusContainerCapacity + 60f;
			}
		}
	}
}
public static class BagEnchantPatches
{
	[HarmonyPatch(typeof(Bag), "OnEquip", new Type[] { typeof(Character) })]
	public class Bag_OnEquip
	{
		[HarmonyPostfix]
		private static void Postfix(ref Bag __instance, ref Character _char)
		{
			Bag LocalScopedBag = __instance;
			if (((Equipment)__instance).m_enchantmentIDs.Contains(EnchantmentID) && (Object)(object)((EffectSynchronizer)LocalScopedBag).OwnerCharacter != (Object)null && !BagEnchantTimers.ContainsKey(__instance))
			{
				BagEnchantTimers.Add(__instance, new SimpleTickTimer(TickDuration, delegate
				{
					((EffectSynchronizer)LocalScopedBag).OwnerCharacter.Inventory.ReceiveItemReward(RewardID, RewardQty, false);
				}));
			}
		}
	}

	[HarmonyPatch(typeof(Item), "DoUpdate")]
	public class Bag_Update
	{
		[HarmonyPostfix]
		private static void Postfix(ref Item __instance)
		{
			Item obj = __instance;
			Bag val = (Bag)(object)((obj is Bag) ? obj : null);
			if (val != null && ((Equipment)val).m_enchantmentIDs.Contains(EnchantmentID) && ((EffectSynchronizer)val).OwnerCharacter.IsLocalPlayer && BagEnchantTimers.ContainsKey(val))
			{
				BagEnchantTimers[val].Tick(Time.deltaTime);
			}
		}
	}

	[HarmonyPatch(typeof(Bag), "OnUnequip", new Type[] { typeof(Character) })]
	public class Bag_OnUnEquip
	{
		[HarmonyPostfix]
		private static void Postfix(ref Bag __instance, ref Character _char)
		{
			if (((Equipment)__instance).m_enchantmentIDs.Contains(EnchantmentID) && BagEnchantTimers.ContainsKey(__instance))
			{
				BagEnchantTimers.Remove(__instance);
			}
		}
	}

	public static Dictionary<Bag, SimpleTickTimer> BagEnchantTimers = new Dictionary<Bag, SimpleTickTimer>();

	public static int EnchantmentID = -30422;

	public static int RewardID = 5600000;

	public static int RewardQty = 1;

	public static float TickDuration = 200f;
}