Decompiled source of Baller v2.1.0

plugins/Baller/Baller.dll

Decompiled 2 months 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.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using GameplayEntities;
using LLBML.States;
using LLBML.Texture;
using LLBML.Utils;
using LLHandlers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d4aec4ca-82b0-4143-8c0a-114b543a4ef1")]
[assembly: AssemblyTitle("Baller (no.mrgentle.plugins.llb.baller)")]
[assembly: AssemblyProduct("Baller")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.0.0")]
[module: UnverifiableCode]
namespace Baller;

[BepInPlugin("no.mrgentle.plugins.llb.baller", "Baller", "2.1.0")]
[BepInProcess("LLBlaze.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Baller : BaseUnityPlugin
{
	public class Ball
	{
		public BallType type;

		public string identifier;

		public DirectoryInfo ballResourcesFolder;

		public Mesh mesh;

		public Texture2D tex;

		public Ball(BallType _type, string _identifier = "")
		{
			//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)
			identifier = _identifier;
			ballResourcesFolder = Directory.CreateDirectory(Path.Combine(ResourceFolder.FullName, _identifier));
			type = _type;
		}
	}

	public static Baller Instance;

	public static DirectoryInfo ResourceFolder;

	private Shader transparentShader;

	private ConfigEntry<bool> regularBallFallback;

	public Ball[] balls = new Ball[10];

	private void Awake()
	{
		Instance = this;
		ResourceFolder = ModdingFolder.GetModSubFolder(((BaseUnityPlugin)this).Info);
		regularBallFallback = ((BaseUnityPlugin)this).Config.Bind<bool>("Toggles", "RegularBallFallback", true, (ConfigDescription)null);
	}

	private void Start()
	{
		ModDependenciesUtils.RegisterToModMenu(((BaseUnityPlugin)this).Info, (List<string>)null);
		balls[0] = new Ball((BallType)0, "regular");
		balls[1] = new Ball((BallType)3, "gravity");
		balls[2] = new Ball((BallType)2, "big");
		balls[3] = new Ball((BallType)1, "beach");
		balls[4] = new Ball((BallType)0, "candy/regular");
		balls[5] = new Ball((BallType)0, "candy/strait");
		balls[6] = new Ball((BallType)0, "candy/saturn");
		balls[7] = new Ball((BallType)0, "nitro/regular");
		balls[8] = new Ball((BallType)0, "nitro/detective");
		balls[9] = new Ball((BallType)0, "nitro/lucha");
		Ball[] array = balls;
		foreach (Ball obj in array)
		{
			FileInfo fileInfo = obj.ballResourcesFolder.GetFiles().FirstOrDefault((FileInfo file) => file.Extension.ToLower() == ".obj");
			obj.mesh = ((fileInfo != null) ? FastObjImporter.Instance.ImportFile(fileInfo.FullName) : null);
			FileInfo fileInfo2 = (from file in obj.ballResourcesFolder.GetFiles()
				where file.Extension.ToLower() == ".png" || file.Extension.ToLower() == ".dds"
				select file into _
				orderby Random.value
				select _).FirstOrDefault();
			obj.tex = ((fileInfo2 != null) ? TextureUtils.LoadTexture(fileInfo2) : null);
		}
	}

	private void Update()
	{
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)transparentShader))
		{
			transparentShader = BundledAssetLoader.GetShader(ShaderType.Transparent);
		}
		if (!GameStates.IsInMatch())
		{
			return;
		}
		BallHandler instance = BallHandler.instance;
		BallEntity val = ((instance != null) ? instance.GetBall(0) : null);
		if (val == null)
		{
			return;
		}
		object obj;
		if (val == null)
		{
			obj = null;
		}
		else
		{
			GameObject gameObject = ((Component)val).gameObject;
			obj = ((gameObject != null) ? gameObject.GetComponentsInChildren<SkinnedMeshRenderer>() : null);
		}
		SkinnedMeshRenderer[] array = (SkinnedMeshRenderer[])obj;
		foreach (SkinnedMeshRenderer smr in array)
		{
			Ball[] array2 = balls;
			foreach (Ball ball in array2)
			{
				string[] array3 = ball.identifier.Split(new char[1] { '/' });
				switch (array3[0])
				{
				case "regular":
				case "gravity":
				case "big":
				case "beach":
					if (((HitableEntity)val).ballType == ball.type)
					{
						ApplyNormal(smr, ball);
					}
					break;
				case "candy":
					ApplyCandy(smr, ball, array3[1]);
					break;
				case "nitro":
					ApplyNitro(smr, ball, array3[1]);
					break;
				}
			}
		}
	}

	public void ApplyNormal(SkinnedMeshRenderer smr, Ball ball)
	{
		string text = ((Object)((Component)smr).transform.parent).name.ToLower();
		if (text.Contains("candy") || text.Contains("cuff"))
		{
			return;
		}
		Texture2D val = ((regularBallFallback.Value && ball.tex == null) ? balls[0].tex : ball.tex);
		Mesh val2 = ((regularBallFallback.Value && ball.mesh == null) ? balls[0].mesh : ball.mesh);
		if ((Object)(object)val != (Object)null && (((Object)smr).name == "ballMesh_MainRenderer" || ((Object)smr).name == "ballMesh002_MainRenderer"))
		{
			ApplyTexture(smr, val);
		}
		if ((Object)(object)val2 != (Object)null)
		{
			if (((Object)smr).name == "ballMesh_MainRenderer" || ((Object)smr).name == "ballMesh002_MainRenderer" || ((Object)smr).name.ToLower().Contains("outline"))
			{
				smr.sharedMesh = val2;
			}
			else
			{
				smr.sharedMesh = null;
			}
		}
	}

	public void ApplyCandy(SkinnedMeshRenderer smr, Ball ball, string type)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)ball.tex != (Object)null && !((Object)smr).name.Contains("Outline"))
		{
			((Renderer)smr).material.SetColor("_LitColor", Color.white);
		}
		switch (type)
		{
		case "strait":
			if (((Object)smr).name.Contains("Strait"))
			{
				if ((Object)(object)ball.tex != (Object)null && !((Object)smr).name.Contains("Outline"))
				{
					ApplyTexture(smr, ball.tex);
				}
				if ((Object)(object)ball.mesh != (Object)null)
				{
					smr.sharedMesh = ball.mesh;
				}
			}
			break;
		case "saturn":
			if (((Object)smr).name.Contains("Saturn"))
			{
				if ((Object)(object)ball.tex != (Object)null && !((Object)smr).name.Contains("Outline"))
				{
					ApplyTexture(smr, ball.tex);
				}
				if ((Object)(object)ball.mesh != (Object)null)
				{
					smr.sharedMesh = ball.mesh;
				}
			}
			break;
		case "regular":
			if (((Object)smr).name.Contains("mesh001") && !((Object)smr).name.Contains("Strait") && !((Object)smr).name.Contains("Saturn"))
			{
				if ((Object)(object)ball.tex != (Object)null && !((Object)smr).name.Contains("Outline"))
				{
					ApplyTexture(smr, ball.tex);
				}
				if ((Object)(object)ball.mesh != (Object)null)
				{
					smr.sharedMesh = ball.mesh;
				}
			}
			break;
		}
	}

	public void ApplyNitro(SkinnedMeshRenderer smr, Ball ball, string type)
	{
		switch (type)
		{
		case "detective":
			if (((Object)smr).name.Contains("Detective"))
			{
				if ((Object)(object)ball.tex != (Object)null && !((Object)smr).name.Contains("Outline"))
				{
					ApplyTexture(smr, ball.tex);
				}
				if ((Object)(object)ball.mesh != (Object)null)
				{
					smr.sharedMesh = ball.mesh;
				}
			}
			break;
		case "lucha":
			if (((Object)smr).name.Contains("Lucha"))
			{
				if ((Object)(object)ball.tex != (Object)null && !((Object)smr).name.Contains("Outline"))
				{
					ApplyTexture(smr, ball.tex);
				}
				if ((Object)(object)ball.mesh != (Object)null)
				{
					smr.sharedMesh = ball.mesh;
				}
			}
			break;
		case "regular":
			if (((Object)smr).name.Contains("cuff") && !((Object)smr).name.Contains("Detective") && !((Object)smr).name.Contains("Luchador"))
			{
				if ((Object)(object)ball.tex != (Object)null && !((Object)smr).name.Contains("Outline"))
				{
					ApplyTexture(smr, ball.tex);
				}
				if ((Object)(object)ball.mesh != (Object)null)
				{
					smr.sharedMesh = ball.mesh;
				}
			}
			break;
		}
	}

	private void ApplyTexture(SkinnedMeshRenderer _smr, Texture2D _tex)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		((Renderer)_smr).material.SetColor("_LitColor", Color.white);
		((Renderer)_smr).material.mainTexture = (Texture)(object)_tex;
		ApplyTransparencyToMat(((Renderer)_smr).material);
	}

	private void ApplyTransparencyToMat(Material _mat)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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)
		Color pixel = ((Texture2D)_mat.mainTexture).GetPixel(0, 0);
		if (Object.op_Implicit((Object)(object)transparentShader))
		{
			_mat.shader = transparentShader;
			_mat.SetColor("_ShadowColor", new Color(0.5f, 0.5f, 0.5f, 1f));
			_mat.SetFloat("_RefractionFresnelStrength", pixel.r);
			_mat.SetFloat("_RefractionFresnelExponent", pixel.g);
			_mat.SetFloat("_Transparency", 1f - pixel.a);
		}
	}
}
public static class BundledAssetLoader
{
	public static Object GetAsset(string _bundleName, string _assetName)
	{
		AssetBundle[] array = AssetBundle.GetAllLoadedAssetBundles().ToArray();
		foreach (AssetBundle val in array)
		{
			if (((Object)val).name == _bundleName)
			{
				return val.LoadAsset(_assetName);
			}
		}
		Debug.Log((object)("Could not find " + _assetName + " in bundle " + _bundleName));
		return null;
	}

