Decompiled source of LethalBattle v1.0.4

Lethal_Battle.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Lethal_Battle.NewFolder;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[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("Lethal_Battle")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d53ed931d8c6c2a2f91a6c09a5b25f800f86226b")]
[assembly: AssemblyProduct("Lethal_Battle")]
[assembly: AssemblyTitle("Lethal_Battle")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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 Lethal_Battle
{
	[HarmonyPatch(typeof(RoundManager))]
	internal class Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch("FinishGeneratingNewLevelClientRpc")]
		public static void Changes()
		{
			if (Plugin.hasBattleStarted || TimeOfDay.Instance.daysUntilDeadline != 0 || !(TimeOfDay.Instance.currentLevel.PlanetName == "71 Gordion"))
			{
				return;
			}
			Plugin.log.LogError((object)"In gordion for the last phase!");
			int num = 5 * (StartOfRound.Instance.allPlayerObjects.Length - 1);
			int num2 = Object.FindObjectsOfType<GrabbableObject>().Where(delegate(GrabbableObject o)
			{
				int result;
				if (o.itemProperties.isScrap && o.itemProperties.minValue > 0)
				{
					StunGrenadeItem val = (StunGrenadeItem)(object)((o is StunGrenadeItem) ? o : null);
					if (val == null || !val.hasExploded || !val.DestroyGrenade)
					{
						result = ((o.isInShipRoom && o.isInElevator) ? 1 : 0);
						goto IL_0049;
					}
				}
				result = 0;
				goto IL_0049;
				IL_0049:
				return (byte)result != 0;
			}).ToList()
				.Sum((GrabbableObject s) => s.scrapValue);
			if (num2 + num + TimeOfDay.Instance.quotaFulfilled >= TimeOfDay.Instance.profitQuota)
			{
				Plugin.log.LogError((object)"No battle !");
				return;
			}
			Plugin.log.LogError((object)"battle !");
			ManageBattle.ItemsSpawner();
			Plugin.hasBattleStarted = true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		public static void ChangesUI_death()
		{
			if (Plugin.hasBattleStarted)
			{
				StartMatchLever val = Object.FindObjectOfType<StartMatchLever>();
				val.triggerScript.interactable = false;
				if ((Object)(object)Plugin.instance.UI_players_alive_and_kills != (Object)null && !Plugin.hasMessageWonShowed)
				{
					UI.UpdateUI();
				}
				if (StartOfRound.Instance.livingPlayers == 1 && !Plugin.hasMessageWonShowed)
				{
					string playerUsername = ManageBattle.GetPlayers()[0].playerUsername;
					HUDManager.Instance.DisplayTip(playerUsername + " won !!!", "some loosers are here ...", true, false, "LC_Tip1");
					ManageBattle.MakeShipLeave(val);
					Plugin.hasMessageWonShowed = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class PatchStartOfRound
	{
		[HarmonyPrefix]
		[HarmonyPatch("EndOfGame")]
		public static void ChangesDeleteUI()
		{
			if (Plugin.hasBattleStarted && (Object)(object)Plugin.instance.UI_players_alive_and_kills != (Object)null)
			{
				UI.UIDelete();
				Plugin.hasMessageWonShowed = false;
				Plugin.hasBattleStarted = false;
			}
		}
	}
	[BepInPlugin("POUY.LETHAL_BATTLE", "Lethal Battle", "0.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "POUY.LETHAL_BATTLE";

		private const string NAME = "Lethal Battle";

		private const string VERSION = "0.0.3";

		public static Plugin instance;

		public static bool hasBattleStarted;

		public static ManualLogSource log;

		public static bool hasMessageWonShowed;

		public readonly Harmony harmony = new Harmony("POUY.LETHAL_BATTLE");

		public GameObject? UI_Lethal_Battle;

		public GameObject? UI_players_alive_and_kills;

		public int numberOfPlayers;

		public void Awake()
		{
			instance = this;
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "lethal_battle");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			string text2 = "Assets/Lethal_Battle/UI/Lethal_Battle_Death_UI.prefab";
			UI_Lethal_Battle = val.LoadAsset<GameObject>(text2);
			harmony.PatchAll();
			log = ((BaseUnityPlugin)this).Logger;
			log.LogMessage((object)"Lethal Battle Loaded !");
		}
	}
}
namespace Lethal_Battle.NewFolder
{
	internal class ManageBattle
	{
		public static void ItemsSpawner()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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)
			UI.UISpawn();
			HUDManager.Instance.DisplayTip("Time to kill !!!", " And die for some loosers...", true, false, "LC_Tip1");
			if (!((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
			{
				return;
			}
			Plugin.log.LogInfo((object)"LETHAL BATTLE : getting all items... c:");
			List<WeightedItem> filteredWeightedItems = ManageScraps.GetFilteredWeightedItems();
			for (int i = 0; i < 100; i++)
			{
				Item randomItem = ManageScraps.GetRandomItem(filteredWeightedItems);
				Vector3 position = PositionManager();
				if ((Object)(object)randomItem != (Object)null && (Object)(object)randomItem.spawnPrefab != (Object)null)
				{
					ManageScraps.SpawnScrap(randomItem, position);
				}
			}
			Plugin.log.LogInfo((object)"LETHAL BATTLE : items spawned successfully !!! UwU");
		}

		private static Vector3 PositionManager()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = RoundManager.Instance.outsideAINodes[Random.Range(0, RoundManager.Instance.outsideAINodes.Length)].transform.position;
			Vector3 val = position;
			position += new Vector3((float)Random.Range(-10, 10), 0f, (float)Random.Range(-10, 10));
			position = RoundManager.Instance.GetNavMeshPosition(position, default(NavMeshHit), 5f, -1);
			if (!RoundManager.Instance.GotNavMeshPositionResult)
			{
				position = val;
			}
			return position;
		}

		public static void MakeShipLeave(StartMatchLever shipLever)
		{
			if ((Object)(object)shipLever != (Object)null)
			{
				shipLever.triggerScript.animationString = "SA_PushLeverBack";
				shipLever.leverHasBeenPulled = false;
				shipLever.triggerScript.interactable = false;
				shipLever.leverAnimatorObject.SetBool("pullLever", false);
				StartOfRound.Instance.ShipLeave();
			}
		}

		public static List<PlayerControllerB> GetPlayers()
		{
			List<PlayerControllerB> list = StartOfRound.Instance.allPlayerScripts.ToList();
			List<PlayerControllerB> list2 = new List<PlayerControllerB>(list);
			foreach (PlayerControllerB item in list)
			{
				if (!((NetworkBehaviour)item).IsSpawned || !item.isPlayerControlled)
				{
					list2.Remove(item);
				}
			}
			return list2;
		}
	}
	internal class ManageScraps
	{
		public static List<WeightedItem> GetFilteredWeightedItems()
		{
			List<Item> list = new List<Item>();
			foreach (ShopItem shopItem in Items.shopItems)
			{
				list.Add(shopItem.item);
			}
			foreach (PlainItem plainItem in Items.plainItems)
			{
				list.Add(plainItem.item);
			}
			foreach (ScrapItem scrapItem in Items.scrapItems)
			{
				list.Add(scrapItem.item);
			}
			foreach (Item items in StartOfRound.Instance.allItemsList.itemsList)
			{
				list.Add(items);
			}
			List<WeightedItem> list2 = new List<WeightedItem>();
			return WeightedItem.GetBattleItemsWeighted(list);
		}

		public static Item GetRandomItem(List<WeightedItem> weightedItems)
		{
			float num = weightedItems.Sum((WeightedItem wi) => wi.weight);
			float num2 = Random.Range(0f, num);
			float num3 = 0f;
			foreach (WeightedItem weightedItem in weightedItems)
			{
				num3 += weightedItem.weight;
				if (num2 <= num3)
				{
					return weightedItem.item;
				}
			}
			return weightedItems[0].item;
		}

		public static void SpawnScrap(Item scrap, Vector3 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(scrap.spawnPrefab, position, Quaternion.identity, RoundManager.Instance.spawnedScrapContainer);
			GrabbableObject component = val.GetComponent<GrabbableObject>();
			((Component)component).transform.rotation = Quaternion.Euler(component.itemProperties.restingRotation);
			component.fallTime = 0f;
			component.scrapValue = 0;
			((NetworkBehaviour)component).NetworkObject.Spawn(false);
		}
	}
	internal class UI
	{
		public static void UISpawn()
		{
			if ((Object)(object)Plugin.instance.UI_Lethal_Battle != (Object)null)
			{
				Plugin.instance.numberOfPlayers = StartOfRound.Instance.livingPlayers;
				Plugin.instance.UI_players_alive_and_kills = Object.Instantiate<GameObject>(Plugin.instance.UI_Lethal_Battle);
			}
		}

		public static void UpdateUI()
		{
			if ((Object)(object)Plugin.instance.UI_players_alive_and_kills != (Object)null)
			{
				TMP_Text[] componentsInChildren = Plugin.instance.UI_players_alive_and_kills.GetComponentsInChildren<TMP_Text>();
				componentsInChildren[0].text = "/ " + (Plugin.instance.numberOfPlayers - 1);
				componentsInChildren[1].text = (Plugin.instance.numberOfPlayers - StartOfRound.Instance.livingPlayers).ToString() ?? "";
			}
		}

		public static void UIDelete()
		{
			if ((Object)(object)Plugin.instance.UI_players_alive_and_kills != (Object)null)
			{
				Object.Destroy((Object)(object)Plugin.instance.UI_players_alive_and_kills);
			}
		}
	}
	internal class WeightedItem
	{
		public Item item;

		public float weight;

		public static readonly Dictionary<string, float> WeightsByName = new Dictionary<string, float>
		{
			{ "YIELD SIGN", 50f },
			{ "STOP SIGN", 50f },
			{ "KITCHEN KNIFE", 10f },
			{ "STUN GRENADE", 5f },
			{ "SHOVEL", 50f },
			{ "DOUBLE-BARREL", 10f },
			{ "SHOTGUN", 10f },
			{ "TRAGEDY", 15f },
			{ "COMEDY", 15f },
			{ "COMICALLY LARGE SPOON", 30f },
			{ "AIRHORN", 30f },
			{ "FRIENDSHIP ENDER", 10f },
			{ "STICK", 20f },
			{ "GALVANIZED SQUARE STEEL", 10f },
			{ "BOMB", 30f },
			{ "CONTROLLER", 10f },
			{ "MAJORA'S MASK", 10f },
			{ "DEATH NOTE", 10f },
			{ "UNO REVERSE CARD", 10f },
			{ "MASTER SWORD", 30f },
			{ "OCARINA", 10f },
			{ "TOTEM OF UNDYING", 1f },
			{ "DANCE NOTE", 10f },
			{ "UNO REVERSE CARD DX", 10f },
			{ "BOOMBOX", 10f }
		};

		public WeightedItem(Item item, float weight)
		{
			this.item = item;
			this.weight = weight;
		}

		public static float GetWeight(string itemName)
		{
			string key = itemName.Trim().ToUpper();
			float value;
			return WeightsByName.TryGetValue(key, out value) ? value : 0f;
		}

		public static List<WeightedItem> GetBattleItemsWeighted(List<Item> allitems)
		{
			List<WeightedItem> list = new List<WeightedItem>();
			foreach (Item allitem in allitems)
			{
				Plugin.log.LogError((object)allitem.itemName.ToUpper());
				float num = GetWeight(allitem.itemName);
				list.Add(new WeightedItem(allitem, num));
			}
			return list;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}