Decompiled source of MajicsGoofsAndGaffs v1.1.0

MajicsGoofs&Gaffs.dll

Decompiled 12 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HG;
using MonoMod.RuntimeDetour;
using R2API;
using RoR2;
using RoR2.ContentManagement;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace MajicsGoofsGaffs;

public class IdolOfTheMountainController
{
	private static ItemDef _idolItem;

	private static BuffDef _idolBuff;

	private static GameObject _iconPrefab;

	private static Dictionary<CharacterBody, GameObject> _activeIcons = new Dictionary<CharacterBody, GameObject>();

	public static AssetBundle MyBundle;

	public static void Init(ItemDef item, BuffDef buff, AssetBundle assetBundle)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		_idolItem = item;
		_idolBuff = buff;
		MyBundle = assetBundle;
		if (!((Object)(object)_idolItem == (Object)null) && !((Object)(object)_idolBuff == (Object)null))
		{
			RecalculateStatsAPI.GetStatCoefficients += new StatHookEventHandler(OnGetStatCoefficients);
			new Hook((MethodBase)typeof(CharacterBody).GetMethod("FixedUpdate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic), typeof(IdolOfTheMountainController).GetMethod("CharacterBody_FixedUpdate", BindingFlags.Static | BindingFlags.NonPublic));
			if ((Object)(object)MyBundle != (Object)null)
			{
				_iconPrefab = MyBundle.LoadAsset<GameObject>("IdolHeadIcon");
			}
			else
			{
				Debug.LogError((object)"MajicsGoofsGaffs: MyBundle is null! Cannot load IdolHeadIcon prefab.");
			}
		}
	}

	private static void OnGetStatCoefficients(CharacterBody sender, StatHookEventArgs args)
	{
		if (Object.op_Implicit((Object)(object)sender.inventory))
		{
			int itemCount = sender.inventory.GetItemCount(_idolItem);
			if (itemCount > 0 && sender.HasBuff(_idolBuff))
			{
				args.damageMultAdd += 0.15f * (float)itemCount;
				args.healthMultAdd += 0.15f * (float)itemCount;
				args.moveSpeedMultAdd += 0.15f * (float)itemCount;
				args.attackSpeedMultAdd += 0.15f * (float)itemCount;
				args.armorAdd += 15f * (float)itemCount;
				args.critAdd += 5f * (float)itemCount;
				args.critDamageMultAdd += 0.15f * (float)itemCount;
				args.baseRegenAdd += 1.5f * (float)itemCount;
			}
		}
	}

	private static void CharacterBody_FixedUpdate(Action<CharacterBody> orig, CharacterBody self)
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		orig(self);
		if (!Object.op_Implicit((Object)(object)self) || !Object.op_Implicit((Object)(object)self.inventory) || !Object.op_Implicit((Object)(object)self.healthComponent) || !self.healthComponent.alive || self.inventory.GetItemCount(_idolItem) <= 0)
		{
			return;
		}
		Vector3 val = (Object.op_Implicit((Object)(object)self.coreTransform) ? self.coreTransform.position : ((Component)self).gameObject.transform.position);
		TeleporterInteraction instance = TeleporterInteraction.instance;
		bool flag = false;
		if (Object.op_Implicit((Object)(object)instance) && instance.isCharging)
		{
			HoldoutZoneController val2 = ((Component)instance).GetComponent<HoldoutZoneController>() ?? ((Component)instance).GetComponentInChildren<HoldoutZoneController>();
			if (Object.op_Implicit((Object)(object)val2))
			{
				float currentRadius = val2.currentRadius;
				Vector3 val3 = val - ((Component)instance).transform.position;
				flag = ((Vector3)(ref val3)).sqrMagnitude <= currentRadius * currentRadius;
			}
		}
		if (flag)
		{
			if (!self.HasBuff(_idolBuff))
			{
				self.AddBuff(_idolBuff);
			}
			if (!_activeIcons.ContainsKey(self) || (Object)(object)_activeIcons[self] == (Object)null)
			{
				SpawnHeadIcon(self);
			}
		}
		else
		{
			if (self.HasBuff(_idolBuff))
			{
				self.RemoveBuff(_idolBuff);
			}
			RemoveHeadIcon(self);
		}
	}

