Decompiled source of balrond ElvenRoof v1.0.3

plugins/BalrondElvenRoof.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RainbowTrollArmor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RainbowTrollArmor")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f405ea1c-ac25-47a3-9aa2-a8f56c14bfd6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BalrondElvenRoof;

public class FxReplacment
{
	private List<GameObject> allPrefabs;

	public void setInstance(List<GameObject> gameObjects)
	{
		allPrefabs = gameObjects;
	}

	public void ReplaceFxOnPiece(GameObject gameObject)
	{
		if ((Object)(object)gameObject == (Object)null)
		{
			Debug.LogWarning((object)"BALROND CONTAINERS: GameObject not found");
			return;
		}
		Piece component = gameObject.GetComponent<Piece>();
		if ((Object)(object)component != (Object)null)
		{
			EffectList placeEffect = component.m_placeEffect;
			if (placeEffect != null)
			{
				findEffectsAndChange(placeEffect.m_effectPrefabs);
			}
		}
		WearNTear component2 = gameObject.GetComponent<WearNTear>();
		if ((Object)(object)component2 != (Object)null)
		{
			EffectList hitEffect = component2.m_hitEffect;
			if (hitEffect != null)
			{
				findEffectsAndChange(hitEffect.m_effectPrefabs);
			}
		}
	}

