Decompiled source of WirelessCharging v1.0.0

WirelessCharging.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WirelessCharging")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WirelessCharging")]
[assembly: AssemblyTitle("WirelessCharging")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace WirelessCharging
{
	[BepInPlugin("floof.WirelessCharging", "WirelessCharging", "1.0.0")]
	public class WirelessCharging : BaseUnityPlugin
	{
		private const string modGUID = "floof.WirelessCharging";

		private const string modName = "WirelessCharging";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("floof.WirelessCharging");

		private static WirelessCharging Instance;

		internal static ManualLogSource mls;

		private void Awake()
		{
			if (Instance == null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("floof.WirelessCharging");
			mls.LogInfo((object)"WirelessCharging active kiwicute");
			harmony.PatchAll();
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")]
	public class Patch
	{
		private static float interval;

		[HarmonyPostfix]
		internal static void Postfix(ref PlayerControllerB __instance)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			if (!__instance.isInElevator || !((NetworkBehaviour)__instance).IsOwner)
			{
				return;
			}
			if (interval > 0.1f)
			{
				interval = 0f;
				for (int i = 0; i < GameNetworkManager.Instance.localPlayerController.ItemSlots.Length; i++)
				{
					GrabbableObject val = GameNetworkManager.Instance.localPlayerController.ItemSlots[i];
					if (!((Object)(object)val == (Object)null) && val.itemProperties.requiresBattery && val.insertedBattery != null && val.insertedBattery.charge < 1f)
					{
						if (val.insertedBattery.empty)
						{
							val.insertedBattery.empty = false;
						}
						Battery insertedBattery = val.insertedBattery;
						insertedBattery.charge += Time.deltaTime / 10f;
						float num = val.insertedBattery.charge * 100f;
						int num2 = (int)Mathf.Ceil(num);
						if (num * 100f % 100f <= 1f)
						{
							val.insertedBattery = new Battery(false, (float)num2 / 100f);
							val.SyncBatteryServerRpc(num2);
						}
					}
				}
			}
			else
			{
				interval += Time.deltaTime;
			}
		}
	}
}