Decompiled source of WorldSeed v1.0.0

WorldSeed.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Koendertjh.Shared;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("WorldSeed")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a45c570d17c512d77d75166ff42bc1dee72ef243")]
[assembly: AssemblyProduct("WorldSeed")]
[assembly: AssemblyTitle("WorldSeed")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 Koendertjh.Shared
{
	internal enum Boss
	{
		None,
		Eikthyr,
		Elder,
		Bonemass,
		Moder,
		Yagluth,
		Queen,
		Fader,
		Kall
	}
	internal static class BossProgress
	{
		private static readonly string[] EnemyNames = new string[9] { null, "$enemy_eikthyr", "$enemy_gdking", "$enemy_bonemass", "$enemy_dragon", "$enemy_goblinking", "$enemy_seekerqueen", "$enemy_fader", "$enemy_frozenking_p3" };

		private static Dictionary<string, string> s_defeatKeys;

		private static ZNetScene s_keysScene;

		internal static string EnemyName(Boss boss)
		{
			return EnemyNames[(int)boss];
		}

		internal static bool IsDefeated(Boss boss)
		{
			if (boss == Boss.None)
			{
				return true;
			}
			string enemyName = EnemyName(boss);
			if (HasKilled(enemyName))
			{
				return true;
			}
			string text = DefeatKey(enemyName);
			if (string.IsNullOrEmpty(text))
			{
				return false;
			}
			if (!((Object)(object)ZoneSystem.instance != (Object)null) || !ZoneSystem.instance.GetGlobalKey(text))
			{
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					return ((Humanoid)Player.m_localPlayer).HaveUniqueKey(text);
				}
				return false;
			}
			return true;
		}

		internal static bool HasKilled(string enemyName)
		{
			Game instance = Game.instance;
			PlayerProfile val = ((instance != null) ? instance.GetPlayerProfile() : null);
			if (val == null)
			{
				return false;
			}
			PlayerStats[] playerStats = val.m_playerStats;
			foreach (PlayerStats val2 in playerStats)
			{
				if (val2?.m_enemyStats == null)
				{
					continue;
				}
				Dictionary<string, float>[] enemyStats = val2.m_enemyStats;
				foreach (Dictionary<string, float> dictionary in enemyStats)
				{
					if (dictionary != null && dictionary.TryGetValue(enemyName, out var value) && value > 0f)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static string DefeatKey(string enemyName)
		{
			if ((Object)(object)ZNetScene.instance == (Object)null)
			{
				return null;
			}
			if (s_defeatKeys == null || (Object)(object)s_keysScene != (Object)(object)ZNetScene.instance)
			{
				s_defeatKeys = new Dictionary<string, string>();
				s_keysScene = ZNetScene.instance;
				foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
				{
					Character val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Character>() : null);
					if ((Object)(object)val != (Object)null && !string.IsNullOrEmpty(val.m_defeatSetGlobalKey))
					{
						s_defeatKeys[val.m_name] = val.m_defeatSetGlobalKey;
					}
				}
			}
			s_defeatKeys.TryGetValue(enemyName, out var value);
			return value;
		}
	}
}
namespace WorldSeed
{
	internal static class Commands
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static ConsoleEvent <0>__Run;
		}

		public static void Register()
		{
			//IL_002f: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			try
			{
				object obj = <>O.<0>__Run;
				if (obj == null)
				{
					ConsoleEvent val = Run;
					<>O.<0>__Run = val;
					obj = (object)val;
				}
				new ConsoleCommand("seed", "WorldSeed: show the world seed and copy it to the clipboard", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			}
			catch (Exception ex)
			{
				WorldSeedPlugin.Log.LogWarning((object)("Couldn't add console commands: " + ex.Message));
			}
		}

		private static void Run(ConsoleEventArgs args)
		{
			string seed = WorldSeedPlugin.Seed;
			if (seed == null)
			{
				Say(args, "WorldSeed: load into a world first.");
				return;
			}
			if (!WorldSeedPlugin.Unlocked)
			{
				Say(args, "WorldSeed: " + WorldSeedPlugin.LockedText);
				return;
			}
			GUIUtility.systemCopyBuffer = seed;
			Say(args, "WorldSeed: the seed of this world is " + seed + " (copied to the clipboard).");
		}

		private static void Say(ConsoleEventArgs args, string text)
		{
			if ((Object)(object)args?.Context != (Object)null)
			{
				args.Context.AddString(text);
			}
			else
			{
				WorldSeedPlugin.Log.LogInfo((object)text);
			}
		}
	}
	[HarmonyPatch(typeof(Minimap))]
	internal static class MapLabel
	{
		private static TMP_Text s_label;

		private static float s_nextRefresh;

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Create(Minimap __instance)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text biomeNameLarge = __instance.m_biomeNameLarge;
			if (!((Object)(object)biomeNameLarge == (Object)null))
			{
				GameObject obj = Object.Instantiate<GameObject>(((Component)biomeNameLarge).gameObject, biomeNameLarge.transform.parent);
				((Object)obj).name = "WorldSeedLabel";
				Animator component = obj.GetComponent<Animator>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				RectTransform val = (RectTransform)obj.transform;
				RectTransform val2 = (RectTransform)biomeNameLarge.transform;
				Vector2 anchoredPosition = val2.anchoredPosition;
				Rect rect = val2.rect;
				val.anchoredPosition = anchoredPosition - new Vector2(0f, ((Rect)(ref rect)).height * 0.6f + 6f);
				s_label = obj.GetComponent<TMP_Text>();
				s_label.fontSize = biomeNameLarge.fontSize * 0.55f;
				s_label.text = "";
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void Refresh()
		{
			if ((Object)(object)s_label == (Object)null)
			{
				return;
			}
			if (!((Behaviour)s_label).isActiveAndEnabled)
			{
				s_nextRefresh = 0f;
			}
			else if (!(Time.time < s_nextRefresh))
			{
				s_nextRefresh = Time.time + 1f;
				string text = "";
				if (WorldSeedPlugin.ShowOnMap.Value && WorldSeedPlugin.Seed != null)
				{
					text = (WorldSeedPlugin.Unlocked ? ("Seed: " + WorldSeedPlugin.Seed) : "Seed: ???");
				}
				if (s_label.text != text)
				{
					s_label.text = text;
				}
			}
		}
	}
	[BepInPlugin("com.koendertjh.worldseed", "WorldSeed", "1.0.0")]
	public class WorldSeedPlugin : BaseUnityPlugin
	{
		public const string ModGuid = "com.koendertjh.worldseed";

		public const string ModName = "WorldSeed";

		public const string ModVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> ShowOnMap;

		internal static ConfigEntry<Boss> RequiredBoss;

		private Harmony _harmony;

		internal static string Seed
		{
			get
			{
				string text = ZNet.World?.m_seedName;
				if (!string.IsNullOrEmpty(text))
				{
					return text;
				}
				return null;
			}
		}

		internal static bool Unlocked => BossProgress.IsDefeated(RequiredBoss.Value);

		internal static string LockedText => "Defeat " + Localization.instance.Localize(BossProgress.EnemyName(RequiredBoss.Value)) + " to learn the seed of this world.";

		private void Awake()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ShowOnMap = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ShowOnMap", true, "Show the seed on the big map.");
			RequiredBoss = ((BaseUnityPlugin)this).Config.Bind<Boss>("1 - General", "RequiredBoss", Boss.None, "Keep the seed secret until you have defeated this boss.");
			_harmony = new Harmony("com.koendertjh.worldseed");
			_harmony.PatchAll(typeof(WorldSeedPlugin).Assembly);
			Commands.Register();
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class PluginInfo
	{
		public const string Version = "1.0.0";
	}
}