using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RechargeRedux;
[HarmonyPatch]
internal class Patches
{
private static FieldRef<SprayPaintItem, float> sprayPaintTank = AccessTools.FieldRefAccess<SprayPaintItem, float>("sprayCanTank");
private static FieldRef<TetraChemicalItem, float> tetraChemicalFuel = AccessTools.FieldRefAccess<TetraChemicalItem, float>("fuel");
[HarmonyPatch(typeof(GrabbableObject), "ChargeBatteries")]
[HarmonyPrefix]
private static void ChargeBatteries(GrabbableObject __instance)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Expected O, but got Unknown
if (RechargeRedux.RechargePaint && __instance is SprayPaintItem)
{
SprayPaintItem val = (SprayPaintItem)__instance;
sprayPaintTank.Invoke(val) = __instance.insertedBattery.charge;
}
else if (RechargeRedux.RechargeTZP && __instance is TetraChemicalItem)
{
TetraChemicalItem val2 = (TetraChemicalItem)__instance;
tetraChemicalFuel.Invoke(val2) = __instance.insertedBattery.charge;
}
}
[HarmonyPatch(typeof(GrabbableObject), "Start")]
[HarmonyPostfix]
private static void Start(GrabbableObject __instance)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Expected O, but got Unknown
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Expected O, but got Unknown
if (RechargeRedux.RechargePaint && __instance is SprayPaintItem)
{
__instance.itemProperties.requiresBattery = true;
__instance.insertedBattery = new Battery(false, sprayPaintTank.Invoke((SprayPaintItem)__instance));
}
else if (RechargeRedux.RechargeTZP && __instance is TetraChemicalItem)
{
_ = (TetraChemicalItem)__instance;
__instance.itemProperties.requiresBattery = true;
__instance.insertedBattery = new Battery(false, tetraChemicalFuel.Invoke((TetraChemicalItem)__instance));
}
}
[HarmonyPatch(typeof(SprayPaintItem), "LateUpdate")]
[HarmonyPostfix]
private static void SprayPaintLateUpdate(SprayPaintItem __instance)
{
if (RechargeRedux.RechargePaint)
{
if (!((GrabbableObject)__instance).itemProperties.requiresBattery)
{
Start((GrabbableObject)(object)__instance);
}
((GrabbableObject)__instance).insertedBattery.charge = sprayPaintTank.Invoke(__instance);
}
else if (((GrabbableObject)__instance).itemProperties.requiresBattery)
{
((GrabbableObject)__instance).itemProperties.requiresBattery = false;
}
}
[HarmonyPatch(typeof(TetraChemicalItem), "Update")]
[HarmonyPostfix]
private static void TetraChemicalUpdate(TetraChemicalItem __instance)
{
if (RechargeRedux.RechargeTZP)
{
if (!((GrabbableObject)__instance).itemProperties.requiresBattery)
{
Start((GrabbableObject)(object)__instance);
}
((GrabbableObject)__instance).insertedBattery.charge = tetraChemicalFuel.Invoke(__instance);
}
else if (((GrabbableObject)__instance).itemProperties.requiresBattery)
{
((GrabbableObject)__instance).itemProperties.requiresBattery = false;
}
}
}
[BepInPlugin("achohbee.RechargeRedux", "RechargeRedux", "1.0.0")]
public class RechargeRedux : BaseUnityPlugin
{
private const string modGUID = "achohbee.RechargeRedux";
private const string modName = "RechargeRedux";
private const string modVersion = "1.0.0";
internal static ManualLogSource log = Logger.CreateLogSource("RechargeRedux");
public static bool RechargePaint { get; private set; }
public static bool RechargeTZP { get; private set; }
private void InitConfig()
{
ConfigEntry<bool> paintConf = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Rechargable Spray Paint", true, (ConfigDescription)null);
log.LogInfo((object)("Setting RechargePaint to " + paintConf.Value));
RechargePaint = paintConf.Value;
paintConf.SettingChanged += delegate
{
log.LogInfo((object)("Config refresh. Setting RechagePaint to " + paintConf.Value));
RechargePaint = paintConf.Value;
};
ConfigEntry<bool> tzpConf = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Rechargable TZP-Inhalant", true, (ConfigDescription)null);
log.LogInfo((object)("Setting RechargeTZP to " + tzpConf.Value));
RechargeTZP = tzpConf.Value;
tzpConf.SettingChanged += delegate
{
log.LogInfo((object)("Config refresh. Setting RechargeTZP to " + tzpConf.Value));
RechargeTZP = tzpConf.Value;
};
}
private void Awake()
{
InitConfig();
log.LogInfo((object)"Applying all patches");
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "achohbee.RechargeRedux");
}
}