	public static Object[] GetAssetWithSubAssets(string _bundleName, string _assetName)
	{
		AssetBundle[] array = AssetBundle.GetAllLoadedAssetBundles().ToArray();
		foreach (AssetBundle val in array)
		{
			if (((Object)val).name == _bundleName)
			{
				return val.LoadAssetWithSubAssets(_assetName);
			}
		}
		Debug.Log((object)("Could not find " + _assetName + " in bundle " + _bundleName));
		return null;
	}

	public static Shader GetShader(ShaderType _shaderType)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		AssetBundle[] array = AssetBundle.GetAllLoadedAssetBundles().ToArray();
		switch (_shaderType)
		{
		case ShaderType.Standard:
			return Shader.Find("Standard");
		case ShaderType.Opaque:
		{
			AssetBundle[] array2 = array;
			foreach (AssetBundle val5 in array2)
			{
				if (((Object)val5).name == "characters/boss")
				{
					return ((Material)val5.LoadAsset("bossmat")).shader;
				}
			}
			break;
		}
		case ShaderType.Transparent:
		{
			AssetBundle[] array2 = array;
			foreach (AssetBundle val2 in array2)
			{
				if (((Object)val2).name == "characters/boss")
				{
					return ((Material)val2.LoadAsset("bossomegaglassmat")).shader;
				}
			}
			break;
		}
		case ShaderType.TransparentSwitch:
		{
			AssetBundle[] array2 = array;
			foreach (AssetBundle val4 in array2)
			{
				if (((Object)val4).name == "characters/boss")
				{
					return ((Material)val4.LoadAsset("bossOmegaGlassSwitchMat")).shader;
				}
			}
			break;
		}
		case ShaderType.NoiseClone:
		{
			AssetBundle[] array2 = array;
			foreach (AssetBundle val3 in array2)
			{
				if (((Object)val3).name == "characters/bag")
				{
					return ((Material)val3.LoadAsset("ScreenSpaceNoiseOverlayMat")).shader;
				}
			}
			break;
		}
		case ShaderType.Visualizer:
		{
			AssetBundle[] array2 = array;
			foreach (AssetBundle val in array2)
			{
				if (((Object)val).name == "characters/boss")
				{
					return ((Material)val.LoadAsset("bossvisualizereffectmat")).shader;
				}
			}
			break;
		}
		}
		return null;
	}

	public static void LogAllAssetsInBundle(string _bundleName)
	{
		AssetBundle[] array = AssetBundle.GetAllLoadedAssetBundles().ToArray();
		foreach (AssetBundle val in array)
		{
			if (((Object)val).name == _bundleName)
			{
				string[] allAssetNames = val.GetAllAssetNames();
				Debug.Log((object)("Assets in [" + _bundleName + "] = " + string.Join("," + Environment.NewLine, allAssetNames)));
			}
		}
	}

	public static void LogAllBundles()
	{
		AssetBundle[] array = AssetBundle.GetAllLoadedAssetBundles().ToArray();
		string text = "All loaded AssetBundles: ";
		AssetBundle[] array2 = array;
		foreach (AssetBundle val in array2)
		{
			text = text + ((Object)val).name + "," + Environment.NewLine;
		}
		Debug.Log((object)text);
	}
}
public enum ShaderType
{
	Standard,
	Opaque,
	Transparent,
	TransparentSwitch,
	NoiseClone,
	Visualizer
}
public sealed class FastObjImporter
{
	private static FastObjImporter _instance;

