Decompiled source of LuckyBlocks64 v1.1.0

plugins/com.github.MiiMii1205.LuckyBlocks64.dll

Decompiled 2 weeks ago
using System;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Core.Extensions;
using PEAKLib.Items.UnityEditor;
using Photon.Pun;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI.Extensions;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.MiiMii1205.LuckyBlocks64")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+a0dbb1c3b7aff7e645d401db55ef16cc00ce6507")]
[assembly: AssemblyProduct("com.github.MiiMii1205.LuckyBlocks64")]
[assembly: AssemblyTitle("LuckyBlocks64")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace LuckyBlocks64
{
	public class Block64MaterialChanger : MonoBehaviour
	{
		public MeshRenderer m_blockRenderer;

		private void Awake()
		{
			Block64Plugin.LuckyBlock64Type.SettingChanged += UpdateMaterial;
		}

		private void UpdateMaterial(object sender, EventArgs e)
		{
			UpdateMaterial();
		}

		private void UpdateMaterial()
		{
			((Renderer)m_blockRenderer).sharedMaterial = Block64Plugin.LuckyBlock64Material;
		}

		private void OnDestroy()
		{
			Block64Plugin.LuckyBlock64Type.SettingChanged -= UpdateMaterial;
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.github.MiiMii1205.LuckyBlocks64", "LuckyBlocks64", "1.1.0")]
	public class Block64Plugin : BaseUnityPlugin
	{
		private bool m_isLoaded;

		public static readonly Dictionary<BlockTypes, Texture2D> LuckyBlockTextures = new Dictionary<BlockTypes, Texture2D>();

		public static readonly Dictionary<BlockTypes, Color> LuckyBlockParticleColors = new Dictionary<BlockTypes, Color>();

		private static readonly int BaseTexture = Shader.PropertyToID("_BaseTexture");

		public const string Id = "com.github.MiiMii1205.LuckyBlocks64";

		internal static ManualLogSource Log { get; private set; } = null;


		public static Mesh LuckyBlock64Model
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get;
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			private set;
		} = null;


		public static Material LuckyBlock64Material
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get;
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			private set;
		} = null;


		public static GameObject LuckyBlock64BreakVFX
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get;
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			private set;
		} = null;


		public static SFX_Instance LuckyBlock64BreakSound
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get;
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			private set;
		} = null;


		public static ConfigEntry<BlockTypes> LuckyBlock64Type
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get;
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			private set;
		} = null;


		private static Texture LuckyBlockTexture
		{
			get
			{
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Expected I4, but got Unknown
				switch (LuckyBlock64Type.Value)
				{
				case BlockTypes.PER_BIOMES:
				{
					if ((Object)(object)Singleton<MapHandler>.Instance == (Object)null)
					{
						return (Texture)(object)LuckyBlockTextures[BlockTypes.YELLOW];
					}
					BiomeType currentBiome = Singleton<MapHandler>.Instance.GetCurrentBiome();
					switch ((int)currentBiome)
					{
					case 0:
						return (Texture)(object)LuckyBlockTextures[BlockTypes.WINGED];
					case 1:
					{
						BiomeVariant componentInChildren = MapHandler.CurrentMapSegment._segmentParent.GetComponentInChildren<BiomeVariant>();
						if (((Object)componentInChildren).name == "Ivy")
						{
							return (Texture)(object)LuckyBlockTextures[BlockTypes.YELLOW];
						}
						return (Texture)(object)LuckyBlockTextures[BlockTypes.WINGED];
					}
					case 2:
						return (Texture)(object)LuckyBlockTextures[BlockTypes.YELLOW];
					case 3:
						return (Texture)(object)LuckyBlockTextures[BlockTypes.METAL];
					case 5:
						return (Texture)(object)LuckyBlockTextures[BlockTypes.WINGED];
					case 6:
						return (Texture)(object)LuckyBlockTextures[BlockTypes.VANISH];
					case 7:
						return (Texture)(object)LuckyBlockTextures[BlockTypes.WINGED];
					default:
						throw new ArgumentOutOfRangeException("GetCurrentBiome");
					}
				}
				case BlockTypes.YELLOW:
				case BlockTypes.WINGED:
				case BlockTypes.VANISH:
				case BlockTypes.METAL:
					return (Texture)(object)LuckyBlockTextures[LuckyBlock64Type.Value];
				default:
					throw new ArgumentOutOfRangeException("LuckyBlock64Type");
				}
			}
		}

		private static Color LuckyBlockParticleColor
		{
			get
			{
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Expected I4, but got Unknown
				//IL_002c: 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_00b4: 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)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				switch (LuckyBlock64Type.Value)
				{
				case BlockTypes.PER_BIOMES:
				{
					if ((Object)(object)Singleton<MapHandler>.Instance == (Object)null)
					{
						return LuckyBlockParticleColors[BlockTypes.YELLOW];
					}
					BiomeType currentBiome = Singleton<MapHandler>.Instance.GetCurrentBiome();
					switch ((int)currentBiome)
					{
					case 0:
						return LuckyBlockParticleColors[BlockTypes.WINGED];
					case 1:
					{
						BiomeVariant componentInChildren = MapHandler.CurrentMapSegment._segmentParent.GetComponentInChildren<BiomeVariant>();
						if (((Object)componentInChildren).name == "Ivy")
						{
							return LuckyBlockParticleColors[BlockTypes.YELLOW];
						}
						return LuckyBlockParticleColors[BlockTypes.WINGED];
					}
					case 2:
						return LuckyBlockParticleColors[BlockTypes.YELLOW];
					case 3:
						return LuckyBlockParticleColors[BlockTypes.METAL];
					case 5:
						return LuckyBlockParticleColors[BlockTypes.WINGED];
					case 6:
						return LuckyBlockParticleColors[BlockTypes.VANISH];
					case 7:
						return LuckyBlockParticleColors[BlockTypes.WINGED];
					default:
						throw new ArgumentOutOfRangeException("GetCurrentBiome");
					}
				}
				case BlockTypes.YELLOW:
				case BlockTypes.WINGED:
				case BlockTypes.VANISH:
				case BlockTypes.METAL:
					return LuckyBlockParticleColors[LuckyBlock64Type.Value];
				default:
					throw new ArgumentOutOfRangeException("LuckyBlock64Type");
				}
			}
		}

		public static Renderer LuckyBlockRenderer
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get;
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			set;
		} = null;


		public static string Name => "LuckyBlocks64";

		public static string Version => "1.1.0";

		private void Awake()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			BundleLoader.LoadBundleWithName((BaseUnityPlugin)(object)this, "lucky64.peakbundle", (Action<PeakBundle>)LoadBundle);
			LuckyBlock64Type = ((BaseUnityPlugin)this).Config.Bind<BlockTypes>("General", "Block Type", BlockTypes.YELLOW, "Which type of block to use. Visual only: doesn't change the mechanics at all. (YELLOW=yellow, WINGED=red, VANISH=blue, METAL=green, PER_BIOMES=matches the current biome)");
			LuckyBlock64Type.SettingChanged += RefreshBlockGraphics;
			SceneManager.sceneLoaded += RefreshPerBiomeBlocks;
			Harmony val = new Harmony("com.github.MiiMii1205.LuckyBlocks64");
			val.PatchAll(typeof(Patcher));
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}

		private void RefreshPerBiomeBlocks(Scene arg0, LoadSceneMode arg1)
		{
			if (GameHandler.IsOnIsland && LuckyBlock64Type.Value == BlockTypes.PER_BIOMES)
			{
				RefreshBlockGraphics();
			}
		}

		private void RefreshBlockGraphics(object sender, EventArgs e)
		{
			RefreshBlockGraphics();
		}

		public static void RefreshBlockGraphics()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			LuckyBlock64Material.SetTexture(BaseTexture, LuckyBlockTexture);
			ParticleSystem component = ((Component)LuckyBlock64BreakVFX.transform.Find("Particles")).GetComponent<ParticleSystem>();
			MainModule main = component.main;
			ParticleSystemRenderer component2 = LuckyBlock64BreakVFX.GetComponent<ParticleSystemRenderer>();
			((Renderer)component2).sharedMaterial = LuckyBlock64Material;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(LuckyBlockParticleColor);
			if (Object.op_Implicit((Object)(object)LuckyBlockRenderer))
			{
				LuckyBlockRenderer.sharedMaterial = LuckyBlock64Material;
			}
		}

		private void LoadBundle(PeakBundle bundle)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			LuckyBlock64Model = bundle.LoadAsset<Mesh>("LuckyCube.fbx");
			LuckyBlock64Material = bundle.LoadAsset<Material>("M_LuckyCube64.mat");
			LuckyBlock64BreakVFX = bundle.LoadAsset<GameObject>("Lucky64Break.prefab");
			LuckyBlock64BreakSound = bundle.LoadAsset<SFX_Instance>("SFXI_Lucky64Break.asset");
			LuckyBlockTextures.Add(BlockTypes.YELLOW, bundle.LoadAsset<Texture2D>("block_y_tex.png"));
			LuckyBlockTextures.Add(BlockTypes.VANISH, bundle.LoadAsset<Texture2D>("block_v_tex.png"));
			LuckyBlockTextures.Add(BlockTypes.METAL, bundle.LoadAsset<Texture2D>("block_m_tex.png"));
			LuckyBlockTextures.Add(BlockTypes.WINGED, bundle.LoadAsset<Texture2D>("block_w_tex.png"));
			LuckyBlockParticleColors.Add(BlockTypes.YELLOW, new Color(0.9215686f, 49f / 85f, 0.2745098f, 1f));
			LuckyBlockParticleColors.Add(BlockTypes.WINGED, new Color(46f / 51f, 0.2509804f, 0.1843137f, 1f));
			LuckyBlockParticleColors.Add(BlockTypes.VANISH, new Color(0.2627451f, 0.2470588f, 41f / 51f, 1f));
			LuckyBlockParticleColors.Add(BlockTypes.METAL, new Color(0.4627451f, 0.7960784f, 0.2588235f, 1f));
			ShaderExtensions.ReplaceShaders(LuckyBlock64BreakVFX);
			Shader val = Shader.Find(((Object)LuckyBlock64Material.shader).name);
			if (Object.op_Implicit((Object)(object)val))
			{
				LuckyBlock64Material.shader = val;
			}
			Log.LogInfo((object)"Lucky 64 data is loaded!");
			RefreshBlockGraphics();
			ModDefinition modDefinition = ModDefinition.GetOrCreate(Chainloader.PluginInfos["legocool.LuckyBlocks"]);
			if (modDefinition.Content.Count >= 1)
			{
				Log.LogInfo((object)"Applying Lucky 64 patch immediately!");
				ApplyPatch(modDefinition);
				m_isLoaded = true;
				return;
			}
			Log.LogInfo((object)"Applying Lucky 64 patch later...");
			BundleLoader.OnBundleLoaded += delegate(PeakBundle b)
			{
				if (b.Contains("LuckyBlock.prefab") && b.Mod.Id == modDefinition.Id && !m_isLoaded)
				{
					ApplyPatch(modDefinition);
					m_isLoaded = true;
				}
			};
		}

		private void ApplyPatch(ModDefinition modDefinition)
		{
			Item val2 = default(Item);
			Item val4 = default(Item);
			Breakable val5 = default(Breakable);
			foreach (IContent item in modDefinition.Content)
			{
				UnityItemContent val = (UnityItemContent)(object)((item is UnityItemContent) ? item : null);
				if (val == null || !val.ItemPrefab.TryGetComponent<Item>(ref val2))
				{
					continue;
				}
				Log.LogInfo((object)"Applying Lucky 64 patch...");
				Transform val3 = ((Component)val2).transform.Find("Cube");
				MeshFilter component = ((Component)val3).GetComponent<MeshFilter>();
				MeshRenderer component2 = ((Component)component).gameObject.GetComponent<MeshRenderer>();
				component.sharedMesh = LuckyBlock64Model;
				LuckyBlockRenderer = (Renderer)(object)component2;
				((Renderer)component2).sharedMaterial = LuckyBlock64Material;
				ShaderExtensions.ReplaceShaders(((Component)component).gameObject);
				LuckyBreakable component3 = val.ItemPrefab.GetComponent<LuckyBreakable>();
				LuckyClientBreakable orAddComponent = ExtensionMethods.GetOrAddComponent<LuckyClientBreakable>(val.ItemPrefab);
				orAddComponent.m_minBreakVelocity = component3.minBreakVelocity;
				orAddComponent.item = component3.item;
				orAddComponent.m_breakOnCollision = component3.breakOnCollision;
				orAddComponent.m_instantiateOnBreak = component3.instantiateNonItemOnBreak;
				LuckyClientBreakable luckyClientBreakable = orAddComponent;
				if (luckyClientBreakable.breakSfx == null)
				{
					luckyClientBreakable.breakSfx = new List<SFX_Instance>();
				}
				luckyClientBreakable = orAddComponent;
				if (luckyClientBreakable.m_instantiateOnBreak == null)
				{
					luckyClientBreakable.m_instantiateOnBreak = new List<GameObject>();
				}
				orAddComponent.breakSfx.Add(LuckyBlock64BreakSound);
				orAddComponent.m_instantiateOnBreak.Add(LuckyBlock64BreakVFX);
				Block64MaterialChanger orAddComponent2 = ExtensionMethods.GetOrAddComponent<Block64MaterialChanger>(val.ItemPrefab);
				orAddComponent2.m_blockRenderer = component2;
				if (!ItemDatabase.TryGetItem((ushort)36, ref val4) || !((Component)val4).TryGetComponent<Breakable>(ref val5))
				{
					continue;
				}
				foreach (SFX_Instance item2 in val5.breakSFX)
				{
					if (((Object)item2).name != "SFXI Break Coconut 1")
					{
						orAddComponent.breakSfx.Add(item2);
					}
				}
			}
		}
	}
	public enum BlockTypes
	{
		YELLOW,
		WINGED,
		VANISH,
		METAL,
		PER_BIOMES
	}
	[RequireComponent(typeof(PhotonView))]
	public class LuckyClientBreakable : MonoBehaviour
	{
		public Item item;

		public bool m_breakOnCollision = true;

		public float m_minBreakVelocity = 5f;

		public List<SFX_Instance> breakSfx = new List<SFX_Instance>();

		public List<GameObject> m_instantiateOnBreak = new List<GameObject>();

		private Rigidbody m_rig;

		private bool m_alreadyBroke;

		private void Awake()
		{
			if (item == null)
			{
				item = ((Component)this).GetComponent<Item>();
			}
			if (m_rig == null)
			{
				m_rig = ((Component)this).GetComponent<Rigidbody>();
			}
		}

		private void OnCollisionEnter(Collision collision)
		{
			//IL_0006: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			if ((int)item.itemState == 0 && m_breakOnCollision && Object.op_Implicit((Object)(object)item.rig))
			{
				Vector3 relativeVelocity = collision.relativeVelocity;
				if (!(((Vector3)(ref relativeVelocity)).magnitude <= m_minBreakVelocity))
				{
					Break(collision);
				}
			}
		}

		public void Break(Collision coll)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!m_alreadyBroke)
			{
				m_alreadyBroke = true;
				Vector3 position = ((Component)this).transform.position;
				PlayBreakSfx(position);
				PlayBreakVfx(position);
			}
		}

		private void PlayBreakVfx(Vector3 pos)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			int i = 0;
			Rigidbody val2 = default(Rigidbody);
			for (int count = m_instantiateOnBreak.Count; i < count; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(m_instantiateOnBreak[i], pos, ((Component)this).transform.rotation);
				if (val.TryGetComponent<Rigidbody>(ref val2))
				{
					val2.linearVelocity = item.rig.linearVelocity;
					val2.angularVelocity = item.rig.angularVelocity;
				}
			}
		}

		private void PlayBreakSfx(Vector3 pos)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			int i = 0;
			for (int count = breakSfx.Count; i < count; i++)
			{
				breakSfx[i].Play(pos);
			}
		}
	}
	public static class Patcher
	{
		[HarmonyPatch(typeof(MountainProgressHandler), "TriggerReached")]
		[HarmonyPrefix]
		public static void TriggerReachedPost(MountainProgressHandler __instance, ProgressPoint progressPoint, bool isFurthestPoint = true)
		{
			if (Block64Plugin.LuckyBlock64Type.Value == BlockTypes.PER_BIOMES)
			{
				Block64Plugin.RefreshBlockGraphics();
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}