Decompiled source of Empress BetterUpgradesFixer v1.1.0

EmpressBetterUpgradesFixer.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.Events;

[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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmpressBetterUpgradesFixer")]
[assembly: AssemblyTitle("EmpressBetterUpgradesFixer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EmpressBetterUpgradesFixer
{
	[BepInPlugin("Fixes.EmpressBetterUpgrades", "Empress BetterUpgrades Fixer", "1.2.0")]
	public class EmpressBetterUpgradesFixer : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		public static Harmony MyHarmony;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			MyHarmony = new Harmony("Fixes.EmpressBetterUpgrades");
			MyHarmony.Patch((MethodBase)AccessTools.Method(typeof(GameObject), "AddComponent", new Type[1] { typeof(Type) }, (Type[])null), new HarmonyMethod(typeof(FixerPatches), "AddComponent_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MyHarmony.Patch((MethodBase)AccessTools.Method(typeof(ItemToggle), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(FixerPatches), "ItemToggle_Start_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Log.LogInfo((object)"Empress BetterUpgrades Fixer initialized.");
		}
	}
	public static class FixerPatches
	{
		public static bool AddComponent_Prefix(GameObject __instance, Type componentType, ref Component __result)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			if (((Object)__instance).name == "BetterUpgrades_Quarantine")
			{
				return true;
			}
			if (componentType.FullName == "BetterUpgrades.BetterUpgrades")
			{
				EmpressBetterUpgradesFixer.Log.LogInfo((object)"BetterUpgrades detected. Diverting to Quarantine.");
				try
				{
					GameObject val = new GameObject("BetterUpgrades_Quarantine");
					val.SetActive(false);
					Object.DontDestroyOnLoad((Object)(object)val);
					Component val2 = val.AddComponent(componentType);
					InitializeBetterUpgrades((BaseUnityPlugin)(object)((val2 is BaseUnityPlugin) ? val2 : null), componentType);
					__result = val2;
					return false;
				}
				catch (Exception ex)
				{
					EmpressBetterUpgradesFixer.Log.LogError((object)("Quarantine failed: " + ex.Message));
					return true;
				}
			}
			return true;
		}

		private static void InitializeBetterUpgrades(BaseUnityPlugin plugin, Type modType)
		{
			try
			{
				Traverse val = Traverse.Create((object)plugin);
				MethodInfo method = typeof(BaseUnityPlugin).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic);
				if (method != null)
				{
					method.Invoke(plugin, null);
				}
				val.Property("Instance", (object[])null).SetValue((object)plugin);
				((Component)plugin).gameObject.transform.parent = null;
				((Object)((Component)plugin).gameObject).hideFlags = (HideFlags)61;
				string location = modType.Assembly.Location;
				string text = Path.Combine(Path.GetDirectoryName(location), "betterupgrades");
				AssetBundle val2 = null;
				foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
				{
					if (((Object)allLoadedAssetBundle).name == "betterupgrades")
					{
						val2 = allLoadedAssetBundle;
					}
				}
				if ((Object)(object)val2 == (Object)null && File.Exists(text))
				{
					val2 = AssetBundle.LoadFromFile(text);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val.Field("assetBundle").SetValue((object)val2);
					GameObject[] source = val2.LoadAllAssets<GameObject>();
					List<string> list = new List<string>
					{
						"Item Upgrade Player Grab Strength Two", "Item Upgrade Player Grab Strength Three", "Item Upgrade Player Energy Two", "Item Upgrade Player Energy Three", "Item Upgrade Player Extra Jump Two", "Item Upgrade Player Extra Jump Three", "Item Upgrade Player Grab Range Two", "Item Upgrade Player Grab Range Three", "Item Upgrade Player Health Two", "Item Upgrade Player Health Three",
						"Item Upgrade Player Sprint Speed Two", "Item Upgrade Player Sprint Speed Three", "Item Upgrade Player Tumble Launch Two", "Item Upgrade Player Tumble Launch Three"
					};
					foreach (string item in list)
					{
						Item itemAsset = val2.LoadAsset<Item>("Assets/Upgrades/" + item + ".asset");
						if ((Object)(object)itemAsset != (Object)null)
						{
							GameObject val3 = ((IEnumerable<GameObject>)source).FirstOrDefault((Func<GameObject, bool>)delegate(GameObject go)
							{
								ItemAttributes component = go.GetComponent<ItemAttributes>();
								return (Object)(object)component != (Object)null && (Object)(object)component.item == (Object)(object)itemAsset;
							});
							if ((Object)(object)val3 != (Object)null)
							{
								Items.RegisterItem(val3.GetComponent<ItemAttributes>());
								EmpressBetterUpgradesFixer.Log.LogInfo((object)("Registered: " + item));
							}
						}
					}
				}
				Type nestedType = modType.GetNestedType("Configuration", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (nestedType != null)
				{
					MethodInfo method2 = nestedType.GetMethod("Init", BindingFlags.Static | BindingFlags.Public);
					if (method2 != null)
					{
						method2.Invoke(null, new object[1] { plugin.Config });
					}
				}
				Type[] types = modType.Assembly.GetTypes();
				foreach (Type type in types)
				{
					bool flag = type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0;
					if (!flag)
					{
						foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(type))
						{
							if (declaredMethod.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0)
							{
								flag = true;
								break;
							}
						}
					}
					if (flag && !type.Name.Contains("ShopManagerPatch"))
					{
						try
						{
							EmpressBetterUpgradesFixer.MyHarmony.CreateClassProcessor(type).Patch();
						}
						catch
						{
						}
					}
				}
				EmpressBetterUpgradesFixer.Log.LogInfo((object)"Empress BetterUpgrades initialized successfully.");
			}
			catch (Exception arg)
			{
				EmpressBetterUpgradesFixer.Log.LogError((object)$"Init Failed: {arg}");
			}
		}

		public static void ItemToggle_Start_Postfix(ItemToggle __instance)
		{
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			ItemToggle __instance2 = __instance;
			MonoBehaviour[] components = ((Component)__instance2).GetComponents<MonoBehaviour>();
			MonoBehaviour[] array = components;
			foreach (MonoBehaviour comp in array)
			{
				string compName = ((object)comp).GetType().Name;
				if (!compName.StartsWith("ItemUpgradePlayer"))
				{
					continue;
				}
				if (!compName.EndsWith("Two") && !compName.EndsWith("Three"))
				{
					continue;
				}
				int multiplier = 1;
				if (compName.EndsWith("Two"))
				{
					multiplier = 2;
				}
				if (compName.EndsWith("Three"))
				{
					multiplier = 3;
				}
				__instance2.onToggle.AddListener((UnityAction)delegate
				{
					//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
					//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
					PhysGrabObject component = ((Component)__instance2).GetComponent<PhysGrabObject>();
					if (__instance2.toggleState && (Object)(object)component != (Object)null && component.heldByLocalPlayer)
					{
						string text = SemiFunc.PlayerGetSteamID(SemiFunc.PlayerAvatarGetFromPhotonID(__instance2.playerTogglePhotonID));
						EmpressBetterUpgradesFixer.Log.LogInfo((object)$"Applying Upgrade {multiplier}x: {compName}");
						if (compName.Contains("SprintSpeed"))
						{
							PunManager.instance.UpgradePlayerSprintSpeed(text, multiplier);
						}
						else if (compName.Contains("Health"))
						{
							PunManager.instance.UpgradePlayerHealth(text, multiplier);
						}
						else if (compName.Contains("Energy"))
						{
							PunManager.instance.UpgradePlayerEnergy(text, multiplier);
						}
						else if (compName.Contains("GrabStrength"))
						{
							PunManager.instance.UpgradePlayerGrabStrength(text, multiplier);
						}
						else if (compName.Contains("GrabRange"))
						{
							PunManager.instance.UpgradePlayerGrabRange(text, multiplier);
						}
						else if (compName.Contains("ExtraJump"))
						{
							PunManager.instance.UpgradePlayerExtraJump(text, multiplier);
						}
						else if (compName.Contains("TumbleLaunch"))
						{
							PunManager.instance.UpgradePlayerTumbleLaunch(text, multiplier);
						}
						else if (compName.Contains("TumbleWings"))
						{
							PunManager.instance.UpgradePlayerTumbleWings(text, multiplier);
						}
						else
						{
							EmpressBetterUpgradesFixer.Log.LogWarning((object)("Unknown Upgrade Type: " + compName));
						}
						bool flag = false;
						FieldInfo[] fields = ((object)comp).GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						FieldInfo[] array2 = fields;
						foreach (FieldInfo fieldInfo in array2)
						{
							if (fieldInfo.FieldType == typeof(GameObject))
							{
								object? value = fieldInfo.GetValue(comp);
								GameObject val = (GameObject)((value is GameObject) ? value : null);
								if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<ItemUpgradeParticleEffects>() != (Object)null)
								{
									Object.Instantiate<GameObject>(val, ((Component)__instance2).transform.position, Quaternion.identity);
									flag = true;
									break;
								}
							}
						}
						if (!flag)
						{
							MethodInfo method = ((object)comp).GetType().GetMethod("PlayerUpgrade");
							if (method != null)
							{
								method.Invoke(comp, null);
							}
						}
						PhotonNetwork.Destroy(((Component)__instance2).gameObject);
					}
				});
			}
		}
	}
}