Decompiled source of InfiniteCharge v1.1.0

InfiniteCharge.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using On;
using Photon.Pun;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("InfiniteCharge")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("InfiniteCharge")]
[assembly: AssemblyTitle("InfiniteCharge")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace InfiniteCharge
{
	[BepInPlugin("Turara.InfiniteCharge", "infinite Charge", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin instance;

		public static InfiniteConfig config;

		public static SpecSlot Spec;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				config = new InfiniteConfig(((BaseUnityPlugin)this).Config);
				Spec = new SpecSlot();
				Spec.Init();
				InfiniteTools.Init();
				InfinitePlayer.Init();
				instance = this;
			}
		}

		public IEnumerator SetPositionDelayed(RectTransform rectTransform)
		{
			yield return null;
			Vector2 anchoredPosition = rectTransform.anchoredPosition;
			anchoredPosition.x = 200f;
			rectTransform.anchoredPosition = anchoredPosition;
		}
	}
	public class InfiniteConfig
	{
		public ConfigEntry<bool> Infinite_Flashlight;

		public ConfigEntry<bool> Infinite_RescueHook;

		public ConfigEntry<bool> Infinite_ShockStick;

		public ConfigEntry<bool> Infinite_Oxygen;

		public ConfigEntry<bool> Infinite_Stamina;

		public ConfigEntry<bool> Never_Fall_Down;

		public ConfigEntry<bool> Hugger_Can_SelfHeal;

		public InfiniteConfig(ConfigFile cfgFile)
		{
			Infinite_Flashlight = cfgFile.Bind<bool>("Item Infinite Charge", "Infinite Flashlight", true, "you can't use up the battery anymore");
			Infinite_RescueHook = cfgFile.Bind<bool>("Item Infinite Charge", "Infinite RescueHook", true, "you can't use up the battery anymore");
			Infinite_ShockStick = cfgFile.Bind<bool>("Item Infinite Charge", "Infinite ShockStick", true, "you can't use up the battery anymore");
			Infinite_Oxygen = cfgFile.Bind<bool>("Player Infinite", "Infinite Oxygen", true, "you can breathe in space now!");
			Infinite_Stamina = cfgFile.Bind<bool>("Player Infinite", "Infinite Stamina", true, "you ran fifty laps on Mars and didn't feel tired");
			Never_Fall_Down = cfgFile.Bind<bool>("Player Infinite", "Never Fall Down", true, "you jumped off the Tokyo Tower with both feet on the ground!");
			Hugger_Can_SelfHeal = cfgFile.Bind<bool>("Other", "Hugger Can SelfHeal", true, "you won't be alone anymore");
		}
	}
	public class SpecSlot
	{
		public HotbarSlotUI ShockStickUI = null;

		public HotbarSlotUI RescueHookUI = null;

		public HotbarSlotUI FlashlightUI = null;

		public void Init()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			GameAPI.Awake += new hook_Awake(GameAPI_Awake);
			HotbarUI.Set += new hook_Set(HotbarUI_Set);
			PlayerInventory.TryAddItem_ItemDescriptor_refInventorySlot += new hook_TryAddItem_ItemDescriptor_refInventorySlot(PlayerInventory_TryAddItem);
			PlayerInventory.TryGetSlot += new hook_TryGetSlot(PlayerInventory_TryGetSlot);
			PlayerItems.Update += new hook_Update(PlayerItems_Update);
			ItemHugger.TriggerSaysTriggerStay += new hook_TriggerSaysTriggerStay(ItemHugger_TriggerSaysTriggerStay);
		}

		private void ItemHugger_TriggerSaysTriggerStay(orig_TriggerSaysTriggerStay orig, ItemHugger self, Collider other)
		{
			if (Plugin.config.Hugger_Can_SelfHeal.Value)
			{
				Player localPlayer = Player.localPlayer;
				float num = PlayerData.maxHealth / (self.fullHealTime / self.healInterval);
				localPlayer.CallHeal(num);
			}
			orig.Invoke(self, other);
		}

		private void PlayerItems_Update(orig_Update orig, PlayerItems self)
		{
			Player component = ((Component)self).GetComponent<Player>();
			if (component.data.isLocal && component.data.physicsAreReady && !component.HasLockedInput())
			{
				if (GlobalInputHandler.GetKeyDown((KeyCode)102))
				{
					ChangePlayerSelected(component, 27);
				}
				if (GlobalInputHandler.GetKeyDown((KeyCode)103))
				{
					ChangePlayerSelected(component, 29);
				}
				if (GlobalInputHandler.GetKeyDown((KeyCode)116))
				{
					ChangePlayerSelected(component, 28);
				}
			}
			orig.Invoke(self);
		}

		private void ChangePlayerSelected(Player player, int slotID)
		{
			if (slotID == player.data.selectedItemSlot)
			{
				player.data.selectedItemSlot = -1;
			}
			else
			{
				player.data.selectedItemSlot = slotID;
			}
		}

		private bool PlayerInventory_TryGetSlot(orig_TryGetSlot orig, PlayerInventory self, int slotID, out InventorySlot slot)
		{
			if (slotID == 27 && SpecInv.GetSlotByInv(self, 27, out InventorySlot slot2))
			{
				slot = slot2;
				return true;
			}
			if (slotID == 28 && SpecInv.GetSlotByInv(self, 28, out InventorySlot slot3))
			{
				slot = slot3;
				return true;
			}
			if (slotID == 29 && SpecInv.GetSlotByInv(self, 29, out InventorySlot slot4))
			{
				slot = slot4;
				return true;
			}
			return orig.Invoke(self, slotID, ref slot);
		}

		private bool PlayerInventory_TryAddItem(orig_TryAddItem_ItemDescriptor_refInventorySlot orig, PlayerInventory self, ItemDescriptor item, out InventorySlot slot)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_0061: 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)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			string name = ((Object)item.item).name;
			Debug.Log((object)("[Turara]:" + name));
			if (name.ToLower().Contains("Flashlight".ToLower()) && SpecInv.GetSlotByInv(self, 27, out InventorySlot slot2) && (Object)(object)slot2.ItemInSlot.item == (Object)null)
			{
				slot2.Add(item);
				slot = slot2;
				return true;
			}
			if (name.ToLower().Contains("RescueHook".ToLower()) && SpecInv.GetSlotByInv(self, 28, out InventorySlot slot3) && (Object)(object)slot3.ItemInSlot.item == (Object)null)
			{
				slot3.Add(item);
				slot = slot3;
				return true;
			}
			if (name.ToLower().Contains("ShockStick".ToLower()) && SpecInv.GetSlotByInv(self, 29, out InventorySlot slot4) && (Object)(object)slot4.ItemInSlot.item == (Object)null)
			{
				slot4.Add(item);
				slot = slot4;
				return true;
			}
			return orig.Invoke(self, item, ref slot);
		}

		private void HotbarUI_Set(orig_Set orig, HotbarUI self, Player player)
		{
			orig.Invoke(self, player);
			PlayerInventory inventory = default(PlayerInventory);
			if (player.TryGetInventory(ref inventory))
			{
				if (SpecInv.GetSlotByInv(inventory, 27, out InventorySlot slot))
				{
					FlashlightUI.SetData(slot, slot.SlotID == player.data.selectedItemSlot);
				}
				if (SpecInv.GetSlotByInv(inventory, 28, out InventorySlot slot2))
				{
					RescueHookUI.SetData(slot2, slot2.SlotID == player.data.selectedItemSlot);
				}
				if (SpecInv.GetSlotByInv(inventory, 29, out InventorySlot slot3))
				{
					ShockStickUI.SetData(slot3, slot3.SlotID == player.data.selectedItemSlot);
				}
			}
		}

		private void GameAPI_Awake(orig_Awake orig, GameAPI self)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			Transform val = ((Component)self).transform.Find("HelmetUI");
			if ((Object)(object)val != (Object)null)
			{
				Plugin instance = Plugin.instance;
				Transform val2 = val.Find("Pivot/Others/Hotbar");
				RectTransform component = ((Component)val2).GetComponent<RectTransform>();
				Vector2 sizeDelta = component.sizeDelta;
				sizeDelta.x = 1000f;
				component.sizeDelta = sizeDelta;
				((MonoBehaviour)instance).StartCoroutine(instance.SetPositionDelayed(component));
				Transform val3 = val2.Find("Items/HotbarSlot");
				int num = 230;
				int num2 = -350;
				int num3 = 0;
				Transform val4 = Object.Instantiate<Transform>(val3, val2.parent);
				val4.localPosition = new Vector3((float)(num + num3 * 65), (float)num2, 0f);
				((TMP_Text)((Component)val4).GetComponentInChildren<TextMeshProUGUI>()).text = "F";
				FlashlightUI = ((Component)val4).GetComponent<HotbarSlotUI>();
				num3 = 1;
				Transform val5 = Object.Instantiate<Transform>(val3, val2.parent);
				val5.localPosition = new Vector3((float)(num + num3 * 65), (float)num2, 0f);
				((TMP_Text)((Component)val5).GetComponentInChildren<TextMeshProUGUI>()).text = "T";
				RescueHookUI = ((Component)val5).GetComponent<HotbarSlotUI>();
				num3 = 2;
				Transform val6 = Object.Instantiate<Transform>(val3, val2.parent);
				val6.localPosition = new Vector3((float)(num + num3 * 65), (float)num2, 0f);
				((TMP_Text)((Component)val6).GetComponentInChildren<TextMeshProUGUI>()).text = "G";
				ShockStickUI = ((Component)val6).GetComponent<HotbarSlotUI>();
			}
		}

		public void InitSpecSlot(Player player)
		{
			SpecInv.InitSpecInv(player);
		}
	}
	internal class SpecInv
	{
		public static Dictionary<int, InventorySlot[]> InventorySlots = new Dictionary<int, InventorySlot[]>();

		public static bool GetSlotByInv(PlayerInventory inventory, int invIndex, out InventorySlot slot)
		{
			int viewID = ((Component)inventory).GetComponent<PhotonView>().ViewID;
			if (!InventorySlots.ContainsKey(viewID))
			{
				slot = null;
				return false;
			}
			InventorySlot[] array = InventorySlots[viewID];
			switch (invIndex)
			{
			case 27:
				slot = array[0];
				return true;
			case 28:
				slot = array[1];
				return true;
			case 29:
				slot = array[2];
				return true;
			default:
				slot = null;
				return false;
			}
		}

		public static void InitSpecInv(Player player)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			PlayerInventory val = default(PlayerInventory);
			if (player.TryGetInventory(ref val))
			{
				int viewID = ((Component)val).GetComponent<PhotonView>().ViewID;
				if (!InventorySlots.ContainsKey(viewID))
				{
					InventorySlots[viewID] = (InventorySlot[])(object)new InventorySlot[3];
					InventorySlot val2 = new InventorySlot(27, val);
					InventorySlot val3 = new InventorySlot(28, val);
					InventorySlot val4 = new InventorySlot(29, val);
					InventorySlots[viewID][0] = val2;
					InventorySlots[viewID][1] = val3;
					InventorySlots[viewID][2] = val4;
				}
			}
		}
	}
	internal class InfinitePlayer
	{
		public static void Init()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Player.Ragdoll += new hook_Ragdoll(Player_Ragdoll);
			PlayerController.Update += new hook_Update(PlayerController_Update);
		}

		private static void PlayerController_Update(orig_Update orig, PlayerController self)
		{
			Player component = ((Component)self).GetComponent<Player>();
			if (!component.ai)
			{
				if (Plugin.config.Infinite_Oxygen.Value)
				{
					component.data.remainingOxygen = component.data.maxOxygen;
				}
				if (Plugin.config.Infinite_Stamina.Value)
				{
					component.data.currentStamina = self.maxStamina;
				}
				if (!component.data.dead && Plugin.config.Never_Fall_Down.Value)
				{
					component.data.fallTime = 0f;
				}
				Plugin.Spec.InitSpecSlot(component);
			}
			orig.Invoke(self);
		}

		private static bool Player_Ragdoll(orig_Ragdoll orig, Player self)
		{
			if (self.ai || self.data.dead || !Plugin.config.Never_Fall_Down.Value)
			{
				return orig.Invoke(self);
			}
			return false;
		}
	}
	public static class InfiniteTools
	{
		public static void Init()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			Flashlight.Update += new hook_Update(Flashlight_Update);
			RescueHook.Update += new hook_Update(RescueHook_Update);
			RescueHook.ConfigItem += new hook_ConfigItem(RescueHook_ConfigItem);
			ShockStick.Update += new hook_Update(ShockStick_Update);
		}

		private static void ShockStick_Update(orig_Update orig, ShockStick self)
		{
			if (Plugin.config.Infinite_ShockStick.Value)
			{
				BatteryEntry batteryEntry = typeof(ShockStick).GetBatteryEntry(self);
				batteryEntry.m_charge = batteryEntry.m_maxCharge;
			}
			orig.Invoke(self);
		}

		private static void RescueHook_ConfigItem(orig_ConfigItem orig, RescueHook self, ItemInstanceData data, PhotonView playerView)
		{
			if (Plugin.config.Infinite_RescueHook.Value)
			{
				self.range = 1000;
				self.dragForce = 600f;
			}
			orig.Invoke(self, data, playerView);
		}

		private static void RescueHook_Update(orig_Update orig, RescueHook self)
		{
			if (Plugin.config.Infinite_RescueHook.Value)
			{
				BatteryEntry batteryEntry = typeof(RescueHook).GetBatteryEntry(self);
				batteryEntry.m_charge = batteryEntry.m_maxCharge;
			}
			orig.Invoke(self);
		}

		private static void Flashlight_Update(orig_Update orig, Flashlight self)
		{
			if (Plugin.config.Infinite_Flashlight.Value)
			{
				BatteryEntry batteryEntry = typeof(Flashlight).GetBatteryEntry(self);
				batteryEntry.m_charge = batteryEntry.m_maxCharge;
			}
			orig.Invoke(self);
		}

		public static BatteryEntry GetBatteryEntry(this Type type, object __instance)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			FieldInfo field = type.GetField("m_batteryEntry", BindingFlags.Instance | BindingFlags.NonPublic);
			return (BatteryEntry)field.GetValue(__instance);
		}
	}
}