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 Lethal_Battle.codes;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
[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+726c6fc3efd23e53ab847a3d5f7e4bc1dc112585")]
[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), "SubmitChat_performed")]
[HarmonyPrefix]
public static bool Prefix(HUDManager __instance, CallbackContext context)
{
if (!((CallbackContext)(ref context)).performed)
{
return true;
}
string text = __instance.chatTextField.text;
if (string.IsNullOrEmpty(text))
{
return true;
}
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if ((Object)(object)localPlayerController == (Object)null)
{
return true;
}
StartOfRound playersManager = localPlayerController.playersManager;
if ((Object)(object)playersManager == (Object)null)
{
return true;
}
if (Plugin.verifying)
{
if (text.Equals("CONFIRM", StringComparison.OrdinalIgnoreCase))
{
ResetTextbox(__instance, localPlayerController);
ManageChat.AcceptRestart(playersManager);
ManageBattle.ItemsSpawner();
Plugin.hasBattleStarted = true;
return false;
}
if (text.Equals("DENY", StringComparison.OrdinalIgnoreCase))
{
ResetTextbox(__instance, localPlayerController);
ManageChat.DeclineRestart();
return false;
}
}
if (text.Equals("/battle", StringComparison.OrdinalIgnoreCase))
{
ResetTextbox(__instance, localPlayerController);
if (!GameNetworkManager.Instance.isHostingGame)
{
ManageChat.SendChatMessage("Only the host can start a battle.");
return false;
}
if (TimeOfDay.Instance.currentLevel.planetHasTime || TimeOfDay.Instance.currentLevel.spawnEnemiesAndScrap)
{
ManageChat.SendChatMessage("Must be in a company battle.");
return false;
}
if (Plugin.hasBattleStarted)
{
ManageChat.SendChatMessage("Must not be in a battle.");
return false;
}
ManageChat.ConfirmRestart();
return false;
}
return true;
}
private static void ResetTextbox(HUDManager manager, PlayerControllerB local)
{
local.isTypingChat = false;
manager.chatTextField.text = "";
EventSystem.current.SetSelectedGameObject((GameObject)null);
manager.PingHUDElement(manager.Chat, 2f, 1f, 0.2f);
((Behaviour)manager.typingIndicator).enabled = false;
}
}
[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)
{
HUDManager.Instance.AddChatMessage(message, "", -1, false);
}
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.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
{
private class ItemWeight
{
public string name { get; set; }
public float value { get; set; }
}
public Item item;
public float weight;
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)("Fichier JSON introuvable : " + jsonPath));
return;
}
string text = File.ReadAllText(jsonPath);
List<ItemWeight> list = JsonConvert.DeserializeObject<List<ItemWeight>>(text);
if (list == null || list.Count == 0)
{
Plugin.log.LogError((object)"Aucun item trouvé dans le JSON !");
return;
}
WeightsByName = list.ToDictionary((ItemWeight x) => x.name.Trim().ToUpper(), (ItemWeight x) => x.value);
Plugin.log.LogInfo((object)(WeightsByName.Count + " items chargés depuis " + jsonPath));
}
catch (Exception ex)
{
Plugin.log.LogError((object)("Erreur lors du chargement du JSON : " + 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, "Lethal_Battle/items.json");
LoadWeightsFromJson(jsonPath);
List<WeightedItem> list = new List<WeightedItem>();
foreach (Item allitem in allitems)
{
Plugin.log.LogInfo((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)
{
}
}
}