using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using GorillaNetworking;
using GorillaTagScripts;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using OldHoldables;
using UnityEngine;
using UnityEngine.XR;
using Valve.VR;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Plugin), "OldHoldables", "2.4.3", "gizmogoat/dev9998/lapis", null)]
[assembly: MelonGame("Another Axiom", "Gorilla Tag")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OldHoldables")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6c0791e683045cb1cbdd40dc64d6fdfca65cfd62")]
[assembly: AssemblyProduct("OldHoldables")]
[assembly: AssemblyTitle("OldHoldables")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace OldHoldables;
public class HarmonyPatches
{
[HarmonyPatch(typeof(TransferrableObject), "IsHeld")]
private class HoldingPatch
{
private static bool Prefix(TransferrableObject __instance, ref bool __result)
{
ThrowableBug val = default(ThrowableBug);
ThrowableSetDressing val2 = default(ThrowableSetDressing);
DecorativeItem val3 = default(DecorativeItem);
if (((Component)__instance).TryGetComponent<ThrowableBug>(ref val) || ((Component)__instance).TryGetComponent<ThrowableSetDressing>(ref val2) || ((Component)__instance).TryGetComponent<DecorativeItem>(ref val3))
{
return true;
}
if (!SetGoingToChange)
{
__result = false;
}
return SetGoingToChange;
}
}
[HarmonyPatch(typeof(TransferrableObject), "OnEnable")]
private class CosSpawnPatch
{
private static void Postfix(TransferrableObject __instance)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Invalid comparison between Unknown and I4
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Invalid comparison between Unknown and I4
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
ThrowableBug val = default(ThrowableBug);
ThrowableSetDressing val2 = default(ThrowableSetDressing);
DecorativeItem val3 = default(DecorativeItem);
if ((!((Component)__instance).TryGetComponent<ThrowableBug>(ref val) || !((Component)__instance).TryGetComponent<ThrowableSetDressing>(ref val2) || !((Component)__instance).TryGetComponent<DecorativeItem>(ref val3)) && __instance.IsMyItem())
{
if ((int)__instance.currentState == 1)
{
__instance.currentState = (PositionState)8;
}
if ((int)__instance.currentState == 2)
{
__instance.currentState = (PositionState)4;
}
}
}
}
[HarmonyPatch(typeof(EquipmentInteractor), "GetIsHolding")]
private class RopeHoldingPatch
{
private static bool Prefix(ref bool __result)
{
if (!SetGoingToChange)
{
__result = false;
}
return SetGoingToChange;
}
}
[HarmonyPatch(typeof(CosmeticsController), "ApplyCosmeticItemToSet", new Type[]
{
typeof(CosmeticSet),
typeof(CosmeticItem),
typeof(bool),
typeof(bool),
typeof(List<CosmeticSlots>)
})]
private class ReleaseBeforeChangingHoldables
{
private static void Prefix()
{
SetGoingToChange = true;
((EquipmentInteractor)EquipmentInteractor.instance).ReleaseLeftHand();
((EquipmentInteractor)EquipmentInteractor.instance).ReleaseRightHand();
}
private static void Postfix()
{
SetGoingToChange = false;
}
}
private static Harmony instance;
public static bool SetGoingToChange;
public static bool HoldQueue;
public static bool HoverLeft;
public static bool IsPatched { get; private set; }
internal static void RemoveHarmonyPatches()
{
if (instance != null && IsPatched)
{
instance.UnpatchSelf();
IsPatched = false;
}
}
}
public class OHManager : MonoBehaviour
{
private bool IsSteamVR;
private bool initialized = false;
public static bool RightStickClick;
private float DropTime;
private void Awake()
{
GorillaTagger.OnPlayerSpawned((Action)GameInitialized);
}
private void GameInitialized()
{
IsSteamVR = Traverse.Create((object)PlayFabAuthenticator.instance).Field("platform").GetValue()
.ToString()
.ToLower() == "steam";
initialized = true;
}
private void OnDisable()
{
HarmonyPatches.RemoveHarmonyPatches();
}
private void LateUpdate()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
if (initialized)
{
if (IsSteamVR)
{
RightStickClick = SteamVR_Actions.gorillaTag_RightJoystickClick.GetState((SteamVR_Input_Sources)2);
}
else
{
((InputDevice)(ref ((ControllerInputPoller)ControllerInputPoller.instance).rightControllerDevice)).TryGetFeatureValue(CommonUsages.primary2DAxisClick, ref RightStickClick);
}
if (!Plugin.disableDropping.Value && RightStickClick && DropTime + 3f < Time.time)
{
DropManually();
}
}
}
private void DropManually()
{
HarmonyPatches.SetGoingToChange = true;
((EquipmentInteractor)EquipmentInteractor.instance).ReleaseLeftHand();
((EquipmentInteractor)EquipmentInteractor.instance).ReleaseRightHand();
HarmonyPatches.SetGoingToChange = false;
DropTime = Time.time;
}
}
public class Plugin : MelonMod
{
public static MelonPreferences_Category Config;
public static MelonPreferences_Entry<bool> disableDropping;
public override void OnInitializeMelon()
{
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
Config = MelonPreferences.CreateCategory("OldHoldables");
string filePath = Path.Combine(MelonEnvironment.UserDataDirectory, "OldHoldables.cfg");
Config.SetFilePath(filePath);
Config.LoadFromFile(true);
disableDropping = Config.CreateEntry<bool>("disableDropping", false, "Disable Dropping", "Turn off manual dropping altogether. Not recommended, but may be needed for Index controllers", false, false, (ValueValidator)null, (string)null);
GameObject val = new GameObject("OldHoldables");
Object.DontDestroyOnLoad((Object)(object)val);
val.AddComponent<OHManager>();
}
}
internal class PluginInfo
{
public const string GUID = "oldholdables";
public const string Name = "OldHoldables";
public const string Version = "2.4.3";
public const string Author = "gizmogoat/dev9998/lapis";
}