Decompiled source of ShakaraAlwaysOnsite v1.0.0

BepInEx/plugins/ShakaraAlwaysOnsite.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
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: AssemblyVersion("0.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 ShakaraAlwaysOnsite
{
	[BepInPlugin("ShakaraAlwaysOnsite.ShakaraAlwaysOnsite", "Shakara Always Onsite", "1.0.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private static readonly Type[] AlwaysOnPatchTypes = new Type[6]
		{
			typeof(MapperPermanentPatch.TimePassesPatch),
			typeof(MapperPermanentPatch.MapperLeavePrevPatch),
			typeof(MapperPermanentPatch.SceneTravelerEvalPatch),
			typeof(MapperPermanentPatch.MapperLeaveAllPatch),
			typeof(MapperPermanentPatch.ResetOnEnterPatch),
			typeof(DeactivateIfPlayerdataTruePatch)
		};

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("ShakaraAlwaysOnsite.ShakaraAlwaysOnsite");
			Type[] alwaysOnPatchTypes = AlwaysOnPatchTypes;
			foreach (Type type in alwaysOnPatchTypes)
			{
				try
				{
					val.PatchAll(type);
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("补丁注册失败 " + type.Name + "(目标方法可能不存在): " + ex.Message));
				}
			}
			Log.LogInfo((object)"Shakara Always Onsite 已加载");
		}
	}
	public static class MapperPermanentPatch
	{
		[HarmonyPatch(typeof(GameManager), "TimePasses")]
		public static class TimePassesPatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				ForceResetMapperFields();
			}
		}

		[HarmonyPatch(typeof(GameManager), "MapperLeavePreviousLocations")]
		public static class MapperLeavePrevPatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				ForceResetMapperFields();
			}
		}

		[HarmonyPatch("HutongGames.PlayMaker.Actions.SceneTravelerTempEval", "OnEnter")]
		public static class SceneTravelerEvalPatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				ForceResetMapperFields();
			}
		}

		[HarmonyPatch(typeof(PlayerData), "MapperLeaveAll")]
		public static class MapperLeaveAllPatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				ForceResetMapperFields();
			}
		}

		[HarmonyPatch(typeof(GameManager), "FinishedEnteringScene")]
		public static class ResetOnEnterPatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				ForceResetMapperFields();
			}
		}

		public static void ForceResetMapperFields()
		{
			PlayerData instance = PlayerData.instance;
			if (instance == null)
			{
				return;
			}
			try
			{
				instance.mapperAway = false;
			}
			catch
			{
			}
			FieldInfo[] fields = typeof(PlayerData).GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (!(fieldInfo.FieldType != typeof(bool)) && (fieldInfo.Name.StartsWith("MapperLeft") || fieldInfo.Name.StartsWith("SeenMapper")))
				{
					try
					{
						fieldInfo.SetValue(instance, false);
					}
					catch
					{
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(DeactivateIfPlayerdataTrue), "ForceEvaluate")]
	public static class DeactivateIfPlayerdataTruePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(DeactivateIfPlayerdataTrue __instance)
		{
			try
			{
				if (string.IsNullOrEmpty(__instance.boolName))
				{
					return true;
				}
				if (!__instance.boolName.StartsWith("MapperLeft"))
				{
					return true;
				}
				GameObject val = (((Object)(object)__instance.objectToDeactivate != (Object)null) ? __instance.objectToDeactivate : ((Component)__instance).gameObject);
				if ((Object)(object)val != (Object)null && !val.activeSelf)
				{
					val.SetActive(true);
				}
				return false;
			}
			catch
			{
			}
			return true;
		}
	}
}