Decompiled source of CustomParams v1.0.0

CustomParams.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Atomicrops.Core.Upgrades;
using Atomicrops.Game.Data;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("CustomParams")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomParams")]
[assembly: AssemblyTitle("CustomParams")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Template
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CustomParams";

		public const string PLUGIN_NAME = "CustomParams";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CustomParams
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "pauli.plugin.CustomParams";

		public const string PLUGIN_NAME = "CustomParams";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	public class ActionContainer
	{
		public Action Function { get; set; }

		public Action Cleanup { get; set; }
	}
	public static class GlobalActions
	{
		public static Dictionary<string, ActionContainer> Actions;

		static GlobalActions()
		{
			Actions = new Dictionary<string, ActionContainer>();
		}

		public static void AddAction(string command, Action function, Action cleanup)
		{
			Actions[command] = new ActionContainer
			{
				Function = function,
				Cleanup = cleanup
			};
		}
	}
	[BepInPlugin("pauli.plugin.CustomParams", "CustomParams", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin pauli.plugin.CustomParams is loaded!");
			Harmony val = new Harmony("pauli.plugin.CustomParams");
			val.PatchAll();
		}
	}
	[HarmonyPatch(typeof(UpgradeRunner), "ApplyUpgradeList")]
	internal class UpgradeRunner_ApplyUpgradeList_Patch
	{
		private static bool Prefix(Dictionary<UpgradeDef, int> currentUpgradeStacks, object paramsObj)
		{
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Invalid comparison between Unknown and I4
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Invalid comparison between Unknown and I4
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Invalid comparison between Unknown and I4
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Invalid comparison between Unknown and I4
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Invalid comparison between Unknown and I4
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Invalid comparison between Unknown and I4
			foreach (KeyValuePair<UpgradeDef, int> currentUpgradeStack in currentUpgradeStacks)
			{
				List<UpgradeParam> @params = currentUpgradeStack.Key.GetParams(currentUpgradeStack.Value);
				if (@params == null || @params.Count == 0)
				{
					continue;
				}
				foreach (UpgradeParam item in @params)
				{
					if (item.Path.StartsWith("#"))
					{
						try
						{
							string path = item.Path;
							if (GlobalActions.Actions.TryGetValue(path, out var value))
							{
								value.Function?.Invoke();
							}
							else
							{
								Plugin.Log.LogWarning((object)("No action found for command '" + path + "' in the GlobalActions dictionary."));
							}
						}
						catch (Exception ex)
						{
							Plugin.Log.LogError((object)("Error processing command '" + item.Path + "': " + ex.Message + "\n" + ex.StackTrace));
						}
						continue;
					}
					FieldValueInfoItem fieldInfoAndValue = UpgradeRunner.GetFieldInfoAndValue(item.Path, paramsObj);
					if (fieldInfoAndValue.info.FieldType == typeof(int))
					{
						if ((int)item.Action == 0)
						{
							fieldInfoAndValue.info.SetValue(fieldInfoAndValue.val, (int)fieldInfoAndValue.info.GetValue(fieldInfoAndValue.val) + Mathf.RoundToInt(item.Value));
						}
						else if ((int)item.Action == 1)
						{
							float num = (int)fieldInfoAndValue.info.GetValue(fieldInfoAndValue.val);
							fieldInfoAndValue.info.SetValue(fieldInfoAndValue.val, Mathf.RoundToInt(num * item.Value));
						}
						else if ((int)item.Action == 2)
						{
							fieldInfoAndValue.info.SetValue(fieldInfoAndValue.val, Mathf.RoundToInt(item.Value));
						}
					}
					else if (fieldInfoAndValue.info.FieldType == typeof(float))
					{
						if ((int)item.Action == 0)
						{
							fieldInfoAndValue.info.SetValue(fieldInfoAndValue.val, (float)fieldInfoAndValue.info.GetValue(fieldInfoAndValue.val) + item.Value);
						}
						else if ((int)item.Action == 1)
						{
							fieldInfoAndValue.info.SetValue(fieldInfoAndValue.val, (float)fieldInfoAndValue.info.GetValue(fieldInfoAndValue.val) * item.Value);
						}
						else if ((int)item.Action == 2)
						{
							fieldInfoAndValue.info.SetValue(fieldInfoAndValue.val, item.Value);
						}
					}
					else if (fieldInfoAndValue.info.FieldType == typeof(bool))
					{
						fieldInfoAndValue.info.SetValue(fieldInfoAndValue.val, item.Value > 0.5f);
					}
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(GameDataPresets), "NewGameData")]
	internal class GameDataPresets_NewGameData_Patch
	{
		private static void Prefix()
		{
			if (GlobalActions.Actions.Count <= 0)
			{
				return;
			}
			foreach (KeyValuePair<string, ActionContainer> action in GlobalActions.Actions)
			{
				ActionContainer value = action.Value;
				value.Cleanup?.Invoke();
			}
		}
	}
}