Decompiled source of PocketPuhScrap v1.0.0

PocketPuh.dll

Decompiled a month 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using PocketPuh.Utils;
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("PocketPuh")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PocketPuh")]
[assembly: AssemblyTitle("PocketPuh")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 PocketPuh
{
	[BepInPlugin("dev.zag.PocketPuh", "PocketPuh", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string modGUID = "dev.zag.PocketPuh";

		public const string modName = "PocketPuh";

		public const string modVersion = "1.0.0";

		private static Harmony _harmony = new Harmony("dev.zag.PocketPuh");

		internal static ManualLogSource mls = Logger.CreateLogSource("dev.zag.PocketPuh");

		public static AssetBundle pocketPuhAssetBundle;

		private Dictionary<LevelTypes, int> spawnMoons = new Dictionary<LevelTypes, int>();

		private void Awake()
		{
			mls.LogInfo((object)"Loading PocketPuh");
			ModConfig.allConfigs(((BaseUnityPlugin)this).Config);
			LoadAssets();
			patchAllStuff();
		}

		private void LoadAssets()
		{
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			pocketPuhAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "pocketpuhassets"));
			if ((Object)(object)pocketPuhAssetBundle == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load PocketPuh Assets");
				return;
			}
			Item val = pocketPuhAssetBundle.LoadAsset<Item>("PocketPuh");
			if ((Object)(object)val == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load PocketPuh Prefab");
				return;
			}
			if (!ModConfig.globalSpawnWeight.Value)
			{
				int num = 0;
				string[] array = ModConfig.spawnMoons.Value.Split(',');
				foreach (string text in array)
				{
					num++;
					string text2 = text.Split('-')[0].Trim();
					int result = 0;
					if (text2.Length <= 0)
					{
						((BaseUnityPlugin)this).Logger.LogError((object)$"Moon name error, (Entry: {num})");
						continue;
					}
					if (text.Split('-')[0].Length <= 0)
					{
						((BaseUnityPlugin)this).Logger.LogError((object)$"Moon spawn weight error, (Entry: {num})");
						continue;
					}
					if (!int.TryParse(text.Split('-')[1].Trim(), out result))
					{
						((BaseUnityPlugin)this).Logger.LogError((object)$"Moon spawn weight error, (Entry: {num})");
						continue;
					}
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Moon name: {text2} | Moon spawn weight: {result}");
					LevelTypes key;
					switch (text2)
					{
					case "Experimentation":
						key = (LevelTypes)4;
						break;
					case "Assurance":
						key = (LevelTypes)8;
						break;
					case "Vow":
						key = (LevelTypes)16;
						break;
					case "Offense":
						key = (LevelTypes)32;
						break;
					case "March":
						key = (LevelTypes)64;
						break;
					case "Rend":
						key = (LevelTypes)128;
						break;
					case "Dine":
						key = (LevelTypes)256;
						break;
					case "Titan":
						key = (LevelTypes)512;
						break;
					case "Embrion":
						key = (LevelTypes)8192;
						break;
					default:
						((BaseUnityPlugin)this).Logger.LogError((object)("Vanilla moon '" + text2 + "' has no LevelType mapping."));
						continue;
					}
					spawnMoons[key] = result;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Spawn Moons: {spawnMoons}");
			}
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			if (ModConfig.globalSpawnWeight.Value)
			{
				Items.RegisterScrap(val, ModConfig.spawnWeight.Value, (LevelTypes)(-1));
			}
			else
			{
				Items.RegisterScrap(val, spawnMoons, (Dictionary<string, int>)null);
			}
			Utilities.FixMixerGroups(val.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
		}

		private static void patchAllStuff()
		{
			_harmony.PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PocketPuh";

		public const string PLUGIN_NAME = "PocketPuh";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace PocketPuh.Utils
{
	internal class ModConfig
	{
		private static bool printConfigs = true;

		public static ConfigEntry<bool> globalSpawnWeight;

		public static ConfigEntry<int> spawnWeight;

		public static ConfigEntry<string> spawnMoons;

		public static void allConfigs(ConfigFile cfg)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			globalSpawnWeight = cfg.Bind<bool>("PocketPuh", "Global Spawn Weight", false, "...");
			spawnWeight = cfg.Bind<int>("PocketPuh", "Spawn Weight", 7, new ConfigDescription("Enter the spawn weight (only for global)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>()));
			spawnMoons = cfg.Bind<string>("PocketPuh", "Spawn Moons", "Assurance-7,Rend-12,March-7", "Enter the names of moons where the PocketPuh can spawn (separated moons with ',' and spawnWeight with -) custom moons may or may not work");
			if (printConfigs)
			{
				printConfig();
			}
		}

		private static void printConfig()
		{
			Plugin.mls.LogInfo((object)$"Use Global Spawn Weight: {globalSpawnWeight.Value}");
			Plugin.mls.LogInfo((object)$"Spawn Weight: {spawnWeight.Value}");
			Plugin.mls.LogInfo((object)("Spawn Moons: " + spawnMoons.Value));
		}
	}
}