SR-25_Plugin/SR-25.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using Receiver2;
using Receiver2ModdingKit;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace SR25_plugin
{
	[BepInPlugin("CiarenceW.SR-25", "SR-25", "1.0.0")]
	public class Loader : BaseUnityPlugin
	{
		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin SR-25 is loaded!");
		}
	}
	public class SR25_Script : ModGunScript
	{
		private float hammer_accel = -5000f;

		private float m_charging_handle_amount;

		public Transform dust_cover_component;

		private RotateMover dust_cover = new RotateMover();

		private bool dust_cover_opened;

		private Spring pose_ads_spring = new Spring(0f, 0f, 90f, 1E-06f);

		public Transform pose_backup;

		public Transform pose_scope;

		private Transform pose_ads;

		public GameObject linza;

		public Camera scopeCam;

		private bool player_scoped = true;

		private ReceiverCoreScript RCS;

		private float lastTriggerAmount;

		private readonly float[] slide_push_hammer_curve = new float[4] { 0f, 0f, 0.35f, 1f };

		public override void InitializeGun()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			RCS = ReceiverCoreScript.Instance();
			((GunScript)this).pooled_muzzle_flash = ((GunScript)RCS.generic_prefabs.First((InventoryItem it) => it is GunScript && (int)((GunScript)it).gun_model == 6)).pooled_muzzle_flash;
			((InventoryItem)RCS.GetMagazinePrefab("Ciarencew.SR25", (MagazineClass)0)).glint_renderer.material = ((InventoryItem)RCS.GetMagazinePrefab("wolfire.glock_17", (MagazineClass)1)).glint_renderer.material;
			((InventoryItem)RCS.GetMagazinePrefab("Ciarencew.SR25", (MagazineClass)1)).glint_renderer.material = ((InventoryItem)RCS.GetMagazinePrefab("wolfire.glock_17", (MagazineClass)1)).glint_renderer.material;
		}

		public override void AwakeGun()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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)
			((SimpleMover)((GunScript)this).hammer).amount = 1f;
			((SimpleMover)dust_cover).transform = dust_cover_component;
			pose_ads = ((Component)this).transform.Find("pose_aim_down_sights");
			dust_cover.rotations[0] = ((Component)this).transform.Find("dust_cover_closed").localRotation;
			dust_cover.rotations[1] = ((Component)this).transform.Find("dust_cover_opened").localRotation;
			((Component)scopeCam).gameObject.SetActive(true);
		}

		public override void UpdateGun()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0083: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			pose_ads_spring.Update(Time.deltaTime);
			if ((Object)(object)LocalAimHandler.player_instance != (Object)null)
			{
				((Component)scopeCam).gameObject.GetComponent<Skybox>().material = ((Component)LocalAimHandler.player_instance.main_camera).GetComponent<Skybox>().material;
			}
			pose_ads.localRotation = Quaternion.LerpUnclamped(pose_scope.localRotation, pose_backup.localRotation, pose_ads_spring.state);
			pose_ads.localPosition = Vector3.LerpUnclamped(pose_scope.localPosition, pose_backup.localPosition, pose_ads_spring.state);
			if (LocalAimHandler.player_instance.IsHoldingGun)
			{
				if (((ModGunScript)this).player_input.GetButtonDown(14) && LocalAimHandler.player_instance.IsAiming())
				{
					ToggleActiveSight();
				}
				((Component)scopeCam).gameObject.SetActive(true);
				linza.SetActive(true);
			}
			else
			{
				((Component)scopeCam).gameObject.SetActive(false);
				linza.SetActive(false);
			}
			((SimpleMover)((GunScript)this).hammer).asleep = true;
			((SimpleMover)((GunScript)this).hammer).accel = hammer_accel;
			if (((SimpleMover)((GunScript)this).slide).amount > 0f && ((ModGunScript)this)._hammer_state != 3)
			{
				((SimpleMover)((GunScript)this).hammer).amount = Mathf.Max(((SimpleMover)((GunScript)this).hammer).amount, ModGunScript.InterpCurve(ref slide_push_hammer_curve, ((SimpleMover)((GunScript)this).slide).amount));
			}
			if (((SimpleMover)((GunScript)this).hammer).amount == 1f)
			{
				((ModGunScript)this)._hammer_state = 3;
			}
			if (((GunScript)this).IsSafetyOn())
			{
				((GunScript)this).trigger.amount = Mathf.Min(((GunScript)this).trigger.amount, 0.1f);
				((GunScript)this).trigger.UpdateDisplay();
			}
			if (((SimpleMover)((GunScript)this).hammer).amount == 0f && ((ModGunScript)this)._hammer_state == 2)
			{
				((ModGunScript)this).TryFireBullet(1f, (Action<ShellCasingScript>)((GunScript)this).FireBullet);
				((ModGunScript)this)._hammer_state = 0;
				((ModGunScript)this)._disconnector_needs_reset = true;
			}
			if (((SimpleMover)((GunScript)this).slide).amount > 0f)
			{
				((ModGunScript)this)._disconnector_needs_reset = true;
			}
			if (((GunScript)this).trigger.amount == 0f && ((SimpleMover)((GunScript)this).slide).amount == 0f)
			{
				if (lastTriggerAmount > 0f && ((ModGunScript)this)._disconnector_needs_reset)
				{
					AudioManager.PlayOneShotAttached("event:/guns/sr25/disconnector", ((Component)((GunScript)this).trigger.transform).gameObject);
				}
				((ModGunScript)this)._disconnector_needs_reset = false;
			}
			if (((SimpleMover)((GunScript)this).slide_stop).amount == 1f)
			{
				((SimpleMover)((GunScript)this).slide_stop).asleep = true;
			}
			if (((SimpleMover)((GunScript)this).slide).amount == 0f && ((ModGunScript)this)._hammer_state == 3 && !((ModGunScript)this)._disconnector_needs_reset)
			{
				((SimpleMover)((GunScript)this).hammer).amount = Mathf.MoveTowards(((SimpleMover)((GunScript)this).hammer).amount, ((ModGunScript)this)._hammer_cocked_val, Time.deltaTime * Time.timeScale * 50f);
				if (((SimpleMover)((GunScript)this).hammer).amount == ((ModGunScript)this)._hammer_cocked_val)
				{
					((ModGunScript)this)._hammer_state = 2;
				}
			}
			if (((ModGunScript)this)._hammer_state != 3 && ((((GunScript)this).trigger.amount == 1f && !((ModGunScript)this)._disconnector_needs_reset && ((SimpleMover)((GunScript)this).slide).amount == 0f) || ((SimpleMover)((GunScript)this).hammer).amount != ((ModGunScript)this)._hammer_cocked_val))
			{
				((SimpleMover)((GunScript)this).hammer).asleep = false;
			}
			((SimpleMover)((GunScript)this).hammer).TimeStep(Time.deltaTime);
			if (((ModGunScript)this).player_input.GetButton(10) || ((ModGunScript)this).player_input.GetButtonUp(10))
			{
				m_charging_handle_amount = Mathf.MoveTowards(m_charging_handle_amount, ((SimpleMover)((GunScript)this).slide).amount, Time.deltaTime * 20f / Time.timeScale);
			}
			else
			{
				m_charging_handle_amount = Mathf.MoveTowards(m_charging_handle_amount, 0f, Time.deltaTime * 50f);
			}
			((GunScript)this).ApplyTransform("charging_handle", m_charging_handle_amount, ((Component)this).transform.Find("charging_handle"));
			((GunScript)this).ApplyTransform("charging_handle_latch", m_charging_handle_amount, ((Component)this).transform.Find("charging_handle/charging_handle_latch"));
			if ((!LocalAimHandler.player_instance.IsAiming() && ((ModGunScript)this).player_input.GetButtonDown(14)) || (!dust_cover_opened && ((SimpleMover)((GunScript)this).slide).amount > 0.03f))
			{
				ToggleDustCover();
			}
			((SimpleMover)dust_cover).UpdateDisplay();
			((SimpleMover)dust_cover).TimeStep(Time.deltaTime);
			((SimpleMover)((GunScript)this).hammer).UpdateDisplay();
			((SimpleMover)((GunScript)this).slide_stop).UpdateDisplay();
			((ModGunScript)this).UpdateAnimatedComponents();
			lastTriggerAmount = ((GunScript)this).trigger.amount;
		}

		private void ToggleActiveSight()
		{
			if (player_scoped)
			{
				AudioManager.PlayOneShotAttached("event:/guns/sr25/raise", ((Component)((Component)this).transform).gameObject);
				pose_ads_spring.target_state = 1f;
				player_scoped = false;
			}
			else
			{
				AudioManager.PlayOneShotAttached("event:/guns/sr25/lower", ((Component)((Component)this).transform).gameObject);
				pose_ads_spring.target_state = 0f;
				player_scoped = true;
			}
		}

		private void ToggleDustCover()
		{
			((SimpleMover)dust_cover).asleep = false;
			if (((SimpleMover)dust_cover).target_amount == 1f && ((SimpleMover)((GunScript)this).slide).amount <= 0.03f)
			{
				((SimpleMover)dust_cover).target_amount = 0f;
				((SimpleMover)dust_cover).accel = -1f;
				((SimpleMover)dust_cover).vel = -10f;
				AudioManager.PlayOneShotAttached(((GunScript)this).sound_cylinder_close, ((Component)((SimpleMover)dust_cover).transform).gameObject);
				dust_cover_opened = false;
			}
			else if (!dust_cover_opened)
			{
				((SimpleMover)dust_cover).target_amount = 1f;
				((SimpleMover)dust_cover).accel = 1f;
				((SimpleMover)dust_cover).vel = 10f;
				AudioManager.PlayOneShotAttached(((GunScript)this).sound_cylinder_open, ((Component)((SimpleMover)dust_cover).transform).gameObject);
				dust_cover_opened = true;
			}
		}
	}
}
namespace SR25BankList.FMODConsts
{
	public static class FMODConsts
	{
		public const string guns_sr25_shot = "event:/guns/sr25/shot";

