Decompiled source of CampfireRespawn v1.0.6

CampfireRespawn 1.0.6.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Peak_NoEndGame")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Peak_NoEndGame")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b253a047-7de8-4c49-8e85-524405e8513d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Peak_NoEndGame;

[BepInPlugin("com.Xiaohai.CampfireRespawn", "Campfire Respawn", "1.0.6")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "com.Xiaohai.CampfireRespawn";

	public const string NAME = "Campfire Respawn";

	public const string VERSION = "1.0.6";

	public static Plugin instance;

	public ConfigEntry<bool> campfireClearStatus;

	public ConfigEntry<bool> reviveAddCurse;

	public ConfigEntry<float> respawnItemChance;

	public ConfigEntry<KeyCode> respawnHotkey;

	public ConfigEntry<int> respawnMaxTimes;

	public void Awake()
	{
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		instance = this;
		campfireClearStatus = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "CampfireClearStatus", true, "是否在篝火处清除玩家状态  Should clear player status at campfire?");
		reviveAddCurse = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "ReviveClearStatus", true, "是否在复活时增加诅咒值 Should add curse state on respawn?");
		respawnItemChance = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "RespawnItemChance", 50f, "复活时每件物品生成的概率(0-100)Percentage chance for each item to respawn when player revives (0-100)");
		respawnHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Settings", "RespawnHotkey", (KeyCode)291, "强制复活热键 Hotkey for respawn");
		respawnMaxTimes = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "RespawnMaxTimes", 99, "复活次数限制 Maximum respawn times allowed");
		new Harmony("com.Xiaohai.CampfireRespawn").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Campfire Respawn v1.0.6 loaded successfully!篝火复活MOD v1.0.6 已加载!");
	}
}
public static class CampfireTracker
{
	public static Vector3? LastCampfirePosition = null;

	public static List<string> LastItemsName = new List<string>();

	public static void UpdateLastCampfire(Vector3 position)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		LastItemsName.Clear();
		LastCampfirePosition = position;
		foreach (Character allCharacter in Character.AllCharacters)
		{
			if ((Object)(object)allCharacter == (Object)null || (Object)(object)allCharacter.player == (Object)null)
			{
				continue;
			}
			List<ItemSlot> allPlayerItems = PlayerInventoryHelper.GetAllPlayerItems(allCharacter);
			foreach (ItemSlot item in allPlayerItems)
			{
				if (item != null && !item.IsEmpty())
				{
					LastItemsName.Add(((Object)item.prefab).name);
				}
			}
			if ((Object)(object)allCharacter.refs.afflictions != (Object)null)
			{
				allCharacter.refs.afflictions.ClearAllStatus(true);
			}
		}
	}

	public static void GenerateItemsAroundCampfire(Vector3 position)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		if (!LastCampfirePosition.HasValue || LastItemsName.Count == 0)
		{
			return;
		}
		foreach (string item in LastItemsName)
		{
			int num = Random.Range(0, 100);
			if ((float)num < Plugin.instance.respawnItemChance.Value)
			{
				Vector3 val = position + Random.insideUnitSphere * 5f;
				val.y = position.y + 1f;
				if (!string.IsNullOrEmpty(item))
				{
					PhotonNetwork.InstantiateItemRoom(item, val, Quaternion.identity);
				}
				else
				{
					Debug.LogWarning((object)"GenerateItemsAroundCampfire中的itemName为空!物品名字不存在!");
				}
			}
		}
		LastItemsName.Clear();
	}

	public static void ResetFog()
	{
		OrbFogHandler instance = Singleton<OrbFogHandler>.Instance;
		if ((Object)(object)instance != (Object)null)
		{
			instance.currentSize = Patch.fogSize;
			instance.photonView.RPC("RPCA_SyncFog", (RpcTarget)0, new object[2]
			{
				Patch.fogSize,
				instance.isMoving
			});
		}
	}
}
public static class PlayerInventoryHelper
{
	public static List<ItemSlot> GetAllPlayerItems(Character player)
	{
		List<ItemSlot> list = new List<ItemSlot>();
		ItemSlot[] itemSlots = player.player.itemSlots;
		ItemSlot[] array = itemSlots;
		foreach (ItemSlot val in array)
		{
			if (!val.IsEmpty())
			{
				list.Add(val);
			}
		}
		if (!((ItemSlot)player.player.backpackSlot).IsEmpty())
		{
			BackpackData backpackData = GetBackpackData((ItemSlot)(object)player.player.backpackSlot);
			if (backpackData != null)
			{
				ItemSlot[] itemSlots2 = backpackData.itemSlots;
				foreach (ItemSlot val2 in itemSlots2)
				{
					if (!val2.IsEmpty())
					{
						list.Add(val2);
					}
				}
			}
		}
		return list;
	}