	private List<int> triangles;

	private List<Vector3> vertices;

	private List<Vector2> uv;

	private List<Vector3> normals;

	private List<Vector3Int> faceData;

	private List<int> intArray;

	private const int MIN_POW_10 = -16;

	private const int MAX_POW_10 = 16;

	private const int NUM_POWS_10 = 33;

	private static readonly float[] pow10 = GenerateLookupTable();

	public static FastObjImporter Instance => _instance ?? (_instance = new FastObjImporter());

	public Mesh ImportFile(string filePath)
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Expected O, but got Unknown
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		triangles = new List<int>();
		vertices = new List<Vector3>();
		uv = new List<Vector2>();
		normals = new List<Vector3>();
		faceData = new List<Vector3Int>();
		intArray = new List<int>();
		LoadMeshData(filePath);
		Vector3[] array = (Vector3[])(object)new Vector3[faceData.Count];
		Vector2[] array2 = (Vector2[])(object)new Vector2[faceData.Count];
		Vector3[] array3 = (Vector3[])(object)new Vector3[faceData.Count];
		for (int i = 0; i < faceData.Count; i++)
		{
			array[i] = vertices[faceData[i].x - 1];
			if (faceData[i].y >= 1 && faceData[i].y - 1 < uv.Count - 1)
			{
				array2[i] = uv[faceData[i].y - 1];
			}
			if (faceData[i].z >= 1)
			{
				array3[i] = normals[faceData[i].z - 1];
			}
		}
		Mesh val = new Mesh
		{
			vertices = array,
			uv = array2,
			normals = array3,
			triangles = triangles.ToArray()
		};
		val.RecalculateBounds();
		return val;
	}

	private void LoadMeshData(string fileName)
	{
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder();
		string text = File.ReadAllText(fileName);
		int num = 0;
		string text2 = null;
		int num2 = 0;
		StringBuilder sbFloat = new StringBuilder();
		for (int i = 0; i < text.Length; i++)
		{
			if (text[i] != '\n')
			{
				continue;
			}
			stringBuilder.Remove(0, stringBuilder.Length);
			stringBuilder.Append(text, num + 1, i - num);
			num = i;
			if (stringBuilder[0] == 'o' && stringBuilder[1] == ' ')
			{
				sbFloat.Remove(0, sbFloat.Length);
				for (int j = 2; j < stringBuilder.Length; j++)
				{
					text2 += stringBuilder[j];
				}
			}
			else if (stringBuilder[0] == 'v' && stringBuilder[1] == ' ')
			{
				int start = 2;
				vertices.Add(new Vector3(GetFloat(stringBuilder, ref start, ref sbFloat), GetFloat(stringBuilder, ref start, ref sbFloat), GetFloat(stringBuilder, ref start, ref sbFloat)));
			}
			else if (stringBuilder[0] == 'v' && stringBuilder[1] == 't' && stringBuilder[2] == ' ')
			{
				int start2 = 3;
				uv.Add(new Vector2(GetFloat(stringBuilder, ref start2, ref sbFloat), GetFloat(stringBuilder, ref start2, ref sbFloat)));
			}
			else if (stringBuilder[0] == 'v' && stringBuilder[1] == 'n' && stringBuilder[2] == ' ')
			{
				int start3 = 3;
				normals.Add(new Vector3(GetFloat(stringBuilder, ref start3, ref sbFloat), GetFloat(stringBuilder, ref start3, ref sbFloat), GetFloat(stringBuilder, ref start3, ref sbFloat)));
			}
			else if (stringBuilder[0] == 'f' && stringBuilder[1] == ' ')
			{
				int start4 = 2;
				int num3 = 1;
				intArray.Clear();
				int num4 = 0;
				while (start4 < stringBuilder.Length && char.IsDigit(stringBuilder[start4]))
				{
					faceData.Add(new Vector3Int(GetInt(stringBuilder, ref start4, ref sbFloat), GetInt(stringBuilder, ref start4, ref sbFloat), GetInt(stringBuilder, ref start4, ref sbFloat)));
					num3++;
					intArray.Add(num2);
					num2++;
				}
				num4 += num3;
				for (num3 = 1; num3 + 2 < num4; num3++)
				{
					triangles.Add(intArray[0]);
					triangles.Add(intArray[num3]);
					triangles.Add(intArray[num3 + 1]);
				}
			}
		}
	}

	private float GetFloat(StringBuilder sb, ref int start, ref StringBuilder sbFloat)
	{
		sbFloat.Remove(0, sbFloat.Length);
		while (start < sb.Length && (char.IsDigit(sb[start]) || sb[start] == '-' || sb[start] == '.'))
		{
			sbFloat.Append(sb[start]);
			start++;
		}
		start++;
		return ParseFloat(sbFloat);
	}

	private int GetInt(StringBuilder sb, ref int start, ref StringBuilder sbInt)
	{
		sbInt.Remove(0, sbInt.Length);
		while (start < sb.Length && char.IsDigit(sb[start]))
		{
			sbInt.Append(sb[start]);
			start++;
		}
		start++;
		return IntParseFast(sbInt);
	}

	private static float[] GenerateLookupTable()
	{
		float[] array = new float[320];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = (float)(i / 33) * Mathf.Pow(10f, (float)(i % 33 + -16));
		}
		return array;
	}

	private float ParseFloat(StringBuilder value)
	{
		float num = 0f;
		bool flag = false;
		int length = value.Length;
		int num2 = value.Length;
		for (int num3 = length - 1; num3 >= 0; num3--)
		{
			if (value[num3] == '.')
			{
				num2 = num3;
				break;
			}
		}
		int num4 = 16 + num2;
		for (int i = 0; i < num2; i++)
		{
			if (i != num2 && value[i] != '-')
			{
				num += pow10[(value[i] - 48) * 33 + num4 - i - 1];
			}
			else if (value[i] == '-')
			{
				flag = true;
			}
		}
		for (int j = num2 + 1; j < length; j++)
		{
			if (j != num2)
			{
				num += pow10[(value[j] - 48) * 33 + num4 - j];
			}
		}
		if (flag)
		{
			num = 0f - num;
		}
		return num;
	}

	private int IntParseFast(StringBuilder value)
	{
		int num = 0;
		for (int i = 0; i < value.Length; i++)
		{
			num = 10 * num + (value[i] - 48);
		}
		return num;
	}
}
public sealed class Vector3Int
{
	public int x { get; set; }

	public int y { get; set; }

	public int z { get; set; }

	public Vector3Int()
	{
	}

	public Vector3Int(int x, int y, int z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
}
internal static class PluginInfos
{
	public const string PLUGIN_NAME = "Baller";

	public const string PLUGIN_ID = "no.mrgentle.plugins.llb.baller";

	public const string PLUGIN_VERSION = "2.1.0";
}