Decompiled source of balrond containers v1.2.6

plugins/BalrondContainers.dll

Decompiled 3 weeks 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 BalrondContainers;

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.BalrondContainers", "BalrondContainers", "1.2.6")]
public class Launch : BaseUnityPlugin
{
	[HarmonyPriority(700)]
	[HarmonyPatch(typeof(FejdStartup), "Awake")]
	private static class Replace_ShaderPatch
	{
		public static void Postfix()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (new ZNet().IsDedicated())
			{
				return;
			}
			ShaderReplacment.findShadersByName();
			foreach (GameObject item in ShaderReplacment.GOToSwap)
			{
				if (!((Object)(object)item == (Object)null))
				{
					Renderer[] componentsInChildren = item.GetComponentsInChildren<Renderer>();
					if (componentsInChildren == null || componentsInChildren.Length == 0)
					{
						break;
					}
					ShaderReplacment.ReplaceShadersInObject(componentsInChildren);
				}
			}
		}
	}

	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	public static class ZNetScene_Awake_Path
	{
		public static void Prefix(ZNetScene __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				Debug.LogWarning((object)"BALROND CONTAINERS: 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);
				}
			}
		}
	}

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

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

	public const string PluginName = "BalrondContainers";

	public const string PluginVersion = "1.2.6";

	public static AssetBundle assetBundle;

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

	public static FxReplacment fxReplacment = new FxReplacment();

	public static GameObject barrel;

	public static GameObject seedbasket;

	public static GameObject fabricShelf;

	public static GameObject shelf;

	public static GameObject shed;

	public static GameObject basket;

	public static GameObject trough;

	public static GameObject locker;

	public static GameObject table;

	public static GameObject table2;

	public static GameObject table3;

	public static GameObject table4;

	public static GameObject weaponrack;

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

	private void loadAssets()
	{
		string text = "Assets/Custom/Containers/Prefabs/";
		weaponrack = assetBundle.LoadAsset<GameObject>(text + "piece_chest_weaponrack.prefab");
		ShaderReplacment.Replace(weaponrack);
		TopContainer topContainer = weaponrack.AddComponent<TopContainer>();
		topContainer.slotAmount = 6;
		prefabs.Add(weaponrack);
		barrel = assetBundle.LoadAsset<GameObject>(text + "piece_chest_barrel_bal.prefab");
		ShaderReplacment.Replace(barrel);
		barrel.AddComponent<TopFood>();
		prefabs.Add(barrel);
		table = assetBundle.LoadAsset<GameObject>(text + "piece_chest_foodtable.prefab");
		ShaderReplacment.Replace(table);
		TopContainer topContainer2 = table.AddComponent<TopContainer>();
		topContainer2.slotAmount = 10;
		prefabs.Add(table);
		table2 = assetBundle.LoadAsset<GameObject>(text + "piece_chest_foodtable_oak.prefab");
		ShaderReplacment.Replace(table2);
		TopContainer topContainer3 = table2.AddComponent<TopContainer>();
		topContainer3.slotAmount = 12;
		prefabs.Add(table2);
		table3 = assetBundle.LoadAsset<GameObject>(text + "piece_chest_foodtable_round.prefab");
		ShaderReplacment.Replace(table3);
		TopContainer topContainer4 = table3.AddComponent<TopContainer>();
		topContainer4.slotAmount = 8;
		prefabs.Add(table3);
		table4 = assetBundle.LoadAsset<GameObject>(text + "piece_chest_foodtable_fine.prefab");
		ShaderReplacment.Replace(table4);
		TopContainer topContainer5 = table4.AddComponent<TopContainer>();
		topContainer5.slotAmount = 4;
		prefabs.Add(table4);
		fabricShelf = assetBundle.LoadAsset<GameObject>(text + "piece_chest_fabricshelf_bal.prefab");
		ShaderReplacment.Replace(fabricShelf);
		TopContainer topContainer6 = fabricShelf.AddComponent<TopContainer>();
		topContainer6.slotAmount = 9;
		prefabs.Add(fabricShelf);
		seedbasket = assetBundle.LoadAsset<GameObject>(text + "piece_chest_seedbasket_bal.prefab");
		Transform val = seedbasket.transform.Find("piece_chest_barrel_bal");
		if ((Object)(object)val != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
		}
		ShaderReplacment.Replace(seedbasket);
		seedbasket.AddComponent<TopFood>();
		prefabs.Add(seedbasket);
		shelf = assetBundle.LoadAsset<GameObject>(text + "piece_chest_shelf_bal.prefab");
		ShaderReplacment.Replace(shelf);
		shelf.AddComponent<TopPotion>();
		prefabs.Add(shelf);
		shed = assetBundle.LoadAsset<GameObject>(text + "piece_chest_woodshed_bal.prefab");
		ShaderReplacment.Replace(shed);
		TopContainer topContainer7 = shed.AddComponent<TopContainer>();
		topContainer7.slotAmount = 28;
		prefabs.Add(shed);
		basket = assetBundle.LoadAsset<GameObject>(text + "piece_chest_rockshed_bal.prefab");
		ShaderReplacment.Replace(basket);
		TopContainer topContainer8 = basket.AddComponent<TopContainer>();
		topContainer8.slotAmount = 24;
		prefabs.Add(basket);
		trough = assetBundle.LoadAsset<GameObject>(text + "piece_chest_trough_bal.prefab");
		ShaderReplacment.Replace(trough);
		TopContainer topContainer9 = trough.AddComponent<TopContainer>();
		topContainer9.slotAmount = 3;
		prefabs.Add(trough);
		locker = assetBundle.LoadAsset<GameObject>(text + "piece_chest_metalshed_bal.prefab");
		ShaderReplacment.Replace(locker);
		TopContainer topContainer10 = locker.AddComponent<TopContainer>();
		topContainer10.slotAmount = 24;
		prefabs.Add(locker);
	}

	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)"BALROND CONTAINERS: 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 "piece_chest_weaponrack":
			piece.m_name = "Visual weapon shelf";
			piece.m_description = "Will display each weapon and tool per slot.(Dose nto support shields)";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("RoundLog", 15));
			list.Add(createReq("Chain", 2));
			list.Add(createReq("BronzeNails", 12));
			list.Add(createReq("Iron", 2));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_fabricshelf_bal":
			piece.m_name = "Visual fabric shelf";
			piece.m_description = "Will display leather and fabric put inside per slot.";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("RoundLog", 8));
			list.Add(createReq("Copper", 2));
			list.Add(createReq("BronzeNails", 12));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_foodtable":
			piece.m_name = "Visual food table";
			piece.m_description = "Will display food on each slot presented on a plate. 10 slot";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 6));
			list.Add(createReq("RoundLog", 20));
			list.Add(createReq("Copper", 4));
			list.Add(createReq("BronzeNails", 22));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_foodtable_oak":
			piece.m_name = "Visual food table";
			piece.m_description = "Will display food on each slot presented on a plate. And has a nice candle light 12 slot";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 30));
			list.Add(createReq("Copper", 8));
			list.Add(createReq("Tar", 3));
			list.Add(createReq("IronNails", 40));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_foodtable_round":
			piece.m_name = "Visual food table";
			piece.m_description = "Will display food on each slot presented on a plate. 8 slot";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 20));
			list.Add(createReq("Copper", 4));
			list.Add(createReq("Tar", 3));
			list.Add(createReq("IronNails", 40));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_foodtable_fine":
			piece.m_name = "Visual food table";
			piece.m_description = "Will display food on each slot presented on a plate. 4 slot";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 10));
			list.Add(createReq("BronzeNails", 10));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_barrel_bal":
			piece.m_name = "Visual barrel";
			piece.m_description = "Will display on top one of items put inside.";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("RoundLog", 10));
			list.Add(createReq("Copper", 4));
			list.Add(createReq("BronzeNails", 10));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_seedbasket_bal":
			piece.m_name = "Visual basket";
			piece.m_description = "Will display on top one of items put inside. Focus on seeds and vegetables!";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("Wood", 8));
			list.Add(createReq("BeechSeeds", 6));
			list.Add(createReq("LeatherScraps", 6));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_shelf_bal":
			piece.m_name = "Visual Shelf";
			piece.m_description = "Will display each elixir put inside per slot";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("FineWood", 6));
			list.Add(createReq("Wood", 6));
			list.Add(createReq("Copper", 2));
			list.Add(createReq("BronzeNails", 12));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_woodshed_bal":
			piece.m_name = "Visual woodshed";
			piece.m_description = "Will display each wood stack put inside";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("RoundLog", 20));
			list.Add(createReq("FineWood", 15));
			list.Add(createReq("LeatherScraps", 10));
			list.Add(createReq("IronNails", 20));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_rockshed_bal":
			piece.m_name = "Visual Ore Basket";
			piece.m_description = "Will display each rock stack and ore inside. Scrap is not Ore!";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("RoundLog", 20));
			list.Add(createReq("Stone", 10));
			list.Add(createReq("Iron", 2));
			list.Add(createReq("BronzeNails", 40));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_trough_bal":
			piece.m_name = "Visual trough";
			piece.m_description = "Will display animal food put inside";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("RoundLog", 3));
			list.Add(createReq("Wood", 3));
			list.Add(createReq("FineWood", 3));
			list.Add(createReq("BronzeNails", 12));
			piece.m_resources = list.ToArray();
			break;
		case "piece_chest_metalshed_bal":
			piece.m_name = "Visual metal shelf";
			piece.m_description = "Will display 2 metal bars for each stack inside";
			piece.m_craftingStation = FindStation(buildPieces, "piece_workbench");
			list.Clear();
			list.Add(createReq("RoundLog", 12));
			list.Add(createReq("Stone", 30));
			list.Add(createReq("Iron", 4));
			list.Add(createReq("BronzeNails", 20));
			piece.m_resources = list.ToArray();
			break;
		}
	}
}
public class ShaderReplacment
{
	public static List<GameObject> GOToSwap = new List<GameObject>();

	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>();

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

