private static void Serialize(TreeManager.Data data, DataSerializer s)
			{
				Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.BeginSerialize(s, "TreeManager");
				TreeInstance[] mBuffer = Singleton<TreeManager>.instance.m_trees.m_buffer;
				int num = 262144;
				EncodedArray.UShort num1 = EncodedArray.UShort.BeginWrite(s);
				for (int i = 1; i < num; i++)
				{
					num1.Write(mBuffer[i].m_flags);
				}
				num1.EndWrite();
				try
				{
					PrefabCollection<TreeInfo>.BeginSerialize(s);
					for (int j = 1; j < num; j++)
					{
						if (mBuffer[j].m_flags != 0)
						{
							PrefabCollection<TreeInfo>.Serialize(mBuffer[j].m_infoIndex);
						}
					}
				}
				finally
				{
					PrefabCollection<TreeInfo>.EndSerialize(s);
				}
				EncodedArray.Short num2 = EncodedArray.Short.BeginWrite(s);
				for (int k = 1; k < num; k++)
				{
					if (mBuffer[k].m_flags != 0)
					{
						num2.Write(mBuffer[k].m_posX);
					}
				}
				num2.EndWrite();
				EncodedArray.Short num3 = EncodedArray.Short.BeginWrite(s);
				for (int l = 1; l < num; l++)
				{
					if (mBuffer[l].m_flags != 0)
					{
						num3.Write(mBuffer[l].m_posZ);
					}
				}
				num3.EndWrite();
				Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.EndSerialize(s, "TreeManager");
			}
