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 HarmonyLib;
using SpriteComposing;
using Spriteshop;
using UnityEngine;
using Voxels.TowerDefense.HeroGeneration;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RandomFlagMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RandomFlagMod")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("10836d0d-d48e-4cfe-97b0-458e7c053c73")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DecalFlagMod;
[BepInPlugin("com.yourname.randomflagmod", "Random Decal Flag Mod", "1.0.0")]
public class ModMain : BaseUnityPlugin
{
public static List<Sprite> customDecalSprites = new List<Sprite>();
private static string modDirectory;
private void Awake()
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
modDirectory = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Decal Mod Path: " + modDirectory));
LoadCustomSprites();
Harmony val = new Harmony("com.yourname.randomflagmod");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Random Decal Flag Mod loaded successfully!");
}
private void LoadCustomSprites()
{
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
string[] files = Directory.GetFiles(modDirectory, "decal_*.png");
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Found {files.Length} custom decal files.");
string[] array = files;
foreach (string path in array)
{
if (File.Exists(path))
{
byte[] array2 = File.ReadAllBytes(path);
Texture2D val = new Texture2D(2, 2);
if (ImageConversion.LoadImage(val, array2))
{
((Texture)val).filterMode = (FilterMode)0;
val.Apply(true);
Sprite item = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
customDecalSprites.Add(item);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Successfully loaded custom decal: " + Path.GetFileName(path)));
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load image data from " + Path.GetFileName(path)));
}
}
}
}
}
[HarmonyPatch(typeof(MonoHero), "MakeHero")]
public class MonoHero_Decal_Patch
{
private static void Postfix(MonoHero __instance)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Expected O, but got Unknown
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
try
{
FieldInfo fieldInfo = AccessTools.Field(typeof(MonoHero), "traitSpriteBanner");
SpriteRenderer val = (SpriteRenderer)fieldInfo.GetValue(__instance);
if (!((Object)(object)val.sprite == (Object)null) || ModMain.customDecalSprites.Count <= 0)
{
return;
}
FieldInfo fieldInfo2 = AccessTools.Field(typeof(MonoHero), "bannerSpriteGen");
ComposedSprite val2 = (ComposedSprite)fieldInfo2.GetValue(__instance);
PsdGroup val3 = null;
PsdGroup[] componentsInChildren = ((Component)val2).GetComponentsInChildren<PsdGroup>(true);
foreach (PsdGroup val4 in componentsInChildren)
{
if (val4.splitName.Contains("IconSlot2"))
{
val3 = val4;
break;
}
}
if ((Object)(object)val3 != (Object)null)
{
((Component)val3).gameObject.SetActive(false);
}
else
{
Debug.LogWarning((object)"Decal Mod: Could not find 'IconSlot2' to hide.");
}
Random random = new Random(__instance.heroDef.nameTerm.GetHashCode());
int index = random.Next(0, ModMain.customDecalSprites.Count);
val.sprite = ModMain.customDecalSprites[index];
val.color = Color.white;
if ((Object)(object)val.sprite != (Object)null)
{
((Component)val).transform.localScale = Vector3.one * 0.3f;
Transform transform = ((Component)val).transform;
Vector3 localPosition = transform.localPosition;
Transform parent = ((Component)val).transform.parent;
Bounds bounds = ((Renderer)val).bounds;
transform.localPosition = localPosition - parent.InverseTransformPoint(((Bounds)(ref bounds)).center);
}
val2.Draw();
}
catch (Exception ex)
{
Debug.LogError((object)("FATAL ERROR in Decal Mod Postfix: " + ex.Message));
}
}
}