	public static Item GetEquippedItem(Character player)
	{
		if (player.refs.items.currentSelectedSlot.IsSome)
		{
			byte value = player.refs.items.currentSelectedSlot.Value;
			ItemSlot itemSlot = player.player.GetItemSlot(value);
			return itemSlot.prefab;
		}
		return null;
	}

	private static BackpackData GetBackpackData(ItemSlot backpackSlot)
	{
		if (backpackSlot.IsEmpty() || backpackSlot.data == null)
		{
			return null;
		}
		BackpackData result = default(BackpackData);
		if (backpackSlot.data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref result))
		{
			return result;
		}
		return null;
	}
}
[HarmonyPatch]
public static class Patch
{
	[HarmonyPatch(typeof(OrbFogHandler))]
	public static class OrbFogHandlerrPatch
	{
		[HarmonyPatch("InitNewSphere")]
		[HarmonyPostfix]
		private static void InitNewSpherePatch(ref FogSphereOrigin newOrigin)
		{
			OrbFogHandler instance = Singleton<OrbFogHandler>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				Debug.LogError((object)"MountainProgressHandlerPatch: OrbFogHandler is null 实例未找到!");
				return;
			}
			fogSize = newOrigin.size;
			Debug.Log((object)$"MountainProgressHandlerPatch: 雾的初始大小为 fogsize= {fogSize}");
		}
	}

	[HarmonyPatch(typeof(Campfire))]
	private static class CampfirePatch
	{
		private static float clearTimer;

		[HarmonyPatch("Light_Rpc")]
		private static void Postfix(Campfire __instance)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsMasterClient)
			{
				return;
			}
			Campfire[] array = Object.FindObjectsByType<Campfire>((FindObjectsSortMode)0);
			float num = 9999999f;
			Campfire val = null;
			Campfire[] array2 = array;
			foreach (Campfire val2 in array2)
			{
				float num2 = Vector3.Distance(((Component)val2).transform.position, Character.localCharacter.Center);
				Debug.Log((object)$"找到篝火位置: {((Component)val2).transform.position},与玩家距离{num2:F2}m");
				if (num2 < num)
				{
					num = num2;
					val = val2;
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				CampfireTracker.UpdateLastCampfire(((Component)val).transform.position);
				Debug.Log((object)$"记录篝火位置: {((Component)val).transform.position},当前点亮篝火{((Component)__instance).transform.position}");
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(Campfire __instance)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Invalid comparison between Unknown and I4
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Invalid comparison between Unknown and I4
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Invalid comparison between Unknown and I4
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Invalid comparison between Unknown and I4
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Invalid comparison between Unknown and I4
			clearTimer += Time.deltaTime;
			if (!Plugin.instance.campfireClearStatus.Value)
			{
				return;
			}
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter != (Object)null) || !((Object)(object)((Component)localCharacter).transform != (Object)null) || localCharacter.data.dead || localCharacter.refs.afflictions.currentStatuses.Length == 0 || !(Vector3.Distance(((Component)__instance).transform.position, Character.localCharacter.Center) <= __instance.moraleBoostRadius))
			{
				return;
			}
			int num = Enum.GetNames(typeof(STATUSTYPE)).Length;
			for (int i = 0; i < num; i++)
			{
				STATUSTYPE val = (STATUSTYPE)i;
				if ((int)val != 7 && (int)val != 4 && (int)val != 9 && (int)val != 5 && (int)val != 8 && clearTimer >= 3f)
				{
					localCharacter.refs.afflictions.SetStatus(val, 0f);
					clearTimer = 0f;
				}
			}
		}
	}

	[HarmonyPatch(typeof(MountainProgressHandler))]
	private static class PatchMountainProgressHandler
	{
		[HarmonyPatch("CheckAreaAchievement")]
		public static void Prefix(MountainProgressHandler __instance, ref ProgressPoint pointReached)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			if (pointReached.title.ToLower() != "shore")
			{
				return;
			}
			List<Campfire> list = Object.FindObjectsByType<Campfire>((FindObjectsSortMode)0).ToList();
			foreach (Campfire item in list)
			{
				if ((Object)(object)Character.localCharacter != (Object)null)
				{
					float num = Vector3.Distance(((Component)item).transform.position, Character.localCharacter.Center);
					if (num < 100f)
					{
						CampfireTracker.UpdateLastCampfire(((Component)item).transform.position);
						break;
					}
				}
			}
			ReviewHandler.Instance.ResetReviveTimes();
			ReviewUI.ActivateDisplay();
		}
	}

	[HarmonyPatch(typeof(Character))]
	public static class CharacterPatch
	{
		[HarmonyPatch("RPCEndGame")]
		[HarmonyPostfix]
		private static void RPCEndGamePostfix(Character __instance)
		{
			ReviewUI.isActive = false;
			CampfireTracker.LastCampfirePosition = null;
			CampfireTracker.LastItemsName.Clear();
			Debug.Log((object)"复活次数已重置,篝火位置已清除");
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyUp(Plugin.instance.respawnHotkey.Value) && PhotonNetwork.IsMasterClient)
			{
				ReviewHandler.RespawnAllAtCampfire();
			}
		}

		[HarmonyPatch("FixedUpdate")]
		[HarmonyPostfix]
		private static void FixedUpdatePostfix(Character __instance)
		{
			if (AllPlayerDeadOrDown() && __instance.view.IsMine && PhotonNetwork.IsMasterClient && CampfireTracker.LastCampfirePosition.HasValue)
			{
				ReviewHandler.RespawnAllAtCampfire();
			}
		}

		private static bool AllPlayerDeadOrDown()
		{
			foreach (Character allCharacter in Character.AllCharacters)
			{
				if ((Object)(object)allCharacter != (Object)null && !allCharacter.data.dead && !allCharacter.data.fullyPassedOut)
				{
					return false;
				}
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(GUIManager))]
	private static class GUIManagerPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch(GUIManager __instance)
		{
			InitUI(__instance);
		}

		private static void InitUI(GUIManager __instance)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_007c: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			AscentUI componentInChildren = ((Component)__instance).GetComponentInChildren<AscentUI>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return;
			}
			Transform val = (Transform)(RectTransform)Object.Instantiate<Transform>(((Component)componentInChildren).transform, ((Component)componentInChildren).transform.parent);
			((Object)val).name = "ReviewUI";
			Object.Destroy((Object)(object)((Component)val).GetComponent<AscentUI>());
			((Component)val).gameObject.AddComponent<ReviewUI>();
			RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.anchorMin = new Vector2(0.5f, 0f);
				val2.anchorMax = new Vector2(0.5f, 0f);
				val2.pivot = new Vector2(0.5f, 0f);
				val2.anchoredPosition = new Vector2(0f, 10f);
				val2.sizeDelta = new Vector2(400f, 120f);
				TMP_Text componentInChildren2 = ((Component)val2).GetComponentInChildren<TMP_Text>();
				if ((Object)(object)componentInChildren2 != (Object)null)
				{
					componentInChildren2.alignment = (TextAlignmentOptions)257;
					componentInChildren2.fontSize = 40f;
					((Graphic)componentInChildren2).color = Color.white;
				}
			}
			else
			{
				Debug.LogError((object)"ReviewUI必须挂载在RectTransform上");
			}
		}
	}

	[HarmonyPatch(typeof(RunManager))]
	private static class RunManagerPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePostfix(RunManager __instance)
		{
			if ((Object)(object)((Component)__instance).gameObject.GetComponent<ReviewHandler>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<ReviewHandler>();
				Debug.Log((object)"RunManager中添加了ReviewHandler组件");
			}
			else
			{
				Debug.Log((object)"RunManager中已存在ReviewHandler组件");
			}
		}
	}

	public static float fogSize = 300f;
}
public class ReviewUI : MonoBehaviourPun
{
	private float displayTimer = 0f;

