Decompiled source of Carecs Sword v0.5.1

plugins/CarecsSword/CarecsSword.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace GreatFlameblade;

internal static class BusterWave
{
	public const string Prefab = "FerroBusterWave";

	public const int RequiredQuality = 5;

	public const float Speed = 30f;

	public const float Lifetime = 1.1f;

	public const float HitRadius = 2.6f;

	public const float DamageFactor = 0.6f;

	internal static readonly Color Glow = new Color(0.35f, 0.75f, 1f);

	private static GameObject prefab;

	private static readonly ConditionalWeakTable<Attack, object> Fired = new ConditionalWeakTable<Attack, object>();

	private static Texture2D softEdge;

	public static void Register(Action<string> log)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Expected O, but got Unknown
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Expected O, but got Unknown
		GameObject val = PrefabManager.Instance.CreateClonedPrefab("FerroBusterWave", "bow_projectile");
		if (!Object.op_Implicit((Object)(object)val))
		{
			log("Buster wave: bow_projectile not found, wave disabled.");
			return;
		}
		Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val2 in componentsInChildren)
		{
			val2.enabled = false;
		}
		ParticleSystem[] componentsInChildren2 = val.GetComponentsInChildren<ParticleSystem>(true);
		foreach (ParticleSystem val3 in componentsInChildren2)
		{
			EmissionModule emission = val3.emission;
			((EmissionModule)(ref emission)).enabled = false;
		}
		Projectile component = val.GetComponent<Projectile>();
		component.m_gravity = 0f;
		component.m_ttl = 1.1f;
		component.m_rayRadius = 2.6f;
		component.m_canHitWater = false;
		component.m_stayAfterHitStatic = false;
		component.m_stayAfterHitDynamic = false;
		component.m_spawnOnHit = null;
		GameObject val4 = new GameObject("BusterWave_Visual");
		val4.transform.SetParent(val.transform, false);
		val4.transform.localRotation = Quaternion.Euler(-75f, 0f, 0f);
		Material material = WaveMaterial(new Color(Glow.r, Glow.g, Glow.b, 0.55f));
		Material material2 = WaveMaterial(new Color(0.85f, 0.97f, 1f, 1f));
		Layer(val4, "Halo", Crescent(3.8f, 2f, 48), material);
		Layer(val4, "Core", Crescent(3.8f, 0.55f, 48), material2);
		Light val5 = val4.AddComponent<Light>();
		val5.type = (LightType)2;
		val5.color = Glow;
		val5.range = 14f;
		val5.intensity = 4f;
		val5.shadows = (LightShadows)0;
		val4.AddComponent<WaveFx>();
		PrefabManager.Instance.AddPrefab(new CustomPrefab(val, true));
		prefab = val;
		log("Registered FerroBusterWave (Rune Buster +" + 5 + " heavy attack wave).");
	}

	internal static Mesh Crescent(float radius, float thickness, int segments)
	{
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Expected O, but got Unknown
		Vector3[] array = (Vector3[])(object)new Vector3[(segments + 1) * 2];
		Vector2[] array2 = (Vector2[])(object)new Vector2[array.Length];
		int[] array3 = new int[segments * 12];
		Vector3 val = default(Vector3);
		Vector3 val2 = default(Vector3);
		for (int i = 0; i <= segments; i++)
		{
			float num = (float)i / (float)segments;
			float num2 = Mathf.Lerp(-72f, 72f, num) * ((float)Math.PI / 180f);
			float num3 = thickness * 0.5f * Mathf.Pow(Mathf.Sin(num * (float)Math.PI), 0.7f);
			((Vector3)(ref val))..ctor(Mathf.Sin(num2), 0f, Mathf.Cos(num2) - 1f);
			((Vector3)(ref val2))..ctor(Mathf.Sin(num2), 0f, Mathf.Cos(num2));
			Vector3 val3 = val * radius;
			ref Vector3 reference = ref array[i * 2];
			reference = val3 + val2 * num3;
			ref Vector3 reference2 = ref array[i * 2 + 1];
			reference2 = val3 - val2 * num3;
			ref Vector2 reference3 = ref array2[i * 2];
			reference3 = new Vector2(num, 0f);
			ref Vector2 reference4 = ref array2[i * 2 + 1];
			reference4 = new Vector2(num, 1f);
		}
		int j = 0;
		int num4 = 0;
		for (; j < segments; j++)
		{
			int num5 = j * 2;
			array3[num4++] = num5;
			array3[num4++] = num5 + 2;
			array3[num4++] = num5 + 1;
			array3[num4++] = num5 + 1;
			array3[num4++] = num5 + 2;
			array3[num4++] = num5 + 3;
			array3[num4++] = num5;
			array3[num4++] = num5 + 1;
			array3[num4++] = num5 + 2;
			array3[num4++] = num5 + 1;
			array3[num4++] = num5 + 3;
			array3[num4++] = num5 + 2;
		}
		Mesh val4 = new Mesh();
		((Object)val4).name = "BusterWave_Crescent";
		val4.vertices = array;
		val4.uv = array2;
		val4.triangles = array3;
		Mesh val5 = val4;
		val5.RecalculateNormals();
		val5.RecalculateBounds();
		return val5;
	}

	private static void Layer(GameObject parent, string name, Mesh mesh, Material material)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		GameObject val = new GameObject(name);
		val.transform.SetParent(parent.transform, false);
		val.AddComponent<MeshFilter>().sharedMesh = mesh;
		MeshRenderer val2 = val.AddComponent<MeshRenderer>();
		((Renderer)val2).sharedMaterial = material;
		((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
	}

	private static Texture2D SoftEdge()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)softEdge))
		{
			return softEdge;
		}
		Texture2D val = new Texture2D(64, 16, (TextureFormat)4, false);
		((Object)val).name = "BusterWave_SoftEdge";
		((Texture)val).wrapMode = (TextureWrapMode)1;
		softEdge = val;
		for (int i = 0; i < 64; i++)
		{
			for (int j = 0; j < 16; j++)
			{
				float num = (float)i / 63f;
				float num2 = (float)j / 15f;
				float num3 = Mathf.Pow(Mathf.Sin(num * (float)Math.PI), 0.5f) * Mathf.Pow(1f - Mathf.Abs(num2 * 2f - 1f), 0.7f);
				softEdge.SetPixel(i, j, new Color(1f, 1f, 1f, num3));
			}
		}
		softEdge.Apply();
		return softEdge;
	}

	private static Material WaveMaterial(Color color)
	{
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: 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_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		Material val = null;
		GameObject val2 = PrefabManager.Instance.GetPrefab("THSwordKrom");
		if (Object.op_Implicit((Object)(object)val2))
		{
			ParticleSystemRenderer[] componentsInChildren = val2.GetComponentsInChildren<ParticleSystemRenderer>(true);
			foreach (ParticleSystemRenderer val3 in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)((Renderer)val3).sharedMaterial))
				{
					val = ((Renderer)val3).sharedMaterial;
					break;
				}
			}
		}
		Material val4 = (Object.op_Implicit((Object)(object)val) ? new Material(val) : new Material(Shader.Find("Sprites/Default")));
		((Object)val4).name = "BusterWave_Glow";
		if (val4.HasProperty("_MainTex"))
		{
			val4.SetTexture("_MainTex", (Texture)(object)SoftEdge());
		}
		val4.mainTextureScale = Vector2.one;
		val4.mainTextureOffset = Vector2.zero;
		string[] array = new string[3] { "_Color", "_TintColor", "_BaseColor" };
		foreach (string text in array)
		{
			if (val4.HasProperty(text))
			{
				val4.SetColor(text, color);
			}
		}
		if (val4.HasProperty("_EmissionColor"))
		{
			val4.EnableKeyword("_EMISSION");
			val4.SetColor("_EmissionColor", color * 3f);
		}
		val4.renderQueue = 3100;
		return val4;
	}

	internal static bool IsHeavy(Attack attack, ItemData weapon)
	{
		SharedData shared = weapon.m_shared;
		if (attack.m_attackAnimation == shared.m_secondaryAttack.m_attackAnimation)
		{
			return shared.m_secondaryAttack.m_attackAnimation != shared.m_attack.m_attackAnimation;
		}
		return false;
	}

	internal static void TryFire(Attack attack, Humanoid owner, ItemData weapon)
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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_0096: 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)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)prefab) && !((Object)(object)owner == (Object)null) && !((Object)(object)owner != (Object)(object)Player.m_localPlayer) && weapon != null && Object.op_Implicit((Object)(object)weapon.m_dropPrefab) && !(((Object)weapon.m_dropPrefab).name != "FerroRuneBuster") && weapon.m_quality >= 5 && IsHeavy(attack, weapon) && !Fired.TryGetValue(attack, out var _))
		{
			Fired.Add(attack, true);
			Vector3 forward = ((Component)owner).transform.forward;
			Vector3 val = ((Component)owner).transform.position + Vector3.up * 1.2f + forward * 3f;
			GameObject val2 = Object.Instantiate<GameObject>(prefab, val, Quaternion.LookRotation(forward));
			HitData val3 = new HitData();
			val3.m_damage = weapon.GetDamage();
			((DamageTypes)(ref val3.m_damage)).Modify(0.6f);
			val3.m_skill = weapon.m_shared.m_skillType;
			val3.m_pushForce = 30f;
			val3.m_backstabBonus = 1f;
			val2.GetComponent<Projectile>().Setup((Character)(object)owner, forward * 30f, 10f, val3, weapon, (ItemData)null);
		}
	}
}
[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
internal static class BusterWaveTriggerPatch
{
	private static void Postfix(Attack __instance, Humanoid ___m_character, ItemData ___m_weapon)
	{
		BusterWave.TryFire(__instance, ___m_character, ___m_weapon);
	}
}
public sealed class WaveFx : MonoBehaviour
{
	private float born;

	private Light glow;

	private Renderer[] layers;

	private MaterialPropertyBlock block;

	private Color[] baseColors;

	private void Start()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		born = Time.time;
		glow = ((Component)this).GetComponent<Light>();
		layers = (Renderer[])(object)((Component)this).GetComponentsInChildren<MeshRenderer>();
		block = new MaterialPropertyBlock();
		baseColors = (Color[])(object)new Color[layers.Length];
		for (int i = 0; i < layers.Length; i++)
		{
			Material sharedMaterial = layers[i].sharedMaterial;
			ref Color reference = ref baseColors[i];
			reference = ((Object.op_Implicit((Object)(object)sharedMaterial) && sharedMaterial.HasProperty("_TintColor")) ? sharedMaterial.GetColor("_TintColor") : ((Object.op_Implicit((Object)(object)sharedMaterial) && sharedMaterial.HasProperty("_Color")) ? sharedMaterial.GetColor("_Color") : Color.white));
		}
	}

	private void Update()
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: 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)
		float num = Mathf.Clamp01((Time.time - born) / 1.1f);
		float num2 = 1f - Mathf.Pow(1f - num, 3f);
		((Component)this).transform.localScale = new Vector3(Mathf.Lerp(0.55f, 1.3f, num2), 1f, Mathf.Lerp(0.8f, 1.1f, num2));
		float num3 = ((num < 0.7f) ? 1f : (1f - (num - 0.7f) / 0.3f));
		float num4 = 0.85f + 0.15f * Mathf.Sin(Time.time * 40f);
		if (Object.op_Implicit((Object)(object)glow))
		{
			glow.intensity = 4f * num3 * num4;
		}
		for (int i = 0; i < layers.Length; i++)
		{
			Color val = baseColors[i];
			val.a *= num3 * num4;
			layers[i].GetPropertyBlock(block);
			block.SetColor("_Color", val);
			block.SetColor("_TintColor", val);
			layers[i].SetPropertyBlock(block);
		}
	}
}
[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
{
	typeof(ItemData),
	typeof(int),
	typeof(bool),
	typeof(float),
	typeof(int),
	typeof(bool)
})]
internal static class DespertarTooltipPatch
{
	private static readonly string[] Roman = new string[5] { "I", "II", "III", "IV", "V" };

