using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using MelonLoader;
using Microsoft.CodeAnalysis;
using Mimic.Actors;
using MiniMap;
using Minimap;
using Minimap.API;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "MiniMap", "1.0.4", "ToxesFoxes", null)]
[assembly: MelonGame("ReLUGames", "MIMESIS")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Minimap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.5")]
[assembly: AssemblyInformationalVersion("1.0.0+ab610ba4b102a145ef26fe8ae68cd3cfa517599a")]
[assembly: AssemblyProduct("Minimap")]
[assembly: AssemblyTitle("Minimap")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 MiniMap
{
public class Core : MelonMod
{
[CompilerGenerated]
private sealed class <RecreateMinimapAfterDelay>d__16 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <RecreateMinimapAfterDelay>d__16(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = null;
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
CreateRoot();
CreateCamera();
CreateUI();
return false;
}
}
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 GameObject mapRootObj;
private static Camera mapCamera;
private static RenderTexture mapTexture;
private static GameObject mapCanvasObj;
private static RawImage mapImage;
private static Transform playerTransform;
private static bool isVisible = false;
private static bool isInDungeon = false;
private static InputAction toggleAction;
private static ProtoActor player;
private static float cameraYOffset = 3f;
private static float nearClipPlane = 1f;
private static float farClipPlane = 20f;
private static readonly Compass compass = new Compass();
public override void OnInitializeMelon()
{
MelonLogger.Msg("MiniMap initialized. Press F4 to toggle minimap.");
SetupInput();
SceneManager.sceneLoaded += OnSceneLoaded;
MelonLogger.Msg("MiniMap setup complete.");
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
MelonLogger.Msg($"Scene loaded: {((Scene)(ref scene)).name}, minimap was visible: {isVisible}");
playerTransform = null;
DestroyUI();
DestroyCamera();
DestroyRoot();
if (isVisible)
{
MelonLogger.Msg("Recreating minimap after scene load...");
MelonCoroutines.Start(RecreateMinimapAfterDelay());
}
}
[IteratorStateMachine(typeof(<RecreateMinimapAfterDelay>d__16))]
private static IEnumerator RecreateMinimapAfterDelay()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <RecreateMinimapAfterDelay>d__16(0);
}
private static void SetupInput()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
InputActionMap val = new InputActionMap("MiniMap");
toggleAction = InputActionSetupExtensions.AddAction(val, "Toggle", (InputActionType)0, "<Keyboard>/f4", (string)null, (string)null, (string)null, (string)null);
toggleAction.performed += delegate
{
ToggleMap();
};
val.Enable();
}
private static void DestroyUI()
{
if ((Object)(object)mapCanvasObj != (Object)null)
{
compass.DestroyCompass();
Object.Destroy((Object)(object)mapCanvasObj);
mapCanvasObj = null;
mapImage = null;
}
}
private static void DestroyCamera()
{
if ((Object)(object)mapCamera != (Object)null)
{
if ((Object)(object)((Component)mapCamera).gameObject != (Object)null)
{
Object.Destroy((Object)(object)((Component)mapCamera).gameObject);
}
mapCamera = null;
mapTexture = null;
}
}
private static void DestroyRoot()
{
if ((Object)(object)mapRootObj != (Object)null)
{
Object.Destroy((Object)(object)mapRootObj);
mapRootObj = null;
}
}
private static void ToggleMap()
{
isVisible = !isVisible;
MelonLogger.Msg("Toggling MiniMap: " + (isVisible ? "Enabled" : "Disabled"));
if (isVisible)
{
if ((Object)(object)mapRootObj == (Object)null)
{
CreateRoot();
}
if ((Object)(object)mapCamera == (Object)null)
{
CreateCamera();
}
if ((Object)(object)mapCanvasObj == (Object)null)
{
CreateUI();
}
if ((Object)(object)mapCamera != (Object)null)
{
((Behaviour)mapCamera).enabled = true;
}
}
else
{
DestroyUI();
DestroyCamera();
DestroyRoot();
}
}
private static void CreateRoot()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
if (!((Object)(object)mapRootObj != (Object)null))
{
mapRootObj = new GameObject("MiniMapRoot");
Object.DontDestroyOnLoad((Object)(object)mapRootObj);
}
}
private static void CreateCamera()
{
//IL_0025: 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)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
if (!((Object)(object)mapCamera != (Object)null))
{
if ((Object)(object)mapRootObj == (Object)null)
{
CreateRoot();
}
GameObject val = new GameObject("MiniMapCamera");
val.transform.SetParent(mapRootObj.transform, false);
mapCamera = val.AddComponent<Camera>();
mapCamera.orthographic = true;
mapCamera.orthographicSize = 10f;
mapCamera.clearFlags = (CameraClearFlags)2;
mapCamera.backgroundColor = new Color(0f, 0f, 0f, 0f);
mapCamera.cullingMask = -1;
mapTexture = new RenderTexture(512, 512, 16, (RenderTextureFormat)0);
mapTexture.Create();
mapCamera.targetTexture = mapTexture;
mapCamera.nearClipPlane = (isInDungeon ? nearClipPlane : 0.1f);
mapCamera.farClipPlane = (isInDungeon ? farClipPlane : 100f);
}
}
private static void CreateUI()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
//IL_00ab: 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_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)mapCanvasObj != (Object)null))
{
if ((Object)(object)mapRootObj == (Object)null)
{
CreateRoot();
}
mapCanvasObj = new GameObject("MiniMapCanvas");
mapCanvasObj.transform.SetParent(mapRootObj.transform, false);
mapCanvasObj.AddComponent<Canvas>().renderMode = (RenderMode)0;
mapCanvasObj.AddComponent<CanvasScaler>();
mapCanvasObj.AddComponent<GraphicRaycaster>();
GameObject val = new GameObject("MiniMapBG");
val.transform.SetParent(mapCanvasObj.transform, false);
Image obj = val.AddComponent<Image>();
((Graphic)obj).color = new Color(0f, 0f, 0f, 0.4f);
RectTransform component = ((Component)obj).GetComponent<RectTransform>();
component.anchorMin = new Vector2(1f, 0f);
component.anchorMax = new Vector2(1f, 0f);
component.pivot = new Vector2(1f, 0f);
component.anchoredPosition = new Vector2(-10f, 10f);
component.sizeDelta = new Vector2(256f, 256f);
GameObject val2 = new GameObject("MiniMapImage");
val2.transform.SetParent(val.transform, false);
mapImage = val2.AddComponent<RawImage>();
mapImage.texture = (Texture)(object)mapTexture;
RectTransform component2 = val2.GetComponent<RectTransform>();
component2.anchorMin = Vector2.zero;
component2.anchorMax = Vector2.one;
component2.offsetMin = new Vector2(5f, 5f);
component2.offsetMax = new Vector2(-5f, -5f);
compass.CreateCompass(val.transform);
}
}
public static ProtoActor GetCurrentSpectatingActor()
{
if (ActorAPI.GetAlivePlayers().Length != 0)
{
CameraManager cameraManager = HubAPI.GetCameraManager();
if ((Object)(object)cameraManager != (Object)null)
{
int? spectatorTargetActorID = cameraManager.SpectatorTargetActorID;
if (spectatorTargetActorID.HasValue)
{
return ActorAPI.GetActorByID(spectatorTargetActorID);
}
}
}
return null;
}
public static bool IsActorInDungeon(ProtoActor actor)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)actor == (Object)null)
{
return false;
}
if (actor == null)
{
return false;
}
Transform transform = ((Component)actor).transform;
return ((transform != null) ? new float?(transform.position.y) : null) < -10f;
}
public static void SetCurrentPlayer(ProtoActor newPlayer)
{
ProtoActor val = player;
player = newPlayer;
isInDungeon = IsActorInDungeon(player);
if ((Object)(object)newPlayer == (Object)null && (Object)(object)val != (Object)null)
{
MelonLogger.Msg("No player to follow on minimap.");
}
else if ((Object)(object)val == (Object)null && (Object)(object)newPlayer != (Object)null)
{
MelonLogger.Msg("Now following player " + ActorAPI.GetActorName(newPlayer) + " on minimap.");
}
else if (((val != null) ? new int?(val.ActorID) : null) != ((newPlayer != null) ? new int?(newPlayer.ActorID) : null))
{
MelonLogger.Msg("Current player changed to " + ActorAPI.GetActorName(newPlayer) + ".");
}
}
public override void OnLateUpdate()
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: 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_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Expected O, but got Unknown
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
if (!isVisible || (Object)(object)mapCamera == (Object)null)
{
return;
}
ProtoActor localPlayer = ActorAPI.GetLocalPlayer();
if ((Object)(object)localPlayer != (Object)null && localPlayer != null && localPlayer.dead)
{
ProtoActor currentSpectatingActor = GetCurrentSpectatingActor();
if (!((Object)(object)currentSpectatingActor != (Object)null))
{
SetCurrentPlayer(null);
return;
}
SetCurrentPlayer(currentSpectatingActor);
}
else
{
SetCurrentPlayer(localPlayer);
}
if (Object.op_Implicit((Object)(object)player))
{
playerTransform = ((Component)player).transform;
if ((Object)(object)playerTransform != (Object)null)
{
Vector3 position = playerTransform.position;
float num = position.y + cameraYOffset;
Vector3 position2 = default(Vector3);
((Vector3)(ref position2))..ctor(position.x, Mathf.Round(num), position.z);
((Component)mapCamera).transform.position = position2;
((Component)mapCamera).transform.rotation = Quaternion.Euler(90f, playerTransform.eulerAngles.y, 0f);
mapCamera.nearClipPlane = (isInDungeon ? nearClipPlane : 0.1f);
mapCamera.farClipPlane = (isInDungeon ? farClipPlane : 100f);
}
if (isInDungeon)
{
Material val = new Material(Shader.Find("UI/Default"));
val.color = new Color(0f, 1f, 0f, 1f);
((Graphic)mapImage).material = val;
}
else
{
((Graphic)mapImage).material = null;
}
compass.UpdateCompass(player);
}
}
}
}
namespace Minimap
{
internal class Compass
{
private List<Vector3> teleporterPositions = new List<Vector3>();
private GameObject compassObj;
private Text northText;
private Text eastText;
private Text southText;
private Text westText;
private Vector2 offset = new Vector2(45f, -40f);
private int heightOffset = 36;
private int widthOffset = 36;
private bool useTeleporterAngle;
private float teleporterAngle;
public void DestroyCompass()
{
if ((Object)(object)compassObj != (Object)null)
{
Object.Destroy((Object)(object)compassObj);
compassObj = null;
northText = (eastText = (southText = (westText = null)));
}
}
public void UpdateCompass(ProtoActor actor)
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)actor == (Object)null || (Object)(object)((Component)actor).transform == (Object)null)
{
return;
}
useTeleporterAngle = false;
GamePlayScene gamePlayScene = HubAPI.GetGamePlayScene();
if ((Object)(object)gamePlayScene != (Object)null)
{
teleporterPositions = ((GameMainBase)gamePlayScene).GetTeleporterPositions(gamePlayScene.CheckActorIsIndoor(actor));
if (teleporterPositions.Count > 0)
{
useTeleporterAngle = true;
teleporterAngle = CalculateTeleporterAngle(actor, teleporterPositions);
}
}
float y = ((Component)actor).transform.eulerAngles.y;
float baseAngle = (useTeleporterAngle ? teleporterAngle : (0f - y));
UpdateCompassLabels(baseAngle);
}
private float CalculateTeleporterAngle(ProtoActor actor, List<Vector3> teleporters)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: 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)
//IL_002c: 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_0044: 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_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: 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_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: 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_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = Vector3.zero;
float num = float.MaxValue;
foreach (Vector3 teleporter in teleporters)
{
Vector3 val2 = ((Component)actor).transform.position - teleporter;
float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
if (sqrMagnitude < num)
{
num = sqrMagnitude;
val = teleporter;
}
}
Vector3 val3 = val - ((Component)actor).transform.position;
val3.y = 0f;
Vector3 forward = ((Component)actor).transform.forward;
float num2 = Vector3.Angle(val3, forward);
if (Vector3.Cross(forward, val3).y < 0f)
{
num2 = 0f - num2;
}
return (num2 + 270f + 360f + 15f) % 360f;
}
public void CreateCompass(Transform bgObj)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
compassObj = new GameObject("MiniMapCompass");
compassObj.transform.SetParent(((Component)bgObj).transform, false);
RectTransform obj = compassObj.AddComponent<RectTransform>();
obj.anchorMin = Vector2.zero;
obj.anchorMax = Vector2.one;
obj.pivot = new Vector2(0.5f, 0.5f);
obj.offsetMin = Vector2.zero;
obj.offsetMax = Vector2.zero;
northText = CreateCompassLabel("N", compassObj.transform);
eastText = CreateCompassLabel("E", compassObj.transform);
southText = CreateCompassLabel("S", compassObj.transform);
westText = CreateCompassLabel("W", compassObj.transform);
}
private Text CreateCompassLabel(string label, Transform parent)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: 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)
GameObject val = new GameObject("Compass" + label);
val.transform.SetParent(parent, false);
Text obj = val.AddComponent<Text>();
obj.text = label;
obj.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
obj.fontSize = 18;
((Graphic)obj).color = Color.white;
RectTransform component = ((Component)obj).GetComponent<RectTransform>();
component.anchorMin = new Vector2(0.5f, 0.5f);
component.anchorMax = new Vector2(0.5f, 0.5f);
component.pivot = new Vector2(0.5f, 0.5f);
component.anchoredPosition = Vector2.zero;
return obj;
}
private Vector2 GetCompassEdgePosition(float angleDeg, float w, float h, float margin)
{
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
float num = (angleDeg + (useTeleporterAngle ? 70f : (-105f))) * (MathF.PI / 180f);
float num2 = Mathf.Sin(num);
float num3 = Mathf.Cos(num);
float num4 = (w + (float)widthOffset) / 2f - margin;
float num5 = (h + (float)heightOffset) / 2f - margin;
float num6 = Mathf.Abs(num2);
float num7 = Mathf.Abs(num3);
float num8 = ((num6 * num5 > num7 * num4) ? (num4 / num6) : (num5 / num7));
return new Vector2(num2 * num8, num3 * num8) + offset;
}
private void UpdateCompassLabels(float baseAngle)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)compassObj == (Object)null))
{
RectTransform component = compassObj.GetComponent<RectTransform>();
Rect rect = component.rect;
float width = ((Rect)(ref rect)).width;
rect = component.rect;
float height = ((Rect)(ref rect)).height;
float margin = 16f;
if ((Object)(object)northText != (Object)null)
{
((Graphic)northText).rectTransform.anchoredPosition = GetCompassEdgePosition(0f + baseAngle, width, height, margin);
}
if ((Object)(object)eastText != (Object)null)
{
((Graphic)eastText).rectTransform.anchoredPosition = GetCompassEdgePosition(90f + baseAngle, width, height, margin);
}
if ((Object)(object)southText != (Object)null)
{
((Graphic)southText).rectTransform.anchoredPosition = GetCompassEdgePosition(180f + baseAngle, width, height, margin);
}
if ((Object)(object)westText != (Object)null)
{
((Graphic)westText).rectTransform.anchoredPosition = GetCompassEdgePosition(270f + baseAngle, width, height, margin);
}
}
}
}
internal class Helpers
{
private const BindingFlags DefaultFlags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
public static T GetPropertyValue<T>(object target, string propertyName)
{
if (target == null)
{
return default(T);
}
PropertyInfo property = target.GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (property == null)
{
MelonLogger.Msg($"[Helpers] Property '{propertyName}' not found on target of type '{target.GetType()}'");
return default(T);
}
object value = property.GetValue(target);
if (value != null)
{
return (T)value;
}
return default(T);
}
public static object GetFieldValue(object target, string fieldName)
{
return target?.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(target);
}
public static object GetFieldValue(Type type, string fieldName)
{
return type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(null);
}
public static T GetFieldValue<T>(object target, string fieldName)
{
object fieldValue = GetFieldValue(target, fieldName);
if (fieldValue != null)
{
return (T)fieldValue;
}
return default(T);
}
public static void SetFieldValue(object target, string fieldName, object value)
{
if (target != null)
{
FieldInfo field = target.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
field.SetValue(target, value);
}
}
}
public static object InvokeMethod(object target, string methodName, params object[] parameters)
{
if (target == null)
{
return null;
}
MethodInfo method = target.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (method == null)
{
return null;
}
return method.Invoke(target, (parameters.Length != 0) ? parameters : null);
}
}
}
namespace Minimap.API
{
internal class ActorAPI
{
public static ProtoActor GetLocalPlayer()
{
return FindActorWhere((ProtoActor a) => a.AmIAvatar());
}
public static ProtoActor GetActorByID(int? actorID)
{
if (!actorID.HasValue)
{
return null;
}
return FindActorWhere((ProtoActor a) => a.ActorID == actorID);
}
public static ProtoActor[] GetAlivePlayers()
{
return FindActorsWhere((ProtoActor a) => !a.dead && (int)a.ActorType == 1);
}
public static ProtoActor[] FindActorsWhere(Func<ProtoActor, bool> predicate)
{
try
{
return UnityObjectAPI.FindObjectsOfType<ProtoActor>().Where(predicate).ToArray();
}
catch
{
return null;
}
}
public static ProtoActor FindActorWhere(Func<ProtoActor, bool> predicate)
{
try
{
return UnityObjectAPI.FindObjectsOfType<ProtoActor>().FirstOrDefault(predicate);
}
catch
{
return null;
}
}
public static string GetActorName(ProtoActor? actor)
{
if ((Object)(object)actor == (Object)null)
{
return "Unknown";
}
return actor.nickName;
}
}
internal class HubAPI
{
public static Hub GetHub()
{
_ = Hub.s;
return Hub.s;
}
public static CameraManager GetCameraManager()
{
Hub hub = GetHub();
if (!((Object)(object)hub != (Object)null))
{
return null;
}
return Helpers.GetPropertyValue<CameraManager>(hub, "cameraman");
}
public static PersistentData GetPersistentData()
{
Hub hub = GetHub();
if (!((Object)(object)hub != (Object)null))
{
return null;
}
return Helpers.GetFieldValue<PersistentData>(hub, "pdata");
}
public static GamePlayScene GetGamePlayScene()
{
GameMainBase main = GetPersistentData().main;
GamePlayScene val = (GamePlayScene)(object)((main is GamePlayScene) ? main : null);
if (val != null)
{
return val;
}
return null;
}
}
internal class UnityObjectAPI
{
public static T[] FindObjectsOfType<T>() where T : Component
{
return Object.FindObjectsByType<T>((FindObjectsSortMode)0);
}
}
}