Decompiled source of PlayerStatueScrap v1.0.0

BepInEx/plugins/PlayerStatueScrap.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.IO;
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 IL;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using UnityEngine;

[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("PlayerStatueScrap")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Mod that adds the player model as scrap")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PlayerStatueScrap")]
[assembly: AssemblyTitle("PlayerStatueScrap")]
[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 PlayerStatueScrap
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("PlayerStatueScrap", "PlayerStatueScrap", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static AssetBundle Assets { get; private set; }

		public static ManualLogSource Log { get; private set; }

		public static ConfigFile ConfigFile { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			ConfigFile = ((BaseUnityPlugin)this).Config;
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			using (Stream stream = executingAssembly.GetManifestResourceStream("PlayerStatueScrap.Resources.modassets"))
			{
				Assets = AssetBundle.LoadFromStream(stream);
			}
			ScavengerStatue.Init();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin PlayerStatueScrap is loaded!");
		}

		public static void LogDebug(object data)
		{
			Log.LogDebug(data);
		}
	}
	internal class ScavengerStatue
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Instruction, bool> <>9__4_1;

			public static Action<GrabbableObject, Random> <>9__4_2;

			public static Manipulator <>9__4_0;

			internal void <Init>b__4_0(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: 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)
				ILCursor val = new ILCursor(il);
				val.GotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction i) => ILPatternMatchingExt.MatchLdstr(i, "Item name: {0}; {1}")
				});
				val.Emit(OpCodes.Ldloc_2);
				val.Emit(OpCodes.Ldarg_0);
				val.Emit(OpCodes.Ldfld, typeof(RoundManager).GetField("ScrapValuesRandom"));
				val.EmitDelegate<Action<GrabbableObject, Random>>((Action<GrabbableObject, Random>)delegate(GrabbableObject grabObj, Random random)
				{
					if (alternateSuitsEnabled.Value && grabObj.itemProperties.materialVariants.Length != 0 && random.NextDouble() < (double)chanceAlternateSuit.Value)
					{
						SkinnedMeshRenderer component = ((Component)grabObj).gameObject.GetComponent<SkinnedMeshRenderer>();
						if ((Object)(object)component != (Object)null)
						{
							((Renderer)component).sharedMaterial = grabObj.itemProperties.materialVariants[random.Next(0, grabObj.itemProperties.materialVariants.Length)];
						}
					}
				});
			}

			internal bool <Init>b__4_1(Instruction i)
			{
				return ILPatternMatchingExt.MatchLdstr(i, "Item name: {0}; {1}");
			}

			internal void <Init>b__4_2(GrabbableObject grabObj, Random random)
			{
				if (alternateSuitsEnabled.Value && grabObj.itemProperties.materialVariants.Length != 0 && random.NextDouble() < (double)chanceAlternateSuit.Value)
				{
					SkinnedMeshRenderer component = ((Component)grabObj).gameObject.GetComponent<SkinnedMeshRenderer>();
					if ((Object)(object)component != (Object)null)
					{
						((Renderer)component).sharedMaterial = grabObj.itemProperties.materialVariants[random.Next(0, grabObj.itemProperties.materialVariants.Length)];
					}
				}
			}
		}

		public static ConfigEntry<bool> enabled;

		public static ConfigEntry<int> rarity;

		public static ConfigEntry<bool> alternateSuitsEnabled;

		public static ConfigEntry<float> chanceAlternateSuit;

		public static void Init()
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			enabled = Plugin.ConfigFile.Bind<bool>("Scavenger Statue", "Enabled", true, "Whether the scavenger statue can spawn as a scrap");
			rarity = Plugin.ConfigFile.Bind<int>("Scavenger Statue", "Rarity", 20, "Rarity of the scavenger statue\nValue from 1 to 100");
			alternateSuitsEnabled = Plugin.ConfigFile.Bind<bool>("Scavenger Statue", "AlternateSuitsEnabled", true, "Whether the scavenger statue can spawn with alternate suits");
			chanceAlternateSuit = Plugin.ConfigFile.Bind<float>("Scavenger Statue", "ChanceAlternateSuit", 0.25f, "Chance for the scavenger statue to spawn with an alternate suit\nValue from 0 to 1");
			Item val = Plugin.Assets.LoadAsset<Item>("assets/playerscrap/playerscrap.asset");
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			if (enabled.Value)
			{
				Items.RegisterScrap(val, rarity.Value, (LevelTypes)(-1));
			}
			object obj = <>c.<>9__4_0;
			if (obj == null)
			{
				Manipulator val2 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					//IL_0038: Unknown result type (might be due to invalid IL or missing references)
					//IL_0044: 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)
					ILCursor val3 = new ILCursor(il);
					val3.GotoNext(new Func<Instruction, bool>[1]
					{
						(Instruction i) => ILPatternMatchingExt.MatchLdstr(i, "Item name: {0}; {1}")
					});
					val3.Emit(OpCodes.Ldloc_2);
					val3.Emit(OpCodes.Ldarg_0);
					val3.Emit(OpCodes.Ldfld, typeof(RoundManager).GetField("ScrapValuesRandom"));
					val3.EmitDelegate<Action<GrabbableObject, Random>>((Action<GrabbableObject, Random>)delegate(GrabbableObject grabObj, Random random)
					{
						if (alternateSuitsEnabled.Value && grabObj.itemProperties.materialVariants.Length != 0 && random.NextDouble() < (double)chanceAlternateSuit.Value)
						{
							SkinnedMeshRenderer component = ((Component)grabObj).gameObject.GetComponent<SkinnedMeshRenderer>();
							if ((Object)(object)component != (Object)null)
							{
								((Renderer)component).sharedMaterial = grabObj.itemProperties.materialVariants[random.Next(0, grabObj.itemProperties.materialVariants.Length)];
							}
						}
					});
				};
				<>c.<>9__4_0 = val2;
				obj = (object)val2;
			}
			RoundManager.SyncScrapValuesClientRpc += (Manipulator)obj;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PlayerStatueScrap";

		public const string PLUGIN_NAME = "PlayerStatueScrap";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}