Decompiled source of Shuffleify v1.3.0

Shuffleify.dll

Decompiled 8 months ago
using System;
using System.Diagnostics;
using System.IO;
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 BepInEx.Configuration;
using BepInEx.Logging;
using CustomAppAPI;
using HarmonyLib;
using Reptile;
using Reptile.Phone;
using Shufleify;
using Shufleify.Patches;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AppMusicHarmonyExample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AppMusicHarmonyExample")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("41731b67-afcf-4d35-a3c0-849e47a2b828")]
[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 Shuffler.Patches
{
	[HarmonyPatch(typeof(MusicPlayer))]
	internal class MusicPlayerPatches
	{
		public static AppMusicPlayer mySongInstance;

		[HarmonyPatch("PlayNext")]
		[HarmonyPostfix]
		public static void PlayNext_Postfix(MusicPlayer __instance)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			ShufleifyPlugin.Log.LogInfo((object)"Playing next SONG.");
			if (ShufleifyPlugin.shuffleState == 0)
			{
				try
				{
					PluginInfo val = new PluginInfo();
					Random random = new Random();
					if (__instance.AmountOfTracks > 0)
					{
						int amountOfTracks = __instance.AmountOfTracks;
						int num = random.Next(amountOfTracks - 1);
						if (amountOfTracks > 0)
						{
							__instance.PlayFrom(num, 0);
						}
					}
				}
				catch (Exception ex)
				{
					ShufleifyPlugin.Log.LogInfo((object)"failed");
					ShufleifyPlugin.Log.LogInfo((object)ex);
					throw;
				}
			}
			if (ShufleifyPlugin.shuffleState == 1)
			{
				__instance.PlayPrevious();
			}
		}
	}
}
namespace Shufleify
{
	[BepInPlugin("com.dragsun.Shufleify", "Shuffleify", "1.3.0")]
	public class ShufleifyPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.dragsun.Shufleify";

		private const string PluginName = "Shuffleify";

		private const string VersionString = "1.3.0";

		public static ManualLogSource Log = new ManualLogSource("Shuffleify");

		private Harmony harmony;

		public static int shuffleState = 0;

		public static GameplayUI ui;

		public static string ShuffleModeKey = "Recall Keyboard Shortcut";

		public static ConfigEntry<KeyboardShortcut> ShuffleMode;

		private static ShufleifyPlugin _instance;

		public static ShufleifyPlugin Instance => _instance;

