using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ee6d99a477f142df0010e7f5c8c3bd67b4b5b005")]
[assembly: AssemblyProduct("EmpressMicroCarts")]
[assembly: AssemblyTitle("EmpressMicroCarts")]
[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.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;
}
}
[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 Empress.MicroCarts
{
[BepInPlugin("Empress.EmpressMicroCarts", "EmpressMicroCarts", "1.1.3")]
public class EmpressMicroCarts : BaseUnityPlugin
{
internal static ConfigEntry<KeyCode> ToggleKey;
internal static ConfigEntry<float> MicroScale;
internal static ConfigEntry<float> MicroMass;
internal static ConfigEntry<float> MicroMassDuration;
internal static ConfigEntry<float> MicroMinGrabStrength;
internal static ConfigEntry<float> MicroGrabStrength;
internal static ConfigEntry<float> MicroDrag;
internal static ConfigEntry<float> MicroAngularDrag;
internal static ConfigEntry<bool> HostOnlyAuthority;
internal static EmpressMicroCarts Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)120, "");
MicroScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MicroScale", 0.15f, "");
MicroMass = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MicroMass", 1f, "");
MicroMassDuration = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MicroMassDuration", 9999f, "");
MicroMinGrabStrength = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MicroMinGrabStrength", 14f, "");
MicroGrabStrength = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MicroGrabStrength", 0f, "");
MicroDrag = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MicroDrag", 0f, "");
MicroAngularDrag = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MicroAngularDrag", 0f, "");
HostOnlyAuthority = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HostOnlyAuthority", true, "");
Patch();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} loaded");
}
internal void Patch()
{
//IL_001a: 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_0021: Expected O, but got Unknown
//IL_0026: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
[HarmonyPatch(typeof(PhysGrabCart), "Start")]
public static class Patch_PhysGrabCart_Start
{
private static void Postfix(PhysGrabCart __instance)
{
if (!Object.op_Implicit((Object)(object)((Component)__instance).gameObject.GetComponent<MicroCartController>()))
{
((Component)__instance).gameObject.AddComponent<MicroCartController>();
EmpressMicroCarts.Logger.LogInfo((object)("MicroCartController attached to " + ((Object)((Component)__instance).gameObject).name));
}
}
}
[HarmonyPatch(typeof(PhysGrabber), "Update")]
public static class Patch_PhysGrabber_Update
{
private static void Postfix(PhysGrabber __instance)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance == (Object)null || ((Object)(object)__instance.photonView != (Object)null && !__instance.photonView.IsMine) || !Input.GetKeyDown(EmpressMicroCarts.ToggleKey.Value))
{
return;
}
Transform grabbedObjectTransform = __instance.grabbedObjectTransform;
if ((Object)(object)grabbedObjectTransform == (Object)null)
{
return;
}
PhysGrabCart componentInParent = ((Component)grabbedObjectTransform).GetComponentInParent<PhysGrabCart>();
if (!((Object)(object)componentInParent == (Object)null))
{
MicroCartController component = ((Component)componentInParent).GetComponent<MicroCartController>();
if (!((Object)(object)component == (Object)null))
{
component.RequestToggle();
EmpressMicroCarts.Logger.LogInfo((object)("Toggle requested on cart " + ((Object)((Component)componentInParent).gameObject).name));
}
}
}
}
public class MicroCartController : MonoBehaviourPun
{
private PhysGrabCart cart;
private PhysGrabObject pgo;
private Rigidbody rb;
private Vector3 originalScale;
private bool cartEnabled;
private string originalTag;
private int originalLayer;
private readonly Dictionary<int, Vector3> itemOriginalScale = new Dictionary<int, Vector3>();
private readonly List<PhysGrabObject> scaledItems = new List<PhysGrabObject>();
public bool IsMicro { get; private set; }
private void Awake()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
cart = ((Component)this).GetComponent<PhysGrabCart>();
pgo = ((Component)this).GetComponent<PhysGrabObject>();
rb = ((Component)this).GetComponent<Rigidbody>();
originalScale = ((Component)this).transform.localScale;
originalTag = ((Component)this).gameObject.tag;
originalLayer = ((Component)this).gameObject.layer;
}
public void RequestToggle()
{
if (!PhotonNetwork.InRoom)
{
ApplyToggle(!IsMicro);
}
else if (EmpressMicroCarts.HostOnlyAuthority.Value)
{
((MonoBehaviourPun)this).photonView.RPC("Empress_ToggleRequest", (RpcTarget)2, new object[1] { PhotonNetwork.LocalPlayer.ActorNumber });
}
else
{
((MonoBehaviourPun)this).photonView.RPC("Empress_ToggleExecute", (RpcTarget)0, new object[1] { !IsMicro });
}
}
[PunRPC]
private void Empress_ToggleRequest(int actorNumber)
{
if (PhotonNetwork.IsMasterClient)
{
((MonoBehaviourPun)this).photonView.RPC("Empress_ToggleExecute", (RpcTarget)0, new object[1] { !IsMicro });
EmpressMicroCarts.Logger.LogInfo((object)$"Master accepted toggle request from {actorNumber} for {((Object)((Component)this).gameObject).name}");
}
}
[PunRPC]
private void Empress_ToggleExecute(bool newState)
{
ApplyToggle(newState);
EmpressMicroCarts.Logger.LogInfo((object)("Applied state " + (newState ? "MICRO" : "NORMAL") + " on " + ((Object)((Component)this).gameObject).name));
}
private List<PhysGrabObject> FindItemsInCart()
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
List<PhysGrabObject> list = new List<PhysGrabObject>();
PhysGrabInCart componentInChildren = ((Component)this).GetComponentInChildren<PhysGrabInCart>();
if (!Object.op_Implicit((Object)(object)componentInChildren))
{
return list;
}
BoxCollider component = ((Component)componentInChildren).GetComponent<BoxCollider>();
if (!Object.op_Implicit((Object)(object)component))
{
return list;
}
Bounds bounds = ((Collider)component).bounds;
Vector3 center = ((Bounds)(ref bounds)).center;
bounds = ((Collider)component).bounds;
Vector3 extents = ((Bounds)(ref bounds)).extents;
Quaternion rotation = ((Component)component).transform.rotation;
Collider[] array = Physics.OverlapBox(center, extents, rotation, -1, (QueryTriggerInteraction)2);
foreach (Collider val in array)
{
PhysGrabObject componentInParent = ((Component)val).GetComponentInParent<PhysGrabObject>();
if (Object.op_Implicit((Object)(object)componentInParent) && !((Object)(object)componentInParent == (Object)(object)pgo) && !list.Contains(componentInParent))
{
list.Add(componentInParent);
}
}
return list;
}
private void ApplyToggle(bool micro)
{
//IL_0442: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_055f: Unknown result type (might be due to invalid IL or missing references)
//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: Unknown result type (might be due to invalid IL or missing references)
//IL_0391: Unknown result type (might be due to invalid IL or missing references)
//IL_039e: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)pgo) || !Object.op_Implicit((Object)(object)rb))
{
return;
}
if (micro)
{
IsMicro = true;
cartEnabled = (Object)(object)cart != (Object)null && ((Behaviour)cart).enabled;
if (Object.op_Implicit((Object)(object)cart))
{
((Behaviour)cart).enabled = false;
}
((Component)this).transform.localScale = originalScale * Mathf.Clamp(EmpressMicroCarts.MicroScale.Value, 0.02f, 1f);
if (((Component)this).gameObject.tag != "Phys Grab Object")
{
((Component)this).gameObject.tag = "Phys Grab Object";
}
int num = LayerMask.NameToLayer("PhysGrabObject");
if (num >= 0)
{
((Component)this).gameObject.layer = num;
}
pgo.OverrideMass(Mathf.Max(0.05f, EmpressMicroCarts.MicroMass.Value), Mathf.Max(0.5f, EmpressMicroCarts.MicroMassDuration.Value));
if (EmpressMicroCarts.MicroMinGrabStrength.Value > 0f)
{
pgo.OverrideMinGrabStrength(EmpressMicroCarts.MicroMinGrabStrength.Value, Mathf.Max(0.5f, EmpressMicroCarts.MicroMassDuration.Value));
}
if (EmpressMicroCarts.MicroGrabStrength.Value > 0f)
{
pgo.OverrideGrabStrength(EmpressMicroCarts.MicroGrabStrength.Value, Mathf.Max(0.5f, EmpressMicroCarts.MicroMassDuration.Value));
}
if (EmpressMicroCarts.MicroDrag.Value > 0f)
{
pgo.OverrideDrag(EmpressMicroCarts.MicroDrag.Value, Mathf.Max(0.5f, EmpressMicroCarts.MicroMassDuration.Value));
}
if (EmpressMicroCarts.MicroAngularDrag.Value > 0f)
{
pgo.OverrideAngularDrag(EmpressMicroCarts.MicroAngularDrag.Value, Mathf.Max(0.5f, EmpressMicroCarts.MicroMassDuration.Value));
}
scaledItems.Clear();
List<PhysGrabObject> list = FindItemsInCart();
for (int i = 0; i < list.Count; i++)
{
PhysGrabObject val = list[i];
if (Object.op_Implicit((Object)(object)val))
{
Transform transform = ((Component)val).transform;
int instanceID = ((Object)val).GetInstanceID();
if (!itemOriginalScale.ContainsKey(instanceID))
{
itemOriginalScale[instanceID] = transform.localScale;
}
transform.localScale = itemOriginalScale[instanceID] * Mathf.Clamp(EmpressMicroCarts.MicroScale.Value, 0.02f, 1f);
val.OverrideMass(0.5f, Mathf.Max(0.5f, EmpressMicroCarts.MicroMassDuration.Value));
if (EmpressMicroCarts.MicroDrag.Value > 0f)
{
val.OverrideDrag(EmpressMicroCarts.MicroDrag.Value, Mathf.Max(0.5f, EmpressMicroCarts.MicroMassDuration.Value));
}
if (EmpressMicroCarts.MicroAngularDrag.Value > 0f)
{
val.OverrideAngularDrag(EmpressMicroCarts.MicroAngularDrag.Value, Mathf.Max(0.5f, EmpressMicroCarts.MicroMassDuration.Value));
}
Rigidbody component = ((Component)val).GetComponent<Rigidbody>();
if (Object.op_Implicit((Object)(object)component))
{
component.velocity = Vector3.zero;
component.angularVelocity = Vector3.zero;
}
scaledItems.Add(val);
}
}
if (Object.op_Implicit((Object)(object)rb))
{
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
}
EmpressMicroCarts.Logger.LogInfo((object)$"Scaled {scaledItems.Count} cart contents to micro");
return;
}
IsMicro = false;
((Component)this).transform.localScale = originalScale;
pgo.ResetMass();
if (EmpressMicroCarts.MicroDrag.Value > 0f)
{
pgo.OverrideDrag(0f, 0.01f);
}
if (EmpressMicroCarts.MicroAngularDrag.Value > 0f)
{
pgo.OverrideAngularDrag(0f, 0.01f);
}
if (EmpressMicroCarts.MicroMinGrabStrength.Value > 0f)
{
pgo.OverrideMinGrabStrength(0.01f, 0.01f);
}
if (EmpressMicroCarts.MicroGrabStrength.Value > 0f)
{
pgo.OverrideGrabStrength(1f, 0.01f);
}
for (int j = 0; j < scaledItems.Count; j++)
{
PhysGrabObject val2 = scaledItems[j];
if (Object.op_Implicit((Object)(object)val2))
{
int instanceID2 = ((Object)val2).GetInstanceID();
if (itemOriginalScale.TryGetValue(instanceID2, out var value))
{
((Component)val2).transform.localScale = value;
}
val2.ResetMass();
if (EmpressMicroCarts.MicroDrag.Value > 0f)
{
val2.OverrideDrag(0f, 0.01f);
}
if (EmpressMicroCarts.MicroAngularDrag.Value > 0f)
{
val2.OverrideAngularDrag(0f, 0.01f);
}
}
}
EmpressMicroCarts.Logger.LogInfo((object)"Restored cart contents from micro");
scaledItems.Clear();
if (!string.IsNullOrEmpty(originalTag))
{
((Component)this).gameObject.tag = originalTag;
}
((Component)this).gameObject.layer = originalLayer;
if (Object.op_Implicit((Object)(object)cart))
{
((Behaviour)cart).enabled = cartEnabled;
}
}
}
}