Decompiled source of ConfigHelper v1.0.0

DreWulff-ConfigHelper.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx.Configuration;
using BepInEx.Logging;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;

[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("DreWulff-ConfigHelper")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7565f4e74749d4e647a9e03c15b0742572c0c27d")]
[assembly: AssemblyProduct("ConfigHelper")]
[assembly: AssemblyTitle("DreWulff-ConfigHelper")]
[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 ConfigHelper
{
	public class General
	{
		public static void ClearUnusedEntries(ConfigFile cfg)
		{
			PropertyInfo property = ((object)cfg).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(cfg, null);
			dictionary.Clear();
			cfg.Save();
		}
	}
	public class Levels
	{
		public static Dictionary<string, LevelTypes> Names = new Dictionary<string, LevelTypes>
		{
			{
				"all",
				(LevelTypes)(-1)
			},
			{
				"modded",
				(LevelTypes)1024
			},
			{
				"vanilla",
				(LevelTypes)15356
			},
			{
				"experimentation",
				(LevelTypes)4
			},
			{
				"assurance",
				(LevelTypes)8
			},
			{
				"vow",
				(LevelTypes)16
			},
			{
				"adamance",
				(LevelTypes)2048
			},
			{
				"march",
				(LevelTypes)64
			},
			{
				"offense",
				(LevelTypes)32
			},
			{
				"rend",
				(LevelTypes)128
			},
			{
				"dine",
				(LevelTypes)256
			},
			{
				"titan",
				(LevelTypes)512
			},
			{
				"embrion",
				(LevelTypes)8192
			},
			{
				"artifice",
				(LevelTypes)4096
			}
		};
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DreWulff-ConfigHelper";

		public const string PLUGIN_NAME = "ConfigHelper";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ConfigHelper.Entities
{
	public static class RarityParser
	{
		public static void Parse(string raw, out Dictionary<LevelTypes, int> levelRarities, out Dictionary<string, int> customRarities)
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			levelRarities = new Dictionary<LevelTypes, int>();
			customRarities = new Dictionary<string, int>();
			if (string.IsNullOrWhiteSpace(raw))
			{
				return;
			}
			string[] array = raw.Split(',');
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split(':');
				if (array3.Length != 2)
				{
					continue;
				}
				string text2 = array3[0].Trim();
				if (int.TryParse(array3[1].Trim(), out var result))
				{
					string key = CleanName(text2);
					if (Levels.Names.ContainsKey(key))
					{
						levelRarities[Levels.Names[key]] = result;
					}
					else
					{
						customRarities[text2] = result;
					}
				}
			}
		}

		public static string CleanName(string name)
		{
			return new string(new ReadOnlySpan<char>(name.Where(char.IsLetter).ToArray())).ToLower().Replace("level", "");
		}
	}
	public class Spawning
	{
		public static ConfigEntry<string> BuildConfig(ConfigFile cfg, Dictionary<string, int> weights)
		{
			string text = "";
			foreach (KeyValuePair<string, int> weight in weights)
			{
				text = text + weight.Key + ":" + weight.Value + ",";
			}
			return cfg.Bind<string>("Spawning", "Rarity", text, "Spawn weights per moon.\nFormat: Key:Weight,Key:Weight\nKeys can be:\n- Names of vanilla moons (e.g., 'Experimentation', '41-experimentation', 'ExperimentationLevel')\n- Custom moon names ('Junic', '60 Mazon', etc)\n- Blanket tags: 'All', 'Vanilla', 'Modded'");
		}

		public static void GetRarities(ConfigFile cfg, Dictionary<string, int> defaultWeights, out Dictionary<LevelTypes, int> vanillaRarities, out Dictionary<string, int> customRarities)
		{
			ConfigEntry<string> val = BuildConfig(cfg, defaultWeights);
			RarityParser.Parse(val.Value, out vanillaRarities, out customRarities);
		}

		public static void LogRarities(ManualLogSource logger, Dictionary<LevelTypes, int> vanillaRarities, Dictionary<string, int> customRarities)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<LevelTypes, int> vanillaRarity in vanillaRarities)
			{
				logger.LogInfo((object)$"Key: {vanillaRarity.Key}, Value: {vanillaRarity.Value}");
			}
			foreach (KeyValuePair<string, int> customRarity in customRarities)
			{
				logger.LogInfo((object)$"Key: {customRarity.Key}, Value: {customRarity.Value}");
			}
		}
	}
}