Decompiled source of LzD PingsCustomDurations v1.2.17

LzD_PingsCustomDurations.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LzD_PingsCustomDurations")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LzD_PingsCustomDurations")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("58cc7ef2-bb1a-49b2-a952-7b00eab24bf5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LzD_PingsCustomDurations;

[BepInPlugin("lzd_pingscustomdurations", "LzD Pings Custom Durations", "1.2.17")]
[BepInProcess("valheim.exe")]
public class LzD_PingsCustomDurations : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Chat), "AddInworldText")]
	private static class Chat_Awake_Patch
	{
		private static void Postfix(ref float ___m_worldTextTTL)
		{
			if (modEnabled.Value && ___m_worldTextTTL != pingsDuration.Value)
			{
				Log($"Changing worldTextTTl to {pingsDuration.Value}");
				___m_worldTextTTL = pingsDuration.Value;
			}
		}
	}

	[HarmonyPatch(typeof(Chat), "UpdateWorldTexts")]
	private static class Chat_UpdateWorldTexts_Patch
	{
		private static void Postfix(float ___m_worldTextTTL, List<WorldTextInstance> ___m_worldTexts, float dt)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!modEnabled.Value)
			{
				return;
			}
			updateFrozenWordTextPositions(___m_worldTexts, dt);
			IInputSystem current = UnityInput.Current;
			KeyboardShortcut value = clearPingKey.Value;
			if (current.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
			{
				clearWorldTexts(___m_worldTexts, ___m_worldTextTTL);
				return;
			}
			IInputSystem current2 = UnityInput.Current;
			value = freezePingKey.Value;
			if (current2.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
			{
				freezeWorldTexts(___m_worldTexts);
			}
		}

		private static void updateFrozenWordTextPositions(List<WorldTextInstance> worldTexts, float dt)
		{
			foreach (WorldTextInstance worldText in worldTexts)
			{
				if (worldText.m_timer < 0f)
				{
					worldText.m_position.y -= dt * 0.15f;
				}
			}
		}

		private static void freezeWorldTexts(List<WorldTextInstance> worldTexts)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			foreach (WorldTextInstance worldText in worldTexts)
			{
				worldText.m_timer = -86400f;
				((TMP_Text)worldText.m_textMeshField).color = frozenPingColor.Value;
			}
			Log("Freezing pings and shouts.");
		}

		private static void clearWorldTexts(List<WorldTextInstance> worldTexts, float maxDuration)
		{
			foreach (WorldTextInstance worldText in worldTexts)
			{
				worldText.m_timer = maxDuration;
			}
			Log("Clearing pings and shouts.");
		}
	}

	public const string modID = "lzd_pingscustomdurations";

	public const string modName = "LzD Pings Custom Durations";

	public const string modVersion = "1.2.17";

	private readonly Harmony harmony = new Harmony("lzd_pingscustomdurations");

	private static ConfigEntry<bool> modEnabled;

	private static ConfigEntry<bool> logsEnabled;

	private static ConfigEntry<float> pingsDuration;

	private static ConfigEntry<KeyboardShortcut> freezePingKey;

	private static ConfigEntry<KeyboardShortcut> clearPingKey;

	private static ConfigEntry<Color> frozenPingColor;

	private void Awake()
	{
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "a. Mod enabled", true, "Enable or disable the mod completely");
		logsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "b. Logs enabled", false, "Enable or disable logs completely");
		pingsDuration = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Pings and Shouts", "a. Duration", 15f, "Enable or disable logs completely");
		freezePingKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("2 - Pings and Shouts", "b. Freeze pings and shouts hotkey", new KeyboardShortcut((KeyCode)307, Array.Empty<KeyCode>()), "Defines the key to freeze pings and shouts");
		clearPingKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("2 - Pings and Shouts", "b. Clear pings and shouts hotkey", new KeyboardShortcut((KeyCode)305, Array.Empty<KeyCode>()), "Defines the key to clear pings and shouts");
		frozenPingColor = ((BaseUnityPlugin)this).Config.Bind<Color>("2 - Pings and Shouts", "b. Frozen ping color", new Color(0.25f, 1f, 1f, 0.75f), "Defines the color of frozen pings");
		if (modEnabled.Value)
		{
			harmony.PatchAll();
			Log("LzD Pings Custom Durations mod initialized");
		}
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	private static void Log(string msg)
	{
		if (logsEnabled.Value)
		{
			Debug.Log((object)msg);
		}
	}
}