	public TMP_Text text;

	public static bool isActive;

	public float timer = 0f;

	public static ReviewUI instance;

	private void Awake()
	{
		instance = this;
		text = ((Component)this).GetComponentInChildren<TMP_Text>();
		text.richText = true;
	}

	private void Update()
	{
		if (isActive)
		{
			text.text = $"<color=red><size=45>♥</color></size>{Plugin.instance.respawnMaxTimes.Value - ReviewHandler.Instance.reviveTimes}";
			displayTimer -= Time.deltaTime;
			if (displayTimer <= 0f)
			{
				isActive = false;
			}
		}
		else
		{
			text.text = " ";
		}
	}

	public static void ActivateDisplay()
	{
		isActive = true;
		instance.displayTimer = 10f;
	}
}
public class ReviewHandler : MonoBehaviourPun
{
	private static float lastRespawnTime;

	public int reviveTimes;

	public static ReviewHandler Instance { get; private set; }

	private void Awake()
	{
		Instance = this;
	}

	public void AddReviveTimes()
	{
		reviveTimes++;
		if (reviveTimes >= Plugin.instance.respawnMaxTimes.Value)
		{
			ReviewUI.isActive = false;
		}
		else
		{
			ReviewUI.ActivateDisplay();
		}
		((MonoBehaviourPun)this).photonView.RPC("RPCA_SetReviveTimes", (RpcTarget)0, new object[1] { reviveTimes });
	}

