Decompiled source of TurnThePage v1.0.0

TurnThePage.dll

Decompiled a week ago
using System.Collections;
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.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("YourName")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("自动将动作翻页到第二页")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TurnThePage")]
[assembly: AssemblyTitle("TurnThePage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace TurnThePage;

public static class EmoteHelper
{
	public static bool alreadyTriggered;

	public static IEnumerator SegmentMonitor()
	{
		while (true)
		{
			yield return (object)new WaitForSeconds(1f);
			if (MapHandler.ExistsAndInitialized)
			{
				Segment currentSegmentNumber = MapHandler.CurrentSegmentNumber;
				if (((int)currentSegmentNumber == 0 || (int)currentSegmentNumber == 1) && !alreadyTriggered)
				{
					Debug.Log((object)("[TurnThePage] Detected segment: " + ((object)(Segment)(ref currentSegmentNumber)).ToString() + ". Triggering emote wheel."));
					Trigger();
					alreadyTriggered = true;
				}
			}
		}
	}

	public static void Trigger()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		if (!alreadyTriggered)
		{
			CoroutineRunner coroutineRunner = new GameObject("TurnThePage_Runner").AddComponent<CoroutineRunner>();
			((MonoBehaviour)coroutineRunner).StartCoroutine(Routine(coroutineRunner));
		}
	}

	private static IEnumerator Routine(CoroutineRunner runner)
	{
		yield return (object)new WaitForSeconds(0.5f);
		EmoteWheel wheel = null;
		EmoteWheel[] array = Resources.FindObjectsOfTypeAll<EmoteWheel>();
		Scene scene;
		foreach (EmoteWheel val in array)
		{
			if ((Object)(object)val != (Object)null)
			{
				scene = ((Component)val).gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					wheel = val;
					break;
				}
			}
		}
		if ((Object)(object)wheel == (Object)null)
		{
			Debug.LogWarning((object)"[TurnThePage] EmoteWheel not found! Retrying in 2s...");
			yield return (object)new WaitForSeconds(2f);
			array = Resources.FindObjectsOfTypeAll<EmoteWheel>();
			foreach (EmoteWheel val2 in array)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					scene = ((Component)val2).gameObject.scene;
					if (((Scene)(ref scene)).IsValid())
					{
						wheel = val2;
						break;
					}
				}
			}
		}
		if ((Object)(object)wheel == (Object)null)
		{
			Debug.LogError((object)"[TurnThePage] EmoteWheel still not found. Aborting.");
			Object.Destroy((Object)(object)((Component)runner).gameObject);
			yield break;
		}
		((Component)wheel).gameObject.SetActive(true);
		Debug.Log((object)"[TurnThePage] EmoteWheel activated.");
		yield return null;
		yield return null;
		int value = Traverse.Create((object)wheel).Field("page").GetValue<int>();
		Debug.Log((object)("[TurnThePage] Current page: " + value));
		object value2 = Traverse.Create((object)wheel).Field("nextButton").GetValue();
		bool flag = false;
		if (value2 != null)
		{
			object? value3 = value2.GetType().GetProperty("gameObject").GetValue(value2);
			GameObject val3 = (GameObject)((value3 is GameObject) ? value3 : null);
			if ((Object)(object)val3 != (Object)null && val3.activeInHierarchy)
			{
				flag = true;
			}
		}
		if (value != 1 && flag)
		{
			object value4 = value2.GetType().GetProperty("onClick").GetValue(value2);
			value4.GetType().GetMethod("Invoke").Invoke(value4, null);
			Debug.Log((object)"[TurnThePage] Flipped to page 2.");
		}
		yield return (object)new WaitForSeconds(1.5f);
		if ((Object)(object)wheel != (Object)null && ((Component)wheel).gameObject.activeSelf)
		{
			((Component)wheel).gameObject.SetActive(false);
			Debug.Log((object)"[TurnThePage] EmoteWheel closed.");
		}
		Object.Destroy((Object)(object)((Component)runner).gameObject);
	}
}
[HarmonyPatch(typeof(MapHandler))]
public static class MapLoadPatches
{
	[HarmonyPatch("InitializeMap")]
	[HarmonyPostfix]
	private static void InitializeMap_Postfix()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		EmoteHelper.alreadyTriggered = false;
		Debug.Log((object)"[TurnThePage] Map initialized, starting segment monitor...");
		((MonoBehaviour)new GameObject("TurnThePage_Monitor").AddComponent<CoroutineRunner>()).StartCoroutine(EmoteHelper.SegmentMonitor());
	}

	[HarmonyPatch("GoToSegment")]
	[HarmonyPostfix]
	private static void GoToSegment_Postfix(Segment s)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Invalid comparison between Unknown and I4
		Debug.Log((object)("[TurnThePage] GoToSegment called with: " + ((object)(Segment)(ref s)).ToString()));
		if ((int)s == 1)
		{
			EmoteHelper.Trigger();
		}
	}
}
internal class CoroutineRunner : MonoBehaviour
{
}
[BepInPlugin("com.yourname.turnthepage", "TurnThePage", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public const string PluginGuid = "com.yourname.turnthepage";

	public const string PluginName = "TurnThePage";

	public const string PluginVersion = "1.0.0";

	public static Plugin Instance { get; private set; }

	public static ManualLogSource Log { get; private set; }

	private void Awake()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TurnThePage is loading...");
		new Harmony("com.yourname.turnthepage").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TurnThePage loaded!");
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "TurnThePage";

	public const string PLUGIN_NAME = "TurnThePage";

	public const string PLUGIN_VERSION = "1.0.0";
}