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;
public bool WasManuallyRemoved;
public string MatchedTrackedObjectName;
}
private struct ExactMatchStatus
{
public bool Current;
public bool Previous;
}
[CompilerGenerated]
private sealed class <RadiusDetectorCoroutine>d__34 : 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 bool <setHasChanged>5__13;
private Dictionary<string, string> <oldCustomNameToPrefabName>5__14;
private int <preRestorationCount>5__15;
private Dictionary<string, TrieNode<TrackedObject>>.Enumerator <>s__16;
private KeyValuePair<string, TrieNode<TrackedObject>> <kvp>5__17;
private string <key>5__18;
private TrackedObject <trackedObject>5__19;
private bool <currentExactMatch>5__20;
private bool <needsUpdate>5__21;
private Exception <ex>5__22;
private bool <hadPreviousValue>5__23;
private bool <previousExactMatch>5__24;
private string <customName>5__25;
private Exception <ex>5__26;
private List<PinData> <stampList>5__27;
private List<PinData> <pinsList>5__28;
private int <stamped>5__29;
private List<PinData>.Enumerator <>s__30;
private PinData <pin>5__31;
private string <normalizedPinName>5__32;
private int <archivedCount>5__33;
private Dictionary<string, int> <archivedByType>5__34;
private List<PinData>.Enumerator <>s__35;
private PinData <pin>5__36;
private string <normalizedPinName>5__37;
private string <pinPrefabName>5__38;
private PinState <archivedPinState>5__39;
private Exception <ex>5__40;
private Dictionary<ZDO, ZNetView> <instanceDict>5__41;
private Exception <ex>5__42;
private Exception <ex>5__43;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <RadiusDetectorCoroutine>d__34(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__14 = null;
<>s__16 = default(Dictionary<string, TrieNode<TrackedObject>>.Enumerator);
<kvp>5__17 = default(KeyValuePair<string, TrieNode<TrackedObject>>);
<key>5__18 = null;
<trackedObject>5__19 = null;
<ex>5__22 = null;
<customName>5__25 = null;
<ex>5__26 = null;
<stampList>5__27 = null;
<pinsList>5__28 = null;
<>s__30 = default(List<PinData>.Enumerator);
<pin>5__31 = null;
<normalizedPinName>5__32 = null;
<archivedByType>5__34 = null;
<>s__35 = default(List<PinData>.Enumerator);
<pin>5__36 = null;
<normalizedPinName>5__37 = null;
<pinPrefabName>5__38 = null;
<archivedPinState>5__39 = null;
<ex>5__40 = null;
<instanceDict>5__41 = null;
<ex>5__42 = null;
<ex>5__43 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_108e: Unknown result type (might be due to invalid IL or missing references)
//IL_1098: Expected O, but got Unknown
//IL_0f2a: Unknown result type (might be due to invalid IL or missing references)
//IL_0f13: Unknown result type (might be due to invalid IL or missing references)
//IL_0f2f: Unknown result type (might be due to invalid IL or missing references)
//IL_0fc6: Unknown result type (might be due to invalid IL or missing references)
//IL_101c: Unknown result type (might be due to invalid IL or missing references)
//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
//IL_03fe: Expected O, but got Unknown
//IL_0362: Unknown result type (might be due to invalid IL or missing references)
//IL_036c: 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_0965: Unknown result type (might be due to invalid IL or missing references)
//IL_096a: Unknown result type (might be due to invalid IL or missing references)
//IL_0ab6: Unknown result type (might be due to invalid IL or missing references)
//IL_0abb: Unknown result type (might be due to invalid IL or missing references)
//IL_09b4: Unknown result type (might be due to invalid IL or missing references)
//IL_09b9: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Expected O, but got Unknown
//IL_0b84: Unknown result type (might be due to invalid IL or missing references)
//IL_0b89: Unknown result type (might be due to invalid IL or missing references)
//IL_0ba8: Unknown result type (might be due to invalid IL or missing references)
//IL_0bad: 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_029e;
case 1:
<>1__state = -1;
goto IL_029e;
case 2:
<>1__state = -1;
goto IL_10a9;
case 3:
<>1__state = -1;
goto IL_10a9;
case 4:
<>1__state = -1;
break;
case 5:
{
<>1__state = -1;
goto IL_10a9;
}
IL_029e:
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);
<>4__this.locationProxyInstanceField = typeof(LocationProxy).GetField("m_instance", 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_10a9;
IL_10a9:
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);
<setHasChanged>5__13 = !<normalizedKeys>5__12.SetEquals(<>4__this.allowedNames.Where((string name) => !name.EndsWith("_frac")));
<oldCustomNameToPrefabName>5__14 = null;
<preRestorationCount>5__15 = 0;
if (<setHasChanged>5__13)
{
<oldCustomNameToPrefabName>5__14 = new Dictionary<string, string>(<>4__this.customNameToPrefabName, StringComparer.OrdinalIgnoreCase);
<>4__this.allowedNames.Clear();
<>4__this.customNameToPrefabName.Clear();
<preRestorationCount>5__15 = <>4__this.removedPinsForRestoration.Count;
}
<>s__16 = PinAssistantReflectionHelper.AltDictionaryInstance.GetEnumerator();
try
{
while (<>s__16.MoveNext())
{
<kvp>5__17 = <>s__16.Current;
<key>5__18 = NormalizeName(<kvp>5__17.Key);
<trackedObject>5__19 = <kvp>5__17.Value?.Value;
if (<trackedObject>5__19 != null)
{
<currentExactMatch>5__20 = true;
try
{
<currentExactMatch>5__20 = <trackedObject>5__19.IsExactMatchOnly;
}
catch (Exception ex)
{
<ex>5__22 = ex;
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.LogWarning((object)$"[RadiusPinDetector][WARN] Failed to read IsExactMatchOnly for '{<key>5__18}': {<ex>5__22}. Defaulting to true.");
}
}
<needsUpdate>5__21 = !<>4__this.exactMatchStatus.ContainsKey(<key>5__18) || <>4__this.exactMatchStatus[<key>5__18].Current != <currentExactMatch>5__20;
if (<needsUpdate>5__21)
{
<hadPreviousValue>5__23 = <>4__this.exactMatchStatus.ContainsKey(<key>5__18);
<previousExactMatch>5__24 = !<hadPreviousValue>5__23 || <>4__this.exactMatchStatus[<key>5__18].Current;
<>4__this.exactMatchStatus[<key>5__18] = new ExactMatchStatus
{
Current = <currentExactMatch>5__20,
Previous = <previousExactMatch>5__24
};
if ((<hadPreviousValue>5__23 & <previousExactMatch>5__24) && !<currentExactMatch>5__20)
{
<>4__this.RestoreManuallyRemovedPins(<key>5__18);
}
}
if (<setHasChanged>5__13)
{
<>4__this.allowedNames.Add(<key>5__18);
<>4__this.allowedNames.Add(<key>5__18 + "_frac");
<customName>5__25 = NormalizeName(<trackedObject>5__19.Name);
if (!string.IsNullOrEmpty(<customName>5__25))
{
<>4__this.customNameToPrefabName[<customName>5__25] = <key>5__18;
}
if (<>4__this.removedPinsForRestoration.ContainsKey(<key>5__18))
{
try
{
<>4__this.RestoreRemovedPins(<key>5__18);
}
catch (Exception ex)
{
<ex>5__26 = ex;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] Failed to restore pins for '{<key>5__18}': {<ex>5__26}. Continuing with other objects.");
<>4__this.removedPinsForRestoration.Remove(<key>5__18);
}
}
<customName>5__25 = null;
}
}
<key>5__18 = null;
<trackedObject>5__19 = null;
<kvp>5__17 = default(KeyValuePair<string, TrieNode<TrackedObject>>);
}
}
finally
{
((IDisposable)<>s__16).Dispose();
}
<>s__16 = default(Dictionary<string, TrieNode<TrackedObject>>.Enumerator);
if (<setHasChanged>5__13)
{
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__15 - <>4__this.removedPinsForRestoration.Count}.");
}
<stampList>5__27 = <>4__this.GetPinsList();
if (<stampList>5__27 != null)
{
<stamped>5__29 = 0;
<>s__30 = <stampList>5__27.GetEnumerator();
try
{
while (<>s__30.MoveNext())
{
<pin>5__31 = <>s__30.Current;
if (<pin>5__31.m_author == PlatformUserID.None)
{
<normalizedPinName>5__32 = NormalizeName(<pin>5__31.m_name);
if (<>4__this.customNameToPrefabName.ContainsKey(<normalizedPinName>5__32))
{
<pin>5__31.m_author = ModAuthorID;
<stamped>5__29++;
}
<normalizedPinName>5__32 = null;
}
<pin>5__31 = null;
}
}
finally
{
((IDisposable)<>s__30).Dispose();
}
<>s__30 = default(List<PinData>.Enumerator);
if (MervilsRadiusPlugin.radiusDebugMode.Value && <stamped>5__29 > 0)
{
Debug.Log((object)$"[RadiusPinDetector][INIT] Retroactively stamped {<stamped>5__29} existing pins with mod author ID");
}
}
<pinsList>5__28 = <>4__this.GetPinsList();
if (<pinsList>5__28 != null)
{
<archivedCount>5__33 = 0;
<archivedByType>5__34 = new Dictionary<string, int>();
<>s__35 = <pinsList>5__28.ToList().GetEnumerator();
try
{
while (<>s__35.MoveNext())
{
<pin>5__36 = <>s__35.Current;
if (<pin>5__36.m_author == ModAuthorID)
{
<normalizedPinName>5__37 = NormalizeName(<pin>5__36.m_name);
<pinPrefabName>5__38 = (<oldCustomNameToPrefabName>5__14.ContainsKey(<normalizedPinName>5__37) ? <oldCustomNameToPrefabName>5__14[<normalizedPinName>5__37] : null);
if (<pinPrefabName>5__38 != null && !<>4__this.allowedNames.Contains(<pinPrefabName>5__38))
{
if (!<>4__this.removedPinsForRestoration.ContainsKey(<pinPrefabName>5__38))
{
<>4__this.removedPinsForRestoration[<pinPrefabName>5__38] = new List<PinState>();
}
<archivedPinState>5__39 = new PinState
{
ZdoID = ZDOID.None,
NormalizedName = <pinPrefabName>5__38,
Mobile = false,
LastPosition = <pin>5__36.m_pos,
PinnedObject = null,
Pin = <pin>5__36,
WasManuallyRemoved = false,
MatchedTrackedObjectName = <pinPrefabName>5__38
};
<>4__this.removedPinsForRestoration[<pinPrefabName>5__38].Add(<archivedPinState>5__39);
<archivedCount>5__33++;
if (!<archivedByType>5__34.ContainsKey(<pinPrefabName>5__38))
{
<archivedByType>5__34[<pinPrefabName>5__38] = 0;
}
<archivedByType>5__34[<pinPrefabName>5__38]++;
Minimap.instance.RemovePin(<pin>5__36);
<archivedPinState>5__39 = null;
}
<normalizedPinName>5__37 = null;
<pinPrefabName>5__38 = null;
}
<pin>5__36 = null;
}
}
finally
{
((IDisposable)<>s__35).Dispose();
}
<>s__35 = default(List<PinData>.Enumerator);
if (MervilsRadiusPlugin.radiusDebugMode.Value && <archivedCount>5__33 > 0)
{
Debug.Log((object)string.Format("[RadiusPinDetector][CLEANUP] Archived {0} pins: {1}", <archivedCount>5__33, string.Join(", ", <archivedByType>5__34.Select((KeyValuePair<string, int> kvp) => $"{kvp.Key}({kvp.Value})"))));
}
<archivedByType>5__34 = null;
}
<stampList>5__27 = null;
<pinsList>5__28 = null;
}
<currentAltKeys>5__11 = null;
<normalizedKeys>5__12 = null;
<oldCustomNameToPrefabName>5__14 = 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__40 = ex;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] PinAssistant reflection failed: {<ex>5__40}. 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__41 = <>4__this.znetInstancesField.GetValue(<>4__this.znetScene) as Dictionary<ZDO, ZNetView>;
if (<instanceDict>5__41 != null)
{
<allObjects>5__1 = (from z in <instanceDict>5__41.Values
where (Object)(object)z != (Object)null && (Object)(object)((Component)z).gameObject != (Object)null
select ((Component)z).gameObject).ToArray();
}
<instanceDict>5__41 = null;
}
}
catch (Exception ex)
{
<ex>5__42 = ex;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] ZNetScene object retrieval failed: {<ex>5__42}. 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__43 = ex;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] CleanUpPinCache failed: {<ex>5__43}. 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 FieldInfo locationProxyInstanceField;
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 Dictionary<string, string> customNameToPrefabName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private HashSet<string> allowedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private Dictionary<string, ExactMatchStatus> exactMatchStatus = new Dictionary<string, ExactMatchStatus>(StringComparer.OrdinalIgnoreCase);
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[6]
{
typeof(Humanoid),
typeof(Character),
typeof(AnimalAI),
typeof(RandomFlyingBird),
typeof(Vagon),
typeof(Ship)
};
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__34))]
private IEnumerator RadiusDetectorCoroutine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <RadiusDetectorCoroutine>d__34(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_093f: Unknown result type (might be due to invalid IL or missing references)
//IL_094d: Unknown result type (might be due to invalid IL or missing references)
//IL_084d: Unknown result type (might be due to invalid IL or missing references)
//IL_0867: Unknown result type (might be due to invalid IL or missing references)
//IL_0875: Unknown result type (might be due to invalid IL or missing references)
//IL_097d: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_0249: Unknown result type (might be due to invalid IL or missing references)
//IL_040a: Unknown result type (might be due to invalid IL or missing references)
//IL_0417: Unknown result type (might be due to invalid IL or missing references)
//IL_0419: Unknown result type (might be due to invalid IL or missing references)
//IL_044d: Unknown result type (might be due to invalid IL or missing references)
//IL_0452: Unknown result type (might be due to invalid IL or missing references)
//IL_045d: Unknown result type (might be due to invalid IL or missing references)
//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
//IL_054b: Unknown result type (might be due to invalid IL or missing references)
//IL_0550: Unknown result type (might be due to invalid IL or missing references)
//IL_0485: Unknown result type (might be due to invalid IL or missing references)
//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0591: Unknown result type (might be due to invalid IL or missing references)
//IL_05a4: Unknown result type (might be due to invalid IL or missing references)
//IL_0708: Unknown result type (might be due to invalid IL or missing references)
//IL_070a: Unknown result type (might be due to invalid IL or missing references)
//IL_072c: Unknown result type (might be due to invalid IL or missing references)
//IL_0731: Unknown result type (might be due to invalid IL or missing references)
//IL_05fb: 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_0607: Unknown result type (might be due to invalid IL or missing references)
//IL_060c: Unknown result type (might be due to invalid IL or missing references)
//IL_0634: Unknown result type (might be due to invalid IL or missing references)
//IL_0639: Unknown result type (might be due to invalid IL or missing references)
//IL_065b: Unknown result type (might be due to invalid IL or missing references)
//IL_0660: Unknown result type (might be due to invalid IL or missing references)
//IL_0669: Unknown result type (might be due to invalid IL or missing references)
//IL_0681: Unknown result type (might be due to invalid IL or missing references)
//IL_0688: Unknown result type (might be due to invalid IL or missing references)
//IL_068d: Unknown result type (might be due to invalid IL or missing references)
//IL_078b: Unknown result type (might be due to invalid IL or missing references)
//IL_0799: Unknown result type (might be due to invalid IL or missing references)
//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
//IL_09ba: Unknown result type (might be due to invalid IL or missing references)
//IL_09db: Unknown result type (might be due to invalid IL or missing references)
//IL_0893: Unknown result type (might be due to invalid IL or missing references)
//IL_08ed: Unknown result type (might be due to invalid IL or missing references)
//IL_08bd: Unknown result type (might be due to invalid IL or missing references)
//IL_08cd: Unknown result type (might be due to invalid IL or missing references)
//IL_0929: Unknown result type (might be due to invalid IL or missing references)
//IL_0907: 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 val8 = pin.Key - playerPos;
return ((Vector3)(ref val8)).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;
}
LocationProxy component2 = gameObject.GetComponent<LocationProxy>();
if ((Object)(object)component2 != (Object)null && locationProxyInstanceField != null)
{
object? value = locationProxyInstanceField.GetValue(component2);
GameObject val2 = (GameObject)((value is GameObject) ? value : null);
if (!((Object)(object)val2 != (Object)null))
{
continue;
}
gameObject = val2;
}
ZDOID val3 = component.GetZDO()?.m_uid ?? ZDOID.None;
if (val3 == ZDOID.None)
{
continue;
}
if (alreadyPinned.TryGetValue(val3, out var value2) && !value2.Mobile)
{
scanCycleSkippedAlreadyPinned++;
continue;
}
if (foundAndNotPinned.TryGetValue(val3, out var value3) && !value3.Mobile)
{
scanCycleSkippedPreviouslyFound++;
string normalizedName = value3.NormalizedName;
if (!scanCycleSkippedByType.ContainsKey(normalizedName))
{
scanCycleSkippedByType[normalizedName] = 0;
}
scanCycleSkippedByType[normalizedName]++;
continue;
}
string text;
if ((Object)(object)component2 != (Object)null)
{
text = ((Object)gameObject).name;
}
else
{
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 val4 = (GameObject)obj;
text = ((val4 != null) ? ((Object)val4).name : null) ?? ((Object)gameObject).name;
}
string text2 = NormalizeName(text);
if (text2.EndsWith("_frac"))
{
string undamagedName = text2.Substring(0, text2.Length - 5);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)("[RadiusPinDetector][DETECT] Found damaged resource node '" + text2 + "', 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 val7 = kvp.Value.LastPosition - gameObject.transform.position;
result = ((((Vector3)(ref val7)).sqrMagnitude < 0.1f) ? 1 : 0);
}
else
{
result = 0;
}
return (byte)result != 0;
});
if (keyValuePair.Value != null)
{
PinState value4 = keyValuePair.Value;
alreadyPinned.Remove(keyValuePair.Key);
value4.ZdoID = val3;
value4.NormalizedName = text2;
value4.PinnedObject = gameObject;
value4.LastPosition = gameObject.transform.position;
alreadyPinned[val3] = value4;
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][DETECT] Transferred pin from {undamagedName} to {text2} (ID={val3})");
}
continue;
}
}
string matchingTrackedObjectName = GetMatchingTrackedObjectName(text2);
if (matchingTrackedObjectName == null)
{
continue;
}
bool value5 = false;
if (!prefabMobilityCache.TryGetValue(text2, out value5))
{
value5 = IsMobile(gameObject);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][DETECT] First '{text2}' found. Is Mobile: {value5}");
}
prefabMobilityCache[text2] = value5;
}
PinData val5 = 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 val6 = kvp.Key - objectPos;
return ((Vector3)(ref val6)).sqrMagnitude < 0.1f;
});
if (keyValuePair2.Value != null)
{
val5 = keyValuePair2.Value;
existingPinsForCorrelation.Remove(keyValuePair2.Key);
nearbyOrphanedPins.Remove(keyValuePair2.Key);
scanCycleObjectsCorrelated++;
}
}
PinState value6 = null;
bool flag = false;
if (alreadyPinned.TryGetValue(val3, out value6))
{
if (!value6.Mobile)
{
continue;
}
val = gameObject.transform.position - value6.LastPosition;
if (!(((Vector3)(ref val)).sqrMagnitude > 1f))
{
continue;
}
value6.LastPosition = gameObject.transform.position;
if (value6.Pin != null)
{
Vector3 position = gameObject.transform.position;
value6.Pin.m_pos = new Vector3(position.x, value6.Pin.m_pos.y, position.z);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][SCAN] Mobile object '{text2}' (ID={val3}) moved; pin updated.");
}
}
continue;
}
if (foundAndNotPinned.TryGetValue(val3, out value6))
{
if (value6.WasManuallyRemoved || !value5)
{
continue;
}
}
else
{
value6 = new PinState
{
ZdoID = val3,
NormalizedName = text2,
Mobile = value5,
LastPosition = gameObject.transform.position,
PinnedObject = gameObject,
Pin = val5,
WasManuallyRemoved = false,
MatchedTrackedObjectName = matchingTrackedObjectName
};
flag = val5 == null;
}
if (flag)
{
List<PinData> pinsList = GetPinsList();
if (pinsList == null)
{
alreadyPinned.Remove(val3);
foundAndNotPinned.Remove(val3);
continue;
}
int count = pinsList.Count;
float num3 = (value5 ? 0f : redundancyDistanceSame);
float num4 = (value5 ? 0f : redundancyDistanceAny);
try
{
string arg = ((Object)gameObject).name;
if (text2.EndsWith("_frac"))
{
arg = text.Replace("_frac", "") + "(clone)";
}
PinAssistantReflectionHelper.AddObjAsPinDelegate?.Invoke(arg, gameObject);
}
catch (Exception arg2)
{
GameObject obj2 = gameObject;
Debug.LogError((object)$"[RadiusPinDetector][ERROR] AddObjAsPin failed for '{((obj2 != null) ? ((Object)obj2).name : null)}' (ID={val3}): {arg2}. Cannot proceed with PinData capture.");
alreadyPinned.Remove(val3);
foundAndNotPinned.Remove(val3);
continue;
}
try
{
value6.Pin = CaptureNewlyCreatedPin(gameObject.transform.position, count, pinsList);
if (value6.Pin != null)
{
alreadyPinned[val3] = value6;
foundAndNotPinned.Remove(val3);
scanCyclePinsCreated++;
continue;
}
alreadyPinned.Remove(val3);
if (!value5)
{
foundAndNotPinned[val3] = value6;
scanCycleObjectsClustered++;
}
else
{
foundAndNotPinned.Remove(val3);
}
}
catch (Exception arg3)
{
alreadyPinned.Remove(val3);
foundAndNotPinned.Remove(val3);
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={val3}), entry removed/cleaned from tracking: {arg3}");
}
}
}
else if (val5 != null && value6 != null && value6.Pin != null)
{
alreadyPinned[val3] = value6;
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][SCAN] An orphaned pin was correlated to {text2} (ID={val3})");
}
}
}
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] Objects skipped (previously found, not pinned): " + 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_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
//IL_0290: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_045d: Unknown result type (might be due to invalid IL or missing references)
//IL_0462: Unknown result type (might be due to invalid IL or missing references)
//IL_0488: 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();
List<PinData> pinsList = GetPinsList();
HashSet<Vector3> pinPositions = ((pinsList != null) ? new HashSet<Vector3>(pinsList.Select((PinData p) => p.m_pos)) : new HashSet<Vector3>());
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_009c: 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_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: 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)
ZDOID key = pair.Key;
PinState value = pair.Value;
string normalizedName = value.NormalizedName;
if (activeZDOIDs != null && !activeZDOIDs.Contains(key))
{
Vector3 val3 = value.LastPosition - playerPos;
if (((Vector3)(ref val3)).sqrMagnitude <= scanRadius * scanRadius)
{
return new
{
Key = key,
Name = normalizedName,
IsDestroyed = true,
ShouldRemove = true,
PinState = value,
WasManuallyRemoved = false
};
}
return new
{
Key = key,
Name = normalizedName,
IsDestroyed = true,
ShouldRemove = false,
PinState = value,
WasManuallyRemoved = false
};
}
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 ((value.MatchedTrackedObjectName == null || !allowedNames.Contains(value.MatchedTrackedObjectName)) && !allowedNames.Contains(normalizedName))
{
return new
{
Key = key,
Name = normalizedName,
IsDestroyed = false,
ShouldRemove = true,
PinState = value,
WasManuallyRemoved = false
};
}
return new
{
Key = key,
Name = normalizedName,
IsDestroyed = false,
ShouldRemove = false,
PinState = value,
WasManuallyRemoved = false
};
}
if ((value.MatchedTrackedObjectName == null || !allowedNames.Contains(value.MatchedTrackedObjectName)) && !allowedNames.Contains(normalizedName))
{
return new
{
Key = key,
Name = normalizedName,
IsDestroyed = false,
ShouldRemove = true,
PinState = value,
WasManuallyRemoved = false
};
}
return (value.Pin != null && !pinPositions.Contains(value.Pin.m_pos)) ? new
{
Key = key,
Name = normalizedName,
IsDestroyed = false,
ShouldRemove = true,
PinState = value,
WasManuallyRemoved = true
} : new
{
Key = key,
Name = normalizedName,
IsDestroyed = false,
ShouldRemove = false,
PinState = value,
WasManuallyRemoved = false
};
})
where item.ShouldRemove
select item).ToList();
foreach (var item in list)
{
PinState pinState = item.PinState;
if (item.WasManuallyRemoved)
{
pinState.WasManuallyRemoved = true;
pinState.Pin = null;
foundAndNotPinned[item.Key] = pinState;
alreadyPinned.Remove(item.Key);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][CLEANUP] Detected manually removed pin for '{item.Name}' (ID={item.Key}), moved to foundAndNotPinned");
}
continue;
}
if (item.IsDestroyed && pinState.Pin != null)
{
Vector3 removedPosition = pinState.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 (pinState.Pin != null)
{
Minimap.instance.RemovePin(pinState.Pin);
pinState.Pin = null;
num++;
}
alreadyPinned.Remove(item.Key);
}
var list3 = foundAndNotPinned.Select((KeyValuePair<ZDOID, PinState> pair) => new
{
Key = pair.Key,
PinState = pair.Value
}).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_0046: 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_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: 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))
{
Vector3 val = item.PinState.LastPosition - playerPos;
if (((Vector3)(ref val)).sqrMagnitude <= scanRadius * scanRadius)
{
return true;
}
return false;
}
return ((item.PinState.MatchedTrackedObjectName == null || !allowedNames.Contains(item.PinState.MatchedTrackedObjectName)) && !allowedNames.Contains(item.PinState.NormalizedName)) ? 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 value2 in nearbyOrphanedPins.Values)
{
if (value2.m_author == ModAuthorID)
{
Minimap.instance.RemovePin(value2);
existingPinsForCorrelation.Remove(value2.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 void RestoreManuallyRemovedPins(string trackedObjectName)
{
//IL_0026: 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_0056: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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)
List<ZDOID> list = new List<ZDOID>();
foreach (KeyValuePair<ZDOID, PinState> item in foundAndNotPinned.ToList())
{
ZDOID key = item.Key;
PinState value = item.Value;
if (value.WasManuallyRemoved && value.MatchedTrackedObjectName == trackedObjectName)
{
list.Add(key);
if (MervilsRadiusPlugin.radiusDebugMode.Value)
{
Debug.Log((object)$"[RadiusPinDetector][RESTORE] Will restore manually removed pin for '{value.NormalizedName}' (ID={key}) when ExactMatch changed from ON to OFF for '{trackedObjectName}'");
}
}
}
foreach (ZDOID item2 in list)
{
foundAndNotPinned.Remove(item2);
}
if (MervilsRadiusPlugin.radiusDebugMode.Value && list.Count > 0)
{
Debug.Log((object)$"[RadiusPinDetector][RESTORE] Removed {list.Count} manually removed pins from foundAndNotPinned for '{trackedObjectName}' - they will be re-pinned on next scan");
}
}
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 string GetMatchingTrackedObjectName(string normalizedPrefabName)
{
if (allowedNames.Contains(normalizedPrefabName))
{
return normalizedPrefabName;
}
foreach (string allowedName in allowedNames)
{
if (exactMatchStatus.ContainsKey(allowedName) && !exactMatchStatus[allowedName].Current && normalizedPrefabName.Contains(allowedName))
{
return allowedName;
}
}
return null;
}
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;
}
}
}