	private void findEffectsAndChange(EffectData[] effects)
	{
		if (effects == null || effects.Length == 0)
		{
			Debug.LogError((object)"BALROND CONTAINERS: Effects in Method are empty");
			return;
		}
		foreach (EffectData val in effects)
		{
			if ((Object)(object)val.m_prefab != (Object)null)
			{
				string name = ((Object)val.m_prefab).name;
				GameObject val2 = allPrefabs.Find((GameObject x) => ((Object)x).name == name);
				if ((Object)(object)val2 == (Object)null)
				{
					Debug.LogWarning((object)("BALROND CONTAINERS: Replace Effect not found: " + name));
				}
				else
				{
					val.m_prefab = val2;
				}
			}
		}
	}
}
[BepInPlugin("balrond.astafaraios.BalrondElvenRoof", "BalrondElvenRoof", "1.0.3")]
public class Launch : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	public static class ZNetScene_Awake_Path
	{
		public static void Prefix(ZNetScene __instance)
		{
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null)
			{
				Debug.LogWarning((object)"BalrondElvenRoof: No ZnetScene found");
				return;
			}
			GameObject val = FindItem(__instance.m_prefabs, "Hammer");
			List<GameObject> pieces = val.GetComponent<ItemDrop>().m_itemData.m_shared.m_buildPieces.m_pieces;
			fxReplacment.setInstance(__instance.m_prefabs);
			foreach (GameObject item in prefabs)
			{
				editBuildPiece(__instance.m_prefabs, item);
				fxReplacment.ReplaceFxOnPiece(item);
				GameObject val2 = __instance.m_prefabs.Find((GameObject x) => ((Object)x).name == ((Object)item).name);
				if ((Object)(object)val2 == (Object)null)
				{
					__instance.m_prefabs.Add(item);
				}
				GameObject val3 = pieces.Find((GameObject x) => ((Object)x).name == ((Object)item).name);
				if ((Object)(object)val3 == (Object)null)
				{
					pieces.Add(item);
				}
			}
			if (!new ZNet().IsDedicated())
			{
				ShaderReplacment.runMaterialFix();
			}
		}
	}

	private readonly Harmony harmony = new Harmony("balrond.astafaraios.BalrondElvenRoof");

	public const string PluginGUID = "balrond.astafaraios.BalrondElvenRoof";

	public const string PluginName = "BalrondElvenRoof";

	public const string PluginVersion = "1.0.3";

	public static AssetBundle assetBundle;

	public static List<GameObject> prefabs = new List<GameObject>();

	public static FxReplacment fxReplacment = new FxReplacment();

	private string[] prefabnames = new string[173]
	{
		"elvenwood_roof_flat1", "elvenwood_roof_45", "elvenwood_roof_45_half", "elvenwood_roof_45_large", "elvenwood_roof_45_tower_curved_v1", "elvenwood_roof_45_tower_curved_v2", "elvenwood_roof_45_tower_curved_v2_reverse", "elvenwood_roof_45_tower_curved_v1_reverse", "elvenwood_roof_icorner_45", "elvenwood_roof_ocorner_45",
		"elvenwood_roof_ocorner_45_large", "elvenwood_roof_ocorner_45_sharp", "elvenwood_roof_window_45", "elvenwood_roof_ocorner_45_window_double", "elvenwood_roof_top_45", "elvenwood_roof_top_45_peak", "elvenwood_roof_top_45_quarter", "elvenwood_beam_45_tile", "elvenwood_wall_roof_45", "elvenwood_wall_roof_45_upsidedown",
		"elvenwood_wall_roof_45_double", "elvenwood_wall_top_45", "elvenwood_beam_side1", "elvenwood_beam_top1", "elvenwood_roof_flat", "elvenwood_roof_45_v2", "elvenwood_roof_45_half_v2", "elvenwood_roof_45_v2_large", "elvenwood_roof_45_tower_convex_v1", "elvenwood_roof_45_tower_convex_v1_reverse",
		"elvenwood_roof_45_tower_convex_v2", "elvenwood_roof_45_tower_convex_v2_reverse", "elvenwood_roof_icorner_45_v2", "elvenwood_roof_ocorner_45_v2", "elvenwood_roof_ocorner_45_v2_large", "elvenwood_roof_window_45_v2", "elvenwood_roof_ocorner_45_window_v2", "elvenwood_roof_ocorner_45_window_double_v2", "elvenwood_roof_top_45_v2", "elvenwood_roof_top_45_peak_v2",
		"elvenwood_roof_top_45_quarter_v2", "elvenwood_beam_45_tile_v2", "elvenwood_wall_roof_45_v2", "elvenwood_wall_roof_45_upsidedown_v2", "elvenwood_wall_roof_45_double_v2", "elvenwood_wall_top_45_v2", "elvenwood_beam_top", "elvenwood_beam_side", "elvenwood_roof_flat2", "elvenwood_roof_45_v3",
		"elvenwood_roof_45_half_v3", "elvenwood_roof_45_v3_large", "elvenwood_roof_45_tower_straight_v1", "elvenwood_roof_45_tower_straight_v2", "elvenwood_roof_45_tower_straight_v2_reverse", "elvenwood_roof_45_tower_straight_v1_reverse", "elvenwood_roof_icorner_45_v3", "elvenwood_roof_ocorner_45_v3", "elvenwood_roof_ocorner_45_v3_large", "elvenwood_roof_ocorner_45_sharp1",
		"elvenwood_roof_window_45_v3", "elvenwood_roof_ocorner_45_window_double_v3", "elvenwood_roof_top_45_v3", "elvenwood_roof_top_45_peak_v3", "elvenwood_roof_top_45_quarter_v3", "elvenwood_beam_45_tile_v3", "elvenwood_wall_roof_45_v3", "elvenwood_wall_roof_45_upsidedown_v3", "elvenwood_wall_roof_45_double_v3", "elvenwood_wall_top_45_v3",
		"elvenwood_beam_top2", "elvenwood_beam_side2", "elvenwood_roof", "elvenwood_wall_roof", "elvenwood_beam_26", "elven_woodwall", "elven_woodwall1", "elven_woodwall2", "elven_woodwall3", "elven_woodwall4",
		"elven_woodwall6", "elven_woodwall7", "elven_woodwall_2x1", "elven_woodwall_1x1", "elven_woodwall_half", "elven_woodwall_half_window", "elven_woodwall_large", "elven_woodwall_large1", "elven_woodwall_large2", "elvenwood_door_curved",
		"elvenwood_door_curved_double", "elven_woodarch", "elven_woodarch1", "elven_wooddoor", "elven_wooddoor1", "elven_wooddoor_large", "elvenwood_roof_top_orial", "elvenwood_wall_curved", "elvenwood_wall_curved1", "elvenwood_wall_curved2",
		"elvenwood_wall_curved_large", "elvenwood_wall_curved_large_half", "elvenwood_wall_curved_large_door", "elvenwood_floor2x2", "elvenwood_floor2x2_curved", "elvenwood_floor_1x1", "elvenwood_floor_1x1_curved", "elvenwood_floor_curved_medium", "elvenwood_floor_curved_large", "elvenwood_wall_curved_step",
		"elvenwood_railing_1", "elvenwood_railing_2", "elvenwood_railing_curved", "elvenwood_railing_curved_medium", "elvenwood_railing_curved_large", "elvenwood_wall_step", "elvenstone_stair", "elvenstone_stair_railing", "elvenstone_stair1", "elvenwood_beam_45_tilegreen",
		"elvenwood_beam_45_tile_v2green", "elvenwood_beam_45_tile_v3green", "elvenwood_beam_topgreen", "elvenwood_beam_sidegreen", "elvenwood_roof_flatgreen", "elvenwood_roof_top_45green", "elvenwood_roof_top_45_peakgreen", "elvenwood_roof_top_45_quartergreen", "elvenwood_roof_top_45_v2green", "elvenwood_roof_top_45_peak_v2green",
		"elvenwood_roof_top_45_quarter_v2green", "elvenwood_roof_top_45_v3green", "elvenwood_roof_top_45_peak_v3green", "elvenwood_roof_top_45_quarter_v3green", "elvenwood_roof_45green", "elvenwood_roof_45_halfgreen", "elvenwood_roof_45_v2green", "elvenwood_roof_45_half_v2green", "elvenwood_roof_45_v3green", "elvenwood_roof_45_half_v3green",
		"elvenwood_roof_icorner_45green", "elvenwood_roof_icorner_45_v2green", "elvenwood_roof_icorner_45_v3green", "elvenwood_roof_ocorner_45green", "elvenwood_roof_ocorner_45_v2green", "elvenwood_roof_ocorner_45_window_v2green", "elvenwood_roof_ocorner_45_v3green", "elvenwood_roof_ocorner_45_sharpgreen", "elvenwood_roof_ocorner_45_sharp1green", "elvenwood_roof_45_largegreen",
		"elvenwood_roof_45_v2_largegreen", "elvenwood_roof_45_v3_largegreen", "elvenwood_roof_ocorner_45_v2_largegreen", "elvenwood_roof_ocorner_45_largegreen", "elvenwood_roof_ocorner_45_v3_largegreen", "elvenwood_roof_window_45green", "elvenwood_roof_ocorner_45_window_doublegreen", "elvenwood_roof_window_45_v2green", "elvenwood_roof_ocorner_45_window_double_v2", "elvenwood_roof_window_45_v3",
		"elvenwood_roof_ocorner_45_window_double_v3", "elvenwood_roof_45_tower_curved_v1green", "elvenwood_roof_45_tower_curved_v2green", "elvenwood_roof_45_tower_curved_v2_reversegreen", "elvenwood_roof_45_tower_curved_v1_reversegreen", "elvenwood_roof_45_tower_convex_v1green", "elvenwood_roof_45_tower_convex_v1_reversegreen", "elvenwood_roof_45_tower_convex_v2green", "elvenwood_roof_45_tower_convex_v2_reversegreen", "elvenwood_roof_45_tower_straight_v1green",
		"elvenwood_roof_45_tower_straight_v2green", "elvenwood_roof_45_tower_straight_v2_reversegreen", "elvenwood_roof_45_tower_straight_v1_reversegreen"
	};

	private void Awake()
	{
		assetBundle = GetAssetBundleFromResources("elvenroof");
		loadAssets();
		harmony.PatchAll();
	}

	private void loadAssets()
	{
		string text = "Assets/Custom/BalrondElvenRoof/";
		string[] array = prefabnames;
		foreach (string text2 in array)
		{
			GameObject val = assetBundle.LoadAsset<GameObject>(text + text2 + ".prefab");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogWarning((object)("BalrondElvenRoof: Could not find file with name: " + text2));
				continue;
			}
			ShaderReplacment.Replace(val);
			val.SetActive(true);
			prefabs.Add(val);
		}
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	private static bool IsObjectDBValid()
	{
		return (Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_items.Count != 0 && ObjectDB.instance.m_recipes.Count != 0 && (Object)(object)ObjectDB.instance.GetItemPrefab("Amber") != (Object)null;
	}

	public static AssetBundle GetAssetBundleFromResources(string filename)
	{
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		string name = executingAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(filename));
		using Stream stream = executingAssembly.GetManifestResourceStream(name);
		return AssetBundle.LoadFromStream(stream);
	}

	private static GameObject FindItem(List<GameObject> list, string name)
	{
		GameObject val = list.Find((GameObject x) => ((Object)x).name == name);
		if ((Object)(object)val != (Object)null)
		{
			return val;
		}
		Debug.LogWarning((object)"BalrondElvenRoof: Item Not Found");
		return null;
	}

	public static CraftingStation FindStation(List<GameObject> list, string name)
	{
		GameObject val = FindItem(list, name);
		if ((Object)(object)val != (Object)null)
		{
			return val.GetComponent<CraftingStation>();
		}
		return null;
	}

	public static void editBuildPiece(List<GameObject> buildPieces, GameObject gameObject)
	{
		Piece component = gameObject.GetComponent<Piece>();
		component.m_enabled = true;
		createResourceFor(((Object)gameObject).name, component, buildPieces);
	}

	public static Requirement createReq(string name, int amount)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		Requirement val = new Requirement();
		val.m_resItem = FindItem(ObjectDB.instance.m_items, name).GetComponent<ItemDrop>();
		val.m_amount = amount;
		val.m_recover = true;
		val.m_amountPerLevel = amount;
		return val;
	}

	public static void createResourceFor(string prefabName, Piece piece, List<GameObject> buildPieces)
	{
		List<Requirement> list = new List<Requirement>();
		switch (prefabName)
		{
		case "elvenwood_roof_45_tower_curved_v1green":
		case "elvenwood_roof_45_tower_curved_v2green":
		case "elvenwood_roof_45_tower_curved_v2_reversegreen":
		case "elvenwood_roof_45_tower_curved_v1_reversegreen":
		case "elvenwood_roof_45_tower_convex_v1green":
		case "elvenwood_roof_45_tower_convex_v1_reversegreen":
		case "elvenwood_roof_45_tower_convex_v2green":
		case "elvenwood_roof_45_tower_convex_v2_reversegreen":
		case "elvenwood_roof_45_tower_straight_v1green":
		case "elvenwood_roof_45_tower_straight_v2green":
		case "elvenwood_roof_45_tower_straight_v2_reversegreen":
		case "elvenwood_roof_45_tower_straight_v1_reversegreen":
		case "elvenwood_roof_45_tower_curved_v1":
		case "elvenwood_roof_45_tower_curved_v2":
		case "elvenwood_roof_45_tower_curved_v2_reverse":
		case "elvenwood_roof_45_tower_curved_v1_reverse":
		case "elvenwood_roof_45_tower_convex_v1":
		case "elvenwood_roof_45_tower_convex_v1_reverse":
		case "elvenwood_roof_45_tower_convex_v2":
		case "elvenwood_roof_45_tower_convex_v2_reverse":
		case "elvenwood_roof_45_tower_straight_v1":
		case "elvenwood_roof_45_tower_straight_v2":
		case "elvenwood_roof_45_tower_straight_v2_reverse":
		case "elvenwood_roof_45_tower_straight_v1_reverse":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 3));
			list.Add(createReq("BronzeNails", 3));
			list.Add(createReq("Stone", 3));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_roof_flatgreen":
		case "elvenwood_roof_top_45green":
		case "elvenwood_roof_top_45_v2green":
		case "elvenwood_roof_top_45_v3green":
		case "elvenwood_roof_45green":
		case "elvenwood_roof_45_v2green":
		case "elvenwood_roof_45_v3green":
		case "elvenwood_roof_icorner_45green":
		case "elvenwood_roof_icorner_45_v2green":
		case "elvenwood_roof_icorner_45_v3green":
		case "elvenwood_roof_ocorner_45green":
		case "elvenwood_roof_ocorner_45_v2green":
		case "elvenwood_roof_ocorner_45_v3green":
		case "elvenwood_roof_ocorner_45_sharpgreen":
		case "elvenwood_roof_ocorner_45_sharp1green":
		case "elvenwood_roof_top_orial":
		case "elvenwood_roof":
		case "elvenwood_roof_flat1":
		case "elvenwood_roof_45":
		case "elvenwood_roof_icorner_45":
		case "elvenwood_roof_ocorner_45":
		case "elvenwood_roof_ocorner_45_sharp":
		case "elvenwood_roof_flat":
		case "elvenwood_roof_45_v2":
		case "elvenwood_roof_icorner_45_v2":
		case "elvenwood_roof_ocorner_45_v2":
		case "elvenwood_roof_flat2":
		case "elvenwood_roof_45_v3":
		case "elvenwood_roof_icorner_45_v3":
		case "elvenwood_roof_ocorner_45_v3":
		case "elvenwood_roof_ocorner_45_sharp1":
		case "elvenwood_roof_top_45":
		case "elvenwood_roof_top_45_v2":
		case "elvenwood_roof_top_45_v3":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 2));
			list.Add(createReq("BronzeNails", 4));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_roof_top_45_peakgreen":
		case "elvenwood_roof_top_45_peak_v2green":
		case "elvenwood_roof_top_45_peak_v3green":
		case "elvenwood_roof_top_45_peak":
		case "elvenwood_roof_top_45_peak_v2":
		case "elvenwood_roof_top_45_peak_v3":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 3));
			list.Add(createReq("BronzeNails", 4));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_roof_window_45green":
		case "elvenwood_roof_window_45_v2green":
		case "elvenwood_roof_ocorner_45_window_v2green":
		case "elvenwood_roof_window_45_v3green":
		case "elvenwood_roof_window_45":
		case "elvenwood_roof_window_45_v2":
		case "elvenwood_roof_ocorner_45_window_v2":
		case "elvenwood_roof_window_45_v3":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 3));
			list.Add(createReq("BronzeNails", 4));
			list.Add(createReq("Crystal", 1));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_roof_ocorner_45_window_doublegreen":
		case "elvenwood_roof_ocorner_45_window_double_v2green":
		case "elvenwood_roof_ocorner_45_window_double_v3green":
		case "elvenwood_roof_ocorner_45_window_double":
		case "elvenwood_roof_ocorner_45_window_double_v2":
		case "elvenwood_roof_ocorner_45_window_double_v3":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 6));
			list.Add(createReq("BronzeNails", 8));
			list.Add(createReq("Crystal", 1));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_roof_top_45_quartergreen":
		case "elvenwood_roof_top_45_quarter_v2green":
		case "elvenwood_roof_top_45_quarter_v3green":
		case "elvenwood_roof_45_halfgreen":
		case "elvenwood_roof_45_half_v2green":
		case "elvenwood_roof_45_half_v3green":
		case "elvenwood_roof_top_45_quarter":
		case "elvenwood_roof_top_45_quarter_v2":
		case "elvenwood_roof_top_45_quarter_v3":
		case "elvenwood_roof_45_half":
		case "elvenwood_roof_45_half_v2":
		case "elvenwood_roof_45_half_v3":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 1));
			list.Add(createReq("BronzeNails", 2));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_railing_curved":
		case "elvenwood_beam_26":
		case "elvenwood_beam_top2":
		case "elvenwood_beam_side2":
		case "elvenwood_beam_top":
		case "elvenwood_beam_side":
		case "elvenwood_beam_side1":
		case "elvenwood_beam_top1":
		case "elvenwood_beam_45_tile":
		case "elvenwood_beam_45_tile_v2":
		case "elvenwood_beam_45_tile_v3":
		case "elvenwood_railing_2":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 2));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_beam_45_tilegreen":
		case "elvenwood_beam_45_tile_v2green":
		case "elvenwood_beam_45_tile_v3green":
		case "elvenwood_beam_topgreen":
		case "elvenwood_beam_sidegreen":
		case "elvenwood_wall_step":
		case "elvenwood_wall_curved_step":
		case "elvenwood_beam_45":
		case "elvenwood_beam_45_v3":
		case "elvenwood_beam_45_v2":
		case "elvenwood_railing_1":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 1));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_wall_roof":
		case "elvenwood_wall_top_45":
		case "elvenwood_wall_roof_45":
		case "elvenwood_wall_roof_45_v2":
		case "elvenwood_wall_top_45_v2":
		case "elvenwood_wall_roof_45_v3":
		case "elvenwood_wall_top_45_v3":
		case "elvenwood_wall_roof_45_upsidedown":
		case "elvenwood_wall_roof_45_upsidedown_v2":
		case "elvenwood_wall_roof_45_upsidedown_v3":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("Stone", 2));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_wall_roof_45_double":
		case "elvenwood_wall_roof_45_double_v2":
		case "elvenwood_wall_roof_45_double_v3":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("Stone", 4));
			list.Add(createReq("Crystal", 1));
			piece.m_resources = list.ToArray();
			break;
		case "elvenstone_stair":
		case "elvenwood_wall_curved2":
		case "elven_woodwall":
		case "elven_woodwall_2x1":
		case "elven_woodwall_1x1":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("Stone", 2));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_wall_curved1":
		case "elven_woodwall1":
		case "elven_woodwall2":
		case "elven_woodwall3":
		case "elven_woodwall4":
		case "elven_woodwall6":
		case "elven_woodwall7":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("Stone", 2));
			list.Add(createReq("Crystal", 1));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_wall_curved":
		case "elven_woodwall_half":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 1));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_wall_curved_large_half":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 3));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_wall_curved_large_door":
		case "elvenwood_wall_curved_large":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 6));
			piece.m_resources = list.ToArray();
			break;
		case "elven_woodwall_half_window":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 1));
			list.Add(createReq("Crystal", 1));
			piece.m_resources = list.ToArray();
			break;
		case "elven_woodwall_large":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 4));
			list.Add(createReq("Crystal", 2));
			piece.m_resources = list.ToArray();
			break;
		case "elven_woodwall_large1":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 3));
			list.Add(createReq("Crystal", 1));
			piece.m_resources = list.ToArray();
			break;
		case "elven_woodwall_large2":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 8));
			list.Add(createReq("Crystal", 4));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_roof_45_largegreen":
		case "elvenwood_roof_45_v2_largegreen":
		case "elvenwood_roof_45_v3_largegreen":
		case "elvenwood_roof_ocorner_45_v2_largegreen":
		case "elvenwood_roof_ocorner_45_largegreen":
		case "elvenwood_roof_ocorner_45_v3_largegreen":
		case "elvenwood_roof_45_large":
		case "elvenwood_roof_45_v2_large":
		case "elvenwood_roof_45_v3_large":
		case "elvenwood_roof_ocorner_45_large":
		case "elvenwood_roof_ocorner_45_v2_large":
		case "elvenwood_roof_ocorner_45_v3_large":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 4));
			list.Add(createReq("FineWood", 10));
			piece.m_resources = list.ToArray();
			break;
		case "elven_wooddoor":
		case "elven_wooddoor1":
		case "elvenwood_door_curved":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 4));
			list.Add(createReq("FineWood", 2));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_door_curved_double":
		case "elven_wooddoor_large":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 8));
			list.Add(createReq("FineWood", 4));
			piece.m_resources = list.ToArray();
			break;
		case "elvenstone_stair_railing":
		case "elvenstone_stair1":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("Stone", 10));
			list.Add(createReq("FineWood", 4));
			piece.m_resources = list.ToArray();
			break;
		case "elven_woodarch":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("FineWood", 3));
			list.Add(createReq("Stone", 2));
			piece.m_resources = list.ToArray();
			break;
		case "elven_woodarch1":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("FineWood", 4));
			list.Add(createReq("Stone", 2));
			list.Add(createReq("BronzeNails", 2));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_floor_curved_large":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("FineWood", 5));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_railing_curved_large":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("FineWood", 3));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_railing_curved_medium":
		case "elvenwood_floor2x2":
		case "elvenwood_floor2x2_curved":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_stonecutter");
			list.Clear();
			list.Add(createReq("FineWood", 2));
			piece.m_resources = list.ToArray();
			break;
		case "elvenwood_floor_1x1":
		case "elvenwood_floor_1x1_curved":
			piece.m_name = prefabName;
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 1));
			piece.m_resources = list.ToArray();
			break;
		}
	}
}
public class ShaderReplacment
{
	public static List<GameObject> prefabsToReplaceShader = new List<GameObject>();

