using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PurrNet;
using Steamworks;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MinimapFriends")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1e487b5a4930ff159ab9deac2cec5ef0ba980a15")]
[assembly: AssemblyProduct("MinimapFriends")]
[assembly: AssemblyTitle("MinimapFriends")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace MinimapFriends
{
[BepInPlugin("com.xaviergmail.minimapfriends", "MinimapFriends", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(MapManager), "Update")]
private static class MapFriendDotPatch
{
private static void Postfix(MapManager __instance)
{
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
try
{
GameObject val = MapRootRef.Invoke(__instance);
if ((Object)(object)val == (Object)null || !val.activeSelf)
{
return;
}
PlayerPanelController i = NetworkSingleton<PlayerPanelController>.I;
if ((Object)(object)i == (Object)null)
{
return;
}
List<Image> list = MapIconImagesRef.Invoke(__instance);
if (list == null)
{
return;
}
List<string> playerSteamIDs = i.PlayerSteamIDs;
List<NetworkTransform> playerTransforms = i.PlayerTransforms;
NetworkTransform val2 = NetworkSingleton<TextChannelManager>.I?.MainNetTransform;
int num = Mathf.Min(list.Count, Mathf.Min(playerSteamIDs.Count, playerTransforms.Count));
int num2 = -1;
for (int j = 0; j < num; j++)
{
Image val3 = list[j];
if ((Object)(object)val3 == (Object)null)
{
continue;
}
if ((Object)(object)playerTransforms[j] == (Object)(object)val2)
{
((Graphic)val3).color = Color.white;
num2 = j;
continue;
}
bool flag = IsFriend(playerSteamIDs[j]);
((Graphic)val3).color = (flag ? FriendColor : Color.white);
if (flag)
{
((Transform)((Graphic)val3).rectTransform).SetAsLastSibling();
}
}
if (num2 >= 0 && (Object)(object)list[num2] != (Object)null)
{
((Transform)((Graphic)list[num2]).rectTransform).SetAsLastSibling();
}
}
catch (Exception arg)
{
Log.LogError((object)$"[MinimapFriends] Map update failed: {arg}");
}
}
}
public const string PluginGuid = "com.xaviergmail.minimapfriends";
public const string PluginName = "MinimapFriends";
public const string PluginVersion = "1.0.0";
internal static ManualLogSource Log;
private static Harmony _harmony;
private static readonly Color FriendColor = new Color(0.24f, 0.86f, 0.35f);
private static readonly FieldRef<MapManager, List<Image>> MapIconImagesRef = AccessTools.FieldRefAccess<MapManager, List<Image>>("_playerIconImages");
private static readonly FieldRef<MapManager, GameObject> MapRootRef = AccessTools.FieldRefAccess<MapManager, GameObject>("_mapRoot");
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
_harmony = new Harmony("com.xaviergmail.minimapfriends");
_harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"MinimapFriends 1.0.0 loaded");
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private static bool IsFriend(string steamId)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Invalid comparison between Unknown and I4
if (string.IsNullOrEmpty(steamId))
{
return false;
}
try
{
if (ulong.TryParse(steamId, out var result))
{
return (int)SteamFriends.GetFriendRelationship(new CSteamID(result)) == 3;
}
}
catch (Exception ex)
{
Log.LogWarning((object)("[MinimapFriends] friend check failed for " + steamId + ": " + ex.Message));
}
return false;
}
}
}