Decompiled source of EnergyBottle v0.1.5

EnergyBottle.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Photon.Pun;
using ShopUtils;
using ShopUtils.Language;
using ShopUtils.Network;
using UnityEngine;
using UnityEngine.Localization;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("EnergyBottle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EnergyBottle")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("438d928e-447f-4654-95e7-e68f650c4cb2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace EnergyBottle;

public abstract class EnergyBehavior : ItemInstanceBehaviour
{
	private OnOffEntry onOffEntry;

	private bool on;

	private SFX_PlayOneShot Use;

	private Material Middle;

	public override void ConfigItem(ItemInstanceData data, PhotonView playerView)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		if (!data.TryGetEntry<OnOffEntry>(ref onOffEntry))
		{
			onOffEntry = new OnOffEntry
			{
				on = true
			};
			data.AddDataEntry((ItemDataEntry)(object)onOffEntry);
		}
		if (!onOffEntry.on)
		{
			Middle.SetColor("_Color", new Color(0f, 0f, 0f));
		}
		on = onOffEntry.on;
	}

	private void Awake()
	{
		Use = ((Component)((Component)this).transform.Find("SFX/Use")).GetComponent<SFX_PlayOneShot>();
		Middle = ((Renderer)((Component)((Component)this).transform.Find("Bottle/Middle")).GetComponent<MeshRenderer>()).material;
	}

	private void Update()
	{
		if (base.isHeldByMe && !Player.localPlayer.HasLockedInput() && Player.localPlayer.input.clickWasPressed && onOffEntry.on && CanUse())
		{
			onOffEntry.on = false;
			((ItemDataEntry)onOffEntry).SetDirty();
		}
		if (on == onOffEntry.on)
		{
			return;
		}
		Use.Play();
		if (base.isHeldByMe)
		{
			PlayerController controller = Player.localPlayer.refs.controller;
			((MonoBehaviour)controller).StartCoroutine(OnUse(controller));
			PlayerInventory val = default(PlayerInventory);
			if (Player.localPlayer.TryGetInventory(ref val))
			{
				ItemDescriptor val2 = default(ItemDescriptor);
				val.TryRemoveItemFromSlot(Player.localPlayer.data.selectedItemSlot, ref val2);
			}
		}
	}

	public abstract bool CanUse();

	public abstract IEnumerator OnUse(PlayerController player);
}
public class JumpBehavior : EnergyBehavior
{
	private static bool jumpCoolingTime = true;

	public static EnergyType jump;

	public override bool CanUse()
	{
		if (jump.SteamLoaded)
		{
			return jumpCoolingTime;
		}
		return false;
	}

	public override IEnumerator OnUse(PlayerController player)
	{
		jumpCoolingTime = false;
		float defaultJump = player.jumpImpulse;
		player.jumpImpulse = jump.m_Force;
		yield return (object)new WaitForSeconds(jump.m_Time);
		player.jumpImpulse = defaultJump;
		jumpCoolingTime = true;
	}
}
public class HealthBehavior : EnergyBehavior
{
	public static EnergyType health;

	public override bool CanUse()
	{
		if (Player.localPlayer.data.health < PlayerData.maxHealth)
		{
			return health.SteamLoaded;
		}
		return false;
	}

	public override IEnumerator OnUse(PlayerController player)
	{
		Player.localPlayer.data.health = Mathf.MoveTowards(Player.localPlayer.data.health, PlayerData.maxHealth, health.m_Force);
		yield break;
	}
}
public class OxygenBehavior : EnergyBehavior
{
	public static EnergyType oxygen;

	public override bool CanUse()
	{
		if (Player.localPlayer.data.remainingOxygen < Player.localPlayer.data.maxOxygen)
		{
			return oxygen.SteamLoaded;
		}
		return false;
	}

	public override IEnumerator OnUse(PlayerController player)
	{
		Player.localPlayer.data.remainingOxygen = Mathf.MoveTowards(Player.localPlayer.data.remainingOxygen, Player.localPlayer.data.maxOxygen, oxygen.m_Force);
		yield break;
	}
}
public class SpeedBehavior : EnergyBehavior
{
	private static bool speedCoolingTime = true;

	public static EnergyType speed;

