using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Splatform;
using UnityEngine;
using WxAxW.PinAssistant.Core;
using WxAxW.PinAssistant.Utils;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PinAssistantRadiusPatch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PinAssistantRadiusPatch")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1e2fbbcd-1b9c-4956-8b09-1d343d666154")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PinAssistantRadiusPatch;
[BepInPlugin("Mervil.pinassistantradiuspatch", "PinAssistant Radius Detection Patch", "1.3.0")]
public class MervilsRadiusPlugin : BaseUnityPlugin
{
internal static ConfigEntry<bool> radiusDetectionEnabled;
internal static ConfigEntry<float> radiusDetectionInterval;
internal static ConfigEntry<bool> useFullExplorationRadius;
internal static ConfigEntry<float> radiusDetectionRadius;
internal static ConfigEntry<KeyboardShortcut> radiusDetectionToggleKey;
internal static ConfigEntry<bool> radiusDebugMode;
private void Awake()
{
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Expected O, but got Unknown
radiusDetectionEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RadiusDetectionEnabled", true, "Enable radius-based object detection. If false, only direct visualization detection will be used.");
radiusDetectionInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RadiusDetectionInterval", 1f, "Time in seconds between automatic radius detection scans.");
useFullExplorationRadius = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UsePlayerExploreRadius", true, "If true, radius detection uses the player's current map exploration radius. If false, it uses the configured RadiusDetectionRadius.");
radiusDetectionRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RadiusDetectionRadius", 50f, "The radius around the player to detect pins (in Unity units, ~meters).");
radiusDetectionToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "RadiusDetectionToggleKey", new KeyboardShortcut((KeyCode)292, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Hotkey to toggle radius detection on/off.");
radiusDebugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "RadiusDebugMode", false, "Enable debug logging.");
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "Mervil.pinassistantradiuspatch");
GameObject val = new GameObject("RadiusPinDetector");
val.AddComponent<RadiusPinDetector>();
Object.DontDestroyOnLoad((Object)(object)val);
}
}
public class RadiusPinDetector : MonoBehaviour
{
private class PinState
{
public string NormalizedName;
public ZDOID ZdoID;
public bool Mobile;
public Vector3 LastPosition;
public GameObject PinnedObject;
public PinData Pin;
}
[CompilerGenerated]
private sealed class <RadiusDetectorCoroutine>d__31 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public RadiusPinDetector <>4__this;
private GameObject[] <allObjects>5__1;
private int <currentIndex>5__2;
private int <allObjectsLength>5__3;
private PlatformUserID <localPlatformID>5__4;
private float <batchStartTime>5__5;
private int <batchSize>5__6;
private Vector3 <playerPos>5__7;
private float <scanRadius>5__8;
private float <elapsed>5__9;
private float <waitTime>5__10;
private HashSet<string> <currentAltKeys>5__11;
private HashSet<string> <normalizedKeys>5__12;
private Dictionary<string, string> <oldCustomNameToPrefabName>5__13;
private int <preRestorationCount>5__14;
private List<PinData> <stampList>5__15;
private List<PinData> <pinsList>5__16;
private Dictionary<string, TrieNode<TrackedObject>>.Enumerator <>s__17;
private KeyValuePair<string, TrieNode<TrackedObject>> <kvp>5__18;
private string <key>5__19;
private TrackedObject <trackedObject>5__20;
private string <customName>5__21;
private Exception <ex>5__22;
private int <stamped>5__23;
private List<PinData>.Enumerator <>s__24;
private PinData <pin>5__25;
private string <normalizedPinName>5__26;
private int <archivedCount>5__27;
private Dictionary<string, int> <archivedByType>5__28;
private List<PinData>.Enumerator <>s__29;
private PinData <pin>5__30;
private string <normalizedPinName>5__31;
private string <pinPrefabName>5__32;
private PinState <archivedPinState>5__33;
private Exception <ex>5__34;
private Dictionary<ZDO, ZNetView> <instanceDict>5__35;
private Exception <ex>5__36;
private Exception <ex>5__37;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <RadiusDetectorCoroutine>d__31(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
<allObjects>5__1 = null;
<localPlatformID>5__4 = default(PlatformUserID);
<currentAltKeys>5__11 = null;
<normalizedKeys>5__12 = null;
<oldCustomNameToPrefabName>5__13 = null;
<stampList>5__15 = null;
<pinsList>5__16 = null;
<>s__17 = default(Dictionary<string, TrieNode<TrackedObject>>.Enumerator);
<kvp>5__18 = default(KeyValuePair<string, TrieNode<TrackedObject>>);
<key>5__19 = null;
<trackedObject>5__20 = null;
<customName>5__21 = null;
<ex>5__22 = null;
<>s__24 = default(List<PinData>.Enumerator);
<pin>5__25 = null;
<normalizedPinName>5__26 = null;
<archivedByType>5__28 = null;
<>s__29 = default(List<PinData>.Enumerator);
<pin>5__30 = null;
<normalizedPinName>5__31 = null;
<pinPrefabName>5__32 = null;
<archivedPinState>5__33 = null;
<ex>5__34 = null;
<instanceDict>5__35 = null;
<ex>5__36 = null;
<ex>5__37 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0eb8: Unknown result type (might be due to invalid IL or missing references)
//IL_0ec2: Expected O, but got Unknown
//IL_0d54: Unknown result type (might be due to invalid IL or missing references)
//IL_0d3d: Unknown result type (might be due to invalid IL or missing references)
//IL_0d59: Unknown result type (might be due to invalid IL or missing references)
//IL_0df0: Unknown result type (might be due to invalid IL or missing references)
//IL_0e46: Unknown result type (might be due to invalid IL or missing references)
//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
//IL_03dd: Expected O, but got Unknown
//IL_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_034b: Expected O, but got Unknown
//IL_0096: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_07a2: Unknown result type (might be due to invalid IL or missing references)
//IL_07a7: Unknown result type (might be due to invalid IL or missing references)
//IL_08f3: Unknown result type (might be due to invalid IL or missing references)
//IL_08f8: Unknown result type (might be due to invalid IL or missing references)
//IL_07f1: Unknown result type (might be due to invalid IL or missing references)
//IL_07f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_026c: Expected O, but got Unknown
//IL_09c1: Unknown result type (might be due to invalid IL or missing references)
//IL_09c6: Unknown result type (might be due to invalid IL or missing references)
//IL_09e5: Unknown result type (might be due to invalid IL or missing references)
//IL_09ea: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
goto IL_027d;
case 1:
<>1__state = -1;
goto IL_027d;
case 2:
<>1__state = -1;
goto IL_0ed3;
case 3:
<>1__state = -1;
goto IL_0ed3;
case 4:
<>1__state = -1;
break;
case 5:
{
<>1__state = -1;
goto IL_0ed3;
}
IL_027d:
if ((Object)(object)<>4__this.m_player == (Object)null || (Object)(object)<>4__this.m_minimap == (Object)null || (Object)(object)<>4__this.znetScene == (Object)null)
{
if ((Object)(object)<>4__this.m_player == (Object)null && (Object)(object)Player.m_localPlayer != (Object)null)
{
<>4__this.m_player = Player.m_localPlayer;
<localPlatformID>5__4 = ((IUser)PlatformManager.DistributionPlatform.LocalUser).PlatformUserID;
ModAuthorID = new PlatformUserID("PinAssistantRadiusPatch", ((object)(PlatformUserID)(ref <localPlatformID>5__4)).ToString());
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)("[RadiusPinDetector][INIT] Player found: " + ((Object)<>4__this.m_player).name));
Debug.Log((object)$"[RadiusPinDetector][INIT] Initialized ModAuthorID: {ModAuthorID}");
}
<localPlatformID>5__4 = default(PlatformUserID);
}
if ((Object)(object)<>4__this.m_minimap == (Object)null && (Object)(object)Minimap.instance != (Object)null)
{
<>4__this.m_minimap = Minimap.instance;
<>4__this.minimapPinsField = typeof(Minimap).GetField("m_pins", BindingFlags.Instance | BindingFlags.NonPublic);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][INIT] Minimap instance found.");
}
}
if ((Object)(object)<>4__this.znetScene == (Object)null && (Object)(object)ZNetScene.instance != (Object)null)
{
<>4__this.znetScene = ZNetScene.instance;
<>4__this.znetInstancesField = typeof(ZNetScene).GetField("m_instances", BindingFlags.Instance | BindingFlags.NonPublic);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][INIT] ZNetScene.instance is ready!");
}
}
if (((Object)(object)<>4__this.m_player == (Object)null || (Object)(object)<>4__this.m_minimap == (Object)null || (Object)(object)<>4__this.znetScene == (Object)null) && MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][WAIT] Waiting for asset initiation...");
}
<>2__current = (object)new WaitForSeconds(5f);
<>1__state = 1;
return true;
}
if (!<>4__this.InitializePinAssistantReferences())
{
return false;
}
<allObjects>5__1 = Array.Empty<GameObject>();
<currentIndex>5__2 = 0;
<allObjectsLength>5__3 = 0;
goto IL_0ed3;
IL_0ed3:
if (!<>4__this.AreCoreReferencesValid() && !<>4__this.ReInitializeCoreReferences())
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][WAIT] Core references still unavailable, waiting 5 seconds...");
}
<>2__current = (object)new WaitForSeconds(5f);
<>1__state = 2;
return true;
}
if (!<>4__this.ArePinAssistantReferencesValid())
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][WAIT] PinAssistant references invalid, refreshing...");
}
if (!<>4__this.InitializePinAssistantReferences())
{
return false;
}
}
<batchStartTime>5__5 = Time.realtimeSinceStartup;
if (!MervilsRadiusPlugin.radiusDetectionEnabled.Value)
{
<>2__current = (object)new WaitForSeconds(MervilsRadiusPlugin.radiusDetectionInterval.Value);
<>1__state = 3;
return true;
}
try
{
PinAssistantReflectionHelper.AltDictionaryInstance = PinAssistantReflectionHelper.AltDictionaryProperty.GetValue(PinAssistantReflectionHelper.TrackedObjectsInstance) as Dictionary<string, TrieNode<TrackedObject>>;
if (PinAssistantReflectionHelper.AltDictionaryInstance != null)
{
<currentAltKeys>5__11 = new HashSet<string>(PinAssistantReflectionHelper.AltDictionaryInstance.Keys, StringComparer.OrdinalIgnoreCase);
<normalizedKeys>5__12 = <currentAltKeys>5__11.Select((string k) => NormalizeName(k)).ToHashSet<string>(StringComparer.OrdinalIgnoreCase);
if (!<normalizedKeys>5__12.SetEquals(<>4__this.allowedNames.Where((string name) => !name.EndsWith("_frac"))))
{
<oldCustomNameToPrefabName>5__13 = new Dictionary<string, string>(<>4__this.customNameToPrefabName, StringComparer.OrdinalIgnoreCase);
<>4__this.allowedNames.Clear();
<>4__this.customNameToPrefabName.Clear();
<preRestorationCount>5__14 = <>4__this.removedPinsForRestoration.Count;
<>s__17 = PinAssistantReflectionHelper.AltDictionaryInstance.GetEnumerator();
try
{
while (<>s__17.MoveNext())
{
<kvp>5__18 = <>s__17.Current;
<key>5__19 = NormalizeName(<kvp>5__18.Key);
<>4__this.allowedNames.Add(<key>5__19);
<>4__this.allowedNames.Add(<key>5__19 + "_frac");
<trackedObject>5__20 = <kvp>5__18.Value?.Value;
if (<trackedObject>5__20 != null)
{
<customName>5__21 = NormalizeName(<trackedObject>5__20.Name);
if (!string.IsNullOrEmpty(<customName>5__21))
{
<>4__this.customNameToPrefabName[<customName>5__21] = <key>5__19;
}
<customName>5__21 = null;
}
if (<>4__this.removedPinsForRestoration.ContainsKey(<key>5__19))
{
try
{
<>4__this.RestoreRemovedPins(<key>5__19);
}
catch (Exception ex)
{
<ex>5__22 = ex;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] Failed to restore pins for '{<key>5__19}': {<ex>5__22}. Continuing with other objects.");
<>4__this.removedPinsForRestoration.Remove(<key>5__19);
}
}
<key>5__19 = null;
<trackedObject>5__20 = null;
<kvp>5__18 = default(KeyValuePair<string, TrieNode<TrackedObject>>);
}
}
finally
{
((IDisposable)<>s__17).Dispose();
}
<>s__17 = default(Dictionary<string, TrieNode<TrackedObject>>.Enumerator);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)string.Format("[RadiusPinDetector][INFO] AltDictionary contains {0} entries: {1}", PinAssistantReflectionHelper.AltDictionaryInstance.Count, string.Join(", ", PinAssistantReflectionHelper.AltDictionaryInstance.Keys)));
Debug.Log((object)$"[RadiusPinDetector][INFO] AllowedNames updated to match. Total entries: {<>4__this.allowedNames.Count}. Pins restored from archive: {<preRestorationCount>5__14 - <>4__this.removedPinsForRestoration.Count}.");
}
<stampList>5__15 = <>4__this.GetPinsList();
if (<stampList>5__15 != null)
{
<stamped>5__23 = 0;
<>s__24 = <stampList>5__15.GetEnumerator();
try
{
while (<>s__24.MoveNext())
{
<pin>5__25 = <>s__24.Current;
if (<pin>5__25.m_author == PlatformUserID.None)
{
<normalizedPinName>5__26 = NormalizeName(<pin>5__25.m_name);
if (<>4__this.customNameToPrefabName.ContainsKey(<normalizedPinName>5__26))
{
<pin>5__25.m_author = ModAuthorID;
<stamped>5__23++;
}
<normalizedPinName>5__26 = null;
}
<pin>5__25 = null;
}
}
finally
{
((IDisposable)<>s__24).Dispose();
}
<>s__24 = default(List<PinData>.Enumerator);
if (MervilsRadiusPlugin.radiusDebugMode.Value && <stamped>5__23 > 0)
{
Debug.Log((object)$"[RadiusPinDetector][INIT] Retroactively stamped {<stamped>5__23} existing pins with mod author ID");
}
}
<pinsList>5__16 = <>4__this.GetPinsList();
if (<pinsList>5__16 != null)
{
<archivedCount>5__27 = 0;
<archivedByType>5__28 = new Dictionary<string, int>();
<>s__29 = <pinsList>5__16.ToList().GetEnumerator();
try
{
while (<>s__29.MoveNext())
{
<pin>5__30 = <>s__29.Current;
if (<pin>5__30.m_author == ModAuthorID)
{
<normalizedPinName>5__31 = NormalizeName(<pin>5__30.m_name);
<pinPrefabName>5__32 = (<oldCustomNameToPrefabName>5__13.ContainsKey(<normalizedPinName>5__31) ? <oldCustomNameToPrefabName>5__13[<normalizedPinName>5__31] : null);
if (<pinPrefabName>5__32 != null && !<>4__this.allowedNames.Contains(<pinPrefabName>5__32))
{
if (!<>4__this.removedPinsForRestoration.ContainsKey(<pinPrefabName>5__32))
{
<>4__this.removedPinsForRestoration[<pinPrefabName>5__32] = new List<PinState>();
}
<archivedPinState>5__33 = new PinState
{
ZdoID = ZDOID.None,
NormalizedName = <pinPrefabName>5__32,
Mobile = false,
LastPosition = <pin>5__30.m_pos,
PinnedObject = null,
Pin = <pin>5__30
};
<>4__this.removedPinsForRestoration[<pinPrefabName>5__32].Add(<archivedPinState>5__33);
<archivedCount>5__27++;
if (!<archivedByType>5__28.ContainsKey(<pinPrefabName>5__32))
{
<archivedByType>5__28[<pinPrefabName>5__32] = 0;
}
<archivedByType>5__28[<pinPrefabName>5__32]++;
Minimap.instance.RemovePin(<pin>5__30);
<archivedPinState>5__33 = null;
}
<normalizedPinName>5__31 = null;
<pinPrefabName>5__32 = null;
}
<pin>5__30 = null;
}
}
finally
{
((IDisposable)<>s__29).Dispose();
}
<>s__29 = default(List<PinData>.Enumerator);
if (MervilsRadiusPlugin.radiusDebugMode.Value && <archivedCount>5__27 > 0)
{
Debug.Log((object)string.Format("[RadiusPinDetector][CLEANUP] Archived {0} pins: {1}", <archivedCount>5__27, string.Join(", ", <archivedByType>5__28.Select((KeyValuePair<string, int> kvp) => $"{kvp.Key}({kvp.Value})"))));
}
<archivedByType>5__28 = null;
}
<oldCustomNameToPrefabName>5__13 = null;
<stampList>5__15 = null;
<pinsList>5__16 = null;
}
<currentAltKeys>5__11 = null;
<normalizedKeys>5__12 = null;
}
else if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)"[RadiusPinDetector][WARN] AltDictionary is null! PinAssistant's tracked objects cannot be read.");
}
}
catch (Exception ex)
{
<ex>5__34 = ex;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] PinAssistant reflection failed: {<ex>5__34}. Continuing with existing allowedNames.");
}
try
{
if ((<allObjects>5__1.Length == 0 || <currentIndex>5__2 >= <allObjectsLength>5__3) && (Object)(object)<>4__this.znetScene != (Object)null && <>4__this.znetInstancesField != null)
{
<instanceDict>5__35 = <>4__this.znetInstancesField.GetValue(<>4__this.znetScene) as Dictionary<ZDO, ZNetView>;
if (<instanceDict>5__35 != null)
{
<allObjects>5__1 = (from z in <instanceDict>5__35.Values
where (Object)(object)z != (Object)null && (Object)(object)((Component)z).gameObject != (Object)null
select ((Component)z).gameObject).ToArray();
}
<instanceDict>5__35 = null;
}
}
catch (Exception ex)
{
<ex>5__36 = ex;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] ZNetScene object retrieval failed: {<ex>5__36}. Using empty object array for this cycle.");
<allObjects>5__1 = Array.Empty<GameObject>();
}
<currentIndex>5__2 = 0;
<allObjectsLength>5__3 = <allObjects>5__1.Length;
<batchSize>5__6 = Mathf.Clamp(<allObjectsLength>5__3 / 60, 50, 200);
<playerPos>5__7 = (((Object)(object)<>4__this.m_player != (Object)null) ? ((Component)<>4__this.m_player).transform.position : Vector3.zero);
<>4__this.scanCyclePinsCreated = 0;
<>4__this.scanCycleObjectsCorrelated = 0;
<>4__this.scanCycleObjectsClustered = 0;
<>4__this.scanCycleSkippedAlreadyPinned = 0;
<>4__this.scanCycleSkippedPreviouslyFound = 0;
<>4__this.scanCycleSkippedByType.Clear();
<scanRadius>5__8 = <>4__this.ResolveScanRadius();
<>4__this.UpdateRedundancyDistances();
break;
}
if (<currentIndex>5__2 < <allObjectsLength>5__3)
{
<>4__this.ProcessAllObjectsInBatches(<allObjects>5__1, ref <currentIndex>5__2, <batchSize>5__6, <allObjectsLength>5__3, <scanRadius>5__8, <playerPos>5__7, <>4__this.allowedNames);
<>2__current = null;
<>1__state = 4;
return true;
}
try
{
<>4__this.CleanUpPinCache(<>4__this.allowedNames, <playerPos>5__7, <scanRadius>5__8);
}
catch (Exception ex)
{
<ex>5__37 = ex;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] CleanUpPinCache failed: {<ex>5__37}. Continuing to next scan cycle.");
}
<elapsed>5__9 = Time.realtimeSinceStartup - <batchStartTime>5__5;
<waitTime>5__10 = Mathf.Max(0f, MervilsRadiusPlugin.radiusDetectionInterval.Value - <elapsed>5__9);
<>2__current = (object)new WaitForSeconds(<waitTime>5__10);
<>1__state = 5;
return true;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static PlatformUserID ModAuthorID = PlatformUserID.None;
private Player m_player;
private Minimap m_minimap;
private FieldInfo minimapPinsField;
private ZNetScene znetScene;
private FieldInfo znetInstancesField;
private HashSet<string> allowedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private Dictionary<string, string> customNameToPrefabName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private float redundancyDistanceSame = 1f;
private float redundancyDistanceAny = 1f;
private float lastRedundancyRefreshTime = 0f;
private const float redundancyRefreshInterval = 5f;
private ConfigEntry<float> cachedSameConfigEntry;
private ConfigEntry<float> cachedAnyConfigEntry;
private Dictionary<ZDOID, PinState> alreadyPinned = new Dictionary<ZDOID, PinState>();
private Dictionary<ZDOID, PinState> foundAndNotPinned = new Dictionary<ZDOID, PinState>();
private Dictionary<string, bool> prefabMobilityCache = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
private Dictionary<string, List<PinState>> removedPinsForRestoration = new Dictionary<string, List<PinState>>(StringComparer.OrdinalIgnoreCase);
private Dictionary<Vector3, PinData> existingPinsForCorrelation = new Dictionary<Vector3, PinData>();
private Dictionary<Vector3, PinData> nearbyOrphanedPins = new Dictionary<Vector3, PinData>();
private int scanCyclePinsCreated = 0;
private int scanCycleObjectsCorrelated = 0;
private int scanCycleObjectsClustered = 0;
private int scanCycleSkippedAlreadyPinned = 0;
private int scanCycleSkippedPreviouslyFound = 0;
private Dictionary<string, int> scanCycleSkippedByType = new Dictionary<string, int>();
private static readonly Type[] MobileTypes = new Type[4]
{
typeof(Humanoid),
typeof(Character),
typeof(AnimalAI),
typeof(RandomFlyingBird)
};
private static bool IsMobile(GameObject targetObject)
{
Type[] mobileTypes = MobileTypes;
foreach (Type type in mobileTypes)
{
if ((Object)(object)targetObject.GetComponent(type) != (Object)null)
{
return true;
}
}
return false;
}
private void Start()
{
((MonoBehaviour)this).StartCoroutine(RadiusDetectorCoroutine());
}
private void Update()
{
//IL_000d: 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 (MervilsRadiusPlugin.radiusDetectionToggleKey == null)
{
return;
}
KeyboardShortcut value = MervilsRadiusPlugin.radiusDetectionToggleKey.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
MervilsRadiusPlugin.radiusDetectionEnabled.Value = !MervilsRadiusPlugin.radiusDetectionEnabled.Value;
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][INFO] Radius detection toggled: {MervilsRadiusPlugin.radiusDetectionEnabled.Value}");
}
}
}
[IteratorStateMachine(typeof(<RadiusDetectorCoroutine>d__31))]
private IEnumerator RadiusDetectorCoroutine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <RadiusDetectorCoroutine>d__31(0)
{
<>4__this = this
};
}
private bool InitializePinAssistantReferences()
{
//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
//IL_05f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0612: Unknown result type (might be due to invalid IL or missing references)
Type type = null;
Type type2 = null;
Assembly pinAssistantAssembly = PinAssistantReflectionHelper.GetPinAssistantAssembly();
if (pinAssistantAssembly != null)
{
type = pinAssistantAssembly.GetType("WxAxW.PinAssistant.Core.TrackingHandler");
type2 = pinAssistantAssembly.GetType("WxAxW.PinAssistant.Configuration.ModConfig");
}
else
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)"[RadiusPinDetector][WARN] PinAssistant assembly not found via helper in Coroutine. Attempting full assembly scan.");
}
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (type == null)
{
type = assembly.GetType("WxAxW.PinAssistant.Core.TrackingHandler");
}
if (type2 == null)
{
type2 = assembly.GetType("WxAxW.PinAssistant.Configuration.ModConfig");
}
if (type != null && type2 != null)
{
break;
}
}
}
if (type == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] Could not find WxAxW.PinAssistant.Core.TrackingHandler type.");
return false;
}
if (type2 == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] Could not find WxAxW.PinAssistant.Core.ModConfig type.");
return false;
}
PropertyInfo property = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public);
if (property == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] TrackingHandler.Instance property not found.");
return false;
}
PinAssistantReflectionHelper.TrackingHandlerInstance = property.GetValue(null);
if (PinAssistantReflectionHelper.TrackingHandlerInstance == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] TrackingHandler.Instance is null.");
return false;
}
PropertyInfo property2 = type2.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public);
if (property2 == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] ModConfig.Instance property not found.");
return false;
}
PinAssistantReflectionHelper.ModConfigInstance = property2.GetValue(null);
if (PinAssistantReflectionHelper.ModConfigInstance == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] ModConfig.Instance is null.");
return false;
}
PinAssistantReflectionHelper.AddObjAsPinMethod = type.GetMethod("AddObjAsPin", BindingFlags.Instance | BindingFlags.Public);
if (PinAssistantReflectionHelper.AddObjAsPinMethod == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] AddObjAsPin method not found on TrackingHandler.");
return false;
}
PinAssistantReflectionHelper.AddObjAsPinDelegate = delegate(string name, GameObject gameObj)
{
PinAssistantReflectionHelper.AddObjAsPinMethod.Invoke(PinAssistantReflectionHelper.TrackingHandlerInstance, new object[2] { name, gameObj });
};
PinAssistantReflectionHelper.TrackedObjectsField = type.GetField("m_trackedObjects", BindingFlags.Instance | BindingFlags.NonPublic);
if (PinAssistantReflectionHelper.TrackedObjectsField == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] m_trackedObjects field not found on TrackingHandler.");
return false;
}
PinAssistantReflectionHelper.TrackedObjectsInstance = PinAssistantReflectionHelper.TrackedObjectsField.GetValue(PinAssistantReflectionHelper.TrackingHandlerInstance);
if (PinAssistantReflectionHelper.TrackedObjectsInstance == null)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)"[RadiusPinDetector][WARN] m_trackedObjects from TrackingHandler is null.");
}
return false;
}
PinAssistantReflectionHelper.AltDictionaryProperty = PinAssistantReflectionHelper.TrackedObjectsInstance.GetType().GetProperty("AltDictionary", BindingFlags.Instance | BindingFlags.Public);
if (PinAssistantReflectionHelper.AltDictionaryProperty == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] AltDictionary property not found on m_trackedObjects object.");
return false;
}
Type type3 = pinAssistantAssembly?.GetType("WxAxW.PinAssistant.Core.PinHandler");
if (type3 == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] Could not find WxAxW.PinAssistant.Core.PinHandler type.");
return false;
}
PropertyInfo property3 = type3.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public);
if (property3 == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] PinHandler.Instance property not found.");
return false;
}
PinAssistantReflectionHelper.PinHandlerInstance = property3.GetValue(null);
if (PinAssistantReflectionHelper.PinHandlerInstance == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] PinHandler.Instance is null.");
return false;
}
PinAssistantReflectionHelper.M_PinsField = type3.GetField("m_monitoredPins", BindingFlags.Instance | BindingFlags.NonPublic);
if (PinAssistantReflectionHelper.M_PinsField == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] Could not find PinHandler.m_monitoredPins field via reflection.");
return false;
}
PinAssistantReflectionHelper.RedundancySameProp = type2.GetProperty("RedundancyDistanceSameConfig", BindingFlags.Instance | BindingFlags.Public);
if (PinAssistantReflectionHelper.RedundancySameProp == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] RedundancyDistanceSameConfig property not found on ModConfig.");
return false;
}
PinAssistantReflectionHelper.RedundancyAnyProp = type2.GetProperty("RedundancyDistanceAnyConfig", BindingFlags.Instance | BindingFlags.Public);
if (PinAssistantReflectionHelper.RedundancyAnyProp == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] RedundancyDistanceAnyConfig property not found on ModConfig.");
return false;
}
Type type4 = pinAssistantAssembly?.GetType("WxAxW.PinAssistant.Components.TrackObjectUI");
if (type4 == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] Could not find WxAxW.PinAssistant.Components.TrackObjectUI type.");
return false;
}
PinAssistantReflectionHelper.TrackObjectUIInstance = type4.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public)?.GetValue(null);
if (PinAssistantReflectionHelper.TrackObjectUIInstance == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] TrackObjectUI.Instance property not found or is null.");
return false;
}
PinAssistantReflectionHelper.TrackObjectUI_m_edittingObject = type4.GetField("m_edittingObject", BindingFlags.Instance | BindingFlags.NonPublic);
if (PinAssistantReflectionHelper.TrackObjectUI_m_edittingObject == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] TrackObjectUI.m_edittingObject field not found.");
return false;
}
try
{
Type type5 = pinAssistantAssembly.GetType("WxAxW.PinAssistant.Patches.MinimapPatches");
if (type5 != null)
{
EventInfo @event = type5.GetEvent("OnPinAdd", BindingFlags.Static | BindingFlags.Public);
if (@event != null)
{
Delegate handler = Delegate.CreateDelegate(@event.EventHandlerType, this, "OnPinAddedByPinAssistant");
@event.AddEventHandler(null, handler);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][INIT] Subscribed to PinAssistant's OnPinAdd event");
}
}
else
{
Debug.LogWarning((object)"[RadiusPinDetector][WARN] Could not find OnPinAdd event in MinimapPatches");
}
}
}
catch (Exception arg)
{
Debug.LogError((object)$"[RadiusPinDetector][ERROR] Failed to subscribe to OnPinAdd event: {arg}");
}
existingPinsForCorrelation.Clear();
alreadyPinned.Clear();
foundAndNotPinned.Clear();
List<PinData> pinsList = GetPinsList();
if (pinsList != null)
{
Player localPlayer = Player.m_localPlayer;
long num = ((localPlayer != null) ? localPlayer.GetPlayerID() : 0);
foreach (PinData item in pinsList)
{
if (item.m_author == ModAuthorID && !existingPinsForCorrelation.ContainsKey(item.m_pos))
{
existingPinsForCorrelation[item.m_pos] = item;
}
}
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][INIT] Collected {existingPinsForCorrelation.Count} existing pins for correlation.");
}
}
return true;
}
private void OnPinAddedByPinAssistant(PinData pin)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_001c: 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_004e: Unknown result type (might be due to invalid IL or missing references)
if (!(ModAuthorID == PlatformUserID.None) && pin.m_author == PlatformUserID.None)
{
string key = NormalizeName(pin.m_name);
if (customNameToPrefabName.ContainsKey(key))
{
pin.m_author = ModAuthorID;
}
}
}
private bool ReInitializeCoreReferences()
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][WAIT] Core game references lost, refreshing them...");
}
if ((Object)(object)m_player == (Object)null && (Object)(object)Player.m_localPlayer != (Object)null)
{
m_player = Player.m_localPlayer;
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)("[RadiusPinDetector][INIT] Player reference refreshed: " + ((Object)m_player).name));
}
}
if ((Object)(object)m_minimap == (Object)null && (Object)(object)Minimap.instance != (Object)null)
{
m_minimap = Minimap.instance;
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][INIT] Minimap reference refreshed.");
}
}
if ((Object)(object)znetScene == (Object)null && (Object)(object)ZNetScene.instance != (Object)null)
{
znetScene = ZNetScene.instance;
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][INIT] ZNetScene reference refreshed.");
}
}
return (Object)(object)m_player != (Object)null && (Object)(object)m_minimap != (Object)null && (Object)(object)znetScene != (Object)null;
}
private void ProcessAllObjectsInBatches(GameObject[] allObjects, ref int currentIndex, int batchSize, int allObjectsLength, float scanRadius, Vector3 playerPos, HashSet<string> allowedNames)
{
//IL_0007: 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_0861: Unknown result type (might be due to invalid IL or missing references)
//IL_086f: Unknown result type (might be due to invalid IL or missing references)
//IL_076f: Unknown result type (might be due to invalid IL or missing references)
//IL_0789: Unknown result type (might be due to invalid IL or missing references)
//IL_0797: Unknown result type (might be due to invalid IL or missing references)
//IL_089f: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_038e: Unknown result type (might be due to invalid IL or missing references)
//IL_039b: Unknown result type (might be due to invalid IL or missing references)
//IL_039d: Unknown result type (might be due to invalid IL or missing references)
//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
//IL_054c: Unknown result type (might be due to invalid IL or missing references)
//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
//IL_0409: Unknown result type (might be due to invalid IL or missing references)
//IL_0512: Unknown result type (might be due to invalid IL or missing references)
//IL_0525: Unknown result type (might be due to invalid IL or missing references)
//IL_064f: Unknown result type (might be due to invalid IL or missing references)
//IL_057c: Unknown result type (might be due to invalid IL or missing references)
//IL_0583: Unknown result type (might be due to invalid IL or missing references)
//IL_0588: Unknown result type (might be due to invalid IL or missing references)
//IL_058d: Unknown result type (might be due to invalid IL or missing references)
//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
//IL_066e: Unknown result type (might be due to invalid IL or missing references)
//IL_0670: Unknown result type (might be due to invalid IL or missing references)
//IL_0692: Unknown result type (might be due to invalid IL or missing references)
//IL_0697: Unknown result type (might be due to invalid IL or missing references)
//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
//IL_05ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0602: Unknown result type (might be due to invalid IL or missing references)
//IL_0609: Unknown result type (might be due to invalid IL or missing references)
//IL_060e: Unknown result type (might be due to invalid IL or missing references)
//IL_062a: Unknown result type (might be due to invalid IL or missing references)
//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
//IL_08dc: Unknown result type (might be due to invalid IL or missing references)
//IL_08fd: Unknown result type (might be due to invalid IL or missing references)
//IL_07b5: Unknown result type (might be due to invalid IL or missing references)
//IL_080f: Unknown result type (might be due to invalid IL or missing references)
//IL_07df: Unknown result type (might be due to invalid IL or missing references)
//IL_07ef: Unknown result type (might be due to invalid IL or missing references)
//IL_084b: Unknown result type (might be due to invalid IL or missing references)
//IL_0829: Unknown result type (might be due to invalid IL or missing references)
if (currentIndex == 0 && existingPinsForCorrelation.Count > 0)
{
nearbyOrphanedPins = existingPinsForCorrelation.Where(delegate(KeyValuePair<Vector3, PinData> pin)
{
//IL_0002: 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_0012: Unknown result type (might be due to invalid IL or missing references)
Vector3 val7 = pin.Key - playerPos;
return ((Vector3)(ref val7)).sqrMagnitude <= scanRadius * scanRadius;
}).ToDictionary((KeyValuePair<Vector3, PinData> pin) => pin.Key, (KeyValuePair<Vector3, PinData> pin) => pin.Value);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][SCAN] Found {nearbyOrphanedPins.Count} orphaned pins within scan radius");
}
}
int num = Math.Min(currentIndex + batchSize, allObjectsLength);
for (int i = currentIndex; i < num; i++)
{
GameObject gameObject = allObjects[i];
if ((Object)(object)gameObject == (Object)null || !gameObject.activeInHierarchy)
{
continue;
}
Vector3 val = gameObject.transform.position - playerPos;
if (((Vector3)(ref val)).sqrMagnitude > scanRadius * scanRadius)
{
continue;
}
ZNetView component = gameObject.GetComponent<ZNetView>();
if ((Object)(object)component == (Object)null)
{
continue;
}
ZDOID val2 = component.GetZDO()?.m_uid ?? ZDOID.None;
if (val2 == ZDOID.None)
{
continue;
}
if (alreadyPinned.TryGetValue(val2, out var value) && !value.Mobile)
{
scanCycleSkippedAlreadyPinned++;
continue;
}
string key = NormalizeName(((Object)gameObject).name);
if (foundAndNotPinned.TryGetValue(val2, out var value2) && !value2.Mobile)
{
scanCycleSkippedPreviouslyFound++;
if (!scanCycleSkippedByType.ContainsKey(key))
{
scanCycleSkippedByType[key] = 0;
}
scanCycleSkippedByType[key]++;
continue;
}
ZDO zDO = component.GetZDO();
int num2 = ((zDO != null) ? zDO.GetPrefab() : 0);
object obj;
if (num2 == 0)
{
obj = null;
}
else
{
ZNetScene instance = ZNetScene.instance;
obj = ((instance != null) ? instance.GetPrefab(num2) : null);
}
GameObject val3 = (GameObject)obj;
string raw = ((val3 != null) ? ((Object)val3).name : null) ?? ((Object)gameObject).name;
string text = NormalizeName(raw);
if (text.EndsWith("_frac"))
{
string undamagedName = text.Substring(0, text.Length - 5);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)("[RadiusPinDetector][DETECT] Found damaged resource node '" + text + "', looking for pin from '" + undamagedName + "'"));
}
KeyValuePair<ZDOID, PinState> keyValuePair = alreadyPinned.FirstOrDefault(delegate(KeyValuePair<ZDOID, PinState> kvp)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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_003f: Unknown result type (might be due to invalid IL or missing references)
int result;
if (kvp.Value.NormalizedName == undamagedName)
{
Vector3 val6 = kvp.Value.LastPosition - gameObject.transform.position;
result = ((((Vector3)(ref val6)).sqrMagnitude < 0.1f) ? 1 : 0);
}
else
{
result = 0;
}
return (byte)result != 0;
});
if (keyValuePair.Value != null)
{
PinState value3 = keyValuePair.Value;
alreadyPinned.Remove(keyValuePair.Key);
value3.ZdoID = val2;
value3.NormalizedName = text;
value3.PinnedObject = gameObject;
value3.LastPosition = gameObject.transform.position;
alreadyPinned[val2] = value3;
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][DETECT] Transferred pin from {undamagedName} to {text} (ID={val2})");
}
continue;
}
}
if (!allowedNames.Contains(text))
{
continue;
}
bool value4 = false;
if (!prefabMobilityCache.TryGetValue(text, out value4))
{
value4 = IsMobile(gameObject);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][DETECT] First '{text}' found. Is Mobile: {value4}");
}
prefabMobilityCache[text] = value4;
}
PinData val4 = null;
if (nearbyOrphanedPins.Count > 0)
{
Vector3 objectPos = gameObject.transform.position;
KeyValuePair<Vector3, PinData> keyValuePair2 = nearbyOrphanedPins.FirstOrDefault(delegate(KeyValuePair<Vector3, PinData> kvp)
{
//IL_0002: 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_0012: Unknown result type (might be due to invalid IL or missing references)
Vector3 val5 = kvp.Key - objectPos;
return ((Vector3)(ref val5)).sqrMagnitude < 0.1f;
});
if (keyValuePair2.Value != null)
{
val4 = keyValuePair2.Value;
existingPinsForCorrelation.Remove(keyValuePair2.Key);
nearbyOrphanedPins.Remove(keyValuePair2.Key);
scanCycleObjectsCorrelated++;
}
}
PinState value5 = null;
bool flag = false;
if (alreadyPinned.TryGetValue(val2, out value5))
{
if (!value5.Mobile)
{
continue;
}
val = gameObject.transform.position - value5.LastPosition;
if (!(((Vector3)(ref val)).sqrMagnitude > 1f))
{
continue;
}
value5.LastPosition = gameObject.transform.position;
if (value5.Pin != null)
{
Vector3 position = gameObject.transform.position;
value5.Pin.m_pos = new Vector3(position.x, value5.Pin.m_pos.y, position.z);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][SCAN] Mobile object '{text}' (ID={val2}) moved; pin updated.");
}
}
}
else
{
if (!value4 && foundAndNotPinned.TryGetValue(val2, out value5))
{
continue;
}
value5 = new PinState
{
ZdoID = val2,
NormalizedName = text,
Mobile = value4,
LastPosition = gameObject.transform.position,
PinnedObject = gameObject,
Pin = val4
};
if (val4 == null)
{
List<PinData> pinsList = GetPinsList();
if (pinsList == null)
{
alreadyPinned.Remove(val2);
foundAndNotPinned.Remove(val2);
continue;
}
int count = pinsList.Count;
float num3 = (value4 ? 0f : redundancyDistanceSame);
float num4 = (value4 ? 0f : redundancyDistanceAny);
try
{
PinAssistantReflectionHelper.AddObjAsPinDelegate?.Invoke(((Object)gameObject).name, gameObject);
}
catch (Exception arg)
{
GameObject obj2 = gameObject;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] AddObjAsPin failed for '{((obj2 != null) ? ((Object)obj2).name : null)}' (ID={val2}): {arg}. Cannot proceed with PinData capture.");
alreadyPinned.Remove(val2);
foundAndNotPinned.Remove(val2);
continue;
}
try
{
value5.Pin = CaptureNewlyCreatedPin(gameObject.transform.position, count, pinsList);
if (value5.Pin != null)
{
alreadyPinned[val2] = value5;
foundAndNotPinned.Remove(val2);
scanCyclePinsCreated++;
continue;
}
alreadyPinned.Remove(val2);
if (!value4)
{
foundAndNotPinned[val2] = value5;
scanCycleObjectsClustered++;
}
else
{
foundAndNotPinned.Remove(val2);
}
}
catch (Exception arg2)
{
alreadyPinned.Remove(val2);
foundAndNotPinned.Remove(val2);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
GameObject obj3 = gameObject;
Debug.LogWarning((object)$"[RadiusPinDetector][WARN] Failed to capture PinData reference for '{((obj3 != null) ? ((Object)obj3).name : null)}' (ID={val2}), entry removed/cleaned from tracking: {arg2}");
}
}
}
else if (val4 != null && value5 != null && value5.Pin != null)
{
alreadyPinned[val2] = value5;
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][SCAN] Added correlated pin to alreadyPinned for {text} (ID={val2})");
}
}
}
}
if (num >= allObjectsLength && MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][SCAN] Scan complete - Created: {scanCyclePinsCreated}, Correlated: {scanCycleObjectsCorrelated}, Clustered: {scanCycleObjectsClustered}, Skipped: {scanCycleSkippedAlreadyPinned} already pinned + {scanCycleSkippedPreviouslyFound} previously found");
if (scanCycleSkippedByType.Count > 0)
{
Debug.Log((object)("[RadiusPinDetector][SCAN] Previously found breakdown: " + string.Join(", ", scanCycleSkippedByType.Select((KeyValuePair<string, int> kvp) => $"{kvp.Key}({kvp.Value})"))));
}
}
currentIndex = num;
}
private void CleanUpPinCache(HashSet<string> allowedNames, Vector3 playerPos, float scanRadius)
{
//IL_0007: 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_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
int num = 0;
int num2 = 0;
if ((Object)(object)ZNetScene.instance == (Object)null)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][CLEANUP] ZNetScene.instance is null, skipping cleanup.");
}
return;
}
HashSet<ZDOID> activeZDOIDs = (from zdo in (znetInstancesField?.GetValue(ZNetScene.instance) as Dictionary<ZDO, ZNetView>)?.Keys
where zdo != null
select zdo.m_uid).ToHashSet();
var list = (from item in alreadyPinned.Select(delegate(KeyValuePair<ZDOID, PinState> pair)
{
//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_0026: 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_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: 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_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
ZDOID key = pair.Key;
PinState value2 = pair.Value;
string normalizedName = value2.NormalizedName;
if (activeZDOIDs != null && !activeZDOIDs.Contains(key))
{
Vector3 val3 = value2.LastPosition - playerPos;
if (((Vector3)(ref val3)).sqrMagnitude <= scanRadius * scanRadius)
{
return new
{
Key = key,
Name = normalizedName,
IsDestroyed = true,
ShouldRemove = true,
Pin = value2.Pin
};
}
return new
{
Key = key,
Name = normalizedName,
IsDestroyed = true,
ShouldRemove = false,
Pin = value2.Pin
};
}
ZNetScene instance = ZNetScene.instance;
GameObject val4 = ((instance != null) ? instance.FindInstance(key) : null);
if ((Object)(object)val4 == (Object)null || (Object)(object)val4.gameObject == (Object)null)
{
if (!allowedNames.Contains(normalizedName))
{
return new
{
Key = key,
Name = normalizedName,
IsDestroyed = false,
ShouldRemove = true,
Pin = value2.Pin
};
}
return new
{
Key = key,
Name = normalizedName,
IsDestroyed = false,
ShouldRemove = false,
Pin = value2.Pin
};
}
return (!allowedNames.Contains(normalizedName)) ? new
{
Key = key,
Name = normalizedName,
IsDestroyed = false,
ShouldRemove = true,
Pin = value2.Pin
} : new
{
Key = key,
Name = normalizedName,
IsDestroyed = false,
ShouldRemove = false,
Pin = value2.Pin
};
})
where item.ShouldRemove
select item).ToList();
foreach (var item in list)
{
if (!alreadyPinned.TryGetValue(item.Key, out var value))
{
continue;
}
string name = item.Name;
if (item.IsDestroyed && value.Pin != null)
{
Vector3 removedPosition = value.Pin.m_pos;
List<ZDOID> list2 = (from kvp in foundAndNotPinned.Where(delegate(KeyValuePair<ZDOID, PinState> kvp)
{
//IL_0007: 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_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)
Vector3 val2 = kvp.Value.LastPosition - removedPosition;
return ((Vector3)(ref val2)).sqrMagnitude < redundancyDistanceSame * redundancyDistanceSame;
})
select kvp.Key).ToList();
foreach (ZDOID item2 in list2)
{
string text = (foundAndNotPinned.ContainsKey(item2) ? foundAndNotPinned[item2].NormalizedName : item.Name);
foundAndNotPinned.Remove(item2);
num2++;
}
}
if (value.Pin != null)
{
Minimap.instance.RemovePin(value.Pin);
value.Pin = null;
num++;
}
alreadyPinned.Remove(item.Key);
}
var list3 = foundAndNotPinned.Select((KeyValuePair<ZDOID, PinState> pair) => new
{
Key = pair.Key,
Name = pair.Value.NormalizedName
}).Where(item =>
{
//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_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: 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_0063: 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)
if (item.Key == ZDOID.None)
{
return true;
}
if (activeZDOIDs != null && !activeZDOIDs.Contains(item.Key))
{
PinState pinState = foundAndNotPinned[item.Key];
Vector3 val = pinState.LastPosition - playerPos;
if (((Vector3)(ref val)).sqrMagnitude <= scanRadius * scanRadius)
{
return true;
}
return false;
}
return (!allowedNames.Contains(item.Name)) ? true : false;
}).ToList();
foreach (var item3 in list3)
{
if (foundAndNotPinned.Remove(item3.Key))
{
num2++;
}
}
if (MervilsRadiusPlugin.radiusDebugMode.Value && (num > 0 || num2 > 0))
{
Debug.Log((object)$"[RadiusPinDetector][CLEANUP] Removed {num} pins, cleared {num2} foundAndNotPinned entries");
}
if (nearbyOrphanedPins.Count <= 0)
{
return;
}
int num3 = 0;
foreach (PinData value3 in nearbyOrphanedPins.Values)
{
if (value3.m_author == ModAuthorID)
{
Minimap.instance.RemovePin(value3);
existingPinsForCorrelation.Remove(value3.m_pos);
num3++;
}
}
if (MervilsRadiusPlugin.radiusDebugMode.Value && num3 > 0)
{
Debug.Log((object)$"[RadiusPinDetector][CLEANUP] Removed {num3} orphaned pins");
}
nearbyOrphanedPins.Clear();
}
private void RestoreRemovedPins(string normalizedName)
{
//IL_007d: 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_00c5: 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_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
if (!removedPinsForRestoration.TryGetValue(normalizedName, out var value))
{
return;
}
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][RESTORE] Restoring {value.Count} pins for retracked object '{normalizedName}'.");
}
foreach (PinState item in value)
{
if (item.Pin != null)
{
try
{
Minimap.instance.AddPin(item.Pin.m_pos, item.Pin.m_type, item.Pin.m_name, item.Pin.m_save, item.Pin.m_checked, item.Pin.m_ownerID, item.Pin.m_author);
}
catch (Exception arg)
{
Debug.LogError((object)$"[RadiusPinDetector][ERROR] Failed to add pin to minimap for '{normalizedName}': {arg}. Skipping this pin.");
continue;
}
List<PinData> pinsList = GetPinsList();
int beforeCount = (pinsList?.Count ?? 1) - 1;
PinData val = CaptureNewlyCreatedPin(item.Pin.m_pos, beforeCount, pinsList);
if (val != null)
{
item.Pin = val;
existingPinsForCorrelation[val.m_pos] = val;
}
if (item.ZdoID != ZDOID.None)
{
alreadyPinned[item.ZdoID] = item;
}
else if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)("[RadiusPinDetector][WARN] Archived PinState for '" + item.NormalizedName + "' had invalid ZDOID, not re-added to alreadyPinned."));
}
}
}
removedPinsForRestoration.Remove(normalizedName);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)("[RadiusPinDetector][RESTORE] Cleared archived pins for '" + normalizedName + "' from restoration cache."));
}
}
private PinData CaptureNewlyCreatedPin(Vector3 expectedPosition, int beforeCount, List<PinData> pinsList)
{
//IL_002d: 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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
if (pinsList == null)
{
return null;
}
float num = 0.1f;
float num2 = num * num;
for (int i = beforeCount; i < pinsList.Count; i++)
{
PinData val = pinsList[i];
if (val != null)
{
Vector3 val2 = val.m_pos - expectedPosition;
if (((Vector3)(ref val2)).sqrMagnitude < num2)
{
return val;
}
}
}
return null;
}
private float ResolveScanRadius()
{
if (!MervilsRadiusPlugin.useFullExplorationRadius.Value)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][RADIUS] Using configured radius: {MervilsRadiusPlugin.radiusDetectionRadius.Value}");
}
return Mathf.Max(1f, MervilsRadiusPlugin.radiusDetectionRadius.Value);
}
float lastCapturedRadius = PinAssistantPatches.ValheimMinimapPatches.GetLastCapturedRadius();
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][RADIUS] Player's exploration radius is: {lastCapturedRadius}");
}
return Mathf.Max(1f, lastCapturedRadius);
}
private static string NormalizeName(string raw)
{
if (string.IsNullOrEmpty(raw))
{
return string.Empty;
}
string text = raw.ToLowerInvariant();
return text.Replace("(clone)", "").Trim();
}
private List<PinData> GetPinsList()
{
if (minimapPinsField == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] GetPinsList: minimapPinsField is null! Reflection failed during initialization.");
return null;
}
if ((Object)(object)m_minimap == (Object)null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] GetPinsList: m_minimap is null! Minimap instance lost.");
return null;
}
List<PinData> list = minimapPinsField.GetValue(m_minimap) as List<PinData>;
if (list == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] GetPinsList: Reflection returned null. Field exists but value is null. This should never happen!");
Debug.LogError((object)("[RadiusPinDetector][ERROR] Raw field value: " + (minimapPinsField.GetValue(m_minimap)?.GetType()?.Name ?? "null")));
}
return list;
}
private void UpdateRedundancyDistances()
{
if (Time.time - lastRedundancyRefreshTime < 5f)
{
return;
}
lastRedundancyRefreshTime = Time.time;
if (PinAssistantReflectionHelper.RedundancySameProp == null && PinAssistantReflectionHelper.RedundancyAnyProp == null)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)"[RadiusPinDetector][WARN] Unable to update redundancy distances -- Properties are null.");
}
return;
}
float num = redundancyDistanceSame;
float num2 = redundancyDistanceAny;
if (cachedSameConfigEntry == null && PinAssistantReflectionHelper.RedundancySameProp != null)
{
cachedSameConfigEntry = PinAssistantReflectionHelper.RedundancySameProp.GetValue(PinAssistantReflectionHelper.ModConfigInstance) as ConfigEntry<float>;
}
if (cachedAnyConfigEntry == null && PinAssistantReflectionHelper.RedundancyAnyProp != null)
{
cachedAnyConfigEntry = PinAssistantReflectionHelper.RedundancyAnyProp.GetValue(PinAssistantReflectionHelper.ModConfigInstance) as ConfigEntry<float>;
}
if (cachedSameConfigEntry != null)
{
redundancyDistanceSame = cachedSameConfigEntry.Value;
}
if (cachedAnyConfigEntry != null)
{
redundancyDistanceAny = cachedAnyConfigEntry.Value;
}
if (redundancyDistanceSame != num || redundancyDistanceAny != num2)
{
foundAndNotPinned.Clear();
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][SCAN] Redundancy distances changed (old: same={num}, any={num2} | new: same={redundancyDistanceSame}, any={redundancyDistanceAny}). Clearing foundAndNotPinned cache.");
}
}
}
private bool AreCoreReferencesValid()
{
return (Object)(object)m_player != (Object)null && (Object)(object)m_minimap != (Object)null && (Object)(object)znetScene != (Object)null;
}
private bool ArePinAssistantReferencesValid()
{
if (PinAssistantReflectionHelper.TrackingHandlerInstance == null)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][DEBUG] TrackingHandlerInstance is null");
}
return false;
}
if (PinAssistantReflectionHelper.TrackingHandlerInstance == null)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][DEBUG] PinHandlerInstance is null");
}
return false;
}
if (PinAssistantReflectionHelper.ModConfigInstance == null)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][DEBUG] ModConfigInstance is null");
}
return false;
}
if (PinAssistantReflectionHelper.TrackObjectUIInstance == null)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][DEBUG] TrackObjectUIInstance is null");
}
return false;
}
if (PinAssistantReflectionHelper.TrackedObjectsInstance == null)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][DEBUG] TrackedObjectsInstance is null");
}
return false;
}
if (PinAssistantReflectionHelper.AltDictionaryInstance == null)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)"[RadiusPinDetector][DEBUG] AltDictionaryInstance is null");
}
return false;
}
object trackObjectUIInstance = PinAssistantReflectionHelper.TrackObjectUIInstance;
Object val = (Object)((trackObjectUIInstance is Object) ? trackObjectUIInstance : null);
if (val != null && val == (Object)null)
{
return false;
}
try
{
int count = PinAssistantReflectionHelper.AltDictionaryInstance.Count;
return true;
}
catch
{
return false;
}
}
}
public static class PinAssistantReflectionHelper
{
public static MethodInfo AddObjAsPinMethod;
public static Action<string, GameObject> AddObjAsPinDelegate;
public static FieldInfo M_PinsField;
public static FieldInfo TrackedObjectsField;
public static FieldInfo TrackObjectUI_m_edittingObject;
public static PropertyInfo AltDictionaryProperty;
public static PropertyInfo RedundancySameProp;
public static PropertyInfo RedundancyAnyProp;
public static object TrackingHandlerInstance;
public static object PinHandlerInstance;
public static object ModConfigInstance;
public static object TrackObjectUIInstance;
public static object TrackedObjectsInstance;
public static Dictionary<string, TrieNode<TrackedObject>> AltDictionaryInstance;
private static Assembly s_pinAssistantAssembly;
public static Assembly GetPinAssistantAssembly()
{
if (s_pinAssistantAssembly == null)
{
s_pinAssistantAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "WxAxW.PinAssistant");
}
return s_pinAssistantAssembly;
}
}
public static class PinAssistantPatches
{
public static class PinHandlerPatches
{
public static class CheckPinPositionExist
{
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return (PinAssistantReflectionHelper.GetPinAssistantAssembly()?.GetType("WxAxW.PinAssistant.Core.PinHandler"))?.GetMethod("CheckPinPositionExist", BindingFlags.Instance | BindingFlags.Public);
}
[HarmonyPrefix]
public static bool Prefix(object __instance, Vector3 pinPos, ref bool __result, ref bool __runOriginal)
{
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
if (!MervilsRadiusPlugin.radiusDetectionEnabled.Value)
{
__runOriginal = true;
return true;
}
long num = 0L;
bool flag = false;
if ((Object)(object)Player.m_localPlayer != (Object)null)
{
num = Player.m_localPlayer.GetPlayerID();
flag = true;
}
if (!flag)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)"[RadiusPinDetector][WARN] PatchCheckPinPositionExist: Local player not yet available. Letting original method run for now.");
}
__runOriginal = true;
return true;
}
if (PinAssistantReflectionHelper.M_PinsField == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] PatchCheckPinPositionExist: PinAssistantReflectionHelper.M_PinsField is null. Letting original method run.");
__runOriginal = true;
return true;
}
if (!(PinAssistantReflectionHelper.M_PinsField.GetValue(PinAssistantReflectionHelper.PinHandlerInstance) is Dictionary<Vector3, PinData> dictionary))
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)"[RadiusPinDetector][WARN] PatchCheckPinPositionExist: PinHandler's m_monitoredPins dictionary is null. Letting original method run.");
}
__runOriginal = true;
return true;
}
if (dictionary.TryGetValue(pinPos, out var value))
{
if (value.m_ownerID == 0L || value.m_ownerID == num)
{
__result = true;
}
else
{
__result = false;
}
}
else
{
__result = false;
}
__runOriginal = false;
return false;
}
}
public static class CheckValidPinPosition
{
[HarmonyTargetMethod]
private static MethodBase TargetMethod()
{
return (PinAssistantReflectionHelper.GetPinAssistantAssembly()?.GetType("WxAxW.PinAssistant.Core.PinHandler"))?.GetMethod("CheckValidPinPosition", BindingFlags.Instance | BindingFlags.Public);
}
[HarmonyPrefix]
public static bool Prefix(object __instance, Vector3 pinToAdd, string pinName, float redundancyDistance, bool allPins, ref bool __result, ref bool __runOriginal)
{
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
if (!MervilsRadiusPlugin.radiusDetectionEnabled.Value)
{
__runOriginal = true;
return true;
}
long num = 0L;
bool flag = false;
if ((Object)(object)Player.m_localPlayer != (Object)null)
{
num = Player.m_localPlayer.GetPlayerID();
flag = true;
}
if (!flag)
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)"[RadiusPinDetector][WARN] PatchCheckValidPinPosition: Local player not yet available. Letting original method run for now.");
}
__runOriginal = true;
return true;
}
if (PinAssistantReflectionHelper.M_PinsField == null)
{
Debug.LogError((object)"[RadiusPinDetector][ERROR] PatchCheckValidPinPosition: PinAssistantReflectionHelper.M_PinsField is null. Letting original method run.");
__runOriginal = true;
return true;
}
if (!(PinAssistantReflectionHelper.M_PinsField.GetValue(PinAssistantReflectionHelper.PinHandlerInstance) is Dictionary<Vector3, PinData> dictionary))
{
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)"[RadiusPinDetector][WARN] PatchCheckValidPinPosition: PinHandler's m_monitoredPins dictionary is null. Letting original method run.");
}
__runOriginal = true;
return true;
}
foreach (PinData value in dictionary.Values)
{
if ((value.m_ownerID == 0L || value.m_ownerID == num) && (allPins || value.m_name.IndexOf(pinName, StringComparison.OrdinalIgnoreCase) != -1) && !CheckValidDistance(pinToAdd, value.m_pos, redundancyDistance))
{
__result = false;
__runOriginal = false;
return false;
}
}
__result = true;
__runOriginal = false;
return false;
}
}
private static bool CheckValidDistance(Vector3 v1, Vector3 v2, float redundancyDistance)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return Get2DDistanceSquared(v1, v2) > redundancyDistance * redundancyDistance;
}
private static float Get2DDistanceSquared(Vector3 v1, Vector3 v2)
{
//IL_0001: 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_000f: 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)
float num = v2.x - v1.x;
float num2 = v2.z - v1.z;
return num * num + num2 * num2;
}
}
[HarmonyPatch(typeof(TrackingHandler))]
public static class TrackingHandlerPatches
{
[HarmonyPrefix]
[HarmonyPatch("PinLookedObject")]
public static bool PinLookedObject_Prefix(TrackingHandler __instance, float lookDistance, ref bool __runOriginal)
{
if (MervilsRadiusPlugin.radiusDetectionEnabled.Value)
{
__runOriginal = false;
return false;
}
__runOriginal = true;
return true;
}
}
[HarmonyPatch(typeof(Minimap))]
public static class ValheimMinimapPatches
{
private static float lastCapturedRadius = 50f;
[HarmonyPatch("Explore", new Type[]
{
typeof(Vector3),
typeof(float)
})]
[HarmonyPrefix]
public static void Explore_Prefix(Vector3 p, float radius)
{
if (radius != lastCapturedRadius)
{
lastCapturedRadius = radius;
}
}
public static float GetLastCapturedRadius()
{
return lastCapturedRadius;
}
}
}