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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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 = "")]
[assembly: AssemblyCompany("OrbitRecharge")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Recharge all items on ship when in orbit")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+0c850d8d15ee0807fac0d589503862e84d04d31c")]
[assembly: AssemblyProduct("OrbitRecharge")]
[assembly: AssemblyTitle("OrbitRecharge")]
[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 OrbitRecharge
{
[BepInPlugin("OrbitRecharge", "OrbitRecharge", "0.0.1")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource logger;
private void Awake()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin OrbitRecharge is loaded!");
logger = ((BaseUnityPlugin)this).Logger;
Harmony val = new Harmony("OrbitRecharge");
val.PatchAll();
}
}
[HarmonyPatch(typeof(StartOfRound))]
public static class StartOfRound_SetShipReadyToLand_Patch
{
private static void RechargeItem(GrabbableObject itemToCharge, string playerHeldBy = "on ship")
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
Plugin.logger.LogDebug((object)$"Recharging {itemToCharge.itemProperties.itemName} ({playerHeldBy}) - {Math.Ceiling(itemToCharge.insertedBattery.charge) * 100.0}%");
itemToCharge.insertedBattery = new Battery(false, 1f);
itemToCharge.SyncBatteryServerRpc(100);
}
[HarmonyPatch("SetShipReadyToLand")]
[HarmonyPrefix]
public static void Prefix(StartOfRound __instance)
{
GameObject val = GameObject.Find("/Environment/HangarShip");
GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>();
GrabbableObject[] array = componentsInChildren;
foreach (GrabbableObject val2 in array)
{
if (val2.insertedBattery != null)
{
RechargeItem(val2);
}
}
PlayerControllerB[] allPlayerScripts = __instance.allPlayerScripts;
PlayerControllerB[] array2 = allPlayerScripts;
foreach (PlayerControllerB val3 in array2)
{
GrabbableObject[] itemSlots = val3.ItemSlots;
GrabbableObject[] array3 = itemSlots;
foreach (GrabbableObject val4 in array3)
{
if (!((Object)(object)val4 == (Object)null) && val4.insertedBattery != null)
{
RechargeItem(val4, ((Object)val3).name);
}
}
}
FlashlightItem[] array4 = Object.FindObjectsOfType<FlashlightItem>();
FlashlightItem[] array5 = array4;
foreach (FlashlightItem val5 in array5)
{
try
{
val5.SwitchFlashlight(false);
((Behaviour)val5.flashlightBulb).enabled = false;
((Behaviour)val5.flashlightBulbGlow).enabled = false;
((GrabbableObject)val5).isBeingUsed = false;
}
catch (Exception ex)
{
Plugin.logger.LogDebug((object)"Failed to turn off flashlight");
Plugin.logger.LogDebug((object)ex);
}
}
WalkieTalkie[] array6 = Object.FindObjectsOfType<WalkieTalkie>();
WalkieTalkie[] array7 = array6;
foreach (WalkieTalkie val6 in array7)
{
try
{
val6.SwitchWalkieTalkieOn(false);
}
catch
{
Plugin.logger.LogDebug((object)"Failed to turn off walkie");
}
}
RadarBoosterItem[] array8 = Object.FindObjectsOfType<RadarBoosterItem>();
RadarBoosterItem[] array9 = array8;
foreach (RadarBoosterItem val7 in array9)
{
try
{
val7.EnableRadarBooster(false);
}
catch
{
Plugin.logger.LogDebug((object)"Failed to turn off radar booster");
}
}
SprayPaintItem[] array10 = Object.FindObjectsOfType<SprayPaintItem>();
SprayPaintItem[] array11 = array10;
foreach (SprayPaintItem val8 in array11)
{
try
{
val8.sprayCanTank = 100f;
}
catch
{
Plugin.logger.LogDebug((object)"Failed to turn off spray paint");
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "OrbitRecharge";
public const string PLUGIN_NAME = "OrbitRecharge";
public const string PLUGIN_VERSION = "0.0.1";
}
}