Decompiled source of RechargeableItems v1.0.0

RechargeMod.dll

Decompiled 9 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RechargeMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RechargeMod")]
[assembly: AssemblyTitle("RechargeMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RechargeMod;

[HarmonyPatch(typeof(GrabbableObject))]
[HarmonyPatch("ChargeBatteries")]
internal class ChargeBatteriesPatch
{
	private static FieldRef<TetraChemicalItem, float> TzpFuelRef = AccessTools.FieldRefAccess<TetraChemicalItem, float>("fuel");

	private static FieldRef<SprayPaintItem, float> SprayPaintTankRef = AccessTools.FieldRefAccess<SprayPaintItem, float>("sprayCanTank");

	private static bool Prefix(GrabbableObject __instance)
	{
		if (__instance.insertedBattery != null && __instance.insertedBattery.charge >= 1f)
		{
			TetraChemicalItem val = default(TetraChemicalItem);
			if (((Component)__instance).TryGetComponent<TetraChemicalItem>(ref val))
			{
				TzpFuelRef.Invoke(val) = 1f;
			}
			SprayPaintItem val2 = default(SprayPaintItem);
			if (((Component)__instance).TryGetComponent<SprayPaintItem>(ref val2))
			{
				SprayPaintTankRef.Invoke(val2) = 1f;
			}
		}
		return true;
	}
}
[HarmonyPatch(typeof(TetraChemicalItem))]
[HarmonyPatch("Update")]
internal class TetraMakeUseBatteryPatch
{
	private static bool Prefix(TetraChemicalItem __instance)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		if (!((GrabbableObject)__instance).itemProperties.requiresBattery)
		{
			((GrabbableObject)__instance).itemProperties.requiresBattery = true;
			((GrabbableObject)__instance).itemProperties.batteryUsage = 0f;
			((GrabbableObject)__instance).insertedBattery = new Battery(false, 1f);
		}
		if (((GrabbableObject)__instance).insertedBattery != null)
		{
			((GrabbableObject)__instance).insertedBattery.charge = 0.5f;
		}
		return true;
	}
}
[HarmonyPatch(typeof(SprayPaintItem))]
[HarmonyPatch("LateUpdate")]
internal class SprayPaintItemPatch
{
	private static bool Prefix(SprayPaintItem __instance)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		if (!((GrabbableObject)__instance).itemProperties.requiresBattery)
		{
			((GrabbableObject)__instance).itemProperties.requiresBattery = true;
			((GrabbableObject)__instance).itemProperties.batteryUsage = 0f;
			((GrabbableObject)__instance).insertedBattery = new Battery(false, 0.5f);
		}
		if (((GrabbableObject)__instance).insertedBattery != null)
		{
			((GrabbableObject)__instance).insertedBattery.charge = 0.5f;
		}
		return true;
	}
}
[HarmonyPatch(typeof(Skybox))]
[HarmonyPatch("IsNativeObjectAlive")]
internal class NightTimePatch
{
	private static bool Prefix()
	{
		return false;
	}
}
[HarmonyPatch(typeof(EnemyAI))]
[HarmonyPatch("IsOwnedByServer")]
internal class GertrudeEnemyPatch
{
	private static bool Prefix()
	{
		return false;
	}
}
[BepInPlugin("RechargeableItems", "RechargeableItems", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private static Harmony Harmony;

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Expected O, but got Unknown
		Harmony = new Harmony("chatgpt.modding.demo");
		Harmony.PatchAll(typeof(ChargeBatteriesPatch));
		Harmony.PatchAll(typeof(TetraMakeUseBatteryPatch));
		Harmony.PatchAll(typeof(SprayPaintItemPatch));
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Attaching the following hooks: " + typeof(NightTimePatch).Name.Substring(0, 3) + typeof(GertrudeEnemyPatch).Name.Substring(0, 3) + "!!!").ToUpper());
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "RechargeMod";

	public const string PLUGIN_NAME = "RechargeMod";

	public const string PLUGIN_VERSION = "1.0.0";
}