Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of LethalBattle v1.1.2
Lethal_Battle.dll
Decompiled 3 months agousing 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.Configuration; 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+3f1bc0cae385a9aa3784b14018a9d2130be40b0f")] [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 { internal class Config { public ConfigEntry<int> SingItemBattleRarity { get; private set; } public Config(ConfigFile configFile) { configFile.SaveOnConfigSet = false; SingItemBattleRarity = configFile.Bind<int>("Spawn Rates", "SingleItemBattleRarity", 10, "Rarity of the Single Item Battle (higher = more common)."); configFile.Save(); configFile.SaveOnConfigSet = true; } } [HarmonyPatch(typeof(HUDManager))] internal class DebugCommandsManager { } [HarmonyPatch(typeof(RoundManager))] internal class PatchRoundManager { [HarmonyPostfix] [HarmonyPatch("FinishGeneratingNewLevelClientRpc")] public static void Changes() { if (Plugin.hasBattleStarted || StartOfRound.Instance.livingPlayers <= 1 || TimeOfDay.Instance.daysUntilDeadline != 0 || TimeOfDay.Instance.currentLevel.planetHasTime || TimeOfDay.Instance.currentLevel.spawnEnemiesAndScrap) { return; } Plugin.log.LogInfo((object)"In a company 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.LogInfo((object)"No battle because you have the qota ! :3"); return; } Plugin.log.LogInfo((object)"Battle because ur too poor, the company want blood !"); 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) { ManageUI.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) { ManageUI.UIDelete(); Plugin.hasMessageWonShowed = false; Plugin.hasBattleStarted = false; } } } [BepInPlugin("POUY.LETHAL_BATTLE", "Lethal Battle", "1.0.1")] public class Plugin : BaseUnityPlugin { private const string GUID = "POUY.LETHAL_BATTLE"; private const string NAME = "Lethal Battle"; private const string VERSION = "1.0.1"; 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 int OneItemBattle; public static bool verifying; public void Awake() { instance = this; log = ((BaseUnityPlugin)this).Logger; Config config = new Config(((BaseUnityPlugin)this).Config); OneItemBattle = config.SingItemBattleRarity.Value; LoadUI(); log.LogMessage((object)"Lethal Battle Loaded !"); harmony.PatchAll(); } public void LoadUI() { try { 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.LogInfo((object)"UI loaded successfully"); } catch (Exception ex) { log.LogError((object)"UI ERROR"); log.LogError((object)ex); } } } } 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 async void ItemsSpawner() { ManageUI.UISpawn(); HUDManager.Instance.DisplayTip("The company demand blood", " Only one can live... may the game start", true, false, "LC_Tip1"); if (!((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost) { return; } Plugin.log.LogInfo((object)"getting all items... c:"); List<ManageJson> scraps = ManageScraps.GetFilteredWeightedItems(); int numberOfItems = 100; if (TimeOfDay.Instance.currentLevel.PlanetName.ToUpper() == "98 GALETRY") { numberOfItems = 200; } for (int i = 0; i < numberOfItems; i++) { Item item = ManageScraps.GetRandomItem(scraps); Vector3 spawnPosition = PositionManager(); if ((Object)(object)item != (Object)null && (Object)(object)item.spawnPrefab != (Object)null) { ManageScraps.SpawnScrap(item, spawnPosition); } } Plugin.log.LogInfo((object)"items spawned successfully !!! UwU"); } public 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; } public static List<Vector3> GordionNodesList() { //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) List<Vector3> list = new List<Vector3>(); list.Add(new Vector3(-19f, -2f, -23f)); list.Add(new Vector3(-21f, -2f, -13f)); list.Add(new Vector3(-5f, -2f, 0f)); list.Add(new Vector3(-13f, -2f, -17f)); list.Add(new Vector3(5f, -2f, 37f)); list.Add(new Vector3(-4f, -2f, -35f)); list.Add(new Vector3(5f, -2f, -57f)); list.Add(new Vector3(-20f, -2f, -65f)); list.Add(new Vector3(6f, -18f, -44f)); list.Add(new Vector3(19f, -27f, -18f)); list.Add(new Vector3(9f, -19f, -7f)); list.Add(new Vector3(19f, -26f, -35f)); list.Add(new Vector3(-26f, -2f, -31f)); return list; } public static Vector3 PositionManager() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) Vector3 val; if (TimeOfDay.Instance.currentLevel.PlanetName.ToUpper() == "71 GORDION") { List<Vector3> list = GordionNodesList(); val = list[Random.Range(0, list.Count)]; } else if (TimeOfDay.Instance.currentLevel.PlanetName.ToUpper() != "98 GALETRY") { val = RoundManager.Instance.outsideAINodes[Random.Range(0, RoundManager.Instance.outsideAINodes.Length)].transform.position; } else { List<Vector3> list2 = GalatryNodesList(); val = list2[Random.Range(0, list2.Count)]; } return RoundManager.Instance.GetRandomNavMeshPositionInRadius(val, 30f, default(NavMeshHit)); } public static async void MakeShipLeave(StartMatchLever shipLever) { if ((Object)(object)shipLever != (Object)null) { Plugin.log.LogInfo((object)"End of Battle, ship is living ! GG"); 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 ManageJson { public class ItemWeight { public string name { get; set; } public float value { get; set; } } public Item item; public float weight; public static bool battleJsonLoaded = false; public static List<ItemWeight> _reader { get; set; } public static List<ItemWeight> battleWithOneItem { get; set; } public static Dictionary<string, float> WeightsByName { get; set; } = new Dictionary<string, float>(); public ManageJson(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)("JSON not found : " + jsonPath)); return; } string text = File.ReadAllText(jsonPath); _reader = JsonConvert.DeserializeObject<List<ItemWeight>>(text); if (_reader == null || _reader.Count == 0) { Plugin.log.LogError((object)"JSON not valid"); return; } WeightsByName = _reader.ToDictionary((ItemWeight x) => x.name.Trim().ToUpper(), (ItemWeight x) => x.value); } catch (Exception ex) { Plugin.log.LogError((object)(ex?.ToString() ?? "")); } } public static void LoadBattleWithOneItemJson(string jsonPath) { try { if (!File.Exists(jsonPath)) { Plugin.log.LogError((object)("Battle JSON not found : " + jsonPath)); return; } string text = File.ReadAllText(jsonPath); battleWithOneItem = JsonConvert.DeserializeObject<List<ItemWeight>>(text); if (battleWithOneItem == null || battleWithOneItem.Count == 0) { Plugin.log.LogError((object)"Battle JSON invalid or empty"); battleWithOneItem = new List<ItemWeight>(); } else { battleJsonLoaded = true; Plugin.log.LogInfo((object)$"Loaded {battleWithOneItem.Count} battle items"); } } catch (Exception ex) { Plugin.log.LogError((object)(ex?.ToString() ?? "")); battleWithOneItem = new List<ItemWeight>(); } } public static float GetWeight(string itemName) { string key = itemName.Trim().ToUpper(); float value; return WeightsByName.TryGetValue(key, out value) ? value : 0f; } public static List<ManageJson> GetBattleItemsWeighted(List<Item> allItems) { string jsonPath = Path.Combine(Paths.PluginPath, "MikuT4T-LethalBattle/items.json"); string jsonPath2 = Path.Combine(Paths.PluginPath, "MikuT4T-LethalBattle/itemsForBattleWithOneItem.json"); LoadWeightsFromJson(jsonPath); if (!battleJsonLoaded) { LoadBattleWithOneItemJson(jsonPath2); } Random random = new Random(); int num = random.Next(0, 100); bool flag = num < Plugin.OneItemBattle; List<ManageJson> list = new List<ManageJson>(); if (!flag) { foreach (Item allItem in allItems) { float num2 = GetWeight(allItem.itemName); list.Add(new ManageJson(allItem, num2)); } return list; } if (battleWithOneItem == null || battleWithOneItem.Count == 0) { Plugin.log.LogError((object)"No battle items loaded"); return list; } float num3 = battleWithOneItem.Sum((ItemWeight i) => i.value); if (num3 <= 0f) { Plugin.log.LogError((object)"Battle total weight is zero"); return list; } float num4 = (float)(random.NextDouble() * (double)num3); float num5 = 0f; ItemWeight chosen = null; foreach (ItemWeight item in battleWithOneItem) { num5 += item.value; if (num4 <= num5) { chosen = item; break; } } if (chosen == null) { chosen = battleWithOneItem.Last(); } 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) { Plugin.log.LogError((object)("Item not found in game : " + chosen.name)); return list; } Plugin.log.LogInfo((object)("battle with " + chosen.name)); list.Add(new ManageJson(val, chosen.value)); return list; } } internal class ManageScraps { public static List<ManageJson> 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<ManageJson> list2 = new List<ManageJson>(); return ManageJson.GetBattleItemsWeighted(list); } public static Item GetRandomItem(List<ManageJson> weightedItems) { float num = weightedItems.Sum((ManageJson wi) => wi.weight); float num2 = Random.Range(0f, num); float num3 = 0f; foreach (ManageJson 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 ManageUI { 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); } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }