Decompiled source of minimapa diman3012 v1.1.2

MIniMap.dll

Decompiled 3 days ago
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 GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MIniMap")]
[assembly: AssemblyDescription("Minimalistic Minimap mod for Lethal Company")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Diman3012")]
[assembly: AssemblyProduct("MIniMap")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4d061c1c-dea6-41cf-ac43-cd97a23e03fa")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace MIniMap;

[HarmonyPatch(typeof(ManualCameraRenderer))]
internal class ManualCameraRendererPatch
{
	private static Vector3 defaultEulerAngles = new Vector3(90f, 0f, 0f);

	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	private static void MapCameraLogic(ref Camera ___mapCamera, ref PlayerControllerB ___targetedPlayer, ref Image ___compassRose)
	{
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: 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)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		if (!MinimalMinimap.Instance.ConfigEnabled.Value || (Object)(object)___mapCamera == (Object)null)
		{
			return;
		}
		((Behaviour)___mapCamera).enabled = true;
		if (___mapCamera.orthographicSize != MinimalMinimap.Data.Zoom)
		{
			___mapCamera.orthographicSize = MinimalMinimap.Data.Zoom;
		}
		if (MinimalMinimap.Data.AutoRotate && (Object)(object)___targetedPlayer != (Object)null)
		{
			((Component)___mapCamera).transform.eulerAngles = new Vector3(defaultEulerAngles.x, ((Component)___targetedPlayer).transform.eulerAngles.y, defaultEulerAngles.z);
		}
		else if (((Component)___mapCamera).transform.eulerAngles != defaultEulerAngles)
		{
			((Component)___mapCamera).transform.eulerAngles = defaultEulerAngles;
		}
		TerminalAccessibleObject[] array = Object.FindObjectsOfType<TerminalAccessibleObject>();
		for (int i = 0; i < array.Length; i++)
		{
			if ((Object)(object)array[i].mapRadarObject != (Object)null)
			{
				array[i].mapRadarObject.transform.eulerAngles = new Vector3(defaultEulerAngles.x, ((Component)___mapCamera).transform.eulerAngles.y, defaultEulerAngles.z);
			}
		}
		if ((Object)(object)___compassRose != (Object)null)
		{
			((Transform)((Graphic)___compassRose).rectTransform).localEulerAngles = new Vector3(0f, 0f, ((Component)___mapCamera).transform.eulerAngles.y);
		}
	}
}
[BepInPlugin("com.diman3012.minimap", "Minimal Minimap", "1.0.0")]
public class MinimalMinimap : BaseUnityPlugin
{
	public static MinimalMinimap Instance;

	public static MinimapData Data;

	public ConfigEntry<bool> ConfigEnabled;

	private Harmony harmony;

	private void Awake()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		Instance = this;
		Data = new MinimapData();
		ConfigEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", false, "Enable or disable the minimap");
		harmony = new Harmony("com.diman3012.minimap");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Minimal Minimap (Minimal Minimap) loaded successfully!");
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "com.diman3012.minimap";

	public const string PLUGIN_NAME = "Minimal Minimap";

	public const string PLUGIN_VERSION = "1.0.0";
}
public class MinimapData
{
	public int Size = 200;

	public float XOffset = -10f;

	public float YOffset = -10f;

	public float Zoom = 20f;

	public bool AutoRotate = true;

	public bool FreezeTarget = false;

	public KeyCode OverrideKey = (KeyCode)284;

	public KeyCode SwitchKey = (KeyCode)285;

	public KeyCode ToggleKey = (KeyCode)283;
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class NetworkPrefabPatch
{
	[HarmonyPostfix]
	[HarmonyPatch("SetSingleton")]
	private static void RegisterPrefab()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_000e: 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)
		GameObject val = new GameObject("com.diman3012.minimap Prefab");
		((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
		Object.DontDestroyOnLoad((Object)(object)val);
		NetworkObject obj = val.AddComponent<NetworkObject>();
		FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
		if (field != null)
		{
			field.SetValue(obj, GetHash("com.diman3012.minimap"));
		}
		NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
	}

	private static uint GetHash(string value)
	{
		return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
	}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class MinimapPatch
{
	private static GameObject minimapObject;

	private static RawImage minimapImage;

	[HarmonyPatch("ConnectClientToPlayerObject")]
	[HarmonyPostfix]
	private static void CreateMinimap()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)minimapObject != (Object)null))
		{
			minimapObject = new GameObject("MIniMap_UI");
			minimapImage = minimapObject.AddComponent<RawImage>();
			RectTransform rectTransform = ((Graphic)minimapImage).rectTransform;
			rectTransform.anchorMin = new Vector2(1f, 1f);
			rectTransform.anchorMax = new Vector2(1f, 1f);
			rectTransform.pivot = new Vector2(1f, 1f);
			rectTransform.sizeDelta = new Vector2((float)MinimalMinimap.Data.Size, (float)MinimalMinimap.Data.Size);
			rectTransform.anchoredPosition = new Vector2(MinimalMinimap.Data.XOffset, MinimalMinimap.Data.YOffset);
			if ((Object)(object)StartOfRound.Instance.mapScreen != (Object)null)
			{
				minimapImage.texture = (Texture)(object)StartOfRound.Instance.mapScreen.cam.targetTexture;
			}
			minimapObject.transform.SetParent(((Component)HUDManager.Instance.playerScreenTexture).transform, false);
			bool value = MinimalMinimap.Instance.ConfigEnabled.Value;
			minimapObject.SetActive(value);
		}
	}

	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	private static void HandleHotkeys(PlayerControllerB __instance)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		if (!((NetworkBehaviour)__instance).IsOwner || (Object)(object)__instance != (Object)(object)GameNetworkManager.Instance.localPlayerController || (!__instance.isPlayerControlled && !__instance.isPlayerDead))
		{
			return;
		}
		if (UnityInput.Current.GetKeyDown(MinimalMinimap.Data.ToggleKey))
		{
			bool flag = !MinimalMinimap.Instance.ConfigEnabled.Value;
			MinimalMinimap.Instance.ConfigEnabled.Value = flag;
			if ((Object)(object)minimapObject != (Object)null)
			{
				minimapObject.SetActive(flag);
				HUDManager.Instance.DisplayTip("Minimap", flag ? "Visible" : "Hidden", false, false, "LC_Tip1");
			}
		}
		if (!MinimalMinimap.Instance.ConfigEnabled.Value)
		{
			return;
		}
		if (UnityInput.Current.GetKeyDown(MinimalMinimap.Data.OverrideKey))
		{
			MinimalMinimap.Data.FreezeTarget = !MinimalMinimap.Data.FreezeTarget;
			HUDManager.Instance.DisplayTip("Minimap", MinimalMinimap.Data.FreezeTarget ? "Override ON" : "Override OFF", false, false, "LC_Tip1");
		}
		if (UnityInput.Current.GetKeyDown(MinimalMinimap.Data.SwitchKey) && MinimalMinimap.Data.FreezeTarget)
		{
			SwitchTarget();
		}
		if (!__instance.isPlayerDead || !((Object)(object)__instance.spectatedPlayerScript != (Object)null) || MinimalMinimap.Data.FreezeTarget)
		{
			return;
		}
		ManualCameraRenderer mapScreen = StartOfRound.Instance.mapScreen;
		if (!((Object)(object)mapScreen != (Object)null) || !((Object)(object)mapScreen.targetedPlayer != (Object)(object)__instance.spectatedPlayerScript))
		{
			return;
		}
		for (int i = 0; i < mapScreen.radarTargets.Count; i++)
		{
			TransformAndName val = mapScreen.radarTargets[i];
			if (val != null && (Object)(object)val.transform != (Object)null)
			{
				PlayerControllerB component = ((Component)val.transform).GetComponent<PlayerControllerB>();
				if ((Object)(object)component == (Object)(object)__instance.spectatedPlayerScript)
				{
					mapScreen.targetTransformIndex = i;
					mapScreen.targetedPlayer = component;
					break;
				}
			}
		}
	}

	private static void SwitchTarget()
	{
		ManualCameraRenderer mapScreen = StartOfRound.Instance.mapScreen;
		if ((Object)(object)mapScreen == (Object)null || mapScreen.radarTargets == null)
		{
			return;
		}
		int count = mapScreen.radarTargets.Count;
		int num = mapScreen.targetTransformIndex;
		for (int i = 0; i < count; i++)
		{
			num = (num + 1) % count;
			TransformAndName val = mapScreen.radarTargets[num];
			if (val != null && !((Object)(object)val.transform == (Object)null))
			{
				PlayerControllerB component = ((Component)val.transform).GetComponent<PlayerControllerB>();
				if (!((Object)(object)component != (Object)null) || component.isPlayerControlled || component.isPlayerDead)
				{
					mapScreen.targetTransformIndex = num;
					mapScreen.targetedPlayer = component;
					break;
				}
			}
		}
	}

	[HarmonyPatch(typeof(ManualCameraRenderer), "updateMapTarget")]
	[HarmonyPrefix]
	private static bool PreventAutoUpdate()
	{
		if (MinimalMinimap.Data.FreezeTarget)
		{
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(ManualCameraRenderer), "SwitchRadarTargetForward")]
	[HarmonyPrefix]
	private static bool PreventForwardSwitch()
	{
		return !MinimalMinimap.Data.FreezeTarget;
	}
}