Decompiled source of MoreScraps v0.2.4

MoreScraps.dll

Decompiled 6 months 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 BepInEx;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("MoreScraps")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MoreScraps")]
[assembly: AssemblyTitle("MoreScraps")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace MoreScraps
{
	[BepInPlugin("lonewolf.morescraps", "MoreScraps", "0.2.2")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "lonewolf.morescraps";

		private const string NAME = "MoreScraps";

		private const string VERSION = "0.2.2";

		private static Plugin instance;

		private ScrapsDataManager ScrapsManager;

		private int LoadedItem;

		private void Awake()
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Thanks using MoreScraps-0.2.2 by JusteLoneWolf ! ");
			instance = this;
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "morescraps"));
			ScrapsManager = new ScrapsDataManager();
			foreach (ScrapData asset in ScrapsManager.Assets)
			{
				((BaseUnityPlugin)this).Logger.LogDebug((object)"Loadings assets...");
				Item val2 = val.LoadAsset<Item>(asset.AssetPath);
				NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
				Utilities.FixMixerGroups(val2.spawnPrefab);
				((BaseUnityPlugin)this).Logger.LogDebug((object)(val2.itemName + " loading..."));
				foreach (KeyValuePair<LevelTypes, int> spawnMoonsDatum in asset.SpawnMoonsData)
				{
					Items.RegisterScrap(val2, spawnMoonsDatum.Value, spawnMoonsDatum.Key);
					((BaseUnityPlugin)this).Logger.LogDebug((object)$"{val2}: Moons: {spawnMoonsDatum.Key}, Rarity: {spawnMoonsDatum.Value} ");
				}
				((BaseUnityPlugin)this).Logger.LogDebug((object)(val2.itemName + " is now loaded"));
			}
			((BaseUnityPlugin)this).Logger.LogDebug((object)"Assets loaded !");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Loaded ! add {ScrapsManager.Assets.Count} scraps to Lethal Company");
		}
	}
	public class ScrapData
	{
		public string AssetPath { get; private set; }

		public Dictionary<LevelTypes, int> SpawnMoonsData { get; private set; }

		public ScrapData(string assetPath, Dictionary<LevelTypes, int> spawnMoonsData)
		{
			AssetPath = assetPath;
			SpawnMoonsData = spawnMoonsData;
		}
	}
	public class ScrapsDataManager
	{
		public List<ScrapData> Assets { get; private set; }

		public ScrapsDataManager()
		{
			Assets = new List<ScrapData>();
			InitializeAssets();
		}

		private void InitializeAssets()
		{
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Battery/Battery.asset", GetSpawnValues(20, 20, 20, 24, 24, 24, 28, 28)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Battery/PowerCell.asset", GetSpawnValues(5, 5, 5, 3, 3, 1, 1, 4)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Ammo/Ammo.asset", GetSpawnValues(30, 30, 30, 28, 28, 15, 15, 20)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Bottle/Bottle.asset", GetSpawnValues(60, 60, 60, 60, 60, 60, 60, 60)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Bucket/Bucket.asset", GetSpawnValues(40, 40, 40, 40, 40, 20, 20, 25)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Camera/Camera.asset", GetSpawnValues(30, 30, 40, 40, 40, 60, 60, 60)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Coffee/Pot.asset", GetSpawnValues(30, 30, 30, 30, 30, 30, 30, 30)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Coffee/Machine.asset", GetSpawnValues(2, 2, 2, 3, 3, 3, 3, 3)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/CopperWire/CopperWire.asset", GetSpawnValues(60, 60, 60, 60, 65, 65, 65, 10)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/GameBoy/Gameboy.asset", GetSpawnValues(20, 30, 30, 30, 20, 20, 50, 50)));
		}

		private Dictionary<LevelTypes, int> GetSpawnValues(params int[] values)
		{
			LevelTypes[] array = (from LevelTypes x in Enum.GetValues(typeof(LevelTypes))
				where (int)x != -1 && (int)x != 1
				select x).ToArray();
			Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
			int num = values.Sum();
			for (int i = 0; i < array.Length; i++)
			{
				dictionary.Add(value: (i >= values.Length) ? (num / values.Length) : values[i], key: array[i]);
			}
			return dictionary;
		}
	}
}