Example #2
0
        // The given DataSerializer is the dummy one that writes to Stream.Null.
        public void Serialize(DataSerializer s)
        {
            if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
            {
                Logger.dbgLog("Fake serialize from " + startIndex.ToString() + " to " + idxList.Count.ToString());
            }

            // Setup a dummy PrefabCollection<TreeInfo>.m_encodedArray so that we can continue refcounting.
            FieldInfo encoderField = typeof(PrefabCollection <TreeInfo>).GetField("m_encodedArray", BindingFlags.NonPublic | BindingFlags.Static);

            EncodedArray.UShort original = (EncodedArray.UShort)encoderField.GetValue(null);

            try
            {
                EncodedArray.UShort dummy = EncodedArray.UShort.BeginWrite(s);
                encoderField.SetValue(null, dummy);

                // Now that the do-nothing m_encodedArray has been set, we can safely continue refcounting.
                TreeInstance[] mBuffer = Singleton <TreeManager> .instance.m_trees.m_buffer;
                int            limit   = idxList.Count;

                for (int j = startIndex; j < limit; j++)
                {
                    if (mBuffer[idxList[j]].m_flags != 0)
                    {
                        PrefabCollection <TreeInfo> .Serialize(mBuffer[idxList[j]].m_infoIndex);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.dbgLog("", ex, true);
            }

            finally
            {
                encoderField.SetValue(null, original);
            }
        }
			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");
			}
Example #4
0
        /// <summary>
        /// Custom serialize call
        /// </summary>
        /// <param name="idxList"> ByRef to the List of ints representing tree indexes that should be serialised</param>
        /// <param name="s">ByRef to The DataSerializer object </param>
        internal static void Serialize(ref List <int> idxList, ref DataSerializer s)
        {
            //Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.BeginSerialize(s, "TreeManager");


            if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
            {
                if (idxList == null)
                {
                    Logger.dbgLog("idxlist is null. lastsaveusedpacking: " + LoadingExtension.LastSaveUsedPacking.ToString());
                }
                else
                {
                    Logger.dbgLog("idxlist count: " + idxList.Count + " lastsaveusedpacking: " + LoadingExtension.LastSaveUsedPacking.ToString());
                }

                if (OptionsWrapper <Configuration> .Options.GhostModeEnabled)
                {
                    Logger.dbgLog("Ghost Mode is activated!");
                }
            }

            TreeInstance[] mBuffer = Singleton <TreeManager> .instance.m_trees.m_buffer;
            FastList <TreeManager.BurningTree> tmburning = Singleton <TreeManager> .instance.m_burningTrees;
            int num = Mod.DEFAULT_TREE_COUNT; //262144

            //if (idxList != null && idxList.Count >= Mod.DEFAULT_TREE_COUNT) //custom one.
            if (idxList != null && idxList.Count > 1) //always use custom one unless problem.
            {
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("Start using packer seralizer for first 262144 realones.");
                }
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && idxList.Count < 262144)
                {
                    Logger.dbgLog(string.Format("tree seralizer will serialize first {0} trees then dummy up the rest.", idxList.Count));
                }
                LoadingExtension.LastSaveUsedPacking = true;
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("Loader.LastSaveUsedPacking now set to True.");
                }

                EncodedArray.UShort num1 = EncodedArray.UShort.BeginWrite(s);

                //remember idxlist index entry 0 is also zeroed'd to account for treebuffer starting at 1 not 0)
                for (int i = 1; i < num; i++)
                {
                    if (i < idxList.Count)
                    {
                        num1.Write(mBuffer[idxList[i]].m_flags);
                    }
                    else
                    {
                        num1.Write(0);
                    }
                }
                num1.EndWrite();
                //now lets process the treeinfo
                try
                {
                    PrefabCollection <TreeInfo> .BeginSerialize(s);

                    //
                    int limit = Math.Min(num, idxList.Count);
                    for (int j = 1; j < limit; j++)
                    {
                        if (j < idxList.Count)  //pretty sure I had this here for a reason as count could be 0 or 1 in cases of error or no real trees.
                        {
                            if (mBuffer[idxList[j]].m_flags != 0)
                            {
                                PrefabCollection <TreeInfo> .Serialize(mBuffer[idxList[j]].m_infoIndex);
                            }
                        }
                        else
                        {
                            Logger.dbgLog("j >= idxList.Count Do we ever hit this?? No real trees to save.");
                        }
                    }

                    //Thale5's cool refcounter work around --THANKS!!
                    // This is the easiest (and only) way to create a dummy DataSerializer that writes to Stream.Null.
                    // This will simply call RefCounter.Serialize() below.
                    try
                    {
                        if (idxList.Count > limit)
                        {
                            if ((OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1))
                            {
                                Logger.dbgLog("Incrementing related reference counts for prefabs for trees > " + limit.ToString());
                            }

                            DataSerializer.Serialize(System.IO.Stream.Null, DataSerializer.Mode.Memory, 0, new RefCounter(limit, idxList));
                        }
                    }
                    catch (Exception ex)
                    { Logger.dbgLog("RefCounter caused an error:", ex, true); }
                }
                finally
                {
                    PrefabCollection <TreeInfo> .EndSerialize(s);
                }

                EncodedArray.Short num2 = EncodedArray.Short.BeginWrite(s);
                for (int k = 1; k < num; k++)
                {
                    if (k < idxList.Count)
                    {
                        if (mBuffer[idxList[k]].m_flags != 0)
                        {
                            num2.Write(mBuffer[idxList[k]].m_posX);
                        }
                    }
                }
                num2.EndWrite();

                EncodedArray.Short num3 = EncodedArray.Short.BeginWrite(s);
                for (int l = 1; l < num; l++)
                {
                    if (l < idxList.Count)
                    {
                        if (mBuffer[idxList[l]].m_flags != 0)
                        {
                            num3.Write(mBuffer[idxList[l]].m_posZ);
                        }
                    }
                }
                num3.EndWrite();

                //reorder if neccessary
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("reordering burning trees indexes for our seralizer. (packed)");
                }

                if ((uint)tmburning.m_size > 0)
                {
                    FastList <TreeManager.BurningTree> returnedMatchingBurnList;
                    int retval = ReOrderBurningTrees(ref idxList, out returnedMatchingBurnList);
                    FastList <TreeManager.BurningTree> orgBurningTrees; //used below holds tmp copy of burningtrees;

                    //we only need burning tress with indexes < 262144k.
                    orgBurningTrees = CopyBurningTreesList(ref returnedMatchingBurnList, 1);
                    //create 2  fastlists of burning trees from idxlist
                    //one with indexes 0 -> 262143  one with indexes > 262144
                    //save 0-262k list as usual
                    //save 262k+ list to our own storage devices via customer serializer class that gets called before this.

                    if (orgBurningTrees == null)
                    {
                        Logger.dbgLog("orgBurningTrees is null, copyburningtrees retuned null array.");
                        orgBurningTrees = new FastList <TreeManager.BurningTree>();
                        Logger.dbgLog("We dummied up a fake 0 count one.");
                    }
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog("Adjusted burning trees for our seralizer.(packed-reorderedlist)");
                    }
                    //
                    s.WriteUInt24((uint)orgBurningTrees.m_size);
                    for (int m = 0; m < orgBurningTrees.m_size; m++)
                    {
                        s.WriteUInt24(orgBurningTrees.m_buffer[m].m_treeIndex);
                        s.WriteUInt8(orgBurningTrees.m_buffer[m].m_fireIntensity);
                        s.WriteUInt8(orgBurningTrees.m_buffer[m].m_fireDamage);
                    }
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog("Saved " + orgBurningTrees.m_size.ToString() + " packed burning trees");
                    }
                }
                else
                {
                    //There are supposedly no burningtree so just exec the original code untouched.
                    //org
                    s.WriteUInt24((uint)tmburning.m_size);
                    for (int m = 0; m < tmburning.m_size; m++)
                    {
                        s.WriteUInt24(tmburning.m_buffer[m].m_treeIndex);
                        s.WriteUInt8(tmburning.m_buffer[m].m_fireIntensity);
                        s.WriteUInt8(tmburning.m_buffer[m].m_fireDamage);
                    }
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog("Saved " + tmburning.m_size.ToString() + " org burning trees (pack but empty)");
                    }
                }

                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("End using packer seralizer.  " + DateTime.Now.ToString(Mod.DTMilli));
                }
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled())
                {
                    Logger.dbgLog("Tree saving process completed. (packed) " + DateTime.Now.ToString(Mod.DTMilli));
                }
            }

            else //use original. we can hit this when we're active but packer either didn't get used or we are in ghost mode.
            {
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("idxList was Null or idxList.Count was < 2");
                }
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("Start using original seralizer.");
                }
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("Loader.LastSaveUsedPacking state = " + LoadingExtension.LastSaveUsedPacking.ToString());
                }
                EncodedArray.UShort num1 = EncodedArray.UShort.BeginWrite(s);
                for (int i = 1; i < num; i++)
                {
                    num1.Write(mBuffer[i].m_flags);
                }
                num1.EndWrite();
                try
                {
                    PrefabCollection <TreeInfo> .BeginSerialize(s);

                    for (int j = 1; j < num; j++)
                    {
                        if (mBuffer[j].m_flags != 0)
                        {
                            PrefabCollection <TreeInfo> .Serialize(mBuffer[j].m_infoIndex);
                        }
                    }
                }
                finally
                {
                    PrefabCollection <TreeInfo> .EndSerialize(s);
                }

                EncodedArray.Short num2 = EncodedArray.Short.BeginWrite(s);
                for (int k = 1; k < num; k++)
                {
                    if (mBuffer[k].m_flags != 0)
                    {
                        num2.Write(mBuffer[k].m_posX);
                    }
                }
                num2.EndWrite();
                EncodedArray.Short num3 = EncodedArray.Short.BeginWrite(s);
                for (int l = 1; l < num; l++)
                {
                    if (mBuffer[l].m_flags != 0)
                    {
                        num3.Write(mBuffer[l].m_posZ);
                    }
                }
                num3.EndWrite();

                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("Adjusting burning trees for original seralizer.");
                }
                //12-4 KH - you know we could ecapsilate this with above.
                // save some code, for now leaving it though.

                //Since we are not packing we don't need to reorder, but we do
                //need just trees < 262144k

                //we feed it the real TreeManager.burningtrees. get back 0-262k
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("No reordering of trees indexes used.");
                }
                if (tmburning.m_size > 0)
                {
                    FastList <TreeManager.BurningTree> orgBurningTrees2; //used below holds tmp copy of burningtrees;
                    orgBurningTrees2 = CopyBurningTreesList(ref tmburning, 1);

                    if (orgBurningTrees2 != null)
                    {
                        Logger.dbgLog("orgBurningTrees2 is null, copyburning returned null? Dummy up new one don't save burning");
                        orgBurningTrees2 = new FastList <TreeManager.BurningTree>();
                    }

                    s.WriteUInt24((uint)orgBurningTrees2.m_size);
                    for (int m = 0; m < orgBurningTrees2.m_size; m++)
                    {
                        s.WriteUInt24(orgBurningTrees2.m_buffer[m].m_treeIndex);
                        s.WriteUInt8(orgBurningTrees2.m_buffer[m].m_fireIntensity);
                        s.WriteUInt8(orgBurningTrees2.m_buffer[m].m_fireDamage);
                    }
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog("Saved " + orgBurningTrees2.m_size.ToString() + " org burning trees");
                    }
                }
                else
                {
                    //use real original cause it' empty anyway?
                    s.WriteUInt24((uint)tmburning.m_size);
                    for (int m = 0; m < tmburning.m_size; m++)
                    {
                        s.WriteUInt24(tmburning.m_buffer[m].m_treeIndex);
                        s.WriteUInt8(tmburning.m_buffer[m].m_fireIntensity);
                        s.WriteUInt8(tmburning.m_buffer[m].m_fireDamage);
                    }
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog("Saved " + tmburning.m_size.ToString() + " org burning trees (org empty)");
                    }
                }

                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                {
                    Logger.dbgLog("End using original seralizer.  " + DateTime.Now.ToString(Mod.DTMilli));
                }
                if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled())
                {
                    Logger.dbgLog("Tree saving process completed. (original) " + DateTime.Now.ToString(Mod.DTMilli));
                }
            }
            // Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.EndSerialize(s, "TreeManager");
        }