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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Autodesk.Fbx")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")]
[assembly: IgnoresAccessChecksTo("Klattersynth")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("websocket-sharp")]
[assembly: AssemblyCompany("linkoid")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DreadHeadDuck")]
[assembly: AssemblyTitle("DreadHeadDuck")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 Linkoid.Repo.DreadHeadDuck
{
[BepInPlugin("Linkoid.Repo.DreadHeadDuck", "Dread Head Duck", "1.0")]
public class DreadHeadDuck : BaseUnityPlugin
{
public ConfigEntry<float> DreadHeadChance;
public ConfigEntry<bool> MimicPlayerHeads;
internal static DreadHeadDuck Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
//IL_00a8: Expected O, but got Unknown
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
DreadHeadChance = ((BaseUnityPlugin)this).Config.Bind<float>("DreadHeadDuck", "DreadHeadChance", 0.5f, new ConfigDescription("Chance for a duck to have a Dread Head", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
MimicPlayerHeads = ((BaseUnityPlugin)this).Config.Bind<bool>("DreadHeadDuck", "MimicPlayerHeads", true, "Mimic player heads in multiplayer, random otherwise.");
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
}
}
[HarmonyPatch(typeof(EnemyDuck))]
internal static class EnemyDuckPatch
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
private static void Start_Prefix(EnemyDuck __instance)
{
DreadHeadDuck.Logger.LogDebug((object)$"controllerActorNr = {__instance.photonView.InstantiationId}");
Random random = new Random(__instance.photonView.InstantiationId);
if ((float)random.NextDouble() < DreadHeadDuck.Instance.DreadHeadChance.Value)
{
ConvertToDreadHeadDuck(__instance, random);
}
}
private static void ConvertToDreadHeadDuck(EnemyDuck enemyDuck, Random random)
{
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
bool flag = false;
PlayerDeathHead val = null;
if (GameDirector.instance.PlayerList.Count > 1 && DreadHeadDuck.Instance.MimicPlayerHeads.Value)
{
val = PickRandomPlayerDeathHead(random);
}
if ((Object)(object)val == (Object)null)
{
val = GenerateRandomDeathHead(random);
flag = true;
}
EnemyParent componentInParent = ((Component)enemyDuck).GetComponentInParent<EnemyParent>();
componentInParent.enemyName = "Dread Head Predator";
GameObject gameObject = ((Component)componentInParent).gameObject;
((Object)gameObject).name = "Enemy - Dread Head Duck(Clone)";
GameObject val2 = gameObject.FindFirstChild("ANIM Head") ?? throw new MissingReferenceException("Could not find GameObject 'ANIM Head'");
PlayerDeathHead component = Object.Instantiate<GameObject>(((Component)val).gameObject, val2.transform.parent, false).GetComponent<PlayerDeathHead>();
StripDeathHead(component);
((Component)component).transform.SetAsFirstSibling();
((Object)component).name = "ANIM Head";
val2.SetActive(false);
GameObject val3 = gameObject.FindFirstChild("ANIM Mon Head") ?? throw new MissingReferenceException("Could not find GameObject 'ANIM Mon Head'");
PlayerDeathHead component2 = Object.Instantiate<GameObject>(((Component)val).gameObject, val3.transform, false).GetComponent<PlayerDeathHead>();
StripDeathHead(component2);
InitializeEyeMaterials(component2);
component2.eyeMaterial.SetColor(component2.eyeMaterialColor, Color.red);
component2.eyeMaterial.SetFloat(component2.eyeMaterialAmount, 1f);
((Component)component2).transform.position = val3.transform.position;
((Component)component2).transform.rotation = val3.transform.rotation;
if (flag)
{
Object.Destroy((Object)(object)((Component)val).gameObject);
}
}
private static PlayerDeathHead? PickRandomPlayerDeathHead(Random random)
{
if (GameDirector.instance.PlayerList.Count <= 0)
{
return null;
}
int index = random.Next(GameDirector.instance.PlayerList.Count);
PlayerDeathHead val = GameDirector.instance.PlayerList[index]?.playerDeathHead;
if (val != null)
{
val.UpdateColor();
}
return val;
}
private static PlayerDeathHead GenerateRandomDeathHead(Random random)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
PlayerDeathHead component = Object.Instantiate<GameObject>(LevelGenerator.Instance.PlayerDeathHeadPrefab).GetComponent<PlayerDeathHead>();
int index = random.Next(AssetManager.instance.playerColors.Count);
((Renderer)component.headRenderer).GetMaterial().SetColor(Shader.PropertyToID("_AlbedoColor"), AssetManager.instance.playerColors[index]);
return component;
}
private static void InitializeEyeMaterials(PlayerDeathHead playerDeathHead)
{
playerDeathHead.eyeMaterialAmount = Shader.PropertyToID("_ColorOverlayAmount");
playerDeathHead.eyeMaterialColor = Shader.PropertyToID("_ColorOverlay");
playerDeathHead.eyeFlashCurve = AssetManager.instance.animationCurveImpact;
MeshRenderer[] eyeRenderers = playerDeathHead.eyeRenderers;
foreach (MeshRenderer val in eyeRenderers)
{
if (playerDeathHead.eyeMaterial == null)
{
playerDeathHead.eyeMaterial = ((Renderer)val).GetMaterial();
}
((Renderer)val).SetMaterial(playerDeathHead.eyeMaterial);
}
}
private static void StripDeathHead(PlayerDeathHead deathHead)
{
((Component)deathHead).gameObject.tag = "Untagged";
deathHead.playerAvatar = null;
deathHead.photonView = null;
((Component)deathHead).gameObject.SetActive(true);
((Behaviour)deathHead).enabled = false;
StripUnusedComponentsOfType<PhotonView>(deathHead);
StripUnusedComponentsOfType<PhotonTransformView>(deathHead);
StripUnusedComponentsOfType<PhysGrabObject>(deathHead);
StripUnusedComponentsOfType<PhysGrabObjectImpactDetector>(deathHead);
StripUnusedComponentsOfType<RoomVolumeCheck>(deathHead);
StripUnusedComponentsOfType<NotValuableObject>(deathHead);
StripUnusedComponentsOfType<MapCustom>(deathHead);
StripUnusedComponentsOfType<Rigidbody>(deathHead);
Collider[] componentsInChildren = ((Component)deathHead).GetComponentsInChildren<Collider>();
foreach (Collider val in componentsInChildren)
{
Object.Destroy((Object)(object)((Component)val).gameObject);
}
}
private static void StripUnusedComponentsOfType<T>(PlayerDeathHead playerDeathHead) where T : Object
{
T[] componentsInChildren = ((Component)playerDeathHead).GetComponentsInChildren<T>();
foreach (T val in componentsInChildren)
{
Object.Destroy((Object)(object)val);
}
}
}
internal static class GameObjectExtensions
{
public static GameObject? FindFirstChild(this GameObject parent, string name)
{
Transform? obj = parent.transform.FindFirstChild(name);
if (obj == null)
{
return null;
}
return ((Component)obj).gameObject;
}
public static Transform? FindFirstChild(this Transform parent, string name)
{
Queue<Transform> queue = new Queue<Transform>();
queue.Enqueue(parent);
while (queue.Count > 0)
{
parent = queue.Dequeue();
Transform val = parent.Find(name);
if ((Object)(object)val != (Object)null)
{
return val;
}
int childCount = parent.childCount;
for (int i = 0; i < childCount; i++)
{
queue.Enqueue(parent.GetChild(i));
}
}
return null;
}
}
}