Please disclose if your mod was created primarily 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 ItemMotionSensor v1.0.2
MotionSensorItem.dll
Decompiled a year agousing System; 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 HarmonyLib; using Microsoft.CodeAnalysis; using MotionSensorItem; using Photon.Pun; using UnityEngine; using UnityEngine.Events; [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-CSharp-firstpass")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("Autodesk.Fbx")] [assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")] [assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")] [assembly: IgnoresAccessChecksTo("Klattersynth")] [assembly: IgnoresAccessChecksTo("Photon3Unity3D")] [assembly: IgnoresAccessChecksTo("PhotonChat")] [assembly: IgnoresAccessChecksTo("PhotonRealtime")] [assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")] [assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")] [assembly: IgnoresAccessChecksTo("PhotonVoice.API")] [assembly: IgnoresAccessChecksTo("PhotonVoice")] [assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")] [assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")] [assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")] [assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")] [assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")] [assembly: IgnoresAccessChecksTo("Sirenix.Serialization")] [assembly: IgnoresAccessChecksTo("Sirenix.Utilities")] [assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")] [assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.InputSystem")] [assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")] [assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")] [assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")] [assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")] [assembly: IgnoresAccessChecksTo("Unity.Timeline")] [assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")] [assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")] [assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")] [assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")] [assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")] [assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")] [assembly: IgnoresAccessChecksTo("UnityEngine.UI")] [assembly: IgnoresAccessChecksTo("websocket-sharp")] [assembly: AssemblyCompany("Vee")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+a64c6cbf9cc1fdf97299931c34a80b7fe2b438b2")] [assembly: AssemblyProduct("MotionSensorItem")] [assembly: AssemblyTitle("MotionSensorItem")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.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.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] [Microsoft.CodeAnalysis.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] [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; } } } public class ItemSensor : MonoBehaviour { public enum States { Armed = 0, Triggered = 2 } public Color emissionColor; public UnityEvent onTriggered; public float triggeringTime; private SpringQuaternion triggerSpringQuaternion; private Quaternion triggerTargetRotation; private bool upsideDown; public Transform triggerTransform; private float beepTimer; private ItemSensorTrigger itemSensorTrigger; private ItemEquippable itemEquippable; private ItemAttributes itemAttributes; [Space(20f)] private PhotonView photonView; private PhysGrabObject physGrabObject; public MeshRenderer meshRenderer; public Light lightArmed; [Space(20f)] public Sound soundArmedBeep; public Sound soundTriggereringBeep; private float initialLightIntensity; private bool hasBeenGrabbed; private Vector3 startPosition; private Quaternion startRotation; internal Vector3 triggeredPosition; internal Transform triggeredTransform; internal PhysGrabObject triggeredPhysGrabObject; public bool triggeredByRigidBodies = true; public bool triggeredByEnemies = true; public bool triggeredByPlayers = true; public bool triggeredByForces = true; internal bool wasTriggeredByEnemy; internal bool wasTriggeredByPlayer; internal bool firstLight = true; private bool wasGrabbed; private float targetLineLength = 1f; private Vector3 prevPos = Vector3.zero; private Quaternion prevRot = Quaternion.identity; internal States state; private bool stateStart = true; private PhysGrabObjectImpactDetector impactDetector; private void Start() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0057: 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_00ae: 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_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) triggerSpringQuaternion = new SpringQuaternion(); triggerSpringQuaternion.damping = 0.2f; triggerSpringQuaternion.speed = 10f; itemAttributes = ((Component)this).GetComponent<ItemAttributes>(); physGrabObject = ((Component)this).GetComponent<PhysGrabObject>(); photonView = ((Component)this).GetComponent<PhotonView>(); lightArmed.color = emissionColor; ((Renderer)meshRenderer).material.SetColor("_EmissionColor", emissionColor); initialLightIntensity = lightArmed.intensity; impactDetector = ((Component)this).GetComponent<PhysGrabObjectImpactDetector>(); itemSensorTrigger = ((Component)this).GetComponentInChildren<ItemSensorTrigger>(); startPosition = ((Component)this).transform.position; itemEquippable = ((Component)this).GetComponent<ItemEquippable>(); startRotation = ((Component)this).transform.rotation; } private void ColorSet(Color _color) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) lightArmed.intensity = initialLightIntensity; lightArmed.color = _color; ((Renderer)meshRenderer).material.SetColor("_EmissionColor", _color); } private void StateTriggered() { if (state == States.Armed) { stateStart = true; StateSet(States.Triggered); } global::MotionSensorItem.MotionSensorItem.LogMessage($"[{Time.time}] TRIGGER NOISE"); if (stateStart) { stateStart = false; beepTimer = 1f; if (SemiFunc.IsMultiplayer()) { photonView.RPC("MineBeepRPC", (RpcTarget)0, Array.Empty<object>()); } else { MineBeepRPC(); } } beepTimer -= Time.deltaTime * 4f; if (beepTimer < 0f) { if (SemiFunc.IsMultiplayer()) { photonView.RPC("MineBeepRPC", (RpcTarget)0, Array.Empty<object>()); } else { MineBeepRPC(); } beepTimer = 1f; } if (SemiFunc.IsMasterClientOrSingleplayer()) { StateSet(States.Armed); } } [PunRPC] public void MineBeepRPC() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) global::MotionSensorItem.MotionSensorItem.LogMessage($"[{Time.time}] sensed via rpc"); soundTriggereringBeep.Play(((Component)this).transform.position, 1f, 1f, 1f, 1f); ColorSet(emissionColor); lightArmed.intensity = initialLightIntensity * 8f; lightArmed.intensity = Mathf.Lerp(lightArmed.intensity, initialLightIntensity, Time.deltaTime * 4f); } private void ResetMine() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) hasBeenGrabbed = false; StateSet(States.Armed); if (SemiFunc.IsMasterClientOrSingleplayer()) { Rigidbody component = ((Component)this).GetComponent<Rigidbody>(); if (!component.isKinematic) { component.velocity = Vector3.zero; component.angularVelocity = Vector3.zero; } } } private void AnimateLight() { //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) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) if (lightArmed.intensity > 0f && beepTimer > 0f) { float num = 1f - beepTimer; lightArmed.intensity = Mathf.Lerp(lightArmed.intensity, 0f, num); Color val = Color.Lerp(((Renderer)meshRenderer).material.GetColor("_EmissionColor"), Color.black, num); ((Renderer)meshRenderer).material.SetColor("_EmissionColor", val); } } private void Update() { //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) TriggerRotation(); TriggerScaleFixer(); AnimateLight(); if (physGrabObject.grabbedLocal && !SemiFunc.RunIsShop()) { PhysGrabber.instance.OverrideGrabDistance(1f); } if (physGrabObject.grabbed) { hasBeenGrabbed = true; } if (itemEquippable.isEquipped && SemiFunc.IsMasterClientOrSingleplayer() && hasBeenGrabbed) { StateSet(States.Armed); } if (!SemiFunc.RunIsShop()) { if (SemiFunc.IsMasterClientOrSingleplayer() && wasGrabbed && !physGrabObject.grabbed) { Rigidbody component = ((Component)this).GetComponent<Rigidbody>(); if (!component.isKinematic) { component.velocity *= 0.15f; } } wasGrabbed = physGrabObject.grabbed; } States states = state; States states2 = states; if (states2 == States.Triggered) { StateTriggered(); } } [PunRPC] public void TriggeredRPC() { onTriggered.Invoke(); } private void StateSet(States newState) { if (!SemiFunc.IsMasterClientOrSingleplayer() || newState == state) { return; } if (newState == States.Triggered) { if (SemiFunc.IsMultiplayer()) { photonView.RPC("TriggeredRPC", (RpcTarget)0, Array.Empty<object>()); } else { TriggeredRPC(); } } if (SemiFunc.IsMultiplayer()) { photonView.RPC("StateSetRPC", (RpcTarget)0, new object[1] { (int)newState }); } else { StateSetRPC((int)newState); } } [PunRPC] public void StateSetRPC(int newState) { state = (States)newState; stateStart = true; beepTimer = 0f; } private void TriggerScaleFixer() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_011a: 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_013f: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) if (state != 0) { return; } bool flag = false; if (SemiFunc.FPSImpulse30()) { if (Vector3.Distance(prevPos, ((Component)this).transform.position) > 0.01f) { flag = true; prevPos = ((Component)this).transform.position; } if (Quaternion.Angle(prevRot, ((Component)this).transform.rotation) > 0.01f) { flag = true; prevRot = ((Component)this).transform.rotation; } } if ((!flag && SemiFunc.FPSImpulse1()) || (flag && SemiFunc.FPSImpulse30())) { RaycastHit val = default(RaycastHit); if (Physics.Raycast(triggerTransform.position, triggerTransform.forward, ref val, 1f, LayerMask.GetMask(new string[1] { "Default" }))) { targetLineLength = ((RaycastHit)(ref val)).distance * 0.8f; } else { targetLineLength = 1f; } } triggerTransform.localScale = Mathf.Lerp(triggerTransform.localScale.z, targetLineLength, Time.deltaTime * 8f) * Vector3.one; } private void TriggerRotation() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) upsideDown = true; if (Vector3.Dot(((Component)this).transform.up, Vector3.up) < 0f) { upsideDown = false; } if (upsideDown) { triggerTargetRotation = Quaternion.Euler(-90f, 0f, 0f); } else { triggerTargetRotation = Quaternion.Euler(90f, 0f, 0f); } triggerTransform.localRotation = SemiFunc.SpringQuaternionGet(triggerSpringQuaternion, triggerTargetRotation, -1f); } public void SetTriggered() { if (state == States.Armed) { StateSet(States.Triggered); } } public void SetUntriggered() { ResetMine(); } } public class ItemSensorTrigger : MonoBehaviour { private enum TargetType { None, Enemy } private PhysGrabObject parentPhysGrabObject; private ItemSensor itemSensor; public bool enemyTrigger; private bool targetAcquired; private float visionCheckTimer; private void Start() { parentPhysGrabObject = ((Component)this).GetComponentInParent<PhysGrabObject>(); itemSensor = ((Component)this).GetComponentInParent<ItemSensor>(); if (!SemiFunc.IsMasterClientOrSingleplayer()) { Object.Destroy((Object)(object)this); } } private void OnTriggerEnter(Collider other) { if (Object.op_Implicit((Object)(object)itemSensor) && itemSensor.state == ItemSensor.States.Armed && PassesTriggerChecks(other)) { visionCheckTimer = 0f; global::MotionSensorItem.MotionSensorItem.LogMessage($"[{Time.time}] motion sensor trigger enter called"); OnDetect(other); } } private void OnTriggerStay(Collider other) { if (Object.op_Implicit((Object)(object)itemSensor) && itemSensor.state == ItemSensor.States.Armed && PassesTriggerChecks(other)) { visionCheckTimer += Time.deltaTime; if (visionCheckTimer > 2f) { global::MotionSensorItem.MotionSensorItem.LogMessage($"[{Time.time}] trigger stay called"); visionCheckTimer = 0f; OnDetect(other); } } } private void OnTriggerExit(Collider other) { if (Object.op_Implicit((Object)(object)itemSensor) && itemSensor.state == ItemSensor.States.Triggered) { global::MotionSensorItem.MotionSensorItem.LogMessage($"[{Time.time}] trigger leave called"); itemSensor.SetUntriggered(); } } private bool PassesTriggerChecks(Collider other) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) PhysGrabObject componentInParent = ((Component)other).GetComponentInParent<PhysGrabObject>(); if (enemyTrigger && (!Object.op_Implicit((Object)(object)componentInParent) || !componentInParent.isEnemy)) { return false; } if (Object.op_Implicit((Object)(object)componentInParent) && !componentInParent.isEnemy) { return false; } if (Object.op_Implicit((Object)(object)componentInParent) && !componentInParent.isEnemy && !componentInParent.grabbed) { Vector3 val = componentInParent.rb.velocity; if (((Vector3)(ref val)).magnitude < 0.1f) { val = componentInParent.rb.angularVelocity; if (((Vector3)(ref val)).magnitude < 0.1f) { return false; } } } return true; } private void OnDetect(Collider other) { itemSensor.SetTriggered(); } private bool VisionObstruct(Vector3 start, Vector3 end, PhysGrabObject targetPhysObj) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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) int num = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()); Vector3 val = end - start; Vector3 normalized = ((Vector3)(ref val)).normalized; float num2 = Vector3.Distance(start, end); RaycastHit[] array = Physics.RaycastAll(start, normalized, num2, num); for (int i = 0; i < array.Length; i++) { RaycastHit val2 = array[i]; if (((Component)((RaycastHit)(ref val2)).collider).CompareTag("Wall") || ((Component)((RaycastHit)(ref val2)).collider).CompareTag("Ceiling")) { return true; } } return false; } } namespace MotionSensorItem { [HarmonyPatch(typeof(PlayerController))] internal static class ExamplePlayerControllerPatch { [HarmonyPrefix] [HarmonyPatch("Start")] private static void Start_Prefix(PlayerController __instance) { MotionSensorItem.Logger.LogDebug((object)$"{__instance} Start Prefix"); } [HarmonyPostfix] [HarmonyPatch("Start")] private static void Start_Postfix(PlayerController __instance) { MotionSensorItem.Logger.LogDebug((object)$"{__instance} Start Postfix"); } } [BepInPlugin("Vee.MotionSensorItem", "MotionSensorItem", "1.0.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class MotionSensorItem : BaseUnityPlugin { private ConfigEntry<bool> enableDevLogging; internal static MotionSensorItem Instance { get; private set; } internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } private void Awake() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; enableDevLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Logging", false, new ConfigDescription("Enables developer logging.", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { true, false }), Array.Empty<object>())); Patch(); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } public static void LogMessage(string message) { if (Instance.enableDevLogging.Value) { Logger.LogMessage((object)message); } } 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 Update() { } } }