using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using FistVR;
using Microsoft.CodeAnalysis;
using On.FistVR;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("QuickbeltRotLock")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("QuickbeltRotLock")]
[assembly: AssemblyTitle("QuickbeltRotLock")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace QuickbeltRotLock
{
internal static class PluginInfo
{
internal const string NAME = "Look Down to Lock Quickbelt";
internal const string GUID = "okkim.lookdowntolockquickbelt";
internal const string VERSION = "1.1.0";
}
[BepInPlugin("okkim.lookdowntolockquickbelt", "Look Down to Lock Quickbelt", "1.1.0")]
[BepInProcess("h3vr.exe")]
public class QuickbeltRotLock : BaseUnityPlugin
{
private static ConfigEntry<float> rotLockThreshold;
private static ConfigEntry<bool> alsoLockWhenLookingUp;
private static ConfigEntry<string> excludedQuickbeltSlotTypes;
private string[] enumBlacklist = new string[0];
private List<FVRQuickBeltSlot> validQBSlots = new List<FVRQuickBeltSlot>();
private bool canQuickbeltRotate;
private Vector3 torsoProxy;
private bool hasProxyRotReset = true;
private float curRotOffset;
private void Awake()
{
rotLockThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Rotation lock threshold", 35f, "How far down (in degrees) you need to look before the quickbelt stops rotating with you");
alsoLockWhenLookingUp = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Also lock when looking up", false, "Controls whether the quickbelt also rotates when looking up; useful for armors and backpacks");
excludedQuickbeltSlotTypes = ((BaseUnityPlugin)this).Config.Bind<string>("Advanced", "Quickbelt slot type blacklist", "1985 1987", "Add a quickbelt slot type (name for base game, number for modded) to this list (separated by a space) to exclude it from the rotation lock");
enumBlacklist = excludedQuickbeltSlotTypes.Value.Split(new char[1] { ' ' });
for (int i = 0; i < enumBlacklist.Length; i++)
{
enumBlacklist[i].Trim();
}
}
public QuickbeltRotLock()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
FVRPlayerBody.Update += new hook_Update(FVRPlayerBody_Update);
FVRPlayerBody.ConfigureQuickbelt += new hook_ConfigureQuickbelt(FVRPlayerBody_ConfigureQuickbelt);
}
private void FVRPlayerBody_Update(orig_Update orig, FVRPlayerBody self)
{
//IL_0012: 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_001a: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
orig.Invoke(self);
Quaternion rotation = ((Component)self.Head).transform.rotation;
float num = ((Quaternion)(ref rotation)).eulerAngles.x;
if (num > 180f)
{
num -= 360f;
}
canQuickbeltRotate = (alsoLockWhenLookingUp.Value ? (canQuickbeltRotate = Mathf.Abs(num) < rotLockThreshold.Value) : (canQuickbeltRotate = num < rotLockThreshold.Value));
if (canQuickbeltRotate)
{
if (!hasProxyRotReset)
{
ResetRots();
}
rotation = GM.CurrentPlayerBody.Torso.rotation;
torsoProxy = ((Quaternion)(ref rotation)).eulerAngles;
return;
}
hasProxyRotReset = false;
float y = torsoProxy.y;
rotation = GM.CurrentPlayerBody.Torso.rotation;
float num2 = y - ((Quaternion)(ref rotation)).eulerAngles.y;
float num3 = curRotOffset - num2;
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(0f, num2, 0f);
foreach (FVRQuickBeltSlot validQBSlot in validQBSlots)
{
((Component)validQBSlot).transform.RotateAround(((Component)validQBSlot).transform.parent.position, Vector3.up, 0f - num3);
((Component)validQBSlot).transform.localRotation = Quaternion.Euler(val);
}
curRotOffset = num2;
}
private void FVRPlayerBody_ConfigureQuickbelt(orig_ConfigureQuickbelt orig, FVRPlayerBody self, int index)
{
orig.Invoke(self, index);
GetValidQBSlots();
ResetRots();
}
private void GetValidQBSlots()
{
validQBSlots.Clear();
foreach (FVRQuickBeltSlot item in GM.CurrentPlayerBody.QBSlots_Internal)
{
bool flag = false;
string[] array = enumBlacklist;
foreach (string text in array)
{
if (((object)(QuickbeltSlotType)(ref item.Type)).ToString() == text)
{
flag = true;
}
}
if (!flag)
{
validQBSlots.Add(item);
}
}
}
private void ResetRots()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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_0048: Unknown result type (might be due to invalid IL or missing references)
foreach (FVRQuickBeltSlot validQBSlot in validQBSlots)
{
((Component)validQBSlot).transform.RotateAround(((Component)validQBSlot).transform.parent.position, Vector3.up, 0f - curRotOffset);
((Component)validQBSlot).transform.localRotation = Quaternion.Euler(Vector3.zero);
}
curRotOffset = 0f;
hasProxyRotReset = true;
}
}
}