using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using UnityEngine;
using UnityEngine.Events;
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("Erenshor-Area-Maps-Mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Erenshor-Area-Maps-Mod")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a7d024e2-15bb-4b54-a3e0-f13ac143f6be")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Erenshor_Area_Maps_Mod;
public class AreaMaps : MonoBehaviour
{
private readonly string mapAssetsPath = Path.Combine(Paths.PluginPath, "Ayloonah.Erenshor-Area-Maps-Mod", "Assets");
private List<string> mapAreas = new List<string>
{
"Azure", "Azynthi", "AzynthiClear", "Blight", "Brake", "Braxonian", "Duskenlight", "FernallaField", "Hidden", "Loomingwood",
"Malaroth", "Ripper", "SaltedStrand", "ShiveringStep", "ShiveringTomb", "Silkengrass", "Soluna", "Stowaway", "Tutorial", "Vitheo",
"Windwashed", "Abyssal", "Bonepits", "Braxonia", "DuskenPortal", "Elderstone", "FernallaPortal", "Jaws", "Krakengard", "PrielPlateau",
"RipperPortal", "Rockshade", "Rottenfoot", "Undercity", "Underspine", "VitheosEnd"
};
private Dictionary<string, Texture2D> mapCache = new Dictionary<string, Texture2D>();
private string sceneName;
private GameObject mapCanvas;
private string lastLoadedMap = "";
private Button toggleButton;
private bool showingWorldMap = false;
private Text toggleButtonText;
private void Awake()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
sceneName = ((Scene)(ref scene)).name;
if (sceneName == "Menu" || sceneName == "LoadScene")
{
return;
}
if ((Object)(object)mapCanvas == (Object)null)
{
RectTransform[] array = Resources.FindObjectsOfTypeAll<RectTransform>();
foreach (RectTransform val in array)
{
if (((Object)val).name == "Map" && (Object)(object)((Component)val).GetComponent<Image>() != (Object)null)
{
mapCanvas = ((Component)val).gameObject;
break;
}
}
}
if ((Object)(object)mapCanvas == (Object)null)
{
return;
}
CreateToggleButton();
Image component = mapCanvas.GetComponent<Image>();
if (!((Object)(object)component == (Object)null) && lastLoadedMap != sceneName)
{
if (!mapAreas.Contains(sceneName) || mapAreas.IndexOf(sceneName) >= 21)
{
ApplyMapTexture("MapRoutes", isWorldMap: true);
ButtonSetter(-2, hasAreaMap: false);
}
else
{
ApplyMapTexture(sceneName, isWorldMap: false);
ButtonSetter(mapAreas.IndexOf(sceneName));
}
}
}
private void CreateToggleButton()
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: 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_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: 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_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Expected O, but got Unknown
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Expected O, but got Unknown
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: 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_0253: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)mapCanvas == (Object)null) && !((Object)(object)toggleButton != (Object)null))
{
GameObject val = new GameObject("MapToggleButton", new Type[4]
{
typeof(RectTransform),
typeof(CanvasRenderer),
typeof(Image),
typeof(Button)
});
val.transform.SetParent(mapCanvas.transform, false);
RectTransform component = val.GetComponent<RectTransform>();
component.anchorMin = new Vector2(1f, 0f);
component.anchorMax = new Vector2(1f, 0f);
component.anchoredPosition = new Vector2(-60f, 0f);
component.sizeDelta = new Vector2(100f, 40f);
Image component2 = val.GetComponent<Image>();
((Graphic)component2).color = new Color(1f / 85f, 18f / 85f, 24f / 85f, 1f);
Outline val2 = val.AddComponent<Outline>();
((Shadow)val2).effectColor = new Color(0.2784314f, 35f / 51f, 0.7058824f, 1f);
((Shadow)val2).effectDistance = new Vector2(1f, 1f);
Button component3 = val.GetComponent<Button>();
((UnityEvent)component3.onClick).AddListener(new UnityAction(ToggleMapView));
toggleButton = component3;
GameObject val3 = new GameObject("Text", new Type[3]
{
typeof(RectTransform),
typeof(CanvasRenderer),
typeof(Text)
});
val3.transform.SetParent(val.transform, false);
RectTransform component4 = val3.GetComponent<RectTransform>();
component4.anchorMin = Vector2.zero;
component4.anchorMax = Vector2.one;
component4.offsetMin = Vector2.zero;
component4.offsetMax = Vector2.zero;
toggleButtonText = val3.GetComponent<Text>();
toggleButtonText.text = (showingWorldMap ? "Area Map" : "World Map");
toggleButtonText.alignment = (TextAnchor)4;
toggleButtonText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
((Graphic)toggleButtonText).color = Color.white;
toggleButtonText.fontSize = 18;
}
}
private void ToggleMapView()
{
if ((Object)(object)mapCanvas == (Object)null)
{
return;
}
Image component = mapCanvas.GetComponent<Image>();
if ((Object)(object)component == (Object)null)
{
return;
}
if (showingWorldMap)
{
if (mapAreas.Contains(sceneName) && mapAreas.IndexOf(sceneName) < 21)
{
ApplyMapTexture(sceneName, isWorldMap: false);
ButtonSetter(mapAreas.IndexOf(sceneName));
}
}
else
{
ApplyMapTexture("MapRoutes", isWorldMap: true);
ButtonSetter(-1);
}
}
private Texture2D GetMapTexture(string sceneName)
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
if (mapCache.ContainsKey(sceneName))
{
return mapCache[sceneName];
}
string path = Path.Combine(mapAssetsPath, sceneName + ".png");
if (sceneName == "MapRoutes")
{
path = Path.Combine(mapAssetsPath, "MapRoutes.png");
}
try
{
byte[] array = File.ReadAllBytes(path);
Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
ImageConversion.LoadImage(val, array);
mapCache[sceneName] = val;
return val;
}
catch (IOException ex)
{
Debug.LogWarning((object)("[AreaMaps] Failed to load map image " + sceneName + ": " + ex.Message));
return null;
}
}
private void ApplyMapTexture(string mapKey, bool isWorldMap)
{
//IL_0044: 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)
GameObject obj = mapCanvas;
Image val = ((obj != null) ? obj.GetComponent<Image>() : null);
if (!((Object)(object)val == (Object)null))
{
Texture2D mapTexture = GetMapTexture(mapKey);
val.sprite = Sprite.Create(mapTexture, new Rect(0f, 0f, (float)((Texture)mapTexture).width, (float)((Texture)mapTexture).height), new Vector2(0.5f, 0.5f));
showingWorldMap = isWorldMap;
lastLoadedMap = sceneName;
}
}
private void ButtonSetter(int index, bool hasAreaMap = true)
{
if (!hasAreaMap && index == -2)
{
Button obj = toggleButton;
if (obj != null)
{
((Component)obj).gameObject.SetActive(false);
}
}
else if (index == -1 || index >= 21)
{
if ((Object)(object)toggleButtonText != (Object)null)
{
toggleButtonText.text = "Area Map";
}
Button obj2 = toggleButton;
if (obj2 != null)
{
((Component)obj2).gameObject.SetActive(true);
}
}
else
{
if ((Object)(object)toggleButtonText != (Object)null)
{
toggleButtonText.text = "World Map";
}
Button obj3 = toggleButton;
if (obj3 != null)
{
((Component)obj3).gameObject.SetActive(true);
}
}
}
}
[BepInPlugin("com.ayloonah.erenshor_area_maps_mod", "Erenshor Area Maps Mod", "1.0.0")]
public class Mod : BaseUnityPlugin
{
private void Awake()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Erenshor Area Maps Mod loaded!");
GameObject val = new GameObject("AreaMaps");
val.AddComponent<AreaMaps>();
Object.DontDestroyOnLoad((Object)(object)val);
}
public void OnDestroy()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Erenshor Area Maps Mod unloaded!");
}
}