using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ShowCapacity.Patches;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RadiationIsCool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RadiationIsCool")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8ee335db-0cbe-470c-8fbc-69263f01b35a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ShowCapacity
{
[BepInPlugin("Piggy.ShowCapacity", "ShowCapacity", "1.0.12")]
public class Plugin : BaseUnityPlugin
{
private const string modGUID = "Piggy.ShowCapacity";
private const string modName = "ShowCapacity";
private const string modVersion = "1.0.12";
private readonly Harmony harmony = new Harmony("Piggy.ShowCapacity");
private static Plugin Instance;
public static ManualLogSource mls;
public static int colorRed;
public static int colorGreen;
public static int colorBlue;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("Piggy.ShowCapacity");
mls.LogInfo((object)"Show Capacity is loaded");
colorRed = ((BaseUnityPlugin)this).Config.Bind<int>("Color", "Red", 0, "Red value in RGB (0-255)").Value;
colorGreen = ((BaseUnityPlugin)this).Config.Bind<int>("Color", "Green", 255, "Green value in RGB (0-255)").Value;
colorBlue = ((BaseUnityPlugin)this).Config.Bind<int>("Color", "Blue", 255, "Blue value in RGB (0-255)").Value;
harmony.PatchAll(typeof(Plugin));
harmony.PatchAll(typeof(HUDManagerPatch));
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(SprayPaintItemPatch));
harmony.PatchAll(typeof(TetraChemicalItemPatch));
}
}
}
namespace ShowCapacity.Patches
{
[HarmonyPatch(typeof(TetraChemicalItem))]
internal static class TetraChemicalItemPatch
{
private static readonly FieldInfo fuelField = typeof(TetraChemicalItem).GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic);
public static float GetTZPFuel(TetraChemicalItem instance)
{
return (float)fuelField.GetValue(instance);
}
}
[HarmonyPatch(typeof(SprayPaintItem))]
internal static class SprayPaintItemPatch
{
private static readonly FieldInfo sprayCanTankField = typeof(SprayPaintItem).GetField("sprayCanTank", BindingFlags.Instance | BindingFlags.NonPublic);
public static float GetSprayCanTank(SprayPaintItem instance)
{
return (float)sprayCanTankField.GetValue(instance);
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal static class PlayerControllerBPatch
{
private static Image capacityMeter;
private static CanvasGroup capacityGroup;
private static bool isPlayerHoldingSpray;
private static readonly FieldInfo sprayCanTankField = typeof(SprayPaintItem).GetField("sprayCanTank", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly FieldInfo fuelField = typeof(TetraChemicalItem).GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic);
private static TetraChemicalItem tzpScript;
private static SprayPaintItem sprayScript;
private static GrabbableObject prevHeldObject;
[HarmonyPostfix]
[HarmonyPatch("Update")]
private static void Update_PostFix(ref bool ___isHoldingObject, ref GrabbableObject ___currentlyHeldObjectServer, ref bool ___isCameraDisabled)
{
if ((Object)(object)capacityMeter == (Object)null)
{
GameObject val = GameObject.Find("CapacityMeter");
if ((Object)(object)val != (Object)null)
{
capacityMeter = val.GetComponent<Image>();
capacityGroup = GameObject.Find("Capacities").GetComponent<CanvasGroup>();
capacityGroup.alpha = 0f;
}
}
if (((Object)(object)capacityMeter == (Object)null) | ___isCameraDisabled)
{
return;
}
if (___isHoldingObject && (Object)(object)___currentlyHeldObjectServer != (Object)null)
{
GrabbableObject val2 = ___currentlyHeldObjectServer;
if (___currentlyHeldObjectServer is SprayPaintItem)
{
isPlayerHoldingSpray = true;
if ((Object)(object)sprayScript != (Object)(object)val2)
{
SprayPaintItem component = ((Component)val2).GetComponent<SprayPaintItem>();
sprayScript = component;
}
else
{
FieldInfo field = typeof(SprayPaintItem).GetField("isSpraying", BindingFlags.Instance | BindingFlags.NonPublic);
if ((Object)(object)prevHeldObject != (Object)(object)val2)
{
UpdateMeter(sprayScript, sprayCanTankField);
prevHeldObject = val2;
}
if ((Object)(object)sprayScript != (Object)null && (bool)field.GetValue(sprayScript))
{
UpdateMeter(sprayScript, sprayCanTankField);
}
}
}
else if (___currentlyHeldObjectServer is TetraChemicalItem)
{
isPlayerHoldingSpray = true;
if ((Object)(object)tzpScript != (Object)(object)val2)
{
TetraChemicalItem component2 = ((Component)val2).GetComponent<TetraChemicalItem>();
tzpScript = component2;
}
else
{
FieldInfo field2 = typeof(TetraChemicalItem).GetField("emittingGas", BindingFlags.Instance | BindingFlags.NonPublic);
if ((Object)(object)prevHeldObject != (Object)(object)val2)
{
UpdateMeter(tzpScript, fuelField);
prevHeldObject = val2;
}
if ((Object)(object)tzpScript != (Object)null && (bool)field2.GetValue(tzpScript))
{
UpdateMeter(tzpScript, fuelField);
}
}
}
else
{
isPlayerHoldingSpray = false;
}
}
else
{
isPlayerHoldingSpray = false;
}
EnableMeter(isPlayerHoldingSpray);
}
private static void UpdateMeter(object item, FieldInfo field)
{
if (field != null && item != null)
{
float num = (float)field.GetValue(item);
capacityMeter.fillAmount = num / 1.3f;
}
}
private static void EnableMeter(bool isActive)
{
if ((Object)(object)capacityMeter != (Object)null)
{
capacityGroup.alpha = (isActive ? 1 : 0);
}
}
}
[HarmonyPatch(typeof(HUDManager))]
internal class HUDManagerPatch
{
[HarmonyPrefix]
[HarmonyPatch("Start")]
private static void Start_PreFix(HUDManager __instance)
{
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
GameObject val = GameObject.Find("Batteries");
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)"Batteries object not assigned!");
return;
}
GameObject val2 = Object.Instantiate<GameObject>(val, val.transform.parent);
((Object)val2).name = "Capacities";
Transform[] componentsInChildren = val2.GetComponentsInChildren<Transform>(true);
Image val4 = default(Image);
foreach (Transform val3 in componentsInChildren)
{
if (((Object)val3).name.Contains("Battery"))
{
((Object)val3).name = ((Object)val3).name.Replace("Battery", "Capacity");
if (((Object)val3).name == "CapacityIcon")
{
Object.Destroy((Object)(object)((Component)val3).gameObject);
}
}
if (((Component)val3).TryGetComponent<Image>(ref val4))
{
((Graphic)val4).color = Color32.op_Implicit(new Color32((byte)Plugin.colorRed, (byte)Plugin.colorGreen, (byte)Plugin.colorBlue, (byte)((((Graphic)val4).color.a >= 1f) ? byte.MaxValue : 111)));
}
}
}
}
}