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 UnityEngine;
using UnityEngine.UI.Extensions;
[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.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+8b187500dcedf8e42988f6b002c4d317bb434b42")]
[assembly: AssemblyProduct("com.github.MiiMii1205.LuckyBlocks64")]
[assembly: AssemblyTitle("LuckyBlocks64")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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.0.1")]
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 { get; private set; } = null;
public static Material LuckyBlock64Material { get; private set; } = null;
public static GameObject LuckyBlock64BreakVFX { get; private set; } = null;
public static SFX_Instance LuckyBlock64BreakSound { get; private set; } = null;
public static ConfigEntry<BlockTypes> LuckyBlock64Type { get; private set; } = null;
public static Renderer LuckyBlockRenderer { get; set; } = null;
public static string Name => "LuckyBlocks64";
public static string Version => "1.0.1";
private void Awake()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: 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)");
LuckyBlock64Type.SettingChanged += RefreshBlockGraphics;
Harmony val = new Harmony("com.github.MiiMii1205.LuckyBlocks64");
val.PatchAll(typeof(Patcher));
Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
}
private void RefreshBlockGraphics(object sender, EventArgs e)
{
RefreshBlockGraphics();
}
private void RefreshBlockGraphics()
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
LuckyBlock64Material.SetTexture(BaseTexture, (Texture)(object)LuckyBlockTextures[LuckyBlock64Type.Value]);
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(LuckyBlockParticleColors[LuckyBlock64Type.Value]);
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 val5 = default(Item);
Breakable val6 = 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 = val.ItemPrefab.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>();
LuckyBreakable val4 = component3;
if (val4.breakSFX == null)
{
val4.breakSFX = new List<SFX_Instance>();
}
val4 = component3;
if (val4.instantiateNonItemOnBreak == null)
{
val4.instantiateNonItemOnBreak = new List<GameObject>();
}
component3.breakSFX.Add(LuckyBlock64BreakSound);
component3.instantiateNonItemOnBreak.Add(LuckyBlock64BreakVFX);
Block64MaterialChanger orAddComponent = ExtensionMethods.GetOrAddComponent<Block64MaterialChanger>(val.ItemPrefab);
orAddComponent.m_blockRenderer = component2;
if (!ItemDatabase.TryGetItem((ushort)36, ref val5) || !((Component)val5).TryGetComponent<Breakable>(ref val6))
{
continue;
}
foreach (SFX_Instance item2 in val6.breakSFX)
{
if (((Object)item2).name != "SFXI Break Coconut 1")
{
component3.breakSFX.Add(item2);
}
}
}
}
}
public enum BlockTypes
{
YELLOW,
WINGED,
VANISH,
METAL
}
public static class Patcher
{
[HarmonyPatch(typeof(LuckyBreakable), "Break")]
[HarmonyPrefix]
public static void Break64Patch(LuckyBreakable __instance)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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)
if (__instance.instantiateNonItemOnBreak.Count <= 0)
{
return;
}
Rigidbody val2 = default(Rigidbody);
for (int i = 0; i < __instance.instantiateNonItemOnBreak.Count; i++)
{
GameObject val = Object.Instantiate<GameObject>(__instance.instantiateNonItemOnBreak[i], ((Component)__instance).transform.position, ((Component)__instance).transform.rotation);
if (val.TryGetComponent<Rigidbody>(ref val2))
{
val2.linearVelocity = __instance.item.rig.linearVelocity;
val2.angularVelocity = __instance.item.rig.angularVelocity;
}
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}