using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
[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("CleanCaseboard")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CleanCaseboard")]
[assembly: AssemblyTitle("CleanCaseboard")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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]
[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;
}
}
}
public class CleanCaseboardBehaviour : MonoBehaviour
{
private PinnedItemController _hoveredPic;
private PinnedItemController _pendingSnap;
private readonly List<RaycastResult> _sharedResults = new List<RaycastResult>();
public static CleanCaseboardBehaviour Instance { get; private set; }
private void Awake()
{
Instance = this;
}
private void OnDestroy()
{
if ((Object)(object)Instance == (Object)(object)this)
{
Instance = null;
}
}
private void Update()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(CleanCaseboardPlugin.SnapKey) || Input.GetKeyDown(CleanCaseboardPlugin.SnapButton))
{
_pendingSnap = ResolveTargetCard();
}
}
public void NoteHover(PinnedItemController pic, bool hovered)
{
if (!((Object)(object)pic == (Object)null))
{
if (hovered)
{
_hoveredPic = pic;
}
else if ((Object)(object)_hoveredPic == (Object)(object)pic)
{
_hoveredPic = null;
}
}
}
public void ApplySnap(PinnedItemController pic)
{
if ((Object)(object)pic == (Object)null || (Object)(object)_pendingSnap != (Object)(object)pic)
{
return;
}
_pendingSnap = null;
RectTransform val = ((Il2CppObjectBase)((Component)pic).transform).TryCast<RectTransform>();
if (!((Object)(object)val == (Object)null))
{
Transform parent = ((Transform)val).parent;
if (!((Object)(object)parent == (Object)null))
{
DoSnap(pic, parent, val);
}
}
}
private PinnedItemController ResolveTargetCard()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
EventSystem current = EventSystem.current;
if ((Object)(object)current != (Object)null)
{
PointerEventData val = new PointerEventData(current);
val.position = Vector2.op_Implicit(Input.mousePosition);
_sharedResults.Clear();
current.RaycastAll(val, _sharedResults);
int num = ((_sharedResults.Count < 40) ? _sharedResults.Count : 40);
for (int i = 0; i < num; i++)
{
GameObject gameObject = _sharedResults[i].gameObject;
if (!((Object)(object)gameObject == (Object)null))
{
PinnedItemController val2 = FindPicUpwards(gameObject.transform);
if ((Object)(object)val2 != (Object)null)
{
return val2;
}
}
}
}
if ((Object)(object)_hoveredPic != (Object)null)
{
return _hoveredPic;
}
if ((Object)(object)current != (Object)null)
{
GameObject currentSelectedGameObject = current.currentSelectedGameObject;
if ((Object)(object)currentSelectedGameObject != (Object)null)
{
return FindPicUpwards(currentSelectedGameObject.transform);
}
}
return null;
}
private PinnedItemController FindPicUpwards(Transform t)
{
Transform val = t;
int num = 0;
while ((Object)(object)val != (Object)null && num < 64)
{
PinnedItemController component = ((Component)val).GetComponent<PinnedItemController>();
if ((Object)(object)component != (Object)null)
{
return component;
}
val = val.parent;
num++;
}
return null;
}
private void DoSnap(PinnedItemController pic, Transform pinnedRoot, RectTransform dragTarget)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: 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_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
Vector2 alignPointLocal = GetAlignPointLocal(pinnedRoot, dragTarget);
FindReferences(pinnedRoot, dragTarget, alignPointLocal, out RectTransform refX, out RectTransform refY);
if (!((Object)(object)refX == (Object)null) || !((Object)(object)refY == (Object)null))
{
Vector2 val = alignPointLocal;
if ((Object)(object)refX != (Object)null)
{
val.x = GetAlignPointLocal(pinnedRoot, refX).x;
}
if ((Object)(object)refY != (Object)null)
{
val.y = GetAlignPointLocal(pinnedRoot, refY).y;
}
Vector2 rootLocal = GetRootLocal(pinnedRoot, dragTarget);
Vector2 val2 = alignPointLocal - rootLocal;
WritePosition(pic, dragTarget, val - val2);
}
}
private void WritePosition(PinnedItemController pic, RectTransform dragTarget, Vector2 targetLocal)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: 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_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: 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_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = ((Transform)dragTarget).position;
Vector2 val = (((Object)(object)pic.joint != (Object)null) ? ((AnchoredJoint2D)pic.joint).connectedAnchor : Vector2.zero);
pic.SetPostion(targetLocal);
Vector3 position2 = ((Transform)dragTarget).position;
Vector2 val2 = default(Vector2);
((Vector2)(ref val2))..ctor(position2.x - position.x, position2.y - position.y);
if ((Object)(object)pic.joint != (Object)null && (Object)(object)((Joint2D)pic.joint).connectedBody == (Object)null)
{
Vector2 connectedAnchor = ((AnchoredJoint2D)pic.joint).connectedAnchor;
Vector2 val3 = connectedAnchor - val;
if (((Vector2)(ref val3)).sqrMagnitude < 0.0001f && ((Vector2)(ref val2)).sqrMagnitude > 0.0001f)
{
((AnchoredJoint2D)pic.joint).connectedAnchor = connectedAnchor + val2;
}
}
if ((Object)(object)pic.rb != (Object)null)
{
pic.rb.velocity = Vector2.zero;
pic.rb.angularVelocity = 0f;
pic.rb.position = new Vector2(position2.x, position2.y);
}
}
private bool IsCandidate(RectTransform child, RectTransform dragTarget)
{
if ((Object)(object)child == (Object)null)
{
return false;
}
if ((Object)(object)child == (Object)(object)dragTarget)
{
return false;
}
if (!((Component)child).gameObject.activeInHierarchy)
{
return false;
}
return true;
}
private void FindReferences(Transform pinnedRoot, RectTransform dragTarget, Vector2 origin, out RectTransform refX, out RectTransform refY)
{
//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_0064: 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_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
refX = null;
refY = null;
float value = CleanCaseboardPlugin.SearchRadius.Value;
RectTransform val = null;
RectTransform val2 = null;
float num = float.MaxValue;
float num2 = float.MaxValue;
int childCount = pinnedRoot.childCount;
for (int i = 0; i < childCount; i++)
{
RectTransform val3 = ((Il2CppObjectBase)pinnedRoot.GetChild(i)).TryCast<RectTransform>();
if (IsCandidate(val3, dragTarget))
{
Vector2 alignPointLocal = GetAlignPointLocal(pinnedRoot, val3);
float num3 = Mathf.Abs(origin.x - alignPointLocal.x);
if (num3 <= value && num3 < num)
{
num = num3;
val = val3;
}
float num4 = Mathf.Abs(origin.y - alignPointLocal.y);
if (num4 <= value && num4 < num2)
{
num2 = num4;
val2 = val3;
}
}
}
if ((Object)(object)val != (Object)null)
{
refX = WalkColumnToTop(pinnedRoot, dragTarget, val);
}
if ((Object)(object)val2 != (Object)null)
{
refY = WalkRowToLeft(pinnedRoot, dragTarget, val2);
}
}
private RectTransform WalkColumnToTop(Transform pinnedRoot, RectTransform dragTarget, RectTransform seed)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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)
float value = CleanCaseboardPlugin.LineTolerance.Value;
RectTransform val = seed;
int childCount = pinnedRoot.childCount;
for (int i = 0; i < 8; i++)
{
Vector2 alignPointLocal = GetAlignPointLocal(pinnedRoot, val);
RectTransform val2 = val;
float y = alignPointLocal.y;
for (int j = 0; j < childCount; j++)
{
RectTransform val3 = ((Il2CppObjectBase)pinnedRoot.GetChild(j)).TryCast<RectTransform>();
if (IsCandidate(val3, dragTarget))
{
Vector2 alignPointLocal2 = GetAlignPointLocal(pinnedRoot, val3);
if (Mathf.Abs(alignPointLocal2.x - alignPointLocal.x) <= value && alignPointLocal2.y > y)
{
y = alignPointLocal2.y;
val2 = val3;
}
}
}
if ((Object)(object)val2 == (Object)(object)val)
{
break;
}
val = val2;
}
return val;
}
private RectTransform WalkRowToLeft(Transform pinnedRoot, RectTransform dragTarget, RectTransform seed)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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)
float value = CleanCaseboardPlugin.LineTolerance.Value;
RectTransform val = seed;
int childCount = pinnedRoot.childCount;
for (int i = 0; i < 8; i++)
{
Vector2 alignPointLocal = GetAlignPointLocal(pinnedRoot, val);
RectTransform val2 = val;
float x = alignPointLocal.x;
for (int j = 0; j < childCount; j++)
{
RectTransform val3 = ((Il2CppObjectBase)pinnedRoot.GetChild(j)).TryCast<RectTransform>();
if (IsCandidate(val3, dragTarget))
{
Vector2 alignPointLocal2 = GetAlignPointLocal(pinnedRoot, val3);
if (Mathf.Abs(alignPointLocal2.y - alignPointLocal.y) <= value && alignPointLocal2.x < x)
{
x = alignPointLocal2.x;
val2 = val3;
}
}
}
if ((Object)(object)val2 == (Object)(object)val)
{
break;
}
val = val2;
}
return val;
}
private Vector2 GetRootLocal(Transform pinnedRoot, RectTransform rt)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: 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_001f: 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)
Vector3 val = pinnedRoot.InverseTransformPoint(((Transform)rt).position);
return new Vector2(val.x, val.y);
}
private Vector2 GetAlignPointLocal(Transform pinnedRoot, RectTransform rt)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: 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_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: 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_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)((Transform)rt).parent != (Object)(object)pinnedRoot)
{
return GetRootLocal(pinnedRoot, rt);
}
PinnedItemController component = ((Component)rt).GetComponent<PinnedItemController>();
Vector3 val = default(Vector3);
if ((Object)(object)component != (Object)null && (Object)(object)component.joint != (Object)null)
{
Vector2 anchor = ((AnchoredJoint2D)component.joint).anchor;
((Vector3)(ref val))..ctor(anchor.x, anchor.y, 0f);
}
else
{
Rect rect = rt.rect;
((Vector3)(ref val))..ctor(((Rect)(ref rect)).center.x, ((Rect)(ref rect)).yMax, 0f);
}
Vector3 val2 = ((Transform)rt).localRotation * val;
Vector3 localPosition = ((Transform)rt).localPosition;
return new Vector2(localPosition.x + val2.x, localPosition.y + val2.y);
}
}
[HarmonyPatch]
public static class CleanCaseboardPatches
{
[HarmonyPatch(typeof(PinnedItemController), "LateUpdate")]
[HarmonyPostfix]
public static void PinnedItemController_LateUpdate_Postfix(PinnedItemController __instance)
{
CleanCaseboardBehaviour instance = CleanCaseboardBehaviour.Instance;
if (!((Object)(object)instance == (Object)null))
{
instance.ApplySnap(__instance);
}
}
[HarmonyPatch(typeof(PinnedItemController), "SetHovered")]
[HarmonyPostfix]
public static void PinnedItemController_SetHovered_Postfix(PinnedItemController __instance, bool val)
{
CleanCaseboardBehaviour instance = CleanCaseboardBehaviour.Instance;
if (!((Object)(object)instance == (Object)null))
{
instance.NoteHover(__instance, val);
}
}
}
[BepInPlugin("orionis.cleancaseboard", "Clean Caseboard", "1.0.0")]
public class CleanCaseboardPlugin : BasePlugin
{
public static KeyCode SnapKey = (KeyCode)304;
public static KeyCode SnapButton = (KeyCode)332;
public static ConfigEntry<float> SearchRadius;
public static ConfigEntry<float> LineTolerance;
private static ConfigEntry<string> _snapKeyName;
private static ConfigEntry<string> _snapButtonName;
private Harmony _harmony;
public override void Load()
{
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Expected O, but got Unknown
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Expected O, but got Unknown
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Expected O, but got Unknown
_snapKeyName = ((BasePlugin)this).Config.Bind<string>("Controls", "SnapKey", "LeftShift", "Key pressed while hovering a pinned item to snap it into the nearest row and column. Accepts any Unity KeyCode name, such as LeftShift, Space, or F. Set to None to disable.");
_snapButtonName = ((BasePlugin)this).Config.Bind<string>("Controls", "SnapButton", "JoystickButton2", "Controller button for the same action. JoystickButton2 is X on an Xbox pad. Accepts JoystickButton0 through JoystickButton19. Set to None to disable.");
SearchRadius = ((BasePlugin)this).Config.Bind<float>("Tuning", "SearchRadius", 150f, new ConfigDescription("How far away another item can be and still count as a row or column to join. Larger values snap more eagerly.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(20f, 600f), Array.Empty<object>()));
LineTolerance = ((BasePlugin)this).Config.Bind<float>("Tuning", "LineTolerance", 50f, new ConfigDescription("How far apart two items can be and still count as part of the same row or column. Larger values group ragged rows together.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 200f), Array.Empty<object>()));
RefreshBindings();
_snapKeyName.SettingChanged += OnBindingChanged;
_snapButtonName.SettingChanged += OnBindingChanged;
_harmony = new Harmony("orionis.cleancaseboard");
_harmony.PatchAll();
((BasePlugin)this).AddComponent<CleanCaseboardBehaviour>();
((BasePlugin)this).Log.LogInfo((object)"Clean Caseboard loaded.");
}
private static void OnBindingChanged(object sender, EventArgs e)
{
RefreshBindings();
}
private static void RefreshBindings()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
SnapKey = Parse(_snapKeyName.Value, (KeyCode)304);
SnapButton = Parse(_snapButtonName.Value, (KeyCode)332);
}
private static KeyCode Parse(string name, KeyCode fallback)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: 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_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrEmpty(name))
{
return fallback;
}
if (Enum.TryParse<KeyCode>(name, ignoreCase: true, out KeyCode result))
{
return result;
}
return fallback;
}
}