using System.Collections;
using System.Collections.Generic;
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 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]
namespace AK47Beast
{
public class BeastAiming : MonoBehaviour
{
public Transform Muzzle;
public Transform ReflexWindow;
public Transform SurfaceDot;
public float ConvergenceDistance = 50f;
public float LaserMaxRange = 300f;
public LayerMask HitMask = LayerMask.op_Implicit(-5);
public bool ReflexEnabled = true;
public bool LaserEnabled = true;
private readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[64];
private MaterialPropertyBlock reflexProperties;
public void UpdateAim()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: 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_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0200: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Muzzle == (Object)null || (Object)(object)ReflexWindow == (Object)null || (Object)(object)SurfaceDot == (Object)null)
{
return;
}
((Component)ReflexWindow).gameObject.SetActive(ReflexEnabled);
Vector3 val = Muzzle.position + Muzzle.forward * ConvergenceDistance;
ReflexWindow.rotation = Quaternion.LookRotation(val - ReflexWindow.position, ((Component)this).transform.up);
if (reflexProperties == null)
{
reflexProperties = new MaterialPropertyBlock();
}
reflexProperties.SetFloat("_ZeroDistance", Vector3.Distance(val, ReflexWindow.position));
((Component)ReflexWindow).GetComponent<Renderer>().SetPropertyBlock(reflexProperties);
((Component)SurfaceDot).gameObject.SetActive(false);
if (!LaserEnabled)
{
return;
}
int num = Physics.RaycastNonAlloc(Muzzle.position, Muzzle.forward, hits, LaserMaxRange, LayerMask.op_Implicit(HitMask), (QueryTriggerInteraction)1);
RaycastHit[] array = hits;
if (num == hits.Length)
{
array = Physics.RaycastAll(Muzzle.position, Muzzle.forward, LaserMaxRange, LayerMask.op_Implicit(HitMask), (QueryTriggerInteraction)1);
num = array.Length;
}
float num2 = float.MaxValue;
RaycastHit val2 = default(RaycastHit);
bool flag = false;
for (int i = 0; i < num; i++)
{
RaycastHit val3 = array[i];
if (!((Object)(object)((RaycastHit)(ref val3)).collider == (Object)null) && !((Component)((RaycastHit)(ref val3)).collider).transform.IsChildOf(((Component)this).transform) && !(((RaycastHit)(ref val3)).distance >= num2))
{
num2 = ((RaycastHit)(ref val3)).distance;
val2 = val3;
flag = true;
}
}
if (flag)
{
SurfaceDot.position = ((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * 0.0008f;
SurfaceDot.rotation = Quaternion.LookRotation(((RaycastHit)(ref val2)).normal);
float num3 = Mathf.Clamp(0.003f + num2 * 3E-05f, 0.003f, 0.018f);
SurfaceDot.localScale = Vector3.one * num3;
((Component)SurfaceDot).gameObject.SetActive(true);
}
}
private void LateUpdate()
{
UpdateAim();
}
}
public class BeastMagazineAmmo : FVRFireArmMagazine
{
public override void Awake()
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected I4, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
FireArmRoundClass[] array = (FireArmRoundClass[])(object)new FireArmRoundClass[base.m_capacity];
FireArmRoundClass defaultRoundClass = AM.GetDefaultRoundClass(base.RoundType);
for (int i = 0; i < array.Length; i++)
{
array[i] = (FireArmRoundClass)(int)defaultRoundClass;
}
FVRMagazineLoadingPattern val = new FVRMagazineLoadingPattern();
val.Classes = array;
base.DefaultLoadingPattern = val;
((FVRFireArmMagazine)this).Awake();
}
}
public class BeastMagazineRelease : MonoBehaviour
{
private struct ColliderPair
{
public Collider a;
public Collider b;
}
public FVRFireArm FireArm;
public HingeJoint Joint;
public float Threshold = -16f;
public readonly ReleaseCycle Cycle = new ReleaseCycle();
private FVRFireArmMagazine striker;
private float lastContact = -10f;
private readonly List<ColliderPair> ignored = new List<ColliderPair>();
private void OnCollisionStay(Collision hit)
{
Rigidbody attachedRigidbody = hit.collider.attachedRigidbody;
FVRFireArmMagazine val = ((!((Object)(object)attachedRigidbody == (Object)null)) ? ((Component)attachedRigidbody).GetComponent<FVRFireArmMagazine>() : null);
if (!((Object)(object)val == (Object)null) && ((FVRInteractiveObject)val).IsHeld && !((Object)(object)val == (Object)(object)FireArm.Magazine) && !((Object)(object)val.FireArm != (Object)null))
{
striker = val;
lastContact = Time.time;
}
}
private void FixedUpdate()
{
FVRFireArmMagazine magazine = FireArm.Magazine;
bool contact = Time.time - lastContact < 0.06f && (Object)(object)striker != (Object)null && ((FVRInteractiveObject)striker).IsHeld && (Object)(object)striker.FireArm == (Object)null && (Object)(object)striker != (Object)(object)magazine;
if (Cycle.Step((!((Object)(object)magazine == (Object)null)) ? ((Object)magazine).GetInstanceID() : 0, Time.time, contact, Joint.angle, Threshold))
{
FVRFireArmMagazine newMag = striker;
List<ColliderPair> pairs = IgnorePair(magazine, newMag);
FireArm.EjectMag(true);
((MonoBehaviour)this).StartCoroutine(RestorePairs(pairs));
}
}
private List<ColliderPair> IgnorePair(FVRFireArmMagazine oldMag, FVRFireArmMagazine newMag)
{
List<ColliderPair> list = new List<ColliderPair>();
Collider[] componentsInChildren = ((Component)oldMag).GetComponentsInChildren<Collider>();
foreach (Collider val in componentsInChildren)
{
Collider[] componentsInChildren2 = ((Component)newMag).GetComponentsInChildren<Collider>();
foreach (Collider val2 in componentsInChildren2)
{
if (!val.isTrigger && !val2.isTrigger)
{
ColliderPair item = new ColliderPair
{
a = val,
b = val2
};
Physics.IgnoreCollision(val, val2, true);
list.Add(item);
ignored.Add(item);
}
}
}
return list;
}
private IEnumerator RestorePairs(List<ColliderPair> pairs)
{
yield return (object)new WaitForSeconds(0.25f);
foreach (ColliderPair pair in pairs)
{
if ((Object)(object)pair.a != (Object)null && (Object)(object)pair.b != (Object)null)
{
Physics.IgnoreCollision(pair.a, pair.b, false);
}
ignored.Remove(pair);
}
}
private void OnDisable()
{
foreach (ColliderPair item in ignored)
{
if ((Object)(object)item.a != (Object)null && (Object)(object)item.b != (Object)null)
{
Physics.IgnoreCollision(item.a, item.b, false);
}
}
ignored.Clear();
}
}
public class ReleaseCycle
{
private int magazine;
private float installedAt;
private float lastContact = -10f;
private bool latched;
public bool Step(int current, float now, bool contact, float angle, float threshold)
{
if (current != magazine)
{
magazine = current;
installedAt = now;
}
if (contact)
{
lastContact = now;
}
if (latched && now - lastContact > 0.12f && angle > -5f)
{
latched = false;
}
if (current == 0 || latched || now - installedAt < 0.25f || !contact || angle >= threshold)
{
return false;
}
latched = true;
return true;
}
}
}
namespace LocalTest.AK47BeastPrototype
{
[BepInPlugin("LocalTest.AK47BeastPrototype", "AK47BeastPrototype", "0.1.3")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class AK47BeastPrototypePlugin : 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(), "LocalTest.AK47BeastPrototype");
OtherLoader.RegisterDirectLoad(BasePath, "LocalTest.AK47BeastPrototype", "", "", "ak47_beast", "");
}
}
}