Decompiled source of CompressedGold v1.1.1

CompressedGold.dll

Decompiled 8 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("LethalLib")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("CompressedGold")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds compressed gold from Deep Rock Galactic as an item in Lethal Company.")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("CompressedGold")]
[assembly: AssemblyTitle("CompressedGold")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 CompressedGold
{
	public class Config
	{
		public static ConfigEntry<int> compressedGoldSpawnWeight;

		public static ConfigEntry<int> compressedGoldMinValue;

		public static ConfigEntry<int> compressedGoldMaxValue;

		public static ConfigEntry<string> moonSpawnListType;

		public static ConfigEntry<string> moonSpawnList;

		public static ConfigEntry<bool> enableDebugLogging;

		public Config(ConfigFile cfg)
		{
			compressedGoldSpawnWeight = cfg.Bind<int>("Spawn Weight", "CompressedGold", 1, "How much should this item spawn (greater number = more often).\nRange: >=0");
			compressedGoldMaxValue = cfg.Bind<int>("Value", "compressedGoldMaxValue", 236, "The maximum value this item can be worth.\nRange: >=1");
			compressedGoldMinValue = cfg.Bind<int>("Value", "compressedGoldMinValue", 120, "The minimum value this item can be worth.\nRange: >=1");
			moonSpawnListType = cfg.Bind<string>("Moons", "moonSpawnListType", "ALL", "NOT FULLY TESTED, MAY NOT WORK AS INTENDED\nWhat moons this item should spawn on.\nAccepted values: ALL, VANILLA, MODDED, LIST");
			moonSpawnList = cfg.Bind<string>("Moons", "moonSpawnList", "", "NOT FULLY TESTED, MAY NOT WORK AS INTENDED\nList of moons this item should spawn on, separated by commas.\nIf you want to specify spawn weight, add the weight after the moon name, separated by an @.\nExample: RendLevel@5,TitanLevel would set it to only spawn on Rend with a spawn weight of 5, and on Titan with a weight of whatever compressedGoldSpawnWeight is set to.");
			enableDebugLogging = cfg.Bind<bool>("Debug", "enableDebugLogging", false, "Enables logs to help with debugging. You shouldn't need to enable this.");
		}
	}
	public class ItemValue
	{
		public static Item spawnedCompressedGoldItem;

		public static int maxConfigValue = Config.compressedGoldMaxValue.Value;

		public static int minConfigValue = Config.compressedGoldMinValue.Value;

		public static int maxDefaultValue = (int)((ConfigEntryBase)Config.compressedGoldMaxValue).DefaultValue;

		public static int minDefaultValue = (int)((ConfigEntryBase)Config.compressedGoldMinValue).DefaultValue;

		private static readonly bool DebugLog = Config.enableDebugLogging.Value;

		public static void SetItemValue()
		{
			spawnedCompressedGoldItem = ((IEnumerable<Item>)StartOfRound.Instance.allItemsList.itemsList).FirstOrDefault((Func<Item, bool>)((Item item) => item.itemName == "Compressed Gold"));
			if (!Object.op_Implicit((Object)(object)spawnedCompressedGoldItem) & DebugLog)
			{
				Plugin.mls.LogMessage((object)"No compressed gold found.");
				return;
			}
			if (DebugLog)
			{
				Plugin.mls.LogMessage((object)"Compressed gold found, setting value...");
			}
			if ((maxConfigValue < minConfigValue) | (maxConfigValue <= 0) | (minConfigValue <= 0))
			{
				spawnedCompressedGoldItem.maxValue = (int)((double)maxDefaultValue / 0.4);
				spawnedCompressedGoldItem.minValue = (int)((double)minDefaultValue / 0.4);
				if (DebugLog)
				{
					Plugin.mls.LogMessage((object)$"Invalid value(s) for min/max config! Using default values instead.\nMin value: {minDefaultValue} Max value: {maxDefaultValue}");
				}
			}
			else
			{
				spawnedCompressedGoldItem.maxValue = (int)((double)maxConfigValue / 0.4);
				spawnedCompressedGoldItem.minValue = (int)((double)minConfigValue / 0.4);
				if (DebugLog)
				{
					Plugin.mls.LogMessage((object)$"Using custom min/max values.\nMin value: {minConfigValue} Max value: {maxConfigValue}");
				}
			}
		}
	}
	public class MoonSpawns
	{
		public static AssetBundle CompressedGoldAssets;

		public static Item CompressedGoldItem;

		public static int configSpawnWeight = Config.compressedGoldSpawnWeight.Value;

		public static int defaultSpawnWeight = (int)((ConfigEntryBase)Config.compressedGoldSpawnWeight).DefaultValue;

		public static string moonType = Config.moonSpawnListType.Value.ToUpper();

		public static string sMoonList = Config.moonSpawnList.Value;

		private static readonly bool DebugLog = Config.enableDebugLogging.Value;

		public static void RegisterMoonSpawns()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			CompressedGoldAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "compgoldassets"));
			CompressedGoldItem = CompressedGoldAssets.LoadAsset<Item>("Assets/CompressedGold.asset");
			if ((Object)(object)CompressedGoldItem == (Object)null)
			{
				Plugin.mls.LogError((object)"Failed to load Compressed Gold assets.");
			}
			Utilities.FixMixerGroups(CompressedGoldItem.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(CompressedGoldItem.spawnPrefab);
			if (configSpawnWeight < 0)
			{
				configSpawnWeight = defaultSpawnWeight;
				if (DebugLog)
				{
					Plugin.mls.LogMessage((object)$"Invalid spawn weight. Setting to default: ({defaultSpawnWeight})...");
				}
			}
			int num = configSpawnWeight;
			if (moonType == "ALL")
			{
				Items.RegisterScrap(CompressedGoldItem, num, (LevelTypes)(-1));
				if (DebugLog)
				{
					Plugin.mls.LogMessage((object)("moonSpawnListType: " + moonType));
				}
			}
			else if (moonType == "VANILLA")
			{
				Items.RegisterScrap(CompressedGoldItem, num, (LevelTypes)1020);
				if (DebugLog)
				{
					Plugin.mls.LogMessage((object)("moonSpawnListType: " + moonType));
				}
			}
			else if (moonType == "MODDED")
			{
				Items.RegisterScrap(CompressedGoldItem, num, (LevelTypes)1024);
				if (DebugLog)
				{
					Plugin.mls.LogMessage((object)("moonSpawnListType: " + moonType));
				}
			}
			else if (moonType == "LIST")
			{
				if (DebugLog)
				{
					Plugin.mls.LogMessage((object)("moonSpawnListType: " + moonType));
				}
				string[] array = sMoonList.Split(",", StringSplitOptions.RemoveEmptyEntries);
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Split("@", StringSplitOptions.RemoveEmptyEntries);
					int num2 = array2.Length;
					int result;
					if (num2 > 2)
					{
						if (DebugLog)
						{
							Plugin.mls.LogMessage((object)("Invalid setup for " + array[i] + ". Skipping..."));
						}
					}
					else if (num2 == 1)
					{
						Items.RegisterScrap(CompressedGoldItem, num, (LevelTypes)1, array2);
						if (DebugLog)
						{
							Plugin.mls.LogMessage((object)$"Registered compressed gold for {array2[0]} with a spawn weight of {num}.");
						}
					}
					else if (!int.TryParse(array2[1], out result))
					{
						if (DebugLog)
						{
							Plugin.mls.LogMessage((object)("Could not parse spawn weight for " + array2[0] + ": " + array2[1] + ". Skipping..."));
						}
					}
					else
					{
						Items.RegisterScrap(CompressedGoldItem, result, (LevelTypes)1, array2);
						if (DebugLog)
						{
							Plugin.mls.LogMessage((object)$"Registered compressed gold for {array2[0]} with a spawn weight of {result}.");
						}
					}
				}
			}
			else
			{
				Items.RegisterScrap(CompressedGoldItem, num, (LevelTypes)(-1));
				if (DebugLog)
				{
					Plugin.mls.LogMessage((object)(moonType + " is not a valid input for moonSpawnListType! Setting to spawn on all moons..."));
				}
			}
		}
	}
	[BepInPlugin("charonym.CompressedGold", "CompressedGold", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "charonym.CompressedGold";

		public const string ModNAME = "CompressedGold";

		public const string ModVERSION = "1.1.1";

		private readonly Harmony harmony = new Harmony("charonym.CompressedGold");

		internal static ManualLogSource mls;

		public static Config ModConfig { get; internal set; }

		private void Awake()
		{
			ModConfig = new Config(((BaseUnityPlugin)this).Config);
			mls = Logger.CreateLogSource("CompressedGold");
			MoonSpawns.RegisterMoonSpawns();
			harmony.PatchAll();
			mls.LogInfo((object)"Compressed Gold 1.1.1 is loaded, we're rich!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CompressedGold";

		public const string PLUGIN_NAME = "CompressedGold";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}
namespace CompressedGold.patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostFix(StartOfRound __instance)
		{
			ItemValue.SetItemValue();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}