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")]
[BepInPlugin("Ciarence.Makarov", "Makarov", "1.0.0")]
public class MakarovLoader : BaseUnityPlugin
{
private void Awake()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + ((BepInPlugin)Attribute.GetCustomAttribute(typeof(MakarovLoader), typeof(BepInPlugin))).GUID + " is loaded!"));
Extensions.LogDebugWithColor(((BaseUnityPlugin)this).Logger, ConsoleColor.Blue, (object)"piss");
}
}
public class MakarovScript : ModGunScript
{
private readonly float[] kHammerSlideCurve = new float[6] { 0f, 0f, 0.4f, 0.9f, 0.5f, 0.95f };
private readonly float[] kSearTriggerCurve = new float[4] { 0f, 0f, 1f, 1f };
private bool decocking;
private bool slide_push_hammer;
private RotateMover sear;
private float sear_almost_cocked;
private float sear_cocked;
private float sear_halfcocked;
private float sear_safety_on;
private float sear_hammer_back;
private float sear_uncocked;
private float[] kSearSafetyCurve = new float[4] { 0f, 0f, 1f, 1f };
private float[] kHammerTriggerCurve = new float[4] { 0f, 0f, 1f, 1f };
private bool hammer_rest;
public SkinnedMeshRenderer main_spring;
public AnimationCurve da_animation_curve = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
{
new Keyframe(0f, 0f),
new Keyframe(1f, 1f)
});
public AnimationCurve sa_animation_curve = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
{
new Keyframe(0f, 0f),
new Keyframe(1f, 1f)
});
private bool isInDoubleActionMode;
private bool is_da_pulling_trigger;
private bool da_needs_reset;
private float interpCurveSlideHammer;
public override void InitializeGun()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
ShellCasingScript val2;
((GunScript)this).loaded_cartridge_prefab.GetComponent<ShellCasingScript>().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;
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()
{
//IL_0079: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
sear = AccessTools.FieldRefAccess<GunScript, RotateMover>((GunScript)(object)this, "sear");
sear_almost_cocked = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_almost_cocked");
sear_cocked = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_cocked");
sear_halfcocked = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_halfcocked");
sear_hammer_back = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_hammer_back");
sear_uncocked = AccessTools.FieldRefAccess<GunScript, float>((GunScript)(object)this, "sear_uncocked");
sear_safety_on = Quaternion.Angle(sear.rotations[0], ((Component)this).transform.Find("sear_safety_on").localRotation) / Quaternion.Angle(sear.rotations[0], sear.rotations[1]);
kSearSafetyCurve[3] = sear_safety_on;
}
public override void UpdateGun()
{
if (((ModGunScript)this).player_input.GetButton(14) && ((ModGunScript)this).player_input.GetButtonDown(2) && ((SimpleMover)((GunScript)this).slide).amount == 0f)
{
decocking = true;
}
if (isInDoubleActionMode)
{
((GunScript)this).base_trigger_profile = da_animation_curve;
}
else
{
((GunScript)this).base_trigger_profile = sa_animation_curve;
}
is_da_pulling_trigger = isInDoubleActionMode && LocalAimHandler.player_instance.PullingTrigger && !da_needs_reset && !((GunScript)this).IsSafetyOn();
interpCurveSlideHammer = ModGunScript.InterpCurve(ref kHammerSlideCurve, ((SimpleMover)((GunScript)this).slide).amount);
if (((SimpleMover)((GunScript)this).slide).amount > 0f)
{
slide_push_hammer = true;
}
else
{
slide_push_hammer = false;
}
if (((SimpleMover)((GunScript)this).hammer).amount < ((ModGunScript)this)._hammer_halfcocked)
{
((SimpleMover)sear).amount = sear_uncocked;
}
else if (((SimpleMover)((GunScript)this).hammer).amount < ((ModGunScript)this)._hammer_cocked_val)
{
((SimpleMover)sear).amount = Mathf.Lerp(sear_halfcocked, sear_almost_cocked, (((SimpleMover)((GunScript)this).hammer).amount - ((ModGunScript)this)._hammer_halfcocked) / (((ModGunScript)this)._hammer_cocked_val - ((ModGunScript)this)._hammer_halfcocked));
}
else
{
((SimpleMover)sear).amount = Mathf.Lerp(sear_cocked, sear_hammer_back, (((SimpleMover)((GunScript)this).hammer).amount - ((ModGunScript)this)._hammer_cocked_val) / (1f - ((ModGunScript)this)._hammer_cocked_val));
}
float num = ModGunScript.InterpCurve(ref kSearTriggerCurve, ((GunScript)this).trigger.amount);
if (num > ((SimpleMover)sear).amount && !slide_push_hammer && !((ModGunScript)this)._disconnector_needs_reset)
{
((SimpleMover)sear).amount = num;
}
else if (slide_push_hammer)
{
((SimpleMover)sear).amount = Mathf.MoveTowards(((SimpleMover)sear).amount, sear_cocked, Time.deltaTime * 5f);
}
((SimpleMover)((GunScript)this).hammer).asleep = slide_push_hammer && is_da_pulling_trigger;
if (!slide_push_hammer && !((ModGunScript)this)._disconnector_needs_reset && ((ModGunScript)this)._hammer_state != 2 && !decocking)
{
isInDoubleActionMode = true;
}
float num2 = ModGunScript.InterpCurve(ref kHammerTriggerCurve, ((GunScript)this).trigger.amount);
if (isInDoubleActionMode && num2 > ((SimpleMover)((GunScript)this).hammer).amount && !da_needs_reset)
{
((SimpleMover)((GunScript)this).hammer).amount = num2;
}
if (((SimpleMover)((GunScript)this).hammer).amount > ((ModGunScript)this)._hammer_cocked_val)
{
if (((ModGunScript)this)._hammer_state == 1)
{
((ModGunScript)this)._hammer_state = 2;
}
isInDoubleActionMode = false;
da_needs_reset = true;
}
if (decocking)
{
if (!((ModGunScript)this).player_input.GetButton(14))
{
((SimpleMover)((GunScript)this).hammer).amount = Mathf.MoveTowards(((SimpleMover)((GunScript)this).hammer).amount, ((GunScript)this).IsSafetyOn() ? ((ModGunScript)this)._hammer_halfcocked : 0f, Time.deltaTime * 5f);
}
if (((SimpleMover)((GunScript)this).hammer).amount == (((GunScript)this).IsSafetyOn() ? ((ModGunScript)this)._hammer_halfcocked : 0f) || !((ModGunScript)this).player_input.GetButton(2))
{
((ModGunScript)this)._hammer_state = 0;
decocking = false;
AudioManager.PlayOneShotAttached(((GunScript)this).sound_decock, ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject, 0.3f);
}
}
if (!decocking)
{
if ((((ModGunScript)this)._hammer_state == 1 && ((SimpleMover)((GunScript)this).hammer).amount != ((ModGunScript)this)._hammer_halfcocked) || (((ModGunScript)this)._hammer_state == 2 && ((SimpleMover)((GunScript)this).hammer).amount != ((ModGunScript)this)._hammer_cocked_val))
{
hammer_rest = false;
}
bool flag = !slide_push_hammer && !((ModGunScript)this).player_input.GetButton(14) && !is_da_pulling_trigger;
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 && flag)
{
((SimpleMover)((GunScript)this).hammer).target_amount = ((ModGunScript)this)._hammer_halfcocked;
}
if (!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 && !((GunScript)this).IsSafetyOn())
{
((ModGunScript)this)._hammer_state = 2;
if (!((SimpleMover)((GunScript)this).hammer).asleep && flag)
{
((SimpleMover)((GunScript)this).hammer).target_amount = ((ModGunScript)this)._hammer_cocked_val;
}
if (!LocalAimHandler.player_instance.PullingTrigger)
{
AudioManager.PlayOneShotAttached("event:/guns/1911/1911_full_cock", ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject);
}
}
if (SearBlocksHammer())
{
if (((ModGunScript)this)._hammer_state == 1 && flag)
{
((SimpleMover)((GunScript)this).hammer).target_amount = ((ModGunScript)this)._hammer_halfcocked;
if (!hammer_rest && ((SimpleMover)((GunScript)this).hammer).amount == ((ModGunScript)this)._hammer_halfcocked)
{
if (((GunScript)this).IsSafetyOn() && !decocking)
{
AudioManager.PlayOneShotAttached(((GunScript)this).sound_dry_fire, ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject, 0.5f);
}
AudioManager.PlayOneShotAttached("event:/guns/1911/1911_hammer_rest", ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject, 2f);
hammer_rest = true;
}
}
if (((ModGunScript)this)._hammer_state == 2 && flag)
{
((SimpleMover)((GunScript)this).hammer).target_amount = ((ModGunScript)this)._hammer_cocked_val;
if (!hammer_rest && ((SimpleMover)((GunScript)this).hammer).amount == ((ModGunScript)this)._hammer_cocked_val)
{
AudioManager.PlayOneShotAttached("event:/guns/1911/1911_hammer_rest", ((Component)((SimpleMover)((GunScript)this).hammer).transform).gameObject, 2f);
hammer_rest = true;
}
}
}
}
if (!slide_push_hammer && !is_da_pulling_trigger)
{
((SimpleMover)((GunScript)this).hammer).TimeStep(Time.deltaTime);
}
((SimpleMover)((GunScript)this).hammer).UpdateDisplay();
if (((GunScript)this).IsSafetyOn() && !slide_push_hammer)
{
if (((ModGunScript)this)._hammer_state == 2)
{
((ModGunScript)this)._hammer_state = 1;
}
((SimpleMover)sear).amount = ModGunScript.InterpCurve(ref kSearSafetyCurve, ((SimpleMover)((GunScript)this).safety).amount);
if (((SimpleMover)((GunScript)this).hammer).amount > ((ModGunScript)this)._hammer_halfcocked)
{
((SimpleMover)((GunScript)this).hammer).target_amount = Mathf.Max(((ModGunScript)this)._hammer_halfcocked, ((SimpleMover)((GunScript)this).hammer).target_amount);
}
da_needs_reset = true;
((GunScript)this).trigger.amount = Mathf.Min(((GunScript)this).trigger.amount, 0.1f);
((GunScript)this).trigger.UpdateDisplay();
}
else if (!SearBlocksHammer() && ((SimpleMover)((GunScript)this).hammer).amount >= ((ModGunScript)this)._hammer_cocked_val && !((ModGunScript)this)._disconnector_needs_reset && !((ModGunScript)this).player_input.GetButton(14) && !slide_push_hammer && !decocking && ((SimpleMover)((GunScript)this).slide).amount == 0f)
{
((SimpleMover)((GunScript)this).hammer).target_amount = 0f;
((SimpleMover)((GunScript)this).hammer).vel = -0.1f * ((PlayerStats)(ref ReceiverCoreScript.Instance().player_stats)).animation_speed;
isInDoubleActionMode = false;
}
if (((SimpleMover)((GunScript)this).slide).amount > 0f)
{
((ModGunScript)this)._disconnector_needs_reset = true;
}
if (((SimpleMover)((GunScript)this).slide).amount == 0f && ((GunScript)this).trigger.amount == 0f)
{
da_needs_reset = false;
if (((ModGunScript)this)._disconnector_needs_reset)
{
((ModGunScript)this)._disconnector_needs_reset = false;
AudioManager.PlayOneShotAttached(((GunScript)this).sound_trigger_reset, ((Component)((GunScript)this).trigger.transform).gameObject);
}
}
if (((SimpleMover)((GunScript)this).hammer).amount == 0f && ((ModGunScript)this)._hammer_state == 2 && !decocking && !((ModGunScript)this).player_input.GetButton(14) && !slide_push_hammer)
{
da_needs_reset = true;
((ModGunScript)this).TryFireBullet(1f);
((ModGunScript)this)._hammer_state = 0;
}
((SimpleMover)sear).UpdateDisplay();
((GunScript)this).trigger.UpdateDisplay();
((ModGunScript)this).UpdateAnimatedComponents();
}
private bool SearBlocksHammer()
{
return ((SimpleMover)sear).amount <= sear_safety_on;
}
public override void LateUpdateGun()
{
((GunScript)this).ApplyTransform("slide_stop_tige", ((SimpleMover)((GunScript)this).slide_stop).amount, ((Component)this).transform.Find("sear_and_slide_stop_spring_tige"));
main_spring.SetBlendShapeWeight(0, ((SimpleMover)((GunScript)this).magazine_catch).amount * 100f);
main_spring.SetBlendShapeWeight(1, ((GunScript)this).trigger.amount * 100f);
main_spring.SetBlendShapeWeight(2, ((SimpleMover)((GunScript)this).hammer).amount * 100f);
if (slide_push_hammer && interpCurveSlideHammer > ((SimpleMover)((GunScript)this).hammer).amount)
{
((SimpleMover)((GunScript)this).hammer).amount = interpCurveSlideHammer;
((SimpleMover)((GunScript)this).hammer).UpdateDisplay();
}
}
}