	private static void Postfix(ItemData item, int qualityLevel, ref string __result)
	{
		if (item != null && Object.op_Implicit((Object)(object)item.m_dropPrefab) && !(((Object)item.m_dropPrefab).name != "FerroRuneBuster"))
		{
			int num = 5;
			int num2 = Mathf.Clamp(qualityLevel, 1, num);
			StringBuilder stringBuilder = new StringBuilder(__result);
			stringBuilder.Append("\n\n<color=#7fc8ff><b>Despertar ").Append(Roman[num2 - 1]).Append(" de ")
				.Append(Roman[num - 1])
				.Append("</b></color>");
			if (num2 >= num)
			{
				stringBuilder.Append("\n<color=#7fc8ff>Onda rúnica liberada:</color> o golpe carregado lança uma onda de energia.");
			}
			else
			{
				stringBuilder.Append("\nNo ").Append(Roman[num - 1]).Append(": onda rúnica no golpe carregado.");
			}
			__result = stringBuilder.ToString();
		}
	}
}
internal sealed class DiagnosticsCommand : ConsoleCommand
{
	private static readonly string[] Candidates = new string[16]
	{
		"ArmorBerserkerChest", "ArmorBerserkerLegs", "ArmorWolfChest", "ArmorWolfLegs", "ArmorRagsChest", "ArmorRagsLegs", "ArmorLeatherChest", "ArmorLeatherLegs", "ArmorTrollLeatherChest", "ArmorTrollLeatherLegs",
		"ArmorFenringChest", "ArmorFenringLegs", "ArmorTunic1", "ArmorDeepNorthMediumChest", "ArmorDeepNorthMediumlegs", "CapeWolf"
	};

