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.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
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("LC.Grub4K.YippeeReloaded")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2024 Simon Sawicki")]
[assembly: AssemblyDescription("A plugin for \"Lethal Company\" changing the Hoarder bug sound.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("YippeeReloaded")]
[assembly: AssemblyTitle("LC.Grub4K.YippeeReloaded")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 LC.Grub4K.YippeeReloaded
{
internal record struct HoarderBugInstance(HoarderBugAI AI, AudioClip[] OriginalSFX);
public static class AudioReplacer
{
private static AudioClip[] CustomSFX = Array.Empty<AudioClip>();
private static List<HoarderBugInstance> BugInstances = new List<HoarderBugInstance>();
private static bool _enabled = false;
public static bool IsEnabled
{
get
{
return _enabled;
}
set
{
if (value == _enabled)
{
return;
}
foreach (HoarderBugInstance bugInstance in BugInstances)
{
bugInstance.AI.chitterSFX = (value ? CustomSFX : bugInstance.OriginalSFX);
}
_enabled = value;
if (!value)
{
CustomSFX = Array.Empty<AudioClip>();
}
Plugin.Log.LogDebug((object)$"bugs={BugInstances.Count}, sfxs={CustomSFX.Length}, enabled={_enabled}");
}
}
public static void AddBug(HoarderBugAI bug)
{
BugInstances.Add(new HoarderBugInstance(bug, bug.chitterSFX));
if (IsEnabled)
{
bug.chitterSFX = CustomSFX;
Plugin.Log.LogDebug((object)$"bugs={BugInstances.Count}, sfxs={CustomSFX.Length}, enabled={IsEnabled}");
}
}
public static void RemoveBug(HoarderBugAI bug)
{
HoarderBugAI bug2 = bug;
HoarderBugInstance item = BugInstances.SingleOrDefault((HoarderBugInstance instance) => instance.AI == bug2);
BugInstances.Remove(item);
Plugin.Log.LogDebug((object)$"bugs={BugInstances.Count}, sfxs={CustomSFX.Length}, enabled={IsEnabled}");
}
public static void RemoveAllBugs()
{
BugInstances.Clear();
Plugin.Log.LogDebug((object)$"bugs={BugInstances.Count}, sfxs={CustomSFX.Length}, enabled={IsEnabled}");
}
public static void Load(string path)
{
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrEmpty(path))
{
Plugin.Log.LogInfo((object)"Using original sfx");
IsEnabled = false;
return;
}
if (!Directory.Exists(path))
{
Plugin.Log.LogError((object)("Path does not exist: " + path));
IsEnabled = false;
return;
}
Plugin.Log.LogDebug((object)("Loading sfx from " + path));
List<AudioClip> customSFX = new List<AudioClip>();
string[] files = Directory.GetFiles(path);
int remaining = files.Length;
string[] array = files;
foreach (string filePath in array)
{
AudioType val;
switch (Path.GetExtension(filePath))
{
case ".mp3":
case ".mp2":
val = (AudioType)13;
break;
case ".ogg":
val = (AudioType)14;
break;
case ".wav":
val = (AudioType)20;
break;
case ".it":
val = (AudioType)10;
break;
case ".s3m":
val = (AudioType)17;
break;
case ".aif":
case ".aiff":
val = (AudioType)2;
break;
case ".mod":
val = (AudioType)12;
break;
case ".xm":
val = (AudioType)21;
break;
default:
val = (AudioType)0;
break;
}
AudioType val2 = val;
if ((int)val2 == 0)
{
remaining--;
continue;
}
string text = "file:///" + filePath.Replace('\\', '/');
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(text, val2);
((AsyncOperation)www.SendWebRequest()).completed += delegate
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Invalid comparison between Unknown and I4
if ((int)www.result == 2)
{
Plugin.Log.LogError((object)("Error loading file: " + www.error));
}
else
{
try
{
customSFX.Add(DownloadHandlerAudioClip.GetContent(www));
Plugin.Log.LogDebug((object)("Loaded sfx from file: " + filePath));
}
catch (Exception arg)
{
Plugin.Log.LogError((object)$"Error loading file: {arg}");
}
}
www.Dispose();
remaining--;
if (remaining == 0)
{
CustomSFX = customSFX.ToArray();
Plugin.Log.LogInfo((object)$"Loaded {CustomSFX.Length} custom sound(s)");
IsEnabled = true;
}
};
}
}
}
internal static class BugHandlerPatches
{
[HarmonyPatch(typeof(HoarderBugAI), "Start")]
[HarmonyPostfix]
public static void HoarderBugAI_Start_Post(HoarderBugAI __instance)
{
AudioReplacer.AddBug(__instance);
}
[HarmonyPatch(typeof(StartOfRound), "unloadSceneForAllPlayers")]
[HarmonyPostfix]
public static void StartOfRound_unloadSceneForAllPlayers()
{
AudioReplacer.RemoveAllBugs();
}
}
[BepInPlugin("LC.Grub4K.YippeeReloaded", "YippeeReloaded", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource Log;
private ConfigEntry<EnabledState> EnabledConfig;
private ConfigEntry<string> PathConfig;
public void Awake()
{
//IL_0096: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
//IL_00b9: Expected O, but got Unknown
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Expected O, but got Unknown
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Expected O, but got Unknown
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Expected O, but got Unknown
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
PathConfig = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Path", "", "The path to the directory containing sfx files to use");
PathConfig.SettingChanged += delegate
{
UpdateState();
};
EnabledConfig = ((BaseUnityPlugin)this).Config.Bind<EnabledState>("General", "Mode", EnabledState.Default, "Enable or disable hoarder bug sfx replacement");
EnabledConfig.SettingChanged += delegate
{
UpdateState();
};
LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<EnabledState>(EnabledConfig, false));
LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(PathConfig, new TextInputFieldOptions
{
RequiresRestart = false,
CanModifyCallback = (CanModifyDelegate)(() => (EnabledConfig.Value == EnabledState.Custom) ? CanModifyResult.True() : CanModifyResult.False("\"Mode\" must be set to \"Custom\""))
}));
LethalConfigManager.AddConfigItem((BaseConfigItem)new GenericButtonConfigItem("General", "Reload custom sfx", "Reload custom audio files.\n\nThis button only works if \"Mode\" is set to \"Custom\"", "Reload...", (GenericButtonHandler)delegate
{
if (EnabledConfig.Value == EnabledState.Custom)
{
AudioReplacer.Load(PathConfig.Value);
}
}));
LethalConfigManager.SetModDescription("Change the Hoarder Bug sfx to custom sounds inside a folder");
new Harmony("LC.Grub4K.YippeeReloaded").PatchAll(typeof(BugHandlerPatches));
UpdateState();
}
private void UpdateState()
{
AudioReplacer.Load(EnabledConfig.Value switch
{
EnabledState.Default => Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location),
EnabledState.Custom => PathConfig.Value,
_ => "",
});
}
}
public enum EnabledState
{
Disabled,
Default,
Custom
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "LC.Grub4K.YippeeReloaded";
public const string PLUGIN_NAME = "YippeeReloaded";
public const string PLUGIN_VERSION = "1.0.0";
}
}