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 GameplayEntities;
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.0.0.0")]
[module: UnverifiableCode]
namespace Baller;
[BepInPlugin("no.mrgentle.plugins.llb.baller", "Baller", "2.0.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;
public Ball[] balls = new Ball[9];
private void Awake()
{
Instance = this;
ResourceFolder = ModdingFolder.GetModSubFolder(((BaseUnityPlugin)this).Info);
}
private void Start()
{
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");
Ball[] array = balls;
foreach (Ball ball in array)
{
ball.mesh = FastObjImporter.Instance.ImportFile(ball.ballResourcesFolder.FullName);
FileInfo fileInfo = (from file in ball.ballResourcesFolder.GetFiles()
where file.Extension.ToLower() == ".png" || file.Extension.ToLower() == ".dds"
select file into _
orderby Random.value
select _).FirstOrDefault();
ball.tex = ((fileInfo != null) ? TextureUtils.LoadTexture(fileInfo) : null);
}
}
private void Update()
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)transparentShader))
{
transparentShader = BundledAssetLoader.GetShader(ShaderType.Transparent);
}
BallHandler instance = BallHandler.instance;
BallEntity val = ((instance != null) ? instance.GetBall(0) : null);
if (val == null)
{
return;
}
SkinnedMeshRenderer[] componentsInChildren = ((Component)val).gameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
if (componentsInChildren.Length == 0)
{
return;
}
SkinnedMeshRenderer[] array = componentsInChildren;
foreach (SkinnedMeshRenderer val2 in array)
{
Ball[] array2 = balls;
foreach (Ball ball in array2)
{
if (((HitableEntity)val).ballType == ball.type && ((Object)(object)ball.mesh != (Object)null || (Object)(object)ball.tex != (Object)null) && !ball.identifier.Contains("candy") && !ball.identifier.Contains("nitro"))
{
if ((((Object)val2).name == "ballMesh_MainRenderer" || ((Object)val2).name == "ballMesh002_MainRenderer") && (Object)(object)ball.tex != (Object)null)
{
ApplyTexture(val2, ball.tex);
}
if ((Object)(object)ball.mesh != (Object)null && (((Object)val2).name == "ballMesh_MainRenderer" || ((Object)val2).name == "ballMesh002_MainRenderer" || ((Object)val2).name.ToLower().Contains("outline")))
{
val2.sharedMesh = ball.mesh;
}
else if ((Object)(object)ball.mesh != (Object)null)
{
val2.sharedMesh = null;
}
}
if (ball.identifier.Contains("candy") && ((Object)(object)ball.mesh != (Object)null || (Object)(object)ball.tex != (Object)null))
{
if ((Object)(object)ball.tex != (Object)null && !((Object)val2).name.Contains("Outline"))
{
((Renderer)val2).material.SetColor("_LitColor", Color.white);
if ((Object)(object)ball.tex != (Object)null && ball.identifier.Contains("strait") && ((Object)val2).name.Contains("Strait"))
{
ApplyTexture(val2, ball.tex);
}
else if ((Object)(object)ball.tex != (Object)null && ball.identifier.Contains("saturn") && ((Object)val2).name.Contains("Saturn"))
{
ApplyTexture(val2, ball.tex);
}
else if ((Object)(object)ball.tex != (Object)null && ball.identifier.Contains("regular") && !((Object)val2).name.Contains("Strait") && !((Object)val2).name.Contains("Saturn") && ((Object)val2).name.Contains("mesh001"))
{
ApplyTexture(val2, ball.tex);
}
}
if ((Object)(object)ball.mesh != (Object)null && ball.identifier.Contains("strait") && ((Object)val2).name.Contains("Strait"))
{
val2.sharedMesh = ball.mesh;
}
else if ((Object)(object)ball.mesh != (Object)null && ball.identifier.Contains("saturn") && ((Object)val2).name.Contains("Saturn"))
{
val2.sharedMesh = ball.mesh;
}
else if ((Object)(object)ball.mesh != (Object)null && ball.identifier.Contains("regular") && !((Object)val2).name.Contains("Strait") && !((Object)val2).name.Contains("Saturn") && ((Object)val2).name.Contains("mesh001"))
{
val2.sharedMesh = ball.mesh;
}
}
if (!ball.identifier.Contains("nitro") || (!((Object)(object)ball.mesh != (Object)null) && !((Object)(object)ball.tex != (Object)null)))
{
continue;
}
if ((Object)(object)ball.tex != (Object)null && !((Object)val2).name.Contains("Outline"))
{
if ((Object)(object)ball.tex != (Object)null && ball.identifier.Contains("detective") && ((Object)val2).name.Contains("Detective"))
{
ApplyTexture(val2, ball.tex);
}
else if ((Object)(object)ball.tex != (Object)null && ball.identifier.Contains("regular") && !((Object)val2).name.Contains("Detective") && ((Object)val2).name.Contains("cuff"))
{
ApplyTexture(val2, ball.tex);
}
}
if ((Object)(object)ball.mesh != (Object)null && ball.identifier.Contains("detective") && ((Object)val2).name.Contains("Detective"))
{
val2.sharedMesh = ball.mesh;
}
else if ((Object)(object)ball.mesh != (Object)null && ball.identifier.Contains("regular") && !((Object)val2).name.Contains("Detective") && ((Object)val2).name.Contains("cuff"))
{
val2.sharedMesh = ball.mesh;
}
}
}
}
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 folderPath)
{
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Expected O, but got Unknown
//IL_018c: 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_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
string text = null;
if (Directory.Exists(folderPath) && Directory.GetFiles(folderPath).Length != 0)
{
string[] files = Directory.GetFiles(folderPath);
foreach (string text2 in files)
{
if (text2.ToLower().EndsWith(".obj"))
{
text = text2;
}
}
}
if (text == null)
{
return null;
}
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(text);
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 j = 0; j < faceData.Count; j++)
{
array[j] = vertices[faceData[j].x - 1];
if (faceData[j].y >= 1 && faceData[j].y - 1 < uv.Count - 1)
{
array2[j] = uv[faceData[j].y - 1];
}
if (faceData[j].z >= 1)
{
array3[j] = normals[faceData[j].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.0.0";
}