	public override string Name => "gfb_bones";

	public override string Help => "gfb_bones - writes skeleton and armour info to BepInEx/GreatFlameblade-diagnostics.txt";

	public override void Run(string[] args)
	{
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!Object.op_Implicit((Object)(object)localPlayer))
		{
			Console.instance.Print("Enter a world first.");
			return;
		}
		StringBuilder stringBuilder = new StringBuilder();
		VisEquipment component = ((Component)localPlayer).GetComponent<VisEquipment>();
		SkinnedMeshRenderer val = (Object.op_Implicit((Object)(object)component) ? component.m_bodyModel : null);
		stringBuilder.AppendLine("== Body model: " + (Object.op_Implicit((Object)(object)val) ? (((Object)val).name + " (" + val.sharedMesh.vertexCount + " verts, " + val.bones.Length + " bones)") : "not found"));
		if (Object.op_Implicit((Object)(object)val))
		{
			Transform val2 = (Object.op_Implicit((Object)(object)val.rootBone) ? val.rootBone : val.bones[0]);
			while (Object.op_Implicit((Object)(object)val2.parent) && (Object)(object)val2.parent != (Object)(object)((Component)localPlayer).transform)
			{
				val2 = val2.parent;
			}
			Dump(val2, 0, stringBuilder, ((Component)localPlayer).transform);
		}
		stringBuilder.AppendLine();
		stringBuilder.AppendLine("== Attach points on VisEquipment");
		if (Object.op_Implicit((Object)(object)component))
		{
			FieldInfo[] fields = typeof(VisEquipment).GetFields();
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.FieldType == typeof(Transform))
				{
					object? value = fieldInfo.GetValue(component);
					Transform val3 = (Transform)((value is Transform) ? value : null);
					stringBuilder.AppendLine(fieldInfo.Name + " = " + (Object.op_Implicit((Object)(object)val3) ? Path(val3, ((Component)localPlayer).transform) : "null"));
				}
			}
		}
		stringBuilder.AppendLine();
		stringBuilder.AppendLine("== Candidate vanilla armour");
		string[] candidates = Candidates;
		foreach (string text in candidates)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(text);
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				stringBuilder.AppendLine(text + ": not found");
				continue;
			}
			ItemDrop component2 = prefab.GetComponent<ItemDrop>();
			SharedData val4 = (Object.op_Implicit((Object)(object)component2) ? component2.m_itemData.m_shared : null);
			stringBuilder.AppendLine(text + ": type " + ((val4 != null) ? ((object)val4.m_itemType).ToString() : "?") + ", armor " + ((val4 != null) ? val4.m_armor.ToString() : "?") + ", armorMaterial " + ((val4 != null && Object.op_Implicit((Object)(object)val4.m_armorMaterial)) ? ((Object)val4.m_armorMaterial).name : "none"));
			Transform[] componentsInChildren = prefab.GetComponentsInChildren<Transform>(true);
			foreach (Transform val5 in componentsInChildren)
			{
				SkinnedMeshRenderer component3 = ((Component)val5).GetComponent<SkinnedMeshRenderer>();
				MeshFilter component4 = ((Component)val5).GetComponent<MeshFilter>();
				if (Object.op_Implicit((Object)(object)component3) || Object.op_Implicit((Object)(object)component4))
				{
					Material val6 = (Object.op_Implicit((Object)(object)component3) ? ((Renderer)component3).sharedMaterial : (Object.op_Implicit((Object)(object)((Component)val5).GetComponent<Renderer>()) ? ((Component)val5).GetComponent<Renderer>().sharedMaterial : null));
					stringBuilder.AppendLine("  " + Path(val5, prefab.transform) + (Object.op_Implicit((Object)(object)component3) ? (" [skinned " + component3.sharedMesh.vertexCount + " verts, " + component3.bones.Length + " bones]") : " [mesh]") + " material " + (Object.op_Implicit((Object)(object)val6) ? (((Object)val6).name + " / " + ((Object)val6.shader).name + " / tex " + (Object.op_Implicit((Object)(object)val6.mainTexture) ? (((Object)val6.mainTexture).name + " " + val6.mainTexture.width + "x" + val6.mainTexture.height) : "none")) : "none"));
				}
			}
		}
		string text2 = System.IO.Path.Combine(Paths.BepInExRootPath, "GreatFlameblade-diagnostics.txt");
		File.WriteAllText(text2, stringBuilder.ToString());
		Console.instance.Print("Diagnostics written to " + text2);
	}

	private static void Dump(Transform t, int depth, StringBuilder text, Transform root)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Expected O, but got Unknown
		text.Append(' ', depth * 2).Append(((Object)t).name);
		Vector3 val = t.position - root.position;
		text.AppendLine("  (" + val.x.ToString("0.00") + ", " + val.y.ToString("0.00") + ", " + val.z.ToString("0.00") + ")");
		foreach (Transform item in t)
		{
			Transform t2 = item;
			Dump(t2, depth + 1, text, root);
		}
	}

	private static string Path(Transform t, Transform root)
	{
		string text = ((Object)t).name;
		Transform parent = t.parent;
		while (Object.op_Implicit((Object)(object)parent) && (Object)(object)parent != (Object)(object)root)
		{
			text = ((Object)parent).name + "/" + text;
			parent = parent.parent;
		}
		return text;
	}
}
internal sealed class FxCommand : ConsoleCommand
{
	public override string Name => "gfb_fx";

	public override string Help => "gfb_fx <prefab> - plays a vanilla effect in front of you (Great Flameblade)";

	public override void Run(string[] args)
	{
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!Object.op_Implicit((Object)(object)localPlayer))
		{
			return;
		}
		if (args.Length == 0)
		{
			for (int i = 0; i < Plugin.Explosions.Length; i++)
			{
				Console.instance.Print("Thrust tier " + i + ": " + string.Join(", ", Plugin.Explosions[i]));
			}
		}
		else
		{
			Vector3 point = ((Component)localPlayer).transform.position + ((Component)localPlayer).transform.forward * 3f + Vector3.up;
			Console.instance.Print(Object.op_Implicit((Object)(object)Plugin.Spawn(args[0], point)) ? ("Played " + args[0]) : ("Not found: " + args[0]));
		}
	}

	public override List<string> CommandOptionList()
	{
		List<string> list = new List<string>();
		string[][] explosions = Plugin.Explosions;
		foreach (string[] collection in explosions)
		{
			list.AddRange(collection);
		}
		list.AddRange(new string[4] { "fx_DvergerMage_Fire_hit", "fx_fader_meteor_hit", "fx_Fader_CorpseExplosion", "fx_fimbulvinter_meteor_hit" });
		return list;
	}
}
[HarmonyPatch(typeof(Smelter), "Awake")]
internal static class KilnWoodsPatch
{
	private static readonly string[] Woods = new string[5] { "Wood", "FineWood", "RoundLog", "YggdrasilWood", "Blackwood" };

	[HarmonyPriority(0)]
	private static void Postfix(Smelter __instance)
	{
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Expected O, but got Unknown
		if (!((Object)__instance).name.StartsWith("charcoal_kiln") || (Object)(object)ObjectDB.instance == (Object)null)
		{
			return;
		}
		ItemDrop val = Drop("Coal");
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		string[] woods = Woods;
		foreach (string name in woods)
		{
			ItemDrop from = Drop(name);
			if (!((Object)(object)from == (Object)null) && !__instance.m_conversion.Exists((ItemConversion c) => Object.op_Implicit((Object)(object)c.m_from) && ((Object)c.m_from).name == ((Object)from).name))
			{
				List<ItemConversion> conversion = __instance.m_conversion;
				ItemConversion val2 = new ItemConversion();
				val2.m_from = from;
				val2.m_to = val;
				conversion.Add(val2);
			}
		}
	}

	private static ItemDrop Drop(string name)
	{
		GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(name);
		if (!Object.op_Implicit((Object)(object)itemPrefab))
		{
			return null;
		}
		return itemPrefab.GetComponent<ItemDrop>();
	}
}
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInPlugin("br.ferro.greatflameblade", "Carec's Sword", "0.5.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	public const string Guid = "br.ferro.greatflameblade";

	public const string Prefab = "FerroGreatFlameblade";

	internal const string ItemName = "Great Flameblade";

	internal const string HeatKey = "ferro_gfb_heat";

	internal const float FireRatio = 1f / 3f;

	internal const float SpecialFireRatio = 1.3333334f;

	private Harmony harmony;

	internal static readonly ConditionalWeakTable<Player, HeatState> States = new ConditionalWeakTable<Player, HeatState>();

	internal static readonly ConditionalWeakTable<Attack, AttackInfo> Attacks = new ConditionalWeakTable<Attack, AttackInfo>();

	internal static readonly FieldInfo CurrentAttack = AccessTools.Field(typeof(Humanoid), "m_currentAttack");

	internal static readonly string[][] Explosions = new string[3][]
	{
		new string[2] { "vfx_FireballHit", "sfx_imp_fireball_explode" },
		new string[1] { "fx_shaman_fireball_expl" },
		new string[1] { "fx_goblinking_meteor_hit" }
	};

	internal static ManualLogSource Log;

	private static readonly HashSet<string> missing = new HashSet<string>();

	internal static HeatState Heat(Player p)
	{
		return States.GetValue(p, (Player owner) => new HeatState
		{
			Owner = owner
		});
	}

	internal static float HeatStep(Player p)
	{
		return 1f / 6f;
	}

	internal static void Explode(Vector3 point, float heat)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		string[] array = Explosions[(heat >= 0.999f) ? 2 : ((heat >= 0.5f) ? 1 : 0)];
		foreach (string name in array)
		{
			Spawn(name, point);
		}
	}

	internal static void ExplodeAhead(Player player, float heat)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		Explode(((Component)player).transform.position + ((Component)player).transform.forward * 2.2f + Vector3.up, heat);
	}

	internal static GameObject Spawn(string name, Vector3 point)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		GameObject prefab = PrefabManager.Instance.GetPrefab(name);
		if (!Object.op_Implicit((Object)(object)prefab))
		{
			if (missing.Add(name) && Log != null)
			{
				Log.LogWarning((object)("Effect prefab not found: " + name));
			}
			return null;
		}
		return Object.Instantiate<GameObject>(prefab, point, Quaternion.identity);
	}

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		harmony = new Harmony("br.ferro.greatflameblade");
		harmony.PatchAll(typeof(Plugin).Assembly);
		PrefabManager.OnVanillaPrefabsAvailable += Register;
		SwordModel.Log = ((BaseUnityPlugin)this).Logger.LogInfo;
		Log = ((BaseUnityPlugin)this).Logger;
		CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new FxCommand());
		CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new DiagnosticsCommand());
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Carec's Sword 0.5.1: multiplayer alpha loaded.");
	}

	private void OnDestroy()
	{
		PrefabManager.OnVanillaPrefabsAvailable -= Register;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	private void Register()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Expected O, but got Unknown
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Invalid comparison between Unknown and I4
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Invalid comparison between Unknown and I4
		PrefabManager.OnVanillaPrefabsAvailable -= Register;
		try
		{
			if (!Object.op_Implicit((Object)(object)PrefabManager.Instance.GetPrefab("THSwordKrom")))
			{
				throw new InvalidOperationException("THSwordKrom unavailable; cannot create two-handed sword.");
			}
			ItemConfig val = new ItemConfig();
			val.Name = "Great Flameblade";
			val.Description = "Espada de duas mãos que esquenta a cada golpe. No calor máximo os golpes causam fogo. A estocada (ataque secundário) libera todo o calor acumulado: dano proporcional ao calor.";
			val.CraftingStation = "blackforge";
			val.MinStationLevel = 1;
			ItemConfig val2 = val;
			val2.AddRequirement("Iron", 30, 10);
			val2.AddRequirement("Bronze", 15, 5);
			val2.AddRequirement("SurtlingCore", 5, 2);
			CustomItem val3 = new CustomItem("FerroGreatFlameblade", "THSwordKrom", val2);
			SharedData shared = val3.ItemDrop.m_itemData.m_shared;
			shared.m_maxQuality = 4;
			shared.m_weight = 4f;
			shared.m_damages = new DamageTypes
			{
				m_slash = 105f
			};
			shared.m_damagesPerLevel = new DamageTypes
			{
				m_slash = 6f
			};
			shared.m_attackStatusEffect = null;
			shared.m_attack.m_attackStamina = 18f;
			shared.m_secondaryAttack.m_attackStamina = 30f;
			shared.m_secondaryAttack.m_damageMultiplier = 1f;
			SwordModel.Replace(val3.ItemPrefab);
			if (!ItemManager.Instance.AddItem(val3))
			{
				throw new InvalidOperationException("Item registration failed.");
			}
			if ((int)SystemInfo.graphicsDeviceType != 4)
			{
				Sprite val4 = RenderManager.Instance.Render(val3.ItemPrefab);
				if (Object.op_Implicit((Object)(object)val4))
				{
					shared.m_icons = (Sprite[])(object)new Sprite[1] { val4 };
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered FerroGreatFlameblade; heat builds per hit, thrust releases it.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Great Flameblade registration failed: " + ex));
		}
		try
		{
			CustomItem val5 = RuneBuster.Create((Action<string>)((BaseUnityPlugin)this).Logger.LogInfo);
			if (!ItemManager.Instance.AddItem(val5))
			{
				throw new InvalidOperationException("Item registration failed.");
			}
			if ((int)SystemInfo.graphicsDeviceType != 4)
			{
				Sprite val6 = RenderManager.Instance.Render(val5.ItemPrefab);
				if (Object.op_Implicit((Object)(object)val6))
				{
					val5.ItemDrop.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { val6 };
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered FerroRuneBuster; Bone Bastard Sword moveset is copied once Warfare items are loaded.");
		}
		catch (Exception ex2)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Rune Buster registration failed: " + ex2));
		}
		try
		{
			BusterWave.Register((Action<string>)((BaseUnityPlugin)this).Logger.LogInfo);
		}
		catch (Exception ex3)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Buster wave registration failed: " + ex3));
		}
	}

	internal static bool IsSword(ItemData item)
	{
		if (item != null && Object.op_Implicit((Object)(object)item.m_dropPrefab))
		{
			return ((Object)item.m_dropPrefab).name == "FerroGreatFlameblade";
		}
		return false;
	}

	internal static bool Unsafe(Player p)
	{
		if (!((Character)p).IsDead() && !((Character)p).IsTeleporting() && !((Character)p).IsStaggering() && !((Character)p).InDodge() && !((Character)p).IsSwimming() && !((Character)p).InPlaceMode() && !InventoryGui.IsVisible() && !Menu.IsVisible() && !Console.IsVisible() && !TextInput.IsVisible() && !StoreGui.IsVisible() && !Minimap.IsOpen() && (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()))
		{
			return !Application.isFocused;
		}
		return true;
	}

	private void Update()
	{
		Player localPlayer = Player.m_localPlayer;
		if (Object.op_Implicit((Object)(object)localPlayer) && States.TryGetValue(localPlayer, out var value))
		{
			value.Cool(Time.time, Time.deltaTime);
		}
	}

	private void OnGUI()
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (Object.op_Implicit((Object)(object)localPlayer) && IsSword(((Humanoid)localPlayer).GetCurrentWeapon()) && !Unsafe(localPlayer) && States.TryGetValue(localPlayer, out var value) && Time.time < value.ColdMessageUntil)
		{
			GUI.Box(new Rect((float)Screen.width / 2f - 200f, (float)Screen.height * 0.76f, 400f, 32f), "A espada está fria  •  golpeie para aquecer");
		}
	}
}
internal sealed class HeatState
{
	public const float PerHit = 1f / 6f;

	public const float SpecialMinimum = 0.05f;

	public const float CoolDelay = 8f;

	public const float CoolSeconds = 60f;

	public const float CoolRate = 1f / 52f;

	public float Heat;

	public float LastHit = -1000f;

	public float ColdMessageUntil;

	public Player Owner;

	private int published = -1;

	public bool Full => Heat >= 0.999f;

	public void AddHit(float now, float step)
	{
		Heat = Math.Min(1f, Heat + step);
		LastHit = now;
		Publish();
	}

	public float Release()
	{
		float heat = Heat;
		Heat = 0f;
		Publish();
		return heat;
	}

	public void Cool(float now, float deltaTime)
	{
		if (!(Heat <= 0f) && !(now - LastHit < 8f))
		{
			Heat = Math.Max(0f, Heat - 1f / 52f * deltaTime);
			Publish();
		}
	}

	public void Publish()
	{
		int num = (int)Math.Round(Heat * 100f);
		if (num != published && Object.op_Implicit((Object)(object)Owner))
		{
			ZNetView component = ((Component)Owner).GetComponent<ZNetView>();
			if (Object.op_Implicit((Object)(object)component) && component.IsOwner() && component.GetZDO() != null)
			{
				component.GetZDO().Set("ferro_gfb_heat", num);
				published = num;
			}
		}
	}
}
internal sealed class AttackInfo
{
	public bool Secondary;

	public bool Hit;

	public bool Exploded;

	public bool Released;

	public float Heat;
}
[HarmonyPatch(typeof(Humanoid), "StartAttack")]
internal static class StartAttackPatch
{
	private static bool Prefix(Humanoid __instance, bool secondaryAttack, ref bool __result)
	{
		Player val = (Player)(object)((__instance is Player) ? __instance : null);
		if (!secondaryAttack || (Object)(object)val != (Object)(object)Player.m_localPlayer || !Object.op_Implicit((Object)(object)val) || !Plugin.IsSword(((Humanoid)val).GetCurrentWeapon()))
		{
			return true;
		}
		HeatState heatState = Plugin.Heat(val);
		if (heatState.Heat >= 0.05f)
		{
			return true;
		}
		heatState.ColdMessageUntil = Time.time + 2f;
		__result = false;
		return false;
	}

	private static void Postfix(Humanoid __instance, bool secondaryAttack, bool __result)
	{
		Player val = (Player)(object)((__instance is Player) ? __instance : null);
		if (__result && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)val) && Plugin.IsSword(((Humanoid)val).GetCurrentWeapon()))
		{
			object? value = Plugin.CurrentAttack.GetValue(val);
			Attack val2 = (Attack)((value is Attack) ? value : null);
			if (val2 != null)
			{
				HeatState heatState = Plugin.Heat(val);
				Plugin.Attacks.Remove(val2);
				Plugin.Attacks.Add(val2, new AttackInfo
				{
					Secondary = secondaryAttack,
					Heat = heatState.Heat
				});
			}
		}
	}
}
[HarmonyPatch(typeof(Attack), "ModifyDamage")]
internal static class DamagePatch
{
	private static void Postfix(Attack __instance, HitData hitData)
	{
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.Attacks.TryGetValue(__instance, out var value))
		{
			return;
		}
		float num = hitData.m_damage.m_slash + hitData.m_damage.m_pierce + hitData.m_damage.m_blunt;
		if (value.Secondary)
		{
			ref DamageTypes damage = ref hitData.m_damage;
			damage.m_slash *= value.Heat;
			ref DamageTypes damage2 = ref hitData.m_damage;
			damage2.m_pierce *= value.Heat;
			ref DamageTypes damage3 = ref hitData.m_damage;
			damage3.m_blunt *= value.Heat;
			ref DamageTypes damage4 = ref hitData.m_damage;
			damage4.m_fire += num * 1.3333334f * value.Heat;
			if (!value.Exploded)
			{
				value.Exploded = true;
				Plugin.Explode(hitData.m_point, value.Heat);
			}
			return;
		}
		if (value.Heat >= 0.999f)
		{
			ref DamageTypes damage5 = ref hitData.m_damage;
			damage5.m_fire += num * (1f / 3f);
		}
		if (!value.Hit)
		{
			value.Hit = true;
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer))
			{
				Plugin.Heat(localPlayer).AddHit(Time.time, Plugin.HeatStep(localPlayer));
			}
		}
	}
}
[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
internal static class ThrustTriggerPatch
{
	private static void Postfix(Attack __instance)
	{
		if (Plugin.Attacks.TryGetValue(__instance, out var value) && value.Secondary && !value.Exploded)
		{
			value.Exploded = true;
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer))
			{
				Plugin.ExplodeAhead(localPlayer, value.Heat);
			}
		}
	}
}
[HarmonyPatch(typeof(Attack), "Stop")]
internal static class AttackStopPatch
{
	private static void Postfix(Attack __instance)
	{
		if (Plugin.Attacks.TryGetValue(__instance, out var value) && value.Secondary && !value.Released)
		{
			value.Released = true;
			Player localPlayer = Player.m_localPlayer;
			if (Object.op_Implicit((Object)(object)localPlayer))
			{
				Plugin.Heat(localPlayer).Release();
			}
		}
	}
}
internal static class RuneBuster
{
	public const string Prefab = "FerroRuneBuster";

