Decompiled source of CompanyMonster AllDialogue v1.0.1

CompanyMonsterAllDialogue.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CompanyMonsterAllDialogue.Patches;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CompanyMonsterAllDialogue")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CompanyMonsterAllDialogue")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("092735f7-8dd4-46a7-965c-7ee230909779")]
[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 CompanyMonsterAllDialogue
{
	[BepInPlugin("Prometheus121.CompanyMonsterAllDialogue", "Company Monster All Dialogue", "1.0.1")]
	public class CompanyMonsterAllDialogue : BaseUnityPlugin
	{
		private const string modGUID = "Prometheus121.CompanyMonsterAllDialogue";

		private const string modName = "Company Monster All Dialogue";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("Prometheus121.CompanyMonsterAllDialogue");

		private static CompanyMonsterAllDialogue instance;

		internal static ManualLogSource mls;

		internal static CompanyMonsterAllDialogueConfig config { get; private set; }

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = new CompanyMonsterAllDialogue();
			}
			mls = Logger.CreateLogSource("Prometheus121.CompanyMonsterAllDialogue");
			mls.LogInfo((object)"Company Monster All Dialogue Initialized");
			config = new CompanyMonsterAllDialogueConfig(((BaseUnityPlugin)this).Config);
			harmony.PatchAll();
		}
	}
}
namespace CompanyMonsterAllDialogue.Patches
{
	[HarmonyPatch(typeof(DepositItemsDesk), "MicrophoneSpeak")]
	internal static class CompanyMonsterAllDialoguePatch
	{
		[HarmonyPrefix]
		private static bool MicrophoneSpeakPatch(DepositItemsDesk __instance)
		{
			Random random = new Random();
			AudioClip val = null;
			if (!CompanyMonsterAllDialogue.config.allDialogue.Value)
			{
				val = ((!(random.NextDouble() > (double)CompanyMonsterAllDialogue.config.rareOdds.Value)) ? __instance.rareMicrophoneAudios[random.Next(0, __instance.rareMicrophoneAudios.Length)] : __instance.microphoneAudios[random.Next(0, __instance.microphoneAudios.Length)]);
			}
			else
			{
				List<AudioClip> list = __instance.microphoneAudios.Concat(__instance.rareMicrophoneAudios).ToList();
				random = new Random();
				int index = random.Next(0, list.Count);
				val = list[index];
			}
			__instance.speakerAudio.PlayOneShot(val, 1f);
			return false;
		}
	}
	internal class CompanyMonsterAllDialogueConfig
	{
		public ConfigEntry<bool> allDialogue;

		public ConfigEntry<float> rareOdds;

		internal CompanyMonsterAllDialogueConfig(ConfigFile cfg)
		{
			cfg.SaveOnConfigSet = false;
			allDialogue = cfg.Bind<bool>("General", "UseAllDialogue", true, "Make all dialogue equally likely. Does not require restart.");
			rareOdds = cfg.Bind<float>("General", "RareOdds", 0.03f, "If UseAllDialogue = false, how frequent should rare dialogue be? Between 0f and 1f as a percentage. Does not require restart.");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
			dictionary.Clear();
		}
	}
}