	public static void findShadersByName()
	{
		Shader[] collection = Resources.FindObjectsOfTypeAll<Shader>();
		shaders.AddRange(collection);
	}

	public static void ReplaceShadersInObject(Renderer[] renderers)
	{
		foreach (Renderer val in renderers)
		{
			Material[] sharedMaterials = val.sharedMaterials;
			if (sharedMaterials != null && sharedMaterials.Length != 0)
			{
				fixMaterial(sharedMaterials);
			}
		}
	}

	private static void fixMaterial(Material[] shared)
	{
		foreach (Material val in shared)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			Shader shader = val.shader;
			if (!((Object)(object)shader == (Object)null))
			{
				string name = ((Object)shader).name;
				if (!(name == "Standard") && name.Contains("Balrond"))
				{
					setProperValue(val, name);
				}
			}
		}
	}

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

	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;
	}
}
[Serializable]
public class TopContainer : MonoBehaviour
{
	public Container container;

	public Piece piece;

	public ZNetView znet;

	public Inventory inventory;

	public int prevAmount = 0;

	public float currentWeight = 0f;

	public List<GameObject> shelfSlots = new List<GameObject>();

	public int slotAmount = 3;

	public bool isSetup = false;

	public bool isLanuched = false;

	public GameObject[] activeSlots;

