Decompiled source of CurseOfThistles v1.1.0

thornmaker.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
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 System.Timers;
using BepInEx;
using BepInEx.Configuration;
using GGECS;
using GGECS.Unity;
using GGUtil;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("thornmaker")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Spawn a thorn bush every second.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("thornmaker")]
[assembly: AssemblyTitle("thornmaker")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 recipebrowsernew
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "thornmaker";

		public const string PLUGIN_NAME = "thornmaker";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CurseOfThistles
{
	[BepInPlugin("org.mystgrimreaper.plugins.thornmaker", "Curse of Thistles", "1.1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private ConfigEntry<string> configEntity;

		private ConfigEntry<float> configFrequency;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Curse of Thistles is loaded!");
			configEntity = ((BaseUnityPlugin)this).Config.Bind<string>("Entity", "Entity", "thorn", "Which entity should be summoned? (use 'thorn' for thorn bushes)");
			configFrequency = ((BaseUnityPlugin)this).Config.Bind<float>("Entity.Frequency", "Frequency", 1f, "How many times per second should the entity spawn? (be careful with values greater than 1)");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Hello, world!");
		}

		private static AssetHandle<ECSGameObject> FindECSGameObject(string searchString, out string prefabName)
		{
			//IL_001e: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			searchString = searchString.ToLower();
			if (int.TryParse(searchString, out var result))
			{
				AssetHandle<ECSGameObject> val = default(AssetHandle<ECSGameObject>);
				val..ctor(result);
				ECSGameObject val2 = Assets<ECSGameObject>.Get(val);
				prefabName = ((Object)val2).name;
				return val;
			}
			AssetItem<ECSGameObject>[] assets = Assets<ECSGameObject>.GetAssets();
			List<string> list = new List<string>();
			AssetItem<ECSGameObject>[] array = assets;
			for (int i = 0; i < array.Length; i++)
			{
				AssetItem<ECSGameObject> val3 = array[i];
				list.Add(((Object)val3.asset).name.ToLower());
			}
			for (int j = 0; j < list.Count; j++)
			{
				if (searchString == list[j])
				{
					prefabName = searchString;
					return assets[j].handle;
				}
			}
			for (int k = 0; k < list.Count; k++)
			{
				if (list[k].Contains(searchString))
				{
					prefabName = list[k];
					return assets[k].handle;
				}
			}
			prefabName = string.Empty;
			return AssetHandle<ECSGameObject>.invalid;
		}

		private static Task HandleTimer()
		{
			Console.WriteLine("\nHandler not implemented...");
			throw new NotImplementedException();
		}

		private Task spawnEntity()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "scene-overworld")
			{
				Debug.LogWarning((object)"Not currently in game");
				throw new NotImplementedException();
			}
			ECSWorld val = default(ECSWorld);
			ECSEntity val2 = default(ECSEntity);
			if (!GameUniverse.TryGetPlayerAvatarWorldAndEntity(ref val, ref val2))
			{
				Debug.LogWarning((object)"Cannot process spawn entity cmd because there is no Player Entity");
				throw new NotImplementedException();
			}
			CreateTestEntityCmdSystem system = val.GetSystem<CreateTestEntityCmdSystem>();
			if (system == null)
			{
				Debug.LogWarning((object)"Cannot process spawn cmd because there is no createTestEntityCmdSystem");
				throw new NotImplementedException();
			}
			string prefabName;
			AssetHandle<ECSGameObject> val3 = FindECSGameObject(configEntity.Value, out prefabName);
			if (!val3.isValid)
			{
				Debug.LogWarning((object)("Could not find prefab using " + configEntity.Value + " as a search parameter"));
				throw new NotImplementedException();
			}
			PositionComp component = val.entityManager.GetComponent<PositionComp>(val2);
			system.SendCreateTestEntityCommand(val3, component.position);
			Debug.Log((object)("Successfully sent command to create an entity from prefab " + prefabName));
			return Task.CompletedTask;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name == "scene-overworld")
			{
				Timer timer = new Timer(1000f / configFrequency.Value);
				timer.Elapsed += async delegate
				{
					await spawnEntity();
				};
				timer.Start();
			}
		}

		private void OnEnable()
		{
			Debug.Log((object)"Plugin enabled");
			SceneManager.sceneLoaded += OnSceneLoaded;
		}
	}
}