Decompiled source of TweakMecha v1.0.0

TweakMecha.dll

Decompiled 5 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("IncreaseMaxWarp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IncreaseMaxWarp")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cc54eb62-a05c-4bb4-87c7-340e7681d51a")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: UnverifiableCode]
namespace TweakMecha
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TweakMecha";

		public const string PLUGIN_NAME = "TweakMecha";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Etherios.DSP.TweakMecha
{
	public static class PluginConfig
	{
		public enum ESpeed
		{
			LY,
			AU
		}

		private static readonly string GENERAL_SECTION = "General";

		public static ConfigEntry<double> WarpSpeed;

		public static ConfigEntry<double> CruiseSpeed;

		public static ConfigEntry<ESpeed> WarpSpeedType;

		public static ConfigEntry<ESpeed> CruiseSpeedType;

		internal static void Init(ConfigFile config)
		{
			WarpSpeed = config.Bind<double>(GENERAL_SECTION, "WarpSpeed", 1.0, "Maximum warp speed for the mecha in AUs or LYs based on config. Default is 1 LY");
			WarpSpeedType = config.Bind<ESpeed>(GENERAL_SECTION, "WarpSpeedType", ESpeed.LY, "Speed measurement to use for max warp speed. Default is LY.");
			CruiseSpeed = config.Bind<double>(GENERAL_SECTION, "CruiseSpeed", 2000.0, "Maximum cruise speed for the mecha in AUs or LYs based on config. Default is 2000 AU");
			CruiseSpeedType = config.Bind<ESpeed>(GENERAL_SECTION, "CruiseSpeedType", ESpeed.AU, "Speed measurement to use for max warp speed. Default is AU.");
		}
	}
	[BepInPlugin("JClark.DSP.TweakMecha", "TweakMecha", "1.0.0")]
	[BepInProcess("DSPGAME.exe")]
	public class TweakMechaPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PlayerMove_Sail))]
		public class WarpSpeedPatch
		{
			internal static float? convertSpeed(ConfigEntry<double> setting, ConfigEntry<PluginConfig.ESpeed> speedType)
			{
				return speedType.Value switch
				{
					PluginConfig.ESpeed.AU => (float)Utils.AU(setting.Value), 
					PluginConfig.ESpeed.LY => (float)Utils.LY(setting.Value), 
					_ => null, 
				};
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(PlayerMove_Sail), "GameTick")]
			public static bool PlayerMove_Sail_GameTick(PlayerMove_Sail __instance, long timei)
			{
				float? num = convertSpeed(PluginConfig.WarpSpeed, PluginConfig.WarpSpeedType);
				if (num.HasValue && ((PlayerAction)__instance).player.mecha.maxWarpSpeed != num.Value)
				{
					Logger.LogInfo((object)$"Warp speed is: {((PlayerAction)__instance).player.mecha.maxWarpSpeed}");
					((PlayerAction)__instance).player.mecha.maxWarpSpeed = num.Value;
					Logger.LogInfo((object)$"New warp speed is: {((PlayerAction)__instance).player.mecha.maxWarpSpeed}");
				}
				float? num2 = convertSpeed(PluginConfig.CruiseSpeed, PluginConfig.CruiseSpeedType);
				if (num2.HasValue && ((PlayerAction)__instance).player.mecha.maxSailSpeed != num2.Value)
				{
					Logger.LogInfo((object)$"Cruise speed is: {((PlayerAction)__instance).player.mecha.maxSailSpeed}");
					((PlayerAction)__instance).player.mecha.maxSailSpeed = num2.Value;
					Logger.LogInfo((object)$"New Cruise speed is: {((PlayerAction)__instance).player.mecha.maxSailSpeed}");
				}
				return true;
			}

			public static void TweakMechaOnce(Player __instance)
			{
				Logger.LogInfo((object)$"Replenish speed is: {__instance.mecha.reactorPowerGen}");
				__instance.mecha.reactorPowerGen = __instance.mecha.reactorPowerGen * 1000.0;
				Logger.LogInfo((object)$"New Replenish speed is: {__instance.mecha.reactorPowerGen}");
			}
		}

		public static ManualLogSource Logger;

		public static bool First = true;

		private void Start()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			PluginConfig.Init(((BaseUnityPlugin)this).Config);
			Harmony val = new Harmony("JClark.DSP.TweakMecha");
			val.PatchAll(typeof(WarpSpeedPatch));
			Logger.LogInfo((object)$"TweakMecha - loaded with warp speed updated to {PluginConfig.WarpSpeed.Value} {PluginConfig.WarpSpeedType.Value}");
			Logger.LogInfo((object)$"TweakMecha - loaded with cruise speed updated to {PluginConfig.CruiseSpeed.Value} {PluginConfig.CruiseSpeedType.Value}");
		}
	}
	public static class Utils
	{
		public static double AU(double num)
		{
			return num * 40000.0;
		}

		public static double LY(double num)
		{
			return num * 2400000.0;
		}
	}
}