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.Runtime.Versioning;
using BepInEx;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
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: AssemblyTitle("VITRUV1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VITRUV1")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dc8f52fa-0119-4632-b631-8dc19b322480")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public class LogicButtocksHaHa : MonoBehaviour
{
private Transform modelParent;
private Animator animator;
private RectTransform uiRect;
private Vector2 lastMousePos;
private Vector3 lastRotationDirection = Vector3.up;
private float lastInteractionTime;
private bool isDragging = false;
private bool isClick = false;
private bool isSpinning = true;
private Vector3 originalScale = new Vector3(0.7f, 0.7f, 1f);
private Vector3 targetScale;
private float scaleLerpSpeed = 2f;
private float scaleHoldTime = 0f;
private float scaleStartTime = 0f;
private readonly List<string> animationStates = new List<string> { "headspin", "breakdance", "gangnam", "mac", "tenna kick", "tennacane", "counting", "tennacircle", "idle animation", "goofy ahh pose" };
private string lastPlayedState = "";
private HashSet<string> playedStates = new HashSet<string>();
public void Initialize(Transform modelParent, Animator animator, RectTransform uiRect)
{
//IL_0023: 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)
this.modelParent = modelParent;
this.animator = animator;
this.uiRect = uiRect;
lastInteractionTime = Time.time;
targetScale = originalScale;
}
private void Awake()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
lastInteractionTime = Time.time;
isSpinning = true;
targetScale = originalScale;
if ((Object)(object)animator == (Object)null)
{
Debug.LogWarning((object)"LogicButtocksHaHa: Animator is null, skipping animation setup.");
}
else
{
PlayRandomAnimation();
}
}
private void PlayRandomAnimation()
{
if ((Object)(object)animator == (Object)null || animationStates.Count == 0)
{
return;
}
if (playedStates.Count == animationStates.Count)
{
playedStates.Clear();
}
List<string> list = new List<string>();
foreach (string animationState in animationStates)
{
if (!playedStates.Contains(animationState))
{
list.Add(animationState);
}
}
if (list.Count == 0)
{
list.AddRange(animationStates);
}
string text;
do
{
text = list[Random.Range(0, list.Count)];
}
while (text == lastPlayedState && list.Count > 1);
animator.Play(text, 0, 0f);
lastPlayedState = text;
playedStates.Add(text);
}
private bool IsMouseOverUI()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: 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_0028: Unknown result type (might be due to invalid IL or missing references)
Vector2 val = default(Vector2);
RectTransformUtility.ScreenPointToLocalPointInRectangle(uiRect, Vector2.op_Implicit(Input.mousePosition), (Camera)null, ref val);
Rect rect = uiRect.rect;
return ((Rect)(ref rect)).Contains(val);
}
private void Update()
{
//IL_000d: 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_0024: 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_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: 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_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: 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)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: 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_020f: Unknown result type (might be due to invalid IL or missing references)
((Component)this).transform.localScale = Vector3.Lerp(((Component)this).transform.localScale, targetScale, Time.deltaTime * scaleLerpSpeed);
if (Input.GetMouseButtonDown(0) && IsMouseOverUI())
{
lastMousePos = Vector2.op_Implicit(Input.mousePosition);
lastInteractionTime = Time.time;
isClick = true;
isDragging = true;
}
if (Input.GetMouseButton(0) && isDragging)
{
Vector2 val = Vector2.op_Implicit(Input.mousePosition);
float num = val.x - lastMousePos.x;
if (isClick && Vector2.Distance(val, lastMousePos) > 5f)
{
isClick = false;
}
if (!isClick)
{
lastRotationDirection = ((num > 0f) ? Vector3.up : Vector3.down);
modelParent.Rotate(Vector3.up, num * 0.5f);
lastInteractionTime = Time.time;
isSpinning = false;
}
lastMousePos = val;
}
else if (Input.GetMouseButtonUp(0))
{
isDragging = false;
}
if (Input.GetMouseButtonUp(0) && isClick && IsMouseOverUI())
{
targetScale = originalScale * 2.5f;
scaleStartTime = Time.time;
PlayRandomAnimation();
}
if (targetScale != originalScale && Time.time - scaleStartTime > scaleHoldTime)
{
targetScale = originalScale;
}
if (!isDragging && Time.time - lastInteractionTime > 10f)
{
isSpinning = true;
}
if (isSpinning)
{
modelParent.Rotate(lastRotationDirection, Time.deltaTime * 10f);
}
}
}
[BepInPlugin("doomahreal.ultrakill.VITRUV1", "VITRUV1", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private GameObject modelInstance;
private Camera renderCamera;
private RenderTexture renderTexture;
private Transform modelParent;
private Animator animator;
private AssetBundle loadedBundle;
private readonly string modelName = "stupiddanceshit";
private readonly string targetImagePath = "Canvas/Main Menu (1)/V1";
private void Awake()
{
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
if (!(SceneHelper.CurrentScene == "Main Menu"))
{
return;
}
GameObject val = GameObject.Find(targetImagePath);
if ((Object)(object)val == (Object)null)
{
return;
}
foreach (Transform item in val.transform)
{
Transform val2 = item;
((Component)val2).GetComponent<RawImage>()?.Apply(delegate(RawImage r)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
r.texture = null;
((Graphic)r).color = new Color(1f, 1f, 1f, 0f);
});
((Component)val2).GetComponent<Image>()?.Apply(delegate(Image i)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
i.sprite = null;
((Graphic)i).color = new Color(1f, 1f, 1f, 0f);
});
}
SetupRenderTexture(val);
LoadModel(val);
}
private void OnSceneUnloaded(Scene scene)
{
if ((Object)(object)modelInstance != (Object)null)
{
Object.Destroy((Object)(object)modelInstance);
modelInstance = null;
}
if ((Object)(object)modelParent != (Object)null)
{
Object.Destroy((Object)(object)((Component)modelParent).gameObject);
modelParent = null;
}
if ((Object)(object)renderCamera != (Object)null)
{
Object.Destroy((Object)(object)((Component)renderCamera).gameObject);
renderCamera = null;
}
if ((Object)(object)renderTexture != (Object)null)
{
renderTexture.Release();
renderTexture = null;
}
if ((Object)(object)loadedBundle != (Object)null)
{
loadedBundle.Unload(true);
loadedBundle = null;
}
}
private void SetupRenderTexture(GameObject uiObject)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//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_00c9: Unknown result type (might be due to invalid IL or missing references)
renderTexture = new RenderTexture(1024, 1024, 16);
renderTexture.Create();
renderCamera = new GameObject("RenderCamera").AddComponent<Camera>();
renderCamera.clearFlags = (CameraClearFlags)1;
renderCamera.backgroundColor = new Color(0f, 0f, 0f, 0f);
renderCamera.cullingMask = LayerMask.GetMask(new string[1] { "Armor" });
((Component)renderCamera).transform.position = new Vector3(-0.1f, 2.111f, 4.2928f);
((Component)renderCamera).transform.rotation = Quaternion.Euler(0f, 180f, 0f);
renderCamera.targetTexture = renderTexture;
renderCamera.orthographic = true;
renderCamera.orthographicSize = 2.25f;
RawImage val = uiObject.GetComponent<RawImage>();
Image component = uiObject.GetComponent<Image>();
if ((Object)(object)component != (Object)null)
{
Object.DestroyImmediate((Object)(object)component);
}
if ((Object)(object)val == (Object)null)
{
val = uiObject.AddComponent<RawImage>();
}
val.texture = (Texture)(object)renderTexture;
uiObject.GetComponent<RectTransform>()?.Apply(delegate(RectTransform rt)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
rt.anchoredPosition -= new Vector2(0f, 20f);
});
}
private void LoadModel(GameObject uiObject)
{
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string name) => name.EndsWith(".bundle"));
if (text == null)
{
return;
}
using Stream stream = executingAssembly.GetManifestResourceStream(text);
if (stream == null)
{
return;
}
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.Length);
loadedBundle = AssetBundle.LoadFromMemory(array);
if ((Object)(object)loadedBundle == (Object)null)
{
return;
}
GameObject val = loadedBundle.LoadAsset<GameObject>(modelName);
if (!((Object)(object)val == (Object)null))
{
modelParent = new GameObject("ModelParent").transform;
modelInstance = Object.Instantiate<GameObject>(val, modelParent);
modelInstance.transform.localPosition = Vector3.zero;
modelInstance.layer = LayerMask.NameToLayer("Armor");
Transform[] componentsInChildren = modelInstance.GetComponentsInChildren<Transform>();
foreach (Transform val2 in componentsInChildren)
{
((Component)val2).gameObject.layer = LayerMask.NameToLayer("Armor");
}
animator = modelInstance.GetComponent<Animator>();
LogicButtocksHaHa logicButtocksHaHa = uiObject.AddComponent<LogicButtocksHaHa>();
logicButtocksHaHa.Initialize(modelParent, animator, uiObject.GetComponent<RectTransform>());
ApplyAddressableShaderToModel();
ApplyAddressableShaderToWings();
}
}
private void ApplyAddressableShaderToModel()
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
GameObject obj = modelInstance;
Transform val = ((obj != null && obj.transform.childCount > 0) ? modelInstance.transform.GetChild(0) : null);
Transform val2 = ((val != null && val.childCount > 1) ? val.GetChild(1) : null);
SkinnedMeshRenderer val3 = ((val2 != null) ? ((Component)val2).GetComponent<SkinnedMeshRenderer>() : null);
object obj2;
if (val3 == null)
{
obj2 = null;
}
else
{
Material[] materials = ((Renderer)val3).materials;
obj2 = ((materials != null) ? materials[0] : null);
}
Material mat = (Material)obj2;
if ((Object)(object)mat == (Object)null)
{
return;
}
AsyncOperationHandle<Shader> val4 = Addressables.LoadAssetAsync<Shader>((object)"Assets/Shaders/MasterShader/ULTRAKILL-Standard.shader");
val4.Completed += delegate(AsyncOperationHandle<Shader> handle)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Invalid comparison between Unknown and I4
if ((int)handle.Status == 1 && (Object)(object)handle.Result != (Object)null)
{
mat.shader = handle.Result;
}
};
}
private void ApplyAddressableShaderToWings()
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
GameObject obj = modelInstance;
Transform val = FindChildRecursive((obj != null) ? obj.transform : null, "wings");
SkinnedMeshRenderer val2 = ((val != null) ? ((Component)val).GetComponent<SkinnedMeshRenderer>() : null);
object obj2;
if (val2 == null)
{
obj2 = null;
}
else
{
Material[] materials = ((Renderer)val2).materials;
obj2 = ((materials != null) ? materials[0] : null);
}
Material mat = (Material)obj2;
if ((Object)(object)mat == (Object)null)
{
return;
}
AsyncOperationHandle<Shader> val3 = Addressables.LoadAssetAsync<Shader>((object)"Assets/Shaders/MasterShader/ULTRAKILL-Standard.shader");
val3.Completed += delegate(AsyncOperationHandle<Shader> handle)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Invalid comparison between Unknown and I4
if ((int)handle.Status == 1 && (Object)(object)handle.Result != (Object)null)
{
mat.shader = handle.Result;
}
};
}
private Transform FindChildRecursive(Transform parent, string childName)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
if ((Object)(object)parent == (Object)null)
{
return null;
}
foreach (Transform item in parent)
{
Transform val = item;
if (((Object)val).name == childName)
{
return val;
}
Transform val2 = FindChildRecursive(val, childName);
if ((Object)(object)val2 != (Object)null)
{
return val2;
}
}
return null;
}
}
public static class ExtensionMethods
{
public static void Apply<T>(this T obj, Action<T> action) where T : class
{
if (obj != null)
{
action(obj);
}
}
}