Decompiled source of Hipower v1.0.2

Hipower_Plugin/Hipower.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
public class HiPowerScript : ModGunScript
{
	private readonly float[] slide_push_hammer_curve = new float[4] { 0.03f, 0f, 0.05f, 1f };

	private bool decocking;

	private bool hammer_rest;

	private RotateMover hp_sear;

	private float hp_sear_cocked;

	private float hp_sear_halfcocked;

	private float hp_sear_uncocked;

	private float hp_sear_almost_cocked;

	private float hp_sear_hammer_back;

	public override void InitializeGun()
	{
		//IL_00a3: 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)
		if ((Object)(object)((GunScript)this).loaded_cartridge_prefab != (Object)null)
		{
			ShellCasingScript component = ((GunScript)this).loaded_cartridge_prefab.GetComponent<ShellCasingScript>();
			if ((Object)(object)component != (Object)null)
			{
				ShellCasingScript val2;
				component.ammo_box_prefab = ((ShellCasingScript)ReceiverCoreScript.Instance().generic_prefabs.First((InventoryItem item) => (val2 = (ShellCasingScript)(object)((item is ShellCasingScript) ? item : null)) != null && (int)val2.cartridge_type == 0 && ((Object)val2).name != "load_progression")).ammo_box_prefab;
			}
		}
		if ((Object)(object)((GunScript)this).pooled_muzzle_flash.object_prefab == (Object)null)
		{
			GunScript val;
			((GunScript)this).pooled_muzzle_flash = ((GunScript)ReceiverCoreScript.Instance().generic_prefabs.First((InventoryItem item) => (val = (GunScript)(object)((item is GunScript) ? item : null)) != null && (int)val.gun_model == 1)).pooled_muzzle_flash;
		}
	}

	public override void AwakeGun()
	{
		((SimpleMover)((GunScript)this).hammer).amount = 1f;
		hp_sear = AccessTools.FieldRefAccess<GunScript, RotateMover>((GunScript)(object)this, "sear");
		hp_sear_cocked = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_cocked");
		hp_sear_halfcocked = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_halfcocked");
		hp_sear_uncocked = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_uncocked");
		hp_sear_almost_cocked = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_almost_cocked");
		hp_sear_hammer_back = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_hammer_back");
	}

	private void UpdateManualSafetyVisual()
	{
		if (!((Object)(object)((SimpleMover)((GunScript)this).safety).transform == (Object)null))
		{
			((SimpleMover)((GunScript)this).safety).amount = Mathf.MoveTowards(((SimpleMover)((GunScript)this).safety).amount, ((SimpleMover)((GunScript)this).safety).target_amount, Time.deltaTime * 10f);
			((SimpleMover)((GunScript)this).safety).UpdateDisplay();
		}
	}

