Decompiled source of DeathRelocate v0.1.0

BepInEx/plugins/DeathRelocate.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Riverboat.Players;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DeathRelocate")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("DeathRelocate")]
[assembly: AssemblyTitle("DeathRelocate")]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "This assembly was partially or fully created with the assistance of Generative AI (e.g., Code Suggestions, Refactoring, Documentation Generation).")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "DeepSeek")]
[assembly: AssemblyMetadata("AI_Model_Name", "deepseek-v4-flash")]
[assembly: AssemblyMetadata("AI_Agent", "Claude Code")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VoodooFishin.DeathRelocate
{
	[BepInPlugin("voodoofishin.deathrelocate", "Death Relocate", "0.1.0")]
	public class Plugin : BasePlugin
	{
		public const string Guid = "voodoofishin.deathrelocate";

		internal static ConfigEntry<bool> CfgEnabled;

		internal static ConfigEntry<string> CfgSource;

		internal static ManualLogSource Logger;

		public override void Load()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			CfgEnabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "死亡时把渔具放到重生点,而不是死亡地点。");
			CfgSource = ((BasePlugin)this).Config.Bind<string>("General", "PositionSource", "PlayerSpawn", new ConfigDescription("重生点坐标怎么取。PlayerSpawn = 记录玩家 Initialize 时的位置(默认,离线/联机都适用);SceneSpawnPoint = 直接找场景里的 SpawnPoint 组件(联机多人时可能取错人,仅作备用)。", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "PlayerSpawn", "SceneSpawnPoint" }), Array.Empty<object>()));
			Harmony val = new Harmony("voodoofishin.deathrelocate");
			val.PatchAll(typeof(Player_Initialize_Patch));
			val.PatchAll(typeof(Player_SpawnRecoveryItem_Patch));
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(32, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Death Relocate loaded (source=");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(CfgSource.Value);
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(").");
			}
			log.LogInfo(val2);
		}
	}
	[HarmonyPatch(typeof(Player), "Initialize")]
	internal static class Player_Initialize_Patch
	{
		private static readonly Dictionary<int, Vector3> Homes = new Dictionary<int, Vector3>();

		[HarmonyPostfix]
		private static void Postfix(Player __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			try
			{
				Homes[((Object)__instance).GetInstanceID()] = ((Component)__instance).transform.position;
			}
			catch
			{
			}
		}

		internal static bool TryGetHome(Player player, out Vector3 pos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			pos = default(Vector3);
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			return Homes.TryGetValue(((Object)player).GetInstanceID(), out pos);
		}
	}
	[HarmonyPatch(typeof(Player), "SpawnRecoveryItem")]
	internal static class Player_SpawnRecoveryItem_Patch
	{
		[HarmonyPrefix]
		private static void Prefix(Player __instance)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.CfgEnabled.Value || (Object)(object)__instance == (Object)null)
			{
				return;
			}
			try
			{
				if (Plugin.CfgSource.Value == "SceneSpawnPoint")
				{
					PlayerSpawnPoints val = Object.FindObjectOfType<PlayerSpawnPoints>();
					if ((Object)(object)val != (Object)null)
					{
						SpawnPoint spawnPointAtIndex = val.GetSpawnPointAtIndex(0);
						if ((Object)(object)spawnPointAtIndex != (Object)null)
						{
							__instance.SetRecoveryPositionOverride(spawnPointAtIndex.GetPosition());
							return;
						}
					}
				}
				if (Player_Initialize_Patch.TryGetHome(__instance, out var pos))
				{
					__instance.SetRecoveryPositionOverride(pos);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				if (logger != null)
				{
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(20, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("定位重生点失败,回收物将落在死亡地点: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					logger.LogWarning(val2);
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DeathRelocate";

		public const string PLUGIN_NAME = "DeathRelocate";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}