Decompiled source of ULTRA KASANE v1.0.0

plugins/ULTRA_KASANE.dll

Decompiled 6 hours ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
using UltraKasane.Properties;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: ComVisible(false)]
[assembly: Guid("6a88a782-cbb3-48de-8fc3-24f2aa8c9765")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("tweeni")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Teto")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ULTRA_KASANE")]
[assembly: AssemblyTitle("ULTRA_KASANE")]
[assembly: AssemblyVersion("1.0.0.0")]
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 UltraKasane
{
	public class Class1
	{
	}
	public class PunchPatcherStart
	{
		public static ManualLogSource logSource;

		public static void DoPatching(ManualLogSource logSource)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			PunchPatcherStart.logSource = logSource;
			Harmony val = new Harmony("com.tweeni.ultrakasane.patcher");
			val.PatchAll();
		}
	}
	[HarmonyPatch(typeof(Punch))]
	[HarmonyPatch("Awake")]
	internal class PunchPatcher
	{
		private static FieldRef<Punch, SkinnedMeshRenderer> smr = AccessTools.FieldRefAccess<Punch, SkinnedMeshRenderer>("smr");

		private static void Postfix(Punch __instance)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			if ((int)__instance.type > 0)
			{
				return;
			}
			SkinnedMeshRenderer val = smr.Invoke(__instance);
			Mesh feedbackerMesh = UltraKasaneMain.feedbackerMesh;
			List<Transform> list = new List<Transform>(val.bones);
			List<string> feedbackerBoneNames = UltraKasaneMain.feedbackerBoneNames;
			Matrix4x4[] array = (Matrix4x4[])(object)new Matrix4x4[feedbackerMesh.bindposeCount];
			if (UltraKasaneMain.TetoArmIsEnabled)
			{
				Dictionary<int, int> dictionary = new Dictionary<int, int>();
				int i;
				for (i = 0; i < feedbackerMesh.bindposeCount; i++)
				{
					int num = list.FindIndex((Transform tr) => ((Object)tr).name == feedbackerBoneNames[i]);
					if (num != -1)
					{
						dictionary[i] = num;
						Transform val2 = list[num];
						array[i] = feedbackerMesh.bindposes[num];
					}
					else
					{
						array[i] = Matrix4x4.identity;
						Console.WriteLine("Bone mismatch; no corresponding bone for: " + feedbackerBoneNames[i]);
					}
				}
				BoneWeight[] boneWeights = feedbackerMesh.boneWeights;
				for (int j = 0; j < boneWeights.Length; j++)
				{
					((BoneWeight)(ref boneWeights[j])).boneIndex0 = dictionary[((BoneWeight)(ref boneWeights[j])).boneIndex0];
					((BoneWeight)(ref boneWeights[j])).boneIndex1 = dictionary[((BoneWeight)(ref boneWeights[j])).boneIndex1];
					((BoneWeight)(ref boneWeights[j])).boneIndex2 = dictionary[((BoneWeight)(ref boneWeights[j])).boneIndex2];
					((BoneWeight)(ref boneWeights[j])).boneIndex3 = dictionary[((BoneWeight)(ref boneWeights[j])).boneIndex3];
				}
				feedbackerMesh.bindposes = array;
				feedbackerMesh.boneWeights = boneWeights;
				val.sharedMesh = feedbackerMesh;
				Material sharedMaterial = ((Renderer)val).sharedMaterial;
				List<Material> list2 = new List<Material>();
				for (int k = 0; k < UltraKasaneMain.feedbackerMats.Length; k++)
				{
					Material val3 = Object.Instantiate<Material>(sharedMaterial);
					val3.mainTexture = UltraKasaneMain.feedbackerMats[k].mainTexture;
					val3.color = new Color(0.95f, 0.95f, 0.95f);
					list2.Add(val3);
				}
				((Renderer)val).sharedMaterials = list2.ToArray();
			}
			int num2 = 0;
			while (true)
			{
				int num3 = num2;
				_ = list.Count;
				if (num3 < 0)
				{
					Matrix4x4 val4 = ((Component)__instance).transform.localToWorldMatrix * ((Matrix4x4)(ref val.sharedMesh.bindposes[num2])).inverse;
					list[num2].position = Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(3));
					list[num2].rotation = Quaternion.LookRotation(Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(2)), Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(1)));
					num2++;
					continue;
				}
				break;
			}
		}

		private static string PrintBoneStructure(IList<Transform> trans)
		{
			return BoneNameRecursive(trans[0]);
		}

		private static string BoneNameRecursive(Transform trans, string __pad = "")
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			string text = ((Object)trans).name + "\n";
			foreach (Transform tran in trans)
			{
				Transform trans2 = tran;
				text = text + __pad + BoneNameRecursive(trans2, __pad + "|   ");
			}
			return text;
		}

		private static List<Transform> FindLeafBones(Transform root)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			List<Transform> list = new List<Transform>();
			if (root.childCount == 0)
			{
				list.Add(root);
			}
			else
			{
				foreach (Transform item in root)
				{
					Transform root2 = item;
					list.AddRange(FindLeafBones(root2));
				}
			}
			return list;
		}

		private static void GetSkeleton(SkinnedMeshRenderer smr, Matrix4x4 rootWorld)
		{
			//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)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			Mesh sharedMesh = smr.sharedMesh;
			Transform[] bones = smr.bones;
			Matrix4x4[] bindposes = sharedMesh.bindposes;
			string text = "";
			for (int i = 0; i < bones.Length; i++)
			{
				Matrix4x4 val = bindposes[i];
				text = text + "\n    { \"" + ((Object)bones[i]).name + "\", " + StringUtils.Matrix4x4ToCsharp(rootWorld * ((Matrix4x4)(ref val)).inverse) + " },";
			}
			List<Transform> list = FindLeafBones(bones[0]);
			foreach (Transform item in list)
			{
				text = text + "\n    { \"" + ((Object)item).name + "\", " + StringUtils.Matrix4x4ToCsharp(item.localToWorldMatrix) + " },";
			}
			Console.WriteLine("\nnew Dictionary<string, Matrix4x4>()\n{" + text + "\n};");
		}
	}
	internal class StringUtils
	{
		public static string Matrix4x4ToCsharp(Matrix4x4 matrix)
		{
			string[] array = new string[4];
			for (int i = 0; i < 4; i++)
			{
				string[] array2 = new string[4];
				for (int j = 0; j < 4; j++)
				{
					array2[j] = ((Matrix4x4)(ref matrix))[j, i].ToString("G17") + "f";
				}
				array[i] = "new Vector4(" + string.Join(", ", array2) + ")";
			}
			return "new Matrix4x4(" + string.Join(", ", array) + ")";
		}
	}
	[BepInPlugin("com.tweeni.ultrakasane", "ULTRA_KASANE", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class UltraKasaneMain : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static BoolValueChangeEventDelegate <>9__18_1;

			internal void <PluginConfig_init>b__18_1(BoolValueChangeEvent e)
			{
				TetoArmIsEnabled = e.value;
			}
		}

		public const string pluginGuid = "com.tweeni.ultrakasane";

		public const string pluginName = "ULTRA_KASANE";

		public const string pluginVersion = "1.0.0";

		public static AssetBundle tetoAssetBundle;

		public static Mesh feedbackerMesh;

		public static Material[] feedbackerMats;

		public static List<string> feedbackerBoneNames;

		private static PluginConfigurator config;

		private GameObject spriteObject = null;

		private BoolField armToggle;

		private BoolField textmodeToggle;

		private ConfigDivision textmodeDiv;

		private StringListField variant;

		public static bool TetoArmIsEnabled { get; private set; }

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"I'm a pear");
			try
			{
				tetoAssetBundle = AssetBundle.LoadFromMemory(Resources.teto);
				string[] allAssetNames = tetoAssetBundle.GetAllAssetNames();
				foreach (string text in allAssetNames)
				{
				}
				GameObject val = tetoAssetBundle.LoadAsset<GameObject>("teto_feedbacker_variant");
				SkinnedMeshRenderer componentInChildren = Object.Instantiate<GameObject>(val).GetComponentInChildren<SkinnedMeshRenderer>();
				spriteObject = tetoAssetBundle.LoadAsset<GameObject>("TextmodeTeto");
				PluginConfig_init();
				feedbackerBoneNames = new List<string>(new string[componentInChildren.bones.Length]);
				for (int j = 0; j < componentInChildren.bones.Length; j++)
				{
					feedbackerBoneNames[j] = ((Object)componentInChildren.bones[j]).name;
				}
				feedbackerMesh = componentInChildren.sharedMesh;
				feedbackerMats = ((Renderer)componentInChildren).sharedMaterials;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Vital component of Teto could not be loaded. Teto will not run.");
				((BaseUnityPlugin)this).Logger.LogError((object)ex.Message);
				tetoAssetBundle.Unload(false);
				return;
			}
			PunchPatcherStart.DoPatching(((BaseUnityPlugin)this).Logger);
			SceneManager.sceneLoaded += SceneManager_sceneLoaded;
		}

		private void PluginConfig_init()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00c3: 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_00ce: Expected O, but got Unknown
			config = PluginConfigurator.Create("ULTRA_KASANE", "com.tweeni.ultrakasane");
			ConfigPanel rootPanel = config.rootPanel;
			armToggle = new BoolField(rootPanel, "Enable Teto's Feedbacker (require level reload)", "teto_arm", true);
			textmodeToggle = new BoolField(rootPanel, "Enable Teto's Textmode", "teto_textmode", true);
			textmodeDiv = new ConfigDivision(config.rootPanel, "teto_textmode_div");
			variant = new StringListField(rootPanel, "Variant", "teto_textmode_variant", new string[1] { "Default" }, "Default");
			textmodeToggle.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				((ConfigField)textmodeDiv).interactable = e.value;
			};
			BoolField obj = armToggle;
			object obj2 = <>c.<>9__18_1;
			if (obj2 == null)
			{
				BoolValueChangeEventDelegate val = delegate(BoolValueChangeEvent e)
				{
					TetoArmIsEnabled = e.value;
				};
				<>c.<>9__18_1 = val;
				obj2 = (object)val;
			}
			obj.onValueChange += (BoolValueChangeEventDelegate)obj2;
		}

		private void TextmodeSetup(bool toggled)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Textmode set applied: " + toggled));
		}

		private void SceneManager_sceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0071: 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)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			TetoArmIsEnabled = armToggle.value;
			Image[] array = Object.FindObjectsOfType<Image>(true);
			Image[] array2 = array;
			foreach (Image val in array2)
			{
				if (!((Object)(object)val.sprite != (Object)null) || !(((Object)val.sprite).name == "TextmodeV1"))
				{
					continue;
				}
				GameObject val2 = Object.Instantiate<GameObject>(spriteObject);
				Image component = val2.GetComponent<Image>();
				((Graphic)component).color = ((Graphic)val).color;
				Image[] componentsInChildren = ((Component)val).GetComponentsInChildren<Image>(true);
				Image[] componentsInChildren2 = val2.GetComponentsInChildren<Image>(true);
				ToggleWatcher toggleWatcher = ((Component)val).gameObject.AddComponent<ToggleWatcher>();
				toggleWatcher.tied = component;
				toggleWatcher.localImg = val;
				((Behaviour)toggleWatcher).enabled = true;
				toggleWatcher.Init(textmodeToggle);
				Image[] array3 = componentsInChildren;
				foreach (Image val3 in array3)
				{
					Image[] array4 = componentsInChildren2;
					foreach (Image val4 in array4)
					{
						if (((Object)val4).name == ((Object)val3).name)
						{
							ToggleWatcher toggleWatcher2 = ((Component)val3).gameObject.AddComponent<ToggleWatcher>();
							toggleWatcher2.tied = val4;
							toggleWatcher2.localImg = val3;
							((Graphic)val4).color = ((Graphic)val3).color;
							((Graphic)val4).raycastTarget = false;
							((Behaviour)toggleWatcher2).enabled = true;
							toggleWatcher2.Init(textmodeToggle);
						}
					}
				}
				val2.transform.parent = ((Component)val).transform;
				val2.transform.localScale = Vector3.one * 9.6f;
				val2.transform.localPosition = new Vector3(0f, -5f, 0f);
			}
			textmodeToggle.TriggerValueChangeEvent();
		}
	}
	public class ToggleWatcher : MonoBehaviour
	{
		public Image tied = null;

		public Image localImg = null;

		private Sprite tiedSprite;

		private Sprite localImgSprite;

		private Sprite nullSpr;

		private BoolField toggleEvtHandler;

		public void Init(BoolField toggleEvtHandler)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			this.toggleEvtHandler = toggleEvtHandler;
			toggleEvtHandler.onValueChange += new BoolValueChangeEventDelegate(_SwapToggle);
			nullSpr = createNullSprite();
			tiedSprite = tied.sprite;
			localImgSprite = localImg.sprite;
		}

		private void _SwapToggle(BoolValueChangeEvent toggle)
		{
			SwapToggle(toggle.value);
		}

		private void SwapToggle(bool value)
		{
			if (value && ((Component)localImg).gameObject.activeSelf)
			{
				localImg.sprite = nullSpr;
				tied.sprite = tiedSprite;
			}
			else
			{
				localImg.sprite = localImgSprite;
				tied.sprite = nullSpr;
			}
		}

		private void OnEnable()
		{
			if (toggleEvtHandler != null)
			{
				SwapToggle(toggleEvtHandler.value);
			}
		}

		private void OnDisable()
		{
			tied.sprite = nullSpr;
		}

		private void OnDestroy()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			toggleEvtHandler.onValueChange -= new BoolValueChangeEventDelegate(_SwapToggle);
		}

		private void Update()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)tied).color = ((Graphic)localImg).color;
		}

		private static Sprite createNullSprite()
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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)
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, new Color(0f, 0f, 0f, 0f));
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f));
		}
	}
}
namespace UltraKasane.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("UltraKasane.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] teto
		{
			get
			{
				object @object = ResourceManager.GetObject("teto", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resources()
		{
		}
	}
}