using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Configuration;
using BepInEx.Logging;
using Dissonance;
using Dissonance.Audio.Playback;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TalkingHeads.Configuration;
using TalkingHeads.Util;
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 = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("TalkingHeads")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Talking Heads mod for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TalkingHeads")]
[assembly: AssemblyTitle("TalkingHeads")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace TalkingHeads
{
[BepInPlugin("TalkingHeads", "TalkingHeads", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private static Plugin _instance;
private readonly Harmony _harmony = new Harmony("TalkingHeads");
private Config _config;
public static ManualLogSource Log => ((BaseUnityPlugin)_instance).Logger;
public static Config Config => _instance._config;
private void Awake()
{
_instance = this;
_config = new Config(((BaseUnityPlugin)this).Config);
_harmony.PatchAll();
Log.LogInfo((object)"Plugin TalkingHeads is loaded!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "TalkingHeads";
public const string PLUGIN_NAME = "TalkingHeads";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace TalkingHeads.VoiceChatPatch
{
public class TalkingPlayer
{
public readonly PlayerControllerB Player;
private readonly VoicePlayerState _voice;
private readonly Transform _targetTransform;
private float _currentScale = 0f;
private TalkingPlayer(PlayerControllerB player, VoicePlayerState voice)
{
Player = player;
_voice = voice;
_targetTransform = Player.lowerSpine.FindComponentInChildren("spine.004");
}
public void UpdateScale(float deltaTime)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
float target = _voice.Amplitude * Plugin.Config.AmplitudeMultiplier;
_currentScale = _currentScale.MoveTowards(target, Plugin.Config.ScaleSpeed * deltaTime);
_targetTransform.localScale = (1f + _currentScale) * Vector3.one;
}
public static TalkingPlayer CreateVoicePlayer(VoicePlayerState state)
{
if (!(state.Playback is VoicePlayback))
{
return null;
}
VoicePlayback playback = default(VoicePlayback);
ref VoicePlayback reference = ref playback;
IVoicePlayback playback2 = state.Playback;
reference = (VoicePlayback)(object)((playback2 is VoicePlayback) ? playback2 : null);
PlayerControllerB val = ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB player) => (Object)(object)player.currentVoiceChatAudioSource == (Object)(object)playback.AudioSource));
return (val == null) ? null : new TalkingPlayer(val, state);
}
}
[HarmonyPatch(typeof(StartOfRound))]
public class VoicePatchPatch
{
private static readonly List<TalkingPlayer> _talkingPlayers = new List<TalkingPlayer>();
private static DissonanceComms _voiceChatModule = null;
[HarmonyPatch("OnEnable")]
[HarmonyPostfix]
private static void OnEnable(ref DissonanceComms ___voiceChatModule)
{
_voiceChatModule = ___voiceChatModule;
_voiceChatModule.OnPlayerStartedSpeaking += OnPlayerStartedSpeaking;
_voiceChatModule.OnPlayerStoppedSpeaking += OnPlayerStoppedSpeaking;
Plugin.Log.LogInfo((object)"StartOfRound patch subscribed to voiceChatModule events");
}
[HarmonyPatch("OnDisable")]
[HarmonyPostfix]
private static void OnDisable()
{
_voiceChatModule.OnPlayerStartedSpeaking -= OnPlayerStartedSpeaking;
_voiceChatModule.OnPlayerStoppedSpeaking -= OnPlayerStoppedSpeaking;
_voiceChatModule = null;
_talkingPlayers.Clear();
}
private static void OnPlayerStartedSpeaking(VoicePlayerState state)
{
TalkingPlayer talkingPlayer = TalkingPlayer.CreateVoicePlayer(state);
if (talkingPlayer != null)
{
_talkingPlayers.Add(talkingPlayer);
}
}
private static void OnPlayerStoppedSpeaking(VoicePlayerState state)
{
TalkingPlayer player = TalkingPlayer.CreateVoicePlayer(state);
if (player != null)
{
_talkingPlayers.RemoveAll((TalkingPlayer p) => (Object)(object)p.Player == (Object)(object)player.Player);
}
}
[HarmonyPatch("LateUpdate")]
[HarmonyPostfix]
private static void LateUpdate()
{
List<int> list = new List<int>();
foreach (var (talkingPlayer, item) in _talkingPlayers.Select((TalkingPlayer el, int i) => (el, i)))
{
try
{
talkingPlayer.UpdateScale(Time.deltaTime);
}
catch
{
list.Add(item);
}
}
list.ForEach(_talkingPlayers.RemoveAt);
}
}
}
namespace TalkingHeads.Util
{
public static class UtilExtensions
{
public static float MoveTowards(this float source, float target, float delta)
{
if (target > source)
{
return Mathf.Min(target, source + delta);
}
if (target < source)
{
return Mathf.Max(target, source - delta);
}
return source;
}
public static Transform FindComponentInChildren(this Transform transform, string name)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
foreach (Transform item in transform)
{
Transform val = item;
if (((Object)val).name == name)
{
return val;
}
Transform val2 = val.FindComponentInChildren(name);
if (val2 != null)
{
return val2;
}
}
return null;
}
}
}
namespace TalkingHeads.Configuration
{
public class Config
{
private readonly ConfigEntry<float> _scaleSpeed;
private readonly ConfigEntry<float> _amplitudeMultiplier;
public float ScaleSpeed => _scaleSpeed.Value;
public float AmplitudeMultiplier => _amplitudeMultiplier.Value;
public Config(ConfigFile cfg)
{
_scaleSpeed = cfg.Bind<float>("General", "ScaleSpeed", 20f, "Scale change rate");
_amplitudeMultiplier = cfg.Bind<float>("General", "AmplitudeMultiplier", 4f, "Voice amplitude to scale multiplier");
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}