Decompiled source of MoatMoon v1.2.0

MoatBehaviour.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using MoatBehaviour.Behaviours;
using MoatBehaviour.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.VFX;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MoatBehaviour")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoatBehaviour")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ea6458ca-dcff-48b2-aeab-ef1980ebd7a6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace MoatBehaviour
{
	[BepInPlugin("InstanceWorld.Moat", "Moat Scripts", "1.0.0")]
	public class MoatPatcher : BaseUnityPlugin
	{
		private Harmony harmony = new Harmony("InstanceWorld.Moat");

		private const string GUID = "InstanceWorld.Moat";

		private const string NAME = "Moat Scripts";

		private const string VERSION = "1.0.0";

		private static MoatPatcher Inst;

		internal static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Inst == (Object)null)
			{
				Inst = this;
			}
			mls = Logger.CreateLogSource("InstanceWorld.Moat");
			mls.LogInfo((object)"Starting MoatPatcher...");
			harmony.PatchAll(typeof(MoatPatcher));
			harmony.PatchAll(typeof(GeyserDamage));
			harmony.PatchAll(typeof(GeyserManager));
			mls.LogInfo((object)"Patching Networking...");
			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);
					}
				}
			}
			mls.LogInfo((object)"Ended MoatPatcher");
		}
	}
}
namespace MoatBehaviour.Behaviours
{
	internal class GeyserDamage : MonoBehaviour
	{
		private float lastDamage = 0f;

		public int damage = 10;

		private void OnTriggerStay(Collider other)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if (((Component)other).CompareTag("Player") && Object.op_Implicit((Object)(object)((Component)other).gameObject.GetComponent<PlayerControllerB>()) && (double)lastDamage + 0.2 < (double)Time.time)
			{
				MoatPatcher.mls.LogInfo((object)"Player in area");
				lastDamage = Time.time;
				((Component)other).gameObject.GetComponent<PlayerControllerB>().DamagePlayer(damage, true, true, (CauseOfDeath)3, 0, false, default(Vector3));
			}
		}
	}
	internal class GeyserManager : NetworkBehaviour
	{
		public static GeyserManager Instance;

		private List<int> Active;

		public GameObject[] Geysers;

		public float randMin = 0.2f;

		public float randMax = 0.6f;

		public Random rand;

		private void Awake()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			else
			{
				Object.Destroy((Object)(object)((Component)Instance).gameObject);
			}
			Active = new List<int>();
			rand = new Random(StartOfRound.Instance.randomMapSeed);
			if (((NetworkBehaviour)RoundManager.Instance).IsHost)
			{
				((UnityEvent)StartOfRound.Instance.StartNewRoundEvent).AddListener(new UnityAction(AllPlayerReadLoad));
			}
		}

		public void AllPlayerReadLoad()
		{
			MoatPatcher.mls.LogInfo((object)"awake");
			((MonoBehaviour)this).StartCoroutine(GeyserSelect());
		}

		private IEnumerator GeyserSelect()
		{
			while (true)
			{
				float randWait = Random.Range(randMin, randMax);
				int location = rand.Next(0, Geysers.Count());
				if (Geysers.Count() != 0 && !Active.Contains(location))
				{
					((MonoBehaviour)this).StartCoroutine(Explode(location));
				}
				yield return (object)new WaitForSeconds(randWait);
			}
		}

		private IEnumerator Explode(int location)
		{
			Active.Add(location);
			Animator a = ((Component)Geysers[location].transform.GetChild(0)).GetComponent<Animator>();
			a.SetTrigger("Explode");
			GeyserVFXSyncClientRpc(location);
			yield return (object)new WaitForSeconds(10f);
			Active.Remove(location);
		}

		[ClientRpc]
		public void GeyserVFXSyncClientRpc(int location)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2845143917u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, location);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2845143917u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				((Component)Geysers[location].transform.GetChild(0)).GetComponent<VisualEffect>().Play();
				Transform val3 = Geysers[location].transform.GetChild(0).Find("charge");
				if (Object.op_Implicit((Object)(object)val3))
				{
					((Component)val3).GetComponent<AudioSource>().Play();
				}
				else
				{
					MoatPatcher.mls.LogInfo((object)"Cannot find charge");
				}
				((MonoBehaviour)this).StartCoroutine(ExplodeSFX(location));
			}
		}

		private IEnumerator ExplodeSFX(int location)
		{
			yield return (object)new WaitForSeconds(4.8f);
			((Component)Geysers[location].transform.GetChild(0)).GetComponent<AudioSource>().Play();
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_GeyserManager()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2845143917u, new RpcReceiveHandler(__rpc_handler_2845143917));
		}

		private static void __rpc_handler_2845143917(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int location = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref location);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((GeyserManager)(object)target).GeyserVFXSyncClientRpc(location);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "GeyserManager";
		}
	}
}
namespace MoatBehaviour.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}