	private static void SpawnHeadIcon(CharacterBody body)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_iconPrefab == (Object)null))
		{
			Transform val = (Object.op_Implicit((Object)(object)body.coreTransform) ? body.coreTransform : body.transform);
			GameObject val2 = Object.Instantiate<GameObject>(_iconPrefab, val);
			val2.transform.localPosition = new Vector3(0f, 2.5f, 0f);
			_activeIcons[body] = val2;
		}
	}

	private static void RemoveHeadIcon(CharacterBody body)
	{
		if (_activeIcons.TryGetValue(body, out var value))
		{
			if ((Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)value);
			}
			_activeIcons.Remove(body);
		}
	}
}
public class MajicsGoofsGaffsContent : IContentPackProvider
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static StatHookEventHandler <>9__15_0;

		internal void <FinalizeAsync>b__15_0(CharacterBody body, StatHookEventArgs statArgs)
		{
			if (Object.op_Implicit((Object)(object)body.inventory))
			{
				int itemCount = body.inventory.GetItemCount(_myItem);
				if (itemCount > 0)
				{
					statArgs.attackSpeedMultAdd += 0.1f * (float)itemCount;
					statArgs.critDamageMultAdd += 0.1f * (float)itemCount;
					statArgs.damageMultAdd += 0.1f * (float)itemCount;
					statArgs.healthMultAdd += 0.1f * (float)itemCount;
					statArgs.jumpPowerMultAdd += 0.1f * (float)itemCount;
					statArgs.moveSpeedMultAdd += 0.1f * (float)itemCount;
					statArgs.regenMultAdd += 0.1f * (float)itemCount;
					statArgs.shieldMultAdd += 0.1f * (float)itemCount;
					statArgs.critAdd += 1f * (float)itemCount;
				}
			}
		}
	}

	private static ItemDef _myItem;

	private static ItemDef _allItemsItem;

	private static ItemDef _allItemsItemConsumed;

	private static ItemDef _idolItem;

	private static BuffDef _idolBuff;

	private static AssetBundle _myBundle;

	public string identifier => "com.MajicSpoon.MajicsGoofsGaffs";

	public static ReadOnlyContentPack readOnlyContentPack => new ReadOnlyContentPack(MajicsGoofsGaffsContentPack);

	internal static ContentPack MajicsGoofsGaffsContentPack { get; } = new ContentPack();

	public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
	{
		AssetBundleCreateRequest asyncOperation = AssetBundle.LoadFromFileAsync(MajicsGoofsGaffsMain.assetBundleDir);
		while (!((AsyncOperation)asyncOperation).isDone)
		{
			args.ReportProgress(((AsyncOperation)asyncOperation).progress);
			yield return null;
		}
		_myBundle = asyncOperation.assetBundle;
		_myItem = _myBundle.LoadAsset<ItemDef>("MyItem");
		_allItemsItem = _myBundle.LoadAsset<ItemDef>("AllItemsItem");
		_allItemsItemConsumed = _myBundle.LoadAsset<ItemDef>("AllItemsItemConsumed");
		_idolItem = _myBundle.LoadAsset<ItemDef>("IdolOfTheMountain");
		_idolBuff = _myBundle.LoadAsset<BuffDef>("bdIdolOfTheMountain");
		List<ItemDef> list = new List<ItemDef>();
		if ((Object)(object)_myItem != (Object)null)
		{
			list.Add(_myItem);
		}
		else
		{
			MajicsGoofsGaffsMain.LogError("Failed to load asset: MyItem");
		}
		if ((Object)(object)_allItemsItem != (Object)null)
		{
			list.Add(_allItemsItem);
		}
		else
		{
			MajicsGoofsGaffsMain.LogError("Failed to load asset: AllItemsItem");
		}
		if ((Object)(object)_allItemsItemConsumed != (Object)null)
		{
			list.Add(_allItemsItemConsumed);
		}
		else
		{
			MajicsGoofsGaffsMain.LogError("Failed to load asset: AllItemsItemConsumed");
		}
		if ((Object)(object)_idolItem != (Object)null)
		{
			list.Add(_idolItem);
		}
		else
		{
			MajicsGoofsGaffsMain.LogError("Failed to load asset: IdolOfTheMountain");
		}
		MajicsGoofsGaffsContentPack.itemDefs.Add(list.ToArray());
		if ((Object)(object)_idolBuff != (Object)null)
		{
			MajicsGoofsGaffsContentPack.buffDefs.Add((BuffDef[])(object)new BuffDef[1] { _idolBuff });
		}
		args.ReportProgress(1f);
	}

	public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
	{
		ContentPack.Copy(MajicsGoofsGaffsContentPack, args.output);
		args.ReportProgress(1f);
		yield break;
	}

	public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
	{
		Inventory.onServerItemGiven += OnServerItemGiven;
		IdolOfTheMountainController.Init(_idolItem, _idolBuff, _myBundle);
		object obj = <>c.<>9__15_0;
		if (obj == null)
		{
			StatHookEventHandler val = delegate(CharacterBody body, StatHookEventArgs statArgs)
			{
				if (Object.op_Implicit((Object)(object)body.inventory))
				{
					int itemCount = body.inventory.GetItemCount(_myItem);
					if (itemCount > 0)
					{
						statArgs.attackSpeedMultAdd += 0.1f * (float)itemCount;
						statArgs.critDamageMultAdd += 0.1f * (float)itemCount;
						statArgs.damageMultAdd += 0.1f * (float)itemCount;
						statArgs.healthMultAdd += 0.1f * (float)itemCount;
						statArgs.jumpPowerMultAdd += 0.1f * (float)itemCount;
						statArgs.moveSpeedMultAdd += 0.1f * (float)itemCount;
						statArgs.regenMultAdd += 0.1f * (float)itemCount;
						statArgs.shieldMultAdd += 0.1f * (float)itemCount;
						statArgs.critAdd += 1f * (float)itemCount;
					}
				}
			};
			<>c.<>9__15_0 = val;
			obj = (object)val;
		}
		RecalculateStatsAPI.GetStatCoefficients += (StatHookEventHandler)obj;
		args.ReportProgress(1f);
		yield break;
	}

	private void OnServerItemGiven(Inventory inventory, ItemIndex itemIndex, int count)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Invalid comparison between Unknown and I4
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Invalid comparison between Unknown and I4
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Invalid comparison between Unknown and I4
		if (!NetworkServer.active || (Object)(object)_allItemsItem == (Object)null || itemIndex != _allItemsItem.itemIndex || count <= 0)
		{
			return;
		}
		Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				ItemDef current = enumerator.Current;
				if (!((Object)(object)current == (Object)null) && current.itemIndex != _allItemsItem.itemIndex && (!((Object)(object)_allItemsItemConsumed != (Object)null) || current.itemIndex != _allItemsItemConsumed.itemIndex) && ((int)current.tier == 0 || (int)current.tier == 1 || (int)current.tier == 2 || (int)current.tier == 4))
				{
					inventory.GiveItem(current.itemIndex, 1);
				}
			}
		}
		finally
		{
			((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
		}
		inventory.RemoveItem(_allItemsItem.itemIndex, count);
		if ((Object)(object)_allItemsItemConsumed != (Object)null)
		{
			inventory.GiveItem(_allItemsItemConsumed.itemIndex, count);
		}
	}

	private void AddSelf(AddContentPackProviderDelegate addContentPackProvider)
	{
		addContentPackProvider.Invoke((IContentPackProvider)(object)this);
	}

	internal MajicsGoofsGaffsContent()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(AddSelf);
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.MajicSpoon.MajicsGoofsGaffs", "Majic's Goofs & Gaffs", "0.0.1")]
public class MajicsGoofsGaffsMain : BaseUnityPlugin
{
	public const string GUID = "com.MajicSpoon.MajicsGoofsGaffs";

	public const string MODNAME = "Majic's Goofs & Gaffs";

	public const string VERSION = "0.0.1";

	public static PluginInfo pluginInfo { get; private set; }

	public static MajicsGoofsGaffsMain instance { get; private set; }

	internal static AssetBundle assetBundle { get; private set; }

	internal static string assetBundleDir => Path.Combine(Path.GetDirectoryName(pluginInfo.Location), "MajicsGoofs&GaffsAssets");

	private void Awake()
	{
		instance = this;
		pluginInfo = ((BaseUnityPlugin)this).Info;
		new MajicsGoofsGaffsContent();
	}

	internal static void LogFatal(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogFatal(data);
	}

	internal static void LogError(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogError(data);
	}

	internal static void LogWarning(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogWarning(data);
	}

	internal static void LogMessage(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogMessage(data);
	}

	internal static void LogInfo(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogInfo(data);
	}

	internal static void LogDebug(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogDebug(data);
	}
}