Decompiled source of CanikMC9L v1.0.0

CanikMC9L.dll

Decompiled 12 hours ago
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
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 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 ForeMagRelease : UniversalAdvancedMagazineGrabTrigger
{
	[Header("ForeMagRelease Config")]
	public bool EjectMainMagOnSecondaryRelease = true;

	private bool wasSecondaryMagPresent = true;

	public override void UpdateInteraction(FVRViveHand hand)
	{
		((UniversalAdvancedMagazineGrabTrigger)this).UpdateInteraction(hand);
		if (base.IsSecondarySlotGrab)
		{
			FVRFireArmMagazine magazine = base.FireArm.SecondaryMagazineSlots[base.SecondaryGrabSlot].Magazine;
			if (wasSecondaryMagPresent && (Object)(object)magazine == (Object)null && EjectMainMagOnSecondaryRelease && (Object)(object)base.FireArm.Magazine != (Object)null)
			{
				base.FireArm.EjectMag(false);
			}
			wasSecondaryMagPresent = (Object)(object)magazine != (Object)null;
		}
		else
		{
			wasSecondaryMagPresent = true;
		}
	}
}
public class AmmoRecoilBlast : MonoBehaviour
{
	public BallisticProjectile Projectile;

	[Header("Recoil Settings")]
	public float RecoilForce = 3.5f;

	public bool UseHeadDirection = true;

	private bool _hasBlasted = false;

	private void Start()
	{
		if ((Object)(object)Projectile == (Object)null)
		{
			Projectile = ((Component)this).GetComponent<BallisticProjectile>();
		}
		((MonoBehaviour)this).StartCoroutine(WaitAndApplyRecoil());
	}

	private IEnumerator WaitAndApplyRecoil()
	{
		while ((Object)(object)Projectile != (Object)null && !Projectile.IsMoving())
		{
			yield return null;
		}
		ApplyRecoil();
	}

	private void ApplyRecoil()
	{
		//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_0052: 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_00ab: 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_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		if (_hasBlasted)
		{
			return;
		}
		_hasBlasted = true;
		if (!((Object)(object)GM.CurrentMovementManager == (Object)null) && !((Object)(object)GM.CurrentPlayerBody == (Object)null))
		{
			Vector3 val = ((!UseHeadDirection) ? ((Component)GM.CurrentPlayerBody).transform.forward : GM.CurrentPlayerBody.Head.forward);
			val.y = 0f;
			((Vector3)(ref val)).Normalize();
			if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
			{
				val = -((Component)GM.CurrentPlayerBody).transform.forward;
			}
			GM.CurrentMovementManager.Blast(-val, RecoilForce, true);
		}
	}
}
public class SAFA_BoltController : MonoBehaviour
{
	private enum BoltState
	{
		semiAuto,
		fullAuto,
		safe,
		uncocked
	}

	public OpenBoltReceiver weapon;

	public int semiAuto;

	public int fullAuto;

	public Transform closedBoltSearPosition;

	private OpenBoltReceiverBolt bolt;

	private Transform sear;

	private Vector3 uncockedPos;

	private Transform openBoltSearPosition;

	private string lastMessage = "";

	private bool waitForShot;

	private BoltState boltState;

	public void Start()
	{
		//IL_0039: 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)
		bolt = weapon.Bolt;
		sear = weapon.Bolt.Point_Bolt_LockPoint;
		uncockedPos = weapon.Bolt.Point_Bolt_Forward.localPosition;
		openBoltSearPosition = sear;
	}

	public void Update()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: 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_006d: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
		if (((Component)bolt).transform.localPosition == uncockedPos)
		{
			boltState = BoltState.uncocked;
		}
		else if (((Component)bolt).transform.localPosition == openBoltSearPosition.localPosition)
		{
			boltState = BoltState.fullAuto;
		}
		else if (((Component)bolt).transform.localPosition == closedBoltSearPosition.localPosition)
		{
			boltState = BoltState.semiAuto;
		}
		if (boltState == BoltState.uncocked && weapon.m_fireSelectorMode == fullAuto)
		{
			bolt.m_boltZ_lock = openBoltSearPosition.localPosition.z;
		}
		else if (boltState == BoltState.uncocked && weapon.m_fireSelectorMode == semiAuto)
		{
			bolt.m_boltZ_lock = closedBoltSearPosition.localPosition.z;
		}
		else if (boltState == BoltState.semiAuto && weapon.m_fireSelectorMode == fullAuto)
		{
			waitForShot = true;
		}
		else if (boltState == BoltState.fullAuto && weapon.m_fireSelectorMode == semiAuto)
		{
			bolt.m_boltZ_lock = closedBoltSearPosition.localPosition.z;
			bolt.LastPos = (BoltPos)4;
			bolt.CurPos = (BoltPos)3;
		}
		if (waitForShot && (int)bolt.LastPos == 0)
		{
			bolt.m_boltZ_lock = openBoltSearPosition.localPosition.z;
			waitForShot = false;
		}
	}

	public void DebugOnce(string message)
	{
		if (message != lastMessage)
		{
			Debug.Log((object)message);
		}
		lastMessage = message;
	}
}
namespace Volks.CanikMC9L;