	public List<ItemData> currentList = new List<ItemData>();

	private void Start()
	{
		piece = ((Component)this).GetComponent<Piece>();
		znet = ((Component)this).GetComponent<ZNetView>();
		container = ((Component)this).GetComponent<Container>();
		if ((Object)(object)container == (Object)null)
		{
			Debug.Log((object)"BALROND CONTAINERS: container  NOT found");
			return;
		}
		prepareContainer();
		inventory = container.m_inventory;
		if (isSetup && validate())
		{
			((MonoBehaviour)this).InvokeRepeating("setSlot", 1f, 4f);
			isLanuched = true;
		}
	}

	public void prepareContainer()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		List<GameObject> list = new List<GameObject>();
		for (int i = 0; i < slotAmount; i++)
		{
			list.Add(null);
		}
		activeSlots = list.ToArray();
		foreach (Transform item in ((Component)this).transform)
		{
			Transform val = item;
			if (((Object)val).name == "slot")
			{
				shelfSlots.Add(((Component)val).gameObject);
			}
		}
		isSetup = true;
	}

	private bool validate()
	{
		if ((Object)(object)container == (Object)null && !znet.IsValid())
		{
			Debug.LogWarning((object)"I did not pass Validation");
			return false;
		}
		if (inventory == null)
		{
			inventory = container.m_inventory;
		}
		if (inventory == null)
		{
			return false;
		}
		return true;
	}

	private bool compareWeight()
	{
		float totalWeight = inventory.GetTotalWeight();
		if (totalWeight != currentWeight)
		{
			currentWeight = totalWeight;
			return true;
		}
		return false;
	}

	private void FixedUpdate()
	{
		if (isSetup && validate() && !isLanuched)
		{
			((MonoBehaviour)this).InvokeRepeating("setSlot", 1f, 4f);
			isLanuched = true;
		}
	}

	public void setSlot()
	{
		if (!validate())
		{
			return;
		}
		List<ItemData> list = new List<ItemData>();
		list = inventory.GetAllItems();
		if (list == null)
		{
			return;
		}
		int num = list.Count();
		if (num > slotAmount)
		{
			return;
		}
		for (int i = 0; i < activeSlots.Length; i++)
		{
			if ((Object)(object)activeSlots[i] != (Object)null)
			{
				activeSlots[i].SetActive(false);
				activeSlots[i] = null;
			}
		}
		if (num <= 0)
		{
			return;
		}
		int num2 = 1;
		foreach (ItemData item in list)
		{
			int index = num - num2;
			checkSlot(shelfSlots[num - num2], ((Object)item.m_dropPrefab).name, index);
			num2++;
		}
	}

	private void checkSlot(GameObject slot, string name, int index)
	{
		if ((Object)(object)activeSlots[index] != (Object)null && ((Object)activeSlots[index]).name == name)
		{
			return;
		}
		Transform val = slot.transform.Find(name);
		if ((Object)(object)val == (Object)null)
		{
			if ((Object)(object)activeSlots[index] != (Object)null)
			{
				activeSlots[index].SetActive(false);
				activeSlots[index] = null;
			}
			return;
		}
		if ((Object)(object)activeSlots[index] != (Object)null)
		{
			activeSlots[index].SetActive(false);
		}
		activeSlots[index] = ((Component)val).gameObject;
		activeSlots[index].SetActive(true);
	}
}
[Serializable]
public class TopFood : MonoBehaviour
{
	public Container container;

