Decompiled source of FixRechargeDroneGlitch v1.0.0

plugins/yazirushi-FixRechargeDroneGlitch/FixRechargeDroneGlitch.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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("FixRechargeDroneGlitch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FixRechargeDroneGlitch")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b73c8d47-a0ee-4424-959a-121bfadeed43")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FixRechargeDroneGlitch;

[BepInPlugin("yazirushi.FixRechargeDroneGlitch", "FixRechargeDroneGlitch", "1.0.0")]
public class FixRechargeDroneGlitch : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("yazirushi.FixRechargeDroneGlitch");

	internal static ManualLogSource mls;

	private void Awake()
	{
		mls = ((BaseUnityPlugin)this).Logger;
		mls.LogInfo((object)"Starting FixRechargeDroneGlitch...");
		harmony.PatchAll();
	}
}
[HarmonyPatch(typeof(ItemDroneBattery), "Update")]
public class DronePatch
{
	[CompilerGenerated]
	private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private CodeInstruction <>2__current;

		private int <>l__initialThreadId;

		private IEnumerable<CodeInstruction> instructions;

		public IEnumerable<CodeInstruction> <>3__instructions;

		private int <r4_5>5__1;

		private IEnumerator<CodeInstruction> <>s__2;

		private CodeInstruction <code>5__3;

		CodeInstruction IEnumerator<CodeInstruction>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <Transpiler>d__0(int <>1__state)
		{
			this.<>1__state = <>1__state;
			<>l__initialThreadId = Environment.CurrentManagedThreadId;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || (uint)(num - 1) <= 2u)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<>s__2 = null;
			<code>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			try
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<r4_5>5__1 = 0;
					<>s__2 = instructions.GetEnumerator();
					<>1__state = -3;
					break;
				case 1:
					<>1__state = -3;
					<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(DronePatch), "GetChargeAmount", (Type[])null, (Type[])null));
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -3;
					break;
				case 3:
					<>1__state = -3;
					<code>5__3 = null;
					break;
				}
				if (<>s__2.MoveNext())
				{
					<code>5__3 = <>s__2.Current;
					if (<code>5__3.opcode == OpCodes.Ldc_R4 && (float)<code>5__3.operand == 5f)
					{
						<r4_5>5__1++;
						if (<r4_5>5__1 == 1)
						{
							<>2__current = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
							<>1__state = 1;
							return true;
						}
					}
					<>2__current = <code>5__3;
					<>1__state = 3;
					return true;
				}
				<>m__Finally1();
				<>s__2 = null;
				return false;
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<>s__2 != null)
			{
				<>s__2.Dispose();
			}
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}

		[DebuggerHidden]
		IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
		{
			<Transpiler>d__0 <Transpiler>d__;
			if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
			{
				<>1__state = 0;
				<Transpiler>d__ = this;
			}
			else
			{
				<Transpiler>d__ = new <Transpiler>d__0(0);
			}
			<Transpiler>d__.instructions = <>3__instructions;
			return <Transpiler>d__;
		}

		[DebuggerHidden]
		IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
		}
	}

	private static readonly FieldInfo fieldItemBattery = AccessTools.Field(typeof(ItemDroneBattery), "itemBattery");

	[IteratorStateMachine(typeof(<Transpiler>d__0))]
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <Transpiler>d__0(-2)
		{
			<>3__instructions = instructions
		};
	}

	private static float GetChargeAmount(ItemDroneBattery __instance)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Expected O, but got Unknown
		if ((Object)(object)__instance == (Object)null)
		{
			return 0f;
		}
		ItemBattery val = (ItemBattery)fieldItemBattery.GetValue(__instance);
		if ((Object)(object)val == (Object)null)
		{
			return 0f;
		}
		if (val.batteryLife >= 5f)
		{
			return 5f;
		}
		if (5f > val.batteryLife && val.batteryLife > 0f)
		{
			return val.batteryLife;
		}
		return 0f;
	}
}
[HarmonyPatch(typeof(ItemBattery), "ChargeBattery")]
public class ChargePatch
{
	private static bool Prefix(float chargeAmount)
	{
		if (chargeAmount != 0f)
		{
			return true;
		}
		return false;
	}
}