	public static List<Material> materialsInPrefabs = new List<Material>();

	public string[] shaderlist = new string[49]
	{
		"Custom/AlphaParticle", "Custom/Blob", "Custom/Bonemass", "Custom/Clouds", "Custom/Creature", "Custom/Decal", "Custom/Distortion", "Custom/Flow", "Custom/FlowOpaque", "Custom/Grass",
		"Custom/GuiScroll", "Custom/Heightmap", "Custom/icon", "Custom/InteriorSide", "Custom/LitGui", "Custom/LitParticles", "Custom/mapshader", "Custom/ParticleDecal", "Custom/Piece", "Custom/Player",
		"Custom/Rug", "Custom/ShadowBlob", "Custom/SkyboxProcedural", "Custom/SkyObject", "Custom/StaticRock", "Custom/Tar", "Custom/Trilinearmap", "Custom/UI/BGBlur", "Custom/Vegetation", "Custom/Water",
		"Custom/WaterBottom", "Custom/WaterMask", "Custom/Yggdrasil", "Custom/Yggdrasil/root", "Hidden/BlitCopyHDRTonemap", "Hidden/Dof/DepthOfFieldHdr", "Hidden/Dof/DX11Dof", "Hidden/Internal-Loading", "Hidden/Internal-UIRDefaultWorld", "Hidden/SimpleClear",
		"Hidden/SunShaftsComposite", "Lux Lit Particles/ Bumped", "Lux Lit Particles/ Tess Bumped", "Particles/Standard Surface2", "Particles/Standard Unlit2", "Standard TwoSided", "ToonDeferredShading2017", "Unlit/DepthWrite", "Unlit/Lighting"
	};

