Decompiled source of ModulBullpupAR v1.1.0

ModulBullpupAR.dll

Decompiled 2 weeks ago
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OpenScripts2;
using OtherLoader;
using Sodalite.Api;
using UnityEngine;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class SuppressorAddSound : Suppressor
{
	public bool PlaysTail = true;

	public AudioEvent AudEvent_SoundToPlay;

	public override void OnShot(FVRFireArm f, FVRTailSoundClass tailClass)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		FVRFirearmAudioSet audioClipSet = f.AudioClipSet;
		if (PlaysTail)
		{
			f.PlayShotTail((FVRTailSoundClass)11, (FVRSoundEnvironment)12, 1f);
			int playerIFF = GM.CurrentPlayerBody.GetPlayerIFF();
			GM.CurrentSceneSettings.OnPerceiveableSound(200f, 80f, ((Component)this).transform.position, playerIFF, GM.CurrentPlayerBody.PlayerEntities[0]);
		}
		else
		{
			f.PlayAudioAsHandling(AudEvent_SoundToPlay, ((Component)this).transform.position);
		}
		((MuzzleDevice)this).OnShot(f, tailClass);
	}

	public override void OnShot(AttachableFirearm f, FVRTailSoundClass tailClass)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		FVRFirearmAudioSet audioClipSet = f.AudioClipSet;
		if (PlaysTail)
		{
			f.PlayShotTail((FVRTailSoundClass)11, (FVRSoundEnvironment)12, 1f);
			int playerIFF = GM.CurrentPlayerBody.GetPlayerIFF();
			GM.CurrentSceneSettings.OnPerceiveableSound(200f, 80f, ((Component)this).transform.position, playerIFF, GM.CurrentPlayerBody.PlayerEntities[0]);
		}
		else
		{
			f.PlayAudioAsHandling(AudEvent_SoundToPlay, ((Component)this).transform.position);
		}
		((MuzzleDevice)this).OnShot(f, tailClass);
	}

	[ContextMenu("Copy Suppressor")]
	public void CopySuppressor()
	{
		Suppressor[] components = ((Component)this).GetComponents<Suppressor>();
		Suppressor val = components.Single((Suppressor c) => (Object)(object)c != (Object)(object)this);
		foreach (FVRFireArmAttachmentMount attachmentMount in ((FVRPhysicalObject)val).AttachmentMounts)
		{
			attachmentMount.MyObject = (FVRPhysicalObject)(object)this;
			attachmentMount.Parent = (FVRPhysicalObject)(object)this;
		}
		((FVRFireArmAttachment)val).AttachmentInterface.Attachment = (FVRFireArmAttachment)(object)this;
		((FVRFireArmAttachment)val).Sensor.Attachment = (FVRFireArmAttachment)(object)this;
		UniversalCopy.CopyComponent<Suppressor>((Component)(object)this, val);
	}
}
public class MuzzleDeviceParentMonitor : MuzzleDevice
{
	public bool DisableParentBehavior = true;

	private FVRFireArmAttachmentMount monitoredAttachmentMount;

	public override void Start()
	{
		((FVRInteractiveObject)this).Start();
		FindAttachmentMount();
	}

	private void Update()
	{
		if (DisableParentBehavior)
		{
			if ((Object)(object)monitoredAttachmentMount == (Object)null)
			{
				FindAttachmentMount();
			}
			if ((Object)(object)monitoredAttachmentMount != (Object)null && monitoredAttachmentMount.ParentToThis)
			{
				KeepObjectInPlaceWhileParented();
			}
		}
	}

	private void FindAttachmentMount()
	{
		monitoredAttachmentMount = ((Component)this).GetComponentInParent<FVRFireArmAttachmentMount>();
	}

	private void KeepObjectInPlaceWhileParented()
	{
		//IL_0019: 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_002a: 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_0049: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)monitoredAttachmentMount != (Object)null)
		{
			Vector3 position = ((Component)this).transform.position;
			Quaternion rotation = ((Component)this).transform.rotation;
			monitoredAttachmentMount.ParentToThis = false;
			((Component)this).transform.position = position;
			((Component)this).transform.rotation = rotation;
		}
	}
}
public class LeverActionDustCover : FVRInteractiveObject
{
	public LeverActionFirearm LeverAction;

	public Transform DustCoverGeo;

	public float OpenRot;

	public float ClosedRot;

	public float RotSpeed = 360f;

	public AudioEvent AudEvent_CoverOpen;

	public AudioEvent AudEvent_CoverClose;

	private bool m_isOpen;

	private float m_curRot;

	private float m_tarRot;

