Decompiled source of SuitSaver v1.0.0

FluxTeam.SuitSaver.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("YourName")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Save and load suit configurations for Subterranauts")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SuitSaver")]
[assembly: AssemblyTitle("SuitSaver")]
[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 SuitSaver
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FluxTeam.SuitSaver";

		public const string PLUGIN_NAME = "SuitSaver";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("FluxTeam.SuitSaver", "SuitSaver", "1.0.0")]
	public class SuitSaverPlugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("FluxTeam.SuitSaver");

		internal ConfigEntry<string> SavedSuitColor;

		internal static SuitSaverPlugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Initializing SuitSaver v1.0.0");
			InitializeConfiguration();
			try
			{
				harmony.PatchAll();
				Log.LogInfo((object)"Harmony patches applied successfully");
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to apply Harmony patches: {arg}");
			}
			Log.LogInfo((object)"SuitSaver initialized successfully!");
		}

		private void InitializeConfiguration()
		{
			SavedSuitColor = ((BaseUnityPlugin)this).Config.Bind<string>("Suit", "SavedSuitColor", "0,0,0", "Saved suit color in RGB format (0-1 range). Format: R,G,B");
			Log.LogInfo((object)"Configuration initialized");
			if (!string.IsNullOrEmpty(SavedSuitColor.Value) && SavedSuitColor.Value != "0,0,0")
			{
				Log.LogInfo((object)("Found saved suit color: " + SavedSuitColor.Value));
			}
		}

		internal static string ColorToString(Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return $"{color.r},{color.g},{color.b}";
		}

		internal static Color StringToColor(string colorStr)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string[] array = colorStr.Split(new char[1] { ',' });
				if (array.Length == 3 && float.TryParse(array[0], out var result) && float.TryParse(array[1], out var result2) && float.TryParse(array[2], out var result3))
				{
					return new Color(Mathf.Clamp01(result), Mathf.Clamp01(result2), Mathf.Clamp01(result3));
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to parse color string '{colorStr}': {arg}");
			}
			Log.LogWarning((object)("Invalid color string '" + colorStr + "', using white as fallback"));
			return Color.white;
		}
	}
	[HarmonyPatch]
	public class SuitSaverPatches
	{
		[HarmonyPatch(typeof(PlayerData), "ChangeColor")]
		[HarmonyPostfix]
		private static void PlayerData_ChangeColor_Postfix(PlayerData __instance, Color color)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance.pv != (Object)null && __instance.pv.IsMine)
				{
					string value = SuitSaverPlugin.ColorToString(color);
					SuitSaverPlugin.Instance.SavedSuitColor.Value = value;
					SuitSaverPlugin.Log.LogInfo((object)$"Suit color saved: RGB({color.r:F2}, {color.g:F2}, {color.b:F2})");
				}
			}
			catch (Exception arg)
			{
				SuitSaverPlugin.Log.LogError((object)$"Error saving suit color: {arg}");
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void ClientPlayerCharacter_Initialize_Postfix(ClientPlayerCharacter __instance)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Object)(object)__instance.pv != (Object)null) || !__instance.pv.IsMine)
				{
					return;
				}
				string value = SuitSaverPlugin.Instance.SavedSuitColor.Value;
				if (!string.IsNullOrEmpty(value) && value != "0,0,0")
				{
					Color val = SuitSaverPlugin.StringToColor(value);
					PlayerData val2 = NetworkManager.instance?.localData;
					if ((Object)(object)val2 != (Object)null)
					{
						val2.ChangeColor(val);
						SuitSaverPlugin.Log.LogInfo((object)$"Loaded and applied saved suit color: RGB({val.r:F2}, {val.g:F2}, {val.b:F2})");
					}
					else
					{
						SuitSaverPlugin.Log.LogWarning((object)"Could not load saved suit: NetworkManager.instance.localData is null");
					}
				}
				else
				{
					SuitSaverPlugin.Log.LogInfo((object)"No saved suit color found or default color - using game default");
				}
			}
			catch (Exception arg)
			{
				SuitSaverPlugin.Log.LogError((object)$"Error loading saved suit color: {arg}");
			}
		}
	}
}