	public void ResetReviveTimes()
	{
		lastRespawnTime = 0f;
		reviveTimes = 0;
		((MonoBehaviourPun)this).photonView.RPC("RPCA_SetReviveTimes", (RpcTarget)0, new object[1] { reviveTimes });
	}

	[PunRPC]
	public void RPCA_SetReviveTimes(int times)
	{
		reviveTimes = times;
	}

	public static void RespawnAllAtCampfire()
	{
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Invalid comparison between Unknown and I4
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		if (!CampfireTracker.LastCampfirePosition.HasValue || !PhotonNetwork.IsMasterClient || Time.time - lastRespawnTime < 2f || Instance.reviveTimes >= Plugin.instance.respawnMaxTimes.Value)
		{
			return;
		}
		float num = Random.Range(-3f, 3f);
		float num2 = Random.Range(-3f, 3f);
		Vector3 value = CampfireTracker.LastCampfirePosition.Value;
		((Vector3)(ref value))..ctor(value.x + num, value.y + 1f, value.z + num2);
		Debug.Log((object)$"在篝火位置复活所有玩家: {CampfireTracker.LastCampfirePosition.Value}");
		foreach (Character allCharacter in Character.AllCharacters)
		{
			if ((Object)(object)allCharacter != (Object)null)
			{
				if (allCharacter.data.dead)
				{
					((MonoBehaviourPun)allCharacter).photonView.RPC("RPCA_ReviveAtPosition", (RpcTarget)3, new object[2]
					{
						value,
						Plugin.instance.reviveAddCurse.Value
					});
				}
				else
				{
					((MonoBehaviourPun)allCharacter).photonView.RPC("WarpPlayerRPC", (RpcTarget)3, new object[2] { value, true });
					allCharacter.refs.afflictions.ClearAllStatus(true);
				}
			}
		}
		if (CampfireTracker.LastCampfirePosition.HasValue)
		{
			CampfireTracker.GenerateItemsAroundCampfire(CampfireTracker.LastCampfirePosition.Value);
			CampfireTracker.ResetFog();
		}
		int currentSegment = Singleton<MapHandler>.Instance.currentSegment;
		ProgressPoint val = Singleton<MountainProgressHandler>.Instance.progressPoints[currentSegment];
		if ((int)LocalizedText.CURRENT_LANGUAGE == 9)
		{
			GUIManager.instance.SetHeroTitle("继续加油", val.clip);
		}
		else
		{
			GUIManager.instance.SetHeroTitle("Nice Try", val.clip);
		}
		Instance.AddReviveTimes();
		lastRespawnTime = Time.time;
	}
}