	public override bool CanUse()
	{
		if (speed.SteamLoaded)
		{
			return speedCoolingTime;
		}
		return false;
	}

	public override IEnumerator OnUse(PlayerController player)
	{
		speedCoolingTime = false;
		float defaultSpeed = player.movementForce;
		player.movementForce = speed.m_Force;
		yield return (object)new WaitForSeconds(speed.m_Time);
		player.jumpImpulse = defaultSpeed;
		speedCoolingTime = true;
	}
}
public class EnergyType
{
	public static ConfigFile Config;

	private string EnergyName;

	private bool HasTime = true;

	private float DefualtForce;

	private float DefualtTime;

	private int DefaultPrice;

	private string Description;

	private Item item;

	public float m_Time;

	public float m_Force;

	public bool SteamLoaded;

	private string TimeKey => EnergyName + "Sconds";

	private string BuyableKey => EnergyName + "Buyable";

	private string PriceKey => EnergyName + "Price";

	private string ForceKey => EnergyName + "Force";

	public EnergyType(bool HasTime, string EnergyName, float Force, float Time, int Price, Item item, Type type, string Description)
	{
		this.EnergyName = EnergyName;
		this.HasTime = HasTime;
		this.item = item;
		this.Description = Description;
		DefualtForce = Force;
		DefualtTime = Time;
		DefaultPrice = Price;
		item.itemObject.AddComponent(type);
		LoadConfigData();
		Items.RegisterSpawnableItem(item, PluginInfo.SpawnRarity.Value, PluginInfo.SpawnBudgetCost.Value);
	}

