Decompiled source of MagnusNecroSkin v1.0.0

MagnusNecroSkin.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MagnusNecroSkin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MagnusNecroSkin")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("50399f5b-19b4-4337-9e61-f3fb29683772")]
[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 MagnusNecroSkin;

[BepInPlugin("com.VotrePseudo.MagnusNecroSkin", "Magnus Necromancer Skin", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Globals), "GetSkinData")]
	private class SkinPatch
	{
		[HarmonyPostfix]
		public static void Postfix(string id, SkinData __result)
		{
			if (id.ToLower() == "magnuswolfwars" && (Object)(object)__result != (Object)null && (Object)(object)__result.SkinGo != (Object)null)
			{
				SpriteRenderer componentInChildren = __result.SkinGo.GetComponentInChildren<SpriteRenderer>();
				if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.sprite != (Object)null)
				{
					Log.LogInfo((object)"CIBLE TROUVÉE ! Remplacement de la texture originale...");
					Texture2D texture = componentInChildren.sprite.texture;
					ImageConversion.LoadImage(texture, necroTextureBytes);
					Log.LogInfo((object)"La texture originale a été modifiée en mémoire.");
				}
			}
		}
	}

	internal static ManualLogSource Log;

	internal static byte[] necroTextureBytes;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		necroTextureBytes = LoadResourceBytes("MagnusNecroSkin.Assets.necromancer.png");
		if (necroTextureBytes != null && necroTextureBytes.Length != 0)
		{
			Harmony.CreateAndPatchAll(typeof(SkinPatch), (string)null);
			Log.LogInfo((object)"Harmony patch for Necromancer skin is active!");
		}
		else
		{
			Log.LogError((object)"Failed to load the Necromancer skin texture bytes.");
		}
	}

	public static byte[] LoadResourceBytes(string resourcePath)
	{
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(resourcePath);
		if (manifestResourceStream == null)
		{
			if (Log != null)
			{
				Log.LogError((object)("Ressource introuvable : " + resourcePath));
			}
			return null;
		}
		using MemoryStream memoryStream = new MemoryStream();
		manifestResourceStream.CopyTo(memoryStream);
		return memoryStream.ToArray();
	}
}