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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LCSoundTool;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("CustomSoundImplementation")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod which allows the custom Implementation for sound effects for various objects")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomSoundImplementation")]
[assembly: AssemblyTitle("CustomSoundImplementation")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CustomSoundImplementation;
[BepInPlugin("CustomSoundImplementation", "Custom Sound Implementation", "0.1")]
public class Plugin : BaseUnityPlugin
{
private const string PLUGIN_GUID = "CustomSoundImplementation";
private const string PLUGIN_NAME = "Custom Sound Implementation";
private const string PLUGIN_VERSION = "0.1";
public static Plugin instance;
private bool initialized = false;
private Harmony harmony;
internal ManualLogSource logger;
private Dictionary<string, List<string>> monsterAudioNames;
private void Awake()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
logger = Logger.CreateLogSource("CustomSoundImplementation");
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CustomSoundImplementation is loaded!");
instance = this;
logger.LogInfo((object)"Plugin CustomSoundImplementation is loaded! FUCK YEAH");
harmony = new Harmony("CustomSoundImplementation");
monsterAudioNames = getSoundNames(readTextFile(Path.Combine(getCustomSoundsPath(), "monsterAudio.txt")));
}
internal void Start()
{
Initialize();
}
internal void Initialize()
{
if (!initialized)
{
initialized = true;
initializeFolders();
loadNewSounds();
}
}
internal void initializeFolders()
{
string customSoundsPath = getCustomSoundsPath();
if (!Directory.Exists(customSoundsPath))
{
logger.LogInfo((object)"CustomSoundImplementation folder does not exist. Creating now.");
Directory.CreateDirectory(customSoundsPath);
}
foreach (KeyValuePair<string, List<string>> monsterAudioName in monsterAudioNames)
{
string text = Path.Combine(customSoundsPath, monsterAudioName.Key);
if (!Directory.Exists(text))
{
logger.LogInfo((object)(monsterAudioName.Key + " folder does not exist. Creating now."));
Directory.CreateDirectory(text);
}
foreach (string item in monsterAudioName.Value)
{
if (!Directory.Exists(Path.Combine(text, item)))
{
logger.LogInfo((object)(item + " folder does not exist. Creating now."));
Directory.CreateDirectory(Path.Combine(text, item));
}
}
}
}
public string getCustomSoundsPath()
{
return Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)instance).Info.Location), "CustomSoundImplementation");
}
private List<string> readTextFile(string filePath)
{
List<string> list = new List<string>();
try
{
using StreamReader streamReader = new StreamReader(filePath);
while (!streamReader.EndOfStream)
{
string text = streamReader.ReadLine();
if (!string.IsNullOrWhiteSpace(text))
{
list.Add(text);
}
}
}
catch (Exception ex)
{
logger.LogInfo((object)("An error occurred: " + ex.Message + " please ensure you have CustomSoundImplementation in the plugins folder with MonsterAudio.txt"));
Console.WriteLine("An error occurred: " + ex.Message);
}
return list;
}
private Dictionary<string, List<string>> getSoundNames(List<string> lines)
{
Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
foreach (string line in lines)
{
string[] array = line.Split(':');
string key = array[0].Trim();
string[] collection = (from s in array[1].Split(',')
select s.Trim()).ToArray();
dictionary.Add(key, new List<string>(collection));
}
return dictionary;
}
private void loadNewSounds()
{
string customSoundsPath = getCustomSoundsPath();
foreach (KeyValuePair<string, List<string>> monsterAudioName in monsterAudioNames)
{
string text = Path.Combine(customSoundsPath, monsterAudioName.Key);
foreach (string item in monsterAudioName.Value)
{
DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(text, item));
FileInfo[] files = directoryInfo.GetFiles("*.wav");
int num = 0;
FileInfo[] array = files;
foreach (FileInfo fileInfo in array)
{
AudioClip audioClip = SoundTool.GetAudioClip(text, item, fileInfo.Name);
string text3 = (((Object)audioClip).name = fileInfo.Name.Replace(".wav", "-" + findPercentage(files.Length, num)));
logger.LogInfo((object)("Replacing sound for " + monsterAudioName.Key + " called " + item + " wiith " + text3 + " "));
SoundTool.ReplaceAudioClip(item, audioClip);
num++;
}
}
}
}
private int findPercentage(int len, int index)
{
int num = 100;
if (len > 1)
{
num = 100 / len;
}
if (len - 1 == index)
{
num = 100 - num * (len - 1);
}
return num;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "CustomSoundImplementation";
public const string PLUGIN_NAME = "CustomSoundImplementation";
public const string PLUGIN_VERSION = "1.0.0";
}