Decompiled source of LootbugDerelye v1.0.0

LootbugDerelye.dll

Decompiled 9 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LootbugDerelye.Patches;
using LootbugDerelye.Utilities;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LootbugDerelye")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LootbugDerelye")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0ce76791-3774-45bb-9000-f90840faa56f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LootbugDerelye
{
	[BepInPlugin("SZAKI.LootbugDerelye", "Lootbug Derelye", "1.0.0.0")]
	[BepInProcess("Lethal Company.exe")]
	public class Base : BaseUnityPlugin
	{
		private static Base _instance;

		private static Harmony _harmony;

		public static Base Instance
		{
			get
			{
				return _instance;
			}
			private set
			{
				_instance = value;
			}
		}

		public string PluginPath { get; private set; }

		public string ClipsPath { get; private set; }

		public static List<AudioClip> Clips { get; private set; }

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (_harmony == null)
			{
				_harmony = new Harmony("SZAKI.LootbugDerelye");
			}
			if (string.IsNullOrEmpty(PluginPath))
			{
				PluginPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			}
			if (string.IsNullOrEmpty(ClipsPath))
			{
				ClipsPath = $"{PluginPath}{Path.DirectorySeparatorChar}DerelyeSounds";
			}
			if (!Directory.Exists(ClipsPath))
			{
				Directory.CreateDirectory(ClipsPath);
				WriteResourceToFile("derelye_2.wav", $"{ClipsPath}{Path.DirectorySeparatorChar}derelye_2.wav");
				WriteResourceToFile("derelye_3.wav", $"{ClipsPath}{Path.DirectorySeparatorChar}derelye_3.wav");
				WriteResourceToFile("Untitled.wav", $"{ClipsPath}{Path.DirectorySeparatorChar}Untitled.wav");
			}
			Clips = LoadAudios(ClipsPath);
			_harmony.PatchAll(typeof(Base));
			_harmony.PatchAll(typeof(ReplaceLootbugSounds));
			Logger.LogInfo("Successfully awakened!");
		}

		private void WriteResourceToFile(string resourceName, string fileName)
		{
			try
			{
				string text = Assembly.GetExecutingAssembly().GetManifestResourceNames().FirstOrDefault((string x) => x.Contains(resourceName));
				if (string.IsNullOrEmpty(text))
				{
					throw new FileNotFoundException(resourceName + " is not found in the embedded resources!");
				}
				Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text);
				using (FileStream destination = new FileStream(fileName ?? "", FileMode.Create, FileAccess.Write))
				{
					manifestResourceStream.CopyTo(destination);
				}
				manifestResourceStream.Close();
			}
			catch (Exception ex)
			{
				Logger.LogWarning("Failed to copy the '" + resourceName + "' file to here '" + fileName + "'");
				Logger.LogError(ex.Message);
			}
		}

		private List<AudioClip> LoadAudios(string path)
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Invalid comparison between Unknown and I4
			DirectoryInfo directoryInfo = new DirectoryInfo(path);
			Logger.LogInfo(" Start loading audios from: " + path);
			FileInfo[] files = directoryInfo.GetFiles("*.wav");
			if (files.Length == 0)
			{
				Logger.LogInfo("No audio file found!");
				return null;
			}
			Logger.LogInfo(files.Length + " audio file found!");
			List<AudioClip> list = new List<AudioClip>();
			FileInfo[] array = files;
			FileInfo[] array2 = array;
			foreach (FileInfo fileInfo in array2)
			{
				char directorySeparatorChar = Path.DirectorySeparatorChar;
				UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path + directorySeparatorChar + fileInfo.Name, (AudioType)20);
				audioClip.SendWebRequest();
				while (!audioClip.isDone)
				{
					Thread.Sleep(100);
				}
				if ((int)audioClip.result != 2)
				{
					AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
					((Object)content).name = fileInfo.Name;
					list.Add(content);
				}
			}
			Logger.LogInfo(list.Count + " audio file loaded!");
			return list;
		}
	}
}
namespace LootbugDerelye.Utilities
{
	public static class Logger
	{
		private static ManualLogSource _mls;

		private static void Log(LogLevel level, object msg)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrEmpty(msg.ToString()))
			{
				if (_mls == null)
				{
					_mls = Logger.CreateLogSource("Lootbug Derelye");
				}
				_mls.Log(level, (object)(" " + msg.ToString()));
			}
		}

		public static void LogInfo(object msg)
		{
			Log((LogLevel)16, msg);
		}

		public static void LogWarning(object msg)
		{
			Log((LogLevel)4, msg);
		}

		public static void LogError(object msg)
		{
			Log((LogLevel)2, msg);
		}

		public static void LogDebug(object msg)
		{
			Log((LogLevel)32, msg);
		}
	}
	public static class PluginInfos
	{
		public const string GUID = "SZAKI.LootbugDerelye";

		public const string NAME = "Lootbug Derelye";

		public const string VERSION = "1.0.0.0";
	}
}
namespace LootbugDerelye.Patches
{
	[HarmonyPatch(typeof(HoarderBugAI), "Start")]
	public class ReplaceLootbugSounds
	{
		[HarmonyPrefix]
		public static void Prefix(HoarderBugAI __instance)
		{
			if (Base.Clips.Count > 0)
			{
				__instance.chitterSFX = Base.Clips.ToArray();
			}
		}
	}
}