Decompiled source of BigMap v1.5.0

BigMap.dll

Decompiled 7 months ago
using System;
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 BepInEx.Logging;
using DunGen;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
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("BigMap")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BigMap")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e771f53b-5fbd-48a2-8a87-eeb29295dc1e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BigMap;

public static class BigMapBehaviour
{
	private static GameObject mapObj;

	private static RawImage map;

	private static GameObject cameraObj;

	private static Camera mapCamera;

	private static GameObject floorPlane;

	private static Vector3 cameraPos = new Vector3(-16f, -215f, 65f);

	private static float curTierY = -219.59f;

	private static float tierOffset = 6.25f;

	private static float cameraOffset = 4f;

	public static bool bMap = false;

	private static float maxX;

	private static float maxZ;

	private static float minX;

	private static float minZ;

	private static float maxY;

	private static float minY;

	private static float width = 100f;

	private static float height = 100f;

	private static float size = 50f;

	public static void Init()
	{
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Expected O, but got Unknown
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Expected O, but got Unknown
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Expected O, but got Unknown
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_038a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0463: Unknown result type (might be due to invalid IL or missing references)
		//IL_0478: Unknown result type (might be due to invalid IL or missing references)
		//IL_047f: Expected O, but got Unknown
		//IL_0481: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)StartOfRound.Instance == (Object)null)
		{
			return;
		}
		if ((Object)(object)cameraObj == (Object)null || (Object)(object)mapCamera == (Object)null)
		{
			Camera val = StartOfRound.Instance.mapScreen.mapCamera;
			cameraObj = Object.Instantiate<GameObject>(((Component)val).gameObject);
			((Object)cameraObj).name = "BigMapCamera";
			mapCamera = cameraObj.GetComponent<Camera>();
			mapCamera.orthographic = true;
			cameraObj.transform.rotation = Quaternion.Euler(90f, 270f, 0f);
			Volume componentInChildren = cameraObj.GetComponentInChildren<Volume>();
			((Component)componentInChildren).gameObject.SetActive(false);
			Transform val2 = cameraObj.transform.Find("CameraGreenTransition");
			if (Object.op_Implicit((Object)(object)val2))
			{
				((Component)val2).gameObject.SetActive(false);
			}
			Light componentInChildren2 = cameraObj.GetComponentInChildren<Light>(true);
			((Behaviour)componentInChildren2).enabled = true;
			componentInChildren2.intensity = 3f;
			componentInChildren2.range = 100f;
			componentInChildren2.type = (LightType)1;
			RenderTexture val3 = new RenderTexture(1024, 682, 0);
			val3.format = (RenderTextureFormat)0;
			val3.depth = 32;
			mapCamera.targetTexture = val3;
			UpdateCamera();
		}
		if ((Object)(object)mapObj == (Object)null || (Object)(object)map == (Object)null)
		{
			mapObj = new GameObject("BigMap");
			mapObj.layer = LayerMask.NameToLayer("UI");
			map = mapObj.AddComponent<RawImage>();
			((Graphic)map).rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
			((Graphic)map).rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
			((Graphic)map).rectTransform.pivot = new Vector2(0.5f, 0.5f);
			((Graphic)map).rectTransform.sizeDelta = new Vector2(600f, 400f);
			((Graphic)map).rectTransform.anchoredPosition = Vector2.zero;
			map.texture = (Texture)(object)mapCamera.targetTexture;
			int siblingIndex = StartOfRound.Instance.localPlayerController.quickMenuManager.menuContainer.transform.GetSiblingIndex();
			Transform parent = StartOfRound.Instance.localPlayerController.quickMenuManager.menuContainer.transform.parent;
			mapObj.transform.SetParent(parent, false);
			mapObj.transform.SetSiblingIndex(siblingIndex - 1);
			GameObject val4 = new GameObject("BigMapTitle");
			val4.layer = LayerMask.NameToLayer("UI");
			TextMeshProUGUI val5 = val4.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val5).rectTransform.anchorMin = new Vector2(0f, 1f);
			((TMP_Text)val5).rectTransform.anchorMax = new Vector2(0f, 1f);
			((TMP_Text)val5).rectTransform.offsetMax = Vector2.zero;
			((TMP_Text)val5).rectTransform.offsetMin = Vector2.zero;
			((TMP_Text)val5).rectTransform.pivot = new Vector2(0f, 1f);
			((TMP_Text)val5).rectTransform.sizeDelta = new Vector2(400f, 30f);
			((TMP_Text)val5).rectTransform.anchoredPosition = Vector2.zero;
			((TMP_Text)val5).fontSize = 20f;
			((Graphic)val5).color = Color.white;
			((TMP_Text)val5).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)val5).text = "按" + ((InputControl)Config.upFloorKey).displayName + " 或 " + ((InputControl)Config.downFloorKey).displayName + " 切换上下层";
			val4.transform.SetParent(mapObj.transform, false);
		}
		if ((Object)(object)floorPlane == (Object)null)
		{
			floorPlane = GameObject.CreatePrimitive((PrimitiveType)4);
			((Object)floorPlane).name = "BigMapFloorRadar";
			floorPlane.transform.position = new Vector3(0f, 0f, 0f);
			Material val6 = new Material(Shader.Find("HDRP/Lit"));
			val6.color = Color.green;
			floorPlane.GetComponent<Renderer>().material = val6;
			floorPlane.layer = LayerMask.NameToLayer("MapRadar");
		}
		mapObj.SetActive(false);
	}

	public static void SetState()
	{
		if (Object.op_Implicit((Object)(object)mapObj))
		{
			bMap = !bMap;
			mapObj.SetActive(bMap);
		}
	}

	public static void OnSpawnStart()
	{
		maxX = float.MinValue;
		maxZ = float.MinValue;
		minZ = float.MaxValue;
		minX = float.MaxValue;
		maxY = float.MinValue;
		minY = float.MaxValue;
		width = 100f;
		height = 100f;
		size = 50f;
		curTierY = -219.59f;
	}

	public static void OnSpawnEnd()
	{
		//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)
		height = maxX - minX;
		width = maxZ - minZ;
		float num = (minX + maxX) / 2f;
		float num2 = (maxZ + minZ) / 2f;
		cameraPos = new Vector3(num, -214f, num2);
		float num3 = Mathf.Sqrt(width * width + height * height);
		size = num3 * 0.5f;
		SetTiers();
		UpdateCamera();
	}

	public static void CkeckSpawnPos(Vector3 pos)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		if (pos.x < minX)
		{
			minX = pos.x;
		}
		if (pos.x > maxX)
		{
			maxX = pos.x;
		}
		if (pos.z < minZ)
		{
			minZ = pos.z;
		}
		if (pos.z > maxZ)
		{
			maxZ = pos.z;
		}
		if (pos.y > maxY)
		{
			maxY = pos.y;
		}
		if (pos.y < minY)
		{
			minY = pos.y;
		}
	}

	public static void CheckIsFloor(Tile tile)
	{
		//IL_0028: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		if (tile.AllDoorways.Count <= 0)
		{
			return;
		}
		float y = ((Component)tile.AllDoorways[0]).transform.position.y;
		for (int i = 1; i < tile.AllDoorways.Count; i++)
		{
			float num = Mathf.Abs(((Component)tile.AllDoorways[i]).transform.position.y - y);
			if (num > 5f)
			{
				Bounds bounds = tile.Bounds;
				Vector3 val = ((Bounds)(ref bounds)).center.SetPositionY(((Component)tile.AllDoorways[i]).transform.position.y + 0.1f);
				AddRadar(val);
				bounds = tile.Bounds;
				Vector3 val2 = ((Bounds)(ref bounds)).center.SetPositionY(((Component)tile.AllDoorways[0]).transform.position.y + 0.1f);
				AddRadar(val2);
				Plugin.Log.LogInfo((object)$"检测到楼梯节点,设置RadarObj位置:{val},{val2}");
				break;
			}
		}
	}

	private static void AddRadar(Vector3 pos)
	{
		//IL_0010: 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)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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)
		Scene sceneByName = SceneManager.GetSceneByName(StartOfRound.Instance.currentLevel.sceneName);
		GameObject val = Object.Instantiate<GameObject>(floorPlane);
		SceneManager.MoveGameObjectToScene(val, sceneByName);
		val.transform.position = pos;
		val.transform.localScale = Vector3.one * 0.4f;
	}

	public static void UpTier()
	{
		if (Object.op_Implicit((Object)(object)cameraObj))
		{
			if (curTierY + tierOffset <= maxY + 1f)
			{
				curTierY += tierOffset;
			}
			UpdateCamera();
		}
	}

	public static void DownTier()
	{
		if (Object.op_Implicit((Object)(object)cameraObj))
		{
			if (curTierY - tierOffset >= minY - 1f)
			{
				curTierY -= tierOffset;
			}
			UpdateCamera();
		}
	}

	private static void UpdateCamera()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)cameraObj))
		{
			cameraObj.transform.position = cameraPos.SetPositionY(curTierY + cameraOffset);
		}
		if (Object.op_Implicit((Object)(object)mapCamera))
		{
			mapCamera.orthographicSize = size;
		}
	}

	private static void SetTiers()
	{
		string name = ((Object)RoundManager.Instance.dungeonGenerator.Generator.CurrentDungeon.DungeonFlow).name;
		string text = name;
		string text2 = text;
		if (!(text2 == "Level1Flow"))
		{
			if (text2 == "Level2Flow")
			{
				tierOffset = 10f;
				cameraOffset = 6.25f;
			}
			else
			{
				Plugin.Log.LogInfo((object)("检测到未知内部地图,大地图设置失败!" + name));
				tierOffset = 6.25f;
				cameraOffset = 5f;
			}
		}
		else
		{
			tierOffset = 6.25f;
			cameraOffset = 5f;
		}
	}

	public static Vector3 SetPositionY(this Vector3 position, float y)
	{
		//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(position.x, y, position.z);
	}
}
internal static class Config
{
	public static KeyControl mapKey = Keyboard.current.mKey;

