context: #region Header
  // **********
  // ServUO - ComponentVerification.cs
  // **********
  #endregion
  
  #region References
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  #endregion
  
  namespace Server.Multis
  {
  	public class ComponentVerification
  	{
  		private readonly int[] m_ItemTable;
  		private readonly int[] m_MultiTable;
  
  		public ComponentVerification()
  		{
  			m_ItemTable = CreateTable(TileData.MaxItemValue);
  			m_MultiTable = CreateTable(0x4000);
  
  			LoadItems(
  				"Data/Components/walls.txt",
  				//
  				"South1",
  				"South2",
  				"South3",
  				"Corner",
  				"East1",
  				"East2",
  				"East3",
  				"Post",
  				"WindowS",
  				"AltWindowS",
  				"WindowE",
  				"AltWindowE",
  				"SecondAltWindowS",
  				"SecondAltWindowE");
  
  			LoadItems(
  				"Data/Components/teleprts.txt",
  				//
  				"F1",
  				"F2",
  				"F3",
  				"F4",
  				"F5",
  				"F6",
  				"F7",
  				"F8",
  				"F9",
  				"F10",
  				"F11",
  				"F12",
  				"F13",
  				"F14",
  				"F15",
  				"F16");
  
  			LoadItems(
  				"Data/Components/stairs.txt",
  				//
  				"Block",
  				"North",
  				"East",
  				"South",
  				"West",
  				"Squared1",
  				"Squared2",
  				"Rounded1",
  				"Rounded2");
  
  			LoadItems(
  				"Data/Components/roof.txt",
  				//
  				"North",
  				"East",
  				"South",
  				"West",
  				"NSCrosspiece",
  				"EWCrosspiece",
  				"NDent",
  				"EDent",
  				"SDent",
  				"WDent",
  				"NTPiece",
  				"ETPiece",
  				"STPiece",
  				"WTPiece",
  				"XPiece",
  				"Extra Piece");
  
  			LoadItems(
  				"Data/Components/floors.txt",
  				//
  				"F1",
  				"F2",
  				"F3",
  				"F4",
  				"F5",
  				"F6",
  				"F7",
  				"F8",
  				"F9",
  				"F10",
  				"F11",
  				"F12",
  				"F13",
  				"F14",
  				"F15",
  				"F16");
  
  			LoadItems(
  				"Data/Components/misc.txt",
  				//
  				"Piece1",
  				"Piece2",
  				"Piece3",
  				"Piece4",
  				"Piece5",
  				"Piece6",
  				"Piece7",
  				"Piece8");
  
  			LoadItems(
  				"Data/Components/doors.txt",
  				//
  				"Piece1",
  				"Piece2",
  				"Piece3",
  				"Piece4",
  				"Piece5",
  				"Piece6",
  				"Piece7",
  				"Piece8");
  
  			LoadMultis(
  				"Data/Components/stairs.txt",
  				//
  				"MultiNorth",
  				"MultiEast",
  				"MultiSouth",
  				"MultiWest");
  		}
  
  		public bool IsItemValid(int itemID)
  		{
  			if (itemID <= 0 || itemID >= m_ItemTable.Length)
  			{
  				return false;
  			}
  
  			return CheckValidity(m_ItemTable[itemID]);
  		}
  
  		public bool IsMultiValid(int multiID)
  		{
  			if (multiID <= 0 || multiID >= m_MultiTable.Length)
  			{
  				return false;
  			}
  
  			return CheckValidity(m_MultiTable[multiID]);
  		}
  
  		public bool CheckValidity(int val)
  		{
  			if (val == -1)
  			{
  				return false;
  			}
  
  			return (val == 0 || ((int)ExpansionInfo.CoreExpansion.CustomHousingFlag & val) != 0);
  		}
  
  		private static int[] CreateTable(int length)
  		{
  			var table = new int[length];
  
  			for (var i = 0; i < table.Length; ++i)
  			{
  				table[i] = -1;
  			}
  
  			return table;
  		}
  
  		private void LoadItems(string path, params string[] itemColumns)
  		{
  			LoadSpreadsheet(m_ItemTable, path, itemColumns);
  		}
  
  		private void LoadMultis(string path, params string[] multiColumns)
  		{
  			LoadSpreadsheet(m_MultiTable, path, multiColumns);
  		}
  
  		private static void LoadSpreadsheet(int[] table, string path, params string[] tileColumns)
  		{
              //Rpi - Renamed variables for clarity
  			Spreadsheet spreadsheet = new Spreadsheet(path);
  
  			int[] tileColumnsIDs = new int[tileColumns.Length];
  
  			for (var i = 0; i < tileColumns.Length; ++i)
  			{
  				tileColumnsIDs[i] = spreadsheet.GetColumnID(tileColumns[i]);
  			}
  
  			int featureColumnsID = spreadsheet.GetColumnID("FeatureMask");
  
              //RPi - This code replaces the linq code below
              int featureID;
  
  			//foreach (DataRecord record in spreadsheet.Records)
              for (int counter = 0; counter < spreadsheet.Records.Length; counter++)
  			{
  				featureID = spreadsheet.Records[counter].GetInt32(featureColumnsID);
  
                  //Rpi - Replaces the linq code below
                  for (int loop = 0; loop < tileColumnsIDs.Length; loop++)
                  {
                      for (int element = 1; element < table.Length; element++)
                      {
                          table[tileColumnsIDs[loop]] = featureID;
                      }
                  }
  
                  //Rpi - Removed linq code for better speed
  				/*foreach (var itemID in tileColumnsIDs.Select(v => record.GetInt32(v)).Where(id => id > 0 && id < table.Length))
  				{
  
gt: 					table[itemID] = featureID;