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.9")]
public class Plugin : BaseUnityPlugin
{
private const string modGUID = "Piggy.ShowCapacity";
private const string modName = "ShowCapacity";
private const string modVersion = "1.0.9";
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 class TetraChemicalItemPatch
{
public float GetTZPFuel(ref float ___fuel)
{
return ___fuel;
}
}
[HarmonyPatch(typeof(SprayPaintItem))]
internal class SprayPaintItemPatch
{
public float GetSprayCanTank(ref float ___sprayCanTank)
{
return ___sprayCanTank;
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
private static GameObject capacityMeter;
private static bool isPlayerHoldingObject;
private static bool isPlayerHoldingSpray;
[HarmonyPrefix]
[HarmonyPatch("Update")]
private static void Update_PreFix(ref bool ___isHoldingObject, ref GrabbableObject ___currentlyHeldObjectServer, ref bool ___isCameraDisabled)
{
if ((Object)(object)capacityMeter == (Object)null && (Object)(object)GameObject.Find("CapacityMeter") != (Object)null)
{
capacityMeter = GameObject.Find("CapacityMeter");
capacityMeter.SetActive(false);
}
if ((Object)(object)capacityMeter == (Object)null)
{
return;
}
if (!___isCameraDisabled & ___isHoldingObject)
{
isPlayerHoldingObject = true;
}
else if (!___isCameraDisabled && !___isHoldingObject)
{
isPlayerHoldingObject = false;
}
if ((!___isCameraDisabled & ___isHoldingObject) && ((Object)(object)((Component)___currentlyHeldObjectServer).GetComponent<SprayPaintItem>() != (Object)null || (Object)(object)((Component)___currentlyHeldObjectServer).GetComponent<TetraChemicalItem>() != (Object)null))
{
isPlayerHoldingSpray = true;
}
else if ((!___isCameraDisabled & ___isHoldingObject) && (Object)(object)((Component)___currentlyHeldObjectServer).GetComponent<SprayPaintItem>() == (Object)null && (Object)(object)((Component)___currentlyHeldObjectServer).GetComponent<TetraChemicalItem>() == (Object)null)
{
isPlayerHoldingSpray = false;
}
if (isPlayerHoldingObject && (Object)(object)___currentlyHeldObjectServer != (Object)null)
{
if ((Object)(object)((Component)___currentlyHeldObjectServer).gameObject.GetComponent<SprayPaintItem>() != (Object)null)
{
SprayPaintItem component = ((Component)___currentlyHeldObjectServer).gameObject.GetComponent<SprayPaintItem>();
FieldInfo field = typeof(SprayPaintItem).GetField("sprayCanTank", BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
{
float num = (float)field.GetValue(component);
capacityMeter.GetComponent<Image>().fillAmount = num / 1.3f;
}
}
else if ((Object)(object)((Component)___currentlyHeldObjectServer).gameObject.GetComponent<TetraChemicalItem>() != (Object)null)
{
TetraChemicalItem component2 = ((Component)___currentlyHeldObjectServer).gameObject.GetComponent<TetraChemicalItem>();
FieldInfo field2 = typeof(TetraChemicalItem).GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic);
if (field2 != null)
{
float num2 = (float)field2.GetValue(component2);
capacityMeter.GetComponent<Image>().fillAmount = num2 / 1.3f;
}
}
}
EnableMeter(isPlayerHoldingObject);
}
private static void EnableMeter(bool isHoldingObject)
{
if (isHoldingObject && isPlayerHoldingSpray)
{
capacityMeter.SetActive(true);
}
else
{
capacityMeter.SetActive(false);
}
}
private static void CopyChildren(Transform original, Transform copy)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
foreach (Transform item in original)
{
Transform val = item;
GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, copy);
CopyChildren(val, val2.transform);
}
}
private static void ChangeChildName(GameObject child)
{
if (((Object)child).name == "BatteryMeter")
{
((Object)child).name = "CapacityMeter";
}
else if (((Object)child).name == "BatteryMeter(Clone)")
{
((Object)child).name = "CapacityMeter";
}
else if (((Object)child).name == "BatteryIcon")
{
((Object)child).name = "CapacityIcon";
}
else if (((Object)child).name == "BatteryIcon(Clone)")
{
((Object)child).name = "CapacityIcon";
}
else if (((Object)child).name == "BatteryNum")
{
((Object)child).name = "CapacityNum";
}
else if (((Object)child).name == "BatteryNum(Clone)")
{
((Object)child).name = "CapacityNum";
}
else if (((Object)child).name == "BatteryMeterFrame")
{
((Object)child).name = "CapacityMeterFrame";
}
else if (((Object)child).name == "BatteryMeterFrame(Clone)")
{
((Object)child).name = "CapacityMeterFrame";
}
}
}
[HarmonyPatch(typeof(HUDManager))]
internal class HUDManagerPatch
{
[HarmonyPrefix]
[HarmonyPatch("Update")]
private static void Update_PreFix()
{
if ((Object)(object)GameObject.Find("Batteries") != (Object)null && (Object)(object)GameObject.Find("Capacity") == (Object)null)
{
GameObject val = Object.Instantiate<GameObject>(GameObject.Find("Batteries"), GameObject.Find("Batteries").transform.parent);
((Object)val).name = "Capacity";
Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>();
CopyChildren(GameObject.Find("Batteries").transform, val.transform);
Transform[] array = componentsInChildren;
foreach (Transform val2 in array)
{
if ((Object)(object)val2 != (Object)(object)val.transform && (Object)(object)val2.parent != (Object)(object)GameObject.Find("Batteries").transform)
{
Object.Destroy((Object)(object)((Component)val2).gameObject);
}
}
}
Object.Destroy((Object)(object)GameObject.Find("BatteryIcon(Clone)"));
Object.Destroy((Object)(object)GameObject.Find("CapacityIcon"));
if ((Object)(object)GameObject.Find("CapacityIcon") != (Object)null || (Object)(object)GameObject.Find("BatteryMeter(Clone)") != (Object)null || (Object)(object)GameObject.Find("BatteryIcon(Clone)") != (Object)null || (Object)(object)GameObject.Find("BatteryNum(Clone)") != (Object)null || (Object)(object)GameObject.Find("BatteryMeterFrame(Clone)") != (Object)null)
{
Object.Destroy((Object)(object)GameObject.Find("CapacityIcon"));
Object.Destroy((Object)(object)GameObject.Find("BatteryMeter(Clone)"));
Object.Destroy((Object)(object)GameObject.Find("BatteryIcon(Clone)"));
Object.Destroy((Object)(object)GameObject.Find("BatteryNum(Clone)"));
Object.Destroy((Object)(object)GameObject.Find("BatteryMeterFrame(Clone)"));
}
}
private static void CopyChildren(Transform original, Transform copy)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
foreach (Transform item in original)
{
Transform val = item;
GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, copy);
if ((Object)(object)val2.GetComponent<Image>() != (Object)null)
{
if (((Graphic)val2.GetComponent<Image>()).color.a >= 1f)
{
((Graphic)val2.GetComponent<Image>()).color = Color32.op_Implicit(new Color32((byte)Plugin.colorRed, (byte)Plugin.colorGreen, (byte)Plugin.colorBlue, byte.MaxValue));
}
else
{
((Graphic)val2.GetComponent<Image>()).color = Color32.op_Implicit(new Color32((byte)Plugin.colorRed, (byte)Plugin.colorGreen, (byte)Plugin.colorBlue, (byte)111));
}
}
ChangeChildName(val2);
CopyChildren(val, val2.transform);
}
}
private static void ChangeChildName(GameObject child)
{
if (((Object)child).name == "BatteryMeter")
{
((Object)child).name = "CapacityMeter";
}
else if (((Object)child).name == "BatteryMeter(Clone)")
{
((Object)child).name = "CapacityMeter";
}
else if (((Object)child).name == "BatteryIcon")
{
((Object)child).name = "CapacityIcon";
}
else if (((Object)child).name == "BatteryIcon(Clone)")
{
((Object)child).name = "CapacityIcon";
}
else if (((Object)child).name == "BatteryNum")
{
((Object)child).name = "CapacityNum";
}
else if (((Object)child).name == "BatteryNum(Clone)")
{
((Object)child).name = "CapacityNum";
}
else if (((Object)child).name == "BatteryMeterFrame")
{
((Object)child).name = "CapacityMeterFrame";
}
else if (((Object)child).name == "BatteryMeterFrame(Clone)")
{
((Object)child).name = "CapacityMeterFrame";
}
}
}
}