Decompiled source of DeathTips v1.2.0

BepInEx/plugins/MaoNu.DeathTips.dll

Decompiled 4 days ago
using System;
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 FishNet.Object;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.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 DownedNotice
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MaoNu.DownedNotice";

		public const string PLUGIN_NAME = "DownedNotice";

		public const string PLUGIN_VERSION = "1.2.0";
	}
	[BepInPlugin("MaoNu.DownedNotice", "DownedNotice", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		private ConfigEntry<bool> isNoticeEnabled;

		private ConfigEntry<string> languageMode;

		private ConfigEntry<bool> debugLogging;

		private Harmony _harmony;

		public static Plugin Instance { get; private set; }

		public bool IsNoticeEnabled
		{
			get
			{
				if (isNoticeEnabled != null)
				{
					return isNoticeEnabled.Value;
				}
				return false;
			}
		}

		public bool DebugLogging
		{
			get
			{
				if (debugLogging != null)
				{
					return debugLogging.Value;
				}
				return false;
			}
		}

		public string LanguageMode
		{
			get
			{
				if (languageMode == null)
				{
					return "auto";
				}
				return languageMode.Value;
			}
		}

		public void LogInfo(string msg)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)msg);
		}

		public void LogWarning(string msg)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)msg);
		}

		public void LogError(string msg)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)msg);
		}

		public void LogDebug(string msg)
		{
			if (DebugLogging)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)msg);
			}
		}

		private void Awake()
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Expected O, but got Unknown
			//IL_01fd: Expected O, but got Unknown
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[DownedNotice] v1.2.0 loaded!");
			isNoticeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("提示设置", "倒地救起提示", true, "是否在聊天窗显示玩家倒地/复活/被救活提示");
			languageMode = ((BaseUnityPlugin)this).Config.Bind<string>("提示设置", "语言", "auto", new ConfigDescription("提示语言:auto=跟随客户端语言,zh=强制简体中文,zh-tw=强制繁体中文,en=强制英文", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[4] { "auto", "zh", "zh-tw", "en" }), Array.Empty<object>()));
			debugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("调试设置", "详细日志", true, "输出详细调试日志(排查问题用)");
			L.ForcedLang = LanguageMode;
			_harmony = new Harmony("MaoNu.DownedNotice.Patches");
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(PlayerManager), "OnPlayerDied", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					MethodInfo methodInfo2 = AccessTools.Method(typeof(DownedNoticePatch), "OnPlayerDiedPostfix", (Type[])null, (Type[])null);
					if (methodInfo2 != null)
					{
						_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						((BaseUnityPlugin)this).Logger.LogInfo((object)"[倒地提示] PlayerManager.OnPlayerDied 补丁安装成功");
					}
					else
					{
						((BaseUnityPlugin)this).Logger.LogError((object)"[倒地提示] 找不到 OnPlayerDiedPostfix 方法");
					}
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"[倒地提示] 找不到 PlayerManager.OnPlayerDied");
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[倒地提示] " + ex.Message));
			}
			try
			{
				MethodInfo methodInfo3 = AccessTools.Method(typeof(PlayerDying), "ResurrectEffect", (Type[])null, (Type[])null);
				if (methodInfo3 != null)
				{
					MethodInfo methodInfo4 = AccessTools.Method(typeof(DownedNoticePatch), "ResurrectEffectPrefix", (Type[])null, (Type[])null);
					MethodInfo methodInfo5 = AccessTools.Method(typeof(DownedNoticePatch), "ResurrectEffectPostfix", (Type[])null, (Type[])null);
					if (methodInfo4 != null && methodInfo5 != null)
					{
						_harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(methodInfo4), new HarmonyMethod(methodInfo5), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						((BaseUnityPlugin)this).Logger.LogInfo((object)"[复活提示] PlayerDying.ResurrectEffect 补丁安装成功");
					}
					else
					{
						((BaseUnityPlugin)this).Logger.LogError((object)"[复活提示] 找不到 ResurrectEffectPrefix/Postfix 方法");
					}
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"[复活提示] 找不到 PlayerDying.ResurrectEffect");
				}
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[复活提示] " + ex2.Message));
			}
		}

		private void OnDestroy()
		{
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch
			{
			}
		}
	}
	internal static class L
	{
		public static string ForcedLang = "auto";

		public static bool IsSimplifiedChinese()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Invalid comparison between Unknown and I4
			if (ForcedLang == "zh")
			{
				return true;
			}
			if (ForcedLang == "zh-tw" || ForcedLang == "en")
			{
				return false;
			}
			try
			{
				return LocalizationManager.CurLanguage == 2;
			}
			catch
			{
				SystemLanguage systemLanguage = Application.systemLanguage;
				return (int)systemLanguage == 6 || (int)systemLanguage == 40;
			}
		}

		public static bool IsTraditionalChinese()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Invalid comparison between Unknown and I4
			if (ForcedLang == "zh-tw")
			{
				return true;
			}
			if (ForcedLang == "zh" || ForcedLang == "en")
			{
				return false;
			}
			try
			{
				return LocalizationManager.CurLanguage == 3;
			}
			catch
			{
				return (int)Application.systemLanguage == 41;
			}
		}

		public static string Downed()
		{
			if (IsTraditionalChinese())
			{
				return "倒下了!";
			}
			if (IsSimplifiedChinese())
			{
				return "倒下了!";
			}
			return "is down!";
		}

		public static string Respawned()
		{
			if (IsTraditionalChinese())
			{
				return "復活了!";
			}
			if (IsSimplifiedChinese())
			{
				return "复活了!";
			}
			return "has respawned!";
		}

		public static string Revived()
		{
			if (IsTraditionalChinese())
			{
				return "被救活了!";
			}
			if (IsSimplifiedChinese())
			{
				return "被救活了!";
			}
			return "has been revived!";
		}
	}
	internal static class DownedNoticePatch
	{
		public static void OnPlayerDiedPostfix(Player player)
		{
			if (!((Object)(object)Plugin.Instance == (Object)null) && !((Object)(object)player == (Object)null) && Plugin.Instance.IsNoticeEnabled && (Object)(object)Server.Instance != (Object)null && ((NetworkBehaviour)Server.Instance).IsServerInitialized)
			{
				ulong num = 0uL;
				try
				{
					num = player.SteamID;
				}
				catch
				{
				}
				Plugin.Instance.LogDebug($"[倒地提示] steamID={num}");
				SendSystemMessage(num, L.Downed());
			}
		}

		public static void ResurrectEffectPrefix(PlayerDying __instance, out bool __state)
		{
			__state = (Object)(object)__instance != (Object)null && __instance.IsDead;
		}

		public static void ResurrectEffectPostfix(PlayerDying __instance, bool respawned, bool __state)
		{
			if ((Object)(object)Plugin.Instance == (Object)null || (Object)(object)__instance == (Object)null || !Plugin.Instance.IsNoticeEnabled || !__state || !((Object)(object)Server.Instance != (Object)null) || !((NetworkBehaviour)Server.Instance).IsServerInitialized)
			{
				return;
			}
			Player val = null;
			try
			{
				val = AccessTools.FieldRefAccess<PlayerDying, Player>("_player").Invoke(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Instance.LogWarning("[复活提示] 获取 _player 失败: " + ex.Message);
				return;
			}
			if (!((Object)(object)val == (Object)null))
			{
				ulong num = 0uL;
				try
				{
					num = val.SteamID;
				}
				catch
				{
				}
				string message = (respawned ? L.Respawned() : L.Revived());
				Plugin.Instance.LogDebug($"[复活提示] steamID={num} respawned={respawned}");
				SendSystemMessage(num, message);
			}
		}

		private static void SendSystemMessage(ulong steamID, string message)
		{
			if ((Object)(object)Plugin.Instance == (Object)null)
			{
				return;
			}
			try
			{
				OnlineChatManager instance = OnlineChatManager.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance.SendChatMessage(steamID, message);
					Plugin.Instance.LogDebug("[系统消息] 已通过 OnlineChatManager 发送: " + message);
				}
				else
				{
					Plugin.Instance.LogWarning("[系统消息] OnlineChatManager.Instance 为 null(聊天系统未就绪)");
				}
			}
			catch (Exception ex)
			{
				Plugin.Instance.LogWarning("[系统消息] OnlineChatManager 调用失败: " + ex.Message);
			}
		}
	}
}