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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
[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("HakitifySkulls")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("HakitifySkulls")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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]
[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 HakitifySkulls
{
[BepInPlugin("com.mrribkee.hakitifyskulls", "My first plugin", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; private set; }
private void Awake()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin com.mrribkee.hakitifyskulls is loaded!");
((Object)((Component)this).gameObject).hideFlags = (HideFlags)4;
Harmony val = new Harmony("com.mrribke.hakitifyskulls");
val.PatchAll(typeof(SkullAwakePatch));
val.PatchAll(typeof(OnCorrectUsePatch));
val.PatchAll(typeof(OffCorrectUsePatch));
}
}
public class SkullTag : MonoBehaviour
{
}
public class UKAsset<T> where T : Object
{
private T? asset;
private string path;
public T Asset
{
get
{
if ((Object)(object)asset == (Object)null)
{
asset = LoadAsset();
}
return asset;
}
}
private T LoadAsset()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
Object val = (Object)(object)Addressables.LoadAssetAsync<T>((object)path).WaitForCompletion();
return (T)(object)val;
}
public UKAsset(string key)
{
path = key;
}
}
public static class Plushie
{
public static UKAsset<GameObject> HakitaPlush { get; } = new UKAsset<GameObject>("Assets/Prefabs/Items/DevPlushies/DevPlushie (Hakita).prefab");
}
public static class EmbeddedResourceLoader
{
public static Texture2D LoadTextureFromResource(string resourceName)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
Assembly executingAssembly = Assembly.GetExecutingAssembly();
using Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
if (stream == null)
{
return null;
}
byte[] array = new byte[stream.Length];
stream.Read(array, 0, (int)stream.Length);
Texture2D val = new Texture2D(2, 2);
if (ImageConversion.LoadImage(val, array))
{
return val;
}
return null;
}
}
internal static class ReplacementLogic
{
private static Texture2D? sulfurTex;
private static Texture2D? sulfurGlowTex;
private static Texture2D? mercuryTex;
private static Texture2D? mercuryGlowTex;
private static readonly int EmissiveColorID = Shader.PropertyToID("_EmissiveColor");
private static readonly int EmissiveTexID = Shader.PropertyToID("_EmissiveTex");
private static void InitTextures()
{
if (!((Object)(object)sulfurTex != (Object)null))
{
sulfurTex = EmbeddedResourceLoader.LoadTextureFromResource("HakitifySkulls.T_HakitifySkull_Sulfur.png");
sulfurGlowTex = ConvertToRGB24(EmbeddedResourceLoader.LoadTextureFromResource("HakitifySkulls.T_HakitifySkull_SulfurGlow.png"));
mercuryTex = EmbeddedResourceLoader.LoadTextureFromResource("HakitifySkulls.T_HakitifySkull_Mercury.png");
mercuryGlowTex = ConvertToRGB24(EmbeddedResourceLoader.LoadTextureFromResource("HakitifySkulls.T_HakitifySkull_MercuryGlow.png"));
if ((Object)(object)sulfurGlowTex != (Object)null)
{
((Object)sulfurGlowTex).name = "HakitaGlowSulfur";
}
if ((Object)(object)mercuryGlowTex != (Object)null)
{
((Object)mercuryGlowTex).name = "HakitaGlowMercury";
}
}
}
internal static void OnSkullAwake(Skull skull)
{
Replace(skull);
}
private static void Replace(Skull skull)
{
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Expected O, but got Unknown
//IL_0229: Unknown result type (might be due to invalid IL or missing references)
InitTextures();
GameObject asset = Plushie.HakitaPlush.Asset;
if ((Object)(object)asset == (Object)null)
{
Plugin.Logger.LogError((object)"Plush prefab load failed");
return;
}
Transform val = ((IEnumerable<Transform>)((Component)skull).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "NewSkull"));
if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).GetComponent<SkullTag>() != (Object)null)
{
return;
}
Transform val2 = asset.transform.Find("Hakita (1)");
if ((Object)(object)val2 != (Object)null)
{
GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, ((Component)skull).transform);
val3.transform.localPosition = new Vector3(0.15f, 0f, 0.1f);
val3.transform.localRotation = Quaternion.Euler(0f, 20f, 90f);
val3.transform.localScale = Vector3.one;
Collider component = val3.GetComponent<Collider>();
if ((Object)(object)component != (Object)null)
{
component.enabled = false;
}
Renderer component2 = val3.GetComponent<Renderer>();
if ((Object)(object)component2 != (Object)null && (Object)(object)sulfurTex != (Object)null && (Object)(object)mercuryTex != (Object)null && (Object)(object)sulfurGlowTex != (Object)null && (Object)(object)mercuryGlowTex != (Object)null)
{
Material val4 = new Material(component2.material);
bool flag = ((Object)skull).name.Contains("Red");
Texture2D mainTexture = (flag ? sulfurTex : mercuryTex);
Texture2D val5 = (flag ? sulfurGlowTex : mercuryGlowTex);
val4.mainTexture = (Texture)(object)mainTexture;
val4.SetTexture(EmissiveTexID, (Texture)(object)val5);
val4.SetFloat("_UseAlbedoAsEmissive", 0f);
val4.DisableKeyword("_USEALBEDOASEMISSIVE_ON");
val4.EnableKeyword("EMISSIVE");
val4.EnableKeyword("_FOG_OFF");
val4.DisableKeyword("_FOG_ON");
val4.SetColor(EmissiveColorID, Color.black);
component2.material = val4;
}
}
Renderer component3 = ((Component)val).GetComponent<Renderer>();
if ((Object)(object)component3 != (Object)null)
{
component3.enabled = false;
}
((Component)val).gameObject.AddComponent<SkullTag>();
}
private static Texture2D ConvertToRGB24(Texture2D source)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Invalid comparison between Unknown and I4
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
if ((Object)(object)source == (Object)null)
{
return null;
}
if ((int)source.format == 3)
{
return source;
}
Texture2D val = new Texture2D(((Texture)source).width, ((Texture)source).height, (TextureFormat)3, false);
val.SetPixels(source.GetPixels());
val.Apply();
return val;
}
internal static void ChangeSkullEmissionIntensity(Skull skull, float intensity)
{
//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)
Transform val = ((Component)skull).transform.Find("Hakita (1)(Clone)");
if (!((Object)(object)val == (Object)null))
{
Renderer component = ((Component)val).GetComponent<Renderer>();
if (!((Object)(object)component == (Object)null))
{
component.material.SetColor(EmissiveColorID, Color.white * intensity);
}
}
}
}
[HarmonyPatch(typeof(Skull), "Awake")]
internal static class SkullAwakePatch
{
private static void Postfix(Skull __instance)
{
ReplacementLogic.OnSkullAwake(__instance);
}
}
[HarmonyPatch(typeof(Skull), "OnCorrectUse")]
internal static class OnCorrectUsePatch
{
private static void Prefix(Skull __instance)
{
ReplacementLogic.ChangeSkullEmissionIntensity(__instance, 1f);
}
}
[HarmonyPatch(typeof(Skull), "OffCorrectUse")]
internal static class OffCorrectUsePatch
{
private static void Prefix(Skull __instance)
{
ReplacementLogic.ChangeSkullEmissionIntensity(__instance, 0f);
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.mrribkee.hakitifyskulls";
public const string PLUGIN_NAME = "My first plugin";
public const string PLUGIN_VERSION = "1.0.0";
}
}