using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using FistVR;
using Microsoft.CodeAnalysis;
using On.FistVR;
using OpenScripts2;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("UniversalMuzzleAttachmentPoint")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UniversalMuzzleAttachmentPoint")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ab1b9896-67d2-4e4c-b995-3c7c4d021633")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Cityrobo
{
[BepInPlugin("h3vr.cityrobo.UniversalMuzzleAttachmentPoint", "Universal Muzzle Attachment Point", "1.1.0")]
public class UniversalMuzzleAttachmentPoint : BaseUnityPlugin
{
private const string MOUNTNAME = "_PointSuppressorMount";
private const string LAYERNAME = "Interactable";
private const string TAG = "FVRFireArmAttachmentMount";
public ConfigEntry<float> FlintLockScale;
private string _dictionaryPath;
private const string DICTIONARYNAME = "RoundScaleDictionary.txt";
private string _roundScaleDictionaryString;
private Dictionary<FireArmRoundType, float> _roundScaleDictionary = new Dictionary<FireArmRoundType, float>();
private float GetScale(FireArmRoundType roundType)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (_roundScaleDictionary.TryGetValue(roundType, out var value))
{
return value;
}
return 1f;
}
public void Awake()
{
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
FlintLockScale = ((BaseUnityPlugin)this).Config.Bind<float>("Universal Muzzle Attachment Point", "Flintlock Muzzle Scale", 1.5f, "Since Flintlocks don't use conventional caliber types in the game's ammo sense, I cannot auto configure them by caliber. So this config option exists to negate that.");
Hook();
_dictionaryPath = ((BaseUnityPlugin)this).Info.Location;
_dictionaryPath = Path.GetDirectoryName(_dictionaryPath);
_dictionaryPath = Path.Combine(_dictionaryPath, "RoundScaleDictionary.txt");
StreamReader streamReader = new StreamReader(_dictionaryPath);
_roundScaleDictionaryString = streamReader.ReadToEnd();
streamReader.Close();
string[] array = _roundScaleDictionaryString.Split(new char[1] { '\n' });
for (int i = 0; i < array.Length; i++)
{
string[] array2 = array[i].Split(new char[1] { ';' });
FireArmRoundType key = (FireArmRoundType)Enum.Parse(typeof(FireArmRoundType), array2[0]);
float value = float.Parse(array2[1]);
_roundScaleDictionary.Add(key, value);
}
}
public void OnDestroy()
{
Unhook();
}
private void Hook()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
FVRFireArm.Awake += new hook_Awake(FVRFireArm_Awake);
MuzzleDevice.Awake += new hook_Awake(MuzzleDevice_Awake);
}
private void Unhook()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
FVRFireArm.Awake -= new hook_Awake(FVRFireArm_Awake);
MuzzleDevice.Awake -= new hook_Awake(MuzzleDevice_Awake);
}
private void FVRFireArm_Awake(orig_Awake orig, FVRFireArm self)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Invalid comparison between Unknown and I4
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
orig.Invoke(self);
if (((FVRPhysicalObject)self).AttachmentMounts == null)
{
((FVRPhysicalObject)self).AttachmentMounts = new List<FVRFireArmAttachmentMount>();
}
bool flag = false;
bool flag2 = false;
foreach (FVRFireArmAttachmentMount attachmentMount in ((FVRPhysicalObject)self).AttachmentMounts)
{
if ((Object)(object)attachmentMount == (Object)null)
{
flag2 = true;
}
else if ((int)attachmentMount.Type == 2)
{
flag = true;
}
}
if (flag)
{
return;
}
GameObject val = new GameObject("_PointSuppressorMount");
val.layer = LayerMask.NameToLayer("Interactable");
val.tag = "FVRFireArmAttachmentMount";
val.SetActive(false);
FVRFireArmAttachmentMount val2 = CreateNewMountComponent(self, val);
SphereCollider obj2 = val.AddComponent<SphereCollider>();
obj2.radius = 0.01f;
((Collider)obj2).isTrigger = true;
if (flag2)
{
for (int i = 0; i < ((FVRPhysicalObject)self).AttachmentMounts.Count; i++)
{
if ((Object)(object)((FVRPhysicalObject)self).AttachmentMounts[i] == (Object)null)
{
((FVRPhysicalObject)self).AttachmentMounts[i] = val2;
break;
}
}
((FVRPhysicalObject)self).AttachmentMounts.RemoveAll((FVRFireArmAttachmentMount obj) => (Object)(object)obj == (Object)null);
}
else
{
((FVRPhysicalObject)self).AttachmentMounts.Add(val2);
}
val.SetActive(true);
}
private FVRFireArmAttachmentMount CreateNewMountComponent(FVRFireArm self, GameObject MuzzleMountGameObject)
{
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: 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)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0257: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Unknown result type (might be due to invalid IL or missing references)
//IL_0268: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_027b: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
BreakActionWeapon val = (BreakActionWeapon)(object)((self is BreakActionWeapon) ? self : null);
FVRFireArmAttachmentMount val5;
bool parentToThis;
if (val == null)
{
Derringer val2 = (Derringer)(object)((self is Derringer) ? self : null);
if (val2 == null)
{
Flaregun val3 = (Flaregun)(object)((self is Flaregun) ? self : null);
if (val3 == null)
{
FlintlockWeapon val4 = (FlintlockWeapon)(object)((self is FlintlockWeapon) ? self : null);
if (val4 != null)
{
val5 = MuzzleMountGameObject.AddComponent<FVRFireArmAttachmentMount>();
MuzzleMountGameObject.transform.parent = ((Component)self).transform;
parentToThis = false;
Vector3 position = ((Component)val4).GetComponentInChildren<FlintlockBarrel>().Muzzle.position;
Vector3 eulerAngles = ((Component)val4).GetComponentInChildren<FlintlockBarrel>().Muzzle.eulerAngles;
MuzzleMountGameObject.transform.position = position;
MuzzleMountGameObject.transform.rotation = Quaternion.Euler(eulerAngles);
}
else
{
val5 = MuzzleMountGameObject.AddComponent<FVRFireArmAttachmentMount>();
MuzzleMountGameObject.transform.parent = ((Component)self).transform;
parentToThis = false;
Vector3 position = self.GetMuzzle().position;
Vector3 eulerAngles = self.GetMuzzle().eulerAngles;
MuzzleMountGameObject.transform.position = position;
MuzzleMountGameObject.transform.rotation = Quaternion.Euler(eulerAngles);
}
}
else
{
val5 = MuzzleMountGameObject.AddComponent<FVRFireArmAttachmentMount>();
MuzzleMountGameObject.transform.parent = val3.Hinge;
parentToThis = true;
Vector3 position = self.GetMuzzle().position;
Vector3 eulerAngles = self.GetMuzzle().eulerAngles;
MuzzleMountGameObject.transform.position = position;
MuzzleMountGameObject.transform.rotation = Quaternion.Euler(eulerAngles);
}
}
else
{
val5 = (FVRFireArmAttachmentMount)(object)MuzzleMountGameObject.AddComponent<MultiBarrelMount>();
MuzzleMountGameObject.transform.parent = val2.Hinge;
parentToThis = true;
Vector3 position = ComputeAverage(val2.Barrels.Select((DBarrel barrel) => barrel.MuzzlePoint.position));
Vector3 eulerAngles = ComputeAverage(val2.Barrels.Select((DBarrel barrel) => barrel.MuzzlePoint.eulerAngles));
MuzzleMountGameObject.transform.position = position;
MuzzleMountGameObject.transform.rotation = Quaternion.Euler(eulerAngles);
}
}
else
{
val5 = (FVRFireArmAttachmentMount)(object)MuzzleMountGameObject.AddComponent<MultiBarrelMount>();
MuzzleMountGameObject.transform.parent = ((Component)val.Hinge).transform;
parentToThis = true;
Vector3 position = ComputeAverage(val.Barrels.Select((BreakActionBarrel barrel) => barrel.Muzzle.position));
Vector3 eulerAngles = ComputeAverage(val.Barrels.Select((BreakActionBarrel barrel) => barrel.Muzzle.eulerAngles));
MuzzleMountGameObject.transform.position = position;
MuzzleMountGameObject.transform.rotation = Quaternion.Euler(eulerAngles);
}
val5.MyObject = (FVRPhysicalObject)(object)self;
val5.Parent = (FVRPhysicalObject)(object)self;
val5.Type = (FVRFireArmAttachementMountType)2;
val5.Point_Front = ((Component)val5).transform;
val5.Point_Rear = ((Component)val5).transform;
val5.AttachmentsList = new List<FVRFireArmAttachment>();
val5.SubMounts = new List<FVRFireArmAttachmentMount>();
val5.ParentToThis = parentToThis;
val5.ScaleModifier = ((!(self is FlintlockWeapon)) ? GetScale(self.RoundType) : FlintLockScale.Value);
return val5;
}
private Vector3 ComputeAverage(IEnumerable<Vector3> ListOfVectors)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = default(Vector3);
int num = ListOfVectors.Count();
foreach (Vector3 ListOfVector in ListOfVectors)
{
val += ListOfVector;
}
return val / (float)num;
}
private void MuzzleDevice_Awake(orig_Awake orig, MuzzleDevice self)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Invalid comparison between Unknown and I4
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
orig.Invoke(self);
bool flag = false;
if (((FVRPhysicalObject)self).AttachmentMounts == null)
{
((FVRPhysicalObject)self).AttachmentMounts = new List<FVRFireArmAttachmentMount>();
}
bool flag2 = false;
foreach (FVRFireArmAttachmentMount attachmentMount in ((FVRPhysicalObject)self).AttachmentMounts)
{
if ((Object)(object)attachmentMount == (Object)null)
{
flag2 = true;
}
else if ((int)attachmentMount.Type == 2)
{
flag = true;
}
}
if (flag)
{
return;
}
GameObject val = new GameObject("_PointSuppressorMount");
val.transform.parent = ((Component)self).transform;
val.transform.position = self.Muzzle.position;
val.transform.rotation = self.Muzzle.rotation;
val.layer = LayerMask.NameToLayer("Interactable");
val.tag = "FVRFireArmAttachmentMount";
val.SetActive(false);
FVRFireArmAttachmentMount val2 = val.AddComponent<FVRFireArmAttachmentMount>();
val2.MyObject = (FVRPhysicalObject)(object)self;
val2.Parent = (FVRPhysicalObject)(object)self;
val2.ScaleModifier = 1f;
val2.Type = (FVRFireArmAttachementMountType)2;
val2.Point_Front = ((Component)val2).transform;
val2.Point_Rear = ((Component)val2).transform;
val2.AttachmentsList = new List<FVRFireArmAttachment>();
val2.SubMounts = new List<FVRFireArmAttachmentMount>();
SphereCollider obj2 = val.AddComponent<SphereCollider>();
obj2.radius = 0.01f;
((Collider)obj2).isTrigger = true;
if (flag2)
{
for (int i = 0; i < ((FVRPhysicalObject)self).AttachmentMounts.Count; i++)
{
if ((Object)(object)((FVRPhysicalObject)self).AttachmentMounts[i] == (Object)null)
{
((FVRPhysicalObject)self).AttachmentMounts[i] = val2;
break;
}
}
((FVRPhysicalObject)self).AttachmentMounts.RemoveAll((FVRFireArmAttachmentMount obj) => (Object)(object)obj == (Object)null);
}
else
{
((FVRPhysicalObject)self).AttachmentMounts.Add(val2);
}
val.SetActive(true);
}
}
}