MP5_plugin/MP5N.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace MP5_plugin;

public class MP5N_Script : ModGunScript
{
	private float slide_forward_speed = -8f;

	private float hammer_accel = -5000f;

	private float m_charging_handle_amount;

	private int fired_bullet_count;

	private float safety_held_time;

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

	private ModHelpEntry help_entry;

	public Sprite help_entry_sprite;

	public override ModHelpEntry GetGunHelpEntry()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0034: Expected O, but got Unknown
		ModHelpEntry val = new ModHelpEntry("HK MP5")
		{
			info_sprite = help_entry_sprite,
			title = "H&K MP5",
			description = "Heckler & Koch MP5-N, HK MP5, MP5A4\nCapacity: 30 + 1, 9x19mm NATO\n\nFollowing the success of the H&K G3 battle rifle, the engineers at Heckler & Koch developed a family of small arms all based around the same G3 base design and delayed blowback operating system. Originally internally known as the HK54, it became known as the MP5 after having been adopted by the German Federal Police in 1966. Later, H&K introduced the MP5A1 model, and with it, the iconic ring front sight and slimline handguard.\n\nIn the 1983, the MP5-N was released, designed specifically for use by the US Navy, and later adopted by other countries. It features a threaded barrel, fixed titanium front sights, and a Navy trigger group with a Safe, Semi, Burst, and Auto fire mode."
		};
		ModHelpEntry result = val;
		help_entry = val;
		return result;
	}

	public override LocaleTactics GetGunTactics()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: 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_0028: Expected O, but got Unknown
		return new LocaleTactics
		{
			gun_internal_name = ((InventoryItem)this).InternalName,
			title = "H&K MP5-N\n",
			text = "A modded SMG, made while listening to Jus†ice on repeat\nA variant of the MP5 made for the United States Navy. Featuring a three fire mode Navy trigger group, including safe, single fire, 2-3 round burst, and fully automatic"
		};
	}

	public override void InitializeGun()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		((GunScript)this).pooled_muzzle_flash = ((GunScript)ReceiverCoreScript.Instance().generic_prefabs.First((InventoryItem it) => it is GunScript && (int)((GunScript)it).gun_model == 4)).pooled_muzzle_flash;
	}

	public override void AwakeGun()
	{
		((SimpleMover)((GunScript)this).hammer).amount = 1f;
		((GunScript)this).firing_modes[0].sound_event_path = ((GunScript)this).sound_safety_on;
		((GunScript)this).firing_modes[1].sound_event_path = ((GunScript)this).sound_safety_off;
		((GunScript)this).firing_modes[2].sound_event_path = ((GunScript)this).sound_safety_off;
		((GunScript)this).firing_modes[3].sound_event_path = ((GunScript)this).sound_safety_off;
		ReceiverEvents.InsertMagazine += (UnityAction<MagazineScript>)OnInsertMagazine;
	}

	private void OnDestroy()
	{
		ReceiverEvents.InsertMagazine -= (UnityAction<MagazineScript>)OnInsertMagazine;
	}

	private void OnInsertMagazine(MagazineScript magazine)
	{
		if (((SimpleMover)((GunScript)this).slide).amount < ((GunScript)this).press_check_amount)
		{
			((GunScript)this).force_wrongly_seated_mag = true;
		}
	}

	public override void EarlyUpdateGun()
	{
		if (((ModGunScript)this).player_input.GetButtonDown(69) && ((GunScript)this).mag_seated_wrong)
		{
			AudioManager.PlayOneShotAttached("event:/MP5N/mp5_weap_bolt_jam2", ((Component)((SimpleMover)((GunScript)this).magazine_catch).transform).gameObject, 3f);
			((GunScript)this).force_wrongly_seated_mag = false;
		}
	}

	public override void UpdateGun()
	{
		if (((SimpleMover)((ModGunScript)this)._select_fire).amount == 0.67f && !((ModGunScript)this)._disconnector_needs_reset)
		{
			((ModGunScript)this)._disconnector_needs_reset = fired_bullet_count >= 3;
		}
		if (((SimpleMover)((GunScript)this).slide).amount > 0f && ((GunScript)this).trigger.amount > 0f && ((SimpleMover)((ModGunScript)this)._select_fire).amount < 0.66f)
		{
			((ModGunScript)this)._disconnector_needs_reset = true;
		}
		((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).trigger.amount == 0f)
		{
			fired_bullet_count = 0;
			((ModGunScript)this)._disconnector_needs_reset = false;
		}
		if (!((GunScript)this).IsSafetyOn())
		{
			if (((ModGunScript)this).player_input.GetButton(67))
			{
				safety_held_time += Time.deltaTime;
			}
			else
			{
				safety_held_time = 0f;
			}
			if (safety_held_time >= 0.4f)
			{
				((GunScript)this).SwitchFireMode();
			}
		}
		else
		{
			safety_held_time = 0f;
		}
		if (((GunScript)this).IsSafetyOn())
		{
			((GunScript)this).trigger.amount = Mathf.Min(((GunScript)this).trigger.amount, 0.1f);
			((GunScript)this).trigger.UpdateDisplay();
		}
		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;
		}
		if (((SimpleMover)((GunScript)this).slide).amount == 0f && ((ModGunScript)this)._hammer_state == 3 && ((GunScript)this).trigger.amount == 1f)
		{
			((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;
			}
		}
		((SimpleMover)((GunScript)this).hammer).TimeStep(Time.deltaTime);
		if (((SimpleMover)((GunScript)this).hammer).amount == 0f && ((ModGunScript)this)._hammer_state == 2)
		{
			((ModGunScript)this).TryFireBullet(1f, (Action<ShellCasingScript>)((GunScript)this).FireBullet);
			((ModGunScript)this)._disconnector_needs_reset = ((SimpleMover)((ModGunScript)this)._select_fire).amount < 0.67f;
			if (((SimpleMover)((ModGunScript)this)._select_fire).amount == 0.67f)
			{
				fired_bullet_count++;
			}
			else
			{
				fired_bullet_count = 0;
			}
			((ModGunScript)this)._hammer_state = 0;
		}
		if (((SimpleMover)((GunScript)this).slide).vel < 0f)
		{
			((SimpleMover)((GunScript)this).slide).vel = Mathf.Max(((SimpleMover)((GunScript)this).slide).vel, slide_forward_speed);
		}
		if (((ModGunScript)this).player_input.GetButton(10) || ((ModGunScript)this).player_input.GetButtonUp(10))
		{
			m_charging_handle_amount = ((SimpleMover)((GunScript)this).slide).amount;
		}
		else
		{
			m_charging_handle_amount = Mathf.Min(m_charging_handle_amount, ((SimpleMover)((GunScript)this).slide).amount);
		}
		((SimpleMover)((GunScript)this).hammer).UpdateDisplay();
		((GunScript)this).ApplyTransform("charging_handle", m_charging_handle_amount, ((SimpleMover)((GunScript)this).slide_stop).transform);
		((GunScript)this).ApplyTransform("magazine_release_button", ((SimpleMover)((GunScript)this).magazine_catch).amount, ((Component)this).transform.Find("magazine_release_button"));
		((GunScript)this).ApplyTransform("extractor_ejector", ((SimpleMover)((GunScript)this).slide).amount, ((Component)this).transform.Find("extractor_ejector"));
		((GunScript)this).trigger.UpdateDisplay();
		((ModGunScript)this).UpdateAnimatedComponents();
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Ciarencew.MP5N", "MP5N Plugin", "2.0.0")]
internal class MainPlugin : BaseUnityPlugin
{
	public static ConfigEntry<int> stock_setting;

	public static readonly string folder_name = "MP5N_Files";

	public static MainPlugin instance { get; private set; }

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"MP5N Main Plugin loaded!");
		stock_setting = ((BaseUnityPlugin)this).Config.Bind<int>("MP5 Setting", "Stock option", 1, "What stock to choose, hmmmmmmmm... so many choices!");
		instance = this;
	}
}