using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ThemeReplacer.Patches;
using UnityEngine;
using UnityEngine.Networking;
[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("ThemeReplacer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Theme Replacer")]
[assembly: AssemblyTitle("ThemeReplacer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 ThemeReplacer
{
[BepInPlugin("ro.wolftech.dogle.themereplacer", "Theme Replacer", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ConfigEntry<bool> configEnable;
internal static ConfigEntry<KeyCode> configFolderShortcutKey;
internal static ManualLogSource Logger;
private void Awake()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
configEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Whether or not the mod is enabled");
configFolderShortcutKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Keybinds", "ShortcutKey", (KeyCode)289, "The key to press in the menu to quickly open the mod's folder");
if (configEnable.Value)
{
new Harmony("ro.wolftech.dogle.themereplacer").PatchAll(typeof(MenuPatch));
}
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin Theme Replacer is loaded!");
}
}
public static class PluginInformation
{
public const string GUID = "ro.wolftech.dogle.themereplacer";
public const string Name = "Theme Replacer";
public const string Version = "1.0.0";
}
}
namespace ThemeReplacer.Patches
{
public static class MenuPatch
{
private static readonly HashSet<string> Exclusions = new HashSet<string> { "icon.png", "README.md", "CHANGELOG.md", "manifest.json", "ThemeReplacer.dll" };
private static readonly List<AudioClip> clips = new List<AudioClip>();
private static bool initialized = false;
private static AudioClip LoadClip(string path)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Invalid comparison between Unknown and I4
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
path = "file://" + path;
}
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)0);
try
{
audioClip.SendWebRequest();
while (!audioClip.isDone)
{
}
if ((int)audioClip.result != 1)
{
Debug.LogError((object)("Error loading " + path + " (" + audioClip.error + ")"));
return null;
}
return DownloadHandlerAudioClip.GetContent(audioClip);
}
finally
{
((IDisposable)audioClip)?.Dispose();
}
}
private static void EnsureInitialized()
{
if (initialized)
{
return;
}
initialized = true;
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Plugin.Logger.LogInfo((object)("Checking " + directoryName + "..."));
foreach (string item in Directory.EnumerateFiles(directoryName))
{
if (!Exclusions.Contains(Path.GetFileName(item)))
{
AudioClip val = LoadClip(item);
if (Object.op_Implicit((Object)(object)val))
{
clips.Add(val);
}
}
}
}
[HarmonyPatch(typeof(MenuManager), "Start")]
[HarmonyPrefix]
public static void ReplaceTheme()
{
EnsureInitialized();
if (clips.Count == 0)
{
Plugin.Logger.LogInfo((object)"No replacement tracks found!");
return;
}
GameObject val = GameObject.Find("WKTheme");
if (!Object.op_Implicit((Object)(object)val))
{
Plugin.Logger.LogInfo((object)"WKTheme not found (????)");
return;
}
AudioSource component = val.GetComponent<AudioSource>();
if (!Object.op_Implicit((Object)(object)component))
{
Plugin.Logger.LogInfo((object)"WKTheme audio source not found (??????????????)");
return;
}
AudioClip clip = clips[Random.RandomRangeInt(0, clips.Count)];
component.Stop();
component.clip = clip;
component.Play();
Plugin.Logger.LogInfo((object)"done! YAY!");
}
[HarmonyPatch(typeof(MenuManager), "Update")]
[HarmonyPrefix]
public static void UpdateCheck()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(Plugin.configFolderShortcutKey.Value))
{
Application.OpenURL("file://" + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
}
}
}
}