Decompiled source of HaldorVoice v1.0.0

HaldorVoice_v1.0.0.dll

Decompiled 2 weeks ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[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("HaldorVoice")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HaldorVoice")]
[assembly: AssemblyTitle("HaldorVoice")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HaldorVoice;

[BepInPlugin("DEEP_FROST.HaldorVoice", "HaldorVoice", "1.0.0")]
public class HaldorVoicePlugin : BaseUnityPlugin
{
	public const string PluginGuid = "DEEP_FROST.HaldorVoice";

	public const string PluginName = "HaldorVoice";

	public const string PluginVersion = "1.0.0";

	internal static ConfigEntry<float> HearDistance;

	private void Awake()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		HearDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "HearDistance", 100f, "С какого расстояния слышно гудение торговца, м / Distance the trader's humming is audible from, meters");
		new Harmony("DEEP_FROST.HaldorVoice").PatchAll(typeof(HaldorVoicePlugin).Assembly);
		((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("[HaldorVoice] {0} загружен: дальность звука торговца {1} м", "1.0.0", HearDistance.Value));
	}
}
[HarmonyPatch(typeof(Trader), "Start")]
internal static class Trader_Start_Patch
{
	private static void Postfix(Trader __instance)
	{
		float value = HaldorVoicePlugin.HearDistance.Value;
		if (!(value <= 0f))
		{
			int sources = 0;
			AudioSource[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<AudioSource>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Boost(componentsInChildren[i], value);
				sources++;
			}
			BoostFx(__instance.m_randomTalkFX, value, ref sources);
			BoostFx(__instance.m_randomGreetFX, value, ref sources);
			BoostFx(__instance.m_randomGoodbyeFX, value, ref sources);
			BoostFx(__instance.m_randomStartTradeFX, value, ref sources);
			BoostFx(__instance.m_randomBuyFX, value, ref sources);
			BoostFx(__instance.m_randomSellFX, value, ref sources);
			Debug.Log((object)$"[HaldorVoice] {__instance.m_name}: дальность звука расширена до {value} м (источников: {sources})");
		}
	}

	private static void BoostFx(EffectList list, float range, ref int sources)
	{
		if (list == null || list.m_effectPrefabs == null)
		{
			return;
		}
		EffectData[] effectPrefabs = list.m_effectPrefabs;
		foreach (EffectData val in effectPrefabs)
		{
			if (val != null && !((Object)(object)val.m_prefab == (Object)null))
			{
				AudioSource[] componentsInChildren = val.m_prefab.GetComponentsInChildren<AudioSource>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					Boost(componentsInChildren[j], range);
					sources++;
				}
			}
		}
	}

	private static void Boost(AudioSource source, float range)
	{
		if (source.maxDistance < range)
		{
			source.maxDistance = range;
		}
	}
}