using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading.Tasks; using Archipelago.MultiClient.Net; using Archipelago.MultiClient.Net.Enums; using Archipelago.MultiClient.Net.Helpers; using Archipelago.MultiClient.Net.Models; using BepInEx; using BepInEx.Logging; using DG.Tweening; using HarmonyLib; using Microsoft.CodeAnalysis; using MoonlighterAPMod.Archipelago; using MoonlighterAPMod.Mod; using Newtonsoft.Json.Linq; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; 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: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("MoonlighterAPMod")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("0.0.0.0")] [assembly: AssemblyInformationalVersion("0.0.0+a23a1d3f322bb9a461944b85a574dff5cf28e26f")] [assembly: AssemblyProduct("Moonlighter Archipelago Mod")] [assembly: AssemblyTitle("MoonlighterAPMod")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [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 MoonlighterAPMod { internal class APDebug { private static int n; internal static void StartDebug() { n = 0; } internal static void Debug() { MoonlighterAPMod.APInfo($"Debug message: {++n}"); } } internal static class ModInfo { internal const string PLUGIN_GUID = "FeluciaPS.MoonlighterAPMod"; internal const string PLUGIN_NAME = "MoonlighterAPMod"; internal const string PLUGIN_VERSION = "0.0.0"; internal const string GAME_NAME = "Moonlighter"; } [BepInPlugin("FeluciaPS.MoonlighterAPMod", "MoonlighterAPMod", "0.0.0")] internal class MoonlighterAPMod : BaseUnityPlugin { internal static ManualLogSource Logger; internal static ArchipelagoClient client; internal static ConnectionUI connectionUI; internal static void APMessage(object obj) { Logger.LogMessage(obj); } internal static void APInfo(object obj) { Logger.LogInfo(obj); } internal static void APError(object obj) { Logger.LogError(obj); } private void Awake() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown client = new ArchipelagoClient(); Logger = ((BaseUnityPlugin)this).Logger; PatchLoader.LoadPatches(); GameObject val = new GameObject("AP-UIManager"); val.AddComponent(); GameObject val2 = new GameObject("AP-ConnectionUI"); connectionUI = val2.AddComponent(); Object.DontDestroyOnLoad((Object)(object)val2); } internal static void ExitDungeon() { DungeonResultsPanel componentInChildren = ((Component)GUIManager.Instance).GetComponentInChildren(); componentInChildren.PlayAnimations(); typeof(DungeonResultsPanel).GetField("_fromEmblem", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(componentInChildren, false); ((Panel)componentInChildren).OnBButtonPressed(); } } internal class PatchLoader { internal static Harmony harmony; internal static void LoadPatches() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown MoonlighterAPMod.APInfo("Loading patches for FeluciaPS.MoonlighterAPMod..."); harmony = new Harmony("FeluciaPS.MoonlighterAPMod"); harmony.PatchAll(Assembly.GetExecutingAssembly()); MoonlighterAPMod.APInfo("Patches for FeluciaPS.MoonlighterAPMod loaded!"); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "MoonlighterAPMod"; public const string PLUGIN_NAME = "Moonlighter Archipelago Mod"; public const string PLUGIN_VERSION = "0.0.0"; } } namespace MoonlighterAPMod.Patches { internal class BossKeyPatches { [HarmonyPatch(typeof(DungeonBossRoom))] [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class IsBossDefeatedPatch { internal static void Postfix(ref bool __result) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0020: 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) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (ArchipelagoClient.IsClientConnected) { Culture culture = DungeonManager.Instance.culture; long locationId = culture * 100 + 10; __result = LocationHelper.IsChecked(locationId); if (__result) { MoonlighterAPMod.APInfo($"Preventing {culture} boss spawn because location is checked"); } else { MoonlighterAPMod.APInfo($"Forcing {culture} boss spawn because location is unchecked"); } } } } [HarmonyPatch(typeof(DungeonBossRoom))] [HarmonyPatch("InternalOnBossDeath")] internal static class BossDeathPatch { internal static void Postfix(DungeonBossRoom __instance) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Invalid comparison between Unknown and I4 //IL_002c: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) if (ArchipelagoClient.IsClientConnected) { Culture culture = DungeonManager.Instance.culture; if ((int)culture == 5) { GoalHelper.TrySendGoal(GoalHelper.GoalType.PirateBoss); return; } long locationId = culture * 100 + 10; MoonlighterAPMod.APInfo($"Sending location for boss kill {culture}"); LocationHelper.SendLocation(locationId); MoonlighterAPMod.APInfo("Lying to the game and pretending no boss was defeated so no scary cutscenes happen"); GameManager.Instance.bossDefeatedCulture = (Culture)6; } } } [HarmonyPatch(typeof(HeroInventoryPanel))] [HarmonyPatch("UpdateBossKeys")] internal static class InventoryKeysPatch { private static void ShowKey(Image image) { DOTweenModuleUI.DOFade(image, 1f, 0.1f); } private static void HideKey(Image image) { DOTweenModuleUI.DOFade(image, 0f, 0.1f); } internal static bool Prefix(HeroInventoryPanel __instance) { if (!ArchipelagoClient.IsClientConnected) { return true; } MoonlighterAPMod.APInfo("Modifying boss key display"); if (ItemHelper.HasItem("Golem Key")) { ShowKey(__instance.golemKey); } else { HideKey(__instance.golemKey); } if (ItemHelper.HasItem("Forest Key")) { ShowKey(__instance.forestKey); } else { HideKey(__instance.forestKey); } if (ItemHelper.HasItem("Desert Key")) { ShowKey(__instance.desertKey); } else { HideKey(__instance.desertKey); } if (ItemHelper.HasItem("Tech Key")) { ShowKey(__instance.techKey); } else { HideKey(__instance.techKey); } return false; } } } internal class CrazyPetePatches { [HarmonyPatch(typeof(CrazyPeteNotes))] [HarmonyPatch("Start")] internal static class PeteInitPatch { internal static void Postfix(CrazyPeteNotes __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0014: 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) //IL_0018: Unknown result type (might be due to invalid IL or missing references) Culture culture = DungeonManager.Instance.culture; for (int i = 0; i < 3; i++) { long locationId = culture * 100 + i + 1; if (!LocationHelper.IsChecked(locationId)) { __instance.crazyPeteNoteIndex = i; break; } } } } [HarmonyPatch(typeof(CrazyPeteNotes))] [HarmonyPatch("Interact")] internal static class NotePatch { internal static void Prefix(CrazyPeteNotes __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) Culture culture = DungeonManager.Instance.culture; int num = __instance.crazyPeteNoteIndex % 3 + 1; long num2 = culture * 100 + num; MoonlighterAPMod.APInfo($"Sending crazy pete location {culture} {num} with ID {num2}."); LocationHelper.SendLocation(num2); } } } internal class DungeonDoorPatches { [HarmonyPatch(typeof(WorldDungeonDoor))] [HarmonyPatch("UpdateByCulturesDefeated")] internal static class DoorOpenPatch { private static void SetState(WorldDungeonDoor __instance, bool state) { if (state) { __instance.UnlockDoor(); } else { __instance.LockDoor(); } } private static void SetUnknownDungeonState(WorldDungeonDoor __instance) { MoonlighterAPMod.APInfo("Placing keys in 5th dungeon door"); GameObject.Find("GolemLock").SetActive(ItemHelper.HasItem("Golem Key")); GameObject.Find("ForestLock").SetActive(ItemHelper.HasItem("Forest Key")); GameObject.Find("DesertLock").SetActive(ItemHelper.HasItem("Desert Key")); GameObject.Find("TechLock").SetActive(ItemHelper.HasItem("Tech Key")); bool state = ItemHelper.HasItems(new string[4] { "Golem Key", "Forest Key", "Desert Key", "Tech Key" }); SetState(__instance, state); } internal static bool Prefix(WorldDungeonDoor __instance) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected I4, but got Unknown if (!ArchipelagoClient.IsClientConnected) { return true; } MoonlighterAPMod.APInfo($"Setting door state for {__instance.dungeonType}"); Culture dungeonType = __instance.dungeonType; Culture val = dungeonType; switch (val - 1) { case 0: SetState(__instance, ItemHelper.HasItem("Unlock Golem Dungeon")); break; case 1: SetState(__instance, ItemHelper.HasItem("Unlock Forest Dungeon")); break; case 2: SetState(__instance, ItemHelper.HasItem("Unlock Desert Dungeon")); break; case 3: SetState(__instance, ItemHelper.HasItem("Unlock Tech Dungeon")); break; case 4: SetUnknownDungeonState(__instance); break; } return false; } } } internal class DungeonLoadPatches { [HarmonyPatch(typeof(WorldDungeonDoor))] [HarmonyPatch("LoadDungeon")] internal static class DungeonLoadPatch { internal static void Prefix(WorldDungeonDoor __instance) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Invalid comparison between Unknown and I4 if (ArchipelagoClient.IsClientConnected && (int)__instance.dungeonType == 5) { GoalHelper.TrySendGoal(GoalHelper.GoalType.FifthDungeon); } } } } internal class MainMenuPatches { [HarmonyPatch(typeof(MainMenuPanel))] [HarmonyPatch("CloseGamepadPanel")] internal static class ArchipelagoMenuButtonPatch { private static readonly bool finishLater = true; internal static void Prefix(MainMenuPanel __instance) { UIManager.Instance.CreateOrUpdateVersionLabel(((Component)__instance).transform); if (!finishLater) { UIManager.Instance.CreateOrUpdateArchipelagoMenuButton(__instance); UIManager.Instance.CreateOptionsPanel(); } } } [HarmonyPatch(typeof(MainMenuPanel))] [HarmonyPatch("PrepareMenuButtons")] internal static class ArchipelagoConnectionUIPatch { internal static void Prefix() { MoonlighterAPMod.connectionUI.Show(); } } } internal class TreePatches { [HarmonyPatch(typeof(TreeBehaviour))] [HarmonyPatch("OnTriggerEnter2D")] internal static class TreeMoneyPatch { private static float n; internal static void Prefix(TreeBehaviour __instance, float ___timesTreeHitDropped) { n = ___timesTreeHitDropped; } internal static void Postfix(TreeBehaviour __instance, float ___timesTreeHitDropped) { if (___timesTreeHitDropped != n) { MoonlighterAPMod.APInfo("Sending money tree location"); LocationHelper.SendLocation(1L); } } } } } namespace MoonlighterAPMod.Mod { internal class ArchipelagoOptionsPanel : Panel { private InputFieldEntry serverInput; private InputFieldEntry portInput; private InputFieldEntry slotInput; private InputFieldEntry passwordInput; private Button connectButton; private Button disconnectButton; private Text resultMessage; private void Start() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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) //IL_008d: Unknown result type (might be due to invalid IL or missing references) ((Panel)this).Init(); serverInput = CreateInputField("Server", new Vector3(0f, 90f, 0f)); portInput = CreateInputField("Port", new Vector3(0f, 30f, 0f)); slotInput = CreateInputField("Slot", new Vector3(0f, -30f, 0f)); passwordInput = CreateInputField("Password", new Vector3(0f, -90f, 0f)); SetupNavigation(new List(4) { ((Component)serverInput).gameObject, ((Component)portInput).gameObject, ((Component)slotInput).gameObject, ((Component)passwordInput).gameObject }); ((Component)serverInput).gameObject.GetComponent().Select(); } private InputFieldEntry CreateInputField(string name, Vector3 position) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_0099: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); Transform val2 = ((Panel)this).Content.transform.Find("Canvas"); val.transform.SetParent(val2, false); val.transform.localPosition = position; val.AddComponent(); Button button = val.AddComponent