	internal const string ItemName = "Buster Rúnica";

	internal const string MovesetDonor = "BastardBone_TW";

	private static readonly string[] SpinDonors = new string[3] { "AtgeirIron", "AtgeirBronze", "AtgeirBlackmetal" };

	private static Mesh mesh;

	private static Texture2D albedo;

	private static Texture2D emission;

	private static Texture2D metallic;

	private static Texture2D normal;

	private static SharedData shared;

	private static Action<string> log;

	private static bool copied;

	public static CustomItem Create(Action<string> logger)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		log = logger;
		ItemConfig val = new ItemConfig();
		val.Name = "Buster Rúnica";
		val.Description = "Montante de ferro martelado com uma inscrição rúnica no canal da lâmina. Duas mãos. Ataque pesado (botão do meio): golpe carregado em área. No nível máximo (5), o golpe carregado também lança uma onda de energia rúnica.";
		val.CraftingStation = "forge";
		val.MinStationLevel = 2;
		ItemConfig val2 = val;
		val2.AddRequirement("Iron", 15, 5);
		val2.AddRequirement("FineWood", 8, 2);
		val2.AddRequirement("BjornHide", 3, 1);
		val2.AddRequirement("GreydwarfEye", 6, 2);
		CustomItem val3 = new CustomItem("FerroRuneBuster", "THSwordKrom", val2);
		shared = val3.ItemDrop.m_itemData.m_shared;
		shared.m_maxQuality = 5;
		shared.m_weight = 5f;
		shared.m_damages = new DamageTypes
		{
			m_slash = 90f
		};
		shared.m_damagesPerLevel = new DamageTypes
		{
			m_slash = 6f
		};
		shared.m_attackStatusEffect = null;
		shared.m_animationState = (AnimationState)2;
		GameObject prefab = PrefabManager.Instance.GetPrefab("Battleaxe");
		ItemDrop val4 = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<ItemDrop>() : null);
		if ((Object)(object)val4 != (Object)null)
		{
			shared.m_attack = val4.m_itemData.m_shared.m_attack.Clone();
		}
		shared.m_secondaryAttack = Spin(shared.m_secondaryAttack, logger);
		Replace(val3.ItemPrefab);
		return val3;
	}

	internal static void CopyMoveset(ObjectDB db)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		if (shared == null || (Object)(object)db == (Object)null)
		{
			return;
		}
		GameObject itemPrefab = db.GetItemPrefab("BastardBone_TW");
		ItemDrop val = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		SharedData val2 = val.m_itemData.m_shared;
		shared.m_animationState = val2.m_animationState;
		shared.m_attack = val2.m_attack.Clone();
		shared.m_secondaryAttack = val2.m_secondaryAttack.Clone();
		if (!copied)
		{
			copied = true;
			if (log != null)
			{
				log(string.Concat("Moveset copied from BastardBone_TW: grip ", val2.m_animationState, ", attack ", val2.m_attack.m_attackAnimation, ", heavy ", val2.m_secondaryAttack.m_attackAnimation, " x", val2.m_secondaryAttack.m_damageMultiplier));
			}
		}
	}

	private static Attack Spin(Attack fallback, Action<string> log)
	{
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		string[] spinDonors = SpinDonors;
		foreach (string text in spinDonors)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(text);
			ItemDrop val = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<ItemDrop>() : null);
			if (!((Object)(object)val == (Object)null))
			{
				Attack val2 = val.m_itemData.m_shared.m_secondaryAttack.Clone();
				val2.m_attackStamina = 30f;
				log(string.Concat("Heavy attack copied from ", text, ": animation ", val2.m_attackAnimation, ", type ", val2.m_attackType, ", range ", val2.m_attackRange, ", angle ", val2.m_attackAngle, ", damage x", val2.m_damageMultiplier));
				return val2;
			}
		}
		log("No atgeir found; heavy attack falls back to the Krom secondary.");
		return fallback;
	}

	private static void Replace(GameObject prefab)
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)mesh))
		{
			mesh = SwordModel.LoadMesh("RuneBuster.mesh", "RuneBuster_Blender");
		}
		if (!Object.op_Implicit((Object)(object)albedo))
		{
			albedo = SwordModel.LoadTexture("RuneBuster_albedo.jpg", linear: false);
			emission = SwordModel.LoadTexture("RuneBuster_emission.png", linear: false);
			metallic = SwordModel.LoadTexture("RuneBuster_metallic.png", linear: true);
			normal = SwordModel.LoadNormal("RuneBuster_normal.png");
		}
		Material source;
		GameObject val = SwordModel.Mount(prefab, "RuneBuster_BlenderModel", mesh, out source);
		Transform transform = val.transform;
		transform.localRotation *= Quaternion.AngleAxis(180f, Vector3.forward);
		((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = SwordModel.BakedMaterial(source, "RuneBuster_BakedIron", albedo, emission, metallic, normal, 2.2f, 1f);
	}
}
[HarmonyPatch(typeof(ObjectDB), "Awake")]
internal static class BusterMovesetAwakePatch
{
	[HarmonyPriority(0)]
	private static void Postfix(ObjectDB __instance)
	{
		RuneBuster.CopyMoveset(__instance);
	}
}
[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
internal static class BusterMovesetCopyPatch
{
	[HarmonyPriority(0)]
	private static void Postfix(ObjectDB __instance)
	{
		RuneBuster.CopyMoveset(__instance);
	}
}
internal static class SwordModel
{
	private static Mesh mesh;

	private static Texture2D albedo;

	private static Texture2D emission;

	private static Texture2D metallic;

	private static Texture2D normal;

	internal static Action<string> Log;

	private static bool shaderLogged;

	public static void Replace(GameObject prefab)
	{
		if (!Object.op_Implicit((Object)(object)mesh))
		{
			mesh = LoadMesh("GreatFlameblade.gfbmesh", "GreatFlameblade_Blender");
		}
		if (!Object.op_Implicit((Object)(object)albedo))
		{
			albedo = LoadTexture("albedo.png", linear: false);
			emission = LoadTexture("emission.png", linear: false);
			metallic = LoadTexture("metallic.png", linear: true);
			normal = LoadNormal("normal.png");
		}
		Material source;
		GameObject val = Mount(prefab, "GreatFlameblade_BlenderModel", mesh, out source);
		((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = BakedMaterial(source, "GFB_BakedMetal", albedo, emission, metallic, normal, 1.3f, 1f);
		val.AddComponent<EmberLight>();
	}

	internal static GameObject Mount(GameObject prefab, string name, Mesh model, out Material source)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Expected O, but got Unknown
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: 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)
		//IL_00b7: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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)
		Transform val = prefab.transform.Find("attach");
		if (!Object.op_Implicit((Object)(object)val))
		{
			throw new InvalidOperationException("Krom attach transform not found.");
		}
		Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
		source = null;
		Bounds val2 = default(Bounds);
		((Bounds)(ref val2))..ctor(Vector3.zero, Vector3.zero);
		bool flag = false;
		MeshFilter[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<MeshFilter>(true);
		foreach (MeshFilter val3 in componentsInChildren2)
		{
			if (!Object.op_Implicit((Object)(object)val3.sharedMesh))
			{
				continue;
			}
			Bounds bounds = val3.sharedMesh.bounds;
			for (int j = 0; j < 8; j++)
			{
				Vector3 val4 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
				val4 = val.InverseTransformPoint(((Component)val3).transform.TransformPoint(val4));
				if (!flag)
				{
					val2 = new Bounds(val4, Vector3.zero);
					flag = true;
				}
				else
				{
					((Bounds)(ref val2)).Encapsulate(val4);
				}
			}
		}
		source = LitMaterial(componentsInChildren);
		LogShader(source, componentsInChildren);
		GameObject val5 = new GameObject(name);
		val5.layer = ((Component)val).gameObject.layer;
		val5.transform.SetParent(val, false);
		Vector3 size = ((Bounds)(ref val2)).size;
		Vector3 val6 = ((size.z >= size.x && size.z >= size.y) ? Vector3.forward : ((size.y >= size.x) ? Vector3.up : Vector3.right));
		if (Vector3.Dot(((Bounds)(ref val2)).center, val6) < 0f)
		{
			val6 = -val6;
		}
		val5.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, val6);
		float num = Mathf.Max(size.x, Mathf.Max(size.y, size.z));
		Transform transform = val5.transform;
		Vector3 one = Vector3.one;
		float num2;
		if (!flag)
		{
			num2 = 1f;
		}
		else
		{
			Bounds bounds2 = model.bounds;
			num2 = Mathf.Clamp(num / ((Bounds)(ref bounds2)).size.z, 0.65f, 1.5f);
		}
		transform.localScale = one * num2;
		val5.AddComponent<MeshFilter>().sharedMesh = model;
		Renderer[] array = componentsInChildren;
		foreach (Renderer val7 in array)
		{
			val7.enabled = false;
		}
		return val5;
	}

	private static Material LitMaterial(Renderer[] renderers)
	{
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		Material result = null;
		float num = -1f;
		foreach (Renderer val in renderers)
		{
			Material sharedMaterial = val.sharedMaterial;
			if (Object.op_Implicit((Object)(object)sharedMaterial) && !(val is ParticleSystemRenderer) && ((Object)sharedMaterial.shader).name.IndexOf("Particle", StringComparison.OrdinalIgnoreCase) < 0)
			{
				MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
				float num2;
				if (!(val is SkinnedMeshRenderer) && Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMesh))
				{
					Bounds bounds = component.sharedMesh.bounds;
					Vector3 size = ((Bounds)(ref bounds)).size;
					num2 = ((Vector3)(ref size)).sqrMagnitude;
				}
				else
				{
					num2 = 0f;
				}
				float num3 = num2;
				if (num3 > num)
				{
					result = sharedMaterial;
					num = num3;
				}
			}
		}
		return result;
	}

	private static void LogShader(Material m, Renderer[] renderers)
	{
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Invalid comparison between Unknown and I4
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Invalid comparison between Unknown and I4
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		if (shaderLogged || Log == null)
		{
			return;
		}
		shaderLogged = true;
		StringBuilder stringBuilder = new StringBuilder("Krom renderers:");
		foreach (Renderer val in renderers)
		{
			stringBuilder.Append(' ').Append(((Object)val).name).Append('/')
				.Append(((object)val).GetType().Name)
				.Append('=')
				.Append(Object.op_Implicit((Object)(object)val.sharedMaterial) ? (((Object)val.sharedMaterial).name + " (" + ((Object)val.sharedMaterial.shader).name + ")") : "none");
		}
		Log(stringBuilder.ToString());
		if ((Object)(object)m == (Object)null)
		{
			Log("No lit Krom material found; falling back to Standard.");
			return;
		}
		StringBuilder stringBuilder2 = new StringBuilder();
		Shader shader = m.shader;
		for (int j = 0; j < shader.GetPropertyCount(); j++)
		{
			string propertyName = shader.GetPropertyName(j);
			ShaderPropertyType propertyType = shader.GetPropertyType(j);
			stringBuilder2.Append(' ').Append(propertyName).Append('=');
			if ((int)propertyType == 4)
			{
				stringBuilder2.Append(Object.op_Implicit((Object)(object)m.GetTexture(propertyName)) ? ((Object)m.GetTexture(propertyName)).name : "none");
			}
			else if ((int)propertyType == 0)
			{
				stringBuilder2.Append(m.GetColor(propertyName));
			}
			else if ((int)propertyType == 1)
			{
				stringBuilder2.Append(m.GetVector(propertyName));
			}
			else
			{
				stringBuilder2.Append(m.GetFloat(propertyName));
			}
		}
		Log("Krom material " + ((Object)m).name + " uses shader " + ((Object)shader).name + "; keywords [" + string.Join(",", m.shaderKeywords) + "];" + stringBuilder2);
	}

	internal static Material BakedMaterial(Material source, string name, Texture2D albedo, Texture2D emission, Texture2D metallic, Texture2D normal, float glow, float metalness)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: 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)
		Material val = (Object.op_Implicit((Object)(object)source) ? new Material(source) : new Material(Shader.Find("Standard")));
		((Object)val).name = name;
		val.mainTextureScale = Vector2.one;
		val.mainTextureOffset = Vector2.zero;
		SetTexture(val, "_MainTex", (Texture)(object)albedo);
		SetTexture(val, "_EmissionMap", (Texture)(object)emission);
		SetTexture(val, "_MetallicGlossMap", (Texture)(object)metallic);
		SetTexture(val, "_BumpMap", (Texture)(object)normal);
		SetColor(val, "_Color", Color.white);
		SetColor(val, "_EmissionColor", Color.white * glow);
		SetFloat(val, "_Metallic", metalness);
		SetFloat(val, "_GlossMapScale", 1f);
		SetFloat(val, "_Glossiness", 0.45f);
		SetFloat(val, "_BumpScale", 0.7f);
		val.EnableKeyword("_EMISSION");
		val.EnableKeyword("_NORMALMAP");
		val.EnableKeyword("_METALLICGLOSSMAP");
		val.DisableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A");
		return val;
	}

	internal static Texture2D LoadNormal(string filename)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = LoadTexture(filename, linear: true);
		Color[] pixels = val.GetPixels();
		for (int i = 0; i < pixels.Length; i++)
		{
			ref Color reference = ref pixels[i];
			reference = new Color(1f, pixels[i].g, 1f, pixels[i].r);
		}
		val.SetPixels(pixels);
		val.Apply(true, true);
		return val;
	}

	internal static byte[] Resource(string filename)
	{
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("GreatFlameblade." + filename);
		if (stream == null)
		{
			throw new FileNotFoundException("Missing embedded Blender asset: " + filename);
		}
		using MemoryStream memoryStream = new MemoryStream();
		stream.CopyTo(memoryStream);
		return memoryStream.ToArray();
	}

	internal static Texture2D LoadTexture(string filename, bool linear)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear);
		((Object)val).name = "GFB_" + filename;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Texture)val).anisoLevel = 4;
		if (!ImageConversion.LoadImage(val, Resource(filename), false))
		{
			throw new InvalidDataException("Invalid texture: " + filename);
		}
		return val;
	}

	internal static Mesh LoadMesh(string filename, string name)
	{
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Expected O, but got Unknown
		using BinaryReader binaryReader = new BinaryReader(new MemoryStream(Resource(filename)));
		if (new string(binaryReader.ReadChars(4)) != "GFB2")
		{
			throw new InvalidDataException("Invalid mesh header.");
		}
		int num = binaryReader.ReadInt32();
		int num2 = binaryReader.ReadInt32();
		if (num < 3 || num > 250000 || num2 < 3 || num2 > 1000000 || num2 % 3 != 0)
		{
			throw new InvalidDataException("Invalid mesh dimensions.");
		}
		Vector3[] array = (Vector3[])(object)new Vector3[num];
		Vector3[] array2 = (Vector3[])(object)new Vector3[num];
		Vector2[] array3 = (Vector2[])(object)new Vector2[num];
		int[] array4 = new int[num2];
		for (int i = 0; i < num; i++)
		{
			ref Vector3 reference = ref array[i];
			reference = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			ref Vector3 reference2 = ref array2[i];
			reference2 = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			ref Vector2 reference3 = ref array3[i];
			reference3 = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
		}
		for (int j = 0; j < num2; j++)
		{
			array4[j] = binaryReader.ReadInt32();
			if (array4[j] < 0 || array4[j] >= num)
			{
				throw new InvalidDataException("Invalid mesh index.");
			}
		}
		if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
		{
			throw new InvalidDataException("Unexpected mesh data.");
		}
		Mesh val = new Mesh();
		((Object)val).name = name;
		val.indexFormat = (IndexFormat)(num > 65535);
		Mesh val2 = val;
		val2.vertices = array;
		val2.normals = array2;
		val2.uv = array3;
		val2.triangles = array4;
		val2.RecalculateBounds();
		val2.RecalculateTangents();
		return val2;
	}

	private static void SetTexture(Material m, string name, Texture v)
	{
		if (m.HasProperty(name))
		{
			m.SetTexture(name, v);
		}
	}

	private static void SetColor(Material m, string name, Color v)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		if (m.HasProperty(name))
		{
			m.SetColor(name, v);
		}
	}

	private static void SetFloat(Material m, string name, float v)
	{
		if (m.HasProperty(name))
		{
			m.SetFloat(name, v);
		}
	}
}
public sealed class EmberLight : MonoBehaviour
{
	private Light emberLight;

