using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("WeepingAngel")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Change coilhead model to a wheeping angel")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WeepingAngel")]
[assembly: AssemblyTitle("WeepingAngel")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace WeepingAngel
{
[BepInPlugin("raydenoir.WeepingAngel", "WeepingAngel", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string BundleFolderPath = "assets/weepingangels/";
public static ConfigEntry<bool> EnableConcreteSounds;
public static ConfigEntry<int> VarietyChance;
public static string PluginDirectory;
public static ManualLogSource Logging;
public static AudioClip Concrete;
public static GameObject[] AngelModel;
public static AssetBundle Bundle;
private void Awake()
{
PluginDirectory = ((BaseUnityPlugin)this).Info.Location;
Logging = ((BaseUnityPlugin)this).Logger;
EnableConcreteSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("Sounds", "EnableConcreteSounds", false, "true/false: If set to true, enables concrete grinding walking sounds instead of silence.");
VarietyChance = ((BaseUnityPlugin)this).Config.Bind<int>("Variety", "VarietyChance", 100, "Integer number from 0 to 100 inclusive. A chance in percent to spawn a Weeping Angel instead of regular Coilhead. Values below 100 allow regular coilheads to also spawn.");
if (VarietyChance.Value < 0)
{
VarietyChance.Value = 0;
}
if (VarietyChance.Value > 100)
{
VarietyChance.Value = 100;
}
LoadAssets();
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin raydenoir.WeepingAngel is loaded!");
}
private void LoadAssets()
{
try
{
Bundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(PluginDirectory), "weepingangels"));
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Couldn't load asset bundle: " + ex.Message));
return;
}
try
{
if (EnableConcreteSounds.Value)
{
Concrete = Bundle.LoadAsset<AudioClip>("assets/weepingangels/concrete.wav");
}
AngelModel = (GameObject[])(object)new GameObject[3];
for (int i = 0; i < 3; i++)
{
AngelModel[i] = Bundle.LoadAsset<GameObject>("assets/weepingangels/angel" + (i + 1) + ".prefab");
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Successfully loaded assets.");
}
catch (Exception ex2)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Couldn't load assets: " + ex2.Message));
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "WeepingAngel";
public const string PLUGIN_NAME = "WeepingAngel";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace WeepingAngel.Patches
{
[HarmonyPatch]
public class CoilheadPatch : MonoBehaviour
{
private static HashSet<SpringManAI> angels = new HashSet<SpringManAI>();
public static ManualLogSource Logging = Plugin.Logging;
[HarmonyPatch(typeof(EnemyAI), "Start")]
[HarmonyPostfix]
public static void Summon173(EnemyAI __instance)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
if (__instance is SpringManAI)
{
SpringManAI val;
try
{
val = (SpringManAI)__instance;
}
catch (Exception ex)
{
Logging.LogError((object)("Couldn't cast EnemyAI instance to SpringManAI: " + ex.Message));
return;
}
Random random = new Random();
int num = random.Next(100);
if (num < Plugin.VarietyChance.Value)
{
angels.Add(val);
Object.Destroy((Object)(object)((Component)((Component)val).transform.Find("SpringManModel").Find("Body")).gameObject.GetComponent<SkinnedMeshRenderer>());
Object.Destroy((Object)(object)((Component)((Component)val).transform.Find("SpringManModel").Find("Head")).gameObject.GetComponent<MeshRenderer>());
((Component)((Component)val).transform.Find("SpringManModel").Find("FoostepSFX")).gameObject.GetComponent<AudioSource>().mute = true;
val.springNoises = (AudioClip[])(object)new AudioClip[1];
InstantiateAngel(val);
Logging.LogInfo((object)"Weeping Angel resources are loaded.");
}
}
}
private static void InstantiateAngel(SpringManAI parent)
{
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.AngelModel != null && !((Object)(object)Plugin.AngelModel[0] == (Object)null) && angels.Contains(parent))
{
int num = new Random().Next(0, 3);
GameObject val = Object.Instantiate<GameObject>(Plugin.AngelModel[num]);
val.transform.SetParent(((Component)parent).transform.Find("SpringManModel"));
val.transform.localPosition = Vector3.zero;
val.transform.localRotation = Quaternion.identity;
val.transform.localScale = Vector3.one;
}
}
private static void ChangeAngelPose(SpringManAI parent)
{
//IL_0097: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.AngelModel != null && !((Object)(object)Plugin.AngelModel[0] == (Object)null) && angels.Contains(parent))
{
Transform val = ((Component)parent).transform.Find("SpringManModel");
Object.Destroy((Object)(object)((Component)val.GetChild(val.childCount - 1)).gameObject);
int num = new Random().Next(0, 3);
GameObject val2 = Object.Instantiate<GameObject>(Plugin.AngelModel[num]);
val2.transform.SetParent(((Component)parent).transform.Find("SpringManModel"));
val2.transform.localPosition = Vector3.zero;
val2.transform.localRotation = Quaternion.identity;
val2.transform.localScale = Vector3.one;
}
}
[HarmonyPatch(typeof(SpringManAI), "SetAnimationGoClientRpc")]
[HarmonyPostfix]
[ClientRpc]
public static void PlayWalkSounds(SpringManAI __instance)
{
ChangeAngelPose(__instance);
if (Plugin.EnableConcreteSounds.Value && !((Object)(object)Plugin.Concrete == (Object)null) && angels.Contains(__instance))
{
((EnemyAI)__instance).creatureSFX.PlayOneShot(Plugin.Concrete, 0.6f);
WalkieTalkie.TransmitOneShotAudio(((EnemyAI)__instance).creatureSFX, Plugin.Concrete, 0.4f);
}
}
[HarmonyPatch(typeof(SpringManAI), "SetAnimationStopClientRpc")]
[HarmonyPostfix]
[ClientRpc]
public static void StopWalkSounds(SpringManAI __instance)
{
if (Plugin.EnableConcreteSounds.Value && !((Object)(object)Plugin.Concrete == (Object)null) && angels.Contains(__instance) && ((EnemyAI)__instance).creatureSFX.isPlaying)
{
((EnemyAI)__instance).creatureSFX.Stop();
}
}
}
}