Decompiled source of EggRespawnReduction v1.1.0

DragonEggRespawn.dll

Decompiled 2 days ago
using System;
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("DragonEggRespawn")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DragonEggRespawn")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("42560e60-5569-4d97-a186-160da076c3e7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DragonEggRespawn;

[BepInPlugin("robit.valheim.dragoneggrespawn", "Dragon Egg Respawn", "1.1.0")]
public class DragonEggRespawnPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Pickable), "ShouldRespawn")]
	private static class EggRespawnPatch
	{
		[HarmonyPrefix]
		private static void Prefix(Pickable __instance)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)((Component)__instance).gameObject).name.StartsWith("Pickable_DragonEgg", StringComparison.Ordinal))
			{
				return;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return;
			}
			ZDO zDO = component.GetZDO();
			if (zDO != null)
			{
				float num = Mathf.Min(_minMinutes.Value, _maxMinutes.Value);
				float num2 = Mathf.Max(_minMinutes.Value, _maxMinutes.Value);
				if (num == num2)
				{
					__instance.m_respawnTimeMinutes = num;
					return;
				}
				long num3 = zDO.GetLong("picked_time", 0L);
				Vector3 position = zDO.GetPosition();
				int num4 = (int)num3 ^ (int)(num3 >> 32) ^ (Mathf.RoundToInt(position.x * 10f) * 374761393) ^ (Mathf.RoundToInt(position.z * 10f) * 668265263);
				int num5 = (num4 ^ (num4 >>> 13)) * 1274126177;
				float num6 = (float)(uint)((num5 ^ (num5 >>> 16)) & 0xFFFFFF) / 16777216f;
				__instance.m_respawnTimeMinutes = Mathf.Lerp(num, num2, num6);
			}
		}
	}

	private const string ModGuid = "robit.valheim.dragoneggrespawn";

	private const string ModName = "Dragon Egg Respawn";

	private const string ModVersion = "1.1.0";

	private static ConfigEntry<float> _minMinutes;

	private static ConfigEntry<float> _maxMinutes;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Expected O, but got Unknown
		_minMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("Dragon Eggs", "MinRespawnMinutes", 45f, new ConfigDescription("Shortest possible dragon egg respawn delay, in real-world minutes.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10080f), Array.Empty<object>()));
		_maxMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("Dragon Eggs", "MaxRespawnMinutes", 60f, new ConfigDescription("Longest possible dragon egg respawn delay. Set equal to the minimum for a fixed timer.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10080f), Array.Empty<object>()));
		_harmony = new Harmony("robit.valheim.dragoneggrespawn");
		_harmony.PatchAll(typeof(DragonEggRespawnPlugin).Assembly);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Dragon egg respawn range: " + _minMinutes.Value + " to " + _maxMinutes.Value + " minutes."));
	}

	private void OnDestroy()
	{
		if (_harmony != null)
		{
			_harmony.UnpatchSelf();
		}
	}
}