Decompiled source of DawnUltrasItems v1.1.0

DawnUltrasItems.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using DawnUltrasItems.NetcodePatcher;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using UnityEngine;
using YourThunderstoreTeam.patch;
using YourThunderstoreTeam.patch.Items;
using YourThunderstoreTeam.patch.enemies;
using YourThunderstoreTeam.service;
using YourThunderstoreTeam.util;

[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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("DawnUltrasItems")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3-alpha.0.35")]
[assembly: AssemblyProduct("DawnUltrasItems")]
[assembly: AssemblyTitle("DawnUltrasItems")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 YourThunderstoreTeam
{
	[BepInPlugin("DawnUltrasItems", "DawnUltrasItems", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("DawnUltrasItems");

		public TemplateService Service;

		public static AssetBundle DawnUltrasItemsAssets;

		public static Plugin Instance { get; set; }

		public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		public Plugin()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Instance = this;
		}

		private void Awake()
		{
			Service = new TemplateService();
			Log.LogInfo((object)"Applying patches...");
			ApplyPluginPatch();
			Log.LogInfo((object)"Patches applied");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			DawnUltrasItemsAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "dawnultrasitemsbundle"));
			if ((Object)(object)DawnUltrasItemsAssets == (Object)null)
			{
				Log.LogError((object)"Failed to load custom assets");
				return;
			}
			Log.LogInfo((object)"Adding Dawn Ultra's items...");
			AddItems();
			Log.LogInfo((object)"Dawn Ultra's items added");
		}

		private void ApplyPluginPatch()
		{
			_harmony.PatchAll(typeof(ShipLightsPatch));
			_harmony.PatchAll(typeof(PlayerControllerBPatch));
			_harmony.PatchAll(typeof(MaskedPlayerEnemyPatch));
			_harmony.PatchAll(typeof(ForestGiantPatch));
			_harmony.PatchAll(typeof(FlowermanPatch));
		}

		private void AddItems()
		{
			HealthpackItem.AddAsset(DawnUltrasItemsAssets);
			CheezburgerItem.AddAsset(DawnUltrasItemsAssets);
			RizzburgerItem.AddAsset(DawnUltrasItemsAssets);
			SpeedCoilItem.AddAsset(DawnUltrasItemsAssets);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DawnUltrasItems";

		public const string PLUGIN_NAME = "DawnUltrasItems";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace YourThunderstoreTeam.util
{
	public static class Utilities
	{
		public static void PrintToChat(string message)
		{
			HUDManager.Instance.AddTextToChatOnServer(message, -1);
		}
	}
}
namespace YourThunderstoreTeam.service
{
	public class TemplateService
	{
		public bool ReturnTrue()
		{
			return true;
		}

		public bool ReturnFalse()
		{
			return false;
		}
	}
}
namespace YourThunderstoreTeam.patch
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class PlayerControllerBPatch
	{
		private static Dictionary<int, bool> InvinciblePlayerIDs { get; set; } = new Dictionary<int, bool>();


		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool OnPlayerDamage(ref PlayerControllerB __instance)
		{
			return !IsPlayerInvincible(__instance);
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool OnPlayerDeath(ref PlayerControllerB __instance, object[] __args)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			CauseOfDeath causeOfDeath = (CauseOfDeath)__args[2];
			return !CanResistCauseOfDeath(causeOfDeath) || !IsPlayerInvincible(__instance);
		}

		private static bool CanResistCauseOfDeath(CauseOfDeath causeOfDeath)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if ((int)causeOfDeath != 9)
			{
				if ((int)causeOfDeath == 10)
				{
					return false;
				}
				return true;
			}
			return false;
		}

		public static bool IsPlayerInvincible(PlayerControllerB player)
		{
			return IsPlayerInvincible(((Object)player).GetInstanceID());
		}

		public static bool IsPlayerInvincible(int playerObjectId)
		{
			InvinciblePlayerIDs.TryGetValue(playerObjectId, out var value);
			if (!InvinciblePlayerIDs.ContainsKey(playerObjectId))
			{
				InvinciblePlayerIDs.Add(playerObjectId, value: false);
			}
			return value;
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool OnStart(ref PlayerControllerB __instance)
		{
			InvinciblePlayerIDs.Add(((Object)__instance).GetInstanceID(), value: false);
			return true;
		}
	}
	[HarmonyPatch(typeof(ShipLights))]
	public class ShipLightsPatch
	{
		[HarmonyPatch("ToggleShipLights")]
		[HarmonyPrefix]
		private static bool OnPowerSwitch(ref ShipLights __instance, object[] __args)
		{
			Plugin.Log.LogInfo((object)"The lights are now toggled!");
			return false;
		}
	}
}
namespace YourThunderstoreTeam.patch.Items
{
	public class CheezburgerItem : GrabbableObject
	{
		private const int RARITY = 80;

		private bool isActive = false;

		public AudioSource cheezburgerAudio;

		public AudioClip mmmCheezburgerSfx;

		public static void AddAsset(AssetBundle assetBundle)
		{
			Item val = assetBundle.LoadAsset<Item>("Cheezburger");
			Utilities.FixMixerGroups(val.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, 80, (LevelTypes)(-1));
			CheezburgerItem cheezburgerItem = val.spawnPrefab.AddComponent<CheezburgerItem>();
			((GrabbableObject)cheezburgerItem).grabbable = true;
			((GrabbableObject)cheezburgerItem).grabbableToEnemies = true;
			((GrabbableObject)cheezburgerItem).isInFactory = true;
			((GrabbableObject)cheezburgerItem).itemProperties = val;
			cheezburgerItem.cheezburgerAudio = val.spawnPrefab.GetComponent<AudioSource>();
			cheezburgerItem.mmmCheezburgerSfx = cheezburgerItem.cheezburgerAudio.clip;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && base.playerHeldBy != null && !isActive)
			{
				Vector3 positionOffset = base.itemProperties.positionOffset;
				Vector3 rotationOffset = base.itemProperties.rotationOffset;
				isActive = true;
				base.itemProperties.positionOffset = new Vector3(0.03f, -0.375f, -0.33f);
				base.itemProperties.rotationOffset = new Vector3(-90f, 9f, -90f);
				cheezburgerAudio.PlayOneShot(mmmCheezburgerSfx);
				ReturnToNormalOffsets(positionOffset, rotationOffset);
			}
		}

		private async void ReturnToNormalOffsets(Vector3 normalPos, Vector3 normalRot)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			await Task.Delay(1000);
			base.itemProperties.positionOffset = normalPos;
			base.itemProperties.rotationOffset = normalRot;
			isActive = false;
		}

		protected override void __initializeVariables()
		{
			((GrabbableObject)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "CheezburgerItem";
		}
	}
	public class HealthpackItem : GrabbableObject
	{
		private const int HEALTHPACK_PRICE = 60;

		private const string HEALTHPACK_DESC = "A first aid kit containing the standard combat wound treatment, which is used by all UNSC combat personnel, ranging from Marines to Spartans.\n\nEach health pack contains biofoam, a stitch kit, polypseudomorphine, a sterile field generator, self-adhering antiseptic battle dressings, and other useful components.\n\nUse when you receive and injury (critical or not).\n\n";

		public AudioSource healthpackAudio;

		public AudioClip healSfx;

		public static void AddAsset(AssetBundle assetBundle)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			Item val = assetBundle.LoadAsset<Item>("Healthpack");
			Utilities.FixMixerGroups(val.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterShopItem(val, (TerminalNode)null, (TerminalNode)null, new TerminalNode
			{
				displayText = "A first aid kit containing the standard combat wound treatment, which is used by all UNSC combat personnel, ranging from Marines to Spartans.\n\nEach health pack contains biofoam, a stitch kit, polypseudomorphine, a sterile field generator, self-adhering antiseptic battle dressings, and other useful components.\n\nUse when you receive and injury (critical or not).\n\n",
				clearPreviousText = true
			}, 60);
			HealthpackItem healthpackItem = val.spawnPrefab.AddComponent<HealthpackItem>();
			((GrabbableObject)healthpackItem).grabbable = true;
			((GrabbableObject)healthpackItem).isInFactory = true;
			((GrabbableObject)healthpackItem).grabbableToEnemies = true;
			((GrabbableObject)healthpackItem).itemProperties = val;
			healthpackItem.healthpackAudio = val.spawnPrefab.GetComponent<AudioSource>();
			healthpackItem.healSfx = healthpackItem.healthpackAudio.clip;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && base.playerHeldBy != null && base.playerHeldBy.health < 100)
			{
				healthpackAudio.PlayOneShot(healSfx);
				base.playerHeldBy.DamagePlayer(-100, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				if (base.playerHeldBy.criticallyInjured)
				{
					base.playerHeldBy.MakeCriticallyInjured(false);
				}
				base.itemUsedUp = true;
				((GrabbableObject)this).DestroyObjectInHand(base.playerHeldBy);
			}
		}

		protected override void __initializeVariables()
		{
			((GrabbableObject)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "HealthpackItem";
		}
	}
	public class RizzburgerItem : GrabbableObject
	{
		private const int RARITY = 30;

		private const float COOLDOWN = 10f;

		public AudioSource rizzburgerAudio;

		public AudioClip rizzSfx;

		public static void AddAsset(AssetBundle assetBundle)
		{
			Item val = assetBundle.LoadAsset<Item>("Rizzburger");
			Utilities.FixMixerGroups(val.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, 30, (LevelTypes)(-1));
			RizzburgerItem rizzburgerItem = val.spawnPrefab.AddComponent<RizzburgerItem>();
			((GrabbableObject)rizzburgerItem).grabbable = true;
			((GrabbableObject)rizzburgerItem).grabbableToEnemies = true;
			((GrabbableObject)rizzburgerItem).isInFactory = true;
			((GrabbableObject)rizzburgerItem).itemProperties = val;
			rizzburgerItem.rizzburgerAudio = val.spawnPrefab.GetComponent<AudioSource>();
			rizzburgerItem.rizzSfx = rizzburgerItem.rizzburgerAudio.clip;
			((GrabbableObject)rizzburgerItem).useCooldown = 10f;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && base.playerHeldBy != null)
			{
				rizzburgerAudio.PlayOneShot(rizzSfx);
			}
		}

		protected override void __initializeVariables()
		{
			((GrabbableObject)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "RizzburgerItem";
		}
	}
	public class SpeedCoilItem : GrabbableObject
	{
		private const int RARITY = 70;

		private const float SPEED_INCREASE = 3f;

		private bool isSpeedBoostActive = false;

		public static void AddAsset(AssetBundle assetBundle)
		{
			Item val = assetBundle.LoadAsset<Item>("Speed Coil");
			Utilities.FixMixerGroups(val.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, 70, (LevelTypes)(-1));
			SpeedCoilItem speedCoilItem = val.spawnPrefab.AddComponent<SpeedCoilItem>();
			((GrabbableObject)speedCoilItem).grabbable = true;
			((GrabbableObject)speedCoilItem).grabbableToEnemies = true;
			((GrabbableObject)speedCoilItem).isInFactory = true;
			((GrabbableObject)speedCoilItem).itemProperties = val;
		}

		public override void EquipItem()
		{
			((GrabbableObject)this).EquipItem();
			if (base.playerHeldBy != null && !isSpeedBoostActive)
			{
				PlayerControllerB playerHeldBy = base.playerHeldBy;
				playerHeldBy.movementSpeed += 3f;
				isSpeedBoostActive = true;
			}
		}

		public override void DestroyObjectInHand(PlayerControllerB playerHolding)
		{
			DisableSpeedBoost();
			((GrabbableObject)this).DestroyObjectInHand(playerHolding);
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			DisableSpeedBoost();
		}

		public override void DiscardItem()
		{
			DisableSpeedBoost();
			((GrabbableObject)this).DiscardItem();
		}

		private void DisableSpeedBoost()
		{
			if (isSpeedBoostActive && base.playerHeldBy != null)
			{
				PlayerControllerB playerHeldBy = base.playerHeldBy;
				playerHeldBy.movementSpeed -= 3f;
				isSpeedBoostActive = false;
			}
		}

		protected override void __initializeVariables()
		{
			((GrabbableObject)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "SpeedCoilItem";
		}
	}
}
namespace YourThunderstoreTeam.patch.enemies
{
	[HarmonyPatch(typeof(FlowermanAI))]
	public class FlowermanPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool OnKillPlayerAnimationServerRpc(ref FlowermanAI __instance)
		{
			PlayerControllerB targetPlayer = ((EnemyAI)__instance).targetPlayer;
			if (targetPlayer != null)
			{
				bool flag = PlayerControllerBPatch.IsPlayerInvincible(targetPlayer);
				return !flag;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ForestGiantAI))]
	public class ForestGiantPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool OnGrabPlayerServerRpc(ref ForestGiantAI __instance)
		{
			PlayerControllerB targetPlayer = ((EnemyAI)__instance).targetPlayer;
			if (targetPlayer != null)
			{
				bool flag = PlayerControllerBPatch.IsPlayerInvincible(targetPlayer);
				return !flag;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MaskedPlayerEnemy))]
	public class MaskedPlayerEnemyPatch
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool OnKillAnimation(ref MaskedPlayerEnemy __instance)
		{
			PlayerControllerB targetPlayer = ((EnemyAI)__instance).targetPlayer;
			if (targetPlayer != null)
			{
				bool flag = PlayerControllerBPatch.IsPlayerInvincible(targetPlayer);
				return !flag;
			}
			return true;
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static bool OnKillPlayerAnimationServerRpc(ref MaskedPlayerEnemy __instance)
		{
			PlayerControllerB targetPlayer = ((EnemyAI)__instance).targetPlayer;
			if (targetPlayer != null)
			{
				bool flag = PlayerControllerBPatch.IsPlayerInvincible(targetPlayer);
				return !flag;
			}
			Utilities.PrintToChat("Returned true");
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace DawnUltrasItems.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}