Decompiled source of SleepWell v1.0.0

SleepWell.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
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;
		}
	}
}
[BepInPlugin("b54fff0c-5dca-4d6d-8899-c3478b85529f", "Correction of sleep message", "1.0.0")]
public class SleepWell : BaseUnityPlugin
{
	[HarmonyPatch(typeof(TextMeshProUGUI), "Awake")]
	public class Patch_TMPUGUI
	{
		private static void Postfix(TextMeshProUGUI __instance)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).gameObject.GetComponent<TextInterceptor>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<TextInterceptor>();
			}
		}
	}

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("se.omnivore.valheim.sleepwell").PatchAll();
		Debug.Log((object)"Sleep well has awakened");
	}
}
public class TextInterceptor : MonoBehaviour
{
	private TextMeshProUGUI? tmp;

	private string? lastText;

	private void Awake()
	{
		tmp = ((Component)this).GetComponent<TextMeshProUGUI>();
	}

	private void Update()
	{
		TextMeshProUGUI? obj = tmp;
		if (((obj != null) ? ((TMP_Text)obj).text : null) == null)
		{
			return;
		}
		TextMeshProUGUI? obj2 = tmp;
		if (!(((obj2 != null) ? ((TMP_Text)obj2).text : null) != ""))
		{
			return;
		}
		TextMeshProUGUI? obj3 = tmp;
		if (((obj3 != null) ? ((TMP_Text)obj3).text : null) != lastText)
		{
			TextMeshProUGUI? obj4 = tmp;
			lastText = ((obj4 != null) ? ((TMP_Text)obj4).text : null);
			if (((TMP_Text)tmp).text.TrimStart(Array.Empty<char>()).StartsWith("ZZZZ", StringComparison.OrdinalIgnoreCase))
			{
				((TMP_Text)tmp).text = "ZZZzzz...";
			}
		}
	}
}