Decompiled source of RitualDaggerWhispers v1.3.0

RitualDaggerWhispers.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RitualDaggerWhispers;

[BepInPlugin("local.peak.ritualdaggerwhispers", "Ritual Dagger Whispers", "1.3.0")]
public class RitualDaggerWhispersPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "local.peak.ritualdaggerwhispers";

	public const string PluginName = "Ritual Dagger Whispers";

	public const string PluginVersion = "1.3.0";

	internal static ManualLogSource Log;

	private ConfigEntry<bool> _enabled;

	private ConfigEntry<float> _interval;

	private ConfigEntry<float> _firstDelay;

	private ConfigEntry<bool> _useNotifications;

	private ConfigEntry<bool> _useOverlay;

	private ConfigEntry<bool> _nameAllies;

	private ConfigEntry<bool> _soundEnabled;

	private ConfigEntry<float> _soundVolume;

	private ConfigEntry<bool> _volumeMigrated;

	private ConfigEntry<string> _fontStyle;

	private bool _hasDagger;

	private float _timeWithDagger;

	private float _nextWhisper;

	private float _overlayUntil;

	private string _currentWhisper = "";

	private readonly Random _rng = new Random();

	private GUIStyle _overlayStyle;

	private AudioSource _whisperSource;

	private AudioClip _whisperClip;

	private Texture2D _lineTexture;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable the whispers.");
		_interval = ((BaseUnityPlugin)this).Config.Bind<float>("Whispers", "IntervalSeconds", 14f, "Seconds between whispers while the dagger is carried.");
		_firstDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Whispers", "FirstWhisperDelaySeconds", 5f, "Seconds before the first whisper after picking the dagger up.");
		_useNotifications = ((BaseUnityPlugin)this).Config.Bind<bool>("Whispers", "UseGameNotifications", true, "Show whispers in the game's notification feed.");
		_useOverlay = ((BaseUnityPlugin)this).Config.Bind<bool>("Whispers", "UseOverlay", true, "Show whispers as fading text near the bottom of the screen.");
		_nameAllies = ((BaseUnityPlugin)this).Config.Bind<bool>("Whispers", "NameAllies", true, "Some whispers mention a real teammate by name.");
		_soundEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Sound", "Enabled", true, "Play a quiet whisper sound for the local player.");
		_soundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Sound", "Volume", 0.22f, "Whisper volume (0-1).");
		_fontStyle = ((BaseUnityPlugin)this).Config.Bind<string>("Overlay", "FontStyle", "Ancient", "Overlay font: Ancient, Serif or Default.");
		_volumeMigrated = ((BaseUnityPlugin)this).Config.Bind<bool>("Sound", "VolumeMigratedToSoft", false, "One-time migration flag. Do not change manually.");
		if (!_volumeMigrated.Value)
		{
			_soundVolume.Value = 0.22f;
			_volumeMigrated.Value = true;
			((BaseUnityPlugin)this).Config.Save();
		}
		SetupWhisperSound();
		Log.LogInfo((object)"Ritual Dagger Whispers v1.3.0 loaded.");
	}

	private void Update()
	{
		if (!_enabled.Value)
		{
			return;
		}
		if (!HasRitualDagger())
		{
			if (_hasDagger)
			{
				Log.LogDebug((object)"Dagger no longer in inventory; whispers stop.");
			}
			_hasDagger = false;
			_timeWithDagger = 0f;
			_currentWhisper = "";
			_overlayUntil = 0f;
			return;
		}
		if (!_hasDagger)
		{
			_hasDagger = true;
			_timeWithDagger = 0f;
			string[] enPickup = WhisperLines.EnPickup;
			ShowWhisper(Pick(enPickup), 6f);
			_nextWhisper = Time.time + Mathf.Max(2f, _firstDelay.Value);
			return;
		}
		_timeWithDagger += Time.deltaTime;
		if (!(Time.time < _nextWhisper))
		{
			_nextWhisper = Time.time + Mathf.Max(2f, _interval.Value);
			string[] enLines = WhisperLines.EnLines;
			string text = Pick(enLines).Replace("{0}", PickAllyName());
			if (_timeWithDagger > 90f)
			{
				text += "...";
			}
			ShowWhisper(text, 6f);
		}
	}

	private static bool HasRitualDagger()
	{
		Player localPlayer = Player.localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return false;
		}
		if (IsDaggerSlot(localPlayer.tempFullSlot))
		{
			return true;
		}
		if (IsDaggerSlot((ItemSlot)(object)localPlayer.backpackSlot))
		{
			return true;
		}
		ItemSlot[] itemSlots = localPlayer.itemSlots;
		if (itemSlots == null)
		{
			return false;
		}
		for (int i = 0; i < itemSlots.Length; i++)
		{
			if (IsDaggerSlot(itemSlots[i]))
			{
				return true;
			}
		}
		return false;
	}

	private static bool IsDaggerSlot(ItemSlot slot)
	{
		if (slot == null)
		{
			return false;
		}
		try
		{
			if (slot.IsEmpty())
			{
				return false;
			}
		}
		catch
		{
			return false;
		}
		string text = null;
		try
		{
			text = slot.GetPrefabName();
		}
		catch
		{
		}
		if (string.IsNullOrEmpty(text))
		{
			Item prefab = slot.prefab;
			if ((Object)(object)prefab != (Object)null && (Object)(object)((Component)prefab).gameObject != (Object)null)
			{
				text = ((Object)((Component)prefab).gameObject).name;
			}
		}
		if (string.IsNullOrEmpty(text))
		{
			return false;
		}
		return text.IndexOf("ritualdagger", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("dagger", StringComparison.OrdinalIgnoreCase) >= 0;
	}

	private string PickAllyName()
	{
		if (!_nameAllies.Value)
		{
			return "someone";
		}
		List<Character> list = new List<Character>();
		Character localCharacter = Character.localCharacter;
		List<Character> allCharacters = Character.AllCharacters;
		if (allCharacters != null)
		{
			for (int i = 0; i < allCharacters.Count; i++)
			{
				Character val = allCharacters[i];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)localCharacter) && !string.IsNullOrEmpty(val.characterName))
				{
					list.Add(val);
				}
			}
		}
		if (list.Count == 0)
		{
			return "someone";
		}
		return list[_rng.Next(list.Count)].characterName;
	}

	private void ShowWhisper(string text, float overlaySeconds)
	{
		if (string.IsNullOrEmpty(text))
		{
			return;
		}
		_currentWhisper = text;
		_overlayUntil = Time.time + overlaySeconds;
		PlayWhisperSound();
		if (!_useNotifications.Value)
		{
			return;
		}
		try
		{
			UI_Notifications val = Object.FindAnyObjectByType<UI_Notifications>();
			if ((Object)(object)val != (Object)null)
			{
				val.AddNotification(text);
			}
			else
			{
				Log.LogDebug((object)"UI_Notifications not found - overlay only.");
			}
		}
		catch (Exception ex)
		{
			Log.LogDebug((object)("Could not show game notification: " + ex.Message));
		}
	}

	private string Pick(string[] lines)
	{
		if (lines == null || lines.Length == 0)
		{
			return "";
		}
		return lines[_rng.Next(lines.Length)];
	}

	private void SetupWhisperSound()
	{
		if (!_soundEnabled.Value)
		{
			return;
		}
		try
		{
			_whisperClip = CreateWhisperClip();
			_whisperSource = ((Component)this).gameObject.GetComponent<AudioSource>();
			if ((Object)(object)_whisperSource == (Object)null)
			{
				_whisperSource = ((Component)this).gameObject.AddComponent<AudioSource>();
			}
			_whisperSource.playOnAwake = false;
			_whisperSource.loop = false;
			_whisperSource.spatialBlend = 0f;
			_whisperSource.volume = 1f;
			_whisperSource.pitch = 1f;
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("Could not create whisper sound: " + ex.Message));
			_whisperSource = null;
			_whisperClip = null;
		}
	}

	private static AudioClip CreateWhisperClip()
	{
		int num = Mathf.CeilToInt(33075f);
		int num2 = Mathf.RoundToInt(2425.5f);
		float[] array = new float[num];
		Random random = new Random(2026);
		float num3 = 0f;
		float num4 = 0f;
		for (int i = 0; i < num; i++)
		{
			float num5 = (float)i / 22050f;
			float num6 = (float)(random.NextDouble() * 2.0 - 1.0);
			num3 += 0.07f * (num6 - num3);
			num4 += 0.07f * (num3 - num4);
			float num7 = 0.25f + 0.75f * Mathf.Pow(0.5f + 0.5f * Mathf.Sin(num5 * ((float)Math.PI * 2f) * 3.1f - 0.7f), 2f);
			float num8 = Mathf.SmoothStep(0f, 1f, num5 / 0.28f) * Mathf.SmoothStep(0f, 1f, (1.5f - num5) / 0.5f);
			float num9 = 0.05f * Mathf.Sin(num5 * ((float)Math.PI * 2f) * 165f) * num7;
			float num10 = (num4 * 2.4f + num9) * num7 * num8;
			float num11 = ((i >= num2) ? (array[i - num2] * 0.16f) : 0f);
			array[i] = num10 + num11;
		}
		float num12 = 0f;
		for (int i = 0; i < num; i++)
		{
			num12 = Mathf.Max(num12, Mathf.Abs(array[i]));
		}
		if (num12 > 0.0001f)
		{
			float num13 = 0.8f / num12;
			for (int i = 0; i < num; i++)
			{
				array[i] *= num13;
			}
		}
		AudioClip val = AudioClip.Create("RitualDaggerWhisper", num, 1, 22050, false);
		MethodInfo method = typeof(AudioClip).GetMethod("SetData", new Type[2]
		{
			typeof(float[]),
			typeof(int)
		});
		if (method != null)
		{
			method.Invoke(val, new object[2] { array, 0 });
		}
		return val;
	}

	private void PlayWhisperSound()
	{
		if (!_soundEnabled.Value || (Object)(object)_whisperSource == (Object)null || (Object)(object)_whisperClip == (Object)null)
		{
			return;
		}
		try
		{
			_whisperSource.pitch = 0.9f + (float)_rng.NextDouble() * 0.2f;
			_whisperSource.PlayOneShot(_whisperClip, Mathf.Clamp01(_soundVolume.Value));
		}
		catch (Exception ex)
		{
			Log.LogDebug((object)("Whisper sound failed: " + ex.Message));
		}
	}

	private void OnGUI()
	{
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Expected O, but got Unknown
		if (!_useOverlay.Value || string.IsNullOrEmpty(_currentWhisper))
		{
			return;
		}
		float num = _overlayUntil - Time.time;
		if (!(num <= 0f))
		{
			if (_overlayStyle == null)
			{
				_overlayStyle = new GUIStyle(GUI.skin.label);
				_overlayStyle.font = CreateOverlayFont();
				_overlayStyle.alignment = (TextAnchor)4;
				_overlayStyle.fontSize = 22;
				_overlayStyle.fontStyle = (FontStyle)0;
				_overlayStyle.wordWrap = true;
			}
			float num2 = Mathf.Clamp01(num / 1.5f) * 0.95f;
			Color color = GUI.color;
			GUI.color = new Color(1f, 1f, 1f, num2);
			float num3 = Mathf.Min(820f, (float)Screen.width - 40f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((float)Screen.width - num3) * 0.5f, (float)Screen.height - 175f, num3, 100f);
			string text = "« " + _currentWhisper + " »";
			Texture2D lineTexture = GetLineTexture();
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x + 50f, ((Rect)(ref val)).y + 8f, ((Rect)(ref val)).width - 100f, 1f), (Texture)(object)lineTexture);
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x + 50f, ((Rect)(ref val)).yMax - 10f, ((Rect)(ref val)).width - 100f, 1f), (Texture)(object)lineTexture);
			_overlayStyle.normal.textColor = new Color(0.12f, 0.02f, 0.02f, 1f);
			GUI.Label(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 2f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), text, _overlayStyle);
			_overlayStyle.normal.textColor = new Color(0.94f, 0.8f, 0.48f, 1f);
			GUI.Label(val, text, _overlayStyle);
			GUI.color = color;
		}
	}

	private Font CreateOverlayFont()
	{
		string value = _fontStyle.Value;
		if (string.Equals(value, "Default", StringComparison.OrdinalIgnoreCase))
		{
			return GUI.skin.label.font;
		}
		string[] array = ((!string.Equals(value, "Serif", StringComparison.OrdinalIgnoreCase)) ? new string[6] { "Old English Text MT", "Blackadder ITC", "Algerian", "Palatino Linotype", "Georgia", "Times New Roman" } : new string[4] { "Georgia", "Palatino Linotype", "Book Antiqua", "Times New Roman" });
		Font val = Font.CreateDynamicFontFromOSFont(array, 22);
		return ((Object)(object)val != (Object)null) ? val : GUI.skin.label.font;
	}

	private Texture2D GetLineTexture()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_lineTexture == (Object)null)
		{
			_lineTexture = new Texture2D(1, 1);
			_lineTexture.SetPixel(0, 0, new Color(0.62f, 0.42f, 0.18f, 0.9f));
			_lineTexture.Apply();
		}
		return _lineTexture;
	}
}
internal static class WhisperLines
{
	public static readonly string[] EnPickup = new string[12]
	{
		"At last. Now you can see.", "It woke up in your pack.", "Cold. Hungry. Yours.", "The handle is warm. It recognises you.", "You picked me up. Now we are bound.", "Do you feel that? That is the old rite beginning.", "They cannot hear me. Only you can.", "I have been waiting in the dark for a hand like yours.", "Your fingers will remember my shape.", "The whispers start now. Do not fight them.",
		"One blade. One purpose. One of you will understand.", "Welcome, chosen."
	};

