Decompiled source of SimpleMimicRevive v0.0.1

SimpleMimicRevive.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SimpleMimicRevive.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using WeatherRegistry;
using ZetasMoonTweaks;

[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SimpleMimicRevive")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SimpleMimicRevive")]
[assembly: AssemblyTitle("SimpleMimicRevive")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class NetworkPrefabPatch2
{
	private static readonly string MOD_GUID = "ZetaArcade.SimpleMimicRevive";

	[HarmonyPostfix]
	[HarmonyPatch("SetSingleton")]
	private static void RegisterPrefab()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0018: 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)
		GameObject val = new GameObject(MOD_GUID + " Prefab");
		((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
		Object.DontDestroyOnLoad((Object)(object)val);
		NetworkObject obj = val.AddComponent<NetworkObject>();
		FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
		field.SetValue(obj, GetHash(MOD_GUID));
		NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
		static uint GetHash(string value)
		{
			return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
		}
	}
}
namespace SimpleMimicRevive
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency("com.sigurd.csync", "5.0.1")]
	[BepInPlugin("ZetaArcade.SimpleMimicRevive", "SimpleMimicRevive", "0.0.1")]
	public class MyPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(StartOfRound), "ReviveDeadPlayers")]
		internal static class PlayerRevivePatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				PlayerDeathPatch.ResetDeaths();
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayerClientRpc")]
		internal static class PlayerDeathPatch
		{
			private static readonly HashSet<ulong> processedDeaths = new HashSet<ulong>();

			[HarmonyPrefix]
			private static void Prefix(PlayerControllerB __instance, out Vector3 __state)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				__state = ((Component)__instance).transform.position;
			}

			[HarmonyPostfix]
			private static void Postfix(PlayerControllerB __instance, Vector3 __state)
			{
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)StartOfRound.Instance == (Object)null || !((NetworkBehaviour)StartOfRound.Instance).IsServer)
				{
					return;
				}
				ulong playerClientId = __instance.playerClientId;
				if (processedDeaths.Add(playerClientId))
				{
					float weatherSpawnChance = GetWeatherSpawnChance();
					if (!(Random.Range(0f, 100f) >= weatherSpawnChance))
					{
						SpawnMasked(__state);
					}
				}
			}

			internal static void ResetDeaths()
			{
				processedDeaths.Clear();
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "StartGame")]
		internal static class RoundStartPatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				PlayerDeathPatch.ResetDeaths();
			}
		}

		private Harmony harmony = new Harmony("ZetaArcade.SimpleMimicRevive");

		public static ManualLogSource Logger;

		internal static ConfigHandler Config;

		public static MyPlugin Instance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = ((BaseUnityPlugin)this).Logger;
			Config = new ConfigHandler(((BaseUnityPlugin)this).Config);
			harmony.PatchAll();
			Logger.LogInfo((object)"Plugin is loaded!");
		}

		private static void SpawnMasked(Vector3 spawnPosition)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)StartOfRound.Instance).IsServer)
			{
				return;
			}
			EnemyType val = null;
			foreach (SpawnableEnemyWithRarity enemy in RoundManager.Instance.currentLevel.Enemies)
			{
				if (enemy.enemyType.enemyName == "Masked")
				{
					val = enemy.enemyType;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogWarning((object)"Could not find Masked EnemyType??");
				return;
			}
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(spawnPosition, Vector3.down, ref val2, 100f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				spawnPosition = ((RaycastHit)(ref val2)).point;
			}
			GameObject val3 = Object.Instantiate<GameObject>(val.enemyPrefab, spawnPosition, Quaternion.identity);
			NetworkObject component = val3.GetComponent<NetworkObject>();
			component.Spawn(true);
		}

		private static float GetWeatherSpawnChance()
		{
			float num = Mathf.Clamp(Config.defaultSpawnChance.Value, 0f, 100f);
			if ((Object)(object)RoundManager.Instance?.currentLevel == (Object)null)
			{
				return num;
			}
			SelectableLevel currentLevel = RoundManager.Instance.currentLevel;
			Weather currentWeather = WeatherManager.GetCurrentWeather(currentLevel);
			if (currentWeather == null)
			{
				Logger.LogWarning((object)"Could not get current weather!");
				return num;
			}
			string[] array = Config.weathersAndSpawnChances.Value.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split('@');
				if (array3.Length != 2)
				{
					continue;
				}
				string text2 = array3[0].Trim();
				if (!float.TryParse(array3[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					Logger.LogWarning((object)("Invalid spawn chance for " + text2 + ": " + array3[1]));
					continue;
				}
				List<Weather> list;
				try
				{
					list = ConfigHelper.ResolveStringToWeathers(text2);
				}
				catch (Exception ex)
				{
					Logger.LogWarning((object)("Could not resolve weather '" + text2 + "': " + ex.Message));
					continue;
				}
				foreach (Weather item in list)
				{
					if (string.Equals(item.Name, currentWeather.Name, StringComparison.OrdinalIgnoreCase))
					{
						Logger.LogDebug((object)("Weather: " + currentWeather.Name + ", " + $"Masked spawn chance: {result}%"));
						return Mathf.Clamp(result, 0f, 100f);
					}
				}
			}
			Logger.LogInfo((object)("No chance set for " + currentWeather.Name + ". " + $"Using default: {num}%"));
			return num;
		}
	}
	internal class PluginInfo
	{
		public const string modGUID = "ZetaArcade.SimpleMimicRevive";

		public const string modName = "SimpleMimicRevive";

		public const string modVersion = "0.0.1";
	}
}
namespace ZetasMoonTweaks
{
	public class ConfigHandler : SyncedConfig2<ConfigHandler>
	{
		[SyncedEntryField]
		public SyncedEntry<float> defaultSpawnChance;

		[SyncedEntryField]
		public SyncedEntry<string> weathersAndSpawnChances;

		public ConfigHandler(ConfigFile cfg)
			: base("ZetaArcade.SimpleMimicRevive")
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			defaultSpawnChance = SyncedBindingExtensions.BindSyncedEntry<float>(cfg, "Spawn Settings", "Default Spawn Chance", 5f, new ConfigDescription("Default % chance a player will spawn a Masked on death.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			weathersAndSpawnChances = SyncedBindingExtensions.BindSyncedEntry<string>(cfg, "Spawn Settings", "Weather Spawn Chances", "None@5;Eclipsed@50", new ConfigDescription("List of weathers and Masked spawn chances, in the format WeatherName1@SpawnChance;WeatherName2@SpawnChance; E.g. None@5;Eclipsed@50;BloodMoon@100; Make sure the spawn chances are between 0 and 100.", (AcceptableValueBase)null, Array.Empty<object>()));
			ConfigManager.Register<ConfigHandler>((SyncedConfig2<ConfigHandler>)(object)this);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace SimpleMimicRevive.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}