Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ValuableSoundTrigger v1.0.0
ValuableSoundTrigger.dll
Decompiled 8 hours agousing System; using System.Collections.Generic; using System.Diagnostics; 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 ExitGames.Client.Photon; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using REPOLib.Modules; using UnityEngine; using UnityEngine.InputSystem; [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: AssemblyCompany("LingeringHopes")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+c6a9b886e9602a5a7954d6baf0514e85bda6b4c2")] [assembly: AssemblyProduct("ValuableSoundTrigger")] [assembly: AssemblyTitle("ValuableSoundTrigger")] [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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 ValuableSoundTrigger { internal enum InputTriggerCode { ListenToValuableSound, PlayBreakLightAudio, PlayBreakMediumAudio, PlayBreakHeavyAudio, PlayImpactLightAudio, PlayImpactMediumAudio, PlayImpactHeavyAudio, PlayPhysGrabDetectAudio, PlayDestroyAudio } public class InputTriggerManager { private readonly Dictionary<InputTriggerCode, string> DEFAULT_TRIGGER_INPUT_KEYS = new Dictionary<InputTriggerCode, string> { { InputTriggerCode.ListenToValuableSound, "<Keyboard>/g" }, { InputTriggerCode.PlayBreakLightAudio, "<Keyboard>/numpad1" }, { InputTriggerCode.PlayBreakMediumAudio, "<Keyboard>/numpad2" }, { InputTriggerCode.PlayBreakHeavyAudio, "<Keyboard>/numpad3" }, { InputTriggerCode.PlayImpactLightAudio, "<Keyboard>/numpad4" }, { InputTriggerCode.PlayImpactMediumAudio, "<Keyboard>/numpad5" }, { InputTriggerCode.PlayImpactHeavyAudio, "<Keyboard>/numpad6" }, { InputTriggerCode.PlayPhysGrabDetectAudio, "<Keyboard>/numpad7" }, { InputTriggerCode.PlayDestroyAudio, "<Keyboard>/numpad8" } }; private Dictionary<InputTriggerCode, ConfigEntry<string>> triggerConfigs = null; private Dictionary<InputTriggerCode, InputAction> triggerActions = null; private static InputTriggerManager instance; private InputActionMap valuableSoundInputActionMap = null; internal static InputTriggerManager Instance { get { if (instance == null) { instance = new InputTriggerManager(); } return instance; } } public InputTriggerManager() { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown //IL_00b3: Unknown result type (might be due to invalid IL or missing references) valuableSoundInputActionMap = new InputActionMap("ValuableSoundInputActionMap"); valuableSoundInputActionMap.devices = InputSystem.devices; valuableSoundInputActionMap.Enable(); triggerConfigs = new Dictionary<InputTriggerCode, ConfigEntry<string>>(); triggerActions = new Dictionary<InputTriggerCode, InputAction>(); } internal void LoadValuableSoundTriggerActionFromConfig(ConfigFile config) { foreach (InputTriggerCode code in Enum.GetValues(typeof(InputTriggerCode))) { string text = code.ToString(); string text2 = DEFAULT_TRIGGER_INPUT_KEYS[code].Split('/')[1]; ConfigEntry<string> entry = config.Bind<string>("Controls", text, DEFAULT_TRIGGER_INPUT_KEYS[code].Split('/')[1], $"Key used to {code}"); if (!triggerConfigs.ContainsKey(code)) { triggerConfigs.Add(code, entry); } entry.SettingChanged += delegate { string keyPath = "<Keyboard>/" + entry.Value; string text3 = ModifyValuableSoundTriggerActionKey(code, keyPath); }; } } internal void AddValuableSoundTriggerAction(InputTriggerCode triggerCode, Action<CallbackContext> startedCallback = null, Action<CallbackContext> performedCallback = null, Action<CallbackContext> canceledCallback = null) { if (triggerActions.ContainsKey(triggerCode)) { ValuableSoundTrigger.Logger.LogWarning((object)("Input already exist for => " + triggerCode)); return; } valuableSoundInputActionMap.Disable(); string text = null; text = ((!triggerConfigs.TryGetValue(triggerCode, out ConfigEntry<string> value)) ? DEFAULT_TRIGGER_INPUT_KEYS[triggerCode] : (value.Value.Contains("<") ? value.Value : ("<Keyboard>/" + value.Value))); InputAction val = InputActionSetupExtensions.AddAction(valuableSoundInputActionMap, triggerCode.ToString(), (InputActionType)1, text, (string)null, (string)null, (string)null, (string)null); if (startedCallback != null) { val.started += startedCallback; } if (performedCallback != null) { val.performed += performedCallback; } if (canceledCallback != null) { val.canceled += canceledCallback; } val.Enable(); triggerActions.Add(triggerCode, val); valuableSoundInputActionMap.Enable(); } internal string ModifyValuableSoundTriggerActionKey(InputTriggerCode triggerCode, string keyPath) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) if (!triggerActions.ContainsKey(triggerCode) || string.IsNullOrEmpty(keyPath)) { return ""; } InputAction val = triggerActions[triggerCode]; InputBinding val2 = val.bindings[0]; string effectivePath = ((InputBinding)(ref val2)).effectivePath; val.Disable(); InputActionRebindingExtensions.ApplyBindingOverride(val, 0, keyPath); val.Enable(); if (val.controls.Count <= 0) { ValuableSoundTrigger.Logger.LogWarning((object)("Invalid key '" + keyPath + "', reverting to '" + effectivePath + "'")); val.Disable(); InputActionRebindingExtensions.ApplyBindingOverride(val, 0, effectivePath); val.Enable(); return effectivePath.Contains("/") ? effectivePath.Split('/')[1] : effectivePath; } return keyPath.Contains("/") ? keyPath.Split('/')[1] : keyPath; } } internal class ValuableSoundNetwork { private NetworkedEvent playValuableSoundEvent = null; private NetworkedEvent playGrabImpactDetectorAllBreaksEvent = null; private bool listening = false; public void Initialize(InputTriggerManager triggerManager) { //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Expected O, but got Unknown //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown triggerManager.AddValuableSoundTriggerAction(InputTriggerCode.ListenToValuableSound, ListenToValuableSoundTriggers, null, UnlistenToValuableSoundTriggers); triggerManager.AddValuableSoundTriggerAction(InputTriggerCode.PlayBreakLightAudio, delegate { PlayAudio(InputTriggerCode.PlayBreakLightAudio); }); triggerManager.AddValuableSoundTriggerAction(InputTriggerCode.PlayBreakMediumAudio, delegate { PlayAudio(InputTriggerCode.PlayBreakMediumAudio); }); triggerManager.AddValuableSoundTriggerAction(InputTriggerCode.PlayBreakHeavyAudio, delegate { PlayAudio(InputTriggerCode.PlayBreakHeavyAudio); }); triggerManager.AddValuableSoundTriggerAction(InputTriggerCode.PlayImpactLightAudio, delegate { PlayAudio(InputTriggerCode.PlayImpactLightAudio); }); triggerManager.AddValuableSoundTriggerAction(InputTriggerCode.PlayImpactMediumAudio, delegate { PlayAudio(InputTriggerCode.PlayImpactMediumAudio); }); triggerManager.AddValuableSoundTriggerAction(InputTriggerCode.PlayImpactHeavyAudio, delegate { PlayAudio(InputTriggerCode.PlayImpactHeavyAudio); }); triggerManager.AddValuableSoundTriggerAction(InputTriggerCode.PlayPhysGrabDetectAudio, PlayPhysGrabDetecEvent); triggerManager.AddValuableSoundTriggerAction(InputTriggerCode.PlayDestroyAudio, delegate { PlayAudio(InputTriggerCode.PlayDestroyAudio); }); playValuableSoundEvent = new NetworkedEvent("PlayValuableSound", (Action<EventData>)OnPlayValuableSoundReceived); playGrabImpactDetectorAllBreaksEvent = new NetworkedEvent("PlayValuableSoundFromGrabDetector", (Action<EventData>)OnPlayValuableSoundFromGrabDetectorReceived); } private static void OnPlayValuableSoundReceived(EventData data) { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0109: 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_0177: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) try { object[] array = (object[])data.CustomData; int num = (int)array[0]; PhotonView val = PhotonView.Find(num); InputTriggerCode inputTriggerCode = (InputTriggerCode)array[1]; ValuableObject val2 = default(ValuableObject); if ((Object)null != (Object)(object)val && ((Component)val).TryGetComponent<ValuableObject>(ref val2) && Object.op_Implicit((Object)(object)val2.audioPreset)) { switch (inputTriggerCode) { case InputTriggerCode.PlayBreakLightAudio: val2.audioPreset.breakLight.Play(((Component)val2).transform.position, 1f, 1f, 1f, 1f); break; case InputTriggerCode.PlayBreakMediumAudio: val2.audioPreset.breakMedium.Play(((Component)val2).transform.position, 1f, 1f, 1f, 1f); break; case InputTriggerCode.PlayBreakHeavyAudio: val2.audioPreset.breakHeavy.Play(((Component)val2).transform.position, 1f, 1f, 1f, 1f); break; case InputTriggerCode.PlayImpactLightAudio: val2.audioPreset.impactLight.Play(((Component)val2).transform.position, 1f, 1f, 1f, 1f); break; case InputTriggerCode.PlayImpactMediumAudio: val2.audioPreset.impactMedium.Play(((Component)val2).transform.position, 1f, 1f, 1f, 1f); break; case InputTriggerCode.PlayImpactHeavyAudio: val2.audioPreset.impactHeavy.Play(((Component)val2).transform.position, 1f, 1f, 1f, 1f); break; case InputTriggerCode.PlayDestroyAudio: val2.audioPreset.destroy.Play(((Component)val2).transform.position, 1f, 1f, 1f, 1f); break; case InputTriggerCode.PlayPhysGrabDetectAudio: break; } } } catch (Exception arg) { ValuableSoundTrigger.Logger.LogError((object)$"Error when playing sound from ValuableObject : {arg}"); } } private static void OnPlayValuableSoundFromGrabDetectorReceived(EventData data) { try { int num = (int)data.CustomData; PhotonView val = PhotonView.Find(num); if ((Object)null != (Object)(object)val) { ((Component)val).GetComponent<PhysGrabObjectImpactDetector>().onAllBreaks.Invoke(); } } catch (Exception arg) { ValuableSoundTrigger.Logger.LogError((object)$"Error when playing sound from PhysGrabObjectImpactDetector : {arg}"); } } private void ListenToValuableSoundTriggers(CallbackContext context) { listening = true; } private void UnlistenToValuableSoundTriggers(CallbackContext context) { listening = false; } private bool RetrieveValuablePhotonViewID(out int photonViewID) { photonViewID = -1; try { if (!listening) { return false; } PhysGrabObject val = PhysGrabber.instance?.grabbedPhysGrabObject; if (!Object.op_Implicit((Object)(object)val)) { return false; } ValuableObject val2 = default(ValuableObject); if ((Object)(object)val != (Object)null && ((Component)val).TryGetComponent<ValuableObject>(ref val2)) { photonViewID = ((Component)val2).GetComponent<PhotonView>().ViewID; return true; } return false; } catch (Exception arg) { ValuableSoundTrigger.Logger.LogError((object)$"Error when retrieving valuable's photon view ID : {arg}"); return false; } } private void PlayAudio(InputTriggerCode code) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) if (RetrieveValuablePhotonViewID(out var photonViewID)) { playValuableSoundEvent.RaiseEvent((object)new object[2] { photonViewID, code }, NetworkingEvents.RaiseAll, SendOptions.SendReliable); } } private void PlayPhysGrabDetecEvent(CallbackContext context) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) try { if (listening) { PhysGrabObject val = PhysGrabber.instance?.grabbedPhysGrabObject; PhysGrabObjectImpactDetector val2 = default(PhysGrabObjectImpactDetector); if (Object.op_Implicit((Object)(object)val) && ((Component)val).TryGetComponent<PhysGrabObjectImpactDetector>(ref val2)) { playGrabImpactDetectorAllBreaksEvent.RaiseEvent((object)((Component)val2).GetComponent<PhotonView>().ViewID, NetworkingEvents.RaiseAll, SendOptions.SendReliable); } } } catch (Exception arg) { ValuableSoundTrigger.Logger.LogError((object)$"Error when raising event from PhysGrabObjectImpactDetector : {arg}"); } } } [BepInPlugin("LingeringHopes.ValuableSoundTrigger", "ValuableSoundTrigger", "1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class ValuableSoundTrigger : BaseUnityPlugin { private static ValuableSoundNetwork valuableSoundNetwork; internal static ValuableSoundTrigger Instance { get; private set; } internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } private void Awake() { Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; } private void Start() { InputTriggerManager instance = InputTriggerManager.Instance; instance.LoadValuableSoundTriggerActionFromConfig(((BaseUnityPlugin)this).Config); valuableSoundNetwork = new ValuableSoundNetwork(); valuableSoundNetwork.Initialize(instance); } internal void Patch() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0026: Expected O, but got Unknown if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); } internal void Unpatch() { Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } } }