using System;
using System.Collections;
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;
using UnityEngine.ResourceManagement.AsyncOperations;
[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.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("HakitifySkulls")]
[assembly: AssemblyVersion("1.0.2.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.2")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; private set; }
public static GameObject? CachedPlushiePrefab { get; private set; }
private void Awake()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)4;
AsyncOperationHandle<GameObject> val = Addressables.LoadAssetAsync<GameObject>((object)"Assets/Prefabs/Items/DevPlushies/DevPlushie (Hakita).prefab");
val.Completed += delegate(AsyncOperationHandle<GameObject> handle)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Invalid comparison between Unknown and I4
if ((int)handle.Status == 1)
{
CachedPlushiePrefab = handle.Result;
}
};
Harmony val2 = new Harmony("com.mrribke.hakitifyskulls");
val2.PatchAll();
}
}
public class SkullTag : MonoBehaviour
{
}
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 Texture2D? torchTex;
private static Texture2D? secretmercuryTex;
private static Texture2D? secretsulfurTex;
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"));
torchTex = ConvertToRGB24(EmbeddedResourceLoader.LoadTextureFromResource("HakitifySkulls.T_HakitifyTorch.png"));
secretmercuryTex = EmbeddedResourceLoader.LoadTextureFromResource("HakitifySkulls.T_HakitifySkull_MercuryJakito.png");
secretsulfurTex = EmbeddedResourceLoader.LoadTextureFromResource("HakitifySkulls.T_HakitifySkull_SulfurJakito.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)
{
((MonoBehaviour)skull).StartCoroutine(DelayedReplace(skull));
}
internal static void OnTorchStart(Torch torch)
{
ReplaceTorch(torch);
}
private static IEnumerator DelayedReplace(Skull skull)
{
yield return (object)new WaitForEndOfFrame();
ItemIdentifier identifier = ((Component)skull).GetComponent<ItemIdentifier>();
ItemType itemType = identifier.itemType;
if ((int)itemType == 1 || (int)itemType == 2)
{
Replace(skull);
}
}
private static void Replace(Skull skull)
{
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Expected O, but got Unknown
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
InitTextures();
GameObject cachedPlushiePrefab = Plugin.CachedPlushiePrefab;
if ((Object)(object)cachedPlushiePrefab == (Object)null)
{
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 = cachedPlushiePrefab.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 && (Object)(object)secretmercuryTex != (Object)null && (Object)(object)secretsulfurTex != (Object)null)
{
Material val4 = new Material(component2.material);
int num = Random.Range(0, 100);
Texture2D mainTexture;
Texture2D val5;
if (((Object)skull).name.Contains("Red"))
{
mainTexture = ((num == 1) ? secretsulfurTex : sulfurTex);
val5 = sulfurGlowTex;
}
else
{
if (!((Object)skull).name.Contains("Blue"))
{
return;
}
mainTexture = ((num == 1) ? secretmercuryTex : mercuryTex);
val5 = 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>();
Light component4 = ((Component)skull).GetComponent<Light>();
bool flag = (Object)(object)component4 != (Object)null && !((Behaviour)component4).enabled;
ChangeSkullEmissionIntensity(skull, flag ? 1f : 0f);
}
private static void ReplaceTorch(Torch torch)
{
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Expected O, but got Unknown
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
InitTextures();
Transform val = ((IEnumerable<Transform>)((Component)torch).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name.Contains("Fire")));
if ((Object)(object)val != (Object)null)
{
((Component)val).transform.localPosition = new Vector3(0f, 0f, 0f);
}
GameObject cachedPlushiePrefab = Plugin.CachedPlushiePrefab;
if ((Object)(object)cachedPlushiePrefab == (Object)null)
{
return;
}
Transform val2 = ((IEnumerable<Transform>)((Component)torch).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Cylinder"));
if ((Object)(object)val2 == (Object)null)
{
return;
}
Transform val3 = cachedPlushiePrefab.transform.Find("Hakita (1)");
if ((Object)(object)val3 != (Object)null)
{
GameObject val4 = Object.Instantiate<GameObject>(((Component)val3).gameObject, ((Component)torch).transform);
val4.transform.localPosition = new Vector3(0f, 0f, 0f);
val4.transform.localRotation = Quaternion.Euler(270f, 90f, 0f);
val4.transform.localScale = new Vector3(1.6f, 1.6f, 1.6f);
Collider component = val4.GetComponent<Collider>();
if ((Object)(object)component != (Object)null)
{
component.enabled = false;
}
Renderer component2 = val4.GetComponent<Renderer>();
if ((Object)(object)component2 != (Object)null && (Object)(object)torchTex != (Object)null)
{
Material val5 = new Material(component2.material);
Texture2D mainTexture = torchTex;
val5.mainTexture = (Texture)(object)mainTexture;
val5.SetFloat("_UseAlbedoAsEmissive", 0f);
val5.DisableKeyword("_USEALBEDOASEMISSIVE_ON");
val5.EnableKeyword("EMISSIVE");
val5.EnableKeyword("_FOG_OFF");
val5.DisableKeyword("_FOG_ON");
val5.SetColor(EmissiveColorID, Color.black);
component2.material = val5;
}
}
Renderer component3 = ((Component)val2).GetComponent<Renderer>();
if ((Object)(object)component3 != (Object)null)
{
component3.enabled = false;
}
}
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);
}
}
[HarmonyPatch(typeof(Torch), "Start")]
internal static class TorchStartPatch
{
private static void Postfix(Torch __instance)
{
ReplacementLogic.OnTorchStart(__instance);
}
}
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.2";
}
}