	public Piece piece;

	public ZNetView znet;

	public Inventory inventory;

	public int prevAmount = 0;

	public float currentWeight = 0f;

	public List<GameObject> shelfSlots = new List<GameObject>();

	public int slotAmount = 3;

	public bool isSetup = false;

	public bool isLanuched = false;

	public GameObject[] activeSlots = (GameObject[])(object)new GameObject[0];

	public GameObject visibleMesh;

	public bool isVisible = false;

	public GameObject topfood;

	public string currentName;

	private void Start()
	{
		piece = ((Component)this).GetComponent<Piece>();
		znet = ((Component)this).GetComponent<ZNetView>();
		container = ((Component)this).GetComponent<Container>();
		if ((Object)(object)container == (Object)null)
		{
			Debug.Log((object)"BALROND CONTAINERS: container  NOT found");
			return;
		}
		prepareContainer();
		inventory = container.m_inventory;
		if (isSetup && validate())
		{
			((MonoBehaviour)this).InvokeRepeating("setSlot", 1f, 4f);
			isLanuched = true;
		}
	}

	private void prepareContainer()
	{
		topfood = ((Component)((Component)this).transform.Find("topfood")).gameObject;
		isSetup = true;
	}

	private bool validate()
	{
		if ((Object)(object)container == (Object)null || (Object)(object)znet == (Object)null || !znet.IsValid())
		{
			return false;
		}
		if (inventory == null)
		{
			inventory = container.m_inventory;
		}
		if (inventory == null)
		{
			return false;
		}
		return true;
	}

	private bool compareWeight()
	{
		float totalWeight = inventory.GetTotalWeight();
		if (totalWeight != currentWeight)
		{
			currentWeight = totalWeight;
			return true;
		}
		return false;
	}

	private void FixedUpdate()
	{
		if (isSetup && validate() && !isLanuched)
		{
			((MonoBehaviour)this).InvokeRepeating("setSlot", 1f, 4f);
			isLanuched = true;
		}
	}

	public void setSlot()
	{
		if (!validate() || inventory == null || !znet.IsValid())
		{
			return;
		}
		List<ItemData> list = new List<ItemData>();
		list = inventory.GetAllItems();
		if (list == null || list.Count() == 0)
		{
			isVisible = false;
			currentName = null;
			if ((Object)(object)visibleMesh != (Object)null)
			{
				visibleMesh.SetActive(false);
			}
			visibleMesh = null;
			return;
		}
		string name = ((Object)list[0].m_dropPrefab).name;
		if (currentName != name || currentName == null)
		{
			currentName = name;
			if ((Object)(object)visibleMesh != (Object)null)
			{
				visibleMesh.SetActive(false);
			}
			Transform val = topfood.transform.Find(currentName);
			if ((Object)(object)val != (Object)null)
			{
				visibleMesh = ((Component)val).gameObject;
				visibleMesh.SetActive(true);
				isVisible = true;
			}
		}
	}
}
[Serializable]
public class TopPotion : MonoBehaviour
{
	public Container container;