	public override void Awake()
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).Awake();
		m_curRot = ClosedRot;
		m_tarRot = ClosedRot;
		m_isOpen = false;
		if ((Object)(object)DustCoverGeo != (Object)null)
		{
			DustCoverGeo.localEulerAngles = new Vector3(0f, 0f, ClosedRot);
		}
	}

	public override void SimpleInteraction(FVRViveHand hand)
	{
		((FVRInteractiveObject)this).SimpleInteraction(hand);
		ToggleDustCoverState();
	}

	private void ToggleDustCoverState()
	{
		if (m_isOpen)
		{
			Close();
		}
		else
		{
			Open();
		}
	}

	public override void FVRUpdate()
	{
		//IL_0029: 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)
		((FVRInteractiveObject)this).FVRUpdate();
		if (!m_isOpen && (Object)(object)LeverAction != (Object)null && (int)LeverAction.m_curLeverPos != 0)
		{
			Open();
		}
		if (Mathf.Abs(m_tarRot - m_curRot) > 0.01f)
		{
			m_curRot = Mathf.MoveTowards(m_curRot, m_tarRot, Time.deltaTime * RotSpeed);
			if ((Object)(object)DustCoverGeo != (Object)null)
			{
				DustCoverGeo.localEulerAngles = new Vector3(0f, 0f, m_curRot);
			}
		}
	}

	private void Open()
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		if (!m_isOpen)
		{
			m_isOpen = true;
			m_tarRot = OpenRot;
			RotSpeed = 1900f;
			if (AudEvent_CoverOpen != null && AudEvent_CoverOpen.Clips.Count > 0)
			{
				AudioSource.PlayClipAtPoint(AudEvent_CoverOpen.Clips[0], ((Component)this).transform.position, AudEvent_CoverOpen.VolumeRange.x);
			}
		}
	}

	private void Close()
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		if (m_isOpen)
		{
			m_isOpen = false;
			m_tarRot = ClosedRot;
			RotSpeed = 800f;
			if (AudEvent_CoverClose != null && AudEvent_CoverClose.Clips.Count > 0)
			{
				AudioSource.PlayClipAtPoint(AudEvent_CoverClose.Clips[0], ((Component)this).transform.position, AudEvent_CoverClose.VolumeRange.x);
			}
		}
	}
}
public class LeverActionMagRelease : FVRInteractiveObject
{
	public LeverActionFirearm LeverActionWeapon;

	public Transform MagazineReleaseButton;

	public Vector3 MagReleaseUnpressed = Vector3.zero;

	public Vector3 MagReleasePressed = new Vector3(0f, -5f, 0f);

	public InterpStyle MagReleaseInterp = (InterpStyle)0;

	private bool isHeldDown = false;

	public override void SimpleInteraction(FVRViveHand hand)
	{
		TryReleaseMag(hand);
	}

	public override void UpdateInteraction(FVRViveHand hand)
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: 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_00de: Unknown result type (might be due to invalid IL or missing references)
		((FVRInteractiveObject)this).UpdateInteraction(hand);
		bool flag = hand.Input.TriggerDown || hand.Input.TouchpadDown || hand.Input.AXButtonDown;
		bool flag2 = hand.Input.TriggerPressed || hand.Input.TouchpadPressed || hand.Input.AXButtonPressed;
		if (flag)
		{
			TryReleaseMag(hand);
		}
		if ((Object)(object)MagazineReleaseButton != (Object)null)
		{
			if (flag2 && !isHeldDown)
			{
				SetAnimatedComponent(MagazineReleaseButton, MagReleasePressed, MagReleaseInterp);
				isHeldDown = true;
			}
			else if (!flag2 && isHeldDown)
			{
				SetAnimatedComponent(MagazineReleaseButton, MagReleaseUnpressed, MagReleaseInterp);
				isHeldDown = false;
			}
		}
	}

	private void TryReleaseMag(FVRViveHand hand)
	{
		if ((Object)(object)LeverActionWeapon != (Object)null && (Object)(object)((FVRFireArm)LeverActionWeapon).Magazine != (Object)null)
		{
			FVRFireArmMagazine magazine = ((FVRFireArm)LeverActionWeapon).Magazine;
			((FVRFireArm)LeverActionWeapon).EjectMag(false);
			if ((Object)(object)hand != (Object)null)
			{
				hand.ForceSetInteractable((FVRInteractiveObject)(object)magazine);
				((FVRInteractiveObject)magazine).BeginInteraction(hand);
			}
		}
	}

	private void SetAnimatedComponent(Transform t, Vector3 value, InterpStyle interp)
	{
		//IL_0001: 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_0015: Invalid comparison between Unknown and I4
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		if ((int)interp == 0)
		{
			t.localPosition = value;
		}
		else if ((int)interp == 1)
		{
			t.localEulerAngles = value;
		}
	}
}
namespace Volks.ModulBullpupAR;