	public static List<Shader> shaders = new List<Shader>();

	private static readonly HashSet<Shader> CachedShaders = new HashSet<Shader>();

	public static bool debug = true;

	public static Shader findShader(string name)
	{
		Shader[] array = Resources.FindObjectsOfTypeAll<Shader>();
		if (array.Length == 0)
		{
			Debug.LogWarning((object)"SHADER LIST IS EMPTY!");
			return null;
		}
		if (debug)
		{
		}
		return shaders.Find((Shader x) => ((Object)x).name == name);
	}

	public static Shader GetShaderByName(string name)
	{
		return shaders.Find((Shader x) => ((Object)x).name == name.Trim());
	}

	public static void debugShaderList(List<Shader> shadersRes)
	{
		foreach (Shader shadersRe in shadersRes)
		{
			Debug.LogWarning((object)("SHADER NAME IS: " + ((Object)shadersRe).name));
		}
		debug = false;
	}

	public static void Replace(GameObject gameObject)
	{
		prefabsToReplaceShader.Add(gameObject);
		GetMaterialsInPrefab(gameObject);
	}

	public static void GetMaterialsInPrefab(GameObject gameObject)
	{
		Renderer[] componentsInChildren = gameObject.GetComponentsInChildren<Renderer>(true);
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			Material[] sharedMaterials = val.sharedMaterials;
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				continue;
			}
			Material[] array2 = sharedMaterials;
			foreach (Material val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					materialsInPrefabs.Add(val2);
				}
			}
		}
	}

	public static void getMeShaders()
	{
		AssetBundle[] array = Resources.FindObjectsOfTypeAll<AssetBundle>();
		AssetBundle[] array2 = array;
		foreach (AssetBundle val in array2)
		{
			IEnumerable<Shader> enumerable3;
			try
			{
				IEnumerable<Shader> enumerable2;
				if (!val.isStreamedSceneAssetBundle || !Object.op_Implicit((Object)(object)val))
				{
					IEnumerable<Shader> enumerable = val.LoadAllAssets<Shader>();
					enumerable2 = enumerable;
				}
				else
				{
					enumerable2 = from shader in ((IEnumerable<string>)val.GetAllAssetNames()).Select((Func<string, Shader>)val.LoadAsset<Shader>)
						where (Object)(object)shader != (Object)null
						select shader;
				}
				enumerable3 = enumerable2;
			}
			catch (Exception)
			{
				continue;
			}
			if (enumerable3 == null)
			{
				continue;
			}
			foreach (Shader item in enumerable3)
			{
				CachedShaders.Add(item);
			}
		}
	}

	public static void runMaterialFix()
	{
		getMeShaders();
		shaders.AddRange(CachedShaders);
		foreach (Material materialsInPrefab in materialsInPrefabs)
		{
			Shader shader = materialsInPrefab.shader;
			if (!((Object)(object)shader == (Object)null))
			{
				string name = ((Object)shader).name;
				if (!(name == "Standard") && name.Contains("Balrond"))
				{
					setProperValue(materialsInPrefab, name);
				}
			}
		}
	}

	private static void setProperValue(Material material, string shaderName)
	{
		string name = shaderName.Replace("Balrond", "Custom");
		name = checkNaming(name);
		Shader shaderByName = GetShaderByName(name);
		if ((Object)(object)shaderByName == (Object)null)
		{
			Debug.LogWarning((object)("Shader not found " + name));
		}
		else
		{
			material.shader = shaderByName;
		}
	}

	private static string checkNaming(string name)
	{
		string result = name;
		if (name.Contains("Bumped"))
		{
			result = name.Replace("Custom", "Lux Lit Particles");
		}
		if (name.Contains("Tess Bumped"))
		{
			result = name.Replace("Custom", "Lux Lit Particles");
		}
		if (name.Contains("Standard Surface"))
		{
			result = name.Replace("Custom", "Particles");
			result = result.Replace("Standard Surface2", "Standard Surface");
		}
		if (name.Contains("Standard Unlit"))
		{
			result = name.Replace("Custom", "Particles");
			result = result.Replace("Standard Unlit", "Standard Unlit2");
			result = result.Replace("Standard Unlit22", "Standard Unlit2");
		}
		return result;
	}
}