Decompiled source of Tire Swans v0.1.0

plugins/TireSwans/TireSwans.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Blackforge.Hot;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Blackforge.Hot
{
	public interface IHotModule
	{
		void Load(HotHost host);

		Dictionary<string, string> Unload();
	}
	public sealed class HotHost
	{
		private readonly string folder;

		public string Name => "tireswans";

		public ManualLogSource Log { get; }

		public Harmony Harmony { get; }

		public bool Reloading => false;

		public Dictionary<string, string> Handover { get; } = new Dictionary<string, string>();

		public string Version { get; }

		public bool InSync { get; internal set; } = true;

		public bool IsDedicatedServer
		{
			get
			{
				if ((Object)(object)ZNet.instance != (Object)null)
				{
					return ZNet.instance.IsDedicated();
				}
				return false;
			}
		}

		internal HotHost(ManualLogSource log, Harmony harmony, string folder, string version)
		{
			Log = log;
			Harmony = harmony;
			this.folder = folder;
			Version = version;
		}

		public string AssetPath(string relative)
		{
			string text = ModFiles.Find(folder, relative);
			if (text != null)
			{
				return text;
			}
			throw new FileNotFoundException("Tire Swans " + Version + " has no " + relative + " next to its dll, install the whole mod folder");
		}

		public byte[] ReadAsset(string relative)
		{
			return File.ReadAllBytes(AssetPath(relative));
		}

		public IEnumerable<string> Assets(string under)
		{
			string path = Path.Combine(folder, under.Replace('/', Path.DirectorySeparatorChar));
			if (!Directory.Exists(path))
			{
				return Enumerable.Empty<string>();
			}
			return from text in Directory.GetFiles(path, "*", SearchOption.AllDirectories)
				select text.Substring(folder.Length + 1).Replace(Path.DirectorySeparatorChar, '/') into result
				orderby result
				select result;
		}

		public void AddPrefabs(ZNetScene scene, IEnumerable<GameObject> prefabs)
		{
			bool flag = (Object)(object)ZNetScene.instance == (Object)(object)scene;
			foreach (GameObject prefab in prefabs)
			{
				scene.m_prefabs.RemoveAll((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == ((Object)prefab).name);
				scene.m_prefabs.Add(prefab);
				if (flag)
				{
					scene.m_namedPrefabs[StringExtensionMethods.GetStableHashCode(((Object)prefab).name)] = prefab;
				}
			}
		}

		public void UnregisterRpc(IEnumerable<string> names)
		{
			if (ZRoutedRpc.instance == null)
			{
				return;
			}
			foreach (string name in names)
			{
				ZRoutedRpc.instance.m_functions.Remove(StringExtensionMethods.GetStableHashCode(name));
			}
		}
	}
	internal static class ModFiles
	{
		internal static string Find(string folder, string relative)
		{
			string text = Path.Combine(folder, relative.Replace('/', Path.DirectorySeparatorChar));
			if (File.Exists(text))
			{
				return text;
			}
			string text2 = Path.Combine(folder, Path.GetFileName(text));
			if (!File.Exists(text2))
			{
				return null;
			}
			return text2;
		}
	}
}
namespace Blackforge.TireSwans
{
	public static class Models
	{
		public class Model
		{
			public Mesh mesh;

			public string[] slots;

			public List<Box> boxes;
		}

		public class Box
		{
			public Vector3 center;

			public Vector3 size;

			public Quaternion rotation;
		}

		private static readonly Dictionary<string, Model> cache = new Dictionary<string, Model>();

		public static Model Load(string name)
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Expected O, but got Unknown
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			if (cache.TryGetValue(name, out var value))
			{
				return value;
			}
			using Stream input = Asset("meshes/" + name + ".bfm");
			using BinaryReader binaryReader = new BinaryReader(input);
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "BFM5")
			{
				throw new InvalidDataException(name + " is not a mesh file");
			}
			int num = binaryReader.ReadInt32();
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int[]> list4 = new List<int[]>();
			string[] array = new string[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = Encoding.UTF8.GetString(binaryReader.ReadBytes(binaryReader.ReadInt32()));
				int count = list.Count;
				int num2 = binaryReader.ReadInt32();
				for (int j = 0; j < num2; j++)
				{
					list.Add(new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()));
					list2.Add(new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()));
					list3.Add(new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle()));
				}
				int[] array2 = new int[binaryReader.ReadInt32()];
				for (int k = 0; k < array2.Length; k++)
				{
					array2[k] = count + binaryReader.ReadInt32();
				}
				list4.Add(array2);
			}
			List<Box> list5 = new List<Box>();
			int num3 = binaryReader.ReadInt32();
			for (int l = 0; l < num3; l++)
			{
				Vector3 center = ReadVector(binaryReader);
				Vector3 size = ReadVector(binaryReader);
				Vector3 val = ReadVector(binaryReader);
				Vector3 val2 = ReadVector(binaryReader);
				list5.Add(new Box
				{
					center = center,
					size = size,
					rotation = Quaternion.LookRotation(val, val2)
				});
			}
			Mesh val3 = new Mesh
			{
				name = "bf_" + name
			};
			if (list.Count > 65535)
			{
				val3.indexFormat = (IndexFormat)1;
			}
			val3.SetVertices(list);
			val3.SetNormals(list2);
			val3.SetUVs(0, list3);
			val3.SetColors(Enumerable.Repeat<Color>(Color.white, list.Count).ToList());
			val3.subMeshCount = num;
			for (int m = 0; m < num; m++)
			{
				val3.SetTriangles(list4[m], m);
			}
			val3.RecalculateBounds();
			val3.RecalculateTangents();
			value = new Model
			{
				mesh = val3,
				slots = array,
				boxes = list5
			};
			cache[name] = value;
			return value;
		}

		private static Vector3 ReadVector(BinaryReader reader)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
		}

		public static Sprite Icon(string name)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = Texture("icons/" + name + ".png", linear: false);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		public static Texture2D Texture(string path, bool linear)
		{
			//IL_0019: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0050: Expected O, but got Unknown
			using Stream stream = Asset(path);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear)
			{
				name = "bf_" + Path.GetFileNameWithoutExtension(path),
				wrapMode = (TextureWrapMode)0,
				anisoLevel = 4
			};
			ImageConversion.LoadImage(val, memoryStream.ToArray());
			return val;
		}

		private static Stream Asset(string path)
		{
			return new MemoryStream(SwansPlugin.Host.ReadAsset(path));
		}

		public static void Clear()
		{
			cache.Clear();
		}
	}
	public static class Net
	{
		private const string Ask = "tireswans_ask";

		private const string CostCall = "tireswans_cost";

		private static readonly string[] RpcNames = new string[2] { "tireswans_ask", "tireswans_cost" };

		private static GameObject session;

		private static bool asked;

		public static bool IsServer
		{
			get
			{
				if ((Object)(object)ZNet.instance != (Object)null)
				{
					return ZNet.instance.IsServer();
				}
				return false;
			}
		}

		public static void Start()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			Stop();
			ZRoutedRpc instance = ZRoutedRpc.instance;
			instance.Register("tireswans_ask", (Action<long>)OnAsk);
			instance.Register<string>("tireswans_cost", (Action<long, string>)OnCost);
			session = new GameObject("TireSwans");
			session.AddComponent<Session>();
		}

		public static void Stop()
		{
			SwansPlugin.Host.UnregisterRpc(RpcNames);
			if ((Object)(object)session != (Object)null)
			{
				Object.Destroy((Object)(object)session);
				session = null;
			}
			asked = false;
			Settings.Forget();
		}

		public static void Tick()
		{
			if (!asked && !IsServer && ZRoutedRpc.instance != null && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				asked = true;
				ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "tireswans_ask", Array.Empty<object>());
			}
		}

		private static void OnAsk(long sender)
		{
			if (IsServer)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(sender, "tireswans_cost", new object[1] { Settings.Cost });
			}
		}

		private static void OnCost(long sender, string cost)
		{
			if (!IsServer && sender == ZRoutedRpc.instance.GetServerPeerID())
			{
				Settings.FromServer(cost);
				if ((Object)(object)ObjectDB.instance != (Object)null)
				{
					Swans.AddToHammer(ObjectDB.instance);
				}
			}
		}
	}
	public static class SwansPlugin
	{
		public static ManualLogSource Log;

		public static HotHost Host;
	}
	public class SwansModule : IHotModule
	{
		public void Load(HotHost host)
		{
			SwansPlugin.Log = host.Log;
			SwansPlugin.Host = host;
			Settings.Load();
			host.Harmony.PatchAll(typeof(SwansModule).Assembly);
			if ((Object)(object)ZNetScene.instance != (Object)null && Swans.Ensure(ZNetScene.instance.m_prefabs))
			{
				host.AddPrefabs(ZNetScene.instance, Swans.All);
			}
			if ((Object)(object)ObjectDB.instance != (Object)null)
			{
				Swans.AddToHammer(ObjectDB.instance);
			}
			if ((Object)(object)Game.instance != (Object)null && ZRoutedRpc.instance != null)
			{
				Net.Start();
			}
			host.Log.LogInfo((object)("tire swans ready, version " + host.Version));
		}

		public Dictionary<string, string> Unload()
		{
			Net.Stop();
			Swans.Unload();
			return new Dictionary<string, string>();
		}
	}
	[HarmonyPatch(typeof(Game), "Start")]
	internal static class StartOnGame
	{
		private static void Postfix()
		{
			Net.Start();
		}
	}
	public class Session : MonoBehaviour
	{
		private void Update()
		{
			Net.Tick();
		}
	}
	public static class Settings
	{
		private const string FileName = "vladasz.tireswans.cfg";

		public const string DefaultCost = "LeatherScraps:4,BoneFragments:2";

		private static ConfigEntry<string> cost;

		private static string serverCost;

		public static string Cost => serverCost ?? cost.Value;

		public static void Load()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			cost = new ConfigFile(Path.Combine(Paths.ConfigPath, "vladasz.tireswans.cfg"), true).Bind<string>("Costs", "Swan", "LeatherScraps:4,BoneFragments:2", "What a tire swan costs, items by their prefab name with the amount after a colon, like LeatherScraps:4,BoneFragments:2. A server that runs the mod sends its own to every player.");
			serverCost = null;
		}

		public static void FromServer(string costThere)
		{
			serverCost = costThere;
			SwansPlugin.Log.LogInfo((object)("tire swans cost from the server: " + costThere));
		}

		public static void Forget()
		{
			serverCost = null;
		}
	}
	[BepInPlugin("vladasz.tireswans", "Tire Swans", "0.1.0")]
	public class TireSwansPlugin : BaseUnityPlugin
	{
		public const string Id = "vladasz.tireswans";

		public const string Number = "0.1.0";

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			string location = ((BaseUnityPlugin)this).Info.Location;
			HotHost host = new HotHost(((BaseUnityPlugin)this).Logger, new Harmony("vladasz.tireswans"), Path.GetDirectoryName(location), "0.1.0-" + Fingerprint(location));
			new SwansModule().Load(host);
		}

		private static string Fingerprint(string dll)
		{
			try
			{
				using SHA256 sHA = SHA256.Create();
				return BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(dll)), 0, 4).Replace("-", "").ToLowerInvariant();
			}
			catch (Exception)
			{
				return "unknown";
			}
		}
	}
	public static class Swans
	{
		[HarmonyPatch(typeof(ZNetScene), "Awake")]
		private static class RegisterPrefab
		{
			private static void Prefix(ZNetScene __instance)
			{
				if (!Ensure(__instance.m_prefabs))
				{
					SwansPlugin.Log.LogError((object)"the vanilla material was not found, the tire swan is off");
				}
				else
				{
					SwansPlugin.Host.AddPrefabs(__instance, All);
				}
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class OnHammer
		{
			private static void Postfix(ObjectDB __instance)
			{
				AddToHammer(__instance);
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		private static class OnCopiedHammer
		{
			private static void Postfix(ObjectDB __instance)
			{
				AddToHammer(__instance);
			}
		}

		public const string Prefab = "bf_tire_swan";

		private const string Model = "tire_swan";

		private const string Name = "Tire swan";

		private const string Description = "A swan cut from an old car tire and painted white, standing in a second tire.";

		private const string MaterialPrefab = "wood_beam";

		private const string MaterialName = "woodwall";

		private static readonly string[] Looks = new string[2] { "piece_banner01", "wood_floor" };

		private static GameObject prefab;

		private static GameObject holder;

		public static IEnumerable<GameObject> All
		{
			get
			{
				if (!((Object)(object)prefab != (Object)null))
				{
					return Enumerable.Empty<GameObject>();
				}
				return (IEnumerable<GameObject>)(object)new GameObject[1] { prefab };
			}
		}

		public static bool Ensure(IEnumerable<GameObject> vanilla)
		{
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			if ((Object)(object)prefab != (Object)null)
			{
				return true;
			}
			Dictionary<string, GameObject> byName = (from go in vanilla
				where (Object)(object)go != (Object)null
				group go by ((Object)go).name).ToDictionary((IGrouping<string, GameObject> g) => g.Key, (IGrouping<string, GameObject> g) => g.First());
			GameObject value;
			Material val = (byName.TryGetValue("wood_beam", out value) ? value.GetComponentsInChildren<Renderer>(true).SelectMany((Renderer r) => r.sharedMaterials).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null && ((Object)m).name == "woodwall")) : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			GameObject value2;
			GameObject val2 = Looks.Select((string name) => (!byName.TryGetValue(name, out value2)) ? null : value2).FirstOrDefault((Func<GameObject, bool>)((GameObject go) => (Object)(object)go != (Object)null));
			holder = new GameObject("BlackforgeTireSwansPrefabs");
			holder.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)holder);
			prefab = Build(Painted(val), val2);
			SwansPlugin.Log.LogInfo((object)("tire swan built: bf_tire_swan, usage and effects of " + (((Object)(object)val2 != (Object)null) ? ((Object)val2).name : "nothing")));
			return true;
		}

		private static Material Painted(Material source)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			Describe(source);
			Material val = new Material(source)
			{
				name = "bf_tire_swan",
				color = Color.white
			};
			val.mainTexture = (Texture)(object)Models.Texture("textures/tire_swan.png", linear: false);
			val.mainTextureScale = Vector2.one;
			val.mainTextureOffset = Vector2.zero;
			val.DisableKeyword("_PARALLAXMAP");
			if (val.HasProperty("_BumpMap"))
			{
				val.SetTexture("_BumpMap", (Texture)(object)Models.Texture("textures/tire_swan_normal.png", linear: true));
				val.SetTextureScale("_BumpMap", Vector2.one);
				val.SetTextureOffset("_BumpMap", Vector2.zero);
				val.EnableKeyword("_NORMALMAP");
			}
			else if (!SwansPlugin.Host.IsDedicatedServer)
			{
				SwansPlugin.Log.LogWarning((object)("the material " + ((Object)source.shader).name + " has no normal map, the swan shows no tread"));
			}
			return val;
		}

		private static void Describe(Material source)
		{
			//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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected I4, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			Shader shader = source.shader;
			List<string> list = new List<string>();
			for (int i = 0; i < shader.GetPropertyCount(); i++)
			{
				string propertyName = shader.GetPropertyName(i);
				ShaderPropertyType propertyType = shader.GetPropertyType(i);
				switch ((int)propertyType)
				{
				case 2:
				case 3:
					list.Add(propertyName + " " + source.GetFloat(propertyName).ToString("0.###", CultureInfo.InvariantCulture));
					break;
				case 0:
					list.Add($"{propertyName} {source.GetColor(propertyName)}");
					break;
				case 4:
				{
					Texture texture = source.GetTexture(propertyName);
					list.Add(propertyName + " " + (((Object)(object)texture != (Object)null) ? ((Object)texture).name : "none"));
					break;
				}
				case 1:
					list.Add($"{propertyName} {source.GetVector(propertyName)}");
					break;
				default:
					list.Add(propertyName);
					break;
				}
			}
			SwansPlugin.Log.LogInfo((object)string.Format("tire swan material from {0}: shader {1}, keywords {2}, tiling {3} offset {4}, {5}", ((Object)source).name, ((Object)shader).name, string.Join(" ", source.shaderKeywords), source.mainTextureScale, source.mainTextureOffset, string.Join(", ", list)));
		}

		private static GameObject Build(Material material, GameObject look)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00da: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			int layer = LayerMask.NameToLayer("piece");
			GameObject val = new GameObject("bf_tire_swan")
			{
				layer = layer
			};
			val.transform.SetParent(holder.transform, false);
			val.AddComponent<ZNetView>().m_persistent = true;
			Models.Model model = Models.Load("tire_swan");
			GameObject val2 = new GameObject("model")
			{
				layer = layer
			};
			val2.transform.SetParent(val.transform, false);
			val2.AddComponent<MeshFilter>().sharedMesh = model.mesh;
			((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterials = model.slots.Select((string slot) => material).ToArray();
			foreach (Models.Box box in model.boxes)
			{
				GameObject val3 = new GameObject("collider")
				{
					layer = layer
				};
				val3.transform.SetParent(val.transform, false);
				val3.transform.localPosition = box.center;
				val3.transform.localRotation = box.rotation;
				val3.AddComponent<BoxCollider>().size = box.size;
			}
			Piece val4 = val.AddComponent<Piece>();
			val4.m_name = "Tire swan";
			val4.m_description = "A swan cut from an old car tire and painted white, standing in a second tire.";
			val4.m_icon = Models.Icon("tire_swan");
			val4.m_category = (PieceCategory)4;
			val4.m_canBeRemoved = true;
			WearNTear val5 = val.AddComponent<WearNTear>();
			val5.m_materialType = (MaterialType)0;
			val5.m_supports = false;
			val5.m_noRoofWear = false;
			val5.m_health = 200f;
			Piece val6 = (((Object)(object)look != (Object)null) ? look.GetComponent<Piece>() : null);
			WearNTear val7 = (((Object)(object)look != (Object)null) ? look.GetComponent<WearNTear>() : null);
			if ((Object)(object)val6 != (Object)null)
			{
				val4.m_usage = val6.m_usage;
				val4.m_placeEffect = val6.m_placeEffect;
			}
			if ((Object)(object)val7 != (Object)null)
			{
				val5.m_destroyedEffect = val7.m_destroyedEffect;
				val5.m_hitEffect = val7.m_hitEffect;
			}
			return val;
		}

		private static PieceTable Hammer(ObjectDB db)
		{
			GameObject val = (((Object)(object)db != (Object)null) ? db.GetItemPrefab("Hammer") : null);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return val.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_buildPieces;
		}

		public static void Unload()
		{
			PieceTable val = Hammer(ObjectDB.instance);
			if ((Object)(object)val != (Object)null)
			{
				val.m_pieces.RemoveAll((GameObject p) => (Object)(object)p != (Object)null && (Object)(object)p == (Object)(object)prefab);
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && (Object)(object)localPlayer.m_placementGhost != (Object)null && ((Object)localPlayer.m_placementGhost).name.StartsWith("bf_tire_swan"))
			{
				localPlayer.SetupPlacementGhost();
			}
			if ((Object)(object)holder != (Object)null)
			{
				Object.Destroy((Object)(object)holder);
				holder = null;
			}
			prefab = null;
			Models.Clear();
		}

		private static Requirement[] Costs(ObjectDB db, string cost)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			List<Requirement> list = new List<Requirement>();
			string[] array = cost.Split(',');
			foreach (string text in array)
			{
				string[] array2 = text.Split(':');
				object obj;
				if (array2.Length != 2)
				{
					obj = null;
				}
				else
				{
					GameObject itemPrefab = db.GetItemPrefab(array2[0].Trim());
					obj = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				}
				ItemDrop val = (ItemDrop)obj;
				if ((Object)(object)val == (Object)null || !int.TryParse(array2[1].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) || result < 1)
				{
					SwansPlugin.Log.LogWarning((object)("tire swans: the cost " + text.Trim() + " names no item and amount of the game, it is left out"));
					continue;
				}
				list.Add(new Requirement
				{
					m_resItem = val,
					m_amount = result,
					m_recover = true
				});
			}
			return list.ToArray();
		}

		public static void AddToHammer(ObjectDB db)
		{
			PieceTable val = Hammer(db);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (!Ensure(val.m_pieces))
			{
				SwansPlugin.Log.LogError((object)"the vanilla material was not found, the tire swan is not buildable");
				return;
			}
			Piece component = prefab.GetComponent<Piece>();
			component.m_craftingStation = val.m_pieces.Select((GameObject p) => p.GetComponent<CraftingStation>()).FirstOrDefault((Func<CraftingStation, bool>)((CraftingStation s) => (Object)(object)s != (Object)null && ((Object)s).name == "piece_workbench"));
			component.m_resources = Costs(db, Settings.Cost);
			if (!val.m_pieces.Contains(prefab))
			{
				val.m_pieces.Add(prefab);
			}
			SwansPlugin.Log.LogInfo((object)("tire swan on the hammer, station " + (((Object)(object)component.m_craftingStation != (Object)null) ? ((Object)component.m_craftingStation).name : "none") + ", cost " + string.Join(", ", component.m_resources.Select((Requirement r) => $"{((Object)r.m_resItem).name} {r.m_amount}"))));
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer != (Object)null))
			{
				return;
			}
			try
			{
				localPlayer.UpdateKnownRecipesList();
				localPlayer.UpdateAvailablePiecesList();
			}
			catch (Exception ex)
			{
				SwansPlugin.Log.LogWarning((object)("the game could not look for new pieces, the tire swan shows after the next change of the inventory: " + ex.Message));
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}