Decompiled source of McDonaldsFix v1.0.2

McDonaldsFix.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("McDonaldsFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("McDonaldsFix")]
[assembly: AssemblyTitle("McDonaldsFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 McDonaldsFix
{
	[BepInPlugin("themorningstar.mcdonaldsfix", "McDonaldsFix", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "themorningstar.mcdonaldsfix";

		internal static ManualLogSource Log;

		internal static Plugin Instance;

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			try
			{
				new Harmony("themorningstar.mcdonaldsfix").PatchAll(typeof(Plugin).Assembly);
				Log.LogInfo((object)"McDonaldsFix v1.0.2 patches applied.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("McDonaldsFix PatchAll failed: " + ex));
			}
		}
	}
	[HarmonyPatch(typeof(PunManager), "TesterUpgradeCommandRPC")]
	internal static class PunManager_TesterUpgrade_FeedbackFix
	{
		private static readonly List<string> _pending = new List<string>();

		private static Coroutine _flush;

		private static void Postfix(string _steamID, string upgradeName)
		{
			try
			{
				PlayerAvatar instance = PlayerAvatar.instance;
				if (!((Object)(object)instance == (Object)null) && !(SemiFunc.PlayerGetSteamID(instance) != _steamID))
				{
					_pending.Add(upgradeName);
					if (_flush == null && (Object)(object)Plugin.Instance != (Object)null)
					{
						_flush = ((MonoBehaviour)Plugin.Instance).StartCoroutine(FlushSoon());
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[McDonaldsFix] upgrade feedback failed: " + ex.Message));
			}
		}

		private static IEnumerator FlushSoon()
		{
			yield return (object)new WaitForSeconds(0.5f);
			string obj = ((_pending.Count >= 5) ? $"+{_pending.Count} UPGRADES!" : ("+" + string.Join(" +", _pending)));
			_pending.Clear();
			_flush = null;
			SemiFunc.UIFocusText(obj, Color.white, AssetManager.instance.colorYellow, 3f);
		}
	}
	[HarmonyPatch(typeof(ItemToggle), "ToggleItemLogic")]
	internal static class ItemToggle_ToggleItemLogic_McDsFix
	{
		private static readonly string[] AllUpgrades = new string[9] { "MapPlayerCount", "Stamina", "ExtraJump", "Range", "Strength", "Throw", "Health", "Speed", "Launch" };

		private static readonly string[] GiftUpgrades = new string[8] { "Health", "Stamina", "ExtraJump", "Range", "Strength", "Throw", "Speed", "Launch" };

		private static readonly HashSet<int> _consumed = new HashSet<int>();

		private static void Postfix(ItemToggle __instance, bool toggle, int player)
		{
			if (!toggle || !SemiFunc.IsMasterClientOrSingleplayer() || SemiFunc.RunIsShop())
			{
				return;
			}
			ItemAttributes component = ((Component)__instance).GetComponent<ItemAttributes>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.item == (Object)null)
			{
				return;
			}
			string name = (component.item.itemName ?? "").ToLower();
			string go = ((Object)((Component)__instance).gameObject).name.ToLower().Replace("(clone)", "").Trim();
			int num;
			if (IsBigMac(name, go))
			{
				num = 1;
			}
			else if (IsHappyMeal(name, go))
			{
				num = 2;
			}
			else
			{
				if (!IsIceCream(name, go))
				{
					return;
				}
				num = 3;
			}
			if (_consumed.Add(((Object)__instance).GetInstanceID()))
			{
				switch (num)
				{
				case 1:
					ApplyBigMac(player);
					break;
				case 2:
					ApplyHappyMeal(player);
					break;
				default:
					ApplyIceCream(player);
					break;
				}
				ConsumeItem(__instance, component);
			}
		}

		private static void ConsumeItem(ItemToggle toggle, ItemAttributes attrs)
		{
			try
			{
				if ((Object)(object)StatsManager.instance != (Object)null && (Object)(object)attrs != (Object)null)
				{
					StatsManager.instance.ItemRemove(attrs.instanceName);
				}
				attrs.DisableUI(true);
				toggle.ToggleDisable(true);
				if (SemiFunc.IsMultiplayer())
				{
					if ((Object)(object)((Component)toggle).GetComponent<PhotonView>() == (Object)null)
					{
						PhysGrabObject component = ((Component)toggle).GetComponent<PhysGrabObject>();
						if ((Object)(object)component != (Object)null)
						{
							component.DestroyPhysGrabObject();
						}
						else
						{
							Plugin.Log.LogWarning((object)("[McDonaldsFix] Used item has no network view or PhysGrabObject: " + ((Object)toggle).name));
						}
					}
					else
					{
						PhotonNetwork.Destroy(((Component)toggle).gameObject);
					}
				}
				else
				{
					Object.Destroy((Object)(object)((Component)toggle).gameObject);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("[McDonaldsFix] consume failed: " + ex.Message));
			}
		}

		private static bool IsBigMac(string name, string go)
		{
			if (!name.Contains("bigmac") && !name.Contains("big mac") && !go.Contains("bigmac"))
			{
				return go.Contains("big mac");
			}
			return true;
		}

		private static bool IsHappyMeal(string name, string go)
		{
			if (!name.Contains("happymeal") && !name.Contains("happy meal") && !go.Contains("happymeal"))
			{
				return go.Contains("happy meal");
			}
			return true;
		}

		private static bool IsIceCream(string name, string go)
		{
			if (!name.Contains("icecream") && !name.Contains("ice cream") && !go.Contains("icecream"))
			{
				return go.Contains("ice cream");
			}
			return true;
		}

		private static void ApplyBigMac(int playerPhotonID)
		{
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(playerPhotonID);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)$"[McDonaldsFix] Big Mac: no player found for photon ID {playerPhotonID}");
				return;
			}
			val.playerHealth.HealOther(75, true);
			Plugin.Log.LogInfo((object)$"[McDonaldsFix] Big Mac → heal 75 HP → player {playerPhotonID}");
		}

		private static void ApplyHappyMeal(int playerPhotonID)
		{
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(playerPhotonID);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)$"[McDonaldsFix] Happy Meal: no player found for photon ID {playerPhotonID}");
				return;
			}
			string steamID = SemiFunc.PlayerGetSteamID(val);
			string text = GiftUpgrades[Random.Range(0, GiftUpgrades.Length)];
			BroadcastUpgrade(steamID, text, 1);
			Plugin.Log.LogInfo((object)$"[McDonaldsFix] Happy Meal → '{text}' upgrade → player {playerPhotonID}");
		}

		private static void ApplyIceCream(int playerPhotonID)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(playerPhotonID);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)$"[McDonaldsFix] Ice Cream: no player found for photon ID {playerPhotonID}");
			}
			else if (Random.Range(0, 2) == 0)
			{
				string steamID = SemiFunc.PlayerGetSteamID(val);
				string[] allUpgrades = AllUpgrades;
				foreach (string upgradeName in allUpgrades)
				{
					BroadcastUpgrade(steamID, upgradeName, 1);
				}
				Plugin.Log.LogInfo((object)$"[McDonaldsFix] Ice Cream → ALL upgrades → player {playerPhotonID}");
			}
			else
			{
				val.playerHealth.HurtOther(9999, Vector3.zero, false, -1, false);
				Plugin.Log.LogInfo((object)$"[McDonaldsFix] Ice Cream → KILL → player {playerPhotonID}");
			}
		}

		private static void BroadcastUpgrade(string steamID, string upgradeName, int amount)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.IsMultiplayer())
			{
				PunManager.instance.photonView.RPC("TesterUpgradeCommandRPC", (RpcTarget)0, new object[3] { steamID, upgradeName, amount });
			}
			else
			{
				PunManager.instance.TesterUpgradeCommandRPC(steamID, upgradeName, amount, default(PhotonMessageInfo));
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}