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 System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using FMOD;
using FMODUnity;
using Il2CppInterop.Runtime.Injection;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("VoiceSpeaker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VoiceSpeaker")]
[assembly: AssemblyTitle("VoiceSpeaker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 VoiceSpeaker
{
[BepInPlugin("com.custom.voicespeaker", "VoiceSpeaker", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
public const string PluginGuid = "com.custom.voicespeaker";
public const string PluginName = "VoiceSpeaker";
public const string PluginVersion = "1.0.2";
internal static ManualLogSource LogSource;
internal static string SoundsFolder;
public override void Load()
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Expected O, but got Unknown
LogSource = ((BasePlugin)this).Log;
string location = Assembly.GetExecutingAssembly().Location;
SoundsFolder = Path.Combine((!string.IsNullOrEmpty(location)) ? Path.GetDirectoryName(location) : Path.Combine(Paths.PluginPath, "VoiceSpeaker"), "Sounds");
Directory.CreateDirectory(SoundsFolder);
ClassInjector.RegisterTypeInIl2Cpp<VoiceSpeakerUpdater>();
GameObject val = new GameObject("VoiceSpeakerUpdater");
Object.DontDestroyOnLoad((Object)val);
((Object)val).hideFlags = (HideFlags)61;
val.AddComponent<VoiceSpeakerUpdater>();
ManualLogSource logSource = LogSource;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(33, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("VoiceSpeaker");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" v");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("1.0.2");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" loaded. Custom sounds folder: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(SoundsFolder);
}
logSource.LogInfo(val2);
}
}
public class VoiceSpeakerUpdater : MonoBehaviour
{
private struct CustomVoiceEntry
{
public string FilePath;
public string DisplayLabel;
public Sound FmodSound;
}
private class SpeakerRuntimeState
{
public int CustomIndex = -1;
public Channel ActiveChannel;
public bool PrevTestPressed;
public bool PrevPortHigh;
public float NextLoopAllowedTime;
}
private readonly List<CustomVoiceEntry> _customEntries = new List<CustomVoiceEntry>();
private readonly Dictionary<Entity, SpeakerRuntimeState> _states = new Dictionary<Entity, SpeakerRuntimeState>();
private readonly Dictionary<Entity, float> _savedVolumes = new Dictionary<Entity, float>();
private bool _audioLoaded;
private Canvas _overlayCanvas;
private Text _overlayText;
private static readonly HashSet<string> SupportedExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".wav", ".ogg", ".mp3", ".flac" };
public VoiceSpeakerUpdater(IntPtr ptr)
: base(ptr)
{
}
private void EnsureOverlayCreated()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_overlayCanvas != (Object)null))
{
GameObject val = new GameObject("VoiceSpeakerOverlay");
Object.DontDestroyOnLoad((Object)(object)val);
((Object)val).hideFlags = (HideFlags)61;
_overlayCanvas = val.AddComponent<Canvas>();
_overlayCanvas.renderMode = (RenderMode)0;
_overlayCanvas.sortingOrder = 500;
GameObject val2 = new GameObject("VoiceSpeakerLabel");
val2.transform.SetParent(val.transform, false);
_overlayText = val2.AddComponent<Text>();
_overlayText.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
if ((Object)(object)_overlayText.font == (Object)null)
{
_overlayText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
}
_overlayText.fontSize = 18;
_overlayText.fontStyle = (FontStyle)1;
_overlayText.alignment = (TextAnchor)4;
((Graphic)_overlayText).color = new Color(1f, 0.85f, 0.25f, 1f);
((Graphic)_overlayText).raycastTarget = false;
Outline obj = val2.AddComponent<Outline>();
((Shadow)obj).effectColor = new Color(0f, 0f, 0f, 0.9f);
((Shadow)obj).effectDistance = new Vector2(1.5f, -1.5f);
RectTransform component = ((Component)_overlayText).GetComponent<RectTransform>();
component.anchorMin = new Vector2(0.5f, 0.5f);
component.anchorMax = new Vector2(0.5f, 0.5f);
component.pivot = new Vector2(0.5f, 0.5f);
component.anchoredPosition = new Vector2(0f, -45f);
component.sizeDelta = new Vector2(520f, 40f);
((Behaviour)_overlayText).enabled = false;
}
}
private void Update()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Unknown result type (might be due to invalid IL or missing references)
//IL_0286: Unknown result type (might be due to invalid IL or missing references)
//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0302: Unknown result type (might be due to invalid IL or missing references)
World defaultGameObjectInjectionWorld = World.DefaultGameObjectInjectionWorld;
if (defaultGameObjectInjectionWorld == null || !defaultGameObjectInjectionWorld.IsCreated || (!_audioLoaded && !LoadCustomFmodSounds()) || _customEntries.Count == 0)
{
return;
}
EnsureOverlayCreated();
EntityManager entityManager = defaultGameObjectInjectionWorld.EntityManager;
Entity lookedAtOrHeldEntity = GetLookedAtOrHeldEntity(entityManager);
float num = 0f;
if (Mouse.current != null)
{
num = ((InputControl<Vector2>)(object)Mouse.current.scroll).ReadValue().y;
}
int num2 = 0;
if (num > 0.01f)
{
num2 = 1;
}
else if (num < -0.01f)
{
num2 = -1;
}
_savedVolumes.Clear();
EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<SCTypeSpeaker>() });
try
{
if (((EntityQuery)(ref val)).IsEmptyIgnoreFilter)
{
if ((Object)(object)_overlayText != (Object)null)
{
((Behaviour)_overlayText).enabled = false;
}
return;
}
NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
NativeArray<SCTypeSpeaker> val3 = ((EntityQuery)(ref val)).ToComponentDataArray<SCTypeSpeaker>(AllocatorHandle.op_Implicit((Allocator)2));
try
{
string text = null;
for (int i = 0; i < val3.Length; i++)
{
Entity val4 = val2[i];
SCTypeSpeaker val5 = val3[i];
if (!_states.TryGetValue(val4, out var value))
{
value = new SpeakerRuntimeState();
_states[val4] = value;
}
Entity soundKnobEntity = val5._soundKnobEntity;
bool flag = lookedAtOrHeldEntity != Entity.Null && (lookedAtOrHeldEntity == soundKnobEntity || lookedAtOrHeldEntity == val4);
int num3 = 0;
if (soundKnobEntity != Entity.Null && ((EntityManager)(ref entityManager)).Exists(soundKnobEntity) && ((EntityManager)(ref entityManager)).HasComponent<ActionableData>(soundKnobEntity))
{
ActionableData componentData = ((EntityManager)(ref entityManager)).GetComponentData<ActionableData>(soundKnobEntity);
int num4 = Math.Max(1, componentData._roundingIntervals);
num3 = Mathf.RoundToInt(Mathf.Clamp01(componentData._value.x) * (float)num4);
}
if (flag && num2 != 0)
{
if (value.CustomIndex >= 0)
{
value.CustomIndex += num2;
if (value.CustomIndex < 0)
{
value.CustomIndex = -1;
}
else if (value.CustomIndex >= _customEntries.Count)
{
value.CustomIndex = _customEntries.Count - 1;
}
}
else if (num2 > 0 && num3 >= 22)
{
value.CustomIndex = 0;
}
}
if (num3 < 22 && value.CustomIndex >= 0 && !flag)
{
value.CustomIndex = -1;
}
if (value.CustomIndex >= 0)
{
if (((Channel)(ref val5._channel)).hasHandle())
{
((Channel)(ref val5._channel)).setVolume(0f);
((Channel)(ref val5._channel)).stop();
}
if (val5._volumeKnobEntity != Entity.Null && ((EntityManager)(ref entityManager)).Exists(val5._volumeKnobEntity) && ((EntityManager)(ref entityManager)).HasComponent<ActionableData>(val5._volumeKnobEntity))
{
ActionableData componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<ActionableData>(val5._volumeKnobEntity);
_savedVolumes[val4] = componentData2._value.x;
componentData2._value.x = 0f;
((EntityManager)(ref entityManager)).SetComponentData<ActionableData>(val5._volumeKnobEntity, componentData2);
}
if (flag)
{
int value2 = 24 + value.CustomIndex;
text = $"SOUND {value2}: {_customEntries[value.CustomIndex].DisplayLabel}";
}
}
}
if ((Object)(object)_overlayText != (Object)null)
{
if (!string.IsNullOrEmpty(text))
{
_overlayText.text = text;
((Behaviour)_overlayText).enabled = true;
}
else
{
((Behaviour)_overlayText).enabled = false;
}
}
}
finally
{
val2.Dispose();
val3.Dispose();
}
}
finally
{
((EntityQuery)(ref val)).Dispose();
}
}
private void LateUpdate()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_0254: Unknown result type (might be due to invalid IL or missing references)
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_02db: Unknown result type (might be due to invalid IL or missing references)
//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0308: Unknown result type (might be due to invalid IL or missing references)
//IL_0314: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_0340: Unknown result type (might be due to invalid IL or missing references)
//IL_0356: Unknown result type (might be due to invalid IL or missing references)
//IL_035e: Unknown result type (might be due to invalid IL or missing references)
//IL_0366: Unknown result type (might be due to invalid IL or missing references)
//IL_0374: Unknown result type (might be due to invalid IL or missing references)
//IL_0382: Unknown result type (might be due to invalid IL or missing references)
//IL_038e: Unknown result type (might be due to invalid IL or missing references)
//IL_0390: Unknown result type (might be due to invalid IL or missing references)
//IL_0394: Unknown result type (might be due to invalid IL or missing references)
//IL_03be: Unknown result type (might be due to invalid IL or missing references)
//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
//IL_045d: Unknown result type (might be due to invalid IL or missing references)
//IL_0462: Unknown result type (might be due to invalid IL or missing references)
//IL_0443: Unknown result type (might be due to invalid IL or missing references)
World defaultGameObjectInjectionWorld = World.DefaultGameObjectInjectionWorld;
if (defaultGameObjectInjectionWorld == null || !defaultGameObjectInjectionWorld.IsCreated || !_audioLoaded || _customEntries.Count == 0)
{
return;
}
EntityManager entityManager = defaultGameObjectInjectionWorld.EntityManager;
EntityQuery val = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<SCTypeSpeaker>() });
try
{
if (((EntityQuery)(ref val)).IsEmptyIgnoreFilter)
{
return;
}
NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
NativeArray<SCTypeSpeaker> val3 = ((EntityQuery)(ref val)).ToComponentDataArray<SCTypeSpeaker>(AllocatorHandle.op_Implicit((Allocator)2));
try
{
for (int i = 0; i < val3.Length; i++)
{
Entity val4 = val2[i];
SCTypeSpeaker val5 = val3[i];
float volume = 1f;
if (val5._volumeKnobEntity != Entity.Null && ((EntityManager)(ref entityManager)).Exists(val5._volumeKnobEntity) && ((EntityManager)(ref entityManager)).HasComponent<ActionableData>(val5._volumeKnobEntity))
{
ActionableData componentData = ((EntityManager)(ref entityManager)).GetComponentData<ActionableData>(val5._volumeKnobEntity);
if (_savedVolumes.TryGetValue(val4, out var value))
{
componentData._value.x = value;
((EntityManager)(ref entityManager)).SetComponentData<ActionableData>(val5._volumeKnobEntity, componentData);
volume = Mathf.Clamp01(value);
}
else
{
volume = Mathf.Clamp01(componentData._value.x);
}
}
if (!_states.TryGetValue(val4, out var value2) || value2.CustomIndex < 0)
{
continue;
}
if (((Channel)(ref val5._channel)).hasHandle())
{
((Channel)(ref val5._channel)).setVolume(0f);
((Channel)(ref val5._channel)).stop();
}
bool flag = false;
if (val5._buttonTestEntity != Entity.Null && ((EntityManager)(ref entityManager)).Exists(val5._buttonTestEntity) && ((EntityManager)(ref entityManager)).HasComponent<ActionableData>(val5._buttonTestEntity))
{
flag = ((EntityManager)(ref entityManager)).GetComponentData<ActionableData>(val5._buttonTestEntity)._value.x > 0.5f;
}
bool flag2 = false;
if (val5._modeEntity != Entity.Null && ((EntityManager)(ref entityManager)).Exists(val5._modeEntity) && ((EntityManager)(ref entityManager)).HasComponent<ActionableData>(val5._modeEntity))
{
flag2 = ((EntityManager)(ref entityManager)).GetComponentData<ActionableData>(val5._modeEntity)._value.x > 0.5f;
}
bool flag3 = false;
if (((EntityManager)(ref entityManager)).HasBuffer<SpaceshipElectricPortRef>(val4))
{
DynamicBuffer<SpaceshipElectricPortRef> buffer = ((EntityManager)(ref entityManager)).GetBuffer<SpaceshipElectricPortRef>(val4, false);
for (int j = 0; j < buffer.Length; j++)
{
Entity portEntity = buffer[j]._portEntity;
if (portEntity != Entity.Null && ((EntityManager)(ref entityManager)).Exists(portEntity) && ((EntityManager)(ref entityManager)).HasComponent<SpaceshipElectricPort>(portEntity))
{
SpaceshipElectricPort componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<SpaceshipElectricPort>(portEntity);
if (((SpaceshipElectricPort)(ref componentData2)).DataValue01() > 0.5f)
{
flag3 = true;
break;
}
}
}
}
bool num = flag && !value2.PrevTestPressed;
bool flag4 = flag3 && !value2.PrevPortHigh;
value2.PrevTestPressed = flag;
value2.PrevPortHigh = flag3;
Vector3 zero = Vector3.zero;
if (((EntityManager)(ref entityManager)).HasComponent<LocalToWorld>(val4))
{
LocalToWorld componentData3 = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(val4);
((Vector3)(ref zero))..ctor(((LocalToWorld)(ref componentData3)).Position.x, ((LocalToWorld)(ref componentData3)).Position.y, ((LocalToWorld)(ref componentData3)).Position.z);
}
bool flag5 = false;
if (((Channel)(ref value2.ActiveChannel)).hasHandle())
{
((Channel)(ref value2.ActiveChannel)).isPlaying(ref flag5);
if (flag5)
{
((Channel)(ref value2.ActiveChannel)).setVolume(volume);
VECTOR val6 = new VECTOR
{
x = zero.x,
y = zero.y,
z = zero.z
};
VECTOR val7 = new VECTOR
{
x = 0f,
y = 0f,
z = 0f
};
((Channel)(ref value2.ActiveChannel)).set3DAttributes(ref val6, ref val7);
}
}
if (!flag3 && !flag && flag2 && flag5)
{
((Channel)(ref value2.ActiveChannel)).stop();
flag5 = false;
}
bool flag6 = false;
if (num || flag4)
{
flag6 = true;
}
else if (flag2 && flag3 && !flag5 && Time.unscaledTime >= value2.NextLoopAllowedTime)
{
flag6 = true;
}
if (flag6 && value2.CustomIndex < _customEntries.Count)
{
if (flag5)
{
((Channel)(ref value2.ActiveChannel)).stop();
}
Play3DCustomSound(value2, _customEntries[value2.CustomIndex].FmodSound, zero, volume);
value2.NextLoopAllowedTime = Time.unscaledTime + 0.35f;
}
}
}
finally
{
val2.Dispose();
val3.Dispose();
}
}
finally
{
((EntityQuery)(ref val)).Dispose();
}
}
private static Entity GetLookedAtOrHeldEntity(EntityManager em)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
EntityQuery val = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<ActionablesController>() });
try
{
if (((EntityQuery)(ref val)).IsEmptyIgnoreFilter)
{
return Entity.Null;
}
NativeArray<ActionablesController> val2 = ((EntityQuery)(ref val)).ToComponentDataArray<ActionablesController>(AllocatorHandle.op_Implicit((Allocator)2));
try
{
for (int i = 0; i < val2.Length; i++)
{
if (val2[i]._assignedEntity != Entity.Null)
{
return val2[i]._assignedEntity;
}
if (val2[i]._targetEntity != Entity.Null)
{
return val2[i]._targetEntity;
}
}
}
finally
{
val2.Dispose();
}
}
finally
{
((EntityQuery)(ref val)).Dispose();
}
return Entity.Null;
}
private static void Play3DCustomSound(SpeakerRuntimeState state, Sound sound, Vector3 worldPos, float volume)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
try
{
System coreSystem = RuntimeManager.CoreSystem;
if (((System)(ref coreSystem)).hasHandle() && ((Sound)(ref sound)).hasHandle())
{
ChannelGroup val = default(ChannelGroup);
((System)(ref coreSystem)).getMasterChannelGroup(ref val);
Channel activeChannel = default(Channel);
if ((int)((System)(ref coreSystem)).playSound(sound, val, true, ref activeChannel) == 0 && ((Channel)(ref activeChannel)).hasHandle())
{
VECTOR val2 = new VECTOR
{
x = worldPos.x,
y = worldPos.y,
z = worldPos.z
};
VECTOR val3 = new VECTOR
{
x = 0f,
y = 0f,
z = 0f
};
((Channel)(ref activeChannel)).set3DAttributes(ref val2, ref val3);
((Channel)(ref activeChannel)).setVolume(volume);
((Channel)(ref activeChannel)).setPaused(false);
state.ActiveChannel = activeChannel;
}
}
}
catch (Exception ex)
{
ManualLogSource logSource = Plugin.LogSource;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val4 = new BepInExDebugLogInterpolatedStringHandler(25, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Play3DCustomSound error: ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message);
}
logSource.LogDebug(val4);
}
}
private bool LoadCustomFmodSounds()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Expected O, but got Unknown
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Expected O, but got Unknown
System coreSystem;
try
{
coreSystem = RuntimeManager.CoreSystem;
if (!((System)(ref coreSystem)).hasHandle())
{
return false;
}
}
catch
{
return false;
}
Sound fmodSound = default(Sound);
bool flag = default(bool);
foreach (string item in DiscoverSoundFiles())
{
string text = FormatDisplayLabel(item);
MODE val = (MODE)2097424;
RESULT val2 = ((System)(ref coreSystem)).createSound(item, val, ref fmodSound);
if ((int)val2 == 0 && ((Sound)(ref fmodSound)).hasHandle())
{
((Sound)(ref fmodSound)).set3DMinMaxDistance(2f, 45f);
_customEntries.Add(new CustomVoiceEntry
{
FilePath = item,
DisplayLabel = text,
FmodSound = fmodSound
});
ManualLogSource logSource = Plugin.LogSource;
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(34, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Loaded custom speaker voice: '");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' (");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(Path.GetFileName(item));
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(")");
}
logSource.LogInfo(val3);
}
else
{
ManualLogSource logSource2 = Plugin.LogSource;
BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(33, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("FMOD failed to load '");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(item);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("' (Result: ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<RESULT>(val2);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(")");
}
logSource2.LogWarning(val4);
}
}
_audioLoaded = true;
return true;
}
private static List<string> DiscoverSoundFiles()
{
List<string> list = new List<string>();
if (Directory.Exists(Plugin.SoundsFolder))
{
list.AddRange((from f in Directory.GetFiles(Plugin.SoundsFolder)
where SupportedExtensions.Contains(Path.GetExtension(f))
select f).OrderBy<string, string>((string f) => Path.GetFileName(f), StringComparer.OrdinalIgnoreCase));
}
try
{
if (Directory.Exists(Paths.PluginPath))
{
string[] directories = Directory.GetDirectories(Paths.PluginPath);
for (int num = 0; num < directories.Length; num++)
{
string text = Path.Combine(directories[num], "Sounds");
if (!string.Equals(text, Plugin.SoundsFolder, StringComparison.OrdinalIgnoreCase) && Directory.Exists(text))
{
list.AddRange((from f in Directory.GetFiles(text)
where SupportedExtensions.Contains(Path.GetExtension(f))
select f).OrderBy<string, string>((string f) => Path.GetFileName(f), StringComparer.OrdinalIgnoreCase));
}
}
}
}
catch
{
}
return list;
}
private static string FormatDisplayLabel(string filePath)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);
fileNameWithoutExtension = Regex.Replace(fileNameWithoutExtension, "^\\d+[\\s_\\-\\.]*", "");
fileNameWithoutExtension = fileNameWithoutExtension.Replace('_', ' ').Replace('-', ' ').Trim();
if (string.IsNullOrWhiteSpace(fileNameWithoutExtension))
{
fileNameWithoutExtension = "CUSTOM VOICE";
}
fileNameWithoutExtension = fileNameWithoutExtension.ToUpperInvariant();
if (fileNameWithoutExtension.Length > 55)
{
fileNameWithoutExtension = fileNameWithoutExtension.Substring(0, 55);
}
return fileNameWithoutExtension;
}
}
}