Decompiled source of MoreScraps v0.3.0

MoreScraps.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
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: AssemblyVersion("0.0.0.0")]
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;
		}
	}
}
namespace MoreScraps
{
	[BepInPlugin("lonewolf.morescraps", "MoreScraps", "0.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "lonewolf.morescraps";

		private const string NAME = "MoreScraps";

		private const string VERSION = "0.3.0";

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Thanks for using MoreScraps-0.3.0 by JusteLoneWolf!");
			try
			{
				LoadScraps();
				Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "lonewolf.morescraps");
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Harmony integrated, MoreScraps loaded!");
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)string.Format("{0} failed to load:\n{1}", "MoreScraps", arg));
			}
		}

		private void LoadScraps()
		{
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			string? directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (string.IsNullOrEmpty(directoryName))
			{
				throw new DirectoryNotFoundException("Impossible de trouver le dossier du plugin.");
			}
			string text = Path.Combine(directoryName, "morescraps");
			if (!File.Exists(text))
			{
				throw new FileNotFoundException("Le fichier AssetBundle 'morescraps' est introuvable.", text);
			}
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("Impossible de charger l'AssetBundle : " + text);
			}
			ScrapsDataManager scrapsDataManager = new ScrapsDataManager();
			int num = 0;
			foreach (ScrapData asset in scrapsDataManager.Assets)
			{
				((BaseUnityPlugin)this).Logger.LogDebug((object)("Chargement de : " + asset.AssetPath));
				Item val2 = val.LoadAsset<Item>(asset.AssetPath);
				if ((Object)(object)val2 == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Item introuvable : " + asset.AssetPath));
					continue;
				}
				if ((Object)(object)val2.spawnPrefab == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Le prefab de " + val2.itemName + " est manquant."));
					continue;
				}
				NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
				Utilities.FixMixerGroups(val2.spawnPrefab);
				foreach (KeyValuePair<LevelTypes, int> spawnMoonsDatum in asset.SpawnMoonsData)
				{
					Items.RegisterScrap(val2, spawnMoonsDatum.Value, spawnMoonsDatum.Key);
					((BaseUnityPlugin)this).Logger.LogDebug((object)(val2.itemName + " | " + $"Type: {spawnMoonsDatum.Key} | " + $"Rareté: {spawnMoonsDatum.Value}"));
				}
				num++;
				((BaseUnityPlugin)this).Logger.LogDebug((object)(val2.itemName + " chargé."));
			}
			val.Unload(false);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"{num}/{scrapsDataManager.Assets.Count} scraps chargés.");
		}
	}
	public class ScrapData
	{
		public string AssetPath { get; }

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

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

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

		private void InitializeAssets()
		{
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Battery/Battery.asset", GetSpawnValues(30, 30, 30, 30, 30, 30, 20, 20, 24, 24, 25)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Battery/PowerCell.asset", GetSpawnValues(2, 2, 2, 3, 3, 3, 1, 2, 2, 2, 2)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Ammo/Ammo.asset", GetSpawnValues(15, 15, 15, 10, 10, 10, 10, 10, 10, 10, 10)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Bottle/Bottle.asset", GetSpawnValues(50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Bucket/Bucket.asset", GetSpawnValues(35, 35, 35, 35, 35, 35, 20, 20, 40, 40, 30)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Camera/Camera.asset", GetSpawnValues(30, 30, 30, 40, 40, 40, 40, 50, 50, 40, 35)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Coffee/Pot.asset", GetSpawnValues(30, 30, 30, 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, 4, 4, 4, 3, 3)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/CopperWire/CopperWire.asset", GetSpawnValues(40, 40, 40, 40, 40, 40, 10, 10, 35, 45, 35)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/GameBoy/Gameboy.asset", GetSpawnValues(20, 20, 20, 25, 25, 25, 45, 45, 30, 25, 25)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/GPU/GPU.asset", GetSpawnValues(4, 4, 4, 4, 5, 5, 3, 3, 4, 4, 4)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Gears/Gears.asset", GetSpawnValues(40, 40, 40, 40, 10, 10, 30, 30, 35, 30, 30)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Hammer/Hammer.asset", GetSpawnValues(40, 40, 40, 40, 20, 20, 40, 40, 40, 40, 35)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Jerrican/Jerrican.asset", GetSpawnValues(20, 20, 20, 25, 10, 10, 20, 20, 20, 20, 20)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/MetalBeam/MetalBeam.asset", GetSpawnValues(30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/HDD/HDD.asset", GetSpawnValues(30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Monitor/Monitor.asset", GetSpawnValues(1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Laptop/Laptop.asset", GetSpawnValues(2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Microwave/Microwave.asset", GetSpawnValues(2, 2, 2, 2, 3, 3, 1, 1, 2, 2, 2)));
			Assets.Add(new ScrapData("Assets/MoreScraps/Items/Scraps/Phone/Phone.asset", GetSpawnValues(35, 35, 35, 35, 15, 15, 35, 35, 35, 35, 30)));
		}

		private Dictionary<LevelTypes, int> GetSpawnValues(params int[] values)
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			if (values == null || values.Length != 11)
			{
				throw new ArgumentException("GetSpawnValues doit recevoir exactement 11 valeurs : Experimentation, Assurance, Vow, Offense, March, Adamance, Rend, Dine, Titan, Embrion et Modded.");
			}
			string[][] array = new string[10][]
			{
				new string[1] { "ExperimentationLevel" },
				new string[1] { "AssuranceLevel" },
				new string[1] { "VowLevel" },
				new string[2] { "OffenseLevel", "OffenceLevel" },
				new string[1] { "MarchLevel" },
				new string[1] { "AdamanceLevel" },
				new string[1] { "RendLevel" },
				new string[1] { "DineLevel" },
				new string[1] { "TitanLevel" },
				new string[1] { "EmbrionLevel" }
			};
			Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
			for (int i = 0; i < array.Length; i++)
			{
				LevelTypes key = ParseLevel(array[i]);
				dictionary[key] = values[i];
			}
			dictionary[(LevelTypes)1024] = values[10];
			return dictionary;
		}

		private static LevelTypes ParseLevel(IEnumerable<string> candidateNames)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			foreach (string candidateName in candidateNames)
			{
				if (Enum.TryParse<LevelTypes>(candidateName, ignoreCase: true, out LevelTypes result))
				{
					return result;
				}
			}
			throw new InvalidOperationException("Impossible de trouver un niveau LethalLib attendu : " + string.Join(" ou ", candidateNames) + ". Vérifie que la DLL LethalLib utilisée correspond à la version du jeu.");
		}
	}
}