	public static KeyControl upFloorKey = Keyboard.current.upArrowKey;

	public static KeyControl downFloorKey = Keyboard.current.downArrowKey;

	private static bool loadedConfig = false;

	private static string keyDisplayNames;

	public static void Bind()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (!loadedConfig)
		{
			keyDisplayNames = string.Join(", ", ((IEnumerable<KeyControl>)(object)Keyboard.current.allKeys).Select((KeyControl x) => ((InputControl)x).displayName));
			mapKey = BindKey("按键配置", "地图键", Keyboard.current.mKey, "参考按键对应字符串: " + keyDisplayNames);
			upFloorKey = BindKey("按键配置", "上层键", Keyboard.current.upArrowKey, "参考按键对应字符串: " + keyDisplayNames);
			downFloorKey = BindKey("按键配置", "下层键", Keyboard.current.downArrowKey, "参考按键对应字符串: " + keyDisplayNames);
			loadedConfig = true;
		}
	}

	private static KeyControl BindKey(string section, string key, KeyControl defaultValue, string configDescription = null)
	{
		try
		{
			ConfigEntry<string> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>(section, key, ((InputControl)defaultValue).displayName, configDescription);
			KeyControl val2 = Keyboard.current.FindKeyOnCurrentKeyboardLayout(val.Value);
			if (val2 != null)
			{
				return val2;
			}
			Plugin.Log.LogWarning((object)("大地图按键设置失败!" + key + ":" + val.Value));
			return defaultValue;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("大地图按键设置失败!" + ex.Message));
			return defaultValue;
		}
	}
}
[HarmonyPatch(typeof(DungeonGenerator))]
internal class DungeonGenerator_Patch
{
	[HarmonyPatch("Generate")]
	[HarmonyPostfix]
	private static void Generate_Postfix(DungeonGenerator __instance)
	{
		//IL_0033: 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)
		BigMapBehaviour.OnSpawnStart();
		foreach (Tile allTile in __instance.CurrentDungeon.AllTiles)
		{
			Plugin.Log.LogInfo((object)$"地牢Tile位置:{((Component)allTile).transform.position}");
			BigMapBehaviour.CkeckSpawnPos(((Component)allTile).transform.position);
			BigMapBehaviour.CheckIsFloor(allTile);
		}
		BigMapBehaviour.OnSpawnEnd();
	}
}
[HarmonyPatch]
public class PlayerControllerB_Patch
{
	[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
	[HarmonyPostfix]
	private static void ConnectClientToPlayerObjectPostPatch(PlayerControllerB __instance)
	{
		BigMapBehaviour.Init();
		Plugin.Log.LogInfo((object)"大地图初始化成功!");
	}

	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	[HarmonyPostfix]
	public static void UpdatePostfix(PlayerControllerB __instance)
	{
		if (!((Object)(object)__instance == (Object)(object)StartOfRound.Instance.localPlayerController))
		{
			return;
		}
		Config.Bind();
		if (((ButtonControl)Config.mapKey).wasPressedThisFrame)
		{
			BigMapBehaviour.SetState();
		}
		if (BigMapBehaviour.bMap)
		{
			if (((ButtonControl)Config.upFloorKey).wasPressedThisFrame)
			{
				BigMapBehaviour.UpTier();
			}
			if (((ButtonControl)Config.downFloorKey).wasPressedThisFrame)
			{
				BigMapBehaviour.DownTier();
			}
		}
	}
}
[BepInPlugin("qh3.BigMap", "BigMap", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static Plugin Instance;

	private static readonly Harmony harmony = new Harmony("qh3.BigMap");

	internal static ManualLogSource Log = Logger.CreateLogSource("qh3.BigMap");

	private void Awake()
	{
		Log.LogInfo((object)"Loading BigMap Mod");
		Instance = this;
		harmony.PatchAll(typeof(PlayerControllerB_Patch));
		harmony.PatchAll(typeof(DungeonGenerator_Patch));
	}
}