Пример #1
0
        static void SaveInfos(BinaryWriter writer)
        {
            var section = new SaveInfoSection();
            section.Type = ScummHelper.MakeTag('I', 'N', 'F', 'O');
            section.Version = InfoSectionVersion;
            section.Size = SaveInfoSectionSize;

            // TODO: still save old format for older versions
            section.TimeTValue = 0;
            section.PlayTime = 0;

            //TimeDate curTime;
            //_system->getTimeAndDate(curTime);

            //section.date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
            //section.time = ((curTime.tm_hour & 0xFF) << 8) | ((curTime.tm_min) & 0xFF);

            writer.WriteUInt32BigEndian(section.Type);
            writer.WriteUInt32BigEndian(section.Version);
            writer.WriteUInt32BigEndian(section.Size);
            writer.WriteUInt32BigEndian(section.TimeTValue);
            writer.WriteUInt32BigEndian(section.PlayTime);
            writer.WriteUInt32BigEndian(section.Date);
            writer.WriteUInt16(section.Time);
        }
Пример #2
0
        void SaveThumbnail(BinaryWriter output, Surface thumb)
        {
            var bpp = Surface.GetBytesPerPixel(thumb.PixelFormat);
            if (bpp != 2 && bpp != 4)
            {
                // TODO: warning("trying to save thumbnail with bpp %u", bpp);
                return;
            }

            ThumbnailHeader header = new ThumbnailHeader();
            header.Type = ScummHelper.MakeTag('T', 'H', 'M', 'B');
            header.Size = (uint)(ThumbnailHeaderSize + thumb.Width * thumb.Height * bpp);
            header.Version = THMB_VERSION;
            header.Width = (ushort)thumb.Width;
            header.Height = (ushort)thumb.Height;

            output.WriteUInt32BigEndian(header.Type);
            output.WriteUInt32BigEndian(header.Size);
            output.WriteByte(header.Version);
            output.WriteUInt16BigEndian(header.Width);
            output.WriteUInt16BigEndian(header.Height);

            // Serialize the PixelFormat
            output.WriteByte(bpp);
            output.WriteByte(3);
            output.WriteByte(2);
            output.WriteByte(3);
            output.WriteByte(8);
            output.WriteByte(11);
            output.WriteByte(5);
            output.WriteByte(0);
            output.WriteByte(0);

            // Serialize the pixel data
            for (uint y = 0; y < thumb.Height; ++y)
            {
                switch (bpp)
                {
                    case 2:
                        {
                            var pixels = new UShortAccess(thumb.Pixels, (int)(y * thumb.Width * 2));
                            for (uint x = 0; x < thumb.Width; ++x)
                            {
                                output.WriteUInt16BigEndian(pixels[0]);
                                pixels.Offset += 2;
                            }
                        }
                        break;

                    case 4:
                        {
                            var pixels = new UIntAccess(thumb.Pixels, (int)(y * thumb.Width * 4));
                            for (var x = 0; x < thumb.Width; ++x)
                            {
                                output.WriteUInt32BigEndian(pixels[0]);
                                pixels.Offset += 4;
                            }
                        }
                        break;

                    default:
                        throw new NotSupportedException();
                }
            }
        }
Пример #3
0
        static void SaveHeader(string name, BinaryWriter bw)
        {
            var hdr = new SaveGameHeader();
            hdr.Type = ScummHelper.MakeTag('S', 'C', 'V', 'M');
            hdr.Size = 0;
            hdr.Version = SaveCurrentVersion;

            bw.WriteUInt32BigEndian(hdr.Type);
            bw.Write(hdr.Size);
            bw.Write(hdr.Version);

            var data = Encoding.UTF8.GetBytes(name);
            var data2 = new byte[32];
            int length = Math.Min(data.Length, 31);
            Array.Copy(data, data2, Math.Min(data.Length, 31));
            data2[length] = 0;
            bw.Write(data2);
        }
Пример #4
0
        private void SaveGameToFile(byte slot)
        {
            ushort cnt;
            var fName = $"sword1.{slot:D3}";
            ushort[] liveBuf = new ushort[ObjectMan.TOTAL_SECTIONS];

            using (var stream = _saveFileMan.OpenForSaving(fName))
            using (var outf = new BinaryWriter(stream))
            {
                //if (!outf)
                //{
                //    // Display an error message and do nothing
                //    displayMessage(0, "Unable to create file '%s'. (%s)", fName, _saveFileMan.popErrorDesc().c_str());
                //    return;
                //}

                outf.WriteUInt32((uint)SAVEGAME_HEADER);

                outf.Write(StrToBytes(_saveNames[slot], 40));
                outf.WriteByte(SAVEGAME_VERSION);

                if (!IsPanelShown()) // Generate a thumbnail only if we are outside of game menu
                    SaveThumbnail(outf);

                // Date / time
                DateTime curTime = DateTime.Now;

                uint saveDate =
                    (uint)
                        ((curTime.Day & 0xFF) << 24 | ((curTime.Month + 1) & 0xFF) << 16 |
                         ((curTime.Year + 1900) & 0xFFFF));
                ushort saveTime = (ushort)((curTime.Hour & 0xFF) << 8 | ((curTime.Minute) & 0xFF));

                outf.WriteUInt32BigEndian(saveDate);
                outf.WriteUInt16BigEndian(saveTime);

                // TODO: outf.WriteUInt32BigEndian(g_engine.getTotalPlayTime() / 1000); replaced by 0
                outf.WriteUInt32BigEndian(0);

                _objMan.SaveLiveList(liveBuf);
                for (cnt = 0; cnt < ObjectMan.TOTAL_SECTIONS; cnt++)
                    outf.WriteUInt16(liveBuf[cnt]);

                var cpt = _objMan.FetchObject(Logic.PLAYER);
                Logic.ScriptVars[(int)ScriptVariableNames.CHANGE_DIR] = (uint)cpt.dir;
                Logic.ScriptVars[(int)ScriptVariableNames.CHANGE_X] = (uint)cpt.xcoord;
                Logic.ScriptVars[(int)ScriptVariableNames.CHANGE_Y] = (uint)cpt.ycoord;
                Logic.ScriptVars[(int)ScriptVariableNames.CHANGE_STANCE] = StaticRes.STAND;
                Logic.ScriptVars[(int)ScriptVariableNames.CHANGE_PLACE] = (uint)cpt.place;

                for (cnt = 0; cnt < Logic.NUM_SCRIPT_VARS; cnt++)
                    outf.WriteUInt32(Sword1.Logic.ScriptVars[cnt]);

                uint playerSize = (SwordObject.Size - 12000) / 4;
                var playerRaw = new UIntAccess(cpt.Data, cpt.Offset);
                for (var cnt2 = 0; cnt2 < playerSize; cnt2++)
                    outf.WriteUInt32(playerRaw[cnt2]);
            }
            // TODO: error
            //if (outf.err())
            //    displayMessage(0, "Couldn't write to file '%s'. Device full? (%s)", fName, _saveFileMan.popErrorDesc().c_str());
            //delete outf;
        }