Decompiled source of UnlockableDefaults v0.0.1

UnlockableDefaults.dll

Decompiled 10 months 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;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnlockOnStart;
using UnlockableDefaults;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("UnlockableDefaults")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+3e395cd2268504904dd56afa07496de7c264b344")]
[assembly: AssemblyProduct("UnlockableDefaults")]
[assembly: AssemblyTitle("UnlockableDefaults")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.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 UnlockableDefaults
{
	[BepInPlugin("UnlockableDefaults", "UnlockableDefaults", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource logger;

		internal static Harmony harmony;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			logger = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("UnlockableDefaults");
			harmony.PatchAll();
			ConfigManager.Init(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin UnlockableDefaults is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "UnlockableDefaults";

		public const string PLUGIN_NAME = "UnlockableDefaults";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}
namespace UnlockOnStart
{
	public class ConfigManager
	{
		public static Dictionary<string, ConfigEntry<float>> Positions = new Dictionary<string, ConfigEntry<float>>();

		public static ConfigManager Instance { get; private set; }

		public static ConfigFile configFile { get; private set; }

		public static void Init(ConfigFile config)
		{
			Instance = new ConfigManager(config);
		}

		private ConfigManager(ConfigFile config)
		{
			configFile = config;
		}

		public static void Add(string unlockableName, string key, float value)
		{
			if (Positions.TryGetValue(unlockableName + key, out var _))
			{
				((ConfigEntryBase)Positions[unlockableName + key]).BoxedValue = value;
			}
			else
			{
				Positions[unlockableName + key] = configFile.Bind<float>(unlockableName, key, value, key);
			}
		}

		public static float TryGet(string unlockableName, string key)
		{
			if (Positions.TryGetValue(unlockableName + key, out var value))
			{
				return value.Value;
			}
			Add(unlockableName, key, 0f);
			return 0f;
		}

		public static void InitialBind(string unlockableName, string key)
		{
			Positions[unlockableName + key] = configFile.Bind<float>(unlockableName, key, 0f, key);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class NewSavePatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPriority(500)]
		[HarmonyPrefix]
		internal static void Init()
		{
			Plugin.logger.LogDebug((object)"NewSavePatch Init");
			List<UnlockableItem> unlockables = StartOfRound.Instance.unlockablesList.unlockables;
			foreach (UnlockableItem item in unlockables)
			{
				int num = unlockables.IndexOf(item);
				string unlockableName = item.unlockableName;
				Plugin.logger.LogDebug((object)$"Unlockable {unlockableName} / {num}");
				ConfigManager.InitialBind(unlockableName, "Position X");
				ConfigManager.InitialBind(unlockableName, "Position Y");
				ConfigManager.InitialBind(unlockableName, "Position Z");
				ConfigManager.InitialBind(unlockableName, "Rotation X");
				ConfigManager.InitialBind(unlockableName, "Rotation Y");
				ConfigManager.InitialBind(unlockableName, "Rotation Z");
			}
		}

		[HarmonyPatch("firstDayAnimation")]
		[HarmonyPriority(0)]
		[HarmonyPostfix]
		internal static void LoadFromConfig()
		{
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			List<UnlockableItem> unlockables = StartOfRound.Instance.unlockablesList.unlockables;
			GameObject val = GameObject.Find("/Environment/HangarShip");
			Vector3 val3 = default(Vector3);
			Vector3 val4 = default(Vector3);
			foreach (UnlockableItem item in unlockables)
			{
				int unlockableID = unlockables.IndexOf(item);
				string unlockableName = item.unlockableName;
				bool inStorage = item.inStorage;
				bool flag = item.alreadyUnlocked || item.hasBeenUnlockedByPlayer;
				Plugin.logger.LogDebug((object)$"Unlockable {unlockableName} / {unlockableID} : {inStorage} // {flag}");
				if (!flag || item.unlockableType == 0)
				{
					continue;
				}
				float num = ConfigManager.TryGet(unlockableName, "Position X");
				float num2 = ConfigManager.TryGet(unlockableName, "Position Y");
				float num3 = ConfigManager.TryGet(unlockableName, "Position Z");
				float num4 = ConfigManager.TryGet(unlockableName, "Rotation X");
				float num5 = ConfigManager.TryGet(unlockableName, "Rotation Y");
				float num6 = ConfigManager.TryGet(unlockableName, "Rotation Z");
				Plugin.logger.LogDebug((object)$"Unlockable {unlockableName} position: {num}, {num2}, {num3}");
				Plugin.logger.LogDebug((object)$"Unlockable {unlockableName} rotation: {num4}, {num5}, {num6}");
				if (num != 0f && num2 != 0f && num3 != 0f && !inStorage)
				{
					PlaceableShipObject val2 = (from x in val.GetComponentsInChildren<PlaceableShipObject>()
						where x.unlockableID == unlockableID
						select x).FirstOrDefault();
					((Vector3)(ref val3))..ctor(num, num2, num3);
					((Vector3)(ref val4))..ctor(num4, num5, num6);
					try
					{
						ShipBuildModeManager.Instance.PlaceShipObject(val3, val4, val2, false);
					}
					catch (Exception arg)
					{
						Plugin.logger.LogError((object)$"Error placing {unlockableName} : {arg}");
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(ShipBuildModeManager))]
	internal class PlaceObjectPatch
	{
		[HarmonyPatch("PlaceShipObject")]
		[HarmonyPostfix]
		internal static void SaveToConfig(Vector3 placementPosition, Vector3 placementRotation, PlaceableShipObject placeableObject, bool placementSFX = true)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			int unlockableID = placeableObject.unlockableID;
			UnlockableItem val = StartOfRound.Instance.unlockablesList.unlockables[unlockableID];
			string unlockableName = val.unlockableName;
			if (!val.inStorage)
			{
				ConfigManager.Add(unlockableName, "Position X", placementPosition.x);
				ConfigManager.Add(unlockableName, "Position Y", placementPosition.y);
				ConfigManager.Add(unlockableName, "Position Z", placementPosition.z);
				ConfigManager.Add(unlockableName, "Rotation X", placementRotation.x);
				ConfigManager.Add(unlockableName, "Rotation Y", placementRotation.y);
				ConfigManager.Add(unlockableName, "Rotation Z", placementRotation.z);
			}
		}
	}
	[HarmonyPatch(typeof(ShipBuildModeManager))]
	internal class StoreObjectPatch
	{
		[HarmonyPatch("StoreShipObjectClientRpc")]
		[HarmonyPostfix]
		internal static void SaveToConfig(NetworkObjectReference objectRef, int playerWhoStored, int unlockableID)
		{
			UnlockableItem val = StartOfRound.Instance.unlockablesList.unlockables[unlockableID];
			string unlockableName = val.unlockableName;
			bool inStorage = val.inStorage;
		}
	}
}