Decompiled source of FufuScraps v1.0.1

BepInEx/plugins/Pepegas.FufuScraps.dll

Decompiled a month ago
using System;
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.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
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("Pepegas.FufuScraps")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FufuScraps")]
[assembly: AssemblyTitle("Pepegas.FufuScraps")]
[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.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 FufuScraps
{
	[BepInPlugin("Pepegas.FufuScraps", "FufuScraps", "1.0.0")]
	public class FufuScraps : BaseUnityPlugin
	{
		public static FufuScraps Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Logger.LogInfo((object)"Pepegas.FufuScraps v1.0.0 has started loading!");
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "fufuscrapitems");
			string text2 = text + ".manifest";
			AssetBundle val = AssetBundle.LoadFromFile(text);
			Logger.LogInfo((object)text2);
			if (File.Exists(text2))
			{
				Logger.LogInfo((object)"Manifest Found");
				string text3 = "";
				IEnumerable<string> enumerable = File.ReadLines(text2);
				foreach (string item in enumerable)
				{
					string text4 = item.Trim();
					if (text4.StartsWith("-"))
					{
						if (!text3.StartsWith("Assets") || !text4.StartsWith("-") || !text4.EndsWith(".asset") || (!text4.Contains("Scrap") && !text4.Contains("Shop")))
						{
							continue;
						}
						Logger.LogDebug((object)("Item found in manifest " + text4));
						string text5 = text4;
						Item val2 = val.LoadAsset<Item>(text5.Substring(2, text5.Length - 2));
						if ((Object)(object)val2 != (Object)null)
						{
							NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
							Utilities.FixMixerGroups(val2.spawnPrefab);
							if (text4.Contains("Shop"))
							{
								Logger.LogDebug((object)("Item: " + val2.itemName + " loading as Shop Item"));
								Items.RegisterShopItem(val2, val2.creditsWorth);
								continue;
							}
							Logger.LogDebug((object)("Item: " + val2.itemName + " loading as Scrap Item"));
							int num = RetrieveScrapRarity(val2.itemName);
							Logger.LogInfo((object)$"Item: {val2.itemName} loading with rarity {num}");
							Material[] materialVariants = val2.materialVariants;
							if (materialVariants != null && materialVariants.Length != 0)
							{
								Logger.LogDebug((object)("Item: " + val2.itemName + " has material variants, implementing each separately."));
								for (int i = 0; i < val2.materialVariants.Length; i++)
								{
									Item val3 = Object.Instantiate<Item>(val2);
									((Object)val3).name = ((Object)val3).name + i;
									try
									{
										text5 = text4;
										string text6 = text5.Substring(2, text5.Length - 2);
										text6 = text6.Substring(0, text6.LastIndexOf('/'));
										text6 = text6 + "/" + ((Object)val2.materialVariants[i]).name + ".prefab";
										GameObject val4 = val.LoadAsset<GameObject>(text6);
										if ((Object)(object)val4 != (Object)null)
										{
											val3.spawnPrefab = val4;
											HandleSpecialItemAttributes(val3, val);
											Items.RegisterScrap(val3, num, (LevelTypes)(-1));
											Logger.LogDebug((object)("Item: " + val3.itemName + " loaded successfully with material variant " + ((Object)val3.materialVariants[i]).name));
										}
										else
										{
											Logger.LogDebug((object)("Failed to load prefab for variant: " + text6));
										}
									}
									catch (Exception ex)
									{
										Logger.LogError((object)("Item: " + val3.itemName + " failed to load " + ((Object)val3.materialVariants[i]).name + " - " + ex.Message + " - " + ex.StackTrace));
									}
								}
							}
							else
							{
								HandleSpecialItemAttributes(val2, val);
								Items.RegisterScrap(val2, num, (LevelTypes)(-1));
								Logger.LogInfo((object)("Item: " + val2.itemName + " loaded successfully"));
							}
						}
						else
						{
							Logger.LogError((object)"Item failed to load");
						}
					}
					else
					{
						text3 = text4;
					}
				}
			}
			Logger.LogInfo((object)"Pepegas.FufuScraps v1.0.0 has loaded!");
		}

		public static void CopyObjectAttributes(object newobj, object oldobj, bool log = false)
		{
			PropertyInfo[] properties = newobj.GetType().GetProperties();
			foreach (PropertyInfo propertyInfo in properties)
			{
				if (!propertyInfo.CanWrite)
				{
					continue;
				}
				try
				{
					propertyInfo.SetValue(newobj, propertyInfo.GetValue(oldobj));
					if (log)
					{
						Logger.LogInfo((object)propertyInfo.Name);
					}
				}
				catch
				{
					Logger.LogInfo((object)("Ignored prop: " + propertyInfo.Name));
				}
			}
			FieldInfo[] fields = newobj.GetType().GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				try
				{
					fieldInfo.SetValue(newobj, fieldInfo.GetValue(oldobj));
					if (log)
					{
						Logger.LogInfo((object)fieldInfo.Name);
					}
				}
				catch
				{
					Logger.LogInfo((object)("Ignored prop: " + fieldInfo.Name));
				}
			}
		}

		public static int RetrieveScrapRarity(string itemname)
		{
			string text = itemname.ToLower();
			if (1 == 0)
			{
			}
			int result = ((text == "scythe") ? 25 : ((!(text == "suppy cup")) ? 50 : 45));
			if (1 == 0)
			{
			}
			return result;
		}

		public static void HandleSpecialItemAttributes(Item item, AssetBundle bundle)
		{
			Logger.LogDebug((object)("Handling special attributes: " + ((Object)item).name));
			if (((Object)item).name.Contains("Scythe"))
			{
				item.grabAnim = "HoldLung";
				item.twoHandedAnimation = true;
				Shovel component = item.spawnPrefab.GetComponent<Shovel>();
				if ((Object)(object)component != (Object)null)
				{
					Logger.LogDebug((object)"Fixing invalid Scythe audio");
					component.shovelAudio = item.spawnPrefab.GetComponent<AudioSource>();
					((GrabbableObject)component).mainObjectRenderer = item.spawnPrefab.GetComponent<MeshRenderer>();
					component.hitSFX = (AudioClip[])(object)new AudioClip[3]
					{
						component.hitSFX.FirstOrDefault(),
						component.hitSFX.FirstOrDefault(),
						bundle.LoadAsset<AudioClip>("Assets/LethalCompany/Mods/ShovelHitDefault.ogg")
					};
				}
			}
			else if (((Object)item).name.Contains("Suppy"))
			{
				Logger.LogDebug((object)"Suppy Cup Identified");
				Shaker shaker = item.spawnPrefab.AddComponent<Shaker>();
				((GrabbableObject)shaker).grabbable = true;
				((GrabbableObject)shaker).grabbableToEnemies = true;
				((GrabbableObject)shaker).itemProperties = item;
				AudioClip val = bundle.LoadAsset<AudioClip>("Assets/Scrap/Cups/Shake.wav");
				((NoisemakerProp)shaker).noiseSFX = (AudioClip[])(object)new AudioClip[1] { val };
				((NoisemakerProp)shaker).noiseSFXFar = (AudioClip[])(object)new AudioClip[1] { val };
				((NoisemakerProp)shaker).noiseAudioFar = (((NoisemakerProp)shaker).noiseAudio = item.spawnPrefab.GetComponent<AudioSource>());
				((NoisemakerProp)shaker).noiseRange = 15f;
				((NoisemakerProp)shaker).maxLoudness = 1f;
				((NoisemakerProp)shaker).minLoudness = 0.5f;
				((NoisemakerProp)shaker).minPitch = 0.93f;
				((NoisemakerProp)shaker).maxPitch = 1f;
			}
		}
	}
	internal class Shaker : NoisemakerProp
	{
		internal static ManualLogSource Logger = new ManualLogSource("Error");

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			if (buttonDown)
			{
				PlayerControllerB playerHeldBy = ((GrabbableObject)this).playerHeldBy;
				if (playerHeldBy != null)
				{
					playerHeldBy.playerBodyAnimator.Play("ShakeItem", 2);
				}
			}
			((NoisemakerProp)this).ItemActivate(used, buttonDown);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Pepegas.FufuScraps";

		public const string PLUGIN_NAME = "FufuScraps";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}