	public Piece piece;

	public ZNetView znet;

	public Inventory inventory;

	public int prevAmount = 0;

	public float currentWeight = 0f;

	public List<GameObject> shelfSlots = new List<GameObject>();

	public int slotAmount = 3;

	public bool isSetup = false;

	public bool isLanuched = false;

	public GameObject[] activeSlots = (GameObject[])(object)new GameObject[0];

	private void Start()
	{
		piece = ((Component)this).GetComponent<Piece>();
		znet = ((Component)this).GetComponent<ZNetView>();
		container = ((Component)this).GetComponent<Container>();
		if ((Object)(object)container == (Object)null)
		{
			Debug.Log((object)"BALROND CONTAINERS: container  NOT found");
			return;
		}
		prepareContainer();
		inventory = container.m_inventory;
		if (isSetup && validate())
		{
			((MonoBehaviour)this).InvokeRepeating("setSlot", 1f, 4f);
			isLanuched = true;
		}
	}

	private void FixedUpdate()
	{
		if (isSetup && validate() && !isLanuched)
		{
			((MonoBehaviour)this).InvokeRepeating("setSlot", 1f, 4f);
			isLanuched = true;
		}
	}

	public void prepareContainer()
	{
		slotAmount = 9;
		List<GameObject> list = new List<GameObject>();
		for (int i = 0; i < slotAmount; i++)
		{
			list.Add(null);
		}
		activeSlots = list.ToArray();
		shelfSlots.Add(((Component)((Component)this).transform.Find("potionslot-1")).gameObject);
		shelfSlots.Add(((Component)((Component)this).transform.Find("potionslot-2")).gameObject);
		shelfSlots.Add(((Component)((Component)this).transform.Find("potionslot-3")).gameObject);
		shelfSlots.Add(((Component)((Component)this).transform.Find("potionslot-4")).gameObject);
		shelfSlots.Add(((Component)((Component)this).transform.Find("potionslot-5")).gameObject);
		shelfSlots.Add(((Component)((Component)this).transform.Find("potionslot-6")).gameObject);
		shelfSlots.Add(((Component)((Component)this).transform.Find("potionslot-7")).gameObject);
		shelfSlots.Add(((Component)((Component)this).transform.Find("potionslot-8")).gameObject);
		shelfSlots.Add(((Component)((Component)this).transform.Find("potionslot-9")).gameObject);
		isSetup = true;
	}

	private bool validate()
	{
		if ((Object)(object)container == (Object)null || !znet.IsValid())
		{
			return false;
		}
		if (inventory == null)
		{
			inventory = container.m_inventory;
		}
		if (inventory == null)
		{
			return false;
		}
		return true;
	}

	private bool compareWeight()
	{
		float totalWeight = inventory.GetTotalWeight();
		if (totalWeight != currentWeight)
		{
			currentWeight = totalWeight;
			return true;
		}
		return false;
	}

	public void setSlot()
	{
		if (!validate())
		{
			return;
		}
		List<ItemData> list = new List<ItemData>();
		list = inventory.GetAllItems();
		if (list == null)
		{
			return;
		}
		int num = list.Count();
		for (int i = 0; i < activeSlots.Length; i++)
		{
			if ((Object)(object)activeSlots[i] != (Object)null)
			{
				activeSlots[i].SetActive(false);
				activeSlots[i] = null;
			}
		}
		if (num <= 0)
		{
			return;
		}
		int num2 = 1;
		foreach (ItemData item in list)
		{
			int index = num - num2;
			checkSlot(shelfSlots[num - num2], ((Object)item.m_dropPrefab).name, index);
			num2++;
		}
	}

	private void checkSlot(GameObject slot, string name, int index)
	{
		if ((Object)(object)activeSlots[index] != (Object)null && ((Object)activeSlots[index]).name == name)
		{
			return;
		}
		Transform val = slot.transform.Find(name);
		if ((Object)(object)val == (Object)null)
		{
			if ((Object)(object)activeSlots[index] != (Object)null)
			{
				activeSlots[index].SetActive(false);
				activeSlots[index] = null;
			}
			return;
		}
		if ((Object)(object)activeSlots[index] != (Object)null)
		{
			activeSlots[index].SetActive(false);
		}
		activeSlots[index] = ((Component)val).gameObject;
		activeSlots[index].SetActive(true);
	}
}