Decompiled source of Asset Browser v1.0.0

AssetBrowser.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using SideLoader;
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: AssemblyCompany("AssetBrowser")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SL_CustomEffects")]
[assembly: AssemblyTitle("AssetBrowser")]
[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 AssetBrowser
{
	[BepInPlugin("com.wrango.assetbrowser", "Asset Browser", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class AssetBrowserPlugin : BaseUnityPlugin
	{
		public const string GUID = "com.wrango.assetbrowser";

		public const string NAME = "Asset Browser";

		public const string VERSION = "1.0.0";

		internal static ManualLogSource Log;

		private ConfigEntry<bool> m_enabled;

		private ConfigEntry<float> m_autoStopSeconds;

		private ConfigEntry<KeyboardShortcut> m_keyNext;

		private ConfigEntry<KeyboardShortcut> m_keyPrev;

		private ConfigEntry<KeyboardShortcut> m_keyJumpForward;

		private ConfigEntry<KeyboardShortcut> m_keyJumpBack;

		private ConfigEntry<KeyboardShortcut> m_keyReplay;

		private ConfigEntry<KeyboardShortcut> m_keyNextGroup;

		private ConfigEntry<KeyboardShortcut> m_keyPrevGroup;

		private ConfigEntry<KeyboardShortcut> m_keyKeep;

		private ConfigEntry<KeyboardShortcut> m_keyToggleMode;

		private ConfigEntry<KeyboardShortcut> m_keyStop;

		private ConfigEntry<int> m_jumpSize;

		private static readonly string[] Groups = new string[7] { "SFX", "ENV", "UI", "FT", "BGM", "LOC", "CS" };

		private readonly Dictionary<string, List<Sounds>> m_byGroup = new Dictionary<string, List<Sounds>>();

		private int m_groupIndex;

		private int m_soundIndex;

		private SplitableSoundSource m_playing;

		private Sounds m_playingSound;

		private float m_stopAt = -1f;

		private bool m_vfxMode;

		private int m_vfxIndex;

		private readonly List<VFXPrefabs> m_vfxList = new List<VFXPrefabs>();

		private GameObject m_vfxInstance;

		private List<Sounds> Current => m_byGroup[Groups[m_groupIndex]];

		private void BindConfig()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			m_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch. Turn off to ignore every hotkey without uninstalling.");
			m_autoStopSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Auto-stop seconds", 5f, "Cut a playing sound after this many seconds. Many are loops or long ambience.");
			m_jumpSize = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Jump size", 25, "How many entries the jump keys skip.");
			m_keyNext = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Next", new KeyboardShortcut((KeyCode)258, Array.Empty<KeyCode>()), "Next sound or VFX.");
			m_keyPrev = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Previous", new KeyboardShortcut((KeyCode)264, Array.Empty<KeyCode>()), "Previous sound or VFX.");
			m_keyJumpForward = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Jump forward", new KeyboardShortcut((KeyCode)262, Array.Empty<KeyCode>()), "Skip forward by the jump size.");
			m_keyJumpBack = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Jump back", new KeyboardShortcut((KeyCode)260, Array.Empty<KeyCode>()), "Skip back by the jump size.");
			m_keyReplay = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Replay", new KeyboardShortcut((KeyCode)261, Array.Empty<KeyCode>()), "Play the current entry again.");
			m_keyNextGroup = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Next group", new KeyboardShortcut((KeyCode)265, Array.Empty<KeyCode>()), "Next sound group. Sound mode only - VFX has no groups.");
			m_keyPrevGroup = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Previous group", new KeyboardShortcut((KeyCode)263, Array.Empty<KeyCode>()), "Previous sound group. Sound mode only.");
			m_keyKeep = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Keep", new KeyboardShortcut((KeyCode)256, Array.Empty<KeyCode>()), "Write the current entry to the log as a line ready to paste into an XML.");
			m_keyToggleMode = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Switch mode", new KeyboardShortcut((KeyCode)268, Array.Empty<KeyCode>()), "Switch between browsing sounds and browsing VFX.");
			m_keyStop = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Keys", "Stop", new KeyboardShortcut((KeyCode)269, Array.Empty<KeyCode>()), "Silence the current sound and clear any looping VFX.");
		}

		internal void Awake()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			BindConfig();
			string[] groups = Groups;
			foreach (string key in groups)
			{
				m_byGroup[key] = new List<Sounds>();
			}
			foreach (Sounds value in Enum.GetValues(typeof(Sounds)))
			{
				string text = ((object)value/*cast due to .constrained prefix*/).ToString();
				groups = Groups;
				foreach (string text2 in groups)
				{
					if (text.StartsWith(text2 + "_", StringComparison.Ordinal))
					{
						m_byGroup[text2].Add(value);
						break;
					}
				}
			}
			BuildVFXList();
			Log.LogMessage((object)"Asset Browser 1.0.0 loaded. Keys are rebindable in the config.");
			groups = Groups;
			foreach (string text3 in groups)
			{
				Log.LogMessage((object)("  " + text3 + ": " + m_byGroup[text3].Count + " sounds"));
			}
			Log.LogMessage((object)("  VFX: " + m_vfxList.Count + " prefabs"));
		}

		internal void Update()
		{
			if (m_stopAt > 0f && Time.time >= m_stopAt)
			{
				StopCurrentSound();
			}
			if (m_enabled.Value)
			{
				if (Pressed(m_keyNext))
				{
					Step(1);
				}
				else if (Pressed(m_keyPrev))
				{
					Step(-1);
				}
				else if (Pressed(m_keyJumpForward))
				{
					Step(m_jumpSize.Value);
				}
				else if (Pressed(m_keyJumpBack))
				{
					Step(-m_jumpSize.Value);
				}
				else if (Pressed(m_keyReplay))
				{
					Play();
				}
				else if (Pressed(m_keyNextGroup))
				{
					StepGroup(1);
				}
				else if (Pressed(m_keyPrevGroup))
				{
					StepGroup(-1);
				}
				else if (Pressed(m_keyKeep))
				{
					Keep();
				}
				else if (Pressed(m_keyToggleMode))
				{
					ToggleMode();
				}
				else if (Pressed(m_keyStop))
				{
					StopEverything();
				}
			}
		}

		private static bool Pressed(ConfigEntry<KeyboardShortcut> key)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (key != null)
			{
				KeyboardShortcut value = key.Value;
				return ((KeyboardShortcut)(ref value)).IsDown();
			}
			return false;
		}

		private void Step(int delta)
		{
			if (m_vfxMode)
			{
				if (m_vfxList.Count != 0)
				{
					m_vfxIndex = ((m_vfxIndex + delta) % m_vfxList.Count + m_vfxList.Count) % m_vfxList.Count;
					Play();
				}
				return;
			}
			List<Sounds> current = Current;
			if (current.Count != 0)
			{
				m_soundIndex = ((m_soundIndex + delta) % current.Count + current.Count) % current.Count;
				Play();
			}
		}

		private void StepGroup(int delta)
		{
			if (m_vfxMode)
			{
				Notify("VFX has no groups - Numpad * returns to sounds");
				return;
			}
			m_groupIndex = ((m_groupIndex + delta) % Groups.Length + Groups.Length) % Groups.Length;
			m_soundIndex = 0;
			Notify("== " + Groups[m_groupIndex] + " == " + Current.Count + " sounds");
			Play();
		}

		private unsafe void Play()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			if (m_vfxMode)
			{
				PlayVFX();
				return;
			}
			List<Sounds> current = Current;
			if (current.Count != 0)
			{
				Sounds val = current[m_soundIndex];
				string text = "[" + (m_soundIndex + 1) + "/" + current.Count + "] " + ((object)(*(Sounds*)(&val))/*cast due to .constrained prefix*/).ToString();
				StopCurrentSound();
				Character val2 = LocalPlayer();
				if (Object.op_Implicit((Object)(object)val2) && (Object)(object)Global.AudioManager != (Object)null)
				{
					m_playing = Global.AudioManager.PlaySoundAtPosition(val, ((Component)val2).transform, 0f, 1f, 1f, 1f, 1f);
					m_playingSound = val;
					m_stopAt = Time.time + m_autoStopSeconds.Value;
				}
				Notify(text);
				Log.LogMessage((object)text);
			}
		}

		private void StopCurrentSound()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)m_playing == (Object)null))
			{
				if ((Object)(object)Global.AudioManager != (Object)null)
				{
					Global.AudioManager.StopSound(m_playingSound, m_playing, 0.15f, false);
				}
				m_playing = null;
				m_stopAt = -1f;
			}
		}

		private void Keep()
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (m_vfxMode)
			{
				if (m_vfxList.Count != 0)
				{
					Log.LogMessage((object)("KEEP  <VFXPrefab>" + ((object)m_vfxList[m_vfxIndex]/*cast due to .constrained prefix*/).ToString() + "</VFXPrefab>   (or <StartVFX>" + ((object)m_vfxList[m_vfxIndex]/*cast due to .constrained prefix*/).ToString() + "</StartVFX>)"));
					Notify("kept: " + ((object)m_vfxList[m_vfxIndex]/*cast due to .constrained prefix*/).ToString());
				}
			}
			else
			{
				List<Sounds> current = Current;
				if (current.Count != 0)
				{
					Log.LogMessage((object)("KEEP  <Sounds>" + ((object)current[m_soundIndex]/*cast due to .constrained prefix*/).ToString() + "</Sounds>"));
					Notify("kept: " + ((object)current[m_soundIndex]/*cast due to .constrained prefix*/).ToString());
				}
			}
		}

		private void BuildVFXList()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			foreach (VFXPrefabs value in Enum.GetValues(typeof(VFXPrefabs)))
			{
				if ((int)value != 0)
				{
					m_vfxList.Add(value);
				}
			}
		}

		private void ToggleMode()
		{
			m_vfxMode = !m_vfxMode;
			StopCurrentSound();
			ClearVFX();
			Notify(m_vfxMode ? ("== VFX == " + m_vfxList.Count + " prefabs") : "== SOUND ==");
			Play();
		}

		private void StopEverything()
		{
			StopCurrentSound();
			ClearVFX();
		}

		private void ClearVFX()
		{
			if (Object.op_Implicit((Object)(object)m_vfxInstance))
			{
				VFXSystem component = m_vfxInstance.GetComponent<VFXSystem>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.Stop();
				}
				Object.Destroy((Object)(object)m_vfxInstance);
				m_vfxInstance = null;
			}
		}

		private unsafe void PlayVFX()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if (m_vfxList.Count == 0)
			{
				return;
			}
			ClearVFX();
			VFXPrefabs val = m_vfxList[m_vfxIndex];
			string text = "[" + (m_vfxIndex + 1) + "/" + m_vfxList.Count + "] " + ((object)(*(VFXPrefabs*)(&val))/*cast due to .constrained prefix*/).ToString();
			Character val2 = LocalPlayer();
			GameObject vfxSystem = SL_PlayVFX.GetVfxSystem(val);
			if (Object.op_Implicit((Object)(object)val2) && vfxSystem != null)
			{
				m_vfxInstance = Object.Instantiate<GameObject>(vfxSystem);
				m_vfxInstance.transform.SetParent(((Component)val2).transform);
				UnityEngineExtensions.ResetLocal(m_vfxInstance.transform, true);
				m_vfxInstance.SetActive(true);
				VFXSystem component = m_vfxInstance.GetComponent<VFXSystem>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.Play(val2, (Character)null);
				}
				else
				{
					text += "  (no VFXSystem component)";
				}
			}
			else if (vfxSystem == null)
			{
				text += "  (prefab not found)";
			}
			Notify(text);
			Log.LogMessage((object)text);
		}

		private void Notify(string message)
		{
			Character val = LocalPlayer();
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.CharacterUI))
			{
				val.CharacterUI.ShowInfoNotification(message);
			}
		}

		private static Character LocalPlayer()
		{
			if (!Object.op_Implicit((Object)(object)CharacterManager.Instance))
			{
				return null;
			}
			foreach (Character value in CharacterManager.Instance.Characters.Values)
			{
				if (Object.op_Implicit((Object)(object)value) && value.IsLocalPlayer)
				{
					return value;
				}
			}
			return null;
		}
	}
}