using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TurnAudioPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TurnAudioPlugin")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("TurnAudioPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("2.0.0.0")]
namespace LordAshes;
[BepInPlugin("org.lordashes.plugins.turnaudio", "Turn Audio Plug-In", "2.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class TurnAudioPlugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <PlayAudio>d__10 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public object[] inputs;
public TurnAudioPlugin <>4__this;
private UnityWebRequest <www>5__1;
private GameObject <speaker>5__2;
private AudioSource <player>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <PlayAudio>d__10(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<www>5__1 = null;
<speaker>5__2 = null;
<player>5__3 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Invalid comparison between Unknown and I4
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Expected O, but got Unknown
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
LoggingPlugin.LogInfo("Playing " + (string)inputs[0]);
<www>5__1 = UnityWebRequestMultimedia.GetAudioClip((string)inputs[0], (AudioType)0);
<>1__state = -3;
<>2__current = <www>5__1.SendWebRequest();
<>1__state = 1;
return true;
case 1:
<>1__state = -3;
if ((int)<www>5__1.result == 2)
{
LoggingPlugin.LogWarning("Audio Plugin: Failure To Load " + (string)inputs[0] + "...");
Debug.Log((object)<www>5__1.error);
}
else
{
<speaker>5__2 = GameObject.Find("InitiativeSpeaker");
if ((Object)(object)<speaker>5__2 == (Object)null)
{
<speaker>5__2 = new GameObject();
((Object)<speaker>5__2).name = "InitiativeSpeaker";
<speaker>5__2.AddComponent<AudioSource>();
}
<player>5__3 = <speaker>5__2.GetComponent<AudioSource>();
<player>5__3.clip = DownloadHandlerAudioClip.GetContent(<www>5__1);
<player>5__3.Play();
<speaker>5__2 = null;
<player>5__3 = null;
}
<>m__Finally1();
<www>5__1 = null;
return false;
}
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<www>5__1 != null)
{
((IDisposable)<www>5__1).Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <Startup>d__8 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public TurnAudioPlugin <>4__this;
private bool <success>5__1;
private Exception <ex>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Startup>d__8(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<ex>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
LoggingPlugin.LogInfo("Adding Turn Event Handler");
<success>5__1 = false;
break;
case 1:
<>1__state = -1;
break;
}
while (!<success>5__1)
{
try
{
LoggingPlugin.LogDebug("Trying To Add Event Handler");
<>4__this._InitiativeManager.AddEvent("OnTurnSwitch", (Delegate)new Action<object>(<>4__this.TurnHandler));
LoggingPlugin.LogTrace("Adding Event Handler: Success");
<success>5__1 = true;
}
catch (Exception ex)
{
<ex>5__2 = ex;
LoggingPlugin.LogDebug("Adding Event Handler: Failure");
LoggingPlugin.LogTrace(<ex>5__2.Message);
}
if (!<success>5__1)
{
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
}
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public const string Name = "Turn Audio Plug-In";
public const string Guid = "org.lordashes.plugins.turnaudio";
public const string Version = "2.0.0.0";
private bool globalDistribution = false;
private Generic _InitiativeManager = new Generic("InitiativeManager", (object)null);
private Generic _CreaturePresenter = new Generic("CreaturePresenter", (object)null);
private Generic _LocalClient = new Generic("LocalClient", (object)null);
private void Awake()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
string? assemblyQualifiedName = ((object)this).GetType().AssemblyQualifiedName;
DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
LoggingPlugin.LogInfo(assemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + ")");
globalDistribution = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Global Distribution", false, (ConfigDescription)null).Value;
((MonoBehaviour)this).StartCoroutine(Startup());
}
[IteratorStateMachine(typeof(<Startup>d__8))]
private IEnumerator Startup()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <Startup>d__8(0)
{
<>4__this = this
};
}
private void TurnHandler(object genericElement)
{
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Expected O, but got Unknown
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Expected O, but got Unknown
Generic.Info(genericElement);
if (genericElement.GetType().GetRuntimeField("CreatureGuid") != null)
{
if (genericElement.GetType().GetRuntimeField("CreatureGuid").GetValue(genericElement)
.ToString() != "00000000-0000-0000-0000-000000000000")
{
LoggingPlugin.LogTrace("Creature Type Element");
Generic val = new Generic("CreatureGuid", genericElement.GetType().GetRuntimeField("CreatureGuid").GetValue(genericElement));
LoggingPlugin.LogTrace("Obtained CreatureGuid");
Generic val2 = new Generic("CreatureBoardAsset", _CreaturePresenter.Invoke("TryGetAsset", new object[2]
{
val.Instance(),
null
})[1]);
LoggingPlugin.LogTrace("Obtained Asset");
if (val2.Instance() == null)
{
return;
}
LoggingPlugin.LogDebug("Turn Audio Plugin: It is now " + val2.Get<string>("Name") + "'s Turn");
try
{
if (globalDistribution || (bool)_LocalClient.Invoke("CanControlCreature", new object[1] { val.Instance() })[0])
{
string text = null;
if (File.Exists("Audio/" + GetCreatureName(val2.Get<string>("Name"))))
{
text = File.Find("Audio/" + GetCreatureName(val2.Get<string>("Name")), (CacheType)999)[0];
}
else if (File.Exists("Audio/Default"))
{
text = File.Find("Audio/Default", (CacheType)999)[0];
}
if (text != null)
{
((MonoBehaviour)this).StartCoroutine("PlayAudio", (object)new object[1] { text });
}
}
return;
}
catch (Exception ex)
{
LoggingPlugin.LogWarning("Exception Starting Audio. " + ex.Message);
return;
}
}
LoggingPlugin.LogTrace("Empty Creature Guid");
}
else
{
LoggingPlugin.LogTrace("Non-Creature Type Element");
}
}
[IteratorStateMachine(typeof(<PlayAudio>d__10))]
private IEnumerator PlayAudio(object[] inputs)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <PlayAudio>d__10(0)
{
<>4__this = this,
inputs = inputs
};
}
private static string GetCreatureName(string statBlock)
{
if (statBlock.Contains("<"))
{
statBlock = statBlock.Substring(0, statBlock.IndexOf("<"));
}
return statBlock;
}
}