	public override void UpdateGun()
	{
		UpdateManualSafetyVisual();
		if ((Object)(object)LocalAimHandler.player_instance != (Object)null && !LocalAimHandler.player_instance.PullingTrigger)
		{
			((GunScript)this).trigger.target_amount = 0f;
			((GunScript)this).trigger.amount = Mathf.MoveTowards(((GunScript)this).trigger.amount, 0f, Time.deltaTime * 8f);
		}
		if (((ModGunScript)this).player_input.GetButton(14) && ((ModGunScript)this).player_input.GetButtonDown(2) && ((SimpleMover)((GunScript)this).slide).amount == 0f)
		{
			decocking = true;
		}
		((SimpleMover)((GunScript)this).hammer).asleep = false;
		if (decocking)
		{
			if (!((ModGunScript)this).player_input.GetButton(14))
			{
				((SimpleMover)((GunScript)this).hammer).amount = Mathf.MoveTowards(((SimpleMover)((GunScript)this).hammer).amount, 0f, Time.deltaTime * 5f);
			}
			if (((SimpleMover)((GunScript)this).hammer).amount <= 0.001f || !((ModGunScript)this).player_input.GetButton(2))
			{
				((ModGunScript)this)._hammer_state = 0;
				decocking = false;
				if (((SimpleMover)((GunScript)this).hammer).amount <= 0.001f)
				{
					((SimpleMover)((GunScript)this).hammer).amount = 0f;
					((SimpleMover)((GunScript)this).hammer).UpdateDisplay();
					AudioManager.PlayOneShotAttached(((GunScript)this).sound_decock, ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject, 0.3f);
				}
			}
		}
		if (!decocking)
		{
			if (((ModGunScript)this)._hammer_state == 0 && ((SimpleMover)((GunScript)this).hammer).amount >= ((ModGunScript)this)._hammer_halfcocked)
			{
				((ModGunScript)this)._hammer_state = 1;
				if (!((SimpleMover)((GunScript)this).hammer).asleep)
				{
					((SimpleMover)((GunScript)this).hammer).target_amount = ((ModGunScript)this)._hammer_halfcocked;
				}
				if ((Object)(object)LocalAimHandler.player_instance == (Object)null || !LocalAimHandler.player_instance.PullingTrigger)
				{
					AudioManager.PlayOneShotAttached("event:/guns/1911/1911_half_cock", ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject);
				}
			}
			if (((ModGunScript)this)._hammer_state == 1 && ((SimpleMover)((GunScript)this).hammer).amount >= ((ModGunScript)this)._hammer_cocked_val)
			{
				((ModGunScript)this)._hammer_state = 2;
				if (!((SimpleMover)((GunScript)this).hammer).asleep)
				{
					((SimpleMover)((GunScript)this).hammer).target_amount = ((ModGunScript)this)._hammer_cocked_val;
				}
				if ((Object)(object)LocalAimHandler.player_instance == (Object)null || !LocalAimHandler.player_instance.PullingTrigger)
				{
					AudioManager.PlayOneShotAttached("event:/guns/1911/1911_full_cock", ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject);
				}
			}
			if (((GunScript)this).trigger.amount == 0f && !((ModGunScript)this).player_input.GetButton(14))
			{
				if (((ModGunScript)this)._hammer_state == 1)
				{
					((SimpleMover)((GunScript)this).hammer).target_amount = ((ModGunScript)this)._hammer_halfcocked;
					if (!hammer_rest)
					{
						AudioManager.PlayOneShotAttached("event:/guns/1911/1911_hammer_rest", ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject);
					}
				}
				if (((ModGunScript)this)._hammer_state == 2)
				{
					((SimpleMover)((GunScript)this).hammer).target_amount = ((ModGunScript)this)._hammer_cocked_val;
					if (!hammer_rest)
					{
						AudioManager.PlayOneShotAttached("event:/guns/1911/1911_hammer_rest", ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject);
					}
				}
				hammer_rest = true;
			}
			else
			{
				hammer_rest = false;
			}
		}
		((SimpleMover)((GunScript)this).hammer).TimeStep(Time.deltaTime * 5f);
		((SimpleMover)((GunScript)this).hammer).UpdateDisplay();
		if (((GunScript)this).IsSafetyOn())
		{
			((ModGunScript)this)._hammer_state = 2;
			((SimpleMover)((GunScript)this).hammer).amount = Mathf.Clamp(((SimpleMover)((GunScript)this).hammer).amount, ((ModGunScript)this)._hammer_cocked_val, 1f);
			((SimpleMover)((GunScript)this).hammer).target_amount = ((ModGunScript)this)._hammer_cocked_val;
			((SimpleMover)((GunScript)this).hammer).UpdateDisplay();
			((GunScript)this).trigger.amount = Mathf.Min(((GunScript)this).trigger.amount, 0.1f);
			((GunScript)this).trigger.target_amount = Mathf.Min(((GunScript)this).trigger.target_amount, 0.1f);
			((GunScript)this).trigger.UpdateDisplay();
		}
		if (((SimpleMover)((GunScript)this).slide).amount > 0f)
		{
			((ModGunScript)this)._disconnector_needs_reset = true;
		}
		if (((ModGunScript)this)._disconnector_needs_reset && ((SimpleMover)((GunScript)this).slide).amount == 0f && ((GunScript)this).trigger.amount <= 0.05f)
		{
			((ModGunScript)this)._disconnector_needs_reset = false;
			AudioManager.PlayOneShotAttached(((GunScript)this).sound_trigger_reset, ((Component)((GunScript)this).trigger.transform).gameObject);
		}
		if (((SimpleMover)((GunScript)this).slide).amount > 0.2f && ((ModGunScript)this)._hammer_state != 2)
		{
			((SimpleMover)((GunScript)this).hammer).amount = Mathf.Max(((SimpleMover)((GunScript)this).hammer).amount, ModGunScript.InterpCurve(ref slide_push_hammer_curve, ((SimpleMover)((GunScript)this).slide).amount));
			((SimpleMover)((GunScript)this).hammer).UpdateDisplay();
		}
		bool flag = ((ModGunScript)this).player_input != null && ((ModGunScript)this).player_input.GetButton(14);
		if (((GunScript)this).trigger.amount >= 0.92f && ((SimpleMover)((GunScript)this).hammer).amount >= ((ModGunScript)this)._hammer_cocked_val - 0.01f && ((ModGunScript)this)._hammer_state == 2 && !((ModGunScript)this)._disconnector_needs_reset && !((GunScript)this).IsSafetyOn() && !flag && ((SimpleMover)((GunScript)this).slide).amount <= 0.001f)
		{
			((SimpleMover)((GunScript)this).hammer).target_amount = 0f;
			((SimpleMover)((GunScript)this).hammer).vel = -0.1f * ((PlayerStats)(ref ReceiverCoreScript.Instance().player_stats)).animation_speed;
		}
		((SimpleMover)((GunScript)this).hammer).TimeStep(Time.deltaTime);
		if (((SimpleMover)((GunScript)this).hammer).amount <= 0.001f && ((ModGunScript)this)._hammer_state == 2 && !decocking)
		{
			((SimpleMover)((GunScript)this).hammer).amount = 0f;
			((SimpleMover)((GunScript)this).hammer).UpdateDisplay();
			((ModGunScript)this).TryFireBullet(1f);
			((ModGunScript)this)._hammer_state = 0;
		}
		if (hp_sear != null)
		{
			if (((SimpleMover)((GunScript)this).hammer).amount < ((ModGunScript)this)._hammer_halfcocked)
			{
				((SimpleMover)hp_sear).amount = hp_sear_uncocked;
			}
			else if (((SimpleMover)((GunScript)this).hammer).amount < ((ModGunScript)this)._hammer_cocked_val)
			{
				((SimpleMover)hp_sear).amount = Mathf.Lerp(hp_sear_halfcocked, hp_sear_almost_cocked, (((SimpleMover)((GunScript)this).hammer).amount - ((ModGunScript)this)._hammer_halfcocked) / (((ModGunScript)this)._hammer_cocked_val - ((ModGunScript)this)._hammer_halfcocked));
			}
			else
			{
				((SimpleMover)hp_sear).amount = Mathf.Lerp(hp_sear_cocked, hp_sear_hammer_back, (((SimpleMover)((GunScript)this).hammer).amount - ((ModGunScript)this)._hammer_cocked_val) / (1f - ((ModGunScript)this)._hammer_cocked_val));
			}
			((SimpleMover)hp_sear).UpdateDisplay();
		}
		((GunScript)this).trigger.UpdateDisplay();
		((ModGunScript)this).UpdateAnimatedComponents();
	}

	public override void LateUpdateGun()
	{
	}
}
[BepInPlugin("hipower", "hipower", "1.0.0")]
public class HipowerLoader : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		BepInPlugin val = (BepInPlugin)Attribute.GetCustomAttribute(typeof(HipowerLoader), typeof(BepInPlugin));
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + val.GUID + " is loaded!"));
	}
}