Decompiled source of Clearwater AdditionalFastTravel v1.0.0

BepInEx/Atlyss-AdditionalFastTravel/ATLYSS_AdditionalFastTravel.dll

Decompiled a month ago
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.Logging;
using HarmonyLib;
using Mirror;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ATLYSS_Template")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ATLYSS_Template")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("A4FDB1E9-D3B5-4F4C-AC3F-532ED2D1FBC6")]
[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 ATLYSS_Template
{
	public static class GotoCommand
	{
		public static void buildChatMessage(string inputMessage, bool useDividers = true)
		{
			string text = (useDividers ? "---\n" : "") + inputMessage + (useDividers ? "---\n" : "");
			ChatBehaviour._current.New_ChatMessage(text);
		}

		public static void ProcessCommand(string rawCommand)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			string[] array = rawCommand.Split(new char[1] { ' ' });
			if (SceneData.isInDungeon())
			{
				buildChatMessage("<color=orange>Cannot use this command while in a dungeon.</color>", useDividers: false);
				return;
			}
			if (array.Length == 2)
			{
				string text = array[1];
				try
				{
					Player._mainPlayer._pSound._aSrcGeneral.PlayOneShot(Player._mainPlayer._pSound._warp, 1f);
					Vector3 position = SceneData.data[SceneData.currentScene][text];
					((Component)Player._mainPlayer).gameObject.SetActive(false);
					((Component)Player._mainPlayer).transform.position = position;
					((Component)Player._mainPlayer).gameObject.SetActive(true);
					buildChatMessage("Moved to " + text + ".", useDividers: false);
					return;
				}
				catch (KeyNotFoundException)
				{
					buildChatMessage("<color=orange>ERROR</color>: This goto point does not exist for this area.", useDividers: false);
					return;
				}
			}
			try
			{
				string text2 = string.Join("\n", SceneData.data[SceneData.currentScene].Keys.ToArray());
				buildChatMessage("Available goto points for this area:\n" + text2 + "\nUse <color=orange>/goto [POINT]</color> to goto the given point.");
			}
			catch (KeyNotFoundException)
			{
				buildChatMessage("ERROR: No goto points were found for the current scene (" + SceneData.currentScene + ")", useDividers: false);
			}
		}
	}
	public static class Logging
	{
		public static ManualLogSource PluginLogger = Logger.CreateLogSource("AdditionalFastTravel");

		public static void Debug(string text)
		{
			PluginLogger.LogDebug((object)text);
		}

		public static void Message(string text)
		{
			PluginLogger.LogMessage((object)text);
		}

		public static void Warn(string text)
		{
			PluginLogger.LogWarning((object)text);
		}

		public static void Error(string text)
		{
			PluginLogger.LogError((object)text);
		}

		public static void Fatal(string text)
		{
			PluginLogger.LogFatal((object)text);
		}

		public static void Info(string text)
		{
			PluginLogger.LogInfo((object)text);
		}
	}
	[BepInPlugin("clearwater.atlyss.additionalfasttravel", "AdditionalFastTravel", "1.0.0")]
	public class Main : BaseUnityPlugin
	{
		public const string pluginId = "clearwater.atlyss.additionalfasttravel";

		public const string pluginName = "AdditionalFastTravel";

		public const string pluginVersion = "1.0.0";

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			Logging.Warn("-- LOADING AdditionalFastTravel--");
			Harmony val = new Harmony("clearwater.atlyss.additionalfasttravel");
			val.PatchAll();
		}

		public void onSceneLoaded(Scene scene, LoadSceneMode mode)
		{
		}
	}
	public static class SceneData
	{
		public static string currentScene = "map_hub_sanctum";

		public static List<string> dungeonScenes = new List<string> { "map_dungeon00_sanctumCatacombs", "map_dungeon01_crescentGrove" };

		public static Dictionary<string, int> defaultSpawns = new Dictionary<string, int>
		{
			{ "sanctum", 0 },
			{ "effoldTerrace", 0 },
			{ "tuulValley", 0 },
			{ "sanctumCourtyard", 0 },
			{ "crescentRoad", 0 }
		};

		public static Dictionary<string, string> sceneNames = new Dictionary<string, string>
		{
			{ "sanctum", "map_hub_sanctum" },
			{ "sanctumCourtyard", "map_zone00_sanctumCourtyard" },
			{ "outerSanctum", "map_zone00_outerSanctum" },
			{ "effoldTerrace", "map_zone00_effoldTerrace" },
			{ "tuulValley", "map_zone00_tuulValley" },
			{ "crescentRoad", "map_zone00_crescentKeep" },
			{ "gateOfTheMoon", "map_zone00_gateOfTheMoon" },
			{ "wallOfTheStars", "map_hub_wallOfTheStars" },
			{ "trialOfTheStars", "map_zone00_starwall_A1" },
			{ "sanctumArena", "map_pvp_sanctumArena" },
			{ "catacombsArena", "map_pvp_catacombsArena" }
		};

		public static Dictionary<string, Dictionary<string, Vector3>> data = new Dictionary<string, Dictionary<string, Vector3>>
		{
			{
				"map_hub_sanctum",
				new Dictionary<string, Vector3>
				{
					{
						"spawn",
						new Vector3(8.4f, 7.3f, -16.1f)
					},
					{
						"shop",
						new Vector3(200f, 11f, -110f)
					},
					{
						"enchanting",
						new Vector3(310f, 11f, -281f)
					},
					{
						"barracks",
						new Vector3(-160f, 29f, -600f)
					},
					{
						"lake",
						new Vector3(500f, 43f, 90f)
					}
				}
			},
			{
				"map_zone00_outerSanctum",
				new Dictionary<string, Vector3>
				{
					{
						"sanctumPortal",
						new Vector3(0f, -45f, -295f)
					},
					{
						"effoldTerracePortal",
						new Vector3(-342f, 6f, 926f)
					},
					{
						"crescentRoadPortal",
						new Vector3(570f, 20f, 1295f)
					},
					{
						"tuulValleyPortal",
						new Vector3(512f, 76f, 660f)
					},
					{
						"catacombsEntrance",
						new Vector3(300f, 80f, 2245f)
					},
					{
						"catacombsPVPPortal",
						new Vector3(300f, 80f, 2310f)
					},
					{
						"catacombsDungeonPortal",
						new Vector3(75f, 62f, 2245f)
					},
					{
						"catacombsMerchants",
						new Vector3(-10f, 0f, 1680f)
					},
					{
						"catacombsBossMerchants",
						new Vector3(135f, 81f, 2580f)
					},
					{
						"fishingPond",
						new Vector3(460f, 45f, 1765f)
					}
				}
			},
			{
				"map_zone00_effoldTerrace",
				new Dictionary<string, Vector3>
				{
					{
						"outerSanctumPortal",
						new Vector3(-195f, 20f, -275f)
					},
					{
						"centerArea",
						new Vector3(20f, 18f, 45f)
					}
				}
			},
			{
				"map_zone00_tuulValley",
				new Dictionary<string, Vector3>
				{
					{
						"outerSanctumPortal",
						new Vector3(-460f, 30f, 385f)
					},
					{
						"tuulEnclaveEntrance",
						new Vector3(-750f, 30f, 40f)
					},
					{
						"fastTravelPortal",
						new Vector3(25f, 12f, -715f)
					},
					{
						"rageboarCastleEntrance",
						new Vector3(-37f, 52f, -1390f)
					},
					{
						"rageboarCastleEnd",
						new Vector3(-50f, 143f, -2690f)
					}
				}
			},
			{
				"map_zone00_sanctumCourtyard",
				new Dictionary<string, Vector3>
				{
					{
						"sanctumPortal",
						new Vector3(-15f, 18f, -230f)
					},
					{
						"courtyardBack",
						new Vector3(0f, 2f, 385f)
					}
				}
			},
			{
				"map_zone00_crescentKeep",
				new Dictionary<string, Vector3>
				{
					{
						"outerSanctumPortal",
						new Vector3(650f, 47f, 990f)
					},
					{
						"keepEntrance",
						new Vector3(-150f, 55f, 235f)
					},
					{
						"groveDungeonLobby",
						new Vector3(-1265f, 225f, 575f)
					},
					{
						"groveDungeonBossMerchants",
						new Vector3(-1265f, 225f, 655f)
					},
					{
						"gateOftheMoonPortal",
						new Vector3(305f, 13f, 1040f)
					}
				}
			},
			{
				"map_hub_wallOfTheStars",
				new Dictionary<string, Vector3>
				{
					{
						"fastTravelPortal",
						new Vector3(137f, 12f, -268f)
					},
					{
						"trialOfTheStarsPortal",
						new Vector3(54f, 78f, -355f)
					},
					{
						"gateOfTheMoonPortal",
						new Vector3(-313f, 37f, -410f)
					},
					{
						"merchant",
						new Vector3(-100f, 12f, -345f)
					}
				}
			},
			{
				"map_map00_gateOfTheMoon",
				new Dictionary<string, Vector3>
				{
					{
						"wallOfTheStarsPortal",
						new Vector3(156f, 102f, 911f)
					},
					{
						"redwoudEntrance",
						new Vector3(805f, 5f, 820f)
					},
					{
						"crescentRoadPortal",
						new Vector3(612f, 3f, 93f)
					}
				}
			},
			{
				"map_zone00_starwall_A1",
				new Dictionary<string, Vector3>
				{
					{
						"wallOfTheStarsPortal",
						new Vector3(-12f, 4f, 3f)
					},
					{
						"checkpointHub",
						new Vector3(30f, 0f, 188f)
					},
					{
						"checkpoint1",
						new Vector3(60f, 448f, 185f)
					},
					{
						"checkpoint2",
						new Vector3(-10f, 878f, 184f)
					},
					{
						"checkpoint3",
						new Vector3(50f, 1130f, 181f)
					},
					{
						"summit",
						new Vector3(-9f, 1507f, 289f)
					}
				}
			}
		};

		public static bool isInDungeon()
		{
			return dungeonScenes.Contains(currentScene);
		}
	}
	public static class WarpCommand
	{
		public static void buildChatMessage(string inputMessage, bool useDividers = true)
		{
			string text = (useDividers ? "---\n" : "") + inputMessage + (useDividers ? "\n---" : "");
			ChatBehaviour._current.New_ChatMessage(text);
		}

		public static void ProcessCommand(string rawCommand)
		{
			string[] array = rawCommand.Split(new char[1] { ' ' });
			if (SceneData.isInDungeon())
			{
				buildChatMessage("<color=orange>Cannot use this command while in a dungeon.</color>", useDividers: false);
			}
			else if (array.Length == 2)
			{
				if (array[1] == "*")
				{
					string text = string.Join("\n", SceneData.sceneNames.Keys.ToArray());
					buildChatMessage("Available areas:\n" + text + "\nUse <color=orange>/warp [Area name]</color> to warp to the given area.");
				}
				else if (SceneData.sceneNames.ContainsKey(array[1]))
				{
					string text2 = array[1];
					if (SceneData.currentScene == SceneData.sceneNames[text2])
					{
						buildChatMessage("<color=orange>You are already in the target area.</color>", useDividers: false);
						return;
					}
					string text3 = "";
					try
					{
						switch (SceneData.defaultSpawns[text2])
						{
						case 0:
							text3 = "startPoint";
							break;
						case 1:
							text3 = "spawnPoint";
							break;
						case 2:
							text3 = "respawnPoint";
							break;
						}
					}
					catch (KeyNotFoundException)
					{
						Logging.Warn("Spawn name for area " + text2 + " not found in data, using spawnPoint instead");
						text3 = "spawnPoint";
					}
					string text4 = "Assets/Scenes/" + SceneData.sceneNames[text2] + ".unity";
					SceneData.currentScene = SceneData.sceneNames[text2];
					Player._mainPlayer._pSound._aSrcGeneral.PlayOneShot(Player._mainPlayer._pSound._portalInteract, 1f);
					Player._mainPlayer.Cmd_SceneTransport(text4, text3, (ZoneDifficulty)1);
				}
				else
				{
					buildChatMessage("<color=orange>ERROR</color>: Given scene does not exist", useDividers: false);
				}
			}
			else if (array.Length != 2)
			{
				buildChatMessage("Usage: <color=orange>/warp</color> [AREA] \n(Use <color=orange>/warp *</color> to view warpable areas)");
			}
		}
	}
}
namespace ATLYSS_Template.Harmony_Patches
{
	[HarmonyPatch(typeof(RecallPortal), "Init_PickupItem")]
	public static class RecallPortalUpdateScenePatch
	{
		[HarmonyPrefix]
		public static bool RecallPortalUpdateScene(NetworkIdentity _netID)
		{
			SceneData.currentScene = Player._mainPlayer._recalledMapInstance.Replace("Assets/Scenes/", "").Replace(".unity", "");
			return true;
		}
	}
	[HarmonyPatch(typeof(ScriptableSceneTransferCondition), "Init_ConditionEffect")]
	public static class RecallSkillPatch
	{
		[HarmonyPrefix]
		public static bool RecallSkillUpdateScene(StatusEntity _targetEntity, ConditionData _conDat)
		{
			SceneData.currentScene = "map_hub_sanctum";
			return true;
		}
	}
	[HarmonyPatch(typeof(WorldPortalManager), "Init_WorldPortalTeleport")]
	public static class FastTravelPortalPatch
	{
		[HarmonyPrefix]
		public static bool FastTravelPortalUpdateScene(WorldPortalEntry ____selectedWorldPortalEntry)
		{
			string currentScene = ____selectedWorldPortalEntry._scriptMapData._subScene.Replace("Assets/Scenes/", "").Replace(".unity", "");
			SceneData.currentScene = currentScene;
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerInteract), "Cmd_InteractWithPortal")]
	public static class NormalPortalPatch
	{
		[HarmonyPrefix]
		public static bool NormalPortalUpdateScene(Portal _portal, ZoneDifficulty _setDifficulty)
		{
			string currentScene = _portal._scenePortal._subScene.Replace("Assets/Scenes/", "").Replace(".unity", "");
			SceneData.currentScene = currentScene;
			return true;
		}
	}
	[HarmonyPatch(typeof(AtlyssNetworkManager), "OnStopClient")]
	public static class ResetOnLeaveGamePatch
	{
		[HarmonyPostfix]
		public static void ResetCurrentScene()
		{
			Logging.Message("Resetting current scene back to Sanctum");
			SceneData.currentScene = "map_hub_sanctum";
		}
	}
	[HarmonyPatch(typeof(ChatBehaviour), "Cmd_SendChatMessage")]
	public static class ListenForWarpCommandPatch
	{
		[HarmonyPrefix]
		public static bool WarpCommandHandler(string _message, ChatChannel _chatChannel)
		{
			if (_message.Contains("/warp"))
			{
				WarpCommand.ProcessCommand(_message);
				return false;
			}
			if (_message.Contains("/goto"))
			{
				GotoCommand.ProcessCommand(_message);
				return false;
			}
			return true;
		}
	}
}