Decompiled source of RedTrailDyrnwyn v1.0.0

RedTrailDyrnwyn.dll

Decompiled 5 days ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
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("RedTrailDyrnwyn")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RedTrailDyrnwyn")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("86fbe7b7-46b4-4e7f-914c-d08eedfe3a1b")]
[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 RedTrailDyrnwyn;

[BepInPlugin("com.sbo.redtraildyrnwyn", "Red Trail Dyrnwyn Mod", "1.0.0")]
public class TrailModifierPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	public static class ObjectDB_Awake_Patch
	{
		public static void Postfix()
		{
			ModifyDyrnwynTrail();
		}
	}

	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	public static class ZNetScene_Awake_Patch
	{
		public static void Postfix()
		{
			ModifyDyrnwynTrail();
		}
	}

	private static bool s_isModified;

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.sbo.redtraildyrnwyn");
		val.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Red Trail Dyrnwyn 模組已成功載入!");
	}

	private static void ModifyDyrnwynTrail()
	{
		if (s_isModified || (Object)(object)ZNetScene.instance == (Object)null)
		{
			return;
		}
		GameObject prefab = ZNetScene.instance.GetPrefab("SwordDyrnwyn");
		if ((Object)(object)prefab == (Object)null)
		{
			return;
		}
		Component[] componentsInChildren = prefab.GetComponentsInChildren<Component>(true);
		foreach (Component val in componentsInChildren)
		{
			if (!((Object)(object)val != (Object)null) || !(((object)val).GetType().Name == "MeleeWeaponTrail"))
			{
				continue;
			}
			FieldInfo field = ((object)val).GetType().GetField("_material", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				Material gameMaterial = GetGameMaterial("red_trail");
				if ((Object)(object)gameMaterial != (Object)null)
				{
					field.SetValue(val, gameMaterial);
					Debug.Log((object)"[RedTrailDyrnwyn] 成功將 SwordDyrnwyn 的軌跡材質替換為 red_trail!");
					s_isModified = true;
					break;
				}
			}
		}
	}

	private static Material GetGameMaterial(string matName)
	{
		Material[] array = Resources.FindObjectsOfTypeAll<Material>();
		foreach (Material val in array)
		{
			if (((Object)val).name == matName)
			{
				return val;
			}
		}
		return null;
	}
}