Decompiled source of MoreUpgrades v1.0.3

MoreUpgrades.dll

Decompiled 11 hours ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MoreUpgrades.Properties;
using Photon.Pun;
using REPOLib.Modules;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ShrinkItemsInCart")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShrinkItemsInCart")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5e12a72d-c200-488d-940a-653d1003d96e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreUpgrades
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("bulletbot.moreupgrades", "MoreUpgrades", "1.0.3")]
	internal class Plugin : BaseUnityPlugin
	{
		internal class UpgradeItem
		{
			private static int staticId;

			internal int id;

			internal string name;

			internal string fullName;

			internal int maxAmount;

			internal int maxAmountInShop;

			internal float valueMin;

			internal float valueMax;

			internal Color mainColor;

			internal Color lightColor;

			internal Color darkColor;

			private Dictionary<string, ConfigEntryBase> configEntries;

			internal Dictionary<string, int> playerUpgrades;

			internal Item item;

			internal void AddConfig<T>(string key, T defaultValue, string description = "")
			{
				configEntries.Add(key, (ConfigEntryBase)(object)((BaseUnityPlugin)instance).Config.Bind<T>($"{name} (Upgrade Item ID: {id})", key, defaultValue, description));
			}

			internal T GetConfigValue<T>(string name)
			{
				if (!configEntries.TryGetValue(name, out var value))
				{
					throw new Exception("Missing config entry '" + name + "'.");
				}
				if (typeof(T) != value.SettingType)
				{
					throw new Exception("Type mismatch for config entry '" + name + "'. Expected: " + value.SettingType.FullName + ".");
				}
				return (T)value.BoxedValue;
			}

			internal int GetValue()
			{
				if ((Object)(object)PlayerAvatar.instance == (Object)null)
				{
					return 0;
				}
				return playerUpgrades[SemiFunc.PlayerGetSteamID(PlayerAvatar.instance)];
			}

			internal UpgradeItem(string name, int maxAmount, int maxAmountInShop, bool maxPurchase, int maxPurchaseAmount, float valueMin, float valueMax, Color mainColor = default(Color), Color lightColor = default(Color), Color darkColor = default(Color))
			{
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ff: 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_0211: Unknown result type (might be due to invalid IL or missing references)
				id = staticId;
				staticId++;
				this.name = name;
				fullName = "Item Upgrade Player " + name;
				this.maxAmount = maxAmount;
				this.maxAmountInShop = maxAmountInShop;
				this.valueMin = valueMin;
				this.valueMax = valueMax;
				this.mainColor = mainColor;
				this.lightColor = lightColor;
				this.darkColor = darkColor;
				configEntries = new Dictionary<string, ConfigEntryBase>();
				AddConfig("Enabled", defaultValue: true);
				AddConfig("Max Amount", maxAmount);
				AddConfig("Max Amount In Shop", maxAmountInShop);
				AddConfig("Min Value", valueMin);
				AddConfig("Max Value", valueMax);
				AddConfig("Has Max Purchase", maxPurchase);
				AddConfig("Max Purchase Amount", maxPurchaseAmount);
				playerUpgrades = new Dictionary<string, int>();
				item = instance.assetBundle.LoadAsset<Item>(name);
				((Object)item).name = fullName;
				item.itemAssetName = fullName;
				item.itemName = name + " Upgrade";
				item.maxAmount = maxAmount;
				item.maxAmountInShop = maxAmountInShop;
				item.maxPurchase = maxPurchase;
				item.maxPurchaseAmount = maxPurchaseAmount;
				item.value = ScriptableObject.CreateInstance<Value>();
				item.value.valueMin = valueMin;
				item.value.valueMax = valueMax;
				if ((Object)(object)item.colorPreset == (Object)null)
				{
					item.colorPreset = ScriptableObject.CreateInstance<ColorPresets>();
					item.colorPreset.colorMain = mainColor;
					item.colorPreset.colorLight = lightColor;
					item.colorPreset.colorDark = darkColor;
				}
				item.prefab = instance.assetBundle.LoadAsset<GameObject>(name + " Prefab");
				((Object)item.prefab).name = fullName;
				NetworkPrefabs.RegisterNetworkPrefab("Items/" + ((Object)item.prefab).name, item.prefab);
			}
		}

		internal class MoreUpgradesManager : MonoBehaviour
		{
			internal static MoreUpgradesManager instance;

			internal PhotonView photonView;

			internal int previousValuableCount;

			internal List<ValuableObject> currentValuables;

			internal bool missionChanged;

			internal int valuableTextLength;

			private void Awake()
			{
				instance = this;
				photonView = ((Component)this).GetComponent<PhotonView>();
				currentValuables = new List<ValuableObject>();
			}

			private void Update()
			{
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				if ((Object)(object)MissionUI.instance == (Object)null || (Object)(object)RunManager.instance == (Object)null)
				{
					return;
				}
				TextMeshProUGUI val = (TextMeshProUGUI)AccessTools.Field(typeof(MissionUI), "Text").GetValue(MissionUI.instance);
				string text = (string)AccessTools.Field(typeof(MissionUI), "messagePrev").GetValue(MissionUI.instance);
				int count = currentValuables.Count;
				UpgradeItem upgradeItem = Plugin.instance.upgradeItems.FirstOrDefault((UpgradeItem x) => x.id == 1);
				if (!SemiFunc.RunIsShop() && upgradeItem != null && upgradeItem.GetValue() != 0 && !Utility.IsNullOrWhiteSpace(((TMP_Text)val).text) && (missionChanged || previousValuableCount != count))
				{
					string text2 = ((TMP_Text)val).text;
					if (!missionChanged && previousValuableCount != count)
					{
						text2 = text2.Substring(0, text2.Length - valuableTextLength);
					}
					string text3 = $"\nValuable Count: <b>{count}</b>";
					text2 += text3;
					valuableTextLength = text3.Length;
					previousValuableCount = count;
					((TMP_Text)val).text = text2;
					AccessTools.Field(typeof(MissionUI), "messagePrev").SetValue(MissionUI.instance, text2);
					missionChanged = false;
				}
			}

			internal void Give(int upgradeItemId, string steamId)
			{
				Dictionary<string, int> playerUpgrades = Plugin.instance.upgradeItems.First((UpgradeItem x) => x.id == upgradeItemId).playerUpgrades;
				playerUpgrades[steamId]++;
				if (SemiFunc.IsMasterClient())
				{
					photonView.RPC("GiveRPC", (RpcTarget)1, new object[3]
					{
						upgradeItemId,
						steamId,
						playerUpgrades[steamId]
					});
				}
			}

			[PunRPC]
			internal void GiveRPC(int upgradeItemId, string steamID, int value)
			{
				Plugin.instance.upgradeItems.First((UpgradeItem x) => x.id == upgradeItemId).playerUpgrades[steamID] = value;
			}
		}

		private const string modGUID = "bulletbot.moreupgrades";

		private const string modName = "MoreUpgrades";

		private const string modVer = "1.0.3";

		internal static Plugin instance;

		internal ManualLogSource logger;

		private readonly Harmony harmony = new Harmony("bulletbot.moreupgrades");

		internal AssetBundle assetBundle;

		private List<UpgradeItem> _upgradeItems;

		internal float playerSprintDrainTemp;

		internal int previousValuableLength;

		internal IEnumerable<UpgradeItem> upgradeItems => _upgradeItems.Where((UpgradeItem x) => x.GetConfigValue<bool>("Enabled"));

		private void Awake()
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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)
			instance = this;
			logger = Logger.CreateLogSource("MoreUpgrades");
			harmony.PatchAll();
			assetBundle = AssetBundle.LoadFromMemory(Resources.assetbundle);
			if ((Object)(object)assetBundle == (Object)null)
			{
				logger.LogError((object)"Something went wrong when loading the asset bundle.");
				return;
			}
			_upgradeItems = new List<UpgradeItem>();
			Color val = default(Color);
			((Color)(ref val))..ctor(0.82f, 0f, 0.46f);
			UpgradeItem upgradeItem = new UpgradeItem("Sprint Usage", 5, 2, maxPurchase: false, -1, 3000f, 4000f, val, val, val);
			upgradeItem.AddConfig("Scaling Factor", 0.25f, "Formula: sprintDrainBase / (1f + (upgradeValue * scalingFactor))");
			_upgradeItems.Add(upgradeItem);
			_upgradeItems.Add(new UpgradeItem("Valuable Count", 1, 1, maxPurchase: true, 1, 3000f, 5000f));
			SceneManager.activeSceneChanged += delegate
			{
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Expected O, but got Unknown
				playerSprintDrainTemp = -1f;
				if ((Object)(object)RunManager.instance != (Object)null && (Object)(object)RunManager.instance.levelCurrent != (Object)(object)RunManager.instance.levelMainMenu)
				{
					GameObject val2 = new GameObject();
					PhotonNetwork.AllocateViewID(val2.AddComponent<PhotonView>());
					val2.AddComponent<MoreUpgradesManager>();
					((Object)val2).name = "More Upgrades Manager";
				}
			};
			logger.LogMessage((object)"MoreUpgrades has started.");
		}
	}
}
namespace MoreUpgrades.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("MoreUpgrades.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] assetbundle
		{
			get
			{
				object @object = ResourceManager.GetObject("assetbundle", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resources()
		{
		}
	}
}
namespace MoreUpgrades.Patches
{
	[HarmonyPatch(typeof(MissionUIPatch))]
	internal class MissionUIPatch
	{
		[HarmonyPatch(typeof(MissionUI), "MissionText")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(typeof(MissionUIPatch), "MissionText", (Type[])null, (Type[])null);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Stfld && ((FieldInfo)list[i].operand).Name == "messagePrev")
				{
					list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)methodInfo));
					break;
				}
			}
			return list;
		}

		private static void MissionText()
		{
			if (!((Object)(object)Plugin.MoreUpgradesManager.instance == (Object)null))
			{
				Plugin.MoreUpgradesManager.instance.missionChanged = true;
			}
		}
	}
	[HarmonyPatch(typeof(ValuableObject))]
	internal class ValuableObjectPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(ValuableObject __instance)
		{
			if (!((Object)(object)Plugin.MoreUpgradesManager.instance == (Object)null))
			{
				Plugin.MoreUpgradesManager.instance.currentValuables.Add(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(PhysGrabObject))]
	internal class PhysGrabObjectPatch
	{
		[HarmonyPatch("OnDestroy")]
		[HarmonyPostfix]
		private static void OnDestroy(PhysGrabObject __instance)
		{
			if (!((Object)(object)Plugin.MoreUpgradesManager.instance == (Object)null))
			{
				ValuableObject component = ((Component)__instance).gameObject.GetComponent<ValuableObject>();
				if (!((Object)(object)component == (Object)null) && Plugin.MoreUpgradesManager.instance.currentValuables.Contains(component))
				{
					Plugin.MoreUpgradesManager.instance.currentValuables.Remove(component);
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController))]
	internal class PlayerControllerPatch
	{
		[HarmonyPatch("FixedUpdate")]
		[HarmonyPrefix]
		private static void FixedUpdate(PlayerController ___instance, ref float ___EnergySprintDrain)
		{
			if ((Object)(object)Plugin.instance.assetBundle == (Object)null)
			{
				return;
			}
			Plugin.UpgradeItem upgradeItem = Plugin.instance.upgradeItems.FirstOrDefault((Plugin.UpgradeItem x) => x.id == 0);
			if (upgradeItem == null)
			{
				return;
			}
			int value = upgradeItem.GetValue();
			if (value != 0)
			{
				if (Plugin.instance.playerSprintDrainTemp == -1f)
				{
					Plugin.instance.playerSprintDrainTemp = ___EnergySprintDrain;
				}
				___EnergySprintDrain = Plugin.instance.playerSprintDrainTemp / (1f + (float)value * upgradeItem.GetConfigValue<float>("Scaling Factor"));
			}
		}
	}
	[HarmonyPatch(typeof(ItemUpgrade))]
	internal class ItemUpgradePatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(ItemUpgrade __instance)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			if ((Object)(object)Plugin.instance.assetBundle == (Object)null)
			{
				return;
			}
			GameObject gameObject = ((Component)__instance).gameObject;
			foreach (Plugin.UpgradeItem upgradeItem in Plugin.instance.upgradeItems)
			{
				if (gameObject.GetComponent<ItemAttributes>().item.itemAssetName == upgradeItem.fullName)
				{
					__instance.upgradeEvent = new UnityEvent();
					__instance.upgradeEvent.AddListener((UnityAction)delegate
					{
						Plugin.MoreUpgradesManager.instance.Give(upgradeItem.id, SemiFunc.PlayerGetSteamID(SemiFunc.PlayerAvatarGetFromPhotonID((int)AccessTools.Field(typeof(ItemToggle), "playerTogglePhotonID").GetValue(gameObject.GetComponent<ItemToggle>()))));
					});
				}
			}
		}
	}
	[HarmonyPatch(typeof(StatsManager))]
	internal class StatsManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void Start(StatsManager __instance)
		{
			if ((Object)(object)Plugin.instance.assetBundle == (Object)null)
			{
				return;
			}
			foreach (Plugin.UpgradeItem upgradeItem in Plugin.instance.upgradeItems)
			{
				__instance.dictionaryOfDictionaries.Add("playerUpgrade" + new string(upgradeItem.name.Where((char c) => !char.IsWhiteSpace(c)).ToArray()), upgradeItem.playerUpgrades);
			}
		}

		[HarmonyPatch("LoadItemsFromFolder")]
		[HarmonyPrefix]
		private static void LoadItemsFromFolder(StatsManager __instance, Dictionary<string, Item> ___itemDictionary)
		{
			if ((Object)(object)Plugin.instance.assetBundle == (Object)null)
			{
				return;
			}
			foreach (Plugin.UpgradeItem upgradeItem in Plugin.instance.upgradeItems)
			{
				if (!___itemDictionary.ContainsKey(upgradeItem.fullName))
				{
					___itemDictionary.Add(upgradeItem.fullName, upgradeItem.item);
				}
				List<Dictionary<string, int>> list = (List<Dictionary<string, int>>)AccessTools.Method(((object)__instance).GetType(), "AllDictionariesWithPrefix", new Type[1] { typeof(string) }, (Type[])null).Invoke(__instance, new object[1] { "item" });
				foreach (Dictionary<string, int> item in list)
				{
					item.Add(upgradeItem.fullName, 0);
				}
			}
		}
	}
}
namespace MoreUpgrades.Classes
{
	internal static class ComponentExtensions
	{
		internal static T CopyComponent<T>(this GameObject target, T source) where T : Component
		{
			Type type = ((object)source).GetType();
			Component obj = target.AddComponent(type);
			T val = (T)(object)((obj is T) ? obj : null);
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
			FieldInfo[] fields = type.GetFields(bindingAttr);
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				fieldInfo.SetValue(val, fieldInfo.GetValue(source));
			}
			return val;
		}
	}
}