示例#1
0
        protected override void SaveAllData(DataBuffer file)
        {
            int dataSize = 0;
            int size;
            int numOuterBlocks;

            WorkBuff.Reset();
            CheckSum = 0;
            SimpleVars.SizeOfGameInBytes = DataSize;

            if (FileFormat.IsPS2)
            {
                if (!FileFormat.IsJapanese)
                {
                    SimpleVars.SizeOfGameInBytes += 1;
                }
                WorkBuff.Write(SimpleVars, FileFormat);
                SaveObject(Scripts);
                SaveObject(PlayerPeds);
                SaveObject(Garages);
                SaveObject(Vehicles);
                dataSize += WriteBlock(file);
                SaveObject(Objects);
                SaveObject(Paths);
                SaveObject(Cranes);
                dataSize += WriteBlock(file);
                SaveObject(Pickups);
                SaveObject(PhoneInfo);
                SaveObject(RestartPoints);
                SaveObject(RadarBlips);
                SaveObject(Zones);
                SaveObject(Gangs);
                SaveObject(CarGenerators);
                SaveObject(ParticleObjects);
                SaveObject(AudioScriptObjects);
                SaveObject(PlayerInfo);
                SaveObject(Stats);
                SaveObject(Streaming);
                SaveObject(PedTypeInfo);
                dataSize      += WriteBlock(file);
                numOuterBlocks = NumOuterBlocksPS2;
            }
            else
            {
                SimpleVars.SizeOfGameInBytes += 1;
                WorkBuff.Write(SimpleVars, FileFormat);
                SaveObject(Scripts); dataSize            += WriteBlock(file);
                SaveObject(PlayerPeds); dataSize         += WriteBlock(file);
                SaveObject(Garages); dataSize            += WriteBlock(file);
                SaveObject(Vehicles); dataSize           += WriteBlock(file);
                SaveObject(Objects); dataSize            += WriteBlock(file);
                SaveObject(Paths); dataSize              += WriteBlock(file);
                SaveObject(Cranes); dataSize             += WriteBlock(file);
                SaveObject(Pickups); dataSize            += WriteBlock(file);
                SaveObject(PhoneInfo); dataSize          += WriteBlock(file);
                SaveObject(RestartPoints); dataSize      += WriteBlock(file);
                SaveObject(RadarBlips); dataSize         += WriteBlock(file);
                SaveObject(Zones); dataSize              += WriteBlock(file);
                SaveObject(Gangs); dataSize              += WriteBlock(file);
                SaveObject(CarGenerators); dataSize      += WriteBlock(file);
                SaveObject(ParticleObjects); dataSize    += WriteBlock(file);
                SaveObject(AudioScriptObjects); dataSize += WriteBlock(file);
                SaveObject(PlayerInfo); dataSize         += WriteBlock(file);
                SaveObject(Stats); dataSize              += WriteBlock(file);
                SaveObject(Streaming); dataSize          += WriteBlock(file);
                SaveObject(PedTypeInfo); dataSize        += WriteBlock(file);
                numOuterBlocks = NumOuterBlocks;
            }

            int numPaddingBlocks = 0;

            for (int i = 0; i < MaxNumPaddingBlocks; i++)
            {
                size = (SimpleVars.SizeOfGameInBytes - dataSize - 1) & 0x7FFFFFFC;
                if (size > GetBufferSize())
                {
                    size = GetBufferSize();
                }
                if (size > 4)
                {
                    WorkBuff.Reset();
                    WorkBuff.Pad(size);
                    dataSize += WriteBlock(file);
                    numPaddingBlocks++;
                }
            }

            file.Write(CheckSum);
            if (FileFormat.IsXbox)
            {
                byte[] data = file.GetBytes();
                byte[] sig  = XboxHelper.CalculateGameSaveSignature(XboxTitleKey, data, 0, data.Length - 4);
                file.Write(sig);
            }

            // Size checks
            int expectedDataSize = DataSize;

            if (!(FileFormat.IsPS2 && FileFormat.IsJapanese))
            {
                expectedDataSize += 1;
            }
            expectedDataSize = (expectedDataSize - 1) & 0x7FFFFFFC;
            int expectedFileSize = expectedDataSize + ((numOuterBlocks + numPaddingBlocks) * sizeof(int)) + sizeof(int);

            if (FileFormat.IsXbox)
            {
                expectedFileSize += XboxHelper.SignatureLength;
            }
            Debug.Assert(expectedDataSize == dataSize);
            Debug.Assert(expectedFileSize == file.Length);
            Debug.WriteLine("Save successful!");
        }
示例#2
0
 static void Main(string[] args)
 {
     XboxHelper xbhelper = new XboxHelper();
     XboxHelper.Start();
 }