	private Player owner;

	private ZNetView view;

	private Renderer surface;

	private MaterialPropertyBlock block;

	private void Start()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Invalid comparison between Unknown and I4
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Expected O, but got Unknown
		if ((int)SystemInfo.graphicsDeviceType != 4)
		{
			GameObject val = new GameObject("Ember glow");
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.localPosition = new Vector3(0f, 0f, 1.1f);
			emberLight = val.AddComponent<Light>();
			emberLight.type = (LightType)2;
			emberLight.color = new Color(1f, 0.3f, 0.04f);
			emberLight.range = 2.6f;
			emberLight.intensity = 0f;
			emberLight.shadows = (LightShadows)0;
			owner = ((Component)this).GetComponentInParent<Player>();
			if (Object.op_Implicit((Object)(object)owner))
			{
				view = ((Component)owner).GetComponent<ZNetView>();
			}
			surface = ((Component)this).GetComponent<Renderer>();
			block = new MaterialPropertyBlock();
		}
	}

	private void Update()
	{
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)emberLight))
		{
			float num = ((Object.op_Implicit((Object)(object)view) && view.GetZDO() != null) ? Mathf.Clamp01((float)view.GetZDO().GetInt("ferro_gfb_heat", 0) / 100f) : 0f);
			if (!Object.op_Implicit((Object)(object)owner) || !Plugin.IsSword(((Humanoid)owner).GetCurrentWeapon()))
			{
				num = 0f;
			}
			float num2 = ((num <= 0f) ? 0f : Mathf.Lerp(0.06f, 1.3f, Mathf.Pow(num, 1.6f)));
			if (num >= 0.999f)
			{
				num2 += 0.35f * (0.5f + 0.5f * Mathf.Sin(Time.time * 5f));
			}
			emberLight.intensity = 1.5f * Mathf.Pow(num, 1.5f) * ((num >= 0.999f) ? (0.85f + 0.15f * Mathf.Sin(Time.time * 9f)) : 1f);
			block.SetColor("_EmissionColor", Color.white * num2);
			if (Object.op_Implicit((Object)(object)surface))
			{
				surface.SetPropertyBlock(block);
			}
		}
	}
}