Decompiled source of FreedomUnits v0.0.1

FreedomUnits.dll

Decompiled 3 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CG.Game.Player;
using Gameplay.SpacePlatforms;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UI.MainHUD;
using UI.PilotHUD;
using UnityEngine;
using UnityEngine.UIElements;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.Utilities;

[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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("FreedomUnits")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreedomUnits")]
[assembly: AssemblyTitle("FreedomUnits")]
[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 FreedomUnits
{
	internal static class MyPluginInfo
	{
		internal const string PLUGIN_GUID = "id107.freedomunits";

		internal const string PLUGIN_NAME = "FreedomUnits";

		internal const string PLUGIN_VERSION = "0.0.1";
	}
	[BepInPlugin("id107.freedomunits", "FreedomUnits", "0.0.1")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "id107.freedomunits");
			Configs.Load(this);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.freedomunits is loaded!");
		}
	}
	internal class Configs
	{
		internal enum TemperatureUnit
		{
			Celsius,
			Fahrenheit,
			Kelvin,
			Rankine,
			Delisle,
			Reaumur,
			Romer,
			Custom
		}

		internal enum SpeedUnit
		{
			ms,
			kmh,
			mih,
			kt,
			fts,
			C,
			Custom
		}

		private static readonly FieldInfo viewField = AccessTools.Field(typeof(PlayerHUD), "view");

		private static readonly FieldInfo temperatureField = AccessTools.Field(typeof(LocalPlayerHUDView), "temperature");

		internal static ConfigEntry<TemperatureUnit> TemperatureUnitConfig;

		internal static ConfigEntry<float> TemperatureMultiplier;

		internal static ConfigEntry<float> TemperatureAddend;

		internal static ConfigEntry<SpeedUnit> SpeedUnitConfig;

		internal static ConfigEntry<float> SpeedMultiplier;

		internal static ConfigEntry<string> SpeedName;

		internal static float GetTemperature(float celsius)
		{
			TemperatureUnit value = TemperatureUnitConfig.Value;
			if (1 == 0)
			{
			}
			float result = value switch
			{
				TemperatureUnit.Celsius => celsius, 
				TemperatureUnit.Fahrenheit => celsius * 1.8f + 32f, 
				TemperatureUnit.Kelvin => celsius + 273.15f, 
				TemperatureUnit.Rankine => (celsius + 273.15f) * 1.8f, 
				TemperatureUnit.Delisle => (100f - celsius) * 1.5f, 
				TemperatureUnit.Reaumur => celsius * 0.8f, 
				TemperatureUnit.Romer => celsius * 21f / 40f + 7.5f, 
				TemperatureUnit.Custom => celsius * TemperatureMultiplier.Value + TemperatureAddend.Value, 
				_ => celsius, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		internal static void SetTemperatureThresholds()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			LocalPlayer instance = LocalPlayer.Instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				GameObject gameObject = ((Component)instance).gameObject;
				obj = ((gameObject != null) ? gameObject.GetComponentInChildren<PlayerHUD>() : null);
			}
			PlayerHUD val = (PlayerHUD)obj;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			LocalPlayerHUDView val2 = (LocalPlayerHUDView)viewField.GetValue(val);
			if (val2 != null)
			{
				HUDResourceVE val3 = (HUDResourceVE)temperatureField.GetValue(val2);
				if (val3 != null)
				{
					val3.SetThresholds(new List<Tuple<int, string>>
					{
						new Tuple<int, string>((int)GetTemperature(-20f), "normal"),
						new Tuple<int, string>((int)GetTemperature(-200f), "medium"),
						new Tuple<int, string>((int)GetTemperature(-400f), "low")
					});
				}
			}
		}

		internal static float GetSpeed(float ms)
		{
			SpeedUnit value = SpeedUnitConfig.Value;
			if (1 == 0)
			{
			}
			float result = value switch
			{
				SpeedUnit.ms => ms, 
				SpeedUnit.kmh => ms * 3.6f, 
				SpeedUnit.mih => ms * 2.2369363f, 
				SpeedUnit.kt => ms * 1.9438444f, 
				SpeedUnit.fts => ms * 3.28084f, 
				SpeedUnit.C => ms / 299792450f, 
				SpeedUnit.Custom => ms * SpeedMultiplier.Value, 
				_ => ms, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		internal static string GetSpeedUnit()
		{
			SpeedUnit value = SpeedUnitConfig.Value;
			if (1 == 0)
			{
			}
			string result = value switch
			{
				SpeedUnit.ms => "m/s", 
				SpeedUnit.kmh => "km/h", 
				SpeedUnit.mih => "mi/h", 
				SpeedUnit.kt => "kt", 
				SpeedUnit.fts => "ft/s", 
				SpeedUnit.C => "C", 
				SpeedUnit.Custom => SpeedName.Value, 
				_ => "", 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		internal static void Load(BepinPlugin plugin)
		{
			TemperatureUnitConfig = ((BaseUnityPlugin)plugin).Config.Bind<TemperatureUnit>("FreedomUnits", "Temperature", TemperatureUnit.Celsius, (ConfigDescription)null);
			TemperatureMultiplier = ((BaseUnityPlugin)plugin).Config.Bind<float>("FreedomUnits", "TemperatureMultiplier", 1f, (ConfigDescription)null);
			TemperatureAddend = ((BaseUnityPlugin)plugin).Config.Bind<float>("FreedomUnits", "TemperatureAddend", 0f, (ConfigDescription)null);
			SpeedUnitConfig = ((BaseUnityPlugin)plugin).Config.Bind<SpeedUnit>("FreedomUnits", "Speed", SpeedUnit.ms, (ConfigDescription)null);
			SpeedMultiplier = ((BaseUnityPlugin)plugin).Config.Bind<float>("FreedomUnits", "SpeedMultiplier", 1f, (ConfigDescription)null);
			SpeedName = ((BaseUnityPlugin)plugin).Config.Bind<string>("FreedomUnits", "SpeedUnit", "m/s", (ConfigDescription)null);
		}
	}
	internal class GUI : ModSettingsMenu
	{
		private static string Multiplier = Configs.TemperatureMultiplier.Value.ToString();

		private static string Addend = Configs.TemperatureAddend.Value.ToString();

		private static string SpeedMultiplier = Configs.SpeedMultiplier.Value.ToString();

		private static string SpeedName = Configs.SpeedName.Value;

		public override string Name()
		{
			return "Freedom Units";
		}

		public override void Draw()
		{
			bool flag = false;
			GUILayout.Label("Temperature", Array.Empty<GUILayoutOption>());
			flag |= DrawCheckbox("Celsius", Configs.TemperatureUnit.Celsius);
			flag |= DrawCheckbox("Fahrenheit", Configs.TemperatureUnit.Fahrenheit);
			flag |= DrawCheckbox("Kelvin", Configs.TemperatureUnit.Kelvin);
			flag |= DrawCheckbox("Rankine", Configs.TemperatureUnit.Rankine);
			flag |= DrawCheckbox("Delisle", Configs.TemperatureUnit.Delisle);
			flag |= DrawCheckbox("Reaumur", Configs.TemperatureUnit.Reaumur);
			flag |= DrawCheckbox("Romer", Configs.TemperatureUnit.Romer);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			flag |= DrawCheckbox("Custom: ", Configs.TemperatureUnit.Custom);
			GUILayout.Label("Multiplier: ", Array.Empty<GUILayoutOption>());
			Multiplier = GUILayout.TextField(Multiplier, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(80f) });
			GUILayout.Label("  Addend:", Array.Empty<GUILayoutOption>());
			Addend = GUILayout.TextField(Addend, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(80f) });
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Apply", Array.Empty<GUILayoutOption>()))
			{
				flag = true;
				if (float.TryParse(Multiplier, out var result))
				{
					Configs.TemperatureMultiplier.Value = result;
				}
				if (float.TryParse(Addend, out var result2))
				{
					Configs.TemperatureAddend.Value = result2;
				}
				Multiplier = Configs.TemperatureMultiplier.Value.ToString();
				Addend = Configs.TemperatureAddend.Value.ToString();
			}
			if (GUILayout.Button("Reset", Array.Empty<GUILayoutOption>()))
			{
				flag = true;
				Configs.TemperatureMultiplier.Value = 1f;
				Configs.TemperatureAddend.Value = 0f;
				Multiplier = Configs.TemperatureMultiplier.Value.ToString();
				Addend = Configs.TemperatureAddend.Value.ToString();
			}
			GUILayout.EndHorizontal();
			if (flag)
			{
				Configs.SetTemperatureThresholds();
			}
			GUILayout.Label("", Array.Empty<GUILayoutOption>());
			GUILayout.Label("Speed", Array.Empty<GUILayoutOption>());
			DrawCheckbox("Meters per second", Configs.SpeedUnit.ms);
			DrawCheckbox("Kilometers per hour", Configs.SpeedUnit.kmh);
			DrawCheckbox("Miles per hour", Configs.SpeedUnit.mih);
			DrawCheckbox("Knots", Configs.SpeedUnit.kt);
			DrawCheckbox("Feet per second", Configs.SpeedUnit.fts);
			DrawCheckbox("% speed of light", Configs.SpeedUnit.C);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			DrawCheckbox("Custom: ", Configs.SpeedUnit.Custom);
			GUILayout.Label("Multiplier: ", Array.Empty<GUILayoutOption>());
			SpeedMultiplier = GUILayout.TextField(SpeedMultiplier, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(80f) });
			GUILayout.Label("  Unit", Array.Empty<GUILayoutOption>());
			SpeedName = GUILayout.TextField(SpeedName, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(80f) });
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Apply", Array.Empty<GUILayoutOption>()))
			{
				if (float.TryParse(SpeedMultiplier, out var result3))
				{
					Configs.SpeedMultiplier.Value = result3;
				}
				SpeedMultiplier = Configs.SpeedMultiplier.Value.ToString();
				Configs.SpeedName.Value = SpeedName;
			}
			if (GUILayout.Button("Reset", Array.Empty<GUILayoutOption>()))
			{
				Configs.SpeedMultiplier.Value = 1f;
				Configs.SpeedName.Value = "m/s";
				SpeedMultiplier = Configs.SpeedMultiplier.Value.ToString();
				SpeedName = Configs.SpeedName.Value;
			}
			GUILayout.EndHorizontal();
		}

		private static bool DrawCheckbox(string name, Configs.TemperatureUnit unit)
		{
			bool flag = Configs.TemperatureUnitConfig.Value == unit;
			if (GUITools.DrawCheckbox(name, ref flag))
			{
				Configs.TemperatureUnitConfig.Value = unit;
				return true;
			}
			return false;
		}

		private static void DrawCheckbox(string name, Configs.SpeedUnit unit)
		{
			bool flag = Configs.SpeedUnitConfig.Value == unit;
			if (GUITools.DrawCheckbox(name, ref flag))
			{
				Configs.SpeedUnitConfig.Value = unit;
			}
		}
	}
	[HarmonyPatch(typeof(LocalPlayerHUDController))]
	internal class LocalPlayerHUDControllerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("UpdateTemperature")]
		private static void UpdateTemperaturePrefix(CharacterAtmosphericDataTracker ___atmosphereData, out float __state)
		{
			__state = ___atmosphereData.AtmosphereData.Temperature;
			___atmosphereData.AtmosphereData.Temperature = Configs.GetTemperature(__state);
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdateTemperature")]
		private static void UpdateTemperaturePostfix(CharacterAtmosphericDataTracker ___atmosphereData, float __state)
		{
			___atmosphereData.AtmosphereData.Temperature = __state;
		}
	}
	[HarmonyPatch(typeof(LocalPlayerHUDView))]
	internal class LocalPlayerHUDViewPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SetupVE")]
		private static void SetupVE(HUDResourceVE ___temperature)
		{
			___temperature.SetThresholds(new List<Tuple<int, string>>
			{
				new Tuple<int, string>((int)Configs.GetTemperature(-20f), "normal"),
				new Tuple<int, string>((int)Configs.GetTemperature(-200f), "medium"),
				new Tuple<int, string>((int)Configs.GetTemperature(-400f), "low")
			});
		}
	}
	[HarmonyPatch(typeof(PilotHUD))]
	internal class PilotHUDPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void Update(bool ___inVoid, Label ___speedIndicator, MovingSpacePlatform ___ship)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (!___inVoid)
			{
				Vector3 velocity = ((SpacePlatform)___ship).Velocity;
				((TextElement)___speedIndicator).text = Configs.GetSpeed(((Vector3)(ref velocity)).magnitude).ToString("#") + " " + Configs.GetSpeedUnit();
			}
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)3;

		public override string Author => "18107";

		public override string Description => "Allows the user to see the temperature or ship speed in any units";
	}
}