[BepInPlugin("Volks.ModulBullpupAR", "ModulBullpupAR", "1.1.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
[BepInDependency("h3vr.cityrobo.ModularWorkshopManager", "1.0.0")]
[BepInDependency("nrgill28.Sodalite", "1.4.2")]
public class ModulBullpupARPlugin : BaseUnityPlugin
{
	private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	internal static ManualLogSource Logger;

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		LoadAssets();
	}

	private void LoadAssets()
	{
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Volks.ModulBullpupAR");
		OtherLoader.RegisterDirectLoad(BasePath, "Volks.ModulBullpupAR", "", "", "modulbullpupar", "");
		GameAPI.PreloadAllAssets(Path.Combine(BasePath, "mw_modulbullpupar"));
	}
}
public class FVRTorch : FVRPhysicalObject
{
	public GameObject FireGO;

	public GameObject LinkedObject;

	public AudioSource fireAud;

	public float BurnDuration = 120f;

	public float DestructionDelay = 5f;

	private bool m_isBurning = false;

	private bool m_hasBeenLit = false;

	private bool m_canDestroy = false;

	private float m_burnTimer;

	private float m_unheldTimer;

	public override void Awake()
	{
		((FVRPhysicalObject)this).Awake();
		if ((Object)(object)FireGO != (Object)null)
		{
			fireAud = FireGO.GetComponent<AudioSource>();
			FireGO.SetActive(false);
		}
		if ((Object)(object)LinkedObject != (Object)null)
		{
			LinkedObject.SetActive(false);
		}
	}

	public override void FVRUpdate()
	{
		((FVRPhysicalObject)this).FVRUpdate();
		if (m_isBurning)
		{
			m_burnTimer -= Time.deltaTime;
			if ((Object)(object)fireAud != (Object)null)
			{
				fireAud.volume = Mathf.Lerp(fireAud.volume, 0f, Time.deltaTime / BurnDuration);
			}
			if (m_burnTimer <= 0f)
			{
				StopBurning();
			}
		}
		if (m_canDestroy && !((FVRInteractiveObject)this).IsHeld)
		{
			m_unheldTimer -= Time.deltaTime;
			if (m_unheldTimer <= 0f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
		else if (((FVRInteractiveObject)this).IsHeld)
		{
			m_unheldTimer = DestructionDelay;
		}
	}

	public void Ignite()
	{
		if (!m_hasBeenLit)
		{
			m_hasBeenLit = true;
			m_isBurning = true;
			m_burnTimer = BurnDuration;
			if ((Object)(object)FireGO != (Object)null)
			{
				FireGO.SetActive(true);
			}
			if ((Object)(object)fireAud != (Object)null)
			{
				fireAud.Play();
			}
			if ((Object)(object)LinkedObject != (Object)null)
			{
				LinkedObject.SetActive(true);
			}
		}
	}

	private void StopBurning()
	{
		m_isBurning = false;
		m_canDestroy = true;
		if ((Object)(object)FireGO != (Object)null)
		{
			FireGO.SetActive(false);
		}
		if ((Object)(object)fireAud != (Object)null)
		{
			fireAud.Stop();
		}
		Debug.Log((object)"Torch fire has died out.");
	}

	private void OnCollisionEnter(Collision col)
	{
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Expected O, but got Unknown
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		if (m_hasBeenLit && m_isBurning && (Object)(object)col.collider.attachedRigidbody != (Object)null)
		{
			IFVRDamageable val = ((Component)col.collider).GetComponent<IFVRDamageable>() ?? ((Component)col.collider.attachedRigidbody).GetComponent<IFVRDamageable>();
			if (val != null)
			{
				Damage val2 = new Damage();
				val2.Dam_Thermal = 50f;
				val2.Dam_TotalEnergetic = 50f;
				val2.point = ((ContactPoint)(ref col.contacts[0])).point;
				val2.hitNormal = ((ContactPoint)(ref col.contacts[0])).normal;
				val2.strikeDir = ((Component)this).transform.forward;
				val.Damage(val2);
			}
		}
	}
}
public class TorchTrigger : MonoBehaviour
{
	public FVRTorch Torch;

	public Collider collider;

	private void OnTriggerEnter(Collider col)
	{
		collider.enabled = false;
		((Component)collider).gameObject.layer = LayerMask.NameToLayer("NoCol");
		Torch.Ignite();
	}
}