		public const string guns_sr25_insert_mag = "event:/guns/sr25/insert_mag";

		public const string guns_sr25_dry_fire = "event:/guns/sr25/dry_fire";

		public const string guns_sr25_dust_cover_close = "event:/guns/sr25/dust_cover_close";

		public const string guns_sr25_disconnector = "event:/guns/sr25/disconnector";

		public const string guns_sr25_trigger_release = "event:/guns/sr25/trigger_release";

		public const string guns_sr25_lower = "event:/guns/sr25/lower";

		public const string guns_sr25_dust_cover_open = "event:/guns/sr25/dust_cover_open";

		public const string guns_sr25_eject_mag = "event:/guns/sr25/eject_mag";

		public const string guns_sr25_safety_off = "event:/guns/sr25/safety_off";

		public const string guns_sr25_slide_released = "event:/guns/sr25/slide_released";

		public const string guns_sr25_safety_on = "event:/guns/sr25/safety_on";

		public const string guns_sr25_trigger_pull = "event:/guns/sr25/trigger_pull";

		public const string guns_sr25_press_check_start = "event:/guns/sr25/press_check_start";

		public const string guns_sr25_slide_back_partial = "event:/guns/sr25/slide_back_partial";

		public const string guns_sr25_slide_back = "event:/guns/sr25/slide_back";

		public const string guns_sr25_press_check_end = "event:/guns/sr25/press_check_end";

		public const string guns_sr25_start_insert_mag = "event:/guns/sr25/start_insert_mag";

		public const string guns_sr25_raise = "event:/guns/sr25/raise";
	}
}