[BepInPlugin("Volks.CanikMC9L", "CanikMC9L", "1.0.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class CanikMC9LPlugin : 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.CanikMC9L");
		OtherLoader.RegisterDirectLoad(BasePath, "Volks.CanikMC9L", "", "", "canik_mc9l", "");
	}
}
public class AttachableHammerFirearm : AttachableFirearm
{
	[Header("Hammer Params")]
	public Transform Hammer;

	public bool HasVisibleHammer = true;

	public bool CanCockHammer = true;

	public Axis HammerAxis;

	public InterpStyle HammerInterp = (InterpStyle)1;

	public float HammerMinRot;

	public float HammerMaxRot = -70f;

	[Header("Trigger Params")]
	public Transform Trigger;

	public Vector2 TriggerForwardBackRots;

	[Header("Chamber")]
	public FVRFireArmChamber Chamber;

	private bool m_isHammerCocked;

	private bool m_isTriggerReset = true;

	public void CockHammer()
	{
		//IL_003f: 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)
		if (!m_isHammerCocked && CanCockHammer)
		{
			m_isHammerCocked = true;
			if ((Object)(object)Hammer != (Object)null)
			{
				SetAnimatedComponent(Hammer, HammerMaxRot, HammerInterp, HammerAxis);
			}
		}
	}

	public void SetHammerCocked(bool cocked)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		m_isHammerCocked = cocked;
		if ((Object)(object)Hammer != (Object)null)
		{
			float rot = ((!cocked) ? HammerMinRot : HammerMaxRot);
			SetAnimatedComponent(Hammer, rot, HammerInterp, HammerAxis);
		}
	}

	public override void ProcessInput(FVRViveHand hand, bool fromInterface, FVRInteractiveObject o)
	{
		//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_005f: Unknown result type (might be due to invalid IL or missing references)
		((AttachableFirearm)this).ProcessInput(hand, fromInterface, o);
		if ((Object)(object)Trigger != (Object)null)
		{
			float triggerFloat = hand.Input.TriggerFloat;
			float x = Mathf.Lerp(TriggerForwardBackRots.x, TriggerForwardBackRots.y, triggerFloat);
			Vector3 localEulerAngles = Trigger.localEulerAngles;
			localEulerAngles.x = x;
			Trigger.localEulerAngles = localEulerAngles;
		}
		if (CanCockHammer)
		{
			if (hand.IsInStreamlinedMode)
			{
				if (hand.Input.AXButtonDown)
				{
					CockHammer();
				}
			}
			else if (hand.Input.TouchpadDown)
			{
				CockHammer();
			}
		}
		if (m_isHammerCocked && hand.Input.TriggerFloat > 0.7f && m_isTriggerReset)
		{
			m_isTriggerReset = false;
			SetHammerCocked(cocked: false);
			if ((Object)(object)Chamber != (Object)null && Chamber.IsFull && !Chamber.IsSpent)
			{
				((AttachableFirearm)this).Fire(Chamber, ((AttachableFirearm)this).GetMuzzle(), true, (FVRFireArm)null, 1f);
				((AttachableFirearm)this).FireMuzzleSmoke();
				((AttachableFirearm)this).PlayAudioEvent((FirearmAudioEventType)6, 1f);
				Chamber.SetRound((FVRFireArmRound)null, false);
				Chamber.UpdateProxyDisplay();
			}
			else
			{
				((AttachableFirearm)this).PlayAudioEvent((FirearmAudioEventType)16, 1f);
			}
		}
		else if (hand.Input.TriggerFloat < 0.2f && !m_isTriggerReset)
		{
			m_isTriggerReset = true;
		}
	}

	protected void SetAnimatedComponent(Transform t, float rot, InterpStyle interp, Axis axis)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Invalid comparison between Unknown and I4
		//IL_005d: 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_002b: Invalid comparison between Unknown and I4
		if ((Object)(object)t == (Object)null)
		{
			return;
		}
		Vector3 localEulerAngles = t.localEulerAngles;
		if ((int)axis != 0)
		{
			if ((int)axis != 1)
			{
				if ((int)axis == 2)
				{
					localEulerAngles.z = rot;
				}
			}
			else
			{
				localEulerAngles.y = rot;
			}
		}
		else
		{
			localEulerAngles.x = rot;
		}
		t.localEulerAngles = localEulerAngles;
	}
}