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.Logging;
using Dissonance;
using Microsoft.CodeAnalysis;
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("Gnomegaphone")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Gnomegaphone")]
[assembly: AssemblyTitle("Gnomegaphone")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 Gnomegaphone
{
[BepInPlugin("gnomerul.Gnomegaphone", "Gnomegaphone", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "gnomerul.Gnomegaphone";
public const string PluginName = "Gnomegaphone";
public const string PluginVersion = "1.0.0";
private const float Size = 112f;
private const float Margin = 28f;
internal static ManualLogSource Log;
private Texture2D _face;
private DissonanceComms _comms;
private VoicePlayerState _local;
private bool _speaking;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
_face = LoadEmbeddedTexture("gnome_face.png");
if ((Object)(object)_face == (Object)null)
{
Log.LogError((object)"Could not load gnome_face.png!!!");
}
Log.LogInfo((object)"Gnomegaphone v1.0.0 loaded.");
}
private void Update()
{
if ((Object)(object)_comms == (Object)null)
{
_comms = Object.FindAnyObjectByType<DissonanceComms>();
_local = null;
}
if ((Object)(object)_comms == (Object)null)
{
_speaking = false;
return;
}
if (_local == null || !_local.IsConnected)
{
_local = ((IEnumerable<VoicePlayerState>)_comms.Players).FirstOrDefault((Func<VoicePlayerState, bool>)((VoicePlayerState p) => p.IsLocalPlayer));
}
_speaking = _local != null && _local.IsSpeaking && !_comms.IsMuted;
}
private void OnGUI()
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
if (_speaking && !((Object)(object)_face == (Object)null))
{
float num = (float)Screen.width - 112f - 28f;
float num2 = (float)Screen.height - 112f - 28f;
GUI.DrawTexture(new Rect(num, num2, 112f, 112f), (Texture)(object)_face, (ScaleMode)2);
}
}
private static Texture2D LoadEmbeddedTexture(string fileName)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
//IL_0060: Expected O, but got Unknown
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string n) => n.EndsWith(fileName));
if (text == null)
{
return null;
}
using Stream stream = executingAssembly.GetManifestResourceStream(text);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
ImageConversion.LoadImage(val, memoryStream.ToArray());
return val;
}
}
}