Decompiled source of Gilda Tank v1.0.0

plugins/Patty_GildaTank_MOD.dll

Decompiled 3 weeks ago
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_GildaTank_MOD")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Patty_GildaTank_MOD")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b5b9af5c-ebb2-46ed-95e5-e695c77e4af7")]
[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")]
namespace Patty_GildaTank_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_0045: 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_0047: Unknown result type (might be due to invalid IL or missing references)
		//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_004b: Invalid comparison between Unknown and I4
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Invalid comparison between Unknown and I4
		if (((Object)__instance.SkeletonAnimation).name == "Tank")
		{
			((Component)((Component)__instance).transform.GetChild(0)).gameObject.SetActive(false);
			((Component)__instance.SkeletonAnimation).gameObject.SetActive(true);
			if ((int)animType == 2 || (int)animType == 5)
			{
				__instance.SkeletonAnimation.AnimationState.SetAnimation(0, "shoot", true).TrackTime = startTime;
			}
			else
			{
				__instance.SkeletonAnimation.AnimationState.SetEmptyAnimation(0, 0f);
			}
		}
	}

	[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_LadyGilda_Base")
		{
			if ((Object)(object)((Component)component).transform.Find("Tank") == (Object)null)
			{
				((Graphic)component).material.SetTexture("_Layer1Tex", Plugin.BGTexture);
				Plugin.CreateUITank(((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("LadyGilda", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				Transform transform = ((Component)componentInChildren).transform;
				Object.DestroyImmediate((Object)(object)componentInChildren);
				transform.localPosition += new Vector3(170f, -160f);
				((Component)Plugin.CreateUITank(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_LadyGilda", StringComparison.OrdinalIgnoreCase) < 0)
		{
			return;
		}
		SkeletonAnimation val = Plugin.CreateWorldTank(((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)
	{
		if ((Object)(object)___characterPreview != (Object)null && (Object)(object)___characterPreview.sprite != (Object)null && ((Object)___characterPreview.sprite).name == "PLR_LadyGilda")
		{
			___characterPreview.sprite = null;
		}
	}
}
[BepInPlugin("Patty_GildaTank_MOD", "Gilda Tank", "1.0.0")]
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 Texture BGTexture { get; private set; }

	private void Awake()
	{
		//IL_002c: Expected O, but got Unknown
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Expected O, but got Unknown
		LogSource = ((BaseUnityPlugin)this).Logger;
		try
		{
			PluginHarmony = Harmony.CreateAndPatchAll(typeof(PatchList), "Patty_GildaTank_MOD");
		}
		catch (HarmonyException val)
		{
			HarmonyException val2 = val;
			LogSource.LogError((object)((Exception)(((object)((Exception)(object)val2).InnerException) ?? ((object)val2))).Message);
		}
		string path = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "PRT_Fenix_Base.png");
		Texture2D val3 = new Texture2D(2, 2, (TextureFormat)5, false);
		ImageConversion.LoadImage(val3, File.ReadAllBytes(path));
		((Object)val3).name = Path.GetFileNameWithoutExtension(path);
		BGTexture = (Texture)(object)val3;
		LoadSpineAsset();
	}

	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, "Tank Spine");
		string atlasText = File.ReadAllText(Path.Combine(path, "export", "tank.atlas"));
		string skeletonJson = File.ReadAllText(Path.Combine(path, "export", "tank-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 CreateWorldTank(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 = "Tank";
		((Component)val).gameObject.layer = LayerMask.NameToLayer("Character_Lights");
		((Component)val).transform.SetParent(parent);
		((Component)val).transform.localPosition = Vector3.zero;
		((SkeletonRenderer)val).Skeleton.ScaleX = -1f;
		val.AnimationState.SetEmptyAnimation(0, 0f);
		((Component)val).gameObject.SetActive(true);
		return val;
	}

	public static SkeletonGraphic CreateUITank(Transform parent = null)
	{
		//IL_0088: 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_00b2: 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 = "Tank";
		val.Skeleton.ScaleX = -1f;
		val.Initialize(false);
		val.Skeleton.SetToSetupPose();
		val.AnimationState.SetEmptyAnimation(0, 0f);
		((Component)val).gameObject.SetActive(true);
		((Component)val).transform.localScale = Vector3.one * 0.2f;
		((Component)val).transform.localPosition = new Vector3(0f, -80f, 0f);
		return val;
	}
}
public static class PluginInfo
{
	public const string GUID = "Patty_GildaTank_MOD";

	public const string Name = "Gilda Tank";

	public const string Version = "1.0.0";
}