	private void LoadConfigData()
	{
		Dictionary<string, object> dictionary = new Dictionary<string, object>
		{
			{
				BuyableKey,
				Config.Bind<bool>(EnergyName, "BottleBuyable", false, (ConfigDescription)null).Value
			},
			{
				PriceKey,
				Config.Bind<int>(EnergyName, "BottlePrice", DefaultPrice, (ConfigDescription)null).Value
			},
			{
				ForceKey,
				Config.Bind<float>(EnergyName, "BottleForce", DefualtForce, Description).Value
			}
		};
		if (HasTime)
		{
			dictionary.Add(TimeKey, Config.Bind<float>(EnergyName, "BottleTime", DefualtTime, (ConfigDescription)null).Value);
		}
		Networks.SetNetworkSync(dictionary, (Action<Dictionary<string, string>>)delegate(Dictionary<string, string> dic)
		{
			try
			{
				if (HasTime)
				{
					m_Time = float.Parse(dic[TimeKey]);
				}
				m_Force = float.Parse(dic[ForceKey]);
				bool flag = bool.Parse(dic[BuyableKey]);
				int num = int.Parse(dic[PriceKey]);
				if (flag)
				{
					Items.RegisterShopItem(item, (ShopItemCategory)7, num);
				}
				Debug.Log((object)$"{EnergyName}: [Force: {m_Force}, Time: {m_Time}, Buyable: {flag}, Price: {num}]");
				SteamLoaded = true;
			}
			catch
			{
				Debug.LogError((object)("Load `" + EnergyName + "` Energy Bottles Data Fail."));
			}
		});
	}
}
[BepInPlugin("hyydsz-EnergyBottle", "EnergyBottle", "0.1.5")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class PluginInfo : BaseUnityPlugin
{
	public const string ModGUID = "hyydsz-EnergyBottle";

	public const string ModName = "EnergyBottle";

	public const string ModVersion = "0.1.5";

	public static ConfigEntry<float> SpawnRarity;

	public static ConfigEntry<int> SpawnBudgetCost;

	private readonly Harmony harmony = new Harmony("hyydsz-EnergyBottle");

	private AssetBundle asset;

	private void Awake()
	{
		LoadBottle();
		LoadLangauge();
		harmony.PatchAll();
	}

	private void LoadBottle()
	{
		asset = QuickLoadAssetBundle("energy");
		EnergyType.Config = ((BaseUnityPlugin)this).Config;
		Item item = asset.LoadAsset<Item>("JumpBottle");
		Item item2 = asset.LoadAsset<Item>("HealthBottle");
		Item item3 = asset.LoadAsset<Item>("OxygenBottle");
		Item item4 = asset.LoadAsset<Item>("SpeedBottle");
		SpawnRarity = ((BaseUnityPlugin)this).Config.Bind<float>("Config", "SpawnRarity", 1f, (ConfigDescription)null);
		SpawnBudgetCost = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "SpawnBudgetCost", 1, (ConfigDescription)null);
		JumpBehavior.jump = new EnergyType(HasTime: true, "JumpBottle", 30f, 20f, 50, item, typeof(JumpBehavior), "Jump Height");
		HealthBehavior.health = new EnergyType(HasTime: false, "HealthBottle", 30f, 0f, 50, item2, typeof(HealthBehavior), "Restore Health");
		OxygenBehavior.oxygen = new EnergyType(HasTime: false, "OxygenBottle", 30f, 0f, 50, item3, typeof(OxygenBehavior), "Restore Oxygen");
		SpeedBehavior.speed = new EnergyType(HasTime: true, "SpeedBottle", 25f, 20f, 50, item4, typeof(SpeedBehavior), "Movement Speed");
	}

	private void LoadLangauge()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Expected O, but got Unknown
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Expected O, but got Unknown
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Expected O, but got Unknown
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Expected O, but got Unknown
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Expected O, but got Unknown
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Expected O, but got Unknown
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Expected O, but got Unknown
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Expected O, but got Unknown
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Expected O, but got Unknown
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Expected O, but got Unknown
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Expected O, but got Unknown
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Expected O, but got Unknown
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Expected O, but got Unknown
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Expected O, but got Unknown
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Expected O, but got Unknown
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Expected O, but got Unknown
		Locale language = Languages.GetLanguage((LanguageEnum)0);
		Languages.AddLanguage(language, (LanguageInstance[])(object)new LanguageInstance[8]
		{
			new LanguageInstance("JumpBottle_ToolTips", "[LMB] 使用"),
			new LanguageInstance("JumpBottle", "跳跃能量瓶"),
			new LanguageInstance("HealthBottle_ToolTips", "[LMB] 使用"),
			new LanguageInstance("HealthBottle", "血量能量瓶"),
			new LanguageInstance("OxygenBottle_ToolTips", "[LMB] 使用"),
			new LanguageInstance("OxygenBottle", "氧气能量瓶"),
			new LanguageInstance("SpeedBottle_ToolTips", "[LMB] 使用"),
			new LanguageInstance("SpeedBottle", "速度能量瓶")
		});
		Locale language2 = Languages.GetLanguage((LanguageEnum)1);
		Languages.AddLanguage(language2, (LanguageInstance[])(object)new LanguageInstance[8]
		{
			new LanguageInstance("JumpBottle_ToolTips", "[LMB] 使用"),
			new LanguageInstance("JumpBottle", "跳躍能量瓶"),
			new LanguageInstance("HealthBottle_ToolTips", "[LMB] 使用"),
			new LanguageInstance("HealthBottle", "血量能量瓶"),
			new LanguageInstance("OxygenBottle_ToolTips", "[LMB] 使用"),
			new LanguageInstance("OxygenBottle", "氧氣能量瓶"),
			new LanguageInstance("SpeedBottle_ToolTips", "[LMB] 使用"),
			new LanguageInstance("SpeedBottle", "速度能量瓶")
		});
		Locale language3 = Languages.GetLanguage((LanguageEnum)2);
		Languages.AddLanguage(language3, (LanguageInstance[])(object)new LanguageInstance[8]
		{
			new LanguageInstance("JumpBottle_ToolTips", "[LMB] Use"),
			new LanguageInstance("JumpBottle", "JumpBottle"),
			new LanguageInstance("HealthBottle_ToolTips", "[LMB] Use"),
			new LanguageInstance("HealthBottle", "HealthBottle"),
			new LanguageInstance("OxygenBottle_ToolTips", "[LMB] Use"),
			new LanguageInstance("OxygenBottle", "OxygenBottle"),
			new LanguageInstance("SpeedBottle_ToolTips", "[LMB] Use"),
			new LanguageInstance("SpeedBottle", "SpeedBottle")
		});
	}

	public static AssetBundle QuickLoadAssetBundle(string name)
	{
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), name);
		return AssetBundle.LoadFromFile(text);
	}
}