private static void ReleaseTreeImplementation(TreeManager tm, uint tree, ref TreeInstance data)
		{
            if (data.m_flags != 0)
            {
                InstanceID instanceID = new InstanceID()
                {
                    Tree = tree
                };
                Singleton<InstanceManager>.instance.ReleaseInstance(instanceID);
                data.m_flags = (ushort)(data.m_flags | 2);
                data.UpdateTree(tree);
                data.m_flags = 0;
                try
                {
                    LimitTreeManager.FinalizeTree(tm, tree, ref data);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    object[] objArray = new object[] { tree, tm.m_trees.m_size, LimitTreeManager.Helper.TreeLimit, LimitTreeManager.Helper.UseModifiedTreeCap };
                    Debug.LogFormat("[TreeUnlimiter::ReleaseTreeImplementation] Treexception: Releasing {0} {1} {2} {3}", objArray);
                    Debug.LogException(exception);
                }
                tm.m_trees.ReleaseItem(tree);
                tm.m_treeCount = (int)(tm.m_trees.ItemCount() - 1);
            }
        }
			private static void Deserialize(TreeManager.Data data, DataSerializer s)
			{
				short num;
				short num1;
                if (TreeUnlimiter.Mod.DEBUG_LOG_ON == true) { Debug.Log("[TreeUnlimiter::LimitTreeManager::Data:Deserialize()] calling Ensure Init"); }
                LimitTreeManager.Helper.EnsureInit(1);
				Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.BeginDeserialize(s, "TreeManager");
				TreeManager treeManager = Singleton<TreeManager>.instance;
				TreeInstance[] mBuffer = treeManager.m_trees.m_buffer;
                if(TreeUnlimiter.Mod.DEBUG_LOG_ON == true) { Debug.Log("[TreeUnlimiter::LimitTreeManager::Data:Deserialize()] mbuffersize=" + mBuffer.Length.ToString()); }
                uint[] mTreeGrid = treeManager.m_treeGrid;
				int num2 = 262144;
				int length = (int)mTreeGrid.Length;
				treeManager.m_trees.ClearUnused();
				SimulationManager.UpdateMode mUpdateMode = Singleton<SimulationManager>.instance.m_metaData.m_updateMode;
                if (TreeUnlimiter.Mod.DEBUG_LOG_ON == true) { Debug.LogFormat("[TreeUnlimiter:LimitTreeManager::Data::Deserialize()] mUpdatemode" + mUpdateMode.ToString()); }
                bool flag = (mUpdateMode == SimulationManager.UpdateMode.NewAsset ? true : mUpdateMode == SimulationManager.UpdateMode.LoadAsset);

                for (int i = 0; i < length; i++)
				{
					mTreeGrid[i] = 0;
				}
				EncodedArray.UShort num3 = EncodedArray.UShort.BeginRead(s);
				for (int j = 1; j < num2; j++)
				{
					mBuffer[j].m_flags = num3.Read();
				}
				num3.EndRead();
				PrefabCollection<TreeInfo>.BeginDeserialize(s);
				for (int k = 1; k < num2; k++)
				{
					if (mBuffer[k].m_flags != 0)
					{
						mBuffer[k].m_infoIndex = (ushort)PrefabCollection<TreeInfo>.Deserialize();
					}
				}
				PrefabCollection<TreeInfo>.EndDeserialize(s);
				EncodedArray.Short num4 = EncodedArray.Short.BeginRead(s);
				for (int l = 1; l < num2; l++)
				{
					if (mBuffer[l].m_flags == 0)
					{
						num = 0;
					}
					else
					{
						num = num4.Read();
					}
					mBuffer[l].m_posX = num;
				}
				num4.EndRead();
				EncodedArray.Short num5 = EncodedArray.Short.BeginRead(s);
				for (int m = 1; m < num2; m++)
				{
					if (mBuffer[m].m_flags == 0)
					{
						num1 = 0;
					}
					else
					{
						num1 = num5.Read();
					}
					mBuffer[m].m_posZ = num1;
				}
				num5.EndRead();
				for (int n = 1; n < num2; n++)
				{
					mBuffer[n].m_nextGridTree = 0;
					mBuffer[n].m_posY = 0;
				}
				if (LimitTreeManager.Helper.UseModifiedTreeCap)
				{
                    if (TreeUnlimiter.Mod.DEBUG_LOG_ON == true) { Debug.LogFormat("[TreeUnlimiter::LimitTreeManager::Data:Deserialize()] Using ModifiedTreeCap - Calling Custom Deserializer."); }
					LimitTreeManager.CustomSerializer.Deserialize();
				}
				treeManager.m_trees.ClearUnused();
				for (int o = 0; o < LimitTreeManager.Helper.TreeLimit; o++)
				{
					if (mBuffer[o].m_flags == 0)
					{
						treeManager.m_trees.ReleaseItem((uint)o);
					}
					else
					{
						LimitTreeManager.InitializeTree(treeManager, (uint)o, ref mBuffer[o], flag);
					}
				}
				Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.EndDeserialize(s, "TreeManager");
			}