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 BepInEx.Logging;
using HarmonyLib;
using ShinyShoe;
using Spine;
using Spine.Unity;
using UnityEngine;
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("Patty_FelOwl_MOD")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Patty_FelOwl_MOD")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b5b9af5c-ebb2-46ed-95e5-e695c77e4af7")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace Patty_FelOwl_MOD;
internal class PatchList
{
[HarmonyPostfix]
[HarmonyPatch(typeof(AppManager), "DoesThisBuildReportErrors")]
public static void DisableErrorReportingPatch(ref bool __result)
{
__result = false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(CharacterUIMeshSpine), "PlayAnim", new Type[]
{
typeof(int),
typeof(Anim),
typeof(bool),
typeof(float),
typeof(float),
typeof(Action<AnimNote>)
})]
public static void PlayAnim(CharacterUIMeshSpine __instance, Anim animType, bool loop, float startTime)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: 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_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Expected I4, but got Unknown
if (((Object)__instance.SkeletonAnimation).name == "Owl")
{
((Component)((Component)__instance).transform.GetChild(0)).gameObject.SetActive(false);
((Component)__instance.SkeletonAnimation).gameObject.SetActive(true);
switch (animType - 2)
{
case 0:
case 3:
__instance.SkeletonAnimation.AnimationState.SetAnimation(0, "left", loop).TrackTime = startTime;
break;
case 1:
case 4:
__instance.SkeletonAnimation.AnimationState.SetAnimation(0, "right", loop).TrackTime = startTime;
break;
default:
__instance.SkeletonAnimation.AnimationState.SetAnimation(0, "idle", true).TrackTime = startTime;
break;
}
Transform parent = ((Component)__instance).transform.parent;
((Component)parent.Find("VfxAnchors")).gameObject.SetActive(false);
((Component)parent.Find("FX_NewSpeedLines")).gameObject.SetActive(false);
((Component)parent.Find("HandFX")).gameObject.SetActive(false);
((Component)parent.Find("HeadFX")).gameObject.SetActive(false);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AnimateCardEffects), "Initialize")]
public static bool Initialize(AnimateCardEffects __instance)
{
Image component = ((Component)__instance).GetComponent<Image>();
if ((Object)(object)component != (Object)null && (Object)(object)component.sprite != (Object)null && ((Object)component.sprite).name == "PRT_Fel_Base")
{
if ((Object)(object)((Component)component).transform.Find("Owl") == (Object)null)
{
Plugin.CreateUIOwl(((Component)__instance).transform);
}
return false;
}
return true;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(CharacterDialogueScreen), "InstantiatePrefab")]
public static void InstantiatePrefab(ref GameObject __result)
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: 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)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__result != (Object)null)
{
Image componentInChildren = __result.GetComponentInChildren<Image>();
if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.sprite != (Object)null && ((Object)componentInChildren.sprite).name.IndexOf("Dialog_Fel", StringComparison.OrdinalIgnoreCase) >= 0)
{
Transform transform = ((Component)componentInChildren).transform;
Object.DestroyImmediate((Object)(object)componentInChildren);
transform.localPosition += new Vector3(170f, 0f);
((Component)Plugin.CreateUIOwl(transform)).transform.localScale = Vector3.one * 0.8f;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(CharacterUIMeshSpine), "Setup")]
public static void Setup(CharacterUIMeshSpine __instance, string debugName, ref List<ModelEntry> ___modelVariations)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
if (debugName.IndexOf("Character_Fel", StringComparison.OrdinalIgnoreCase) < 0)
{
return;
}
SkeletonAnimation val = Plugin.CreateWorldOwl(((Component)__instance).transform);
((Component)val).transform.localScale = Vector3.one * 0.5f;
((Component)val).transform.localPosition = new Vector3(0f, -2.19f, 0f);
foreach (ModelEntry ___modelVariation in ___modelVariations)
{
if (___modelVariation == null)
{
continue;
}
for (int i = 0; i < ___modelVariation.animInfos.Length; i++)
{
if (___modelVariation.animInfos[i] != null)
{
___modelVariation.animInfos[i] = new AnimInfo((Anim)1, val, ((Component)val).GetComponent<MeshRenderer>(), ___modelVariation.animInfos[i].animation);
((CharacterUIMeshBase)__instance).PlayAnimLoop((Anim)1, 0f, (Action<AnimNote>)null);
}
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(RoomTargetingUI), "CharacterPlacementPreview", new Type[]
{
typeof(SpawnPoint),
typeof(CharacterData),
typeof(MonsterManager)
})]
public static void CharacterPlacementPreview(RoomTargetingUI __instance, ref SpriteRenderer ___characterPreview)
{
//IL_004d: 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_0061: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)___characterPreview != (Object)null && (Object)(object)___characterPreview.sprite != (Object)null && ((Object)___characterPreview.sprite).name == "PLR_Fel")
{
___characterPreview.sprite = Plugin.OwlPreviewSpr;
Transform transform = ((Component)___characterPreview).transform;
transform.localPosition += new Vector3(-2.12f, -3.45f);
}
}
}
[BepInPlugin("Patty_FelOwl_MOD", "Fel Owl", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
internal static (Material mat, SpineAtlasAsset atlas, SkeletonDataAsset data) SpineWorldData;
internal static (Material mat, SpineAtlasAsset atlas, SkeletonDataAsset data) SpineUIData;
internal static ManualLogSource LogSource { get; private set; }
internal static Harmony PluginHarmony { get; private set; }
internal static Sprite OwlPreviewSpr { get; private set; }
private void Awake()
{
//IL_002c: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
LogSource = ((BaseUnityPlugin)this).Logger;
try
{
PluginHarmony = Harmony.CreateAndPatchAll(typeof(PatchList), "Patty_FelOwl_MOD");
}
catch (HarmonyException val)
{
HarmonyException val2 = val;
LogSource.LogError((object)((Exception)(((object)((Exception)(object)val2).InnerException) ?? ((object)val2))).Message);
}
LoadSpineAsset();
SkeletonAnimation val3 = CreateWorldOwl();
((Component)val3).transform.localPosition = new Vector3(888888f, 888888f);
Texture2D val4 = CaptureScreenshot((Component)(object)val3);
OwlPreviewSpr = Sprite.Create(val4, new Rect(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height), Vector2.zero);
Object.DestroyImmediate((Object)(object)((Component)val3).gameObject);
}
private void LoadSpineAsset()
{
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
string path = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "Owl Spine");
string atlasText = File.ReadAllText(Path.Combine(path, "export", "owl.atlas"));
string skeletonJson = File.ReadAllText(Path.Combine(path, "export", "owl-pro.json"));
string[] files = Directory.GetFiles(Path.Combine(path, "export"), "*.png");
string[] files2 = Directory.GetFiles(Path.Combine(path, "images"), "*.png");
List<string> list = files.Union(files2).ToList();
Texture2D[] array = (Texture2D[])(object)new Texture2D[list.Count];
for (int i = 0; i < list.Count; i++)
{
byte[] array2 = File.ReadAllBytes(list[i]);
array[i] = new Texture2D(2, 2);
ImageConversion.LoadImage(array[i], array2);
((Object)array[i]).name = Path.GetFileNameWithoutExtension(list[i]);
}
SpineWorldData = CreateSpineAsset(atlasText, skeletonJson, array, ui: false);
SpineUIData = CreateSpineAsset(atlasText, skeletonJson, array, ui: true);
}
private (Material, SpineAtlasAsset, SkeletonDataAsset) CreateSpineAsset(string atlasText, string skeletonJson, Texture2D[] textures, bool ui)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
Material val = ((!ui) ? new Material(Shader.Find("Spine/Skeleton")) : new Material(Shader.Find("Spine/SkeletonGraphic")));
SpineAtlasAsset val2 = SpineAtlasAsset.CreateRuntimeInstance(new TextAsset(atlasText), textures, val, true, (Func<SpineAtlasAsset, TextureLoader>)null);
SkeletonDataAsset item = SkeletonDataAsset.CreateRuntimeInstance(new TextAsset(skeletonJson), (AtlasAssetBase)(object)val2, true, 0.01f);
return (val, val2, item);
}
public static SkeletonAnimation CreateWorldOwl(Transform parent = null)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
SkeletonAnimation val = SkeletonAnimation.NewSkeletonAnimationGameObject(SpineWorldData.data, false);
((Object)val).name = "Owl";
((Component)val).gameObject.layer = LayerMask.NameToLayer("Character_Lights");
((Component)val).transform.SetParent(parent);
((Component)val).transform.localPosition = Vector3.zero;
val.AnimationState.SetAnimation(0, "idle", true);
((Component)val).gameObject.SetActive(true);
return val;
}
public static SkeletonGraphic CreateUIOwl(Transform parent = null)
{
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
SkeletonGraphic val = SkeletonGraphic.NewSkeletonGraphicGameObject(SpineUIData.data, parent, SpineUIData.mat);
((Component)val).gameObject.layer = LayerMask.NameToLayer("UI");
((Object)val).name = "Owl";
val.Initialize(false);
val.Skeleton.SetToSetupPose();
val.AnimationState.SetAnimation(0, "idle", true);
((Component)val).gameObject.SetActive(true);
((Component)val).transform.localScale = Vector3.one * 0.3f;
((Component)val).transform.localPosition = new Vector3(0f, -80f, 0f);
return val;
}
public static Texture2D CaptureScreenshot(Component component, int width = 512, int height = 512, int padding = 10)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: 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)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Expected O, but got Unknown
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
Renderer component2 = component.GetComponent<Renderer>();
if ((Object)(object)component2 == (Object)null)
{
LogSource.LogError((object)"Cannot obtain renderer to take screenshot");
return null;
}
GameObject val = new GameObject("ScreenshotCamera");
Camera val2 = val.AddComponent<Camera>();
val2.orthographic = true;
val2.clearFlags = (CameraClearFlags)2;
val2.backgroundColor = Color.clear;
RenderTexture val4 = (val2.targetTexture = new RenderTexture(width, height, 32, (RenderTextureFormat)0));
Bounds val5 = (Bounds)(((Object)(object)component2 != (Object)null) ? component2.bounds : new Bounds(Vector3.zero, new Vector3(2f, 2f, 0f)));
float num = (float)width / (float)height;
float orthographicSize = Mathf.Max(((Bounds)(ref val5)).extents.y, ((Bounds)(ref val5)).extents.x / num) * (1f + (float)padding / 100f);
val2.orthographicSize = orthographicSize;
Vector3 center = ((Bounds)(ref val5)).center;
((Component)val2).transform.position = new Vector3(center.x, center.y, center.z - 10f);
val2.Render();
Texture2D val6 = new Texture2D(width, height, (TextureFormat)5, false);
RenderTexture active = RenderTexture.active;
RenderTexture.active = val4;
val6.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
val6.Apply();
RenderTexture.active = active;
Object.DestroyImmediate((Object)(object)val);
Object.DestroyImmediate((Object)(object)val4);
return val6;
}
}
public static class PluginInfo
{
public const string GUID = "Patty_FelOwl_MOD";
public const string Name = "Fel Owl";
public const string Version = "1.0.1";
}