Decompiled source of DownloadGenshinWhenDowned v1.1.4

DownloadGenshinWhenDowned.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GTFOyuanshenmod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GTFOyuanshenmod")]
[assembly: AssemblyTitle("GTFOyuanshenmod")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 GTFOyuanshenmod
{
	[BepInPlugin("com.gtfo.mod.genshindownloader", "GTFO Genshin Downloader", "1.0.0")]
	[BepInProcess("GTFO.exe")]
	public class Plugin : BasePlugin
	{
		public const string PLUGIN_GUID = "com.gtfo.mod.genshindownloader";

		public const string PLUGIN_NAME = "GTFO Genshin Downloader";

		public const string PLUGIN_VERSION = "1.0.0";

		public const string GENSHIN_DOWNLOAD_URL = "https://ys-api.mihoyo.com/event/download_porter/link/ys_cn/official/pc_default";

		public static Plugin Instance;

		private static bool _hasTriggeredThisDown;

		public override void Load()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("GTFO Genshin Downloader");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] 模组加载成功!玩家倒地将自动启动原神下载。");
			}
			log.LogInfo(val);
			new Harmony("com.gtfo.mod.genshindownloader").PatchAll();
		}

		public static void TriggerGenshinDownload()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			if (_hasTriggeredThisDown)
			{
				return;
			}
			_hasTriggeredThisDown = true;
			Plugin instance = Instance;
			if (instance != null)
			{
				((BasePlugin)instance).Log.LogWarning((object)">>> [GTFO紧急救护] 检测到玩家倒地!正在打开默认浏览器下载《原神》... <<<");
			}
			try
			{
				Process.Start(new ProcessStartInfo
				{
					FileName = "https://ys-api.mihoyo.com/event/download_porter/link/ys_cn/official/pc_default",
					UseShellExecute = true
				});
			}
			catch (Exception ex)
			{
				Plugin instance2 = Instance;
				if (instance2 != null)
				{
					ManualLogSource log = ((BasePlugin)instance2).Log;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(9, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("无法调起浏览器: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogError(val);
				}
			}
		}

		public static void ResetDownState()
		{
			_hasTriggeredThisDown = false;
		}
	}
	[HarmonyPatch(typeof(PlayerAgent))]
	public static class PlayerAgentPatch
	{
		[HarmonyPatch("Setup")]
		[HarmonyPostfix]
		public static void SetupPostfix(PlayerAgent __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && ((Agent)__instance).IsLocallyOwned)
			{
				Plugin.ResetDownState();
			}
		}

		[HarmonyPatch("get_Alive")]
		[HarmonyPostfix]
		public static void GetAlivePostfix(PlayerAgent __instance, ref bool __result)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			if (!((Object)(object)__instance == (Object)null) && ((Agent)__instance).IsLocallyOwned && (int)GameStateManager.CurrentStateName == 10)
			{
				if (!__result)
				{
					Plugin.TriggerGenshinDownload();
				}
				else
				{
					Plugin.ResetDownState();
				}
			}
		}
	}
}