Decompiled source of Rooster Long Lasting Walkie v1.0.1

RoosterWalkie.dll

Decompiled 9 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using RoosterWalkie.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RoosterFleshlight")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RoosterFleshlight")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("035abd56-e489-4c63-969d-f7ef0f102e9d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RoosterWalkie
{
	internal class ConfigurationController
	{
		private static ConfigEntry<float> RoosterWalkieBatteryConfig;

		private static ConfigEntry<float> RoosterFleshLightBatteryConfig;

		private static ConfigEntry<bool> RoosterWalkieAlwaysOnStartOfRoundConfig;

		private static ConfigEntry<bool> RoosterWalkieAlwaysOnPickUpConfig;

		internal float RoosterWalkieBattery
		{
			get
			{
				if (RoosterWalkieBatteryConfig.Value == 2f)
				{
					return (float)((ConfigEntryBase)RoosterWalkieBatteryConfig).DefaultValue;
				}
				return RoosterWalkieBatteryConfig.Value;
			}
			set
			{
				RoosterWalkieBatteryConfig.Value = value;
			}
		}

		internal float RoosterFleshLightBattery
		{
			get
			{
				if (RoosterFleshLightBatteryConfig.Value == 2f)
				{
					return (float)((ConfigEntryBase)RoosterFleshLightBatteryConfig).DefaultValue;
				}
				return RoosterFleshLightBatteryConfig.Value;
			}
			set
			{
				RoosterFleshLightBatteryConfig.Value = value;
			}
		}

		internal bool RoosterWalkieAlwaysOnStartOfRound
		{
			get
			{
				if (RoosterWalkieAlwaysOnStartOfRoundConfig.Value)
				{
					return (bool)((ConfigEntryBase)RoosterWalkieAlwaysOnStartOfRoundConfig).DefaultValue;
				}
				return RoosterWalkieAlwaysOnStartOfRoundConfig.Value;
			}
			set
			{
				RoosterWalkieAlwaysOnStartOfRoundConfig.Value = value;
			}
		}

		internal bool RoosterWalkieAlwaysOnPickUp
		{
			get
			{
				if (RoosterWalkieAlwaysOnPickUpConfig.Value)
				{
					return (bool)((ConfigEntryBase)RoosterWalkieAlwaysOnPickUpConfig).DefaultValue;
				}
				return RoosterWalkieAlwaysOnPickUpConfig.Value;
			}
			set
			{
				RoosterWalkieAlwaysOnPickUpConfig.Value = value;
			}
		}

		public ConfigurationController(ConfigFile config)
		{
			RoosterWalkieBatteryConfig = config.Bind<float>("Walkie Talkie", "Battery Life", 2f, "The battery life of the walkie talkie.");
			RoosterWalkieAlwaysOnStartOfRoundConfig = config.Bind<bool>("Walkie Talkie", "Always On For New Rounds", true, "Will the walkie talkie auto turn on for new rounds");
			RoosterWalkieAlwaysOnPickUpConfig = config.Bind<bool>("Walkie Talkie", "Always On When Picked Up", true, "Will the walkie talkie auto turn on when picked up");
			RoosterFleshLightBatteryConfig = config.Bind<float>("FleshLight", "Battery Life", 2f, "The battery life of the fleshlight.");
		}
	}
	[BepInPlugin("Rooster.Fleshlight", "Rooster's Fleshlight", "1.0.1")]
	public class RoosterWalkie : BaseUnityPlugin
	{
		private const string modGUID = "Rooster.Fleshlight";

		private const string modName = "Rooster's Fleshlight";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("Rooster.Fleshlight");

		internal ManualLogSource fleshLogger;

		internal static RoosterWalkie Instance;

		internal ConfigurationController ConfigManager;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			fleshLogger = Logger.CreateLogSource("Rooster.Fleshlight");
			fleshLogger.LogInfo((object)"The Rooster is Rising!");
			fleshLogger = ((BaseUnityPlugin)this).Logger;
			Instance.ConfigManager = new ConfigurationController(((BaseUnityPlugin)this).Config);
			harmony.PatchAll(typeof(RoosterWalkie));
			harmony.PatchAll(typeof(LongWalkie));
			harmony.PatchAll(typeof(GrabWalkie));
			harmony.PatchAll(typeof(LongFleshlight));
			harmony.PatchAll(typeof(GrabFleshlight));
		}
	}
}
namespace RoosterWalkie.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class LongFleshlight
	{
		private static void RefreshFleshlight(FlashlightItem currentFleshlight)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			try
			{
				if (!((Object)(object)currentFleshlight == (Object)null))
				{
					((GrabbableObject)currentFleshlight).insertedBattery = new Battery(false, 1f);
					((GrabbableObject)currentFleshlight).SyncBatteryServerRpc(100);
					Item itemProperties = ((GrabbableObject)currentFleshlight).itemProperties;
					itemProperties.batteryUsage *= RoosterWalkie.Instance.ConfigManager.RoosterFleshLightBattery;
					RoosterWalkie.Instance.fleshLogger.LogInfo((object)"ROOSTER: Fleshlight Battery Refreshed!");
				}
			}
			catch
			{
				RoosterWalkie.Instance.fleshLogger.LogInfo((object)"ROOSTER: Fleshlight borked!");
			}
		}

		[HarmonyPatch("SetShipReadyToLand")]
		[HarmonyPostfix]
		private static void LongFleshlightBetweenRoundsPatch()
		{
			FlashlightItem[] array = Object.FindObjectsOfType<FlashlightItem>();
			FlashlightItem[] array2 = array;
			foreach (FlashlightItem currentFleshlight in array2)
			{
				RefreshFleshlight(currentFleshlight);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ShipTeleporter), "TeleportPlayerOutWithInverseTeleporter")]
		private static void LongFleshlightInverseTeleportPatch(int playerObj, ref Vector3 teleportPos, ShipTeleporter __instance)
		{
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerObj];
			FlashlightItem[] array = Object.FindObjectsOfType<FlashlightItem>();
			FlashlightItem[] array2 = array;
			foreach (FlashlightItem val2 in array2)
			{
				if ((Object)(object)((GrabbableObject)val2).playerHeldBy == (Object)(object)val)
				{
					RefreshFleshlight(val2);
				}
			}
		}
	}
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabFleshlight
	{
		[HarmonyPostfix]
		[HarmonyPatch("GrabItem")]
		internal static void InteractItem(GrabbableObject __instance)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if (((object)__instance).GetType() == typeof(FlashlightItem))
			{
				try
				{
					FlashlightItem val = (FlashlightItem)__instance;
					Item itemProperties = ((GrabbableObject)val).itemProperties;
					itemProperties.batteryUsage *= RoosterWalkie.Instance.ConfigManager.RoosterFleshLightBattery;
					RoosterWalkie.Instance.fleshLogger.LogInfo((object)"ROOSTER: Fleshlight Battery Refreshed!");
				}
				catch
				{
					RoosterWalkie.Instance.fleshLogger.LogInfo((object)"ROOSTER: Fleshlight borked!");
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class LongWalkie
	{
		private static void RefreshWalkieTalkie(WalkieTalkie currentWalkie)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			try
			{
				((GrabbableObject)currentWalkie).insertedBattery = new Battery(false, 1f);
				((GrabbableObject)currentWalkie).SyncBatteryServerRpc(100);
				Item itemProperties = ((GrabbableObject)currentWalkie).itemProperties;
				itemProperties.batteryUsage *= RoosterWalkie.Instance.ConfigManager.RoosterWalkieBattery;
				currentWalkie.SwitchWalkieTalkieOn(RoosterWalkie.Instance.ConfigManager.RoosterWalkieAlwaysOnStartOfRound);
				RoosterWalkie.Instance.fleshLogger.LogInfo((object)"ROOSTER: Walkie Battery Refreshed!");
			}
			catch
			{
				RoosterWalkie.Instance.fleshLogger.LogInfo((object)"ROOSTER: Walkie borked!");
			}
		}

		[HarmonyPatch("SetShipReadyToLand")]
		[HarmonyPostfix]
		private static void LongWalkieTalkiePatch()
		{
			WalkieTalkie[] array = Object.FindObjectsOfType<WalkieTalkie>();
			WalkieTalkie[] array2 = array;
			foreach (WalkieTalkie currentWalkie in array2)
			{
				RefreshWalkieTalkie(currentWalkie);
			}
		}
	}
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class GrabWalkie
	{
		[HarmonyPostfix]
		[HarmonyPatch("GrabItem")]
		internal static void InteractItem(GrabbableObject __instance)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if (((object)__instance).GetType() == typeof(WalkieTalkie))
			{
				try
				{
					WalkieTalkie val = (WalkieTalkie)__instance;
					Item itemProperties = ((GrabbableObject)val).itemProperties;
					itemProperties.batteryUsage *= RoosterWalkie.Instance.ConfigManager.RoosterWalkieBattery;
					val.SwitchWalkieTalkieOn(RoosterWalkie.Instance.ConfigManager.RoosterWalkieAlwaysOnPickUp);
					RoosterWalkie.Instance.fleshLogger.LogInfo((object)"ROOSTER: Walkie Auto On!");
				}
				catch
				{
					RoosterWalkie.Instance.fleshLogger.LogInfo((object)"ROOSTER: Walkie borked!");
				}
			}
		}
	}
}