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 Newtonsoft.Json;
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: AssemblyCompany("Lethal_Battle")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[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.planetHasTime || TimeOfDay.Instance.currentLevel.spawnEnemiesAndScrap)
{
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(HUDManager))]
internal class DebugCommandsManager
{
}
[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.6")]
public class Plugin : BaseUnityPlugin
{
private const string GUID = "POUY.LETHAL_BATTLE";
private const string NAME = "Lethal Battle";
private const string VERSION = "0.0.6";
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 static bool verifying;
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);
log = ((BaseUnityPlugin)this).Logger;
log.LogMessage((object)"Lethal Battle Loaded !");
harmony.PatchAll();
}
}
}
namespace Lethal_Battle.codes
{
internal class ManageChat
{
public static void SendChatMessage(string message)
{
}
public static void ConfirmRestart()
{
Plugin.verifying = true;
SendChatMessage("Are you sure? Type CONFIRM or DENY.");
}
public static void AcceptRestart(StartOfRound manager)
{
SendChatMessage("Battle confirmed.");
Plugin.verifying = false;
}
public static void DeclineRestart()
{
SendChatMessage("Battle aborted.");
Plugin.verifying = false;
}
}
}
namespace Lethal_Battle.NewFolder
{
internal class ManageBattle
{
public static void ItemsSpawner()
{
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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();
int num = 100;
if (TimeOfDay.Instance.currentLevel.PlanetName.ToUpper() == "98 GALETRY")
{
num = 200;
}
for (int i = 0; i < num; 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 List<Vector3> GalatryNodesList()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Unknown result type (might be due to invalid IL or missing references)
List<Vector3> list = new List<Vector3>();
list.Add(new Vector3(-74f, 21f, -16f));
list.Add(new Vector3(-129f, 1f, -15f));
list.Add(new Vector3(-194f, 1f, -27f));
list.Add(new Vector3(-70f, 1f, 17f));
list.Add(new Vector3(-70f, 1f, 17f));
list.Add(new Vector3(-70f, 1f, 17f));
list.Add(new Vector3(-70f, 1f, 17f));
list.Add(new Vector3(-70f, 1f, 17f));
list.Add(new Vector3(-36f, 1f, -14f));
list.Add(new Vector3(-2f, -2f, 20f));
list.Add(new Vector3(-2f, 1f, 47f));
list.Add(new Vector3(-2f, -1f, -1f));
list.Add(new Vector3(56f, -1f, 13f));
list.Add(new Vector3(-27f, 1f, 11f));
list.Add(new Vector3(23f, 1f, -26f));
list.Add(new Vector3(-8f, -2f, -27f));
list.Add(new Vector3(-104f, 11f, -16f));
list.Add(new Vector3(-51f, 20f, -13f));
list.Add(new Vector3(-31f, 11f, -2f));
list.Add(new Vector3(-31f, 11f, -26f));
list.Add(new Vector3(46f, -1f, -8f));
list.Add(new Vector3(-66f, 1f, -44f));
return list;
}
private static Vector3 PositionManager()
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: 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_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_0083: 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_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
Vector3 val;
if (TimeOfDay.Instance.currentLevel.PlanetName.ToUpper() != "98 GALETRY")
{
val = RoundManager.Instance.outsideAINodes[Random.Range(0, RoundManager.Instance.outsideAINodes.Length)].transform.position;
}
else
{
List<Vector3> list = GalatryNodesList();
val = list[Random.Range(0, list.Count)];
}
return RoundManager.Instance.GetRandomNavMeshPositionInRadius(val, 20f, default(NavMeshHit));
}
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.ShipLeaveAutomatically(false);
}
}
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)
{
if (shopItem != null)
{
list.Add(shopItem.item);
}
}
foreach (PlainItem plainItem in Items.plainItems)
{
if (plainItem != null)
{
list.Add(plainItem.item);
}
}
foreach (ScrapItem scrapItem in Items.scrapItems)
{
if (scrapItem != null)
{
list.Add(scrapItem.item);
}
}
foreach (Item items in StartOfRound.Instance.allItemsList.itemsList)
{
if ((Object)(object)items != (Object)null)
{
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 class ItemWeight
{
public string name { get; set; }
public float value { get; set; }
}
public Item item;
public float weight;
public static List<ItemWeight> _reader { get; set; }
public static int battleWithOneItemProba { get; set; } = 0;
public static List<ItemWeight> battleWithOneItem { get; set; }
public static Dictionary<string, float> WeightsByName { get; private set; } = new Dictionary<string, float>();
public WeightedItem(Item item, float weight)
{
this.item = item;
this.weight = weight;
}
public static void LoadWeightsFromJson(string jsonPath)
{
try
{
if (!File.Exists(jsonPath))
{
Plugin.log.LogError((object)("LETHAL BATTLE : JSON not found : " + jsonPath));
return;
}
string text = File.ReadAllText(jsonPath);
_reader = JsonConvert.DeserializeObject<List<ItemWeight>>(text);
if (_reader == null)
{
Plugin.log.LogError((object)"LETHAL BATTLE : JSON not valide");
return;
}
WeightsByName = _reader.ToDictionary((ItemWeight x) => x.name.Trim().ToUpper(), (ItemWeight x) => x.value);
}
catch (Exception ex)
{
Plugin.log.LogError((object)("LETHAL BATTLE : " + ex.Message));
}
}
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)
{
string jsonPath = Path.Combine(Paths.PluginPath, "MikuT4T-LethalBattle/items.json");
LoadWeightsFromJson(jsonPath);
if (_reader == null)
{
Plugin.log.LogError((object)"LETHAL BATTLE : can't load JSON data !");
return new List<WeightedItem>();
}
Random random = new Random();
int num = random.Next(0, 100);
bool flag = num <= battleWithOneItemProba;
List<WeightedItem> list = new List<WeightedItem>();
if (!flag)
{
WeightsByName = _reader.ToDictionary((ItemWeight x) => x.name.Trim().ToUpper(), (ItemWeight x) => x.value);
foreach (Item allItem in allItems)
{
float num2 = GetWeight(allItem.itemName);
list.Add(new WeightedItem(allItem, num2));
}
}
else
{
Plugin.log.LogError((object)"LETHAL BATTLE : battle with one item !");
List<ItemWeight> list2 = battleWithOneItem;
if (list2 == null || list2.Count == 0)
{
return GetBattleItemsWeighted(allItems);
}
float num3 = list2.Sum((ItemWeight i) => i.value);
float num4 = (float)(random.NextDouble() * (double)num3);
ItemWeight chosen = null;
float num5 = 0f;
foreach (ItemWeight item in list2)
{
num5 += item.value;
if (num4 <= num5)
{
chosen = item;
break;
}
}
if (chosen == null)
{
chosen = list2.Last();
}
Plugin.log.LogError((object)("LETHAL BATTLE : battle with " + chosen.name + " !"));
Item val = ((IEnumerable<Item>)allItems).FirstOrDefault((Func<Item, bool>)((Item it) => it.itemName.Trim().ToUpper() == chosen.name.Trim().ToUpper()));
if ((Object)(object)val != (Object)null)
{
list.Add(new WeightedItem(val, chosen.value));
}
else
{
Plugin.log.LogError((object)("LETHAL BATTLE : can't find " + chosen.name + " !"));
}
}
return list;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}