using System;
using System.Collections;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CustomNameSpells.Config;
using Dissonance;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Recognissimo;
using Recognissimo.Components;
using UnityEngine;
using UnityEngine.Events;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("CustomNameSpells")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+0e22ce82d70e735a36d67dd6aa48b6bb66ee7ef7")]
[assembly: AssemblyProduct("CustomNameSpells")]
[assembly: AssemblyTitle("CustomNameSpells")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.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 CustomNameSpells
{
[BepInPlugin("com.infernumvii.customnamespells", "CustomNameSpells", "1.0.4")]
[BepInProcess("MageArena.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class CustomNameSpells : BaseUnityPlugin
{
public static string modsync = "all";
private readonly Harmony harmony = new Harmony("com.infernumvii.customnamespells");
internal static ManualLogSource Logger;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
VoiceCommandConfig.Init(((BaseUnityPlugin)this).Config);
harmony.PatchAll();
Logger.LogInfo((object)"CustomNameSpells loaded!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "CustomNameSpells";
public const string PLUGIN_NAME = "CustomNameSpells";
public const string PLUGIN_VERSION = "1.0.4";
}
}
namespace CustomNameSpells.Patches
{
[HarmonyPatch(typeof(VoiceControlListener))]
public static class VoiceControlListenerPatch
{
[CompilerGenerated]
private sealed class <>c__DisplayClass11_0
{
public VoiceControlListener instance;
internal void <ModifiedResetMicLong>b__0(Result res)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
instance.tryresult(res.text);
}
}
[CompilerGenerated]
private sealed class <>c__DisplayClass7_0
{
public VoiceControlListener instance;
internal void <ModifiedWaitGetPlayer>b__0(Result res)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
instance.tryresult(res.text);
}
}
[CompilerGenerated]
private sealed class <ModifiedResetMicLong>d__11 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public VoiceControlListener instance;
private <>c__DisplayClass11_0 <>8__1;
private SpeechRecognizer <recognizer>5__2;
private SpeechRecognizer <recognizerNew>5__3;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ModifiedResetMicLong>d__11(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>8__1 = null;
<recognizer>5__2 = null;
<recognizerNew>5__3 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Expected O, but got Unknown
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>8__1 = new <>c__DisplayClass11_0();
<>8__1.instance = instance;
<recognizer>5__2 = srRef.Invoke(<>8__1.instance);
((SpeechProcessor)<recognizer>5__2).StopProcessing();
<>2__current = (object)new WaitForSeconds(0.5f);
<>1__state = 1;
return true;
case 1:
{
<>1__state = -1;
Object.Destroy((Object)(object)<recognizer>5__2);
srRef.Invoke(<>8__1.instance) = ((Component)<>8__1.instance).gameObject.AddComponent<SpeechRecognizer>();
<recognizerNew>5__3 = srRef.Invoke(<>8__1.instance);
((SpeechProcessor)<recognizerNew>5__3).LanguageModelProvider = (LanguageModelProvider)(object)((Component)<>8__1.instance).GetComponent<StreamingAssetsLanguageModelProvider>();
((SpeechProcessor)<recognizerNew>5__3).SpeechSource = (SpeechSource)(object)((Component)<>8__1.instance).GetComponent<DissonanceSpeechSource>();
<recognizerNew>5__3.Vocabulary = new List<string>();
<>8__1.instance.SpellPages = new List<ISpellCommand>();
MonoBehaviour[] components = ((Component)<>8__1.instance).gameObject.GetComponents<MonoBehaviour>();
foreach (MonoBehaviour obj in components)
{
ISpellCommand val = (ISpellCommand)(object)((obj is ISpellCommand) ? obj : null);
if (val != null)
{
<>8__1.instance.SpellPages.Add(val);
}
}
addSpellsToVocabulary(<recognizerNew>5__3);
((UnityEvent<Result>)(object)<recognizerNew>5__3.ResultReady).AddListener((UnityAction<Result>)delegate(Result res)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
<>8__1.instance.tryresult(res.text);
});
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 2;
return true;
}
case 2:
<>1__state = -1;
((SpeechProcessor)<recognizerNew>5__3).StartProcessing();
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();
}
}
[CompilerGenerated]
private sealed class <ModifiedWaitGetPlayer>d__7 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public VoiceControlListener instance;
private <>c__DisplayClass7_0 <>8__1;
private SpeechRecognizer <recognizer>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ModifiedWaitGetPlayer>d__7(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>8__1 = null;
<recognizer>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f5: Expected O, but got Unknown
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Expected O, but got Unknown
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>8__1 = new <>c__DisplayClass7_0();
<>8__1.instance = instance;
goto IL_009f;
case 1:
<>1__state = -1;
goto IL_009f;
case 2:
{
<>1__state = -1;
srRef.Invoke(<>8__1.instance) = ((Component)<>8__1.instance).GetComponent<SpeechRecognizer>();
<recognizer>5__2 = srRef.Invoke(<>8__1.instance);
((SpeechProcessor)<recognizer>5__2).LanguageModelProvider = (LanguageModelProvider)(object)((Component)<>8__1.instance).GetComponent<StreamingAssetsLanguageModelProvider>();
((SpeechProcessor)<recognizer>5__2).SpeechSource = (SpeechSource)(object)((Component)<>8__1.instance).GetComponent<DissonanceSpeechSource>();
<>8__1.instance.SpellPages = new List<ISpellCommand>();
MonoBehaviour[] components = ((Component)<>8__1.instance).gameObject.GetComponents<MonoBehaviour>();
foreach (MonoBehaviour obj in components)
{
ISpellCommand val = (ISpellCommand)(object)((obj is ISpellCommand) ? obj : null);
if (val != null)
{
<>8__1.instance.SpellPages.Add(val);
}
}
addSpellsToVocabulary(<recognizer>5__2);
((UnityEvent<Result>)(object)<recognizer>5__2.ResultReady).AddListener((UnityAction<Result>)delegate(Result res)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
<>8__1.instance.tryresult(res.text);
});
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 3;
return true;
}
case 3:
<>1__state = -1;
((SpeechProcessor)((Component)<>8__1.instance).GetComponent<SpeechRecognizer>()).StartProcessing();
break;
case 4:
{
<>1__state = -1;
if (!vbtRef.Invoke(<>8__1.instance).IsTransmitting && (Object)(object)<recognizer>5__2 != (Object)null && (int)((SpeechProcessor)<recognizer>5__2).State != 0)
{
((SpeechProcessor)<recognizer>5__2).StopProcessing();
((MonoBehaviour)<>8__1.instance).StartCoroutine((IEnumerator)restartsrMethod.Invoke(<>8__1.instance, null));
}
break;
}
IL_009f:
if ((Object)(object)<>8__1.instance.pi == (Object)null)
{
PlayerInventory pi = default(PlayerInventory);
if ((Object)(object)((Component)Camera.main).transform.parent != (Object)null && ((Component)((Component)Camera.main).transform.parent).TryGetComponent<PlayerInventory>(ref pi))
{
<>8__1.instance.pi = pi;
}
<>2__current = null;
<>1__state = 1;
return true;
}
((Component)<>8__1.instance).GetComponent<SetUpModelProvider>().Setup();
<>2__current = null;
<>1__state = 2;
return true;
}
if (((Behaviour)<>8__1.instance).isActiveAndEnabled)
{
<>2__current = (object)new WaitForSeconds(30f);
<>1__state = 4;
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();
}
}
[CompilerGenerated]
private sealed class <SafeRestartSr>d__13 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public VoiceControlListener instance;
private SpeechRecognizer <recognizer>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SafeRestartSr>d__13(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<recognizer>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<recognizer>5__2 = srRef.Invoke(instance);
if ((Object)(object)<recognizer>5__2 == (Object)null)
{
return false;
}
break;
case 1:
<>1__state = -1;
break;
}
if ((int)((SpeechProcessor)<recognizer>5__2).State != 0)
{
<>2__current = null;
<>1__state = 1;
return true;
}
if ((Object)(object)<recognizer>5__2 != (Object)null)
{
((SpeechProcessor)<recognizer>5__2).StartProcessing();
}
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();
}
}
private static Dictionary<string[], Action<VoiceControlListener>> CommandMap;
private static Dictionary<string, string[]> AdditionalCommandMap;
private static readonly FieldRef<VoiceControlListener, SpeechRecognizer> srRef = AccessTools.FieldRefAccess<VoiceControlListener, SpeechRecognizer>("sr");
private static readonly FieldRef<VoiceControlListener, VoiceBroadcastTrigger> vbtRef = AccessTools.FieldRefAccess<VoiceControlListener, VoiceBroadcastTrigger>("vbt");
private static readonly MethodInfo restartsrMethod = AccessTools.Method(typeof(VoiceControlListener), "restartsr", (Type[])null, (Type[])null);
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void AwakePostfix(VoiceControlListener __instance)
{
PluginInfo val = ((IEnumerable<PluginInfo>)Chainloader.PluginInfos.Values).FirstOrDefault((Func<PluginInfo, bool>)((PluginInfo p) => p.Metadata.GUID == "com.infernumvii.customnamespells"));
if (val != null)
{
VoiceCommandConfig.Init(val.Instance.Config);
Dictionary<string[], Action<VoiceControlListener>> dictionary = new Dictionary<string[], Action<VoiceControlListener>>();
dictionary.Add(VoiceCommandConfig.FireballCommand.Value.Split(new char[1] { ' ' }), delegate(VoiceControlListener v)
{
v.CastFireball();
});
dictionary.Add(VoiceCommandConfig.FrostBoltCommand.Value.Split(new char[1] { ' ' }), delegate(VoiceControlListener v)
{
v.CastFrostBolt();
});
dictionary.Add(VoiceCommandConfig.WormCommand.Value.Split(new char[1] { ' ' }), delegate(VoiceControlListener v)
{
v.CastWorm();
});
dictionary.Add(VoiceCommandConfig.HoleCommand.Value.Split(new char[1] { ' ' }), delegate(VoiceControlListener v)
{
v.CastHole();
});
dictionary.Add(VoiceCommandConfig.MagicMissileCommand.Value.Split(new char[1] { ' ' }), delegate(VoiceControlListener v)
{
v.CastMagicMissle();
});
dictionary.Add(VoiceCommandConfig.MirrorCommand.Value.Split(new char[1] { ' ' }), delegate(VoiceControlListener v)
{
v.ActivateMirror();
});
CommandMap = dictionary;
Dictionary<string, string[]> dictionary2 = new Dictionary<string, string[]>();
dictionary2.Add("rock", VoiceCommandConfig.RockCommand.Value.Split(new char[1] { ' ' }));
dictionary2.Add("wisp", VoiceCommandConfig.WispCommand.Value.Split(new char[1] { ' ' }));
dictionary2.Add("blast", VoiceCommandConfig.BlastCommand.Value.Split(new char[1] { ' ' }));
dictionary2.Add("divine", VoiceCommandConfig.DivineCommand.Value.Split(new char[1] { ' ' }));
dictionary2.Add("blink", VoiceCommandConfig.BlinkCommand.Value.Split(new char[1] { ' ' }));
dictionary2.Add("thunderbolt", VoiceCommandConfig.ThunderboltCommand.Value.Split(new char[1] { ' ' }));
dictionary2.Add("bubble", VoiceCommandConfig.BubbleCommand.Value.Split(new char[1] { ' ' }));
dictionary2.Add("doom", VoiceCommandConfig.DoomCommand.Value.Split(new char[1] { ' ' }));
AdditionalCommandMap = dictionary2;
}
}
[HarmonyPatch("waitgetplayer")]
[HarmonyPrefix]
private static bool WaitGetPlayerPrefix(VoiceControlListener __instance, ref IEnumerator __result)
{
__result = ModifiedWaitGetPlayer(__instance);
return false;
}
[IteratorStateMachine(typeof(<ModifiedWaitGetPlayer>d__7))]
private static IEnumerator ModifiedWaitGetPlayer(VoiceControlListener instance)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ModifiedWaitGetPlayer>d__7(0)
{
instance = instance
};
}
private static void addSpellsToVocabulary(SpeechRecognizer recognizer)
{
foreach (KeyValuePair<string[], Action<VoiceControlListener>> item3 in CommandMap)
{
string[] key = item3.Key;
foreach (string item in key)
{
recognizer.Vocabulary.Add(item);
}
}
foreach (KeyValuePair<string, string[]> item4 in AdditionalCommandMap)
{
string[] key = item4.Value;
foreach (string item2 in key)
{
recognizer.Vocabulary.Add(item2);
}
}
}
[HarmonyPatch("tryresult")]
[HarmonyPrefix]
private static bool TryResultPrefix(VoiceControlListener __instance, string res)
{
if (res != null)
{
foreach (KeyValuePair<string[], Action<VoiceControlListener>> item in CommandMap)
{
if (item.Key.Any((string keyword) => res.Contains(keyword)))
{
item.Value(__instance);
}
}
foreach (KeyValuePair<string, string[]> pair in AdditionalCommandMap)
{
if (pair.Value.Any((string keyword) => res.Contains(keyword)))
{
ISpellCommand? obj = ((IEnumerable<ISpellCommand>)__instance.SpellPages).FirstOrDefault((Func<ISpellCommand, bool>)((ISpellCommand s) => s != null && s.GetSpellName() == pair.Key));
if (obj != null)
{
obj.TryCastSpell();
}
}
}
((SpeechProcessor)srRef.Invoke(__instance)).StopProcessing();
((MonoBehaviour)__instance).StartCoroutine((IEnumerator)restartsrMethod.Invoke(__instance, null));
}
return false;
}
[HarmonyPatch("resetmiclong")]
[HarmonyPrefix]
private static bool ResetMicLongPrefix(VoiceControlListener __instance, ref IEnumerator __result)
{
__result = ModifiedResetMicLong(__instance);
return false;
}
[IteratorStateMachine(typeof(<ModifiedResetMicLong>d__11))]
private static IEnumerator ModifiedResetMicLong(VoiceControlListener instance)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ModifiedResetMicLong>d__11(0)
{
instance = instance
};
}
[HarmonyPatch("restartsr")]
[HarmonyPrefix]
private static bool RestartSrPrefix(VoiceControlListener __instance, ref IEnumerator __result)
{
__result = SafeRestartSr(__instance);
return false;
}
[IteratorStateMachine(typeof(<SafeRestartSr>d__13))]
private static IEnumerator SafeRestartSr(VoiceControlListener instance)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SafeRestartSr>d__13(0)
{
instance = instance
};
}
}
}
namespace CustomNameSpells.Config
{
public static class VoiceCommandConfig
{
public static ConfigEntry<string> FireballCommand;
public static ConfigEntry<string> FrostBoltCommand;
public static ConfigEntry<string> WormCommand;
public static ConfigEntry<string> HoleCommand;
public static ConfigEntry<string> MagicMissileCommand;
public static ConfigEntry<string> MirrorCommand;
public static ConfigEntry<string> RockCommand;
public static ConfigEntry<string> WispCommand;
public static ConfigEntry<string> BlastCommand;
public static ConfigEntry<string> DivineCommand;
public static ConfigEntry<string> BlinkCommand;
public static ConfigEntry<string> ThunderboltCommand;
public static ConfigEntry<string> BubbleCommand;
public static ConfigEntry<string> DoomCommand;
public static void Init(ConfigFile config)
{
FireballCommand = config.Bind<string>("Commands", "Fireball", "fire ball fireball", "Command for Fireball spell (all variants of the word can be separated by a space)");
FrostBoltCommand = config.Bind<string>("Commands", "FrostBolt", "freeze ease", "Command for Frost Bolt spell (all variants of the word can be separated by a space)");
WormCommand = config.Bind<string>("Commands", "Worm", "worm", "Command for Worm spell (all variants of the word can be separated by a space)");
HoleCommand = config.Bind<string>("Commands", "Hole", "hole", "Command for Hole spell (all variants of the word can be separated by a space)");
MagicMissileCommand = config.Bind<string>("Commands", "MagicMissile", "magic missile", "Command for Magic Missile spell (all variants of the word can be separated by a space)");
MirrorCommand = config.Bind<string>("Commands", "Mirror", "mirror", "Command for Mirror spell (all variants of the word can be separated by a space)");
RockCommand = config.Bind<string>("AdditionalCommands", "Rock", "rock", "Command for Rock spell (all variants of the word can be separated by a space)");
WispCommand = config.Bind<string>("AdditionalCommands", "Wisp", "wisp", "Command for Wisp spell (all variants of the word can be separated by a space)");
BlastCommand = config.Bind<string>("AdditionalCommands", "Blast", "dark blast", "Command for Blast spell (all variants of the word can be separated by a space)");
DivineCommand = config.Bind<string>("AdditionalCommands", "Divine", "divine light", "Command for Divine spell (all variants of the word can be separated by a space)");
BlinkCommand = config.Bind<string>("AdditionalCommands", "Blink", "blink", "Command for Blink spell (all variants of the word can be separated by a space)");
ThunderboltCommand = config.Bind<string>("AdditionalCommands", "Thunderbolt", "thunderbolt thunder bolt", "Command for Thunderbolt spell (all variants of the word can be separated by a space)");
BubbleCommand = config.Bind<string>("AdditionalCommands", "Bubble", "bubble", "Command for Bubble spell (all variants of the word can be separated by a space)");
DoomCommand = config.Bind<string>("AdditionalCommands", "Doom", "doom", "Command for Doom spell (all variants of the word can be separated by a space)");
}
}
}