Пример #1
0
        protected override void Parse(ref ByteStreamReader bsr)
        {
            SourceFileHeader = new SourceFileHeader(this);
            SourceFileHeader.ParseStream(ref bsr);
            SaveInfo.ParseContext.CurrentSymbolTable = bsr.ReadSymbolTable(SourceFileHeader.TokenCount, SourceFileHeader.TokenTableSize) !;
            GameHeader = bsr.ReadDataMap("GameHeader", SaveInfo);
            Globals    = bsr.ReadDataMap("GLOBAL", SaveInfo);
            StateFiles = new EmbeddedStateFile[bsr.ReadSInt()];

            for (int i = 0; i < StateFiles.Length; i++)
            {
                StateFiles[i] = EmbeddedStateFile.CreateFromName(this, bsr.ReadCharArray(260));
                int fileLength = bsr.ReadSInt();
                StateFiles[i].ParseStream(bsr.SplitAndSkip(fileLength));
            }

            SaveInfo.Cleanup();
            Debug.Assert(bsr.BytesRemaining == 0);
            SaveInfo.PrintDeterminedDatamaps();
        }
        protected override void Parse(ref ByteStreamReader bsr)
        {
            base.Parse(ref bsr);
            Version = bsr.ReadSInt();
            int nBytesSymbols     = bsr.ReadSInt();
            int nSymbols          = bsr.ReadSInt();
            int nBytesDataHeaders = bsr.ReadSInt();
            int nBytesData        = bsr.ReadSInt();

            SaveInfo.ParseContext.CurrentSymbolTable = bsr.ReadSymbolTable(nSymbols, nBytesSymbols) !;

            int @base = bsr.CurrentByteIndex;

            int sizeHeaders = bsr.ReadSInt();
            int sizeBodies  = bsr.ReadSInt();

            // info about the header block
            BlockHeadersInfo = UtilVector <ParsedDataMap> .RestoreEmbedded("BlockHeadersInfo", "SaveRestoreBlockHeader_t", SaveInfo, ref bsr);

            SaveGameHeaders = new List <SaveGameHeader>(BlockHeadersInfo.Count);
            // read the headers one by one
            foreach (ParsedDataMap headerInfo in BlockHeadersInfo)
            {
                int loc = headerInfo.GetField <int>("locHeader");
                if (loc == -1)
                {
                    continue;
                }
                bsr.CurrentByteIndex = @base + loc;
                SaveGameHeader?sgh = SaveGameHeader.CreateFromHeaderInfo(SaveRef, headerInfo);
                if (sgh == null)
                {
                    continue;
                }
                sgh.ParseStream(ref bsr);
                SaveGameHeaders.Add(sgh);
            }

            //@base = bsr.CurrentByteIndex = @base + sizeHeaders;
            ByteStreamReader bodyBase = bsr.Split();             // block data is offset from this location

            SaveHeader = bsr.ReadDataMap("Save Header", SaveInfo);

            SaveInfo.BaseTime = SaveHeader.GetFieldOrDefault <Time>("time__USE_VCR_MODE");
            //SaveInfo.LandmarkPos // todo gotten from adjacency list?

            @base = bsr.CurrentByteIndex;

            int connections = SaveHeader.GetFieldOrDefault <int>("connectionCount");            // to other maps?
            int lightStyles = SaveHeader.GetFieldOrDefault <int>("lightStyleCount");

            if (connections > 0)
            {
                AdjacencyList = new ParsedDataMap[connections];
                for (int i = 0; i < connections; i++)
                {
                    AdjacencyList[i] = bsr.ReadDataMap("ADJACENCY", SaveInfo);
                }
            }
            if (lightStyles > 0)
            {
                LightStyleList = new ParsedDataMap[lightStyles];
                for (int i = 0; i < lightStyles; i++)
                {
                    LightStyleList[i] = bsr.ReadDataMap("LIGHTSTYLE", SaveInfo);
                }
            }

            @base = bsr.CurrentByteIndex;

            Blocks = new List <SaveStateBlock>(SaveGameHeaders.Count);

            // now read the actual blocks of data based off of information from the headers
            foreach (SaveGameHeader header in SaveGameHeaders)
            {
                int loc = header.DataHeader.GetFieldOrDefault <int>("locBody");
                if (loc == -1)
                {
                    continue;
                }
                //bodyBase.CurrentByteIndex = loc;
                //bsr.CurrentByteIndex = @base;
                if (!SaveStateBlock.CreateFromHeader(SaveRef !, header, out SaveStateBlock blockHandler))
                {
                    SaveInfo.AddError($"{nameof(SaveStateBlock)} not created from header: \"{header.Name}\"");
                    continue;
                }
                blockHandler.ParseStream(ref bodyBase);
                Blocks.Add(blockHandler);
            }

            //bsr.CurrentByteIndex = @base + sizeBodies;
        }