using System.Collections.Generic;
using System.Diagnostics;
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 HarmonyLib;
using Photon.Pun;
using UnityEngine;
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.NoEndGame", "xiaohai_NoEndGame", "1.0.0")]
public class NoEndGame : BaseUnityPlugin
{
public void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
new Harmony("com.Xiaohai.NoEndGame").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"NoEndGame v1.0.0 loaded successfully!篝火复活MOD已加载!");
}
}
public static class CampfireTracker
{
public static Vector3? LastCampfirePosition = null;
public static List<string> LastItemsName = new List<string>();
public static float fogSize = 0f;
public static void UpdateLastCampfire(Vector3 position)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
LastItemsName.Clear();
((Vector3)(ref position))..ctor(position.x, position.y + 3f, position.z);
LastCampfirePosition = position;
OrbFogHandler instance = Singleton<OrbFogHandler>.Instance;
fogSize = (((Object)(object)instance != (Object)null) ? instance.currentSize : 600f);
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_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: 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_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: 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(1, 100);
if (num <= 50)
{
Vector3 val = position + Random.insideUnitSphere * 10f;
val.y = position.y + 3f;
PhotonNetwork.InstantiateItemRoom(item, val, Quaternion.identity);
}
}
LastItemsName.Clear();
}
public static void ResetFog()
{
OrbFogHandler instance = Singleton<OrbFogHandler>.Instance;
if ((Object)(object)instance != (Object)null)
{
instance.currentSize = fogSize;
instance.photonView.RPC("RPCA_SyncFog", (RpcTarget)0, new object[2] { 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(CharacterAfflictions), "UpdateNormalStatuses")]
private class Patch_UpdateNormalStatuses
{
private static bool Prefix(CharacterAfflictions __instance)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
Character character = __instance.character;
if ((Object)(object)character == (Object)null || !character.IsLocal || character.data.dead)
{
return true;
}
Campfire[] array = Object.FindObjectsByType<Campfire>((FindObjectsSortMode)0);
Campfire[] array2 = array;
foreach (Campfire val in array2)
{
if (Vector3.Distance(((Component)val).transform.position, character.Center) <= val.moraleBoostRadius)
{
return false;
}
}
return true;
}
}
}
[HarmonyPatch(typeof(Campfire))]
internal class CampfireLightPatch
{
[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(typeof(Character))]
internal static class CharacterPatch
{
private static float lastRespawnTime;
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void UpdatePostfix()
{
if (Input.GetKeyDown((KeyCode)291) && PhotonNetwork.IsMasterClient)
{
RespawnAllAtCampfire();
}
}
[HarmonyPatch("FixedUpdate")]
[HarmonyPostfix]
private static void FixedUpdatePostfix(Character __instance)
{
if (Character.PlayerIsDeadOrDown() && __instance.view.IsMine && PhotonNetwork.IsMasterClient && Time.time - lastRespawnTime > 15f && CampfireTracker.LastCampfirePosition.HasValue)
{
RespawnAllAtCampfire();
lastRespawnTime = Time.time;
}
}
private static void RespawnAllAtCampfire()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
if (!CampfireTracker.LastCampfirePosition.HasValue || !PhotonNetwork.IsMasterClient)
{
return;
}
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]
{
CampfireTracker.LastCampfirePosition.Value,
false
});
}
else
{
allCharacter.refs.afflictions.ClearAllStatus(true);
((MonoBehaviourPun)allCharacter).photonView.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2]
{
CampfireTracker.LastCampfirePosition.Value,
false
});
}
}
}
if (CampfireTracker.LastCampfirePosition.HasValue)
{
CampfireTracker.GenerateItemsAroundCampfire(CampfireTracker.LastCampfirePosition.Value);
CampfireTracker.ResetFog();
}
}
}