	public static readonly string[] EnLines = new string[200]
	{
		"Kill them. Start with {0}.", "Do it now. There is no better moment.", "End them before they end you.", "Take the first life. The rest will follow.", "Strike. Do not think.", "Make your move. They are defenceless.", "Finish it. Quickly and quietly.", "No more waiting. No more excuses.", "Do what you came here to do.", "Obey. The edge is impatient.",
		"{0} is next. They will never see it coming.", "{0} trusts you. Betray that trust.", "Look at {0}. Alone. Unguarded.", "{0} would do the same to you.", "Whisper their name: {0}. Then make it a memory.", "{0} is laughing. Make them stop.", "{0} is slowing you down. Remove the weight.", "There is only room for one at the summit, {0}.", "{0} knows what you are planning. Silence them.", "Start with {0}. It gets easier after the first.",
		"I am hungry. Feed me.", "The blade thirsts. Blood will quiet it.", "My edge has not tasted anything in so long.", "Hunger does not care about friendship.", "I want warmth. Their warmth.", "Feed the ritual. It asks so little.", "The cold cannot be beaten by marshmallows. Only this.", "I need more. Your pack knows why.", "A drop is enough to begin. Then another.", "Do not starve me. Not again.",
		"Come up from behind. One arm. One second.", "They are looking at the mountain, not at you.", "Wait until their back is turned.", "Soft feet. Sharp steel. Simple.", "The fire is loud. Use that.", "No one will hear over the wind.", "Smile first. Then strike.", "Hold your breath. They will not notice.", "A hand on the shoulder is all it takes.", "Silence is a gift. Give it to them.",
		"They would abandon you on the climb.", "They took the last marshmallow. Remember?", "They never deserved to reach the summit.", "You carry more than they do. Because of them.", "It is not murder. It is necessity.", "They are a burden dressed as a friend.", "The mountain rewards the decisive.", "They will thank you for ending their suffering.", "You are doing them a favour. Truly.", "Survival has no room for loyalty.",
		"The voice you hear is not yours. It never was.", "I have waited a long time for hands like yours.", "My previous owner listened. You should too.", "Do you hear the whispering? That is me.", "I remember every name I have taken.", "The handle is warm. That means soon.", "I can smell the fear in your camp.", "I sleep when they die. Wake me.", "There is something inside the steel. It agrees with me.", "You are not holding me. I am holding you.",
		"The old rite demands an offering.", "Blood remembers blood. Give it a reason to remember you.", "The mountain was built on betrayals like this.", "The stones are watching. Do not disappoint them.", "An ancient debt is due. Collect it.", "The ritual is simple. One life for many blessings.", "Before the first campfire, there was the first knife.", "The statue knows what you are thinking.", "Every shrine was built with a sacrifice.", "The old gods are patient. But not infinite.",
		"The Last Resort badge is earned, not given.", "They call it a badge. I call it a promise.", "Cleanse the negative. Keep the guilt.", "One sacrifice cleanses more than any marshmallow.", "You want the badge? Take it.", "The game rewards the obedient.", "A small area of healing. A lifetime of memories.", "They will write it in your report. I will write it in theirs.", "This is the only shortcut the mountain allows.", "Prove you are worthy of the dagger.",
		"They sleep by the fire. Perfect.", "The campfire crackles. It will cover the sound.", "Night is when the honest become quiet.", "They trust the darkness. Teach them not to.", "While they rest, you decide.", "The sleeping do not fight back.", "Rest is a weakness. Remove it from them.", "The wind will carry no screams tonight.", "Their bedroll is a shroud waiting for a body.", "Quietly. The fire is almost out.",
		"A handhold is a promise. Break it.", "One slip is all it takes. Help them slip.", "The rope is not a safety net. It is an opportunity.", "Higher they climb, harder they fall.", "Do not pull them up. Let the mountain keep them.", "The summit is closer without them.", "Gravity is a loyal friend. Use it.", "Their grip is tired. Yours is not.", "A short drop. A long silence.", "The climb is a test. They already failed.",
		"Three breaths. That is all they get.", "One down. More to go.", "Count them. Then subtract.", "The moment is now. The next moment is too late.", "Seconds matter. Hesitation costs.", "They are one step from the edge. Help them take it.", "There are fewer of them every time you look.", "Before the sun sets, make it count.", "No time like the present. No time after either.", "Every heartbeat is a countdown.",
		"Do you hear that? Or is it just me?", "Why wait for them to turn on you?", "What are you afraid of?", "Do you really want to climb with them?", "How many chances will you get?", "What would they do if the roles were reversed?", "Are you still pretending to be good?", "Do you think the dagger chose you by accident?", "Who will miss them, really?", "How much longer can you pretend?",
		"You are special. They are not.", "Only you understand what must be done.", "They mock you when you are not looking.", "You deserve the summit more than they do.", "They will never understand you. That is why they must go.", "I chose you because you are strong enough.", "Imagine the silence after. Peaceful, isn't it?", "They call you friend. I call you chosen.", "You already want this. Admit it.", "No one would blame you. No one would know.",
		"Now.", "Again.", "Soon.", "Do not hesitate.", "Get closer.", "Do it.", "They are watching.", "Make it quick.", "No turning back.", "Obey.",
		"Their silence will be sweeter than any song.", "Warmth. That is all I ask for.", "The petrified statues do not complain.", "A scarlet smile is the honest one.", "They will not feel the second strike.", "Their bonus stamina means nothing to me.", "Even the strongest bar empties eventually.", "I want to hear the sound it makes.", "Blood on snow is a language they understand.", "They will make a beautiful statue.",
		"Share the last marshmallow. Then end them.", "Help them up. Then push.", "Laugh at their joke. Then silence them.", "Promise them safety. Be the exception.", "A friendly hand is the perfect disguise.", "Look into their eyes. Then look away forever.", "Trust is just a slower way to betray.", "They would thank you if they knew. They will not know.", "Betrayal is easiest from behind.", "Hold the door. Then close it on them.",
		"My previous owner hesitated. Do not repeat their mistake.", "I was carved from a stone that remembered violence.", "Every scratch on my edge has a name.", "I was found, not made. That should worry you.", "The statue gave me to you. It knows.", "Ancient luggage carries many things. I am the hungriest.", "I have slept through a hundred ascents.", "Cooking me changes nothing. I remain myself.", "I am not a tool. I am a decision.", "You are the fourth hand I have known. The fourth will be enough.",
		"They whisper about you when you are gone.", "Did you see how they looked at your pack?", "They are closer than they appear.", "Someone is always watching the campfire.", "The footsteps behind you are not yours.", "They know you carry me. That is why they are nervous.", "Trust no one who shares your food.", "The wind carries more than sound.", "They are waiting for you to sleep.", "Even the statues have eyes.",
		"You have gone too far to stop now.", "There is no version of this where you walk away clean.", "The first was the hardest. The rest are easy.", "You cannot un-hear the whispers.", "Your hands already know the motion.", "The dagger agrees with every step you take.", "You are not the person who picked this up.", "The mountain remembers what you did.", "There is only one ending to this story.", "Finish what you started.",
		"Imagine how light your pack will feel.", "No more sharing. No more waiting. No more them.", "The summit is so close. Remove the obstacles.", "You could be the last scout standing. The strongest.", "Think of the quiet. Just you and the wind.", "One strike buys you peace. Forever.", "They take up space in the report. Delete them.", "You have earned the right to choose.", "What if you never had to climb with anyone again?", "Say yes. Just say yes."
	};
}