using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Construction;
using HarmonyLib;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("NebulaSnapSelector")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6c43ac7b19d0e48c6ad6a7d3a84164a7da3a27e6")]
[assembly: AssemblyProduct("NebulaSnapSelector")]
[assembly: AssemblyTitle("NebulaSnapSelector")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace NebulaSnapSelector
{
[BepInPlugin("rias.sotf.nebulasnapselector", "Nebula Snap Selector", "1.0.0")]
[BepInProcess("SonsOfTheForest.exe")]
public class Plugin : BasePlugin
{
public const string Guid = "rias.sotf.nebulasnapselector";
public const string Version = "1.0.0";
internal static ConfigEntry<KeyCode> CycleKey;
public override void Load()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
CycleKey = ((BasePlugin)this).Config.Bind<KeyCode>("Controls", "CycleKey", (KeyCode)308, "Hold this key and turn the mouse wheel to cycle through snap points.");
new Harmony("rias.sotf.nebulasnapselector").PatchAll(typeof(SnapPatch));
((BasePlugin)this).AddComponent<ScrollReader>();
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(64, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Nebula Snap Selector ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded. Hold ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<KeyCode>(CycleKey.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" + mouse wheel while placing.");
}
log.LogInfo(val);
}
}
public class ScrollReader : MonoBehaviour
{
private void Update()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKey(Plugin.CycleKey.Value))
{
float y = Input.mouseScrollDelta.y;
if (y > 0f)
{
SnapPatch.PendingScroll = 1;
}
else if (y < 0f)
{
SnapPatch.PendingScroll = -1;
}
}
}
}
[HarmonyPatch(typeof(SnapPointLookupOperation), "TryFindPredictedTarget")]
public static class SnapPatch
{
internal static int PendingScroll;
private static PredictedTarget _selected;
public static void Postfix(List<PredictedTarget> targetList, ref PredictedTarget target, ref bool __result)
{
if (!__result)
{
return;
}
if (target == null || targetList == null || targetList.Count <= 0)
{
_selected = null;
return;
}
int pendingScroll = PendingScroll;
PendingScroll = 0;
int num = IndexOf(targetList, _selected);
if (pendingScroll == 0)
{
if (num < 0)
{
_selected = null;
}
else
{
target = _selected;
}
return;
}
if (num < 0)
{
num = IndexOf(targetList, target);
}
if (num < 0)
{
_selected = null;
return;
}
int num2 = num;
do
{
num = (num + pendingScroll + targetList.Count) % targetList.Count;
if (targetList[num] != null)
{
_selected = targetList[num];
break;
}
}
while (num != num2);
if (_selected != null)
{
target = _selected;
}
}
private static int IndexOf(List<PredictedTarget> list, PredictedTarget t)
{
if (list == null || t == null)
{
return -1;
}
for (int i = 0; i < list.Count; i++)
{
if (list[i] != null && ((Object)list[i]).Equals((Object)(object)t))
{
return i;
}
}
return -1;
}
}
}