Decompiled source of LunarAnomalies v1.0.0

plugins/LunarAnomalies/TheWeavers.LunarAnomalies.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LunarAnomalies.MoonsScript;
using LunarAnomalies.Patch;
using Microsoft.CodeAnalysis;
using StaticNetcodeLib;
using TheWeavers.LunarAnomalies.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TheWeavers.LunarAnomalies")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+36cbc5b35d19feb2a8ccd9864063ceeb192f8ad2")]
[assembly: AssemblyProduct("LunarAnomalies")]
[assembly: AssemblyTitle("TheWeavers.LunarAnomalies")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 LunarAnomalies
{
	public class LightupScript : MonoBehaviour
	{
		private float duration = 30f;

		private float targetValue = 0.8f;

		private float currentValue;

		public Light light;

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(MoveValueOverTime());
		}

		private IEnumerator MoveValueOverTime()
		{
			float elapsedTime = 0f;
			while (elapsedTime < duration)
			{
				light.intensity = Mathf.Lerp(0f, targetValue, elapsedTime / duration);
				elapsedTime += Time.deltaTime;
				yield return null;
			}
			light.intensity = targetValue;
			LunarAnomaliesManager.currentMoon.ApplyImmediateEffect();
			LunarAnomaliesManager.TellPeopleMoonIsStartingClientRpc();
			((MonoBehaviour)this).InvokeRepeating("MiddleManFunction", 0f, (float)LunarAnomaliesManager.currentMoon.timeBetweenEachCall);
		}

		public void MiddleManFunction()
		{
			LunarAnomaliesManager.UpdateMoon();
		}

		private void OnDestroy()
		{
			MonoBehaviourHelper.Instance.CancelInvokeMoonUpdate();
			MonoBehaviour.Internal_CancelInvokeAll((MonoBehaviour)(object)this);
		}
	}
	public class MonoBehaviourHelper : MonoBehaviour
	{
		private static MonoBehaviourHelper instance;

		public static MonoBehaviourHelper Instance
		{
			get
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Expected O, but got Unknown
				if ((Object)(object)instance == (Object)null)
				{
					instance = Object.FindObjectOfType<MonoBehaviourHelper>();
					if ((Object)(object)instance == (Object)null)
					{
						GameObject val = new GameObject("MonoBehaviourHelper");
						instance = val.AddComponent<MonoBehaviourHelper>();
					}
				}
				return instance;
			}
		}

		private void Awake()
		{
			if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			instance = this;
			((MonoBehaviour)this).InvokeRepeating("Middleman", 0f, 5f);
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		}

		public void InvokeRepeatCallMoon(float x)
		{
			((MonoBehaviour)this).InvokeRepeating("MiddlemanUpdateMoon", 0f, x);
		}

		public void CancelInvokeMoonUpdate()
		{
			((MonoBehaviour)this).CancelInvoke("MiddlemanUpdateMoon");
		}

		public void MiddlemanUpdateMoon()
		{
			Plugin.Logger.LogInfo((object)"We did do the update");
			LunarAnomaliesManager.UpdateMoon();
		}

		private void Middleman()
		{
			LunarAnomaliesManager.TryApplyingEffect();
		}
	}
	[BepInPlugin("TheWeavers.LunarAnomalies", "LunarAnomalies", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static AssetBundle? ModAssets;

		private readonly Harmony harmony = new Harmony("TheWeavers.LunarAnomalies");

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			InitializeNetworkBehaviours();
			string path = "lunaranomaliesmodassets";
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path);
			Logger.LogInfo((object)("Attempting to load AssetBundle from path: " + text));
			if (!File.Exists(text))
			{
				Logger.LogError((object)("AssetBundle file does not exist at path: " + text));
				return;
			}
			ModAssets = AssetBundle.LoadFromFile(text);
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			Logger.LogInfo((object)"AssetBundle loaded successfully.");
			GameObject goldMoon = ModAssets.LoadAsset<GameObject>("GoldMoon");
			GameObject blueMoon = ModAssets.LoadAsset<GameObject>("BlueMoon");
			GameObject redMoon = ModAssets.LoadAsset<GameObject>("RedMoon");
			LunarAnomaliesManager.SetMoon(delegate(HarvestMoon moon)
			{
				moon.Init(goldMoon);
			});
			LunarAnomaliesManager.SetMoon(delegate(DiamondMoon moon)
			{
				moon.Init(blueMoon);
			});
			LunarAnomaliesManager.SetMoon(delegate(BloodMoon moon)
			{
				moon.Init(redMoon);
			});
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(EntranceTeleport));
			Logger.LogInfo((object)"Plugin TheWeavers.LunarAnomalies is loaded!");
		}

		private static void InitializeNetworkBehaviours()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
				typeof(EnemyAI).IsAssignableFrom(type);
			}
		}
	}
	[StaticNetcode]
	public static class LunarAnomaliesManager
	{
		public static GameObject Moon;

		public static List<Moon> moons = new List<Moon>();

		public static Moon currentMoon;

		private static bool hasAlreadyTried = false;

		public static GameObject moonGameObject;

		public static void SetMoon<T>(Action<T> initializationAction) where T : Moon, new()
		{
			T val = new T();
			initializationAction?.Invoke(val);
			moons.Add(val);
		}

		public static void TryApplyingEffect()
		{
			Plugin.Logger.LogInfo((object)RoundManager.Instance.timeScript.globalTime.ToString());
			if (RoundManager.Instance.timeScript.globalTime >= 730f)
			{
				if (!hasAlreadyTried)
				{
					hasAlreadyTried = true;
					if (((NetworkBehaviour)RoundManager.Instance).IsHost)
					{
						ReachedNight();
					}
				}
			}
			else
			{
				hasAlreadyTried = false;
			}
		}

		public static void ReachedNight()
		{
			if (!((Object)(object)moonGameObject == (Object)null))
			{
				return;
			}
			moons.Reverse();
			foreach (Moon moon in moons)
			{
				if (moon.precentageChanceSpawn >= Random.Range(0f, 100f))
				{
					SpawnMoonClientRpc(moon.name);
					currentMoon = moon;
					break;
				}
			}
		}

		[ClientRpc]
		public static void SpawnMoonClientRpc(string name)
		{
			foreach (Moon moon in moons)
			{
				if (moon.name == name)
				{
					currentMoon = moon;
					moonGameObject = Object.Instantiate<GameObject>(moon.moonObject);
				}
			}
		}

		[ClientRpc]
		public static void TellPeopleMoonIsStartingClientRpc()
		{
			HUDManager.Instance.DisplayTip(currentMoon.headerText, currentMoon.messageMoon, true, false, "LC_Tip1");
		}

		public static void StopUpdatingMoon()
		{
			Plugin.Logger.LogInfo((object)("Called Moon " + currentMoon.name + " intervale!"));
			((MonoBehaviour)MonoBehaviourHelper.Instance).CancelInvoke("UpdateMoon");
		}

		public static void UpdateMoon()
		{
			currentMoon.ApplyConstantEffect();
		}
	}
	[StaticNetcode]
	public static class MoonsNetworkManageer
	{
		[ClientRpc]
		public static void ExtendDeadlineClientRpc(int days)
		{
			float timeUntilDeadline = TimeOfDay.Instance.timeUntilDeadline;
			TimeOfDay instance = TimeOfDay.Instance;
			instance.timeUntilDeadline += TimeOfDay.Instance.totalTime * (float)days;
			TimeOfDay.Instance.UpdateProfitQuotaCurrentTime();
			TimeOfDay.Instance.SyncTimeClientRpc(TimeOfDay.Instance.globalTime, (int)TimeOfDay.Instance.timeUntilDeadline);
		}

		[ClientRpc]
		public static void ChangeScrapValueClientRpc()
		{
			GameObject[] array = GameObject.FindGameObjectsWithTag("PhysicsProp");
			foreach (GameObject val in array)
			{
				PhysicsProp component = val.GetComponent<PhysicsProp>();
				if ((Object)(object)component != (Object)null && ((GrabbableObject)component).isInFactory)
				{
					((GrabbableObject)component).SetScrapValue(((GrabbableObject)component).scrapValue * 2);
				}
			}
		}

		[ClientRpc]
		public static void EndOfRoundClientRpc()
		{
			Plugin.Logger.LogInfo((object)"Destroying the moon on all clients!");
			if ((Object)(object)LunarAnomaliesManager.moonGameObject != (Object)null)
			{
				Plugin.Logger.LogInfo((object)"Current mon found, Attempting destruction");
				Object.Destroy((Object)(object)LunarAnomaliesManager.moonGameObject);
				LunarAnomaliesManager.StopUpdatingMoon();
			}
			else if (Object.op_Implicit((Object)(object)Object.FindObjectOfType<LightupScript>()))
			{
				Object.Destroy((Object)(object)((Component)Object.FindObjectOfType<LightupScript>()).gameObject);
			}
		}
	}
	internal static class P
	{
		internal static void Log(object data)
		{
			Plugin.Logger.LogInfo(data);
		}

		internal static void LogError(object data)
		{
			Plugin.Logger.LogError(data);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TheWeavers.LunarAnomalies";

		public const string PLUGIN_NAME = "LunarAnomalies";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LunarAnomalies.Patch
{
	[HarmonyPatch(typeof(EntranceTeleport))]
	public class EntranceTeleport
	{
		[HarmonyPatch("TeleportPlayer")]
		[HarmonyPostfix]
		private static void PostFixStartFunction(EntranceTeleport __instance)
		{
			LightupScript lightupScript = Object.FindObjectOfType<LightupScript>();
			if (GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				((Behaviour)lightupScript.light).enabled = false;
			}
			else
			{
				((Behaviour)lightupScript.light).enabled = true;
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void PostFixStartFunction(RoundManager __instance)
		{
			MonoBehaviourHelper instance = MonoBehaviourHelper.Instance;
		}

		[HarmonyPatch("UnloadSceneObjectsEarly")]
		[HarmonyPostfix]
		private static void PostFixStart(RoundManager __instance)
		{
			MoonsNetworkManageer.EndOfRoundClientRpc();
		}
	}
}
namespace LunarAnomalies.MoonsScript
{
	public class BloodMoon : Moon
	{
		public string name { get; set; } = "Blood Moon";


		public Color color { get; set; } = new Color(224f, 29f, 20f, 255f);


		public GameObject moonObject { get; set; }

		public float precentageChanceSpawn { get; set; } = 10f;


		public int timeBetweenEachCall { get; set; } = 4;


		public string headerText { get; set; } = "The Blood Moon rises...";


		public string messageMoon { get; set; } = "Beware the terrors that come with its crimson glow";


		public void Init(GameObject gameObject)
		{
			moonObject = gameObject;
		}

		public void ApplyImmediateEffect()
		{
		}

		public void ApplyConstantEffect()
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)RoundManager.Instance).IsHost || Object.FindObjectsOfType<EnemyAI>().Length > 30)
			{
				return;
			}
			if (Random.Range(0, 2) == 0)
			{
				Plugin.Logger.LogInfo((object)"Spawning Inside enemy");
				List<SpawnableEnemyWithRarity> list = new List<SpawnableEnemyWithRarity>();
				list.AddRange(RoundManager.Instance.currentLevel.Enemies);
				List<SpawnableEnemyWithRarity> list2 = list.Where((SpawnableEnemyWithRarity x) => !x.enemyType.isOutsideEnemy).ToList();
				SpawnableEnemyWithRarity val = null;
				if (list2.Count > 0)
				{
					int index = Random.Range(0, list2.Count);
					val = list2[index];
					RoundManager.Instance.SpawnEnemyGameObject(RoundManager.Instance.GetRandomNavMeshPositionInRadius(((Component)RoundManager.Instance.allEnemyVents[RandomNumberGenerator.GetInt32(RoundManager.Instance.allEnemyVents.Length)]).transform.position, 3f, default(NavMeshHit)), (float)Random.RandomRangeInt(0, 360), RoundManager.Instance.currentLevel.Enemies.IndexOf(val), val.enemyType);
				}
				else
				{
					Plugin.Logger.LogError((object)"No enemies match the criteria");
				}
				return;
			}
			Plugin.Logger.LogInfo((object)"Spawning Outside enemy");
			List<SpawnableEnemyWithRarity> list3 = new List<SpawnableEnemyWithRarity>();
			list3.AddRange(RoundManager.Instance.currentLevel.OutsideEnemies);
			List<SpawnableEnemyWithRarity> list4 = list3.Where((SpawnableEnemyWithRarity x) => x.enemyType.isOutsideEnemy).ToList();
			SpawnableEnemyWithRarity val2 = null;
			if (list4.Count > 0)
			{
				int index2 = Random.Range(0, list4.Count);
				val2 = list4[index2];
				if (val2 == null)
				{
					Plugin.Logger.LogError((object)"Didn't find an Outside enemy");
				}
				else
				{
					RoundManager.Instance.SpawnEnemyGameObject(RoundManager.Instance.GetRandomNavMeshPositionInRadius(RoundManager.Instance.outsideAINodes[Random.Range(0, RoundManager.Instance.outsideAINodes.Length)].transform.position, 10f, default(NavMeshHit)), (float)Random.RandomRangeInt(0, 360), RoundManager.Instance.currentLevel.Enemies.IndexOf(val2), val2.enemyType);
				}
			}
			else
			{
				Plugin.Logger.LogError((object)"No enemies match the criteria");
			}
		}
	}
	public class DiamondMoon : Moon
	{
		public string name { get; set; } = "Diamond Moon";


		public Color color { get; set; } = new Color(20f, 141f, 224f, 255f);


		public GameObject moonObject { get; set; }

		public float precentageChanceSpawn { get; set; } = 10f;


		public int timeBetweenEachCall { get; set; } = 60;


		public string headerText { get; set; } = "A Diamond Moon illuminates the night...";


		public string messageMoon { get; set; } = "\nTreasures and fortunes await those brave enough to seek them.";


		public void Init(GameObject gameObject)
		{
			moonObject = gameObject;
		}

		public void ApplyImmediateEffect()
		{
			MoonsNetworkManageer.ChangeScrapValueClientRpc();
		}

		public void ApplyConstantEffect()
		{
		}
	}
	public class HarvestMoon : Moon
	{
		public string name { get; set; } = "Harvest Moon";


		public Color color { get; set; } = new Color(218f, 206f, 10f, 255f);


		public GameObject moonObject { get; set; }

		public float precentageChanceSpawn { get; set; } = 10f;


		public int timeBetweenEachCall { get; set; } = 4;


		public string headerText { get; set; } = "The Harvest Moon casts its golden light...";


		public string messageMoon { get; set; } = "\nThe company is feeling generous";


		public void Init(GameObject gameObject)
		{
			moonObject = gameObject;
		}

		public void ApplyImmediateEffect()
		{
			MoonsNetworkManageer.ExtendDeadlineClientRpc(1);
		}

		public void ApplyConstantEffect()
		{
		}
	}
	public interface Moon
	{
		string name { get; set; }

		Color color { get; set; }

		GameObject moonObject { get; set; }

		float precentageChanceSpawn { get; set; }

		int timeBetweenEachCall { get; set; }

		string headerText { get; set; }

		string messageMoon { get; set; }

		void Init(GameObject gameObject);

		void ApplyImmediateEffect();

		void ApplyConstantEffect();
	}
}
namespace TheWeavers.LunarAnomalies.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}