Decompiled source of HearthScrolls v1.0.2

plugins/HearthScrolls.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using SideLoader;
using SideLoader.SaveData;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace HearthScrolls;

[BepInPlugin("iggy.hearthscrolls", "HearthScrolls", "1.0.1")]
public class HearthScrolls : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ResourcesPrefabManager), "Load")]
	public class ResourcesPrefabManager_Load
	{
		private static void Postfix()
		{
		}
	}

	public const string GUID = "iggy.hearthscrolls";

	public const string NAME = "HearthScrolls";

	public const string VERSION = "1.0.1";

	internal static ManualLogSource Log;

	public static ConfigEntry<bool> ExampleConfig;

	public static HearthScrolls Instance { get; private set; }

	internal void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		RetreatCast.Init();
		new Harmony("iggy.hearthscrolls").PatchAll();
	}

	internal void Update()
	{
	}
}
public static class ItemIDs
{
	public static int RetreatScroll = -2071;

	public static string retreatTag = "RetreatTag";
}
public class PlayerVisitSave : PlayerSaveExtension
{
	public float TotalGainedXP;

	public List<string> VisitedCities = new List<string>();

	public override void ApplyLoadedSave(Character character, bool isWorldHost)
	{
		RetreatCast.PlayerVisits = VisitedCities;
	}

	public override void Save(Character character, bool isWorldHost)
	{
		VisitedCities = RetreatCast.PlayerVisits;
	}
}
public static class RetreatCast
{
	[HarmonyPatch(typeof(Item), "Use", new Type[] { typeof(Character) })]
	public class Item_Usage
	{
		[HarmonyPrefix]
		public static void Postfix(Item __instance, Character _character)
		{
			if (!_character.IsLocalPlayer || __instance.ItemID != ItemIDs.RetreatScroll)
			{
				return;
			}
			if (KnowsCity())
			{
				if (_character.Inventory.BagWeightOver > 0f || _character.Inventory.PouchWeightOver > 0f)
				{
					_character.CharacterUI.ShowInfoNotification("Too heavy...");
				}
				else
				{
					((MonoBehaviour)HearthScrolls.Instance).StartCoroutine(checkRetreat(_character));
				}
			}
			else
			{
				_character.CharacterUI.ShowInfoNotification("Regional City Unknown.");
			}
		}
	}

	public static List<string> PlayerVisits = new List<string>();

	internal static void Init()
	{
		SL.OnGameplayResumedAfterLoading += CheckVisits;
	}

	private static void CheckVisits()
	{
		if (AreaManager.Instance.GetIsCurrentAreaTownOrCity() && !PlayerVisits.Contains(SceneManagerHelper.ActiveSceneName))
		{
			PlayerVisits.Add(SceneManagerHelper.ActiveSceneName);
		}
	}

	private static IEnumerator checkRetreat(Character player)
	{
		player.Animator.speed = 0.12f;
		float castTime = 0f;
		yield return (object)new WaitForSeconds(0.3f);
		for (; castTime < 3f; castTime += 1f * Time.deltaTime)
		{
			if ((int)player.CurrentSpellCast != 15)
			{
				break;
			}
			if (((Vector2)(ref player.CharacterControl.m_moveInput)).magnitude > 0.1f)
			{
				player.Knock(false);
				break;
			}
			yield return (object)new WaitForSeconds(0.05f);
		}
		player.Animator.speed = 1f;
		if (castTime >= 2f)
		{
			player.StatusEffectMngr.AddStatusEffect(ItemIDs.retreatTag);
			player.Inventory.RemoveItem(ItemIDs.RetreatScroll, 1);
			NetworkLevelLoader.Instance.RequestSwitchArea(AreaManager.Instance.GetArea(SendArea()).SceneName, 0, 1.5f, false);
		}
	}

	private static bool KnowsCity()
	{
		string activeSceneName = SceneManagerHelper.ActiveSceneName;
		if (activeSceneName.Contains("Cierzo") || activeSceneName.Contains("Chersonese"))
		{
			if (PlayerVisits.Contains("CierzoNewTerrain") || PlayerVisits.Contains("CierzoDestroyed"))
			{
				return true;
			}
		}
		else if (activeSceneName.Contains("Berg") || activeSceneName.Contains("Emercar"))
		{
			if (PlayerVisits.Contains("Berg"))
			{
				return true;
			}
		}
		else if (activeSceneName.Contains("Levant") || activeSceneName.Contains("Abrassar"))
		{
			if (PlayerVisits.Contains("Levant"))
			{
				return true;
			}
		}
		else if (activeSceneName.Contains("Monsoon") || activeSceneName.Contains("Hallowed"))
		{
			if (PlayerVisits.Contains("Monsoon"))
			{
				return true;
			}
		}
		else if (activeSceneName.Contains("Harmattan") || activeSceneName.Contains("Antique"))
		{
			if (PlayerVisits.Contains("Harmattan"))
			{
				return true;
			}
		}
		else if ((activeSceneName.Contains("Sirocco") || activeSceneName.Contains("Caldera")) && PlayerVisits.Contains("NewSirocco"))
		{
			return true;
		}
		return false;
	}

	private static AreaEnum SendArea()
	{
		string activeSceneName = SceneManagerHelper.ActiveSceneName;
		if (activeSceneName.Contains("Cierzo") || activeSceneName.Contains("Chersonese"))
		{
			if (!QuestEventManager.Instance.HasQuestEvent(QuestEventDictionary.GetQuestEvent("lDHL_XMS7kKEs0uOqrLQjw")))
			{
				return (AreaEnum)100;
			}
			return (AreaEnum)115;
		}
		if (!activeSceneName.Contains("Berg") && !activeSceneName.Contains("Emercar"))
		{
			if (!activeSceneName.Contains("Levant") && !activeSceneName.Contains("Abrassar"))
			{
				if (!activeSceneName.Contains("Monsoon") && !activeSceneName.Contains("Hallowed"))
				{
					if (!activeSceneName.Contains("Harmattan") && !activeSceneName.Contains("Antique"))
					{
						if (!activeSceneName.Contains("Sirocco") && !activeSceneName.Contains("Caldera"))
						{
							return (AreaEnum)101;
						}
						return (AreaEnum)601;
					}
					return (AreaEnum)400;
				}
				return (AreaEnum)200;
			}
			return (AreaEnum)300;
		}
		return (AreaEnum)500;
	}
}