Decompiled source of RecallMod v1.1.1

RecallMod.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
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("RecallMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RecallMod")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
public static class RecallHud
{
	private static GameObject _panel;

	private static Image _fillImage;

	private static Text _label;

	public static void Init()
	{
		GUIManager.OnCustomGUIAvailable += CreateHud;
	}

	private static void CreateHud()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Expected O, but got Unknown
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: 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_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		if (GUIManager.Instance != null && !((Object)(object)GUIManager.CustomGUIFront == (Object)null))
		{
			_panel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.15f), new Vector2(0.5f, 0.15f), new Vector2(0f, 10f), 200f, 40f, false);
			GameObject val = new GameObject("RecallFill", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(_panel.transform, false);
			GameObject val2 = new GameObject("RecallText", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val2.transform.SetParent(_panel.transform, false);
			_label = val2.GetComponent<Text>();
			_label.text = "Recalling...";
			_label.alignment = (TextAnchor)4;
			((Graphic)_label).color = Color.white;
			_label.fontSize = 14;
			GUIManager.Instance.ApplyTextStyle(_label, 14);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			_fillImage = val.GetComponent<Image>();
			_fillImage.sprite = GUIManager.Instance.GetSprite("button");
			((Graphic)_fillImage).color = GUIManager.Instance.ValheimOrange;
			_fillImage.type = (Type)3;
			_fillImage.fillMethod = (FillMethod)0;
			_fillImage.fillOrigin = 0;
			_fillImage.fillAmount = 0f;
			_panel.SetActive(false);
		}
	}

	public static void Show()
	{
		if (!((Object)(object)_panel == (Object)null))
		{
			_fillImage.fillAmount = 0f;
			_panel.SetActive(true);
		}
	}

	public static void SetProgress(float t)
	{
		if ((Object)(object)_fillImage == (Object)null)
		{
			Logger.LogWarning((object)"[RecallHud] _fillImage is null");
			return;
		}
		_fillImage.fillAmount = Mathf.Clamp01(t);
		Logger.LogInfo((object)$"[RecallHud] fillAmount={_fillImage.fillAmount:F2}");
	}

	public static void Hide()
	{
		if (!((Object)(object)_panel == (Object)null))
		{
			_panel.SetActive(false);
		}
	}

	public static void SetText(string text)
	{
		if (!((Object)(object)_label == (Object)null))
		{
			_label.text = text;
		}
	}
}
namespace RecallMod;

internal class RecallItemContent
{
	public static void Register(AssetBundle bundle)
	{
		CustomStatusEffect recallEffect = RegisterRecallEffect();
		RegisterRecallItem(bundle, recallEffect);
	}

	private static CustomStatusEffect RegisterRecallEffect()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		SE_Recall sE_Recall = ScriptableObject.CreateInstance<SE_Recall>();
		((Object)sE_Recall).name = "SE_Recall";
		((StatusEffect)sE_Recall).m_name = "Recall";
		sE_Recall.m_recallChannelTime = 6f;
		CustomStatusEffect val = new CustomStatusEffect((StatusEffect)(object)sE_Recall, false);
		ItemManager.Instance.AddStatusEffect(val);
		return val;
	}

	private static void RegisterRecallItem(AssetBundle bundle, CustomStatusEffect recallEffect)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Expected O, but got Unknown
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Expected O, but got Unknown
		GameObject val = bundle.LoadAsset<GameObject>("recallItem");
		ItemDrop component = val.GetComponent<ItemDrop>();
		component.m_itemData.m_shared.m_itemType = (ItemType)2;
		component.m_itemData.m_shared.m_consumeStatusEffect = recallEffect.StatusEffect;
		ItemConfig val2 = new ItemConfig();
		val2.Name = "Recall";
		val2.Description = "Go home after a short channeling";
		val2.CraftingStation = CraftingStations.Workbench;
		val2.StackSize = 10;
		val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[3]
		{
			new RequirementConfig("GreydwarfEye", 5, 0, true),
			new RequirementConfig("SurtlingCore", 2, 0, true),
			new RequirementConfig("FineWood", 1, 0, true)
		};
		ItemConfig val3 = val2;
		CustomItem val4 = new CustomItem(val, false, val3);
		ItemManager.Instance.AddItem(val4);
	}
}
[BepInPlugin("chochua.RecallMod", "RecallMod", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class RecallMod : BaseUnityPlugin
{
	public const string PluginGUID = "chochua.RecallMod";

	public const string PluginName = "RecallMod";

	public const string PluginVersion = "1.1.1";

	private AssetBundle _recallBundle;

	private GameObject _recallPrefab;

	public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

	private void Awake()
	{
		Logger.LogInfo((object)"RecallMod has landed");
		Logger.LogInfo((object)("Embedded resources: " + string.Join(", ", typeof(RecallMod).Assembly.GetManifestResourceNames())));
		AssetBundle bundle = AssetUtils.LoadAssetBundleFromResources("recallitem");
		RecallItemContent.Register(bundle);
		RecallHud.Init();
	}
}
public class SE_Recall : StatusEffect
{
	public float m_recallChannelTime = 6f;

	private float _timer;

	private Player _player;

	private bool _cancelled;

	public override void Setup(Character character)
	{
		((StatusEffect)this).Setup(character);
		_player = (Player)(object)((character is Player) ? character : null);
		_timer = 0f;
		_cancelled = false;
		RecallHud.Show();
		RecallHud.SetText("Recalling");
	}

	public override void UpdateStatusEffect(float dt)
	{
		((StatusEffect)this).UpdateStatusEffect(dt);
		if (!_cancelled && !((Object)(object)_player == (Object)null))
		{
			_timer += dt;
			float num = _timer / m_recallChannelTime;
			Logger.LogInfo((object)$"[Recall] timer={_timer:F2} channelTime={m_recallChannelTime:F2} progress={num:F2}");
			RecallHud.SetProgress(num);
			if (_timer >= m_recallChannelTime)
			{
				((Character)_player).Message((MessageType)2, "Recalling...", 0, (Sprite)null);
				TeleportToSpawn();
				RecallHud.Hide();
				((Character)_player).GetSEMan().RemoveStatusEffect((StatusEffect)(object)this, false);
			}
		}
	}

	public override void Stop()
	{
		((StatusEffect)this).Stop();
		RecallHud.Hide();
	}

	public override void OnDamaged(HitData hit, Character attacker)
	{
		((StatusEffect)this).OnDamaged(hit, attacker);
		_cancelled = true;
		RecallHud.SetText("Recall Cancelled...");
		RecallHud.Hide();
		((Character)_player).Message((MessageType)2, "Recall Cancelled", 0, (Sprite)null);
		((Character)_player).GetSEMan().RemoveStatusEffect((StatusEffect)(object)this, false);
	}

	private void TeleportToSpawn()
	{
		//IL_0025: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		if (Game.instance.GetPlayerProfile().HaveCustomSpawnPoint())
		{
			((Character)_player).TeleportTo(Game.instance.GetPlayerProfile().GetCustomSpawnPoint(), ((Component)_player).transform.rotation, true);
			return;
		}
		((Character)_player).Message((MessageType)2, "No Bed Position Found, Teleporting to StartTemple", 0, (Sprite)null);
		Vector3 val = default(Vector3);
		if (ZoneSystem.instance.GetLocationIcon("StartTemple", ref val))
		{
			((Character)_player).TeleportTo(val, ((Component)_player).transform.rotation, true);
		}
	}
}