Decompiled source of BattleLib v0.1.2

BattleLib.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("BattleLib")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Bopl Battle Library Mod")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyProduct("BattleLib")]
[assembly: AssemblyTitle("BattleLib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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 BattleLib
{
	public static class ConfigManager
	{
		public static ConfigEntry<bool> ExampleConfig { get; private set; }

		public static void Initialize(ConfigFile config)
		{
			ExampleConfig = config.Bind<bool>("General", "ExampleConfig", true, "This is an example config setting.");
		}
	}
	public static class Logger
	{
		private static ManualLogSource logSource;

		public static void Initialize(ManualLogSource source)
		{
			logSource = source;
		}

		public static void LogInfo(string message)
		{
			logSource.LogInfo((object)message);
		}

		public static void LogWarning(string message)
		{
			logSource.LogWarning((object)message);
		}

		public static void LogError(string message)
		{
			logSource.LogError((object)message);
		}
	}
	[BepInPlugin("com.Melon.BattleLib", "BattleLib", "1.0.0")]
	public class BattleLib : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("com.Melon.BattleLib");

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BattleLib is loaded!");
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
			harmony.PatchAll();
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BattleLib is unloaded!");
		}
	}
	public class BattleUtils
	{
		public static bool IsGameOver
		{
			get
			{
				FieldInfo field = typeof(GameSessionHandler).GetField("gameOver", BindingFlags.Instance | BindingFlags.NonPublic);
				return (bool)field.GetValue(GetGameSessionHandler());
			}
			set
			{
				FieldInfo field = typeof(GameSessionHandler).GetField("gameOver", BindingFlags.Instance | BindingFlags.NonPublic);
				field.SetValue(GetGameSessionHandler(), value);
			}
		}

		public static GameSessionHandler GetGameSessionHandler()
		{
			FieldInfo field = typeof(GameSessionHandler).GetField("selfRef", BindingFlags.Static | BindingFlags.NonPublic);
			object? value = field.GetValue(null);
			return (GameSessionHandler)((value is GameSessionHandler) ? value : null);
		}

		public static SlimeController[] GetSlimeControllers()
		{
			FieldInfo field = typeof(GameSessionHandler).GetField("slimeControllers", BindingFlags.Instance | BindingFlags.NonPublic);
			return field.GetValue(GetGameSessionHandler()) as SlimeController[];
		}

		public static void PrepareNextLevel()
		{
			MethodInfo method = typeof(GameSessionHandler).GetMethod("prepareNextlevel", BindingFlags.Instance | BindingFlags.NonPublic);
			method.Invoke(GetGameSessionHandler(), null);
		}

		public static Player GetPlayerFromPlayerBody(PlayerBody playerBody)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			FieldInfo field = typeof(PlayerBody).GetField("idHolder", BindingFlags.Instance | BindingFlags.NonPublic);
			IPlayerIdHolder val = (IPlayerIdHolder)field.GetValue(playerBody);
			return PlayerHandler.Get().GetPlayer(val.GetPlayerId());
		}

		public static PlayerPhysics GetPlayerPhysicsFromPlayerBody(PlayerBody playerBody)
		{
			FieldInfo field = typeof(PlayerBody).GetField("physics", BindingFlags.Instance | BindingFlags.NonPublic);
			object? value = field.GetValue(playerBody);
			return (PlayerPhysics)((value is PlayerPhysics) ? value : null);
		}

		public static bool IsGameSessionActive()
		{
			GameSessionHandler gameSessionHandler = GetGameSessionHandler();
			return (Object)(object)gameSessionHandler != (Object)null && !IsGameOver;
		}

		public static List<Player> GetAllPlayers()
		{
			GameSessionHandler gameSessionHandler = GetGameSessionHandler();
			if ((Object)(object)gameSessionHandler != (Object)null)
			{
				return PlayerHandler.Get().PlayerList();
			}
			return new List<Player>();
		}

		public static Player GetPlayerById(int playerId)
		{
			GameSessionHandler gameSessionHandler = GetGameSessionHandler();
			if ((Object)(object)gameSessionHandler != (Object)null)
			{
				return ((IEnumerable<Player>)PlayerHandler.Get().PlayerList()).FirstOrDefault((Func<Player, bool>)((Player p) => p.Id == playerId));
			}
			return null;
		}

		public static bool IsPlayerAlive(Player player)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			return player != null && (int)player.CauseOfDeath == 5;
		}

		public static void EndGameSession()
		{
			GameSessionHandler gameSessionHandler = GetGameSessionHandler();
			if ((Object)(object)gameSessionHandler != (Object)null)
			{
				IsGameOver = true;
			}
		}

		public static void RespawnAllPlayers()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			GameSessionHandler gameSessionHandler = GetGameSessionHandler();
			if (!((Object)(object)gameSessionHandler != (Object)null))
			{
				return;
			}
			foreach (Player item in PlayerHandler.Get().PlayerList())
			{
				item.Respawn(item.SpawnPosition);
			}
		}
	}
	public class AbilityUtils
	{
		public static void SetAbilityIcon(AbilitySelectCharacter abilitySelectCharacter, AbilityIndicator indicator, Sprite iconSprite)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			abilitySelectCharacter.SetAbility(indicator, iconSprite);
		}

		public static void ResetAbilityIcon(AbilitySelectCharacter abilitySelectCharacter, AbilityIndicator indicator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			abilitySelectCharacter.ResetAbility(indicator);
		}

		public static void ResetAllAbilities(AbilitySelectCharacter abilitySelectCharacter)
		{
			abilitySelectCharacter.ResetAbilites();
		}

		public static void SetMultipleAbilityIcons(AbilitySelectCharacter abilitySelectCharacter, Dictionary<AbilityIndicator, Sprite> icons)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<AbilityIndicator, Sprite> icon in icons)
			{
				abilitySelectCharacter.SetAbility(icon.Key, icon.Value);
			}
		}

		public static Sprite GetAbilityIcon(AbilitySelectCharacter abilitySelectCharacter, AbilityIndicator indicator)
		{
			//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_0017: Expected I4, but got Unknown
			return (Sprite)((int)indicator switch
			{
				0 => abilitySelectCharacter.IconX.sprite, 
				1 => abilitySelectCharacter.IconY.sprite, 
				2 => abilitySelectCharacter.IconZ.sprite, 
				_ => throw new ArgumentException("Invalid ability indicator"), 
			});
		}

		public static bool IsOnCooldown(Ability ability)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return ((AbilityMonoBehaviour)ability).GetCooldown() > Fix.Zero;
		}

		public static void StartCooldown(Ability ability, Fix cooldownDuration)
		{
			//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)
			ability.Cooldown = cooldownDuration;
		}

		public static void ReduceCooldown(Ability ability, Fix amount)
		{
			//IL_0003: 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_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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)
			ability.Cooldown = (Fix)(long)Math.Max((sbyte)(long)(((AbilityMonoBehaviour)ability).GetCooldown() - amount), (sbyte)(long)Fix.Zero);
		}

		public static void ResetCooldown(Ability ability)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			ability.Cooldown = Fix.Zero;
		}

		public static void LogEnterAbility(Ability ability)
		{
			Debug.Log((object)$"Entering ability for player {ability.GetPlayerId()} at {DateTime.Now}");
		}

		public static void LogExitAbility(Ability ability)
		{
			Debug.Log((object)$"Exiting ability for player {ability.GetPlayerId()} at {DateTime.Now}");
		}

		public static bool IsAbilityCastable(Ability ability, Player player)
		{
			return ((AbilityMonoBehaviour)ability).IsCastable(player) && !IsOnCooldown(ability);
		}

		public static void SetPlayerMaterial(Ability ability, Material material)
		{
			ability.GetPlayerMaterial().mainTexture = material.mainTexture;
		}

		public static bool DoesKillPlayersOnContact(Ability ability)
		{
			return ability.KillPlayersOnContact;
		}
	}
	public static class PlayerUtils
	{
		public static void AddAbility(this Player player, GameObject ability, Sprite abilityIcon = null)
		{
			if (player.Abilities == null)
			{
				player.Abilities = new List<GameObject>();
			}
			player.Abilities.Add(ability);
			if ((Object)(object)abilityIcon != (Object)null)
			{
				if (player.AbilityIcons == null)
				{
					player.AbilityIcons = new List<Sprite>();
				}
				player.AbilityIcons.Add(abilityIcon);
			}
		}

		public static void RemoveAbility(this Player player, GameObject ability)
		{
			if (player.Abilities != null && player.Abilities.Contains(ability))
			{
				int num = player.Abilities.IndexOf(ability);
				player.Abilities.RemoveAt(num);
				if (player.AbilityIcons != null && num < player.AbilityIcons.Count)
				{
					player.AbilityIcons.RemoveAt(num);
				}
			}
		}

		public static void Respawn(this Player player, Vec2 spawnPosition)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			player.Position = spawnPosition;
			player.playersAndClonesStillAlive = 1;
			player.WonThisRound = false;
			player.IsMostRecentWinner = false;
			player.CauseOfDeath = (CauseOfDeath)5;
		}

		public static void IncreaseScore(this Player player, int kills = 1)
		{
			player.Kills += kills;
		}

		public static void ResetPlayerState(this Player player)
		{
			player.KillsAtStartOfRound = player.Kills;
			player.Deaths = 0;
			player.WonThisRound = false;
			player.IsMostRecentWinner = false;
			player.playersAndClonesStillAlive = 0;
			player.CauseOfDeath = (CauseOfDeath)5;
			player.CurrentAbilities?.Clear();
			player.RespawnPositions?.Clear();
		}

		public static bool IsClone(this Player player)
		{
			return player.IsClone();
		}

		public static void SetPosition(this Player player, Vec2 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			player.Position = position;
		}

		public static bool IsWinning(this Player player)
		{
			return player.IsMostRecentWinner;
		}

		public static SteamId GetSteamId()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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)
			return SteamClient.SteamId;
		}
	}
	public static class MiscUtils
	{
		public static void ResetGameState()
		{
			//IL_0049: 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)
			GameSessionHandler.selfRef.gameOver = false;
			((Component)GameSessionHandler.selfRef.transitionFade).gameObject.SetActive(true);
			CircleBG.TimeSpentInMenus = 0f;
			foreach (Player item in PlayerHandler.Get().PlayerList())
			{
				item.Position = Vec2.zero;
				item.Scale = Fix.One;
			}
			SceneManager.LoadScene("MainMenu", (LoadSceneMode)0);
		}

		public static InputDevice GetInputDevice()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return InputSystem.devices[0];
		}

		public static bool UsesKeyboardAndMouse()
		{
			InputDevice inputDevice = GetInputDevice();
			return inputDevice is Keyboard || inputDevice is Mouse;
		}

		public static bool UsesController()
		{
			InputDevice inputDevice = GetInputDevice();
			return inputDevice is Gamepad || inputDevice is Joystick;
		}
	}
	public static class GameUtils
	{
		public static bool IsSuddenDeathActive()
		{
			return GameSessionHandler.SuddenDeathInProgress;
		}

		public static void ActivateSuddenDeath(bool activate)
		{
			GameSessionHandler.SuddenDeathInProgress = activate;
		}

		public static void PauseGame()
		{
			GameSessionHandler.GameIsPaused = true;
			InputUpdater.PauseAllRumble();
		}

		public static void ResumeGame()
		{
			GameSessionHandler.GameIsPaused = false;
		}

		public static bool HasGameEnded()
		{
			return (Object)(object)GameSessionHandler.selfRef != (Object)null && !GameSessionHandler.selfRef.gameInProgress;
		}

		public static void EndGameImmediately()
		{
			if ((Object)(object)GameSessionHandler.selfRef != (Object)null && GameSessionHandler.selfRef.gameInProgress)
			{
				GameSessionHandler.selfRef.DeclareGameUndecided(PlayerHandler.Get().PlayerList());
			}
		}
	}
	public static class CameraUtils
	{
		public static void SmoothMove(Transform transform, Vector3 targetPosition, float smoothTime)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			Vector3 zero = Vector3.zero;
			transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref zero, smoothTime);
		}

		public static Vector3 ClampPosition(Vector3 position, Vector2 minBounds, Vector2 maxBounds)
		{
			//IL_0003: 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_000f: 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)
			//IL_0027: 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_003d: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			position.x = Mathf.Clamp(position.x, minBounds.x, maxBounds.x);
			position.y = Mathf.Clamp(position.y, minBounds.y, maxBounds.y);
			return position;
		}

		public static float CalculateDistance(Vector3 fromPosition, Vector3 toPosition)
		{
			//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)
			return Vector3.Distance(fromPosition, toPosition);
		}

		public static float RoundToNearestPixel(float unityUnits, float pixelToUnits)
		{
			return Mathf.Round(unityUnits * pixelToUnits) * (1f / pixelToUnits);
		}

		public static void SmoothZoom(Camera camera, float targetSize, float smoothTime, float minSize, float maxSize)
		{
			camera.orthographicSize = Mathf.Clamp(Mathf.Lerp(camera.orthographicSize, targetSize, smoothTime * Time.deltaTime), minSize, maxSize);
		}

		public static Vector3 GetAveragePosition(List<Vector3> positions)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_002d: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			if (positions.Count == 0)
			{
				return Vector3.zero;
			}
			Vector3 val = Vector3.zero;
			foreach (Vector3 position in positions)
			{
				val += position;
			}
			return val / (float)positions.Count;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BattleLib";

		public const string PLUGIN_NAME = "BattleLib";

		public const string PLUGIN_VERSION = "0.1.1";
	}
}