Decompiled source of RestfulArrival v1.0.1

RestfulArrival.dll

Decompiled 6 months ago
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("RestfulArrival")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Riintouge")]
[assembly: AssemblyProduct("RestfulArrival")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("78540e8c-1ca5-4548-b3c1-5d6259b4db5e")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace RestfulArrival;

[BepInPlugin("com.riintouge.restfularrival", "Restful Arrival", "1.0.1")]
[BepInProcess("valheim.exe")]
public class RestfulArrival : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Game))]
	private class GamePatch
	{
		private static bool FirstSpawnPending;

		internal static double TimeOfLastFirstSpawn;

		[HarmonyPatch("FixedUpdate")]
		[HarmonyPrefix]
		private static void FixedUpdatePrefix(ref bool ___m_firstSpawn)
		{
			if (___m_firstSpawn)
			{
				FirstSpawnPending = true;
			}
		}

		[HarmonyPatch("UpdateRespawn")]
		[HarmonyPostfix]
		private static void UpdateRespawnPostfix()
		{
			if (FirstSpawnPending && Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				FirstSpawnPending = false;
				TimeOfLastFirstSpawn = Time.timeAsDouble;
			}
		}
	}

	[HarmonyPatch(typeof(SE_Cozy))]
	private class SE_CozyPatch
	{
		[HarmonyPatch("UpdateStatusEffect")]
		[HarmonyPrefix]
		private static void UpdateStatusEffectPrefix(ref SE_Cozy __instance)
		{
			if (IsEnabled.Value && Time.timeAsDouble - GamePatch.TimeOfLastFirstSpawn < 3.0)
			{
				Traverse.Create((object)Player.m_localPlayer).Field("m_comfortLevel").SetValue((object)SE_Rested.CalculateComfortLevel(Player.m_localPlayer));
				__instance.m_delay = 0f;
			}
		}
	}

	public static ConfigEntry<bool> IsEnabled;

	public static ConfigEntry<bool> LoadOnStart;

	private readonly Harmony Harmony = new Harmony("com.riintouge.restfularrival");

	private void Awake()
	{
		IsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("0 - Core", "Enable", true, "Whether this plugin has any effect when loaded.");
		LoadOnStart = ((BaseUnityPlugin)this).Config.Bind<bool>("0 - Core", "LoadOnStart", true, "Whether this plugin loads on game start.");
		if (LoadOnStart.Value)
		{
			Harmony.PatchAll();
		}
	}
}