示例#1
0
        public bool Write(DAIIO io, bool skiplength = false)
        {
            try
            {
                io.xbaseStream.Write(DataMagic, 0, 8);
                io.Position = 0x41;
                io.WriteInt64(SavedTime.ToUnixSecondsWithAdd());
                io.WriteInt16((short)SID.Length);
                io.WriteString(SID);
                io.WriteUInt16(GameVersion);
                io.WriteUInt16(SaveVersion);
                io.WriteUInt16(ProjectVersion);
                io.WriteUInt16(BitstreamFeatures);
                io.WriteUInt32(ChangeList);
                io.WriteUInt16((ushort)Level.Length);
                io.WriteString(Level);
                io.WriteUInt32(Difficulty);
                if (BundleList == null)
                {
                    BundleList = new string[BundleCount];

                    for (int xb = 0; xb < BundleCount; xb++)
                    {
                        BundleList[xb] = "";
                    }
                }
                BundleCount = (ushort)BundleList.Length;
                io.WriteUInt16(BundleCount);
                for (int i = 0; i < BundleCount; i++)
                {
                    io.WriteInt16((short)BundleList[i].Length);
                    io.WriteString(BundleList[i]);
                }
                if (Inclusions == null)
                {
                    Inclusions = new Inclusion[InclusionCount];

                    for (int xb = 0; xb < InclusionCount; xb++)
                    {
                        Inclusions[xb] = new Inclusion();
                    }
                }
                InclusionCount = (ushort)Inclusions.Length;
                io.WriteInt16((short)InclusionCount);
                for (int i = 0; i < InclusionCount; i++)
                {
                    Inclusions[i].Write(io);
                }
                if (SubLevelInfoCount <= 0x40 && SubLevelInfoCount > 0)
                {
                    if (SubLevelEntries == null)
                    {
                        SubLevelEntries = new SubLevelInfo[SubLevelInfoCount];

                        for (int xb = 0; xb < SubLevelInfoCount; xb++)
                        {
                            SubLevelEntries[xb] = new SubLevelInfo();
                        }
                    }
                    SubLevelInfoCount = SubLevelEntries.Length;
                    io.WriteBits(SubLevelInfoCount, 0xc);
                    for (int i = 0; i < SubLevelInfoCount; i++)
                    {
                        SubLevelEntries[i].Write(io);
                    }
                }
                if (LevelChecksum == null)
                {
                    LevelChecksum = new byte[0x10];
                }
                for (int i = 0; i < 0x10; i++)
                {
                    io.WriteBits(LevelChecksum[i], 0x8);
                }
                io.WriteBits(DLC, 0x14);
                io.WriteBits(EntityVersion, 0x10);
                io.WriteBits(ProjectVersionContext, 0x10);
                io.WriteBoolean(HasDebugInfo);

                ///////////////////////////////////////////////////////////////////////////////////////////////////
                //////////////////////////////CALCULATE SECTION BOOKMARKS/////////////////////////////////////////
                var pos = io.Position;                                                                     ///////////////////////////////////////////////////////////////////////////
                pos += 0x54;                                                                               ////////////////////////////////////////////////////////////////////////////////////
                pos += (EntityContentLength +                                                              //////////////////////////////////////////////////////////////////
                        (((SaveEntityComplexLength + 0x38) + SaveEntity.Length) + EntityMetaData.Length)); ////
                AgentTocBookmark = (int)pos;                                                               ////////////////////////////////////////////////////////////////
                pos += (AgentToc.Length + 0x18);                                                           ////////////////////////////////////////////////////////////
                ClientDataBookmark = (int)pos;                                                             ////////////////////////////////////////////////////////////
                //////////////////////////////////////////////////////////////////////////////////////////

                io.WriteBits(AgentTocBookmark, 0x1A);
                io.WriteBits(ClientDataBookmark, 0x1A);
                io.WriteBits(EntityContentLength, 0x20);

                ///////////////////////////////////////////////////////////////////////////////
                ////////////////////////WRITE UNFINISHED SECTION//////////////////////////////
                EntityContent.Write(io);                                                 /////////////////////////////////////////////////////
                //MUST WRITE UNFINISHED RAW DATA, REMOVE IF CONTENT HAS BEEN MAPPED OUT/////
                if (tmpdata.Length > 0)                                                  ////////////////////////////////////////////////////
                {
                    io.WriteData(tmpdata, (EntityContentLength - EntityContent.Length)); ////
                }
                /////////////////////////////////////////////////////////////////////////

                //Start writing SaveEntity
                SaveEntityBookmark = (int)io.Position;
                io.WriteBits(SaveEntityComplexLength, 6);
                io.WriteData(SaveEntityComplex, SaveEntityComplexLength);
                io.WriteBits(SaveEntityBookmark, 0x1A);
                SaveEntity.Write(io);
                EntityMetaData.Write(io);
                AgentToc.Write(io);
                ClientData.Write(io);
                // io.FinishWriter();
                if (LastPartSeedLength > 0)
                {
                    io.WriteBits((uint)LastPartSeed, (uint)LastPartSeedLength, true);
                }
                io.Flush();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }