using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("UmamusumeSkulls")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UmamusumeSkulls")]
[assembly: AssemblyTitle("UmamusumeSkulls")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace UmamusumeSkulls
{
[BepInPlugin("com.achelia.umamusumeskulls", "Umamusume Skulls", "1.0.0")]
public class UmamusumeSkullsPlugin : BaseUnityPlugin
{
public const string PluginGuid = "com.achelia.umamusumeskulls";
public const string PluginName = "Umamusume Skulls";
public const string PluginVersion = "1.0.0";
private const string BundleResource = "UmamusumeSkulls.Resources.verxina_gentildonna";
internal static ManualLogSource Log;
internal static GameObject BluePrefab;
internal static GameObject RedPrefab;
internal static AudioClip BluePickup;
internal static AudioClip RedPickup;
private static AssetBundle bundle;
private Harmony harmony;
private void Awake()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
if (LoadBundle())
{
harmony = new Harmony("com.achelia.umamusumeskulls");
harmony.PatchAll(Assembly.GetExecutingAssembly());
SceneManager.sceneLoaded += OnSceneLoaded;
((MonoBehaviour)this).StartCoroutine(SkullReplacer.SweepForever());
Log.LogInfo((object)"Umamusume Skulls loaded successfully.");
}
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
SkullReplacer.SweepNow();
}
private bool LoadBundle()
{
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("UmamusumeSkulls.Resources.verxina_gentildonna"))
{
if (stream == null)
{
return false;
}
bundle = AssetBundle.LoadFromStream(stream);
}
if ((Object)(object)bundle == (Object)null)
{
return false;
}
BluePrefab = bundle.LoadAsset<GameObject>("Verxina_BlueSkull");
RedPrefab = bundle.LoadAsset<GameObject>("Gentildonna_RedSkull");
BluePickup = bundle.LoadAsset<AudioClip>("VerxinaPickup");
RedPickup = bundle.LoadAsset<AudioClip>("GentildonnaPickup");
if ((Object)(object)BluePrefab == (Object)null)
{
Log.LogError((object)"Prefab 'Verxina_BlueSkull' missing from the bundle.");
}
if ((Object)(object)RedPrefab == (Object)null)
{
Log.LogError((object)"Prefab 'Gentildonna_RedSkull' missing from the bundle.");
}
return (Object)(object)BluePrefab != (Object)null || (Object)(object)RedPrefab != (Object)null;
}
}
internal class UmamusumeSkullTag : MonoBehaviour
{
}
internal static class SkullReplacer
{
private const float SizeMultiplier = 2.1f;
private const float YawOffset = 180f;
private const float SweepInterval = 0.5f;
private static readonly Vector3 Nudge = new Vector3(0f, 0f, 0f);
private const float LeftNudge = 0.1f;
private const float VoiceVolume = 1f;
internal static IEnumerator SweepForever()
{
WaitForSeconds wait = new WaitForSeconds(0.5f);
while (true)
{
SweepNow();
yield return wait;
}
}
internal static void SweepNow()
{
ItemIdentifier[] array = Object.FindObjectsOfType<ItemIdentifier>(true);
for (int i = 0; i < array.Length; i++)
{
TryReplace(array[i]);
}
}
internal static void TryReplace(ItemIdentifier item)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Invalid comparison between Unknown and I4
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Invalid comparison between Unknown and I4
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: 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_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0303: Unknown result type (might be due to invalid IL or missing references)
//IL_030d: Unknown result type (might be due to invalid IL or missing references)
//IL_0312: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_0336: Unknown result type (might be due to invalid IL or missing references)
//IL_0342: Unknown result type (might be due to invalid IL or missing references)
//IL_034d: Unknown result type (might be due to invalid IL or missing references)
//IL_0352: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)item == (Object)null)
{
return;
}
GameObject val;
if ((int)item.itemType == 1)
{
val = UmamusumeSkullsPlugin.BluePrefab;
}
else
{
if ((int)item.itemType != 2)
{
return;
}
val = UmamusumeSkullsPlugin.RedPrefab;
}
if ((Object)(object)val == (Object)null || (Object)(object)((Component)item).GetComponentInChildren<UmamusumeSkullTag>(true) != (Object)null)
{
return;
}
Transform transform = ((Component)item).transform;
if (!TryGetVisualBounds(transform, out var bounds))
{
return;
}
Renderer[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Renderer>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
if (componentsInChildren[i] is MeshRenderer || componentsInChildren[i] is SkinnedMeshRenderer)
{
componentsInChildren[i].enabled = false;
}
}
GameObject val2 = Object.Instantiate<GameObject>(val);
((Object)val2).name = "UmamusumeSkull";
val2.AddComponent<UmamusumeSkullTag>();
Quaternion rotation = val.transform.rotation;
Vector3 localScale = val.transform.localScale;
val2.transform.SetParent(transform, false);
val2.transform.localPosition = Vector3.zero;
val2.transform.localScale = localScale;
val2.transform.rotation = rotation;
if (TryGetVisualBounds(val2.transform, out var bounds2) && !(((Bounds)(ref bounds2)).size.y <= 0.0001f))
{
float num = ((Bounds)(ref bounds)).size.y / ((Bounds)(ref bounds2)).size.y * 2.1f;
float y = transform.lossyScale.y;
if (Mathf.Abs(y) > 0.0001f)
{
num /= y;
}
val2.transform.localScale = localScale * num;
Vector3 val3 = transform.forward;
val3.y = 0f;
if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
{
val3 = transform.up;
val3.y = 0f;
}
if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
{
val3 = Vector3.forward;
}
((Vector3)(ref val3)).Normalize();
float num2 = Mathf.Atan2(val3.x, val3.z) * 57.29578f + 180f;
val2.transform.rotation = Quaternion.AngleAxis(num2, Vector3.up) * rotation;
TryGetVisualBounds(val2.transform, out bounds2);
Vector3 val4 = new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).center.z) + Nudge * ((Bounds)(ref bounds)).size.y;
Transform transform2 = val2.transform;
transform2.position += val4 - new Vector3(((Bounds)(ref bounds2)).center.x, ((Bounds)(ref bounds2)).min.y, ((Bounds)(ref bounds2)).center.z);
Transform transform3 = val2.transform;
transform3.position += val2.transform.right * (0.1f * ((Bounds)(ref bounds)).size.y);
}
}
internal static void PlayPickupVoice(ItemIdentifier item)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Invalid comparison between Unknown and I4
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Invalid comparison between Unknown and I4
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)item == (Object)null)
{
return;
}
AudioClip val;
if ((int)item.itemType == 1)
{
val = UmamusumeSkullsPlugin.BluePickup;
}
else
{
if ((int)item.itemType != 2)
{
return;
}
val = UmamusumeSkullsPlugin.RedPickup;
}
if (!((Object)(object)val == (Object)null))
{
GameObject val2 = new GameObject("UmamusumeSkullVoice");
val2.transform.position = ((Component)item).transform.position;
AudioSource val3 = val2.AddComponent<AudioSource>();
val3.clip = val;
val3.spatialBlend = 0f;
val3.volume = 1f;
AudioSource componentInChildren = ((Component)item).GetComponentInChildren<AudioSource>();
if ((Object)(object)componentInChildren != (Object)null)
{
val3.outputAudioMixerGroup = componentInChildren.outputAudioMixerGroup;
}
val3.Play();
Object.Destroy((Object)(object)val2, val.length + 0.5f);
}
}
private static bool TryGetVisualBounds(Transform root, out Bounds bounds)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: 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_004c: Unknown result type (might be due to invalid IL or missing references)
bounds = default(Bounds);
bool flag = false;
Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
if (componentsInChildren[i] is MeshRenderer || componentsInChildren[i] is SkinnedMeshRenderer)
{
if (!flag)
{
bounds = componentsInChildren[i].bounds;
flag = true;
}
else
{
((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds);
}
}
}
return flag;
}
}
[HarmonyPatch(typeof(ItemIdentifier), "PickUp")]
internal static class ItemIdentifierPickUpPatch
{
private static void Postfix(ItemIdentifier __instance)
{
SkullReplacer.PlayPickupVoice(__instance);
}
}
[HarmonyPatch(typeof(ItemIdentifier), "CreateCopy")]
internal static class ItemIdentifierCreateCopyPatch
{
private static void Postfix(ItemIdentifier __result)
{
if ((Object)(object)__result != (Object)null)
{
SkullReplacer.TryReplace(__result);
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
internal IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}