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 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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c574138cfea486cfa7104eae1a6f135c166daf8b")]
[assembly: AssemblyProduct("EmpressSolar")]
[assembly: AssemblyTitle("EmpressSolar")]
[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 SolarBatteries
{
[BepInPlugin("com.empress.solar_batteries", "Solar_Batteries", "1.1.0")]
public class SolarBatteriesMod : BaseUnityPlugin
{
[HarmonyPatch(typeof(ItemBattery), "Update")]
public class SolarBatteriesPatch
{
[HarmonyPrefix]
public static void Prefix(ItemBattery __instance)
{
if (!SemiFunc.IsMasterClientOrSingleplayer() || __instance.batteryLife >= 100f)
{
return;
}
foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
{
if (!player.isDisabled && !((Object)(object)player.flashlightController == (Object)null) && player.flashlightController.LightActive)
{
Light spotlight = player.flashlightController.spotlight;
if (!((Object)(object)spotlight == (Object)null) && IsBatteryLit(__instance, spotlight))
{
__instance.ChargeBattery(((Component)player).gameObject, ChargeRate.Value);
}
}
}
}
private static bool IsBatteryLit(ItemBattery battery, Light spot)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: 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_008c: 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)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = (Object.op_Implicit((Object)(object)battery.batteryTransform) ? battery.batteryTransform.position : ((Component)battery).transform.position);
Vector3 position = ((Component)spot).transform.position;
Vector3 val2 = val - position;
float magnitude = ((Vector3)(ref val2)).magnitude;
if (magnitude > MaxRange.Value)
{
return false;
}
float num = Vector3.Angle(((Component)spot).transform.forward, val2);
if (num > spot.spotAngle * 0.5f)
{
return false;
}
RaycastHit val3 = default(RaycastHit);
if (Physics.Raycast(position, ((Vector3)(ref val2)).normalized, ref val3, magnitude, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct())) && (Object)(object)((RaycastHit)(ref val3)).transform != (Object)(object)((Component)battery).transform && !((RaycastHit)(ref val3)).transform.IsChildOf(((Component)battery).transform))
{
return false;
}
return true;
}
}
public static ConfigEntry<float> ChargeRate;
public static ConfigEntry<float> MaxRange;
private void Awake()
{
ChargeRate = ((BaseUnityPlugin)this).Config.Bind<float>("Solar Charging", "ChargeRate", 2.5f, "How much battery % is restored per second of light exposure.");
MaxRange = ((BaseUnityPlugin)this).Config.Bind<float>("Solar Charging", "MaxRange", 3f, "The maximum distance a flashlight can be to charge a battery.");
Harmony.CreateAndPatchAll(typeof(SolarBatteriesPatch), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Solar Batteries Loaded: Configurable flashlight charging active.");
}
}
}