		public string ModFolderPath => Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			ShuffleMode = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", ShuffleModeKey, new KeyboardShortcut((KeyCode)120, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
			ShuffleMode.SettingChanged += ConfigSettingChanged;
			harmony = new Harmony("com.dragsun.Shufleify");
			harmony.PatchAll();
			_instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: Shuffleify, VersionString: 1.3.0 is loading...");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: Shuffleify, VersionString: 1.3.0 is loaded.");
			Log = ((BaseUnityPlugin)this).Logger;
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = ShuffleMode.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				if (shuffleState < 2)
				{
					shuffleState++;
				}
				else
				{
					shuffleState = 0;
				}
				if (shuffleState == 0)
				{
					UI.Instance.ShowNotification("Music mode shuffled");
				}
				if (shuffleState == 1)
				{
					UI.Instance.ShowNotification("Music mode repeat");
				}
				if (shuffleState == 2)
				{
					UI.Instance.ShowNotification("Music mode normal");
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)shuffleState);
			}
		}

		private void ConfigSettingChanged(object sender, EventArgs e)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((e is SettingChangedEventArgs) ? e : null);
			if (val != null && val.ChangedSetting.Definition.Key == ShuffleModeKey)
			{
				KeyboardShortcut val2 = (KeyboardShortcut)val.ChangedSetting.BoxedValue;
			}
		}
	}
	public class ShufleifyApp : CustomApp
	{
		public static AppMusicPlayer mySongInstance;

		public override string DisplayName => "Shuffle !";

		public override Texture2D Icon => CustomApp.LoadTexture(Path.Combine(ShufleifyPlugin.Instance.ModFolderPath, "myAppIcon.png"));

		public override void OnAppEnable()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			((App)this).MyPhone.CloseCurrentApp();
			ShufleifyPlugin.Log.LogInfo((object)"If you see this... Hi :)");
			try
			{
				PluginInfo val = new PluginInfo();
				Random random = new Random();
				if (mySongInstance.GameMusicPlayer.AmountOfTracks > 0)
				{
					mySongInstance.PlaySong(0);
					int amountOfTracks = mySongInstance.GameMusicPlayer.AmountOfTracks;
					int num = random.Next(amountOfTracks - 1);
					if (amountOfTracks > 0)
					{
						mySongInstance.PlaySong(num);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.Log((object)"failed");
				Debug.Log((object)ex);
				throw;
			}
		}
	}
}
namespace Shufleify.Patches
{
	[HarmonyPatch(typeof(GameplayUI))]
	public class GameplayUIPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Init")]
		public static void Init(GameplayUI __instance)
		{
			ShufleifyPlugin.ui = __instance;
			((Component)__instance.gameplayScreen).gameObject.AddComponent<UI>();
		}
	}
	public class UI : MonoBehaviour
	{
		public static UI Instance;

		private TextMeshProUGUI m_label = null;

		private float m_notificationTimer = 5f;

		private bool m_active;

		private void Awake()
		{
			Instance = this;
			SetupLabel();
		}

		private void FixedUpdate()
		{
			UpdateTimer();
		}

		public void ShowNotification(string text)
		{
			((TMP_Text)m_label).text = text;
			m_notificationTimer = 5f;
			if (!m_active)
			{
				m_active = true;
				((Component)m_label).gameObject.SetActive(true);
			}
		}

		private void UpdateTimer()
		{
			if (m_notificationTimer < 0f && m_active)
			{
				m_notificationTimer = 5f;
				m_active = false;
				((Component)m_label).gameObject.SetActive(false);
				((TMP_Text)m_label).text = "";
			}
			if (m_active)
			{
				m_notificationTimer -= Time.fixedDeltaTime;
			}
		}

		private void SetupLabel()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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)
			m_label = new GameObject("FlyMode_Notification").AddComponent<TextMeshProUGUI>();
			UIManager uIManager = Core.Instance.UIManager;
			GameplayUI value = Traverse.Create((object)uIManager).Field<GameplayUI>("gameplay").Value;
			TextMeshProUGUI graffitiNewLabel = value.graffitiNewLabel;
			((TMP_Text)m_label).font = ((TMP_Text)graffitiNewLabel).font;
			((TMP_Text)m_label).fontSize = 35f;
			((TMP_Text)m_label).fontMaterial = ((TMP_Text)graffitiNewLabel).fontMaterial;
			((TMP_Text)m_label).alignment = (TextAlignmentOptions)257;
			RectTransform rectTransform = ((TMP_Text)m_label).rectTransform;
			rectTransform.anchorMin = new Vector2(0.1f, 0.5f);
			rectTransform.anchorMax = new Vector2(0.6f, 0.1f);
			rectTransform.pivot = new Vector2(0f, 1f);
			rectTransform.anchoredPosition = new Vector2(0.2f, 0.2f);
			((Transform)((TMP_Text)m_label).rectTransform).SetParent((Transform)(object)((Component)value.gameplayScreen).GetComponent<RectTransform>(), false);
		}
	}
	[HarmonyPatch(typeof(AppMusicPlayer))]
	internal class AppMusicPlayerPatch
	{
		[HarmonyPatch("OnAppInit")]
		[HarmonyPostfix]
		public static void OnAppInit_Postfix(AppMusicPlayer __instance)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			ShufleifyApp.mySongInstance = __instance;
			Debug.Log((object)__instance.GameMusicPlayer.AmountOfTracks);
			Debug.Log((object)__instance.GameMusicPlayer.AmountOfTracks);
			Debug.Log((object)__instance.GameMusicPlayer.AmountOfTracks);
			try
			{
				PluginInfo val = new PluginInfo();
				Random random = new Random();
				if (__instance.GameMusicPlayer.AmountOfTracks > 0)
				{
					__instance.PlaySong(10);
					int amountOfTracks = __instance.GameMusicPlayer.AmountOfTracks;
					int num = random.Next(amountOfTracks - 1);
					if (amountOfTracks > 0)
					{
						__instance.PlaySong(num);
						Console.Write("[Shuffleify] Random song number :  " + num);
						Console.Write("[Shuffleify] amount of tracks : " + __instance.GameMusicPlayer.AmountOfTracks);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.Log((object)"failed");
				Debug.